OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "GrPathRendering.h" | 8 #include "GrPathRendering.h" |
9 #include "SkDescriptor.h" | 9 #include "SkDescriptor.h" |
10 #include "SkGlyph.h" | 10 #include "SkGlyph.h" |
11 #include "SkMatrix.h" | 11 #include "SkMatrix.h" |
12 #include "SkTypeface.h" | 12 #include "SkTypeface.h" |
13 #include "GrPathRange.h" | 13 #include "GrPathRange.h" |
14 | 14 |
15 class GlyphGenerator : public GrPathRange::PathGenerator { | 15 class GlyphGenerator : public GrPathRange::PathGenerator { |
16 public: | 16 public: |
17 GlyphGenerator(const SkTypeface& typeface, const SkDescriptor& desc) | 17 GlyphGenerator(const SkTypeface& typeface, const SkDescriptor& desc) |
18 : fScalerContext(typeface.createScalerContext(&desc)) | 18 : fScalerContext(typeface.createScalerContext(&desc)) |
19 #ifdef SK_DEBUG | 19 #ifdef SK_DEBUG |
20 , fDesc(desc.copy()) | 20 , fDesc(desc.copy()) |
21 #endif | 21 #endif |
22 { | 22 {} |
23 fFlipMatrix.setScale(1, -1); | |
24 } | |
25 | 23 |
26 virtual ~GlyphGenerator() { | 24 virtual ~GlyphGenerator() { |
27 #ifdef SK_DEBUG | 25 #ifdef SK_DEBUG |
28 SkDescriptor::Free(fDesc); | 26 SkDescriptor::Free(fDesc); |
29 #endif | 27 #endif |
30 } | 28 } |
31 | 29 |
32 int getNumPaths() override { | 30 int getNumPaths() override { |
33 return fScalerContext->getGlyphCount(); | 31 return fScalerContext->getGlyphCount(); |
34 } | 32 } |
35 | 33 |
36 void generatePath(int glyphID, SkPath* out) override { | 34 void generatePath(int glyphID, SkPath* out) override { |
37 SkGlyph skGlyph; | 35 SkGlyph skGlyph; |
38 skGlyph.initWithGlyphID(glyphID); | 36 skGlyph.initWithGlyphID(glyphID); |
39 fScalerContext->getMetrics(&skGlyph); | 37 fScalerContext->getMetrics(&skGlyph); |
40 | 38 |
41 fScalerContext->getPath(skGlyph, out); | 39 fScalerContext->getPath(skGlyph, out); |
42 out->transform(fFlipMatrix); // Load glyphs with the inverted y-directio
n. | |
43 } | 40 } |
44 #ifdef SK_DEBUG | 41 #ifdef SK_DEBUG |
45 bool isEqualTo(const SkDescriptor& desc) const override { | 42 bool isEqualTo(const SkDescriptor& desc) const override { |
46 return fDesc->equals(desc); | 43 return fDesc->equals(desc); |
47 } | 44 } |
48 #endif | 45 #endif |
49 private: | 46 private: |
50 const SkAutoTDelete<SkScalerContext> fScalerContext; | 47 const SkAutoTDelete<SkScalerContext> fScalerContext; |
51 SkMatrix fFlipMatrix; | |
52 #ifdef SK_DEBUG | 48 #ifdef SK_DEBUG |
53 SkDescriptor* const fDesc; | 49 SkDescriptor* const fDesc; |
54 #endif | 50 #endif |
55 }; | 51 }; |
56 | 52 |
57 GrPathRange* GrPathRendering::createGlyphs(const SkTypeface* typeface, | 53 GrPathRange* GrPathRendering::createGlyphs(const SkTypeface* typeface, |
58 const SkDescriptor* desc, | 54 const SkDescriptor* desc, |
59 const GrStrokeInfo& stroke) { | 55 const GrStrokeInfo& stroke) { |
60 if (nullptr == typeface) { | 56 if (nullptr == typeface) { |
61 typeface = SkTypeface::GetDefaultTypeface(); | 57 typeface = SkTypeface::GetDefaultTypeface(); |
(...skipping 15 matching lines...) Expand all Loading... |
77 SkAutoDescriptor ad(sizeof(rec) + SkDescriptor::ComputeOverhead(1)); | 73 SkAutoDescriptor ad(sizeof(rec) + SkDescriptor::ComputeOverhead(1)); |
78 SkDescriptor* genericDesc = ad.getDesc(); | 74 SkDescriptor* genericDesc = ad.getDesc(); |
79 | 75 |
80 genericDesc->init(); | 76 genericDesc->init(); |
81 genericDesc->addEntry(kRec_SkDescriptorTag, sizeof(rec), &rec); | 77 genericDesc->addEntry(kRec_SkDescriptorTag, sizeof(rec), &rec); |
82 genericDesc->computeChecksum(); | 78 genericDesc->computeChecksum(); |
83 | 79 |
84 SkAutoTUnref<GlyphGenerator> generator(new GlyphGenerator(*typeface, *generi
cDesc)); | 80 SkAutoTUnref<GlyphGenerator> generator(new GlyphGenerator(*typeface, *generi
cDesc)); |
85 return this->createPathRange(generator, stroke); | 81 return this->createPathRange(generator, stroke); |
86 } | 82 } |
OLD | NEW |