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 "SkDWrite.h" | 8 #include "SkDWrite.h" |
9 #include "SkDWriteFontFileStream.h" | 9 #include "SkDWriteFontFileStream.h" |
10 #include "SkFontMgr.h" | 10 #include "SkFontMgr.h" |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 if (!SUCCEEDED(fFactory->QueryInterface(&fFactory2))) { | 270 if (!SUCCEEDED(fFactory->QueryInterface(&fFactory2))) { |
271 // IUnknown::QueryInterface states that if it fails, punk will be se
t to NULL. | 271 // IUnknown::QueryInterface states that if it fails, punk will be se
t to NULL. |
272 // http://blogs.msdn.com/b/oldnewthing/archive/2004/03/26/96777.aspx | 272 // http://blogs.msdn.com/b/oldnewthing/archive/2004/03/26/96777.aspx |
273 SK_ALWAYSBREAK(NULL == fFactory2.get()); | 273 SK_ALWAYSBREAK(NULL == fFactory2.get()); |
274 } | 274 } |
275 #endif | 275 #endif |
276 memcpy(fLocaleName.get(), localeName, localeNameLength * sizeof(WCHAR)); | 276 memcpy(fLocaleName.get(), localeName, localeNameLength * sizeof(WCHAR)); |
277 } | 277 } |
278 | 278 |
279 protected: | 279 protected: |
280 int onCountFamilies() const SK_OVERRIDE; | 280 int onCountFamilies() const override; |
281 void onGetFamilyName(int index, SkString* familyName) const SK_OVERRIDE; | 281 void onGetFamilyName(int index, SkString* familyName) const override; |
282 SkFontStyleSet* onCreateStyleSet(int index) const SK_OVERRIDE; | 282 SkFontStyleSet* onCreateStyleSet(int index) const override; |
283 SkFontStyleSet* onMatchFamily(const char familyName[]) const SK_OVERRIDE; | 283 SkFontStyleSet* onMatchFamily(const char familyName[]) const override; |
284 virtual SkTypeface* onMatchFamilyStyle(const char familyName[], | 284 virtual SkTypeface* onMatchFamilyStyle(const char familyName[], |
285 const SkFontStyle& fontstyle) const S
K_OVERRIDE; | 285 const SkFontStyle& fontstyle) const o
verride; |
286 virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], con
st SkFontStyle&, | 286 virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], con
st SkFontStyle&, |
287 const char* bcp47[], int bcp
47Count, | 287 const char* bcp47[], int bcp
47Count, |
288 SkUnichar character) const S
K_OVERRIDE; | 288 SkUnichar character) const o
verride; |
289 virtual SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember, | 289 virtual SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember, |
290 const SkFontStyle& fontstyle) const SK_
OVERRIDE; | 290 const SkFontStyle& fontstyle) const ove
rride; |
291 SkTypeface* onCreateFromStream(SkStreamAsset* stream, int ttcIndex) const SK
_OVERRIDE; | 291 SkTypeface* onCreateFromStream(SkStreamAsset* stream, int ttcIndex) const ov
erride; |
292 SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const SK_OVERRIDE; | 292 SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override; |
293 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const SK_OVERR
IDE; | 293 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override
; |
294 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], | 294 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], |
295 unsigned styleBits) const SK_OVER
RIDE; | 295 unsigned styleBits) const overrid
e; |
296 | 296 |
297 private: | 297 private: |
298 HRESULT getByFamilyName(const WCHAR familyName[], IDWriteFontFamily** fontFa
mily) const; | 298 HRESULT getByFamilyName(const WCHAR familyName[], IDWriteFontFamily** fontFa
mily) const; |
299 HRESULT getDefaultFontFamily(IDWriteFontFamily** fontFamily) const; | 299 HRESULT getDefaultFontFamily(IDWriteFontFamily** fontFamily) const; |
300 | 300 |
301 /** Creates a typeface using a typeface cache. */ | 301 /** Creates a typeface using a typeface cache. */ |
302 SkTypeface* createTypefaceFromDWriteFont(IDWriteFontFace* fontFace, | 302 SkTypeface* createTypefaceFromDWriteFont(IDWriteFontFace* fontFace, |
303 IDWriteFont* font, | 303 IDWriteFont* font, |
304 IDWriteFontFamily* fontFamily) cons
t; | 304 IDWriteFontFamily* fontFamily) cons
t; |
305 | 305 |
(...skipping 11 matching lines...) Expand all Loading... |
317 }; | 317 }; |
318 | 318 |
319 class SkFontStyleSet_DirectWrite : public SkFontStyleSet { | 319 class SkFontStyleSet_DirectWrite : public SkFontStyleSet { |
320 public: | 320 public: |
321 SkFontStyleSet_DirectWrite(const SkFontMgr_DirectWrite* fontMgr, | 321 SkFontStyleSet_DirectWrite(const SkFontMgr_DirectWrite* fontMgr, |
322 IDWriteFontFamily* fontFamily) | 322 IDWriteFontFamily* fontFamily) |
323 : fFontMgr(SkRef(fontMgr)) | 323 : fFontMgr(SkRef(fontMgr)) |
324 , fFontFamily(SkRefComPtr(fontFamily)) | 324 , fFontFamily(SkRefComPtr(fontFamily)) |
325 { } | 325 { } |
326 | 326 |
327 int count() SK_OVERRIDE; | 327 int count() override; |
328 void getStyle(int index, SkFontStyle* fs, SkString* styleName) SK_OVERRIDE; | 328 void getStyle(int index, SkFontStyle* fs, SkString* styleName) override; |
329 SkTypeface* createTypeface(int index) SK_OVERRIDE; | 329 SkTypeface* createTypeface(int index) override; |
330 SkTypeface* matchStyle(const SkFontStyle& pattern) SK_OVERRIDE; | 330 SkTypeface* matchStyle(const SkFontStyle& pattern) override; |
331 | 331 |
332 private: | 332 private: |
333 SkAutoTUnref<const SkFontMgr_DirectWrite> fFontMgr; | 333 SkAutoTUnref<const SkFontMgr_DirectWrite> fFontMgr; |
334 SkTScopedComPtr<IDWriteFontFamily> fFontFamily; | 334 SkTScopedComPtr<IDWriteFontFamily> fFontFamily; |
335 }; | 335 }; |
336 | 336 |
337 static HRESULT are_same(IUnknown* a, IUnknown* b, bool& same) { | 337 static HRESULT are_same(IUnknown* a, IUnknown* b, bool& same) { |
338 SkTScopedComPtr<IUnknown> iunkA; | 338 SkTScopedComPtr<IUnknown> iunkA; |
339 HRM(a->QueryInterface(&iunkA), "Failed to QI<IUnknown> for a."); | 339 HRM(a->QueryInterface(&iunkA), "Failed to QI<IUnknown> for a."); |
340 | 340 |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 virtual ~FontFallbackRenderer() { } | 512 virtual ~FontFallbackRenderer() { } |
513 | 513 |
514 // IDWriteTextRenderer methods | 514 // IDWriteTextRenderer methods |
515 virtual HRESULT STDMETHODCALLTYPE DrawGlyphRun( | 515 virtual HRESULT STDMETHODCALLTYPE DrawGlyphRun( |
516 void* clientDrawingContext, | 516 void* clientDrawingContext, |
517 FLOAT baselineOriginX, | 517 FLOAT baselineOriginX, |
518 FLOAT baselineOriginY, | 518 FLOAT baselineOriginY, |
519 DWRITE_MEASURING_MODE measuringMode, | 519 DWRITE_MEASURING_MODE measuringMode, |
520 DWRITE_GLYPH_RUN const* glyphRun, | 520 DWRITE_GLYPH_RUN const* glyphRun, |
521 DWRITE_GLYPH_RUN_DESCRIPTION const* glyphRunDescription, | 521 DWRITE_GLYPH_RUN_DESCRIPTION const* glyphRunDescription, |
522 IUnknown* clientDrawingEffect) SK_OVERRIDE | 522 IUnknown* clientDrawingEffect) override |
523 { | 523 { |
524 SkTScopedComPtr<IDWriteFont> font; | 524 SkTScopedComPtr<IDWriteFont> font; |
525 HRM(fOuter->fFontCollection->GetFontFromFontFace(glyphRun->fontFace, &fo
nt), | 525 HRM(fOuter->fFontCollection->GetFontFromFontFace(glyphRun->fontFace, &fo
nt), |
526 "Could not get font from font face."); | 526 "Could not get font from font face."); |
527 | 527 |
528 // It is possible that the font passed does not actually have the reques
ted character, | 528 // It is possible that the font passed does not actually have the reques
ted character, |
529 // due to no font being found and getting the fallback font. | 529 // due to no font being found and getting the fallback font. |
530 // Check that the font actually contains the requested character. | 530 // Check that the font actually contains the requested character. |
531 BOOL exists; | 531 BOOL exists; |
532 HRM(font->HasCharacter(fCharacter, &exists), "Could not find character."
); | 532 HRM(font->HasCharacter(fCharacter, &exists), "Could not find character."
); |
533 | 533 |
534 if (exists) { | 534 if (exists) { |
535 SkTScopedComPtr<IDWriteFontFamily> fontFamily; | 535 SkTScopedComPtr<IDWriteFontFamily> fontFamily; |
536 HRM(font->GetFontFamily(&fontFamily), "Could not get family."); | 536 HRM(font->GetFontFamily(&fontFamily), "Could not get family."); |
537 fResolvedTypeface = fOuter->createTypefaceFromDWriteFont(glyphRun->f
ontFace, | 537 fResolvedTypeface = fOuter->createTypefaceFromDWriteFont(glyphRun->f
ontFace, |
538 font.get(), | 538 font.get(), |
539 fontFamily.
get()); | 539 fontFamily.
get()); |
540 } | 540 } |
541 | 541 |
542 return S_OK; | 542 return S_OK; |
543 } | 543 } |
544 | 544 |
545 virtual HRESULT STDMETHODCALLTYPE DrawUnderline( | 545 virtual HRESULT STDMETHODCALLTYPE DrawUnderline( |
546 void* clientDrawingContext, | 546 void* clientDrawingContext, |
547 FLOAT baselineOriginX, | 547 FLOAT baselineOriginX, |
548 FLOAT baselineOriginY, | 548 FLOAT baselineOriginY, |
549 DWRITE_UNDERLINE const* underline, | 549 DWRITE_UNDERLINE const* underline, |
550 IUnknown* clientDrawingEffect) SK_OVERRIDE | 550 IUnknown* clientDrawingEffect) override |
551 { return E_NOTIMPL; } | 551 { return E_NOTIMPL; } |
552 | 552 |
553 virtual HRESULT STDMETHODCALLTYPE DrawStrikethrough( | 553 virtual HRESULT STDMETHODCALLTYPE DrawStrikethrough( |
554 void* clientDrawingContext, | 554 void* clientDrawingContext, |
555 FLOAT baselineOriginX, | 555 FLOAT baselineOriginX, |
556 FLOAT baselineOriginY, | 556 FLOAT baselineOriginY, |
557 DWRITE_STRIKETHROUGH const* strikethrough, | 557 DWRITE_STRIKETHROUGH const* strikethrough, |
558 IUnknown* clientDrawingEffect) SK_OVERRIDE | 558 IUnknown* clientDrawingEffect) override |
559 { return E_NOTIMPL; } | 559 { return E_NOTIMPL; } |
560 | 560 |
561 virtual HRESULT STDMETHODCALLTYPE DrawInlineObject( | 561 virtual HRESULT STDMETHODCALLTYPE DrawInlineObject( |
562 void* clientDrawingContext, | 562 void* clientDrawingContext, |
563 FLOAT originX, | 563 FLOAT originX, |
564 FLOAT originY, | 564 FLOAT originY, |
565 IDWriteInlineObject* inlineObject, | 565 IDWriteInlineObject* inlineObject, |
566 BOOL isSideways, | 566 BOOL isSideways, |
567 BOOL isRightToLeft, | 567 BOOL isRightToLeft, |
568 IUnknown* clientDrawingEffect) SK_OVERRIDE | 568 IUnknown* clientDrawingEffect) override |
569 { return E_NOTIMPL; } | 569 { return E_NOTIMPL; } |
570 | 570 |
571 // IDWritePixelSnapping methods | 571 // IDWritePixelSnapping methods |
572 virtual HRESULT STDMETHODCALLTYPE IsPixelSnappingDisabled( | 572 virtual HRESULT STDMETHODCALLTYPE IsPixelSnappingDisabled( |
573 void* clientDrawingContext, | 573 void* clientDrawingContext, |
574 BOOL* isDisabled) SK_OVERRIDE | 574 BOOL* isDisabled) override |
575 { | 575 { |
576 *isDisabled = FALSE; | 576 *isDisabled = FALSE; |
577 return S_OK; | 577 return S_OK; |
578 } | 578 } |
579 | 579 |
580 virtual HRESULT STDMETHODCALLTYPE GetCurrentTransform( | 580 virtual HRESULT STDMETHODCALLTYPE GetCurrentTransform( |
581 void* clientDrawingContext, | 581 void* clientDrawingContext, |
582 DWRITE_MATRIX* transform) SK_OVERRIDE | 582 DWRITE_MATRIX* transform) override |
583 { | 583 { |
584 const DWRITE_MATRIX ident = { 1.0, 0.0, 0.0, 1.0, 0.0, 0.0 }; | 584 const DWRITE_MATRIX ident = { 1.0, 0.0, 0.0, 1.0, 0.0, 0.0 }; |
585 *transform = ident; | 585 *transform = ident; |
586 return S_OK; | 586 return S_OK; |
587 } | 587 } |
588 | 588 |
589 virtual HRESULT STDMETHODCALLTYPE GetPixelsPerDip( | 589 virtual HRESULT STDMETHODCALLTYPE GetPixelsPerDip( |
590 void* clientDrawingContext, | 590 void* clientDrawingContext, |
591 FLOAT* pixelsPerDip) SK_OVERRIDE | 591 FLOAT* pixelsPerDip) override |
592 { | 592 { |
593 *pixelsPerDip = 1.0f; | 593 *pixelsPerDip = 1.0f; |
594 return S_OK; | 594 return S_OK; |
595 } | 595 } |
596 | 596 |
597 // IUnknown methods | 597 // IUnknown methods |
598 ULONG STDMETHODCALLTYPE AddRef() SK_OVERRIDE { | 598 ULONG STDMETHODCALLTYPE AddRef() override { |
599 return InterlockedIncrement(&fRefCount); | 599 return InterlockedIncrement(&fRefCount); |
600 } | 600 } |
601 | 601 |
602 ULONG STDMETHODCALLTYPE Release() SK_OVERRIDE { | 602 ULONG STDMETHODCALLTYPE Release() override { |
603 ULONG newCount = InterlockedDecrement(&fRefCount); | 603 ULONG newCount = InterlockedDecrement(&fRefCount); |
604 if (0 == newCount) { | 604 if (0 == newCount) { |
605 delete this; | 605 delete this; |
606 } | 606 } |
607 return newCount; | 607 return newCount; |
608 } | 608 } |
609 | 609 |
610 virtual HRESULT STDMETHODCALLTYPE QueryInterface(IID const& riid, void** ppv
Object) SK_OVERRIDE{ | 610 virtual HRESULT STDMETHODCALLTYPE QueryInterface(IID const& riid, void** ppv
Object) override{ |
611 if (__uuidof(IUnknown) == riid || | 611 if (__uuidof(IUnknown) == riid || |
612 __uuidof(IDWritePixelSnapping) == riid || | 612 __uuidof(IDWritePixelSnapping) == riid || |
613 __uuidof(IDWriteTextRenderer) == riid) | 613 __uuidof(IDWriteTextRenderer) == riid) |
614 { | 614 { |
615 *ppvObject = this; | 615 *ppvObject = this; |
616 this->AddRef(); | 616 this->AddRef(); |
617 return S_OK; | 617 return S_OK; |
618 } | 618 } |
619 *ppvObject = NULL; | 619 *ppvObject = NULL; |
620 return E_FAIL; | 620 return E_FAIL; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 , fLocale(locale) | 653 , fLocale(locale) |
654 , fNumberSubstitution(numberSubstitution) | 654 , fNumberSubstitution(numberSubstitution) |
655 { } | 655 { } |
656 | 656 |
657 virtual ~FontFallbackSource() { } | 657 virtual ~FontFallbackSource() { } |
658 | 658 |
659 // IDWriteTextAnalysisSource methods | 659 // IDWriteTextAnalysisSource methods |
660 virtual HRESULT STDMETHODCALLTYPE GetTextAtPosition( | 660 virtual HRESULT STDMETHODCALLTYPE GetTextAtPosition( |
661 UINT32 textPosition, | 661 UINT32 textPosition, |
662 WCHAR const** textString, | 662 WCHAR const** textString, |
663 UINT32* textLength) SK_OVERRIDE | 663 UINT32* textLength) override |
664 { | 664 { |
665 if (fLength <= textPosition) { | 665 if (fLength <= textPosition) { |
666 *textString = NULL; | 666 *textString = NULL; |
667 *textLength = 0; | 667 *textLength = 0; |
668 return S_OK; | 668 return S_OK; |
669 } | 669 } |
670 *textString = fString + textPosition; | 670 *textString = fString + textPosition; |
671 *textLength = fLength - textPosition; | 671 *textLength = fLength - textPosition; |
672 return S_OK; | 672 return S_OK; |
673 } | 673 } |
674 | 674 |
675 virtual HRESULT STDMETHODCALLTYPE GetTextBeforePosition( | 675 virtual HRESULT STDMETHODCALLTYPE GetTextBeforePosition( |
676 UINT32 textPosition, | 676 UINT32 textPosition, |
677 WCHAR const** textString, | 677 WCHAR const** textString, |
678 UINT32* textLength) SK_OVERRIDE | 678 UINT32* textLength) override |
679 { | 679 { |
680 if (textPosition < 1 || fLength <= textPosition) { | 680 if (textPosition < 1 || fLength <= textPosition) { |
681 *textString = NULL; | 681 *textString = NULL; |
682 *textLength = 0; | 682 *textLength = 0; |
683 return S_OK; | 683 return S_OK; |
684 } | 684 } |
685 *textString = fString; | 685 *textString = fString; |
686 *textLength = textPosition; | 686 *textLength = textPosition; |
687 return S_OK; | 687 return S_OK; |
688 } | 688 } |
689 | 689 |
690 virtual DWRITE_READING_DIRECTION STDMETHODCALLTYPE GetParagraphReadingDirect
ion() SK_OVERRIDE { | 690 virtual DWRITE_READING_DIRECTION STDMETHODCALLTYPE GetParagraphReadingDirect
ion() override { |
691 // TODO: this is also interesting. | 691 // TODO: this is also interesting. |
692 return DWRITE_READING_DIRECTION_LEFT_TO_RIGHT; | 692 return DWRITE_READING_DIRECTION_LEFT_TO_RIGHT; |
693 } | 693 } |
694 | 694 |
695 virtual HRESULT STDMETHODCALLTYPE GetLocaleName( | 695 virtual HRESULT STDMETHODCALLTYPE GetLocaleName( |
696 UINT32 textPosition, | 696 UINT32 textPosition, |
697 UINT32* textLength, | 697 UINT32* textLength, |
698 WCHAR const** localeName) SK_OVERRIDE | 698 WCHAR const** localeName) override |
699 { | 699 { |
700 *localeName = fLocale; | 700 *localeName = fLocale; |
701 return S_OK; | 701 return S_OK; |
702 } | 702 } |
703 | 703 |
704 virtual HRESULT STDMETHODCALLTYPE GetNumberSubstitution( | 704 virtual HRESULT STDMETHODCALLTYPE GetNumberSubstitution( |
705 UINT32 textPosition, | 705 UINT32 textPosition, |
706 UINT32* textLength, | 706 UINT32* textLength, |
707 IDWriteNumberSubstitution** numberSubstitution) SK_OVERRIDE | 707 IDWriteNumberSubstitution** numberSubstitution) override |
708 { | 708 { |
709 *numberSubstitution = fNumberSubstitution; | 709 *numberSubstitution = fNumberSubstitution; |
710 return S_OK; | 710 return S_OK; |
711 } | 711 } |
712 | 712 |
713 // IUnknown methods | 713 // IUnknown methods |
714 ULONG STDMETHODCALLTYPE AddRef() SK_OVERRIDE { | 714 ULONG STDMETHODCALLTYPE AddRef() override { |
715 return InterlockedIncrement(&fRefCount); | 715 return InterlockedIncrement(&fRefCount); |
716 } | 716 } |
717 | 717 |
718 ULONG STDMETHODCALLTYPE Release() SK_OVERRIDE { | 718 ULONG STDMETHODCALLTYPE Release() override { |
719 ULONG newCount = InterlockedDecrement(&fRefCount); | 719 ULONG newCount = InterlockedDecrement(&fRefCount); |
720 if (0 == newCount) { | 720 if (0 == newCount) { |
721 delete this; | 721 delete this; |
722 } | 722 } |
723 return newCount; | 723 return newCount; |
724 } | 724 } |
725 | 725 |
726 virtual HRESULT STDMETHODCALLTYPE QueryInterface(IID const& riid, void** ppv
Object) SK_OVERRIDE{ | 726 virtual HRESULT STDMETHODCALLTYPE QueryInterface(IID const& riid, void** ppv
Object) override{ |
727 if (__uuidof(IUnknown) == riid || | 727 if (__uuidof(IUnknown) == riid || |
728 __uuidof(IDWriteTextAnalysisSource) == riid) | 728 __uuidof(IDWriteTextAnalysisSource) == riid) |
729 { | 729 { |
730 *ppvObject = this; | 730 *ppvObject = this; |
731 this->AddRef(); | 731 this->AddRef(); |
732 return S_OK; | 732 return S_OK; |
733 } | 733 } |
734 *ppvObject = NULL; | 734 *ppvObject = NULL; |
735 return E_FAIL; | 735 return E_FAIL; |
736 } | 736 } |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1112 } | 1112 } |
1113 | 1113 |
1114 #include "SkFontMgr_indirect.h" | 1114 #include "SkFontMgr_indirect.h" |
1115 SK_API SkFontMgr* SkFontMgr_New_DirectWriteRenderer(SkRemotableFontMgr* proxy) { | 1115 SK_API SkFontMgr* SkFontMgr_New_DirectWriteRenderer(SkRemotableFontMgr* proxy) { |
1116 SkAutoTUnref<SkFontMgr> impl(SkFontMgr_New_DirectWrite()); | 1116 SkAutoTUnref<SkFontMgr> impl(SkFontMgr_New_DirectWrite()); |
1117 if (impl.get() == NULL) { | 1117 if (impl.get() == NULL) { |
1118 return NULL; | 1118 return NULL; |
1119 } | 1119 } |
1120 return SkNEW_ARGS(SkFontMgr_Indirect, (impl.get(), proxy)); | 1120 return SkNEW_ARGS(SkFontMgr_Indirect, (impl.get(), proxy)); |
1121 } | 1121 } |
OLD | NEW |