Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(235)

Side by Side Diff: src/fonts/SkGScalerContext.cpp

Issue 14890016: start a wrapper for color fonts (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« src/fonts/SkGScalerContext.h ('K') | « src/fonts/SkGScalerContext.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1
bungeman-skia 2013/05/29 21:21:14 Copyright?
reed1 2013/05/30 16:04:29 Done.
2 #include "SkGScalerContext.h"
3 #include "SkGlyph.h"
4 #include "SkPath.h"
5 #include "SkCanvas.h"
6
7 class SkGScalerContext : public SkScalerContext {
8 public:
9 SkGScalerContext(SkGTypeface*, const SkDescriptor*);
10 virtual ~SkGScalerContext();
11
12 protected:
13 virtual unsigned generateGlyphCount() SK_OVERRIDE;
14 virtual uint16_t generateCharToGlyph(SkUnichar) SK_OVERRIDE;
15 virtual void generateAdvance(SkGlyph*) SK_OVERRIDE;
16 virtual void generateMetrics(SkGlyph*) SK_OVERRIDE;
17 virtual void generateImage(const SkGlyph&) SK_OVERRIDE;
18 virtual void generatePath(const SkGlyph&, SkPath*) SK_OVERRIDE;
19 virtual void generateFontMetrics(SkPaint::FontMetrics* mX,
bungeman-skia 2013/05/29 21:21:14 Fix it with fire!!! (Ok, so that's a different cha
reed1 2013/05/30 16:04:29 Agreed.
20 SkPaint::FontMetrics* mY) SK_OVERRIDE;
21
22 private:
23 SkGTypeface* fFace;
24 SkScalerContext* fProxy;
25 SkMatrix fMatrix;
26 };
27
28 #define STD_SIZE 1
29
30 #include "SkDescriptor.h"
31
32 SkGScalerContext::SkGScalerContext(SkGTypeface* face, const SkDescriptor* desc)
33 : SkScalerContext(face, desc)
34 , fFace(face)
35 {
36
37 size_t descSize = SkDescriptor::ComputeOverhead(1) + sizeof(SkScalerContext ::Rec);
38 SkAutoDescriptor ad(descSize);
39 SkDescriptor* newDesc = ad.getDesc();
40
41 newDesc->init();
42 void* entry = newDesc->addEntry(kRec_SkDescriptorTag,
43 sizeof(SkScalerContext::Rec), &fRec);
44 {
45 SkScalerContext::Rec* rec = (SkScalerContext::Rec*)entry;
46 rec->fTextSize = STD_SIZE;
47 rec->fPreScaleX = SK_Scalar1;
48 rec->fPreSkewX = 0;
49 rec->fPost2x2[0][0] = rec->fPost2x2[1][1] = SK_Scalar1;
50 rec->fPost2x2[1][0] = rec->fPost2x2[0][1] = 0;
51 }
52 SkASSERT(descSize == newDesc->getLength());
53 newDesc->computeChecksum();
54
55 fProxy = face->proxy()->createScalerContext(newDesc);
56
57 fRec.getSingleMatrix(&fMatrix);
58 fMatrix.preScale(SK_Scalar1 / STD_SIZE, SK_Scalar1 / STD_SIZE);
59 }
60
61 SkGScalerContext::~SkGScalerContext() {
62 SkDELETE(fProxy);
63 }
64
65 unsigned SkGScalerContext::generateGlyphCount() {
66 return fProxy->getGlyphCount();
67 }
68
69 uint16_t SkGScalerContext::generateCharToGlyph(SkUnichar uni) {
70 return fProxy->charToGlyphID(uni);
71 }
72
73 void SkGScalerContext::generateAdvance(SkGlyph* glyph) {
74 fProxy->getAdvance(glyph);
75
76 SkVector advance;
77 fMatrix.mapXY(SkFixedToScalar(glyph->fAdvanceX),
78 SkFixedToScalar(glyph->fAdvanceY), &advance);
79 glyph->fAdvanceX = SkScalarToFixed(advance.fX);
80 glyph->fAdvanceY = SkScalarToFixed(advance.fY);
81 }
82
83 void SkGScalerContext::generateMetrics(SkGlyph* glyph) {
84 fProxy->getMetrics(glyph);
85
86 SkVector advance;
87 fMatrix.mapXY(SkFixedToScalar(glyph->fAdvanceX),
88 SkFixedToScalar(glyph->fAdvanceY), &advance);
89 glyph->fAdvanceX = SkScalarToFixed(advance.fX);
90 glyph->fAdvanceY = SkScalarToFixed(advance.fY);
91
92 SkPath path;
93 fProxy->getPath(*glyph, &path);
94 path.transform(fMatrix);
95
96 SkRect storage;
97 const SkPaint& paint = fFace->paint();
98 const SkRect& newBounds = paint.doComputeFastBounds(path.getBounds(),
99 &storage,
100 SkPaint::kFill_Style);
101 SkIRect ibounds;
102 newBounds.roundOut(&ibounds);
103 glyph->fLeft = ibounds.fLeft;
104 glyph->fTop = ibounds.fTop;
105 glyph->fWidth = ibounds.width();
106 glyph->fHeight = ibounds.height();
107 glyph->fMaskFormat = SkMask::kARGB32_Format;
108 }
109
110 void SkGScalerContext::generateImage(const SkGlyph& glyph) {
111 if (SkMask::kARGB32_Format == glyph.fMaskFormat) {
112 SkPath path;
113 fProxy->getPath(glyph, &path);
114
115 SkBitmap bm;
116 bm.setConfig(SkBitmap::kARGB_8888_Config, glyph.fWidth, glyph.fHeight,
117 glyph.rowBytes());
118 bm.setPixels(glyph.fImage);
119 bm.eraseColor(0);
120
121 SkCanvas canvas(bm);
122 canvas.translate(-glyph.fLeft, -glyph.fTop);
123 canvas.concat(fMatrix);
124 canvas.drawPath(path, fFace->paint());
125 } else {
126 fProxy->getImage(glyph);
127 }
128 }
129
130 void SkGScalerContext::generatePath(const SkGlyph& glyph, SkPath* path) {
131 fProxy->getPath(glyph, path);
132 path->transform(fMatrix);
133 }
134
135 void SkGScalerContext::generateFontMetrics(SkPaint::FontMetrics*,
136 SkPaint::FontMetrics* metrics) {
137 fProxy->getFontMetrics(metrics);
138 if (metrics) {
139 SkScalar scale = fMatrix.getScaleY();
140 metrics->fTop = SkScalarMul(metrics->fTop, scale);
141 metrics->fAscent = SkScalarMul(metrics->fAscent, scale);
142 metrics->fDescent = SkScalarMul(metrics->fDescent, scale);
143 metrics->fBottom = SkScalarMul(metrics->fBottom, scale);
144 metrics->fLeading = SkScalarMul(metrics->fLeading, scale);
145 metrics->fAvgCharWidth = SkScalarMul(metrics->fAvgCharWidth, scale);
146 metrics->fXMin = SkScalarMul(metrics->fXMin, scale);
147 metrics->fXMax = SkScalarMul(metrics->fXMax, scale);
148 metrics->fXHeight = SkScalarMul(metrics->fXHeight, scale);
149 }
150 }
151
152 ///////////////////////////////////////////////////////////////////////////////
153
154 #include "SkTypefaceCache.h"
155
156 SkGTypeface::SkGTypeface(SkTypeface* proxy, const SkPaint& paint)
157 : SkTypeface(proxy->style(), SkTypefaceCache::NewFontID(), false)
158 , fProxy(SkRef(proxy))
159 , fPaint(paint) {}
160
161 SkGTypeface::~SkGTypeface() {
162 fProxy->unref();
163 }
164
165 SkScalerContext* SkGTypeface::onCreateScalerContext(
166 const SkDescriptor* desc) const {
167 return SkNEW_ARGS(SkGScalerContext, (const_cast<SkGTypeface*>(this), desc));
168 }
169
170 void SkGTypeface::onFilterRec(SkScalerContextRec* rec) const {
171 fProxy->filterRec(rec);
172 }
173
174 SkAdvancedTypefaceMetrics* SkGTypeface::onGetAdvancedTypefaceMetrics(
175 SkAdvancedTypefaceMetrics::PerGlyphInfo info,
176 const uint32_t* glyphIDs,
177 uint32_t glyphIDsCount) const {
178 return fProxy->getAdvancedTypefaceMetrics(info, glyphIDs, glyphIDsCount);
179 }
180
181 SkStream* SkGTypeface::onOpenStream(int* ttcIndex) const {
182 return fProxy->openStream(ttcIndex);
183 }
184
185 void SkGTypeface::onGetFontDescriptor(SkFontDescriptor* desc,
186 bool* isLocal) const {
187 fProxy->getFontDescriptor(desc, isLocal);
188 }
189
190 int SkGTypeface::onGetUPEM() const {
191 return fProxy->getUnitsPerEm();
192 }
193
194 int SkGTypeface::onGetTableTags(SkFontTableTag tags[]) const {
195 return fProxy->getTableTags(tags);
196 }
197
198 size_t SkGTypeface::onGetTableData(SkFontTableTag tag, size_t offset,
199 size_t length, void* data) const {
200 return fProxy->getTableData(tag, offset, length, data);
201 }
202
203 ///////////////////////////////////////////////////////////////////////////////
204
205 #if 0
206 class SkGFont : public SkRefCnt {
bungeman-skia 2013/05/29 21:21:14 I suppose this is still under construction, but wh
reed1 2013/05/30 16:04:29 Added comment. I *think* one would construct a Sk
207 public:
208 virtual ~SkGFont();
209
210 int unicharToGlyph(SkUnichar) const;
211
212 int countGlyphs() const { return fCount; }
213
214 float getAdvance(int index) const {
215 SkASSERT((unsigned)index < (unsigned)fCount);
216 return fGlyphs[index].fAdvance;
217 }
218
219 const SkPath& getPath(int index) const {
220 SkASSERT((unsigned)index < (unsigned)fCount);
221 return fGlyphs[index].fPath;
222 }
223
224 private:
225 struct Glyph {
226 SkUnichar fUni;
227 float fAdvance;
228 SkPath fPath;
229 };
230 int fCount;
231 Glyph* fGlyphs;
232
233 friend class SkGFontBuilder;
234 SkGFont(int count, Glyph* array);
235 };
236
237 class SkGFontBuilder {
238 public:
239
240 };
241 #endif
OLDNEW
« src/fonts/SkGScalerContext.h ('K') | « src/fonts/SkGScalerContext.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698