| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "gm.h" | 8 #include "gm.h" |
| 9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkFontMgr.h" | 10 #include "SkFontMgr.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 fName.set("fontmgr_iter"); | 61 fName.set("fontmgr_iter"); |
| 62 if (fontMgr) { | 62 if (fontMgr) { |
| 63 fName.append("_factory"); | 63 fName.append("_factory"); |
| 64 fFM.reset(fontMgr); | 64 fFM.reset(fontMgr); |
| 65 } else { | 65 } else { |
| 66 fFM.reset(SkFontMgr::RefDefault()); | 66 fFM.reset(SkFontMgr::RefDefault()); |
| 67 } | 67 } |
| 68 } | 68 } |
| 69 | 69 |
| 70 protected: | 70 protected: |
| 71 virtual SkString onShortName() SK_OVERRIDE { | 71 SkString onShortName() SK_OVERRIDE { |
| 72 return fName; | 72 return fName; |
| 73 } | 73 } |
| 74 | 74 |
| 75 virtual SkISize onISize() SK_OVERRIDE { | 75 SkISize onISize() SK_OVERRIDE { |
| 76 return SkISize::Make(1536, 768); | 76 return SkISize::Make(1536, 768); |
| 77 } | 77 } |
| 78 | 78 |
| 79 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 79 void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 80 SkScalar y = 20; | 80 SkScalar y = 20; |
| 81 SkPaint paint; | 81 SkPaint paint; |
| 82 paint.setAntiAlias(true); | 82 paint.setAntiAlias(true); |
| 83 paint.setLCDRenderText(true); | 83 paint.setLCDRenderText(true); |
| 84 paint.setSubpixelText(true); | 84 paint.setSubpixelText(true); |
| 85 paint.setTextSize(17); | 85 paint.setTextSize(17); |
| 86 | 86 |
| 87 SkFontMgr* fm = fFM; | 87 SkFontMgr* fm = fFM; |
| 88 int count = SkMin32(fm->countFamilies(), MAX_FAMILIES); | 88 int count = SkMin32(fm->countFamilies(), MAX_FAMILIES); |
| 89 | 89 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 108 // check to see that we get different glyphs in japanese and chi
nese | 108 // check to see that we get different glyphs in japanese and chi
nese |
| 109 x = drawCharacter(canvas, 0x5203, x, y, paint, fm, fName.c_str()
, &zh, 1, fs); | 109 x = drawCharacter(canvas, 0x5203, x, y, paint, fm, fName.c_str()
, &zh, 1, fs); |
| 110 x = drawCharacter(canvas, 0x5203, x, y, paint, fm, fName.c_str()
, &ja, 1, fs); | 110 x = drawCharacter(canvas, 0x5203, x, y, paint, fm, fName.c_str()
, &ja, 1, fs); |
| 111 // check that emoji characters are found | 111 // check that emoji characters are found |
| 112 x = drawCharacter(canvas, 0x1f601, x, y, paint, fm, fName.c_str(
), NULL, 0, fs); | 112 x = drawCharacter(canvas, 0x1f601, x, y, paint, fm, fName.c_str(
), NULL, 0, fs); |
| 113 } | 113 } |
| 114 y += 24; | 114 y += 24; |
| 115 } | 115 } |
| 116 } | 116 } |
| 117 | 117 |
| 118 virtual uint32_t onGetFlags() const SK_OVERRIDE { | 118 uint32_t onGetFlags() const SK_OVERRIDE { |
| 119 // fontdescriptors (and therefore serialization) don't yet understand | 119 // fontdescriptors (and therefore serialization) don't yet understand |
| 120 // these new styles, so skip tests that exercise that for now. | 120 // these new styles, so skip tests that exercise that for now. |
| 121 | 121 |
| 122 // If certain fonts are picked up (e.g. Microsoft Jhenghei 20MB for Regu
lar, 12MB for Bold), | 122 // If certain fonts are picked up (e.g. Microsoft Jhenghei 20MB for Regu
lar, 12MB for Bold), |
| 123 // the resulting pdf can be ~700MB and crashes Chrome's PDF viewer. | 123 // the resulting pdf can be ~700MB and crashes Chrome's PDF viewer. |
| 124 | 124 |
| 125 return kSkipPicture_Flag | kSkipPipe_Flag | kSkipPDF_Flag; | 125 return kSkipPicture_Flag | kSkipPipe_Flag | kSkipPDF_Flag; |
| 126 } | 126 } |
| 127 | 127 |
| 128 private: | 128 private: |
| 129 SkAutoTUnref<SkFontMgr> fFM; | 129 SkAutoTUnref<SkFontMgr> fFM; |
| 130 SkString fName; | 130 SkString fName; |
| 131 typedef GM INHERITED; | 131 typedef GM INHERITED; |
| 132 }; | 132 }; |
| 133 | 133 |
| 134 class FontMgrMatchGM : public skiagm::GM { | 134 class FontMgrMatchGM : public skiagm::GM { |
| 135 SkAutoTUnref<SkFontMgr> fFM; | 135 SkAutoTUnref<SkFontMgr> fFM; |
| 136 | 136 |
| 137 public: | 137 public: |
| 138 FontMgrMatchGM() : fFM(SkFontMgr::RefDefault()) { | 138 FontMgrMatchGM() : fFM(SkFontMgr::RefDefault()) { |
| 139 SkGraphics::SetFontCacheLimit(16 * 1024 * 1024); | 139 SkGraphics::SetFontCacheLimit(16 * 1024 * 1024); |
| 140 } | 140 } |
| 141 | 141 |
| 142 protected: | 142 protected: |
| 143 virtual SkString onShortName() SK_OVERRIDE { | 143 SkString onShortName() SK_OVERRIDE { |
| 144 return SkString("fontmgr_match"); | 144 return SkString("fontmgr_match"); |
| 145 } | 145 } |
| 146 | 146 |
| 147 virtual SkISize onISize() SK_OVERRIDE { | 147 SkISize onISize() SK_OVERRIDE { |
| 148 return SkISize::Make(640, 1024); | 148 return SkISize::Make(640, 1024); |
| 149 } | 149 } |
| 150 | 150 |
| 151 void iterateFamily(SkCanvas* canvas, const SkPaint& paint, | 151 void iterateFamily(SkCanvas* canvas, const SkPaint& paint, |
| 152 SkFontStyleSet* fset) { | 152 SkFontStyleSet* fset) { |
| 153 SkPaint p(paint); | 153 SkPaint p(paint); |
| 154 SkScalar y = 0; | 154 SkScalar y = 0; |
| 155 | 155 |
| 156 for (int j = 0; j < fset->count(); ++j) { | 156 for (int j = 0; j < fset->count(); ++j) { |
| 157 SkString sname; | 157 SkString sname; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 179 SkString str; | 179 SkString str; |
| 180 str.printf("request [%d %d]", fs.weight(), fs.width()); | 180 str.printf("request [%d %d]", fs.weight(), fs.width()); |
| 181 p.setTypeface(face)->unref(); | 181 p.setTypeface(face)->unref(); |
| 182 (void)drawString(canvas, str, 0, y, p); | 182 (void)drawString(canvas, str, 0, y, p); |
| 183 y += 24; | 183 y += 24; |
| 184 } | 184 } |
| 185 } | 185 } |
| 186 } | 186 } |
| 187 } | 187 } |
| 188 | 188 |
| 189 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 189 void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 190 SkPaint paint; | 190 SkPaint paint; |
| 191 paint.setAntiAlias(true); | 191 paint.setAntiAlias(true); |
| 192 paint.setLCDRenderText(true); | 192 paint.setLCDRenderText(true); |
| 193 paint.setSubpixelText(true); | 193 paint.setSubpixelText(true); |
| 194 paint.setTextSize(17); | 194 paint.setTextSize(17); |
| 195 | 195 |
| 196 static const char* gNames[] = { | 196 static const char* gNames[] = { |
| 197 "Helvetica Neue", "Arial" | 197 "Helvetica Neue", "Arial" |
| 198 }; | 198 }; |
| 199 | 199 |
| 200 SkAutoTUnref<SkFontStyleSet> fset; | 200 SkAutoTUnref<SkFontStyleSet> fset; |
| 201 for (size_t i = 0; i < SK_ARRAY_COUNT(gNames); ++i) { | 201 for (size_t i = 0; i < SK_ARRAY_COUNT(gNames); ++i) { |
| 202 fset.reset(fFM->matchFamily(gNames[i])); | 202 fset.reset(fFM->matchFamily(gNames[i])); |
| 203 if (fset->count() > 0) { | 203 if (fset->count() > 0) { |
| 204 break; | 204 break; |
| 205 } | 205 } |
| 206 } | 206 } |
| 207 if (NULL == fset.get()) { | 207 if (NULL == fset.get()) { |
| 208 return; | 208 return; |
| 209 } | 209 } |
| 210 | 210 |
| 211 canvas->translate(20, 40); | 211 canvas->translate(20, 40); |
| 212 this->exploreFamily(canvas, paint, fset); | 212 this->exploreFamily(canvas, paint, fset); |
| 213 canvas->translate(150, 0); | 213 canvas->translate(150, 0); |
| 214 this->iterateFamily(canvas, paint, fset); | 214 this->iterateFamily(canvas, paint, fset); |
| 215 } | 215 } |
| 216 | 216 |
| 217 virtual uint32_t onGetFlags() const SK_OVERRIDE { | 217 uint32_t onGetFlags() const SK_OVERRIDE { |
| 218 // fontdescriptors (and therefore serialization) don't yet understand | 218 // fontdescriptors (and therefore serialization) don't yet understand |
| 219 // these new styles, so skip tests that exercise that for now. | 219 // these new styles, so skip tests that exercise that for now. |
| 220 return kSkipPicture_Flag | kSkipPipe_Flag; | 220 return kSkipPicture_Flag | kSkipPipe_Flag; |
| 221 } | 221 } |
| 222 | 222 |
| 223 private: | 223 private: |
| 224 typedef GM INHERITED; | 224 typedef GM INHERITED; |
| 225 }; | 225 }; |
| 226 | 226 |
| 227 class FontMgrBoundsGM : public skiagm::GM { | 227 class FontMgrBoundsGM : public skiagm::GM { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 246 } | 246 } |
| 247 | 247 |
| 248 SkRect r = paint.getFontBounds(); | 248 SkRect r = paint.getFontBounds(); |
| 249 r.offset(x, y); | 249 r.offset(x, y); |
| 250 SkPaint p(paint); | 250 SkPaint p(paint); |
| 251 p.setColor(boundsColor); | 251 p.setColor(boundsColor); |
| 252 canvas->drawRect(r, p); | 252 canvas->drawRect(r, p); |
| 253 } | 253 } |
| 254 | 254 |
| 255 protected: | 255 protected: |
| 256 virtual SkString onShortName() SK_OVERRIDE { | 256 SkString onShortName() SK_OVERRIDE { |
| 257 return fName; | 257 return fName; |
| 258 } | 258 } |
| 259 | 259 |
| 260 virtual SkISize onISize() SK_OVERRIDE { | 260 SkISize onISize() SK_OVERRIDE { |
| 261 return SkISize::Make(1024, 850); | 261 return SkISize::Make(1024, 850); |
| 262 } | 262 } |
| 263 | 263 |
| 264 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 264 void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 265 SkPaint paint; | 265 SkPaint paint; |
| 266 paint.setAntiAlias(true); | 266 paint.setAntiAlias(true); |
| 267 paint.setSubpixelText(true); | 267 paint.setSubpixelText(true); |
| 268 paint.setTextSize(100); | 268 paint.setTextSize(100); |
| 269 paint.setStyle(SkPaint::kStroke_Style); | 269 paint.setStyle(SkPaint::kStroke_Style); |
| 270 paint.setTextScaleX(fScaleX); | 270 paint.setTextScaleX(fScaleX); |
| 271 paint.setTextSkewX(fSkewX); | 271 paint.setTextSkewX(fSkewX); |
| 272 | 272 |
| 273 const SkColor boundsColors[2] = { SK_ColorRED, SK_ColorBLUE }; | 273 const SkColor boundsColors[2] = { SK_ColorRED, SK_ColorBLUE }; |
| 274 | 274 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 293 y += 160; | 293 y += 160; |
| 294 } | 294 } |
| 295 if (index >= 30) { | 295 if (index >= 30) { |
| 296 return; | 296 return; |
| 297 } | 297 } |
| 298 } | 298 } |
| 299 } | 299 } |
| 300 } | 300 } |
| 301 } | 301 } |
| 302 | 302 |
| 303 virtual uint32_t onGetFlags() const SK_OVERRIDE { | 303 uint32_t onGetFlags() const SK_OVERRIDE { |
| 304 // fontdescriptors (and therefore serialization) don't yet understand | 304 // fontdescriptors (and therefore serialization) don't yet understand |
| 305 // these new styles, so skip tests that exercise that for now. | 305 // these new styles, so skip tests that exercise that for now. |
| 306 | 306 |
| 307 // If certain fonts are picked up (e.g. Microsoft Jhenghei 20MB for Regu
lar, 12MB for Bold), | 307 // If certain fonts are picked up (e.g. Microsoft Jhenghei 20MB for Regu
lar, 12MB for Bold), |
| 308 // the resulting pdf can be ~700MB and crashes Chrome's PDF viewer. | 308 // the resulting pdf can be ~700MB and crashes Chrome's PDF viewer. |
| 309 | 309 |
| 310 return kSkipPicture_Flag | kSkipPipe_Flag | kSkipPDF_Flag; | 310 return kSkipPicture_Flag | kSkipPipe_Flag | kSkipPDF_Flag; |
| 311 } | 311 } |
| 312 | 312 |
| 313 private: | 313 private: |
| 314 SkAutoTUnref<SkFontMgr> fFM; | 314 SkAutoTUnref<SkFontMgr> fFM; |
| 315 SkString fName; | 315 SkString fName; |
| 316 SkScalar fScaleX, fSkewX; | 316 SkScalar fScaleX, fSkewX; |
| 317 typedef GM INHERITED; | 317 typedef GM INHERITED; |
| 318 }; | 318 }; |
| 319 | 319 |
| 320 ////////////////////////////////////////////////////////////////////////////// | 320 ////////////////////////////////////////////////////////////////////////////// |
| 321 | 321 |
| 322 DEF_GM( return SkNEW(FontMgrGM); ) | 322 DEF_GM( return SkNEW(FontMgrGM); ) |
| 323 DEF_GM( return SkNEW(FontMgrMatchGM); ) | 323 DEF_GM( return SkNEW(FontMgrMatchGM); ) |
| 324 DEF_GM( return SkNEW(FontMgrBoundsGM(1.0, 0)); ) | 324 DEF_GM( return SkNEW(FontMgrBoundsGM(1.0, 0)); ) |
| 325 DEF_GM( return SkNEW(FontMgrBoundsGM(0.75, 0)); ) | 325 DEF_GM( return SkNEW(FontMgrBoundsGM(0.75, 0)); ) |
| 326 DEF_GM( return SkNEW(FontMgrBoundsGM(1.0, -0.25)); ) | 326 DEF_GM( return SkNEW(FontMgrBoundsGM(1.0, -0.25)); ) |
| 327 | 327 |
| 328 #ifdef SK_BUILD_FOR_WIN | 328 #ifdef SK_BUILD_FOR_WIN |
| 329 DEF_GM( return SkNEW_ARGS(FontMgrGM, (SkFontMgr_New_DirectWrite())); ) | 329 DEF_GM( return SkNEW_ARGS(FontMgrGM, (SkFontMgr_New_DirectWrite())); ) |
| 330 #endif | 330 #endif |
| OLD | NEW |