Index: src/core/SkTextBlob.cpp |
diff --git a/src/core/SkTextBlob.cpp b/src/core/SkTextBlob.cpp |
index 3ffc41e9ba6677b5eb1904da834a4281b26800f4..db233dd8dd0fc1a4c546ab28c1a1e665bc616c28 100644 |
--- a/src/core/SkTextBlob.cpp |
+++ b/src/core/SkTextBlob.cpp |
@@ -11,6 +11,68 @@ |
#include "SkTypeface.h" |
#include "SkWriteBuffer.h" |
+namespace { |
+ |
+// TODO(fmalita): replace with SkFont. |
+class RunFont { |
mtklein
2015/04/08 21:42:18
better : SkNoncopyable this.
f(malita)
2015/04/09 01:08:22
Aww, but that adds 8 bytes to the size (wiping out
|
+public: |
+ RunFont(const SkPaint& paint) |
+ : fTypeface(SkSafeRef(paint.getTypeface())) |
+ , fSize(paint.getTextSize()) |
+ , fScaleX(paint.getTextScaleX()) |
+ , fSkewX(paint.getTextSkewX()) |
+ , fHinting(paint.getHinting()) |
+ , fFlags(paint.getFlags() & kFlagsMask) { } |
+ |
+ void applyToPaint(SkPaint* paint) const { |
+ paint->setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
+ paint->setTypeface(fTypeface.get()); |
+ paint->setTextSize(fSize); |
+ paint->setTextScaleX(fScaleX); |
+ paint->setTextSkewX(fSkewX); |
+ paint->setHinting(fHinting); |
+ |
+ paint->setFlags((paint->getFlags() & ~kFlagsMask) | fFlags); |
+ } |
+ |
+ bool operator==(const RunFont& other) const { |
+ return fTypeface == other.fTypeface |
+ && fSize == other.fSize |
+ && fScaleX == other.fScaleX |
+ && fSkewX == other.fSkewX |
+ && fHinting == other.fHinting |
+ && fFlags == other.fFlags; |
+ } |
+ |
+ bool operator!=(const RunFont& other) const { |
+ return !(*this == other); |
+ } |
+private: |
+ const static uint32_t kFlagsMask = |
+ SkPaint::kAntiAlias_Flag | |
+ SkPaint::kUnderlineText_Flag | |
+ SkPaint::kStrikeThruText_Flag | |
+ SkPaint::kFakeBoldText_Flag | |
+ SkPaint::kLinearText_Flag | |
+ SkPaint::kSubpixelText_Flag | |
+ SkPaint::kDevKernText_Flag | |
+ SkPaint::kLCDRenderText_Flag | |
+ SkPaint::kEmbeddedBitmapText_Flag | |
+ SkPaint::kAutoHinting_Flag | |
+ SkPaint::kVerticalText_Flag | |
+ SkPaint::kGenA8FromLCD_Flag | |
+ SkPaint::kDistanceFieldTextTEMP_Flag; |
+ |
+ SkAutoTUnref<SkTypeface> fTypeface; |
+ SkScalar fSize; |
+ SkScalar fScaleX; |
+ SkScalar fSkewX; |
+ SkPaint::Hinting fHinting; |
+ uint32_t fFlags; |
mtklein
2015/04/08 21:42:18
Do we have two free bits in fFlags to store the Sk
f(malita)
2015/04/09 01:08:22
Yup, looks like SkPaint's flags fit in 16 bits jus
|
+}; |
+ |
+} // anonymous namespace |
+ |
// |
// Textblob data is laid out into externally-managed storage as follows: |
// |
@@ -41,7 +103,7 @@ public: |
return fOffset; |
} |
- const SkPaint& font() const { |
+ const RunFont& font() const { |
return fFont; |
} |
@@ -102,7 +164,7 @@ private: |
uint32_t fCount; |
SkPoint fOffset; |
- SkPaint fFont; |
+ RunFont fFont; |
GlyphPositioning fPositioning; |
SkDEBUGCODE(unsigned fMagic;) |
@@ -262,29 +324,7 @@ SkTextBlob::GlyphPositioning SkTextBlob::RunIterator::positioning() const { |
void SkTextBlob::RunIterator::applyFontToPaint(SkPaint* paint) const { |
SkASSERT(!this->done()); |
- const SkPaint& font = fCurrentRun->font(); |
- |
- paint->setTypeface(font.getTypeface()); |
- paint->setTextEncoding(font.getTextEncoding()); |
- paint->setTextSize(font.getTextSize()); |
- paint->setTextScaleX(font.getTextScaleX()); |
- paint->setTextSkewX(font.getTextSkewX()); |
- paint->setHinting(font.getHinting()); |
- |
- uint32_t flagsMask = SkPaint::kAntiAlias_Flag |
- | SkPaint::kUnderlineText_Flag |
- | SkPaint::kStrikeThruText_Flag |
- | SkPaint::kFakeBoldText_Flag |
- | SkPaint::kLinearText_Flag |
- | SkPaint::kSubpixelText_Flag |
- | SkPaint::kDevKernText_Flag |
- | SkPaint::kLCDRenderText_Flag |
- | SkPaint::kEmbeddedBitmapText_Flag |
- | SkPaint::kAutoHinting_Flag |
- | SkPaint::kVerticalText_Flag |
- | SkPaint::kGenA8FromLCD_Flag |
- | SkPaint::kDistanceFieldTextTEMP_Flag; |
- paint->setFlags((paint->getFlags() & ~flagsMask) | (font.getFlags() & flagsMask)); |
+ fCurrentRun->font().applyToPaint(paint); |
} |
SkTextBlobBuilder::SkTextBlobBuilder() |
@@ -308,7 +348,9 @@ SkRect SkTextBlobBuilder::TightRunBounds(const SkTextBlob::RunRecord& run) { |
SkASSERT(SkTextBlob::kDefault_Positioning == run.positioning()); |
SkRect bounds; |
- run.font().measureText(run.glyphBuffer(), run.glyphCount() * sizeof(uint16_t), &bounds); |
+ SkPaint paint; |
+ run.font().applyToPaint(&paint); |
+ paint.measureText(run.glyphBuffer(), run.glyphCount() * sizeof(uint16_t), &bounds); |
return bounds.makeOffset(run.offset().x(), run.offset().y()); |
} |
@@ -346,7 +388,9 @@ SkRect SkTextBlobBuilder::ConservativeRunBounds(const SkTextBlob::RunRecord& run |
} |
// Expand by typeface glyph bounds. |
- const SkRect fontBounds = run.font().getFontBounds(); |
+ SkPaint paint; |
+ run.font().applyToPaint(&paint); |
+ const SkRect fontBounds = paint.getFontBounds(); |
bounds.fLeft += fontBounds.left(); |
bounds.fTop += fontBounds.top(); |
bounds.fRight += fontBounds.right(); |
@@ -366,7 +410,6 @@ void SkTextBlobBuilder::updateDeferredBounds() { |
SkASSERT(fLastRun >= sizeof(SkTextBlob)); |
SkTextBlob::RunRecord* run = reinterpret_cast<SkTextBlob::RunRecord*>(fStorage.get() + |
fLastRun); |
- SkASSERT(SkPaint::kGlyphID_TextEncoding == run->font().getTextEncoding()); |
// FIXME: we should also use conservative bounds for kDefault_Positioning. |
SkRect runBounds = SkTextBlob::kDefault_Positioning == run->positioning() ? |