OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "SkAdvancedTypefaceMetrics.h" | 9 #include "SkAdvancedTypefaceMetrics.h" |
10 #include "SkBase64.h" | 10 #include "SkBase64.h" |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 | 247 |
248 static LogFontTypeface* Create(const LOGFONT& lf) { | 248 static LogFontTypeface* Create(const LOGFONT& lf) { |
249 return new LogFontTypeface(get_style(lf), lf, false); | 249 return new LogFontTypeface(get_style(lf), lf, false); |
250 } | 250 } |
251 | 251 |
252 static void EnsureAccessible(const SkTypeface* face) { | 252 static void EnsureAccessible(const SkTypeface* face) { |
253 call_ensure_accessible(static_cast<const LogFontTypeface*>(face)->fLogFo
nt); | 253 call_ensure_accessible(static_cast<const LogFontTypeface*>(face)->fLogFo
nt); |
254 } | 254 } |
255 | 255 |
256 protected: | 256 protected: |
257 SkStreamAsset* onOpenStream(int* ttcIndex) const SK_OVERRIDE; | 257 SkStreamAsset* onOpenStream(int* ttcIndex) const override; |
258 SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK_OVERRID
E; | 258 SkScalerContext* onCreateScalerContext(const SkDescriptor*) const override; |
259 void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE; | 259 void onFilterRec(SkScalerContextRec*) const override; |
260 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( | 260 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( |
261 SkAdvancedTypefaceMetrics::PerGlyphInfo, | 261 SkAdvancedTypefaceMetrics::PerGlyphInfo, |
262 const uint32_t*, uint32_t) const SK_OVERRIDE; | 262 const uint32_t*, uint32_t) const override; |
263 void onGetFontDescriptor(SkFontDescriptor*, bool*) const SK_OVERRIDE; | 263 void onGetFontDescriptor(SkFontDescriptor*, bool*) const override; |
264 virtual int onCharsToGlyphs(const void* chars, Encoding encoding, | 264 virtual int onCharsToGlyphs(const void* chars, Encoding encoding, |
265 uint16_t glyphs[], int glyphCount) const SK_OVER
RIDE; | 265 uint16_t glyphs[], int glyphCount) const overrid
e; |
266 int onCountGlyphs() const SK_OVERRIDE; | 266 int onCountGlyphs() const override; |
267 int onGetUPEM() const SK_OVERRIDE; | 267 int onGetUPEM() const override; |
268 void onGetFamilyName(SkString* familyName) const SK_OVERRIDE; | 268 void onGetFamilyName(SkString* familyName) const override; |
269 SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const SK_OVERRIDE
; | 269 SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override; |
270 int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE; | 270 int onGetTableTags(SkFontTableTag tags[]) const override; |
271 virtual size_t onGetTableData(SkFontTableTag, size_t offset, | 271 virtual size_t onGetTableData(SkFontTableTag, size_t offset, |
272 size_t length, void* data) const SK_OVERRIDE; | 272 size_t length, void* data) const override; |
273 }; | 273 }; |
274 | 274 |
275 class FontMemResourceTypeface : public LogFontTypeface { | 275 class FontMemResourceTypeface : public LogFontTypeface { |
276 public: | 276 public: |
277 /** | 277 /** |
278 * The created FontMemResourceTypeface takes ownership of fontMemResource. | 278 * The created FontMemResourceTypeface takes ownership of fontMemResource. |
279 */ | 279 */ |
280 static FontMemResourceTypeface* Create(const LOGFONT& lf, HANDLE fontMemReso
urce) { | 280 static FontMemResourceTypeface* Create(const LOGFONT& lf, HANDLE fontMemReso
urce) { |
281 return new FontMemResourceTypeface(get_style(lf), lf, fontMemResource); | 281 return new FontMemResourceTypeface(get_style(lf), lf, fontMemResource); |
282 } | 282 } |
283 | 283 |
284 protected: | 284 protected: |
285 void weak_dispose() const SK_OVERRIDE { | 285 void weak_dispose() const override { |
286 RemoveFontMemResourceEx(fFontMemResource); | 286 RemoveFontMemResourceEx(fFontMemResource); |
287 //SkTypefaceCache::Remove(this); | 287 //SkTypefaceCache::Remove(this); |
288 INHERITED::weak_dispose(); | 288 INHERITED::weak_dispose(); |
289 } | 289 } |
290 | 290 |
291 private: | 291 private: |
292 /** | 292 /** |
293 * Takes ownership of fontMemResource. | 293 * Takes ownership of fontMemResource. |
294 */ | 294 */ |
295 FontMemResourceTypeface(const SkFontStyle& style, const LOGFONT& lf, HANDLE
fontMemResource) | 295 FontMemResourceTypeface(const SkFontStyle& style, const LOGFONT& lf, HANDLE
fontMemResource) |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 class SkScalerContext_GDI : public SkScalerContext { | 533 class SkScalerContext_GDI : public SkScalerContext { |
534 public: | 534 public: |
535 SkScalerContext_GDI(SkTypeface*, const SkDescriptor* desc); | 535 SkScalerContext_GDI(SkTypeface*, const SkDescriptor* desc); |
536 virtual ~SkScalerContext_GDI(); | 536 virtual ~SkScalerContext_GDI(); |
537 | 537 |
538 // Returns true if the constructor was able to complete all of its | 538 // Returns true if the constructor was able to complete all of its |
539 // initializations (which may include calling GDI). | 539 // initializations (which may include calling GDI). |
540 bool isValid() const; | 540 bool isValid() const; |
541 | 541 |
542 protected: | 542 protected: |
543 unsigned generateGlyphCount() SK_OVERRIDE; | 543 unsigned generateGlyphCount() override; |
544 uint16_t generateCharToGlyph(SkUnichar uni) SK_OVERRIDE; | 544 uint16_t generateCharToGlyph(SkUnichar uni) override; |
545 void generateAdvance(SkGlyph* glyph) SK_OVERRIDE; | 545 void generateAdvance(SkGlyph* glyph) override; |
546 void generateMetrics(SkGlyph* glyph) SK_OVERRIDE; | 546 void generateMetrics(SkGlyph* glyph) override; |
547 void generateImage(const SkGlyph& glyph) SK_OVERRIDE; | 547 void generateImage(const SkGlyph& glyph) override; |
548 void generatePath(const SkGlyph& glyph, SkPath* path) SK_OVERRIDE; | 548 void generatePath(const SkGlyph& glyph, SkPath* path) override; |
549 void generateFontMetrics(SkPaint::FontMetrics*) SK_OVERRIDE; | 549 void generateFontMetrics(SkPaint::FontMetrics*) override; |
550 | 550 |
551 private: | 551 private: |
552 DWORD getGDIGlyphPath(const SkGlyph& glyph, UINT flags, | 552 DWORD getGDIGlyphPath(const SkGlyph& glyph, UINT flags, |
553 SkAutoSTMalloc<BUFFERSIZE, uint8_t>* glyphbuf); | 553 SkAutoSTMalloc<BUFFERSIZE, uint8_t>* glyphbuf); |
554 | 554 |
555 HDCOffscreen fOffscreen; | 555 HDCOffscreen fOffscreen; |
556 /** fGsA is the non-rotational part of total matrix without the text height
scale. | 556 /** fGsA is the non-rotational part of total matrix without the text height
scale. |
557 * Used to find the magnitude of advances. | 557 * Used to find the magnitude of advances. |
558 */ | 558 */ |
559 MAT2 fGsA; | 559 MAT2 fGsA; |
(...skipping 1834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2394 LOGFONT lf; | 2394 LOGFONT lf; |
2395 sk_bzero(&lf, sizeof(lf)); | 2395 sk_bzero(&lf, sizeof(lf)); |
2396 lf.lfCharSet = DEFAULT_CHARSET; | 2396 lf.lfCharSet = DEFAULT_CHARSET; |
2397 _tcscpy_s(lf.lfFaceName, familyName); | 2397 _tcscpy_s(lf.lfFaceName, familyName); |
2398 | 2398 |
2399 HDC hdc = ::CreateCompatibleDC(NULL); | 2399 HDC hdc = ::CreateCompatibleDC(NULL); |
2400 ::EnumFontFamiliesEx(hdc, &lf, enum_family_proc, (LPARAM)&fArray, 0); | 2400 ::EnumFontFamiliesEx(hdc, &lf, enum_family_proc, (LPARAM)&fArray, 0); |
2401 ::DeleteDC(hdc); | 2401 ::DeleteDC(hdc); |
2402 } | 2402 } |
2403 | 2403 |
2404 int count() SK_OVERRIDE { | 2404 int count() override { |
2405 return fArray.count(); | 2405 return fArray.count(); |
2406 } | 2406 } |
2407 | 2407 |
2408 void getStyle(int index, SkFontStyle* fs, SkString* styleName) SK_OVERRIDE { | 2408 void getStyle(int index, SkFontStyle* fs, SkString* styleName) override { |
2409 if (fs) { | 2409 if (fs) { |
2410 *fs = get_style(fArray[index].elfLogFont); | 2410 *fs = get_style(fArray[index].elfLogFont); |
2411 } | 2411 } |
2412 if (styleName) { | 2412 if (styleName) { |
2413 const ENUMLOGFONTEX& ref = fArray[index]; | 2413 const ENUMLOGFONTEX& ref = fArray[index]; |
2414 // For some reason, ENUMLOGFONTEX and LOGFONT disagree on their type
in the | 2414 // For some reason, ENUMLOGFONTEX and LOGFONT disagree on their type
in the |
2415 // non-unicode version. | 2415 // non-unicode version. |
2416 // ENUMLOGFONTEX uses BYTE | 2416 // ENUMLOGFONTEX uses BYTE |
2417 // LOGFONT uses CHAR | 2417 // LOGFONT uses CHAR |
2418 // Here we assert they that the style name is logically the same (si
ze) as | 2418 // Here we assert they that the style name is logically the same (si
ze) as |
2419 // a TCHAR, so we can use the same converter function. | 2419 // a TCHAR, so we can use the same converter function. |
2420 SkASSERT(sizeof(TCHAR) == sizeof(ref.elfStyle[0])); | 2420 SkASSERT(sizeof(TCHAR) == sizeof(ref.elfStyle[0])); |
2421 tchar_to_skstring((const TCHAR*)ref.elfStyle, styleName); | 2421 tchar_to_skstring((const TCHAR*)ref.elfStyle, styleName); |
2422 } | 2422 } |
2423 } | 2423 } |
2424 | 2424 |
2425 SkTypeface* createTypeface(int index) SK_OVERRIDE { | 2425 SkTypeface* createTypeface(int index) override { |
2426 return SkCreateTypefaceFromLOGFONT(fArray[index].elfLogFont); | 2426 return SkCreateTypefaceFromLOGFONT(fArray[index].elfLogFont); |
2427 } | 2427 } |
2428 | 2428 |
2429 SkTypeface* matchStyle(const SkFontStyle& pattern) SK_OVERRIDE { | 2429 SkTypeface* matchStyle(const SkFontStyle& pattern) override { |
2430 // todo: | 2430 // todo: |
2431 return SkCreateTypefaceFromLOGFONT(fArray[0].elfLogFont); | 2431 return SkCreateTypefaceFromLOGFONT(fArray[0].elfLogFont); |
2432 } | 2432 } |
2433 | 2433 |
2434 private: | 2434 private: |
2435 SkTDArray<ENUMLOGFONTEX> fArray; | 2435 SkTDArray<ENUMLOGFONTEX> fArray; |
2436 }; | 2436 }; |
2437 | 2437 |
2438 class SkFontMgrGDI : public SkFontMgr { | 2438 class SkFontMgrGDI : public SkFontMgr { |
2439 public: | 2439 public: |
2440 SkFontMgrGDI() { | 2440 SkFontMgrGDI() { |
2441 LOGFONT lf; | 2441 LOGFONT lf; |
2442 sk_bzero(&lf, sizeof(lf)); | 2442 sk_bzero(&lf, sizeof(lf)); |
2443 lf.lfCharSet = DEFAULT_CHARSET; | 2443 lf.lfCharSet = DEFAULT_CHARSET; |
2444 | 2444 |
2445 HDC hdc = ::CreateCompatibleDC(NULL); | 2445 HDC hdc = ::CreateCompatibleDC(NULL); |
2446 ::EnumFontFamiliesEx(hdc, &lf, enum_family_proc, (LPARAM)&fLogFontArray,
0); | 2446 ::EnumFontFamiliesEx(hdc, &lf, enum_family_proc, (LPARAM)&fLogFontArray,
0); |
2447 ::DeleteDC(hdc); | 2447 ::DeleteDC(hdc); |
2448 } | 2448 } |
2449 | 2449 |
2450 protected: | 2450 protected: |
2451 int onCountFamilies() const SK_OVERRIDE { | 2451 int onCountFamilies() const override { |
2452 return fLogFontArray.count(); | 2452 return fLogFontArray.count(); |
2453 } | 2453 } |
2454 | 2454 |
2455 void onGetFamilyName(int index, SkString* familyName) const SK_OVERRIDE { | 2455 void onGetFamilyName(int index, SkString* familyName) const override { |
2456 SkASSERT((unsigned)index < (unsigned)fLogFontArray.count()); | 2456 SkASSERT((unsigned)index < (unsigned)fLogFontArray.count()); |
2457 tchar_to_skstring(fLogFontArray[index].elfLogFont.lfFaceName, familyName
); | 2457 tchar_to_skstring(fLogFontArray[index].elfLogFont.lfFaceName, familyName
); |
2458 } | 2458 } |
2459 | 2459 |
2460 SkFontStyleSet* onCreateStyleSet(int index) const SK_OVERRIDE { | 2460 SkFontStyleSet* onCreateStyleSet(int index) const override { |
2461 SkASSERT((unsigned)index < (unsigned)fLogFontArray.count()); | 2461 SkASSERT((unsigned)index < (unsigned)fLogFontArray.count()); |
2462 return SkNEW_ARGS(SkFontStyleSetGDI, (fLogFontArray[index].elfLogFont.lf
FaceName)); | 2462 return SkNEW_ARGS(SkFontStyleSetGDI, (fLogFontArray[index].elfLogFont.lf
FaceName)); |
2463 } | 2463 } |
2464 | 2464 |
2465 SkFontStyleSet* onMatchFamily(const char familyName[]) const SK_OVERRIDE { | 2465 SkFontStyleSet* onMatchFamily(const char familyName[]) const override { |
2466 if (NULL == familyName) { | 2466 if (NULL == familyName) { |
2467 familyName = ""; // do we need this check??? | 2467 familyName = ""; // do we need this check??? |
2468 } | 2468 } |
2469 LOGFONT lf; | 2469 LOGFONT lf; |
2470 logfont_for_name(familyName, &lf); | 2470 logfont_for_name(familyName, &lf); |
2471 return SkNEW_ARGS(SkFontStyleSetGDI, (lf.lfFaceName)); | 2471 return SkNEW_ARGS(SkFontStyleSetGDI, (lf.lfFaceName)); |
2472 } | 2472 } |
2473 | 2473 |
2474 virtual SkTypeface* onMatchFamilyStyle(const char familyName[], | 2474 virtual SkTypeface* onMatchFamilyStyle(const char familyName[], |
2475 const SkFontStyle& fontstyle) const S
K_OVERRIDE { | 2475 const SkFontStyle& fontstyle) const o
verride { |
2476 // could be in base impl | 2476 // could be in base impl |
2477 SkAutoTUnref<SkFontStyleSet> sset(this->matchFamily(familyName)); | 2477 SkAutoTUnref<SkFontStyleSet> sset(this->matchFamily(familyName)); |
2478 return sset->matchStyle(fontstyle); | 2478 return sset->matchStyle(fontstyle); |
2479 } | 2479 } |
2480 | 2480 |
2481 virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], con
st SkFontStyle&, | 2481 virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], con
st SkFontStyle&, |
2482 const char* bcp47[], int bcp
47Count, | 2482 const char* bcp47[], int bcp
47Count, |
2483 SkUnichar character) const S
K_OVERRIDE { | 2483 SkUnichar character) const o
verride { |
2484 return NULL; | 2484 return NULL; |
2485 } | 2485 } |
2486 | 2486 |
2487 virtual SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember, | 2487 virtual SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember, |
2488 const SkFontStyle& fontstyle) const SK_
OVERRIDE { | 2488 const SkFontStyle& fontstyle) const ove
rride { |
2489 // could be in base impl | 2489 // could be in base impl |
2490 SkString familyName; | 2490 SkString familyName; |
2491 ((LogFontTypeface*)familyMember)->getFamilyName(&familyName); | 2491 ((LogFontTypeface*)familyMember)->getFamilyName(&familyName); |
2492 return this->matchFamilyStyle(familyName.c_str(), fontstyle); | 2492 return this->matchFamilyStyle(familyName.c_str(), fontstyle); |
2493 } | 2493 } |
2494 | 2494 |
2495 SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) cons
t SK_OVERRIDE { | 2495 SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) cons
t override { |
2496 SkAutoTDelete<SkStreamAsset> stream(bareStream); | 2496 SkAutoTDelete<SkStreamAsset> stream(bareStream); |
2497 return create_from_stream(stream); | 2497 return create_from_stream(stream); |
2498 } | 2498 } |
2499 | 2499 |
2500 SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const SK_OVERRIDE { | 2500 SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override { |
2501 // could be in base impl | 2501 // could be in base impl |
2502 return this->createFromStream(SkNEW_ARGS(SkMemoryStream, (data))); | 2502 return this->createFromStream(SkNEW_ARGS(SkMemoryStream, (data))); |
2503 } | 2503 } |
2504 | 2504 |
2505 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const SK_OVERR
IDE { | 2505 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override
{ |
2506 // could be in base impl | 2506 // could be in base impl |
2507 return this->createFromStream(SkStream::NewFromFile(path)); | 2507 return this->createFromStream(SkStream::NewFromFile(path)); |
2508 } | 2508 } |
2509 | 2509 |
2510 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], | 2510 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], |
2511 unsigned styleBits) const SK_OVER
RIDE { | 2511 unsigned styleBits) const overrid
e { |
2512 LOGFONT lf; | 2512 LOGFONT lf; |
2513 if (NULL == familyName) { | 2513 if (NULL == familyName) { |
2514 lf = get_default_font(); | 2514 lf = get_default_font(); |
2515 } else { | 2515 } else { |
2516 logfont_for_name(familyName, &lf); | 2516 logfont_for_name(familyName, &lf); |
2517 } | 2517 } |
2518 | 2518 |
2519 SkTypeface::Style style = (SkTypeface::Style)styleBits; | 2519 SkTypeface::Style style = (SkTypeface::Style)styleBits; |
2520 lf.lfWeight = (style & SkTypeface::kBold) != 0 ? FW_BOLD : FW_NORMAL; | 2520 lf.lfWeight = (style & SkTypeface::kBold) != 0 ? FW_BOLD : FW_NORMAL; |
2521 lf.lfItalic = ((style & SkTypeface::kItalic) != 0); | 2521 lf.lfItalic = ((style & SkTypeface::kItalic) != 0); |
2522 return SkCreateTypefaceFromLOGFONT(lf); | 2522 return SkCreateTypefaceFromLOGFONT(lf); |
2523 } | 2523 } |
2524 | 2524 |
2525 private: | 2525 private: |
2526 SkTDArray<ENUMLOGFONTEX> fLogFontArray; | 2526 SkTDArray<ENUMLOGFONTEX> fLogFontArray; |
2527 }; | 2527 }; |
2528 | 2528 |
2529 /////////////////////////////////////////////////////////////////////////////// | 2529 /////////////////////////////////////////////////////////////////////////////// |
2530 | 2530 |
2531 SkFontMgr* SkFontMgr_New_GDI() { | 2531 SkFontMgr* SkFontMgr_New_GDI() { |
2532 return SkNEW(SkFontMgrGDI); | 2532 return SkNEW(SkFontMgrGDI); |
2533 } | 2533 } |
OLD | NEW |