summaryrefslogtreecommitdiff
path: root/cocoa/font.m
diff options
context:
space:
mode:
authorSven Weidauer <sven.weidauer@gmail.com>2011-01-27 07:55:06 +0000
committerSven Weidauer <sven.weidauer@gmail.com>2011-01-27 07:55:06 +0000
commit14404769cc41c75468e247c6db94fe164697af90 (patch)
tree45b792f662cda7ce3ee0362194c4a393f6d312a8 /cocoa/font.m
parentf5ef7c71e74722d8f7c00d7c27f1a4486e88a402 (diff)
downloadnetsurf-14404769cc41c75468e247c6db94fe164697af90.tar.gz
netsurf-14404769cc41c75468e247c6db94fe164697af90.tar.bz2
Fixing font calculations and warnings about invalid glyph indices.
svn path=/trunk/netsurf/; revision=11504
Diffstat (limited to 'cocoa/font.m')
-rw-r--r--cocoa/font.m9
1 files changed, 6 insertions, 3 deletions
diff --git a/cocoa/font.m b/cocoa/font.m
index 15debd603..73e73e7e1 100644
--- a/cocoa/font.m
+++ b/cocoa/font.m
@@ -62,8 +62,11 @@ static bool nsfont_position_in_string(const plot_font_style_t *style,
NSUInteger glyphIndex = cocoa_glyph_for_location( layout, x );
NSUInteger chars = [layout characterIndexForGlyphAtIndex: glyphIndex];
- *char_offset = cocoa_bytes_for_characters( string, chars );
- *actual_x = [layout locationForGlyphAtIndex: glyphIndex].x;
+ if (chars >= [cocoa_text_storage length]) *char_offset = length;
+ else *char_offset = cocoa_bytes_for_characters( string, chars );
+
+ *actual_x = NSMaxX( [layout boundingRectForGlyphRange: NSMakeRange( glyphIndex - 1, 1 )
+ inTextContainer: cocoa_text_container] );
return true;
}
@@ -78,7 +81,7 @@ static bool nsfont_split(const plot_font_style_t *style,
NSUInteger glyphIndex = cocoa_glyph_for_location( layout, x );
NSUInteger chars = [layout characterIndexForGlyphAtIndex: glyphIndex];
- if (chars == [cocoa_text_storage length] - 1) {
+ if (chars >= [cocoa_text_storage length]) {
*char_offset = length;
*actual_x = cocoa_layout_width( layout );
return true;