Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | # HG changeset patch |
michael@0 | 2 | # User Nicholas Cameron <ncameron@mozilla.com> |
michael@0 | 3 | # Date 1337146927 -43200 |
michael@0 | 4 | # Node ID 310209abef2c2667e5de41dd2a1f071e8cd42821 |
michael@0 | 5 | # Parent 93f3ca4d5707b2aae9c6ae52d5d29c2c802e7ef8 |
michael@0 | 6 | Bug 746883; changes to the Skia library. r=gw280 |
michael@0 | 7 | |
michael@0 | 8 | diff --git a/gfx/skia/include/core/SkDraw.h b/gfx/skia/include/core/SkDraw.h |
michael@0 | 9 | --- a/gfx/skia/include/core/SkDraw.h |
michael@0 | 10 | +++ b/gfx/skia/include/core/SkDraw.h |
michael@0 | 11 | @@ -125,23 +125,24 @@ public: |
michael@0 | 12 | #endif |
michael@0 | 13 | }; |
michael@0 | 14 | |
michael@0 | 15 | class SkGlyphCache; |
michael@0 | 16 | |
michael@0 | 17 | class SkTextToPathIter { |
michael@0 | 18 | public: |
michael@0 | 19 | SkTextToPathIter(const char text[], size_t length, const SkPaint& paint, |
michael@0 | 20 | - bool applyStrokeAndPathEffects); |
michael@0 | 21 | + bool applyStrokeAndPathEffects, bool useCanonicalTextSize = true); |
michael@0 | 22 | ~SkTextToPathIter(); |
michael@0 | 23 | |
michael@0 | 24 | const SkPaint& getPaint() const { return fPaint; } |
michael@0 | 25 | SkScalar getPathScale() const { return fScale; } |
michael@0 | 26 | |
michael@0 | 27 | const SkPath* next(SkScalar* xpos); //!< returns nil when there are no more paths |
michael@0 | 28 | + bool nextWithWhitespace(const SkPath** path, SkScalar* xpos); //!< returns false when there are no more paths |
michael@0 | 29 | |
michael@0 | 30 | private: |
michael@0 | 31 | SkGlyphCache* fCache; |
michael@0 | 32 | SkPaint fPaint; |
michael@0 | 33 | SkScalar fScale; |
michael@0 | 34 | SkFixed fPrevAdvance; |
michael@0 | 35 | const char* fText; |
michael@0 | 36 | const char* fStop; |
michael@0 | 37 | diff --git a/gfx/skia/src/core/SkPaint.cpp b/gfx/skia/src/core/SkPaint.cpp |
michael@0 | 38 | --- a/gfx/skia/src/core/SkPaint.cpp |
michael@0 | 39 | +++ b/gfx/skia/src/core/SkPaint.cpp |
michael@0 | 40 | @@ -1359,30 +1359,32 @@ void SkPaint::getPosTextPath(const void* |
michael@0 | 41 | const SkPoint pos[], SkPath* path) const { |
michael@0 | 42 | SkASSERT(length == 0 || textData != NULL); |
michael@0 | 43 | |
michael@0 | 44 | const char* text = (const char*)textData; |
michael@0 | 45 | if (text == NULL || length == 0 || path == NULL) { |
michael@0 | 46 | return; |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | - SkTextToPathIter iter(text, length, *this, false); |
michael@0 | 50 | + SkTextToPathIter iter(text, length, *this, false, false); |
michael@0 | 51 | SkMatrix matrix; |
michael@0 | 52 | SkPoint prevPos; |
michael@0 | 53 | prevPos.set(0, 0); |
michael@0 | 54 | |
michael@0 | 55 | matrix.setScale(iter.getPathScale(), iter.getPathScale()); |
michael@0 | 56 | path->reset(); |
michael@0 | 57 | |
michael@0 | 58 | unsigned int i = 0; |
michael@0 | 59 | const SkPath* iterPath; |
michael@0 | 60 | - while ((iterPath = iter.next(NULL)) != NULL) { |
michael@0 | 61 | - matrix.postTranslate(pos[i].fX - prevPos.fX, pos[i].fY - prevPos.fY); |
michael@0 | 62 | - path->addPath(*iterPath, matrix); |
michael@0 | 63 | - prevPos = pos[i]; |
michael@0 | 64 | + while (iter.nextWithWhitespace(&iterPath, NULL)) { |
michael@0 | 65 | + if (iterPath) { |
michael@0 | 66 | + matrix.postTranslate(pos[i].fX - prevPos.fX, pos[i].fY - prevPos.fY); |
michael@0 | 67 | + path->addPath(*iterPath, matrix); |
michael@0 | 68 | + prevPos = pos[i]; |
michael@0 | 69 | + } |
michael@0 | 70 | i++; |
michael@0 | 71 | } |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | static void add_flattenable(SkDescriptor* desc, uint32_t tag, |
michael@0 | 75 | SkFlattenableWriteBuffer* buffer) { |
michael@0 | 76 | buffer->flatten(desc->addEntry(tag, buffer->size(), NULL)); |
michael@0 | 77 | } |
michael@0 | 78 | @@ -2118,30 +2120,31 @@ const SkRect& SkPaint::doComputeFastBoun |
michael@0 | 79 | |
michael@0 | 80 | static bool has_thick_frame(const SkPaint& paint) { |
michael@0 | 81 | return paint.getStrokeWidth() > 0 && |
michael@0 | 82 | paint.getStyle() != SkPaint::kFill_Style; |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | SkTextToPathIter::SkTextToPathIter( const char text[], size_t length, |
michael@0 | 86 | const SkPaint& paint, |
michael@0 | 87 | - bool applyStrokeAndPathEffects) |
michael@0 | 88 | + bool applyStrokeAndPathEffects, |
michael@0 | 89 | + bool useCanonicalTextSize) |
michael@0 | 90 | : fPaint(paint) { |
michael@0 | 91 | fGlyphCacheProc = paint.getMeasureCacheProc(SkPaint::kForward_TextBufferDirection, |
michael@0 | 92 | true); |
michael@0 | 93 | |
michael@0 | 94 | fPaint.setLinearText(true); |
michael@0 | 95 | fPaint.setMaskFilter(NULL); // don't want this affecting our path-cache lookup |
michael@0 | 96 | |
michael@0 | 97 | if (fPaint.getPathEffect() == NULL && !has_thick_frame(fPaint)) { |
michael@0 | 98 | applyStrokeAndPathEffects = false; |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | // can't use our canonical size if we need to apply patheffects |
michael@0 | 102 | - if (fPaint.getPathEffect() == NULL) { |
michael@0 | 103 | + if (useCanonicalTextSize && fPaint.getPathEffect() == NULL) { |
michael@0 | 104 | fPaint.setTextSize(SkIntToScalar(SkPaint::kCanonicalTextSizeForPaths)); |
michael@0 | 105 | fScale = paint.getTextSize() / SkPaint::kCanonicalTextSizeForPaths; |
michael@0 | 106 | if (has_thick_frame(fPaint)) { |
michael@0 | 107 | fPaint.setStrokeWidth(SkScalarDiv(fPaint.getStrokeWidth(), fScale)); |
michael@0 | 108 | } |
michael@0 | 109 | } else { |
michael@0 | 110 | fScale = SK_Scalar1; |
michael@0 | 111 | } |
michael@0 | 112 | @@ -2185,30 +2188,47 @@ SkTextToPathIter::SkTextToPathIter( cons |
michael@0 | 113 | fXYIndex = paint.isVerticalText() ? 1 : 0; |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | SkTextToPathIter::~SkTextToPathIter() { |
michael@0 | 117 | SkGlyphCache::AttachCache(fCache); |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | const SkPath* SkTextToPathIter::next(SkScalar* xpos) { |
michael@0 | 121 | - while (fText < fStop) { |
michael@0 | 122 | + const SkPath* result; |
michael@0 | 123 | + while (nextWithWhitespace(&result, xpos)) { |
michael@0 | 124 | + if (result) { |
michael@0 | 125 | + if (xpos) { |
michael@0 | 126 | + *xpos = fXPos; |
michael@0 | 127 | + } |
michael@0 | 128 | + return result; |
michael@0 | 129 | + } |
michael@0 | 130 | + } |
michael@0 | 131 | + return NULL; |
michael@0 | 132 | +} |
michael@0 | 133 | + |
michael@0 | 134 | +bool SkTextToPathIter::nextWithWhitespace(const SkPath** path, SkScalar* xpos) { |
michael@0 | 135 | + if (fText < fStop) { |
michael@0 | 136 | const SkGlyph& glyph = fGlyphCacheProc(fCache, &fText); |
michael@0 | 137 | |
michael@0 | 138 | fXPos += SkScalarMul(SkFixedToScalar(fPrevAdvance + fAutoKern.adjust(glyph)), fScale); |
michael@0 | 139 | fPrevAdvance = advance(glyph, fXYIndex); // + fPaint.getTextTracking(); |
michael@0 | 140 | |
michael@0 | 141 | if (glyph.fWidth) { |
michael@0 | 142 | if (xpos) { |
michael@0 | 143 | *xpos = fXPos; |
michael@0 | 144 | } |
michael@0 | 145 | - return fCache->findPath(glyph); |
michael@0 | 146 | + *path = fCache->findPath(glyph); |
michael@0 | 147 | + return true; |
michael@0 | 148 | + } else { |
michael@0 | 149 | + *path = NULL; |
michael@0 | 150 | + return true; |
michael@0 | 151 | } |
michael@0 | 152 | } |
michael@0 | 153 | - return NULL; |
michael@0 | 154 | + return false; |
michael@0 | 155 | } |
michael@0 | 156 | |
michael@0 | 157 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 158 | |
michael@0 | 159 | bool SkPaint::nothingToDraw() const { |
michael@0 | 160 | if (fLooper) { |
michael@0 | 161 | return false; |
michael@0 | 162 | } |