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

Add some debug logging to the font size estimator and ensure it never returns...

Add some debug logging to the font size estimator and ensure it never returns a dimension with value 0. Issue 5684.
parent acde36f8
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -28,6 +28,8 @@
 
#import "FontSizeEstimator.h"
 
#import "DebugLogging.h"
@implementation FontSizeEstimator
 
@synthesize size;
Loading
Loading
@@ -49,7 +51,7 @@
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
[dic setObject:aFont forKey:NSFontAttributeName];
NSSize size = [@"W" sizeWithAttributes:dic];
DLog(@"Initial guess at a size for %@ is %@", aFont, NSStringFromSize(size));
CGGlyph glyphs[1];
int advances[1];
UniChar characters[1];
Loading
Loading
@@ -65,11 +67,23 @@
size.width *= [aFont pointSize];
size.width /= CGFontGetUnitsPerEm(cgfont);
size.width = round(size.width);
DLog(@"Improving my guess for width using formula round(%d * %f / %d) giving %f",
advances[0],
[aFont pointSize],
CGFontGetUnitsPerEm(cgfont),
size.width);
}
CGFontRelease(cgfont);
 
size.height = [aFont ascender] - [aFont descender];
// Things go very badly indeed if the size is 0.
size.width = MAX(1, size.width);
size.height = MAX(1, size.height);
double baseline = -(floorf([aFont leading]) - floorf([aFont descender]));
fse.size = size;
fse.baseline = baseline;
}
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