From e7ed1ed865a5d2d96747f7d0b848c03ccc17f33c Mon Sep 17 00:00:00 2001 From: Nicola Pero Date: Mon, 24 Jun 2002 12:22:12 +0000 Subject: [PATCH] Do not use hardcoded 12 height of default font, but retrieve it from NSFont git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@13960 72102866-910b-0410-8b05-ffd578937521 --- Source/GSSimpleLayoutManager.m | 39 +++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/Source/GSSimpleLayoutManager.m b/Source/GSSimpleLayoutManager.m index 11e6aee32..edf4565e2 100644 --- a/Source/GSSimpleLayoutManager.m +++ b/Source/GSSimpleLayoutManager.m @@ -111,6 +111,24 @@ static NSCharacterSet *invSelectionWordGranularitySet; @end // end: _GNULineLayoutInfo------------------------------------------------------ +/* This is the height of the line/insertion point of the default font + * - used when there is no text/font in the textview. FIXME - in many + * cases we use this, but it's inappropriate - consider if there is + * not a way to get a more appropriate font (eg, the last font the + * user was typing in if we're after a newline etc). Anyway, better + * using this function than hardcoding '12' :-) + */ +static inline float defaultFontHeight () +{ + NSFont *userFont; + NSRect fontRect; + + userFont = [NSFont userFontOfSize: 0]; + fontRect = [userFont boundingRectForFont]; + + return fontRect.size.height; +} + @interface GSSimpleLayoutManager (Private) @@ -276,7 +294,7 @@ static NSCharacterSet *invSelectionWordGranularitySet; if (![_textStorage length] || ![_lineLayoutInformation count]) { - return NSMakeRect(0, 0, 0, 12); + return NSMakeRect (0, 0, 0, defaultFontHeight ()); } currentInfo = [_lineLayoutInformation @@ -327,7 +345,7 @@ static NSCharacterSet *invSelectionWordGranularitySet; if (![_textStorage length] || ![_lineLayoutInformation count]) { - return NSMakeRect(0, 0, 0, 12); + return NSMakeRect (0, 0, 0, defaultFontHeight ()); } i1 = [self lineLayoutIndexForGlyphIndex: aRange.location]; @@ -681,7 +699,7 @@ forStartOfGlyphRange: (NSRange)glyphRange width = [container containerSize].width; if (![_textStorage length] || ![_lineLayoutInformation count]) { - return NSMakeRect(0, 0, width, 12); + return NSMakeRect(0, 0, width, defaultFontHeight ()); } currentInfo = [_lineLayoutInformation lastObject]; @@ -911,9 +929,9 @@ scanRange(NSScanner *scanner, NSCharacterSet* aSet) // If there is no text add one empty box [_lineLayoutInformation addObject: [_GNULineLayoutInfo - lineLayoutWithRange: NSMakeRange (0, 0) - rect: NSMakeRect (0, 0, width, 12) - usedRect: NSMakeRect (0, 0, 1, 12)]]; + lineLayoutWithRange: NSMakeRange (0, 0) + rect: NSMakeRect (0, 0, width, defaultFontHeight ()) + usedRect: NSMakeRect (0, 0, 1, defaultFontHeight ())]]; return NSMakeRange(0,1); } @@ -1091,10 +1109,11 @@ scanRange(NSScanner *scanner, NSCharacterSet* aSet) // Add information for the line break scannerPosition += eol.length; usedLineRect.size.width += 1; - // FIXME: This should use the real font size!! + /* FIXME: This should use the real font size!! not + the default one !! */ if (usedLineRect.size.height == 0) { - usedLineRect.size.height = 12; + usedLineRect.size.height = defaultFontHeight (); } } } @@ -1170,9 +1189,9 @@ scanRange(NSScanner *scanner, NSCharacterSet* aSet) addObject: [_GNULineLayoutInfo lineLayoutWithRange: NSMakeRange (length, 0) rect: NSMakeRect (drawingPoint.x, drawingPoint.y, - width, 12) + width, defaultFontHeight ()) usedRect: NSMakeRect (drawingPoint.x, drawingPoint.y, - 1, 12)]]; + 1, defaultFontHeight ())]]; }