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

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

Issue 1259033004: Revert of adding gm to use random scaler context (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 4 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
« no previous file with comments | « gm/textblobrandomfont.cpp ('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
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 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 "SkRandomScalerContext.h" 8 #include "SkRandomScalerContext.h"
9 #include "SkGlyph.h" 9 #include "SkGlyph.h"
10 #include "SkPath.h" 10 #include "SkPath.h"
(...skipping 10 matching lines...) Expand all
21 uint16_t generateCharToGlyph(SkUnichar) override; 21 uint16_t generateCharToGlyph(SkUnichar) override;
22 void generateAdvance(SkGlyph*) override; 22 void generateAdvance(SkGlyph*) override;
23 void generateMetrics(SkGlyph*) override; 23 void generateMetrics(SkGlyph*) override;
24 void generateImage(const SkGlyph&) override; 24 void generateImage(const SkGlyph&) override;
25 void generatePath(const SkGlyph&, SkPath*) override; 25 void generatePath(const SkGlyph&, SkPath*) override;
26 void generateFontMetrics(SkPaint::FontMetrics*) override; 26 void generateFontMetrics(SkPaint::FontMetrics*) override;
27 27
28 private: 28 private:
29 SkRandomTypeface* fFace; 29 SkRandomTypeface* fFace;
30 SkScalerContext* fProxy; 30 SkScalerContext* fProxy;
31 SkMatrix fMatrix;
31 bool fFakeIt; 32 bool fFakeIt;
32 }; 33 };
33 34
34 #define STD_SIZE 1 35 #define STD_SIZE 1
35 36
36 #include "SkDescriptor.h" 37 #include "SkDescriptor.h"
37 38
38 SkRandomScalerContext::SkRandomScalerContext(SkRandomTypeface* face, const SkDes criptor* desc, 39 SkRandomScalerContext::SkRandomScalerContext(SkRandomTypeface* face, const SkDes criptor* desc,
39 bool fakeIt) 40 bool fakeIt)
40 : SkScalerContext(face, desc) 41 : SkScalerContext(face, desc)
41 , fFace(face) 42 , fFace(face)
42 , fFakeIt(fakeIt) { 43 , fFakeIt(fakeIt) {
43 fProxy = face->proxy()->createScalerContext(desc); 44 size_t descSize = SkDescriptor::ComputeOverhead(1) + sizeof(SkScalerContext ::Rec);
45 SkAutoDescriptor ad(descSize);
46 SkDescriptor* newDesc = ad.getDesc();
47
48 newDesc->init();
49 void* entry = newDesc->addEntry(kRec_SkDescriptorTag,
50 sizeof(SkScalerContext::Rec), &fRec);
51 {
52 SkScalerContext::Rec* rec = (SkScalerContext::Rec*)entry;
53 rec->fTextSize = STD_SIZE;
54 rec->fPreScaleX = SK_Scalar1;
55 rec->fPreSkewX = 0;
56 rec->fPost2x2[0][0] = rec->fPost2x2[1][1] = SK_Scalar1;
57 rec->fPost2x2[1][0] = rec->fPost2x2[0][1] = 0;
58 }
59 SkASSERT(descSize == newDesc->getLength());
60 newDesc->computeChecksum();
61
62 fProxy = face->proxy()->createScalerContext(newDesc);
63
64 fRec.getSingleMatrix(&fMatrix);
65 fMatrix.preScale(SK_Scalar1 / STD_SIZE, SK_Scalar1 / STD_SIZE);
44 } 66 }
45 67
46 SkRandomScalerContext::~SkRandomScalerContext() { 68 SkRandomScalerContext::~SkRandomScalerContext() {
47 SkDELETE(fProxy); 69 SkDELETE(fProxy);
48 } 70 }
49 71
50 unsigned SkRandomScalerContext::generateGlyphCount() { 72 unsigned SkRandomScalerContext::generateGlyphCount() {
51 return fProxy->getGlyphCount(); 73 return fProxy->getGlyphCount();
52 } 74 }
53 75
54 uint16_t SkRandomScalerContext::generateCharToGlyph(SkUnichar uni) { 76 uint16_t SkRandomScalerContext::generateCharToGlyph(SkUnichar uni) {
55 return fProxy->charToGlyphID(uni); 77 return fProxy->charToGlyphID(uni);
56 } 78 }
57 79
58 void SkRandomScalerContext::generateAdvance(SkGlyph* glyph) { 80 void SkRandomScalerContext::generateAdvance(SkGlyph* glyph) {
59 fProxy->getAdvance(glyph); 81 fProxy->getAdvance(glyph);
82
83 SkVector advance;
84 fMatrix.mapXY(SkFixedToScalar(glyph->fAdvanceX),
85 SkFixedToScalar(glyph->fAdvanceY), &advance);
86 glyph->fAdvanceX = SkScalarToFixed(advance.fX);
87 glyph->fAdvanceY = SkScalarToFixed(advance.fY);
60 } 88 }
61 89
62 void SkRandomScalerContext::generateMetrics(SkGlyph* glyph) { 90 void SkRandomScalerContext::generateMetrics(SkGlyph* glyph) {
63 // Here we will change the mask format of the glyph 91 // Here we will change the mask format of the glyph
64 // NOTE this is being overridden by the base class 92 // NOTE this is being overridden by the base class
65 SkMask::Format format; 93 SkMask::Format format;
66 switch (glyph->getGlyphID() % 3) { 94 switch (glyph->getGlyphID() % 3) {
67 case 0: 95 case 0:
68 format = SkMask::kLCD16_Format; 96 format = SkMask::kLCD16_Format;
69 break; 97 break;
70 case 1: 98 case 1:
71 format = SkMask::kA8_Format; 99 format = SkMask::kA8_Format;
72 break; 100 break;
73 case 2: 101 case 2:
74 format = SkMask::kARGB32_Format; 102 format = SkMask::kARGB32_Format;
75 break; 103 break;
76 } 104 }
77 105
78 fProxy->getMetrics(glyph); 106 fProxy->getMetrics(glyph);
79 107
80 glyph->fMaskFormat = format; 108 glyph->fMaskFormat = format;
81 if (fFakeIt) { 109 if (fFakeIt) {
82 return; 110 return;
83 } 111 }
84 if (SkMask::kARGB32_Format == format) { 112 if (SkMask::kARGB32_Format == format) {
113 SkVector advance;
114 fMatrix.mapXY(SkFixedToScalar(glyph->fAdvanceX),
115 SkFixedToScalar(glyph->fAdvanceY), &advance);
116 glyph->fAdvanceX = SkScalarToFixed(advance.fX);
117 glyph->fAdvanceY = SkScalarToFixed(advance.fY);
118
85 SkPath path; 119 SkPath path;
86 fProxy->getPath(*glyph, &path); 120 fProxy->getPath(*glyph, &path);
121 path.transform(fMatrix);
87 122
88 SkRect storage; 123 SkRect storage;
89 const SkPaint& paint = fFace->paint(); 124 const SkPaint& paint = fFace->paint();
90 const SkRect& newBounds = paint.doComputeFastBounds(path.getBounds(), 125 const SkRect& newBounds = paint.doComputeFastBounds(path.getBounds(),
91 &storage, 126 &storage,
92 SkPaint::kFill_Style ); 127 SkPaint::kFill_Style );
93 SkIRect ibounds; 128 SkIRect ibounds;
94 newBounds.roundOut(&ibounds); 129 newBounds.roundOut(&ibounds);
95 glyph->fLeft = ibounds.fLeft; 130 glyph->fLeft = ibounds.fLeft;
96 glyph->fTop = ibounds.fTop; 131 glyph->fTop = ibounds.fTop;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 fProxy->getPath(glyph, &path); 188 fProxy->getPath(glyph, &path);
154 189
155 SkBitmap bm; 190 SkBitmap bm;
156 bm.installPixels(SkImageInfo::MakeN32Premul(glyph.fWidth, glyph.fHei ght), 191 bm.installPixels(SkImageInfo::MakeN32Premul(glyph.fWidth, glyph.fHei ght),
157 glyph.fImage, glyph.rowBytes()); 192 glyph.fImage, glyph.rowBytes());
158 bm.eraseColor(0); 193 bm.eraseColor(0);
159 194
160 SkCanvas canvas(bm); 195 SkCanvas canvas(bm);
161 canvas.translate(-SkIntToScalar(glyph.fLeft), 196 canvas.translate(-SkIntToScalar(glyph.fLeft),
162 -SkIntToScalar(glyph.fTop)); 197 -SkIntToScalar(glyph.fTop));
198 canvas.concat(fMatrix);
163 canvas.drawPath(path, fFace->paint()); 199 canvas.drawPath(path, fFace->paint());
164 } else { 200 } else {
165 fProxy->forceGenerateImageFromPath(); 201 fProxy->forceGenerateImageFromPath();
166 fProxy->getImage(glyph); 202 fProxy->getImage(glyph);
167 fProxy->forceOffGenerateImageFromPath(); 203 fProxy->forceOffGenerateImageFromPath();
168 } 204 }
169 } else { 205 } else {
170 sk_bzero(glyph.fImage, glyph.computeImageSize()); 206 sk_bzero(glyph.fImage, glyph.computeImageSize());
171 } 207 }
172 } 208 }
173 209
174 void SkRandomScalerContext::generatePath(const SkGlyph& glyph, SkPath* path) { 210 void SkRandomScalerContext::generatePath(const SkGlyph& glyph, SkPath* path) {
175 fProxy->getPath(glyph, path); 211 fProxy->getPath(glyph, path);
212 path->transform(fMatrix);
176 } 213 }
177 214
178 void SkRandomScalerContext::generateFontMetrics(SkPaint::FontMetrics* metrics) { 215 void SkRandomScalerContext::generateFontMetrics(SkPaint::FontMetrics* metrics) {
179 fProxy->getFontMetrics(metrics); 216 fProxy->getFontMetrics(metrics);
217 if (metrics) {
218 SkScalar scale = fMatrix.getScaleY();
219 metrics->fTop = SkScalarMul(metrics->fTop, scale);
220 metrics->fAscent = SkScalarMul(metrics->fAscent, scale);
221 metrics->fDescent = SkScalarMul(metrics->fDescent, scale);
222 metrics->fBottom = SkScalarMul(metrics->fBottom, scale);
223 metrics->fLeading = SkScalarMul(metrics->fLeading, scale);
224 metrics->fAvgCharWidth = SkScalarMul(metrics->fAvgCharWidth, scale);
225 metrics->fXMin = SkScalarMul(metrics->fXMin, scale);
226 metrics->fXMax = SkScalarMul(metrics->fXMax, scale);
227 metrics->fXHeight = SkScalarMul(metrics->fXHeight, scale);
228 }
180 } 229 }
181 230
182 /////////////////////////////////////////////////////////////////////////////// 231 ///////////////////////////////////////////////////////////////////////////////
183 232
184 #include "SkTypefaceCache.h" 233 #include "SkTypefaceCache.h"
185 234
186 SkRandomTypeface::SkRandomTypeface(SkTypeface* proxy, const SkPaint& paint, bool fakeIt) 235 SkRandomTypeface::SkRandomTypeface(SkTypeface* proxy, const SkPaint& paint, bool fakeIt)
187 : SkTypeface(proxy->fontStyle(), SkTypefaceCache::NewFontID(), false) 236 : SkTypeface(proxy->fontStyle(), SkTypefaceCache::NewFontID(), false)
188 , fProxy(SkRef(proxy)) 237 , fProxy(SkRef(proxy))
189 , fPaint(paint) 238 , fPaint(paint)
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 292
244 int SkRandomTypeface::onGetTableTags(SkFontTableTag tags[]) const { 293 int SkRandomTypeface::onGetTableTags(SkFontTableTag tags[]) const {
245 return fProxy->getTableTags(tags); 294 return fProxy->getTableTags(tags);
246 } 295 }
247 296
248 size_t SkRandomTypeface::onGetTableData(SkFontTableTag tag, size_t offset, 297 size_t SkRandomTypeface::onGetTableData(SkFontTableTag tag, size_t offset,
249 size_t length, void* data) const { 298 size_t length, void* data) const {
250 return fProxy->getTableData(tag, offset, length, data); 299 return fProxy->getTableData(tag, offset, length, data);
251 } 300 }
252 301
OLDNEW
« no previous file with comments | « gm/textblobrandomfont.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698