gfx/thebes/gfxDWriteCommon.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
michael@0 2 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef GFX_DWRITECOMMON_H
michael@0 7 #define GFX_DWRITECOMMON_H
michael@0 8
michael@0 9 // Mozilla includes
michael@0 10 #include "nscore.h"
michael@0 11 #include "nsIServiceManager.h"
michael@0 12 #include "nsCOMPtr.h"
michael@0 13 #include "nsAutoPtr.h"
michael@0 14 #include "cairo-features.h"
michael@0 15 #include "gfxFontConstants.h"
michael@0 16 #include "nsTArray.h"
michael@0 17 #include "gfxWindowsPlatform.h"
michael@0 18 #include "nsIUUIDGenerator.h"
michael@0 19
michael@0 20 #include <windows.h>
michael@0 21 #include <dwrite.h>
michael@0 22
michael@0 23 static DWRITE_FONT_STRETCH
michael@0 24 DWriteFontStretchFromStretch(int16_t aStretch)
michael@0 25 {
michael@0 26 switch (aStretch) {
michael@0 27 case NS_FONT_STRETCH_ULTRA_CONDENSED:
michael@0 28 return DWRITE_FONT_STRETCH_ULTRA_CONDENSED;
michael@0 29 case NS_FONT_STRETCH_EXTRA_CONDENSED:
michael@0 30 return DWRITE_FONT_STRETCH_EXTRA_CONDENSED;
michael@0 31 case NS_FONT_STRETCH_CONDENSED:
michael@0 32 return DWRITE_FONT_STRETCH_CONDENSED;
michael@0 33 case NS_FONT_STRETCH_SEMI_CONDENSED:
michael@0 34 return DWRITE_FONT_STRETCH_SEMI_CONDENSED;
michael@0 35 case NS_FONT_STRETCH_NORMAL:
michael@0 36 return DWRITE_FONT_STRETCH_NORMAL;
michael@0 37 case NS_FONT_STRETCH_SEMI_EXPANDED:
michael@0 38 return DWRITE_FONT_STRETCH_SEMI_EXPANDED;
michael@0 39 case NS_FONT_STRETCH_EXPANDED:
michael@0 40 return DWRITE_FONT_STRETCH_EXPANDED;
michael@0 41 case NS_FONT_STRETCH_EXTRA_EXPANDED:
michael@0 42 return DWRITE_FONT_STRETCH_EXTRA_EXPANDED;
michael@0 43 case NS_FONT_STRETCH_ULTRA_EXPANDED:
michael@0 44 return DWRITE_FONT_STRETCH_ULTRA_EXPANDED;
michael@0 45 default:
michael@0 46 return DWRITE_FONT_STRETCH_UNDEFINED;
michael@0 47 }
michael@0 48 }
michael@0 49
michael@0 50 static int16_t
michael@0 51 FontStretchFromDWriteStretch(DWRITE_FONT_STRETCH aStretch)
michael@0 52 {
michael@0 53 switch (aStretch) {
michael@0 54 case DWRITE_FONT_STRETCH_ULTRA_CONDENSED:
michael@0 55 return NS_FONT_STRETCH_ULTRA_CONDENSED;
michael@0 56 case DWRITE_FONT_STRETCH_EXTRA_CONDENSED:
michael@0 57 return NS_FONT_STRETCH_EXTRA_CONDENSED;
michael@0 58 case DWRITE_FONT_STRETCH_CONDENSED:
michael@0 59 return NS_FONT_STRETCH_CONDENSED;
michael@0 60 case DWRITE_FONT_STRETCH_SEMI_CONDENSED:
michael@0 61 return NS_FONT_STRETCH_SEMI_CONDENSED;
michael@0 62 case DWRITE_FONT_STRETCH_NORMAL:
michael@0 63 return NS_FONT_STRETCH_NORMAL;
michael@0 64 case DWRITE_FONT_STRETCH_SEMI_EXPANDED:
michael@0 65 return NS_FONT_STRETCH_SEMI_EXPANDED;
michael@0 66 case DWRITE_FONT_STRETCH_EXPANDED:
michael@0 67 return NS_FONT_STRETCH_EXPANDED;
michael@0 68 case DWRITE_FONT_STRETCH_EXTRA_EXPANDED:
michael@0 69 return NS_FONT_STRETCH_EXTRA_EXPANDED;
michael@0 70 case DWRITE_FONT_STRETCH_ULTRA_EXPANDED:
michael@0 71 return NS_FONT_STRETCH_ULTRA_EXPANDED;
michael@0 72 default:
michael@0 73 return NS_FONT_STRETCH_NORMAL;
michael@0 74 }
michael@0 75 }
michael@0 76
michael@0 77 struct ffReferenceKey
michael@0 78 {
michael@0 79 FallibleTArray<uint8_t> *mArray;
michael@0 80 nsID mGUID;
michael@0 81 };
michael@0 82
michael@0 83 class gfxDWriteFontFileLoader : public IDWriteFontFileLoader
michael@0 84 {
michael@0 85 public:
michael@0 86 gfxDWriteFontFileLoader()
michael@0 87 {
michael@0 88 }
michael@0 89
michael@0 90 // IUnknown interface
michael@0 91 IFACEMETHOD(QueryInterface)(IID const& iid, OUT void** ppObject)
michael@0 92 {
michael@0 93 if (iid == __uuidof(IDWriteFontFileLoader)) {
michael@0 94 *ppObject = static_cast<IDWriteFontFileLoader*>(this);
michael@0 95 return S_OK;
michael@0 96 } else if (iid == __uuidof(IUnknown)) {
michael@0 97 *ppObject = static_cast<IUnknown*>(this);
michael@0 98 return S_OK;
michael@0 99 } else {
michael@0 100 return E_NOINTERFACE;
michael@0 101 }
michael@0 102 }
michael@0 103
michael@0 104 IFACEMETHOD_(ULONG, AddRef)()
michael@0 105 {
michael@0 106 return 1;
michael@0 107 }
michael@0 108
michael@0 109 IFACEMETHOD_(ULONG, Release)()
michael@0 110 {
michael@0 111 return 1;
michael@0 112 }
michael@0 113
michael@0 114 // IDWriteFontFileLoader methods
michael@0 115 /**
michael@0 116 * Important! Note the key here -has- to be a pointer to an
michael@0 117 * FallibleTArray<uint8_t>.
michael@0 118 */
michael@0 119 virtual HRESULT STDMETHODCALLTYPE
michael@0 120 CreateStreamFromKey(void const* fontFileReferenceKey,
michael@0 121 UINT32 fontFileReferenceKeySize,
michael@0 122 OUT IDWriteFontFileStream** fontFileStream);
michael@0 123
michael@0 124 /**
michael@0 125 * Gets the singleton loader instance. Note that when using this font
michael@0 126 * loader, the key must be a pointer to an FallibleTArray<uint8_t>. This
michael@0 127 * array will be empty when the function returns.
michael@0 128 */
michael@0 129 static IDWriteFontFileLoader* Instance()
michael@0 130 {
michael@0 131 if (!mInstance) {
michael@0 132 mInstance = new gfxDWriteFontFileLoader();
michael@0 133 gfxWindowsPlatform::GetPlatform()->GetDWriteFactory()->
michael@0 134 RegisterFontFileLoader(mInstance);
michael@0 135 }
michael@0 136 return mInstance;
michael@0 137 }
michael@0 138
michael@0 139 private:
michael@0 140 static IDWriteFontFileLoader* mInstance;
michael@0 141 };
michael@0 142
michael@0 143 class gfxDWriteFontFileStream MOZ_FINAL : public IDWriteFontFileStream
michael@0 144 {
michael@0 145 public:
michael@0 146 /**
michael@0 147 * Used by the FontFileLoader to create a new font stream,
michael@0 148 * this font stream is created from data in memory. The memory
michael@0 149 * passed may be released after object creation, it will be
michael@0 150 * copied internally.
michael@0 151 *
michael@0 152 * @param aData Font data
michael@0 153 */
michael@0 154 gfxDWriteFontFileStream(FallibleTArray<uint8_t> *aData);
michael@0 155 ~gfxDWriteFontFileStream();
michael@0 156
michael@0 157 // IUnknown interface
michael@0 158 IFACEMETHOD(QueryInterface)(IID const& iid, OUT void** ppObject)
michael@0 159 {
michael@0 160 if (iid == __uuidof(IDWriteFontFileStream)) {
michael@0 161 *ppObject = static_cast<IDWriteFontFileStream*>(this);
michael@0 162 return S_OK;
michael@0 163 } else if (iid == __uuidof(IUnknown)) {
michael@0 164 *ppObject = static_cast<IUnknown*>(this);
michael@0 165 return S_OK;
michael@0 166 } else {
michael@0 167 return E_NOINTERFACE;
michael@0 168 }
michael@0 169 }
michael@0 170
michael@0 171 IFACEMETHOD_(ULONG, AddRef)()
michael@0 172 {
michael@0 173 NS_PRECONDITION(int32_t(mRefCnt) >= 0, "illegal refcnt");
michael@0 174 ++mRefCnt;
michael@0 175 return mRefCnt;
michael@0 176 }
michael@0 177
michael@0 178 IFACEMETHOD_(ULONG, Release)()
michael@0 179 {
michael@0 180 NS_PRECONDITION(0 != mRefCnt, "dup release");
michael@0 181 --mRefCnt;
michael@0 182 if (mRefCnt == 0) {
michael@0 183 delete this;
michael@0 184 return 0;
michael@0 185 }
michael@0 186 return mRefCnt;
michael@0 187 }
michael@0 188
michael@0 189 // IDWriteFontFileStream methods
michael@0 190 virtual HRESULT STDMETHODCALLTYPE ReadFileFragment(void const** fragmentStart,
michael@0 191 UINT64 fileOffset,
michael@0 192 UINT64 fragmentSize,
michael@0 193 OUT void** fragmentContext);
michael@0 194
michael@0 195 virtual void STDMETHODCALLTYPE ReleaseFileFragment(void* fragmentContext);
michael@0 196
michael@0 197 virtual HRESULT STDMETHODCALLTYPE GetFileSize(OUT UINT64* fileSize);
michael@0 198
michael@0 199 virtual HRESULT STDMETHODCALLTYPE GetLastWriteTime(OUT UINT64* lastWriteTime);
michael@0 200
michael@0 201 private:
michael@0 202 FallibleTArray<uint8_t> mData;
michael@0 203 nsAutoRefCnt mRefCnt;
michael@0 204 };
michael@0 205
michael@0 206 #endif /* GFX_DWRITECOMMON_H */

mercurial