bug fix for character 0x200B : zero-advance-space
If we see a zero-advance, double check to see if its bounds should really be empty, by asking for its path. If that is empty, jam the bounds to 0 The bug was that CT was returning a huge bounds for that character (but, strangely enough, not for normal space character, hence our check for zero-advance) git-svn-id: http://skia.googlecode.com/svn/trunk@2424 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
767ea3be7f
commit
fd8772e008
@ -484,8 +484,31 @@ void SkScalerContext_Mac::generateMetrics(SkGlyph* glyph)
|
||||
cgGlyph = (CGGlyph) glyph->getGlyphID(fBaseGlyphCount);
|
||||
|
||||
CTFontGetBoundingRectsForGlyphs(mFont, kCTFontDefaultOrientation, &cgGlyph, &theBounds, 1);
|
||||
CTFontGetAdvancesForGlyphs( mFont, kCTFontDefaultOrientation, &cgGlyph, &theAdvance, 1);
|
||||
CTFontGetAdvancesForGlyphs(mFont, kCTFontDefaultOrientation, &cgGlyph, &theAdvance, 1);
|
||||
|
||||
// BUG?
|
||||
// 0x200B (zero-advance space) seems to return a huge (garbage) bounds, when
|
||||
// it should be empty. So, if we see a zero-advance, we check if it has an
|
||||
// empty path or not, and if so, we jam the bounds to 0. Hopefully a zero-advance
|
||||
// is rare, so we won't incur a big performance cost for this extra check.
|
||||
if (0 == theAdvance.width && 0 == theAdvance.height) {
|
||||
CGPathRef path = CTFontCreatePathForGlyph(mFont, cgGlyph, NULL);
|
||||
if (NULL == path || CGPathIsEmpty(path)) {
|
||||
theBounds = CGRectMake(0, 0, 0, 0);
|
||||
}
|
||||
if (path) {
|
||||
CGPathRelease(path);
|
||||
}
|
||||
}
|
||||
|
||||
glyph->zeroMetrics();
|
||||
glyph->fAdvanceX = SkFloatToFixed(theAdvance.width);
|
||||
glyph->fAdvanceY = -SkFloatToFixed(theAdvance.height);
|
||||
|
||||
if (CGRectIsEmpty(theBounds)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Adjust the bounds
|
||||
//
|
||||
// CTFontGetBoundingRectsForGlyphs ignores the font transform, so we need
|
||||
@ -495,9 +518,6 @@ void SkScalerContext_Mac::generateMetrics(SkGlyph* glyph)
|
||||
theBounds = CGRectInset(theBounds, -1, -1);
|
||||
|
||||
// Get the metrics
|
||||
glyph->zeroMetrics();
|
||||
glyph->fAdvanceX = SkFloatToFixed(theAdvance.width);
|
||||
glyph->fAdvanceY = -SkFloatToFixed(theAdvance.height);
|
||||
if (isLion()) {
|
||||
// Lion returns fractions in the bounds
|
||||
glyph->fWidth = sk_float_ceil2int(theBounds.size.width);
|
||||
|
Loading…
Reference in New Issue
Block a user