From 045183032f29bdb2211bd2933dd318342fecf041 Mon Sep 17 00:00:00 2001 From: Sven Weidauer Date: Mon, 17 Jan 2011 15:00:18 +0000 Subject: Font scaling and other scaling related fixes. svn path=/trunk/netsurf/; revision=11349 --- cocoa/BrowserView.m | 8 ++++++-- cocoa/font.h | 1 + cocoa/font.m | 12 +++++++++++- cocoa/gui.m | 16 ++++++++++++---- 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/cocoa/BrowserView.m b/cocoa/BrowserView.m index 74bdf7d24..2254ba0d5 100644 --- a/cocoa/BrowserView.m +++ b/cocoa/BrowserView.m @@ -25,6 +25,8 @@ #import "desktop/options.h" #import "desktop/selection.h" +#import "cocoa/font.h" + @implementation BrowserView @synthesize browser; @@ -38,8 +40,8 @@ static const NSTimeInterval CaretBlinkTime = 0.8; static inline NSRect cocoa_get_caret_rect( BrowserView *view ) { NSRect caretRect = { - .origin = view->caretPoint, - .size = NSMakeSize( CaretWidth, view->caretHeight ) + .origin = NSMakePoint( view->caretPoint.x * view->browser->scale, view->caretPoint.y * view->browser->scale ), + .size = NSMakeSize( CaretWidth, view->caretHeight * view->browser->scale ) }; return caretRect; @@ -88,6 +90,8 @@ static inline NSRect cocoa_get_caret_rect( BrowserView *view ) if (NULL == browser->current_content) return; + cocoa_set_font_scale_factor( browser->scale ); + NSRect frame = [self bounds]; const NSRect *rects = NULL; diff --git a/cocoa/font.h b/cocoa/font.h index b65d62844..769bd1dd9 100644 --- a/cocoa/font.h +++ b/cocoa/font.h @@ -20,5 +20,6 @@ #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_set_font_scale_factor( float newFactor ); #endif diff --git a/cocoa/font.m b/cocoa/font.m index 0b78c4d80..2e38b33f5 100644 --- a/cocoa/font.m +++ b/cocoa/font.m @@ -159,9 +159,19 @@ static NSLayoutManager *cocoa_prepare_layout_manager( const char *bytes, size_t 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 ) { - 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) { NSFont *font = [cocoa_text_storage attribute: NSFontAttributeName atIndex: 0 effectiveRange: NULL]; diff --git a/cocoa/gui.m b/cocoa/gui.m index a2b254d75..80ab9cb2a 100644 --- a/cocoa/gui.m +++ b/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) { - NSRect rect = NSMakeRect( x0, y0, x1 - x0, y1 - y0 ); + const NSRect rect = NSMakeRect( x0, y0, x1 - x0, y1 - y0 ); [[(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, const union content_msg_data *data) { - gui_window_redraw( g, data->redraw.x, data->redraw.y, - data->redraw.x + data->redraw.width, - data->redraw.y + data->redraw.height ); + const CGFloat scale = [(BrowserWindow *)g browser]->scale; + const NSRect rect = NSMakeRect( data->redraw.object_x * scale, + 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) @@ -136,6 +139,11 @@ void gui_window_get_dimensions(struct gui_window *g, int *width, int *height, NSCParameterAssert( width != NULL && height != NULL ); 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 ); *height = NSHeight( frame ); } -- cgit v1.2.3