michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "gfxDWriteCommon.h" michael@0: michael@0: IDWriteFontFileLoader* gfxDWriteFontFileLoader::mInstance = nullptr; michael@0: michael@0: HRESULT STDMETHODCALLTYPE michael@0: gfxDWriteFontFileLoader::CreateStreamFromKey(const void *fontFileReferenceKey, michael@0: UINT32 fontFileReferenceKeySize, michael@0: IDWriteFontFileStream **fontFileStream) michael@0: { michael@0: if (!fontFileReferenceKey || !fontFileStream) { michael@0: return E_POINTER; michael@0: } michael@0: michael@0: *fontFileStream = michael@0: new gfxDWriteFontFileStream( michael@0: static_cast(fontFileReferenceKey)->mArray); michael@0: michael@0: if (!*fontFileStream) { michael@0: return E_OUTOFMEMORY; michael@0: } michael@0: (*fontFileStream)->AddRef(); michael@0: return S_OK; michael@0: } michael@0: michael@0: gfxDWriteFontFileStream::gfxDWriteFontFileStream(FallibleTArray *aData) michael@0: { michael@0: mData.SwapElements(*aData); michael@0: } michael@0: michael@0: gfxDWriteFontFileStream::~gfxDWriteFontFileStream() michael@0: { michael@0: } michael@0: michael@0: HRESULT STDMETHODCALLTYPE michael@0: gfxDWriteFontFileStream::GetFileSize(UINT64 *fileSize) michael@0: { michael@0: *fileSize = mData.Length(); michael@0: return S_OK; michael@0: } michael@0: michael@0: HRESULT STDMETHODCALLTYPE michael@0: gfxDWriteFontFileStream::GetLastWriteTime(UINT64 *lastWriteTime) michael@0: { michael@0: return E_NOTIMPL; michael@0: } michael@0: michael@0: HRESULT STDMETHODCALLTYPE michael@0: gfxDWriteFontFileStream::ReadFileFragment(const void **fragmentStart, michael@0: UINT64 fileOffset, michael@0: UINT64 fragmentSize, michael@0: void **fragmentContext) michael@0: { michael@0: // We are required to do bounds checking. michael@0: if (fileOffset + fragmentSize > (UINT64)mData.Length()) { michael@0: return E_FAIL; michael@0: } michael@0: // We should be alive for the duration of this. michael@0: *fragmentStart = &mData[fileOffset]; michael@0: *fragmentContext = nullptr; michael@0: return S_OK; michael@0: } michael@0: michael@0: void STDMETHODCALLTYPE michael@0: gfxDWriteFontFileStream::ReleaseFileFragment(void *fragmentContext) michael@0: { michael@0: }