Chromium Code Reviews| 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 16 matching lines...) Expand all Loading... | |
| 27 virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void** ppvObjec t); | 27 virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void** ppvObjec t); |
| 28 virtual ULONG STDMETHODCALLTYPE AddRef(); | 28 virtual ULONG STDMETHODCALLTYPE AddRef(); |
| 29 virtual ULONG STDMETHODCALLTYPE Release(); | 29 virtual ULONG STDMETHODCALLTYPE Release(); |
| 30 | 30 |
| 31 // IDWriteFontFileLoader methods | 31 // IDWriteFontFileLoader methods |
| 32 virtual HRESULT STDMETHODCALLTYPE CreateStreamFromKey( | 32 virtual HRESULT STDMETHODCALLTYPE CreateStreamFromKey( |
| 33 void const* fontFileReferenceKey, | 33 void const* fontFileReferenceKey, |
| 34 UINT32 fontFileReferenceKeySize, | 34 UINT32 fontFileReferenceKeySize, |
| 35 IDWriteFontFileStream** fontFileStream); | 35 IDWriteFontFileStream** fontFileStream); |
| 36 | 36 |
| 37 // Takes ownership of stream. | |
| 37 static HRESULT Create(SkStream* stream, StreamFontFileLoader** streamFontFil eLoader) { | 38 static HRESULT Create(SkStream* stream, StreamFontFileLoader** streamFontFil eLoader) { |
| 38 *streamFontFileLoader = new StreamFontFileLoader(stream); | 39 *streamFontFileLoader = new StreamFontFileLoader(stream); |
| 39 if (NULL == streamFontFileLoader) { | 40 if (NULL == streamFontFileLoader) { |
| 40 return E_OUTOFMEMORY; | 41 return E_OUTOFMEMORY; |
| 41 } | 42 } |
| 42 return S_OK; | 43 return S_OK; |
| 43 } | 44 } |
| 44 | 45 |
| 45 SkAutoTUnref<SkStream> fStream; | 46 SkAutoTDelete<SkStream> fStream; |
| 46 | 47 |
| 47 private: | 48 private: |
| 48 StreamFontFileLoader(SkStream* stream) : fRefCount(1), fStream(SkRef(stream) ) { } | 49 StreamFontFileLoader(SkStream* stream) : fRefCount(1), fStream(stream) { } |
| 49 virtual ~StreamFontFileLoader() { } | 50 virtual ~StreamFontFileLoader() { } |
| 50 | 51 |
| 51 ULONG fRefCount; | 52 ULONG fRefCount; |
| 52 }; | 53 }; |
| 53 | 54 |
| 54 HRESULT StreamFontFileLoader::QueryInterface(REFIID iid, void** ppvObject) { | 55 HRESULT StreamFontFileLoader::QueryInterface(REFIID iid, void** ppvObject) { |
| 55 if (iid == IID_IUnknown || iid == __uuidof(IDWriteFontFileLoader)) { | 56 if (iid == IID_IUnknown || iid == __uuidof(IDWriteFontFileLoader)) { |
| 56 *ppvObject = this; | 57 *ppvObject = this; |
| 57 AddRef(); | 58 AddRef(); |
| 58 return S_OK; | 59 return S_OK; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 73 } | 74 } |
| 74 return newCount; | 75 return newCount; |
| 75 } | 76 } |
| 76 | 77 |
| 77 HRESULT StreamFontFileLoader::CreateStreamFromKey( | 78 HRESULT StreamFontFileLoader::CreateStreamFromKey( |
| 78 void const* fontFileReferenceKey, | 79 void const* fontFileReferenceKey, |
| 79 UINT32 fontFileReferenceKeySize, | 80 UINT32 fontFileReferenceKeySize, |
| 80 IDWriteFontFileStream** fontFileStream) | 81 IDWriteFontFileStream** fontFileStream) |
| 81 { | 82 { |
| 82 SkTScopedComPtr<SkDWriteFontFileStreamWrapper> stream; | 83 SkTScopedComPtr<SkDWriteFontFileStreamWrapper> stream; |
| 83 HR(SkDWriteFontFileStreamWrapper::Create(fStream, &stream)); | 84 HR(SkDWriteFontFileStreamWrapper::Create(fStream, &stream)); |
|
bungeman
2015/01/21 05:44:29
fStream->duplicate()
This is an existing bug, but
scroggo
2015/01/21 14:56:07
Done.
| |
| 84 *fontFileStream = stream.release(); | 85 *fontFileStream = stream.release(); |
| 85 return S_OK; | 86 return S_OK; |
| 86 } | 87 } |
| 87 | 88 |
| 88 //////////////////////////////////////////////////////////////////////////////// | 89 //////////////////////////////////////////////////////////////////////////////// |
| 89 | 90 |
| 90 class StreamFontFileEnumerator : public IDWriteFontFileEnumerator { | 91 class StreamFontFileEnumerator : public IDWriteFontFileEnumerator { |
| 91 public: | 92 public: |
| 92 // IUnknown methods | 93 // IUnknown methods |
| 93 virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void** ppvObjec t); | 94 virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void** ppvObjec t); |
| (...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 528 HRESULT unregister(IDWriteFactory* factory, IDWriteFontCollectionLoader* unr egister) { | 529 HRESULT unregister(IDWriteFactory* factory, IDWriteFontCollectionLoader* unr egister) { |
| 529 return factory->UnregisterFontCollectionLoader(unregister); | 530 return factory->UnregisterFontCollectionLoader(unregister); |
| 530 } | 531 } |
| 531 | 532 |
| 532 IDWriteFactory* fFactory; | 533 IDWriteFactory* fFactory; |
| 533 T* fUnregister; | 534 T* fUnregister; |
| 534 }; | 535 }; |
| 535 | 536 |
| 536 SkTypeface* SkFontMgr_DirectWrite::onCreateFromStream(SkStream* stream, int ttcI ndex) const { | 537 SkTypeface* SkFontMgr_DirectWrite::onCreateFromStream(SkStream* stream, int ttcI ndex) const { |
| 537 SkTScopedComPtr<StreamFontFileLoader> fontFileLoader; | 538 SkTScopedComPtr<StreamFontFileLoader> fontFileLoader; |
| 539 // This transfers ownership of stream to the new object. | |
| 538 HRN(StreamFontFileLoader::Create(stream, &fontFileLoader)); | 540 HRN(StreamFontFileLoader::Create(stream, &fontFileLoader)); |
| 539 HRN(fFactory->RegisterFontFileLoader(fontFileLoader.get())); | 541 HRN(fFactory->RegisterFontFileLoader(fontFileLoader.get())); |
| 540 SkAutoIDWriteUnregister<StreamFontFileLoader> autoUnregisterFontFileLoader( | 542 SkAutoIDWriteUnregister<StreamFontFileLoader> autoUnregisterFontFileLoader( |
| 541 fFactory.get(), fontFileLoader.get()); | 543 fFactory.get(), fontFileLoader.get()); |
| 542 | 544 |
| 543 SkTScopedComPtr<StreamFontCollectionLoader> fontCollectionLoader; | 545 SkTScopedComPtr<StreamFontCollectionLoader> fontCollectionLoader; |
| 544 HRN(StreamFontCollectionLoader::Create(fontFileLoader.get(), &fontCollection Loader)); | 546 HRN(StreamFontCollectionLoader::Create(fontFileLoader.get(), &fontCollection Loader)); |
| 545 HRN(fFactory->RegisterFontCollectionLoader(fontCollectionLoader.get())); | 547 HRN(fFactory->RegisterFontCollectionLoader(fontCollectionLoader.get())); |
| 546 SkAutoIDWriteUnregister<StreamFontCollectionLoader> autoUnregisterFontCollec tionLoader( | 548 SkAutoIDWriteUnregister<StreamFontCollectionLoader> autoUnregisterFontCollec tionLoader( |
| 547 fFactory.get(), fontCollectionLoader.get()); | 549 fFactory.get(), fontCollectionLoader.get()); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 573 autoUnregisterFontFileLoader.d etatch(), | 575 autoUnregisterFontFileLoader.d etatch(), |
| 574 autoUnregisterFontCollectionLo ader.detatch()); | 576 autoUnregisterFontCollectionLo ader.detatch()); |
| 575 } | 577 } |
| 576 } | 578 } |
| 577 } | 579 } |
| 578 | 580 |
| 579 return NULL; | 581 return NULL; |
| 580 } | 582 } |
| 581 | 583 |
| 582 SkTypeface* SkFontMgr_DirectWrite::onCreateFromData(SkData* data, int ttcIndex) const { | 584 SkTypeface* SkFontMgr_DirectWrite::onCreateFromData(SkData* data, int ttcIndex) const { |
| 583 SkAutoTUnref<SkStream> stream(SkNEW_ARGS(SkMemoryStream, (data))); | 585 return this->createFromStream(SkNEW_ARGS(SkMemoryStream, (data)), ttcIndex); |
| 584 return this->createFromStream(stream, ttcIndex); | |
| 585 } | 586 } |
| 586 | 587 |
| 587 SkTypeface* SkFontMgr_DirectWrite::onCreateFromFile(const char path[], int ttcIn dex) const { | 588 SkTypeface* SkFontMgr_DirectWrite::onCreateFromFile(const char path[], int ttcIn dex) const { |
| 588 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); | 589 return this->createFromStream(SkStream::NewFromFile(path), ttcIndex); |
| 589 return this->createFromStream(stream, ttcIndex); | |
| 590 } | 590 } |
| 591 | 591 |
| 592 HRESULT SkFontMgr_DirectWrite::getByFamilyName(const WCHAR wideFamilyName[], | 592 HRESULT SkFontMgr_DirectWrite::getByFamilyName(const WCHAR wideFamilyName[], |
| 593 IDWriteFontFamily** fontFamily) c onst { | 593 IDWriteFontFamily** fontFamily) c onst { |
| 594 UINT32 index; | 594 UINT32 index; |
| 595 BOOL exists; | 595 BOOL exists; |
| 596 HR(fFontCollection->FindFamilyName(wideFamilyName, &index, &exists)); | 596 HR(fFontCollection->FindFamilyName(wideFamilyName, &index, &exists)); |
| 597 | 597 |
| 598 if (exists) { | 598 if (exists) { |
| 599 HR(fFontCollection->GetFontFamily(index, fontFamily)); | 599 HR(fFontCollection->GetFontFamily(index, fontFamily)); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 765 } | 765 } |
| 766 | 766 |
| 767 #include "SkFontMgr_indirect.h" | 767 #include "SkFontMgr_indirect.h" |
| 768 SK_API SkFontMgr* SkFontMgr_New_DirectWriteRenderer(SkRemotableFontMgr* proxy) { | 768 SK_API SkFontMgr* SkFontMgr_New_DirectWriteRenderer(SkRemotableFontMgr* proxy) { |
| 769 SkAutoTUnref<SkFontMgr> impl(SkFontMgr_New_DirectWrite()); | 769 SkAutoTUnref<SkFontMgr> impl(SkFontMgr_New_DirectWrite()); |
| 770 if (impl.get() == NULL) { | 770 if (impl.get() == NULL) { |
| 771 return NULL; | 771 return NULL; |
| 772 } | 772 } |
| 773 return SkNEW_ARGS(SkFontMgr_Indirect, (impl.get(), proxy)); | 773 return SkNEW_ARGS(SkFontMgr_Indirect, (impl.get(), proxy)); |
| 774 } | 774 } |
| OLD | NEW |