Commit a45efb15 authored by Ben Wagner's avatar Ben Wagner Committed by Commit Bot

On Mac fall back to bounds if no path.

SkFont getPath now distinguishes between empty path and no-path. Use
this for better bounds computation on Mac. In addition, use the newer
non-deprecated SkFont methods for advances and bounds.

Bug: skia:8779
Change-Id: I360b5cbb16eda3c02d8e5773f95c0402e5fae55b
Reviewed-on: https://chromium-review.googlesource.com/c/1487357Reviewed-by: default avatarDominik Röttsches <drott@chromium.org>
Commit-Queue: Ben Wagner <bungeman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#635534}
parent 18f1701c
...@@ -36,7 +36,7 @@ void SkFontGetGlyphWidthForHarfBuzz(const SkFont& font, ...@@ -36,7 +36,7 @@ void SkFontGetGlyphWidthForHarfBuzz(const SkFont& font,
SkScalar sk_width; SkScalar sk_width;
uint16_t glyph = codepoint; uint16_t glyph = codepoint;
font.getWidths(&glyph, 1, &sk_width, nullptr); font.getWidths(&glyph, 1, &sk_width);
if (!font.isSubpixel()) if (!font.isSubpixel())
sk_width = SkScalarRoundToInt(sk_width); sk_width = SkScalarRoundToInt(sk_width);
*width = SkiaScalarToHarfBuzzPosition(sk_width); *width = SkiaScalarToHarfBuzzPosition(sk_width);
...@@ -57,7 +57,7 @@ void SkFontGetGlyphWidthForHarfBuzz(const SkFont& font, ...@@ -57,7 +57,7 @@ void SkFontGetGlyphWidthForHarfBuzz(const SkFont& font,
glyph_array[i] = *glyphs; glyph_array[i] = *glyphs;
} }
Vector<SkScalar, 256> sk_width_array(count); Vector<SkScalar, 256> sk_width_array(count);
font.getWidths(glyph_array.data(), count, sk_width_array.data(), nullptr); font.getWidths(glyph_array.data(), count, sk_width_array.data());
if (!font.isSubpixel()) { if (!font.isSubpixel()) {
for (unsigned i = 0; i < count; i++) for (unsigned i = 0; i < count; i++)
...@@ -90,10 +90,13 @@ void SkFontGetGlyphExtentsForHarfBuzz(const SkFont& font, ...@@ -90,10 +90,13 @@ void SkFontGetGlyphExtentsForHarfBuzz(const SkFont& font,
// TODO(drott): Remove this once we have better metrics bounds // TODO(drott): Remove this once we have better metrics bounds
// on Mac, https://bugs.chromium.org/p/skia/issues/detail?id=5328 // on Mac, https://bugs.chromium.org/p/skia/issues/detail?id=5328
SkPath path; SkPath path;
font.getPath(glyph, &path); if (font.getPath(glyph, &path)) {
sk_bounds = path.getBounds(); sk_bounds = path.getBounds();
} else {
font.getBounds(&glyph, 1, &sk_bounds, nullptr);
}
#else #else
font.getWidths(&glyph, 1, nullptr, &sk_bounds); font.getBounds(&glyph, 1, &sk_bounds, nullptr);
#endif #endif
if (!font.isSubpixel()) { if (!font.isSubpixel()) {
// Use roundOut() rather than round() to avoid rendering glyphs // Use roundOut() rather than round() to avoid rendering glyphs
...@@ -114,16 +117,14 @@ void SkFontGetBoundsForGlyph(const SkFont& font, Glyph glyph, SkRect* bounds) { ...@@ -114,16 +117,14 @@ void SkFontGetBoundsForGlyph(const SkFont& font, Glyph glyph, SkRect* bounds) {
// TODO(drott): Remove this once we have better metrics bounds // TODO(drott): Remove this once we have better metrics bounds
// on Mac, https://bugs.chromium.org/p/skia/issues/detail?id=5328 // on Mac, https://bugs.chromium.org/p/skia/issues/detail?id=5328
SkPath path; SkPath path;
font.getPath(glyph, &path); if (font.getPath(glyph, &path)) {
*bounds = path.getBounds(); *bounds = path.getBounds();
// For Apple Color Emoji path bounds are returning empty rectangles, see } else {
// https://bugs.chromium.org/p/skia/issues/detail?id=8779 // Fonts like Apple Color Emoji have no paths, fall back to bounds here.
// OpenTypeVerticalData::GetVerticalTranslationsForGlyphs needs a non-empty font.getBounds(&glyph, 1, bounds, nullptr);
// rectangle for vertical origin computation, hence fall back to bounds here. }
if (UNLIKELY(bounds->isEmpty()))
font.getWidths(&glyph, 1, nullptr, bounds);
#else #else
font.getWidths(&glyph, 1, nullptr, bounds); font.getBounds(&glyph, 1, bounds, nullptr);
#endif #endif
if (!font.isSubpixel()) { if (!font.isSubpixel()) {
...@@ -142,7 +143,7 @@ void SkFontGetBoundsForGlyphs(const SkFont& font, ...@@ -142,7 +143,7 @@ void SkFontGetBoundsForGlyphs(const SkFont& font,
} }
#else #else
static_assert(sizeof(Glyph) == 2, "Skia expects 2 bytes glyph id."); static_assert(sizeof(Glyph) == 2, "Skia expects 2 bytes glyph id.");
font.getWidths(glyphs.data(), glyphs.size(), nullptr, bounds); font.getBounds(glyphs.data(), glyphs.size(), bounds, nullptr);
if (!font.isSubpixel()) { if (!font.isSubpixel()) {
for (unsigned i = 0; i < glyphs.size(); i++) { for (unsigned i = 0; i < glyphs.size(); i++) {
...@@ -156,7 +157,7 @@ void SkFontGetBoundsForGlyphs(const SkFont& font, ...@@ -156,7 +157,7 @@ void SkFontGetBoundsForGlyphs(const SkFont& font,
float SkFontGetWidthForGlyph(const SkFont& font, Glyph glyph) { float SkFontGetWidthForGlyph(const SkFont& font, Glyph glyph) {
SkScalar sk_width; SkScalar sk_width;
font.getWidths(&glyph, 1, &sk_width, nullptr); font.getWidths(&glyph, 1, &sk_width);
if (!font.isSubpixel()) if (!font.isSubpixel())
sk_width = SkScalarRoundToInt(sk_width); sk_width = SkScalarRoundToInt(sk_width);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment