Skip to content
Snippets Groups Projects
Commit 8977399f authored by George Nachman's avatar George Nachman
Browse files

Change how font sizes are estimated by looking at all upper case letters'...

Change how font sizes are estimated by looking at all upper case letters' estimates and the actual bounds of 'X' to determine the bounding box. Looks at 'x' and 'y' to determine real descender. Fixes bug 1108. Also mostly fixes Consolas (though its baseline is still one pixel too low).
parent 97910b88
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -478,7 +478,7 @@ typedef enum {
CHARTYPE_OTHER, // Symbols, etc. Anything that doesn't fall into the other categories.
} PTYCharType;
 
- (void)modifyFont:(NSFont*)font info:(PTYFontInfo*)fontInfo;
- (void)modifyFont:(NSFont*)font baseline:(double)baseline info:(PTYFontInfo*)fontInfo;
- (void)releaseFontInfo:(PTYFontInfo*)fontInfo;
 
- (unsigned int) _checkForSupportedDragTypes:(id <NSDraggingInfo>) sender;
Loading
Loading
@@ -521,7 +521,7 @@ typedef enum {
- (void)_dragText:(NSString *)aString forEvent:(NSEvent *)theEvent;
- (BOOL)_isCharSelectedInRow:(int)row col:(int)col checkOld:(BOOL)old;
- (void)_settingsChanged:(NSNotification *)notification;
- (void)_modifyFont:(NSFont*)font into:(PTYFontInfo*)fontInfo;
- (void)_modifyFont:(NSFont*)font baseline:(double)baseline into:(PTYFontInfo*)fontInfo;
- (PTYFontInfo*)getFontForChar:(UniChar)ch
isComplex:(BOOL)complex
fgColor:(int)fgColor
Loading
Loading
Loading
Loading
@@ -58,6 +58,7 @@ static const int MAX_WORKING_DIR_COUNT = 50;
#import "iTermExpose.h"
#import "RegexKitLite/RegexKitLite.h"
#import "iTerm/NSStringITerm.h"
#import "FontSizeEstimator.h"
 
#include <sys/time.h>
#include <math.h>
Loading
Loading
@@ -589,18 +590,23 @@ static NSImage* wrapToBottomImage = nil;
return secondaryFont.font;
}
 
+ (NSSize)charSizeForFont:(NSFont*)aFont horizontalSpacing:(double)hspace verticalSpacing:(double)vspace
+ (NSSize)charSizeForFont:(NSFont*)aFont horizontalSpacing:(double)hspace verticalSpacing:(double)vspace baseline:(double*)baseline
{
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
[dic setObject:aFont forKey:NSFontAttributeName];
NSSize size = [@"W" sizeWithAttributes:dic];
FontSizeEstimator* fse = [FontSizeEstimator fontSizeEstimatorForFont:aFont];
NSSize size = [fse size];
size.width = ceil(size.width * hspace);
size.height = ceil(vspace * ceil([aFont ascender] - [aFont descender] + [aFont leading]));
size.height = ceil(vspace * ceil(size.height + [aFont leading]));
if (baseline) {
*baseline = [fse baseline];
}
return size;
}
 
+ (NSSize)charSizeForFont:(NSFont*)aFont horizontalSpacing:(double)hspace verticalSpacing:(double)vspace
{
return [PTYTextView charSizeForFont:aFont horizontalSpacing:hspace verticalSpacing:vspace baseline:nil];
}
- (double)horizontalSpacing
{
return horizontalSpacing_;
Loading
Loading
@@ -616,9 +622,11 @@ static NSImage* wrapToBottomImage = nil;
horizontalSpacing:(double)horizontalSpacing
verticalSpacing:(double)verticalSpacing
{
double baseline;
NSSize sz = [PTYTextView charSizeForFont:aFont
horizontalSpacing:1.0
verticalSpacing:1.0];
verticalSpacing:1.0
baseline:&baseline];
 
charWidthWithoutSpacing = sz.width;
charHeightWithoutSpacing = sz.height;
Loading
Loading
@@ -626,8 +634,8 @@ static NSImage* wrapToBottomImage = nil;
verticalSpacing_ = verticalSpacing;
charWidth = ceil(charWidthWithoutSpacing * horizontalSpacing);
lineHeight = ceil(charHeightWithoutSpacing * verticalSpacing);
[self modifyFont:aFont info:&primaryFont];
[self modifyFont:naFont info:&secondaryFont];
[self modifyFont:aFont baseline:baseline info:&primaryFont];
[self modifyFont:naFont baseline:baseline info:&secondaryFont];
 
// Cannot keep fallback fonts if the primary font changes because their
// baseline offsets are set by the primary font. It's simplest to remove
Loading
Loading
@@ -6377,7 +6385,7 @@ static bool IsUrlChar(NSString* str)
[self setNeedsDisplay:YES];
}
 
- (void)_modifyFont:(NSFont*)font into:(PTYFontInfo*)fontInfo
- (void)_modifyFont:(NSFont*)font baseline:(double)baseline into:(PTYFontInfo*)fontInfo
{
if (fontInfo->font) {
[self releaseFontInfo:fontInfo];
Loading
Loading
@@ -6385,19 +6393,19 @@ static bool IsUrlChar(NSString* str)
 
fontInfo->font = font;
[fontInfo->font retain];
fontInfo->baselineOffset = -(floorf([font leading]) - floorf([font descender]));
fontInfo->baselineOffset = baseline;
fontInfo->boldVersion = NULL;
}
 
- (void)modifyFont:(NSFont*)font info:(PTYFontInfo*)fontInfo
- (void)modifyFont:(NSFont*)font baseline:(double)baseline info:(PTYFontInfo*)fontInfo
{
[self _modifyFont:font into:fontInfo];
[self _modifyFont:font baseline:baseline into:fontInfo];
NSFontManager* fontManager = [NSFontManager sharedFontManager];
NSFont* boldFont = [fontManager convertFont:font toHaveTrait:NSBoldFontMask];
if (boldFont && ([fontManager traitsOfFont:boldFont] & NSBoldFontMask)) {
fontInfo->boldVersion = (PTYFontInfo*)malloc(sizeof(PTYFontInfo));
fontInfo->boldVersion->font = NULL;
[self _modifyFont:boldFont into:fontInfo->boldVersion];
[self _modifyFont:boldFont baseline:baseline into:fontInfo->boldVersion];
}
}
 
Loading
Loading
@@ -6410,7 +6418,7 @@ static bool IsUrlChar(NSString* str)
} else {
PTYFontInfo* info = (PTYFontInfo*) malloc(sizeof(PTYFontInfo));
info->font = NULL;
[self _modifyFont:font into:info];
[self _modifyFont:font baseline:primaryFont.baselineOffset into:info];
 
// Force this font to line up with the primary font's baseline.
info->baselineOffset = primaryFont.baselineOffset;
Loading
Loading
Loading
Loading
@@ -192,6 +192,8 @@
1DA02CFB1327612600D7E7DB /* bell.png in Resources */ = {isa = PBXBuildFile; fileRef = 1DA02CFA1327612600D7E7DB /* bell.png */; };
1DA030F91328BD7C00D7E7DB /* wrap_to_bottom.png in Resources */ = {isa = PBXBuildFile; fileRef = 1DA030F71328BD7C00D7E7DB /* wrap_to_bottom.png */; };
1DA030FA1328BD7C00D7E7DB /* wrap_to_top.png in Resources */ = {isa = PBXBuildFile; fileRef = 1DA030F81328BD7C00D7E7DB /* wrap_to_top.png */; };
1DA8117E13CEA30A00CCA89A /* FontSizeEstimator.h in Headers */ = {isa = PBXBuildFile; fileRef = 1DA8117C13CEA30A00CCA89A /* FontSizeEstimator.h */; };
1DA8117F13CEA30A00CCA89A /* FontSizeEstimator.m in Sources */ = {isa = PBXBuildFile; fileRef = 1DA8117D13CEA30A00CCA89A /* FontSizeEstimator.m */; };
1DA9BD0D122F1077002FCC65 /* star-gold24.png in Resources */ = {isa = PBXBuildFile; fileRef = 1DA9BD0C122F1077002FCC65 /* star-gold24.png */; };
1DAED28812E9395E005E49ED /* GlobalSearch.h in Headers */ = {isa = PBXBuildFile; fileRef = 1DAED28612E9395E005E49ED /* GlobalSearch.h */; };
1DAED28912E9395E005E49ED /* GlobalSearch.m in Sources */ = {isa = PBXBuildFile; fileRef = 1DAED28712E9395E005E49ED /* GlobalSearch.m */; };
Loading
Loading
@@ -358,6 +360,8 @@
1DA02CFA1327612600D7E7DB /* bell.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = bell.png; path = images/bell.png; sourceTree = "<group>"; };
1DA030F71328BD7C00D7E7DB /* wrap_to_bottom.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = wrap_to_bottom.png; path = images/wrap_to_bottom.png; sourceTree = "<group>"; };
1DA030F81328BD7C00D7E7DB /* wrap_to_top.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = wrap_to_top.png; path = images/wrap_to_top.png; sourceTree = "<group>"; };
1DA8117C13CEA30A00CCA89A /* FontSizeEstimator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FontSizeEstimator.h; sourceTree = "<group>"; };
1DA8117D13CEA30A00CCA89A /* FontSizeEstimator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FontSizeEstimator.m; sourceTree = "<group>"; };
1DA9BD0C122F1077002FCC65 /* star-gold24.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "star-gold24.png"; path = "images/star-gold24.png"; sourceTree = "<group>"; };
1DAED28612E9395E005E49ED /* GlobalSearch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GlobalSearch.h; sourceTree = "<group>"; };
1DAED28712E9395E005E49ED /* GlobalSearch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GlobalSearch.m; sourceTree = "<group>"; };
Loading
Loading
@@ -609,6 +613,8 @@
0464AB0E006CD2EC7F000001 /* Classes */ = {
isa = PBXGroup;
children = (
1DA8117C13CEA30A00CCA89A /* FontSizeEstimator.h */,
1DA8117D13CEA30A00CCA89A /* FontSizeEstimator.m */,
1DE214E0128212EE004E3ADF /* Autocomplete.m */,
1D6C50A61226EEFB00E0AA3E /* BookmarkListView.m */,
1DCF3E8D122419D200AD56F1 /* BookmarkModel.m */,
Loading
Loading
@@ -1097,6 +1103,7 @@
1D624BEE1386E34F00111319 /* GTMObjectSingleton.h in Headers */,
1D624BF41386E39D00111319 /* GTMDebugSelectorValidation.h in Headers */,
1D624BF61386E3B400111319 /* GTMTypeCasting.h in Headers */,
1DA8117E13CEA30A00CCA89A /* FontSizeEstimator.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Loading
Loading
@@ -1377,6 +1384,7 @@
1D06A050134CDBED00C414EF /* Trouter.m in Sources */,
1D988598135D23BD0072023F /* ProcessCache.m in Sources */,
1D624BC81386E09E00111319 /* GTMCarbonEvent.m in Sources */,
1DA8117F13CEA30A00CCA89A /* FontSizeEstimator.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment