diff options
author | Ben Wagner <bungeman@google.com> | 2018-04-30 15:39:15 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-05-03 01:00:08 +0000 |
commit | 20fa1e94a0847e3db1567d468810f61a1b3dafb9 (patch) | |
tree | d9da3b420bbe00ef0e6839aba8882edacfcc8f62 /tools | |
parent | 0caef298c2ff935b622673e09cd542151dc2ecc0 (diff) |
Update SkRandomScalerContext to handle mask filters.
SkRandomScalarContext would apply all path and mask filters twice, once
on the proxy and once to itself.
This also changes the SkScalerContext mask generation in anticipation of
removing the mask format overrides.
This also changes the textblobrandomfont test to fix the line spacing
and emoji handling.
Change-Id: Ib2a633d49ccb801a1849dd982185f44c1d2ea85f
Reviewed-on: https://skia-review.googlesource.com/124644
Commit-Queue: Ben Wagner <bungeman@google.com>
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/fonts/SkRandomScalerContext.cpp | 160 |
1 files changed, 60 insertions, 100 deletions
diff --git a/tools/fonts/SkRandomScalerContext.cpp b/tools/fonts/SkRandomScalerContext.cpp index feeca48073..2d472129a1 100644 --- a/tools/fonts/SkRandomScalerContext.cpp +++ b/tools/fonts/SkRandomScalerContext.cpp @@ -43,8 +43,10 @@ SkRandomScalerContext::SkRandomScalerContext(sk_sp<SkRandomTypeface> face, const SkDescriptor* desc, bool fakeIt) : SkScalerContext(std::move(face), effects, desc) - , fFakeIt(fakeIt) { - fProxy = this->getRandomTypeface()->proxy()->createScalerContext(effects, desc); + , fProxy(getRandomTypeface()->proxy()->createScalerContext(SkScalerContextEffects(), desc)) + , fFakeIt(fakeIt) +{ + fProxy->forceGenerateImageFromPath(); } unsigned SkRandomScalerContext::generateGlyphCount() { @@ -61,118 +63,77 @@ void SkRandomScalerContext::generateAdvance(SkGlyph* glyph) { void SkRandomScalerContext::generateMetrics(SkGlyph* glyph) { // Here we will change the mask format of the glyph - // NOTE this is being overridden by the base class - SkMask::Format format = SkMask::kARGB32_Format; // init to handle defective compilers + // NOTE: this may be overridden by the base class (e.g. if a mask filter is applied). switch (glyph->getGlyphID() % 4) { - case 0: - format = SkMask::kLCD16_Format; - break; - case 1: - format = SkMask::kA8_Format; - break; - case 2: - format = SkMask::kARGB32_Format; - break; - case 3: - format = SkMask::kBW_Format; - break; + case 0: glyph->fMaskFormat = SkMask::kLCD16_Format; break; + case 1: glyph->fMaskFormat = SkMask::kA8_Format; break; + case 2: glyph->fMaskFormat = SkMask::kARGB32_Format; break; + case 3: glyph->fMaskFormat = SkMask::kBW_Format; break; } fProxy->getMetrics(glyph); - glyph->fMaskFormat = format; - if (fFakeIt) { + if (fFakeIt || (glyph->getGlyphID() % 4) != 2) { return; } - if (SkMask::kARGB32_Format == format) { - SkPath path; - sk_ignore_unused_variable(fProxy->getPath(glyph->getPackedID(), &path)); - - SkRect storage; - const SkPaint& paint = this->getRandomTypeface()->paint(); - const SkRect& newBounds = paint.doComputeFastBounds(path.getBounds(), - &storage, - SkPaint::kFill_Style); - SkIRect ibounds; - newBounds.roundOut(&ibounds); - glyph->fLeft = ibounds.fLeft; - glyph->fTop = ibounds.fTop; - glyph->fWidth = ibounds.width(); - glyph->fHeight = ibounds.height(); - } else { - SkPath devPath; - this->internalGetPath(glyph->getPackedID(), &devPath); - - // just use devPath - const SkIRect ir = devPath.getBounds().roundOut(); - - if (ir.isEmpty() || !SkRectPriv::Is16Bit(ir)) { - glyph->fLeft = 0; - glyph->fTop = 0; - glyph->fWidth = 0; - glyph->fHeight = 0; - return; - } - glyph->fLeft = ir.fLeft; - glyph->fTop = ir.fTop; - glyph->fWidth = SkToU16(ir.width()); - glyph->fHeight = SkToU16(ir.height()); - - if (glyph->fWidth > 0) { - switch (glyph->fMaskFormat) { - case SkMask::kLCD16_Format: - glyph->fWidth += 2; - glyph->fLeft -= 1; - break; - default: - break; - } - } + + SkPath path; + if (!fProxy->getPath(glyph->getPackedID(), &path)) { + return; } + glyph->fMaskFormat = SkMask::kARGB32_Format; + + SkRect storage; + const SkPaint& paint = this->getRandomTypeface()->paint(); + const SkRect& newBounds = paint.doComputeFastBounds(path.getBounds(), + &storage, + SkPaint::kFill_Style); + SkIRect ibounds; + newBounds.roundOut(&ibounds); + glyph->fLeft = ibounds.fLeft; + glyph->fTop = ibounds.fTop; + glyph->fWidth = ibounds.width(); + glyph->fHeight = ibounds.height(); } void SkRandomScalerContext::generateImage(const SkGlyph& glyph) { + // TODO: can force down but not up + /* SkMask::Format format = (SkMask::Format)glyph.fMaskFormat; switch (glyph.getGlyphID() % 4) { - case 0: - format = SkMask::kLCD16_Format; - break; - case 1: - format = SkMask::kA8_Format; - break; - case 2: - format = SkMask::kARGB32_Format; - break; - case 3: - format = SkMask::kBW_Format; - break; + case 0: format = SkMask::kLCD16_Format; break; + case 1: format = SkMask::kA8_Format; break; + case 2: format = SkMask::kARGB32_Format; break; + case 3: format = SkMask::kBW_Format; break; } const_cast<SkGlyph&>(glyph).fMaskFormat = format; + */ - // if the format is ARGB, we just draw the glyph from path ourselves. Otherwise, we force - // our proxy context to generate the image from paths. - if (!fFakeIt) { - if (SkMask::kARGB32_Format == glyph.fMaskFormat) { - SkPath path; - sk_ignore_unused_variable(fProxy->getPath(glyph.getPackedID(), &path)); - - SkBitmap bm; - bm.installPixels(SkImageInfo::MakeN32Premul(glyph.fWidth, glyph.fHeight), - glyph.fImage, glyph.rowBytes()); - bm.eraseColor(0); - - SkCanvas canvas(bm); - canvas.translate(-SkIntToScalar(glyph.fLeft), - -SkIntToScalar(glyph.fTop)); - canvas.drawPath(path, this->getRandomTypeface()->paint()); - } else { - fProxy->forceGenerateImageFromPath(); - fProxy->getImage(glyph); - fProxy->forceOffGenerateImageFromPath(); - } - } else { + if (fFakeIt) { sk_bzero(glyph.fImage, glyph.computeImageSize()); + return; + } + + if (SkMask::kARGB32_Format != glyph.fMaskFormat) { + fProxy->getImage(glyph); + return; + } + + // If the format is ARGB, just draw the glyph from path. + SkPath path; + if (!fProxy->getPath(glyph.getPackedID(), &path)) { + fProxy->getImage(glyph); + return; } + + SkBitmap bm; + bm.installPixels(SkImageInfo::MakeN32Premul(glyph.fWidth, glyph.fHeight), + glyph.fImage, glyph.rowBytes()); + bm.eraseColor(0); + + SkCanvas canvas(bm); + canvas.translate(-SkIntToScalar(glyph.fLeft), -SkIntToScalar(glyph.fTop)); + canvas.drawPath(path, this->getRandomTypeface()->paint()); } bool SkRandomScalerContext::generatePath(SkGlyphID glyph, SkPath* path) { @@ -185,8 +146,6 @@ void SkRandomScalerContext::generateFontMetrics(SkPaint::FontMetrics* metrics) { /////////////////////////////////////////////////////////////////////////////// -#include "SkTypefaceCache.h" - SkRandomTypeface::SkRandomTypeface(sk_sp<SkTypeface> proxy, const SkPaint& paint, bool fakeIt) : SkTypeface(proxy->fontStyle(), false) , fProxy(std::move(proxy)) @@ -213,8 +172,9 @@ SkStreamAsset* SkRandomTypeface::onOpenStream(int* ttcIndex) const { return fProxy->openStream(ttcIndex); } -void SkRandomTypeface::onGetFontDescriptor(SkFontDescriptor* desc, - bool* isLocal) const { +void SkRandomTypeface::onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocal) const { + // TODO: anything that uses this typeface isn't correctly serializable, since this typeface + // cannot be deserialized. fProxy->getFontDescriptor(desc, isLocal); } |