Font scaling and other scaling related fixes.
svn path=/trunk/netsurf/; revision=11349
This commit is contained in:
parent
d2aa0bcea9
commit
045183032f
|
@ -25,6 +25,8 @@
|
||||||
#import "desktop/options.h"
|
#import "desktop/options.h"
|
||||||
#import "desktop/selection.h"
|
#import "desktop/selection.h"
|
||||||
|
|
||||||
|
#import "cocoa/font.h"
|
||||||
|
|
||||||
@implementation BrowserView
|
@implementation BrowserView
|
||||||
|
|
||||||
@synthesize browser;
|
@synthesize browser;
|
||||||
|
@ -38,8 +40,8 @@ static const NSTimeInterval CaretBlinkTime = 0.8;
|
||||||
static inline NSRect cocoa_get_caret_rect( BrowserView *view )
|
static inline NSRect cocoa_get_caret_rect( BrowserView *view )
|
||||||
{
|
{
|
||||||
NSRect caretRect = {
|
NSRect caretRect = {
|
||||||
.origin = view->caretPoint,
|
.origin = NSMakePoint( view->caretPoint.x * view->browser->scale, view->caretPoint.y * view->browser->scale ),
|
||||||
.size = NSMakeSize( CaretWidth, view->caretHeight )
|
.size = NSMakeSize( CaretWidth, view->caretHeight * view->browser->scale )
|
||||||
};
|
};
|
||||||
|
|
||||||
return caretRect;
|
return caretRect;
|
||||||
|
@ -88,6 +90,8 @@ static inline NSRect cocoa_get_caret_rect( BrowserView *view )
|
||||||
|
|
||||||
if (NULL == browser->current_content) return;
|
if (NULL == browser->current_content) return;
|
||||||
|
|
||||||
|
cocoa_set_font_scale_factor( browser->scale );
|
||||||
|
|
||||||
NSRect frame = [self bounds];
|
NSRect frame = [self bounds];
|
||||||
|
|
||||||
const NSRect *rects = NULL;
|
const NSRect *rects = NULL;
|
||||||
|
|
|
@ -20,5 +20,6 @@
|
||||||
#define COCOA_FONT_H
|
#define COCOA_FONT_H
|
||||||
|
|
||||||
void cocoa_draw_string( int x, int y, const char *bytes, size_t length, const plot_font_style_t *style );
|
void cocoa_draw_string( int x, int y, const char *bytes, size_t length, const plot_font_style_t *style );
|
||||||
|
void cocoa_set_font_scale_factor( float newFactor );
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
12
cocoa/font.m
12
cocoa/font.m
|
@ -159,9 +159,19 @@ static NSLayoutManager *cocoa_prepare_layout_manager( const char *bytes, size_t
|
||||||
return layout;
|
return layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static CGFloat cocoa_font_scale_factor = 1.0;
|
||||||
|
|
||||||
|
void cocoa_set_font_scale_factor( float newFactor )
|
||||||
|
{
|
||||||
|
cocoa_font_scale_factor = newFactor;
|
||||||
|
}
|
||||||
|
|
||||||
void cocoa_draw_string( int x, int y, const char *bytes, size_t length, const plot_font_style_t *style )
|
void cocoa_draw_string( int x, int y, const char *bytes, size_t length, const plot_font_style_t *style )
|
||||||
{
|
{
|
||||||
NSLayoutManager *layout = cocoa_prepare_layout_manager( bytes, length, style );
|
plot_font_style_t scaledStyle = *style;
|
||||||
|
scaledStyle.size *= cocoa_font_scale_factor;
|
||||||
|
|
||||||
|
NSLayoutManager *layout = cocoa_prepare_layout_manager( bytes, length, &scaledStyle );
|
||||||
|
|
||||||
if ([cocoa_text_storage length] > 0) {
|
if ([cocoa_text_storage length] > 0) {
|
||||||
NSFont *font = [cocoa_text_storage attribute: NSFontAttributeName atIndex: 0 effectiveRange: NULL];
|
NSFont *font = [cocoa_text_storage attribute: NSFontAttributeName atIndex: 0 effectiveRange: NULL];
|
||||||
|
|
16
cocoa/gui.m
16
cocoa/gui.m
|
@ -86,7 +86,7 @@ void gui_window_set_title(struct gui_window *g, const char *title)
|
||||||
|
|
||||||
void gui_window_redraw(struct gui_window *g, int x0, int y0, int x1, int y1)
|
void gui_window_redraw(struct gui_window *g, int x0, int y0, int x1, int y1)
|
||||||
{
|
{
|
||||||
NSRect rect = NSMakeRect( x0, y0, x1 - x0, y1 - y0 );
|
const NSRect rect = NSMakeRect( x0, y0, x1 - x0, y1 - y0 );
|
||||||
[[(BrowserWindow *)g view] setNeedsDisplayInRect: rect];
|
[[(BrowserWindow *)g view] setNeedsDisplayInRect: rect];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,9 +98,12 @@ void gui_window_redraw_window(struct gui_window *g)
|
||||||
void gui_window_update_box(struct gui_window *g,
|
void gui_window_update_box(struct gui_window *g,
|
||||||
const union content_msg_data *data)
|
const union content_msg_data *data)
|
||||||
{
|
{
|
||||||
gui_window_redraw( g, data->redraw.x, data->redraw.y,
|
const CGFloat scale = [(BrowserWindow *)g browser]->scale;
|
||||||
data->redraw.x + data->redraw.width,
|
const NSRect rect = NSMakeRect( data->redraw.object_x * scale,
|
||||||
data->redraw.y + data->redraw.height );
|
data->redraw.object_y * scale,
|
||||||
|
data->redraw.object_width * scale,
|
||||||
|
data->redraw.object_height * scale );
|
||||||
|
[[(BrowserWindow *)g view] setNeedsDisplayInRect: rect];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool gui_window_get_scroll(struct gui_window *g, int *sx, int *sy)
|
bool gui_window_get_scroll(struct gui_window *g, int *sx, int *sy)
|
||||||
|
@ -136,6 +139,11 @@ void gui_window_get_dimensions(struct gui_window *g, int *width, int *height,
|
||||||
NSCParameterAssert( width != NULL && height != NULL );
|
NSCParameterAssert( width != NULL && height != NULL );
|
||||||
|
|
||||||
NSRect frame = [[(BrowserWindow *)g view] frame];
|
NSRect frame = [[(BrowserWindow *)g view] frame];
|
||||||
|
if (scaled) {
|
||||||
|
const CGFloat scale = [(BrowserWindow *)g browser]->scale;
|
||||||
|
frame.size.width /= scale;
|
||||||
|
frame.size.height /= scale;
|
||||||
|
}
|
||||||
*width = NSWidth( frame );
|
*width = NSWidth( frame );
|
||||||
*height = NSHeight( frame );
|
*height = NSHeight( frame );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue