|
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
|
2 * This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #include "gfxDWriteCommon.h" |
|
7 |
|
8 IDWriteFontFileLoader* gfxDWriteFontFileLoader::mInstance = nullptr; |
|
9 |
|
10 HRESULT STDMETHODCALLTYPE |
|
11 gfxDWriteFontFileLoader::CreateStreamFromKey(const void *fontFileReferenceKey, |
|
12 UINT32 fontFileReferenceKeySize, |
|
13 IDWriteFontFileStream **fontFileStream) |
|
14 { |
|
15 if (!fontFileReferenceKey || !fontFileStream) { |
|
16 return E_POINTER; |
|
17 } |
|
18 |
|
19 *fontFileStream = |
|
20 new gfxDWriteFontFileStream( |
|
21 static_cast<const ffReferenceKey*>(fontFileReferenceKey)->mArray); |
|
22 |
|
23 if (!*fontFileStream) { |
|
24 return E_OUTOFMEMORY; |
|
25 } |
|
26 (*fontFileStream)->AddRef(); |
|
27 return S_OK; |
|
28 } |
|
29 |
|
30 gfxDWriteFontFileStream::gfxDWriteFontFileStream(FallibleTArray<uint8_t> *aData) |
|
31 { |
|
32 mData.SwapElements(*aData); |
|
33 } |
|
34 |
|
35 gfxDWriteFontFileStream::~gfxDWriteFontFileStream() |
|
36 { |
|
37 } |
|
38 |
|
39 HRESULT STDMETHODCALLTYPE |
|
40 gfxDWriteFontFileStream::GetFileSize(UINT64 *fileSize) |
|
41 { |
|
42 *fileSize = mData.Length(); |
|
43 return S_OK; |
|
44 } |
|
45 |
|
46 HRESULT STDMETHODCALLTYPE |
|
47 gfxDWriteFontFileStream::GetLastWriteTime(UINT64 *lastWriteTime) |
|
48 { |
|
49 return E_NOTIMPL; |
|
50 } |
|
51 |
|
52 HRESULT STDMETHODCALLTYPE |
|
53 gfxDWriteFontFileStream::ReadFileFragment(const void **fragmentStart, |
|
54 UINT64 fileOffset, |
|
55 UINT64 fragmentSize, |
|
56 void **fragmentContext) |
|
57 { |
|
58 // We are required to do bounds checking. |
|
59 if (fileOffset + fragmentSize > (UINT64)mData.Length()) { |
|
60 return E_FAIL; |
|
61 } |
|
62 // We should be alive for the duration of this. |
|
63 *fragmentStart = &mData[fileOffset]; |
|
64 *fragmentContext = nullptr; |
|
65 return S_OK; |
|
66 } |
|
67 |
|
68 void STDMETHODCALLTYPE |
|
69 gfxDWriteFontFileStream::ReleaseFileFragment(void *fragmentContext) |
|
70 { |
|
71 } |