gfx/thebes/gfxFT2FontList.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_FT2FONTLIST_H
michael@0 7 #define GFX_FT2FONTLIST_H
michael@0 8
michael@0 9 #include "mozilla/MemoryReporting.h"
michael@0 10
michael@0 11 #ifdef XP_WIN
michael@0 12 #include "gfxWindowsPlatform.h"
michael@0 13 #include <windows.h>
michael@0 14 #endif
michael@0 15 #include "gfxPlatformFontList.h"
michael@0 16
michael@0 17 namespace mozilla {
michael@0 18 namespace dom {
michael@0 19 class FontListEntry;
michael@0 20 };
michael@0 21 };
michael@0 22 using mozilla::dom::FontListEntry;
michael@0 23
michael@0 24 class FontNameCache;
michael@0 25 typedef struct FT_FaceRec_* FT_Face;
michael@0 26 class nsZipArchive;
michael@0 27
michael@0 28 class FT2FontEntry : public gfxFontEntry
michael@0 29 {
michael@0 30 public:
michael@0 31 FT2FontEntry(const nsAString& aFaceName) :
michael@0 32 gfxFontEntry(aFaceName),
michael@0 33 mFTFace(nullptr),
michael@0 34 mFontFace(nullptr),
michael@0 35 mFTFontIndex(0)
michael@0 36 {
michael@0 37 }
michael@0 38
michael@0 39 ~FT2FontEntry();
michael@0 40
michael@0 41 const nsString& GetName() const {
michael@0 42 return Name();
michael@0 43 }
michael@0 44
michael@0 45 // create a font entry for a downloaded font
michael@0 46 static FT2FontEntry*
michael@0 47 CreateFontEntry(const gfxProxyFontEntry &aProxyEntry,
michael@0 48 const uint8_t *aFontData, uint32_t aLength);
michael@0 49
michael@0 50 // create a font entry representing an installed font, identified by
michael@0 51 // a FontListEntry; the freetype and cairo faces will not be instantiated
michael@0 52 // until actually needed
michael@0 53 static FT2FontEntry*
michael@0 54 CreateFontEntry(const FontListEntry& aFLE);
michael@0 55
michael@0 56 // Create a font entry for a given freetype face; if it is an installed font,
michael@0 57 // also record the filename and index.
michael@0 58 // aFontData (if non-nullptr) is NS_Malloc'ed data that aFace depends on,
michael@0 59 // to be freed after the face is destroyed
michael@0 60 static FT2FontEntry*
michael@0 61 CreateFontEntry(FT_Face aFace,
michael@0 62 const char *aFilename, uint8_t aIndex,
michael@0 63 const nsAString& aName,
michael@0 64 const uint8_t *aFontData = nullptr);
michael@0 65
michael@0 66 virtual gfxFont *CreateFontInstance(const gfxFontStyle *aFontStyle,
michael@0 67 bool aNeedsBold);
michael@0 68
michael@0 69 // Create (if necessary) and return the cairo_font_face for this font.
michael@0 70 // This may fail and return null, so caller must be prepared to handle this.
michael@0 71 cairo_font_face_t *CairoFontFace();
michael@0 72
michael@0 73 // Create a cairo_scaled_font for this face, with the given style.
michael@0 74 // This may fail and return null, so caller must be prepared to handle this.
michael@0 75 cairo_scaled_font_t *CreateScaledFont(const gfxFontStyle *aStyle);
michael@0 76
michael@0 77 nsresult ReadCMAP(FontInfoData *aFontInfoData = nullptr);
michael@0 78
michael@0 79 virtual hb_blob_t* GetFontTable(uint32_t aTableTag) MOZ_OVERRIDE;
michael@0 80
michael@0 81 virtual nsresult CopyFontTable(uint32_t aTableTag,
michael@0 82 FallibleTArray<uint8_t>& aBuffer) MOZ_OVERRIDE;
michael@0 83
michael@0 84 // Check for various kinds of brokenness, and set flags on the entry
michael@0 85 // accordingly so that we avoid using bad font tables
michael@0 86 void CheckForBrokenFont(gfxFontFamily *aFamily);
michael@0 87
michael@0 88 virtual void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf,
michael@0 89 FontListSizes* aSizes) const;
michael@0 90 virtual void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
michael@0 91 FontListSizes* aSizes) const;
michael@0 92
michael@0 93 FT_Face mFTFace;
michael@0 94 cairo_font_face_t *mFontFace;
michael@0 95
michael@0 96 nsCString mFilename;
michael@0 97 uint8_t mFTFontIndex;
michael@0 98 };
michael@0 99
michael@0 100 class FT2FontFamily : public gfxFontFamily
michael@0 101 {
michael@0 102 public:
michael@0 103 FT2FontFamily(const nsAString& aName) :
michael@0 104 gfxFontFamily(aName) { }
michael@0 105
michael@0 106 // Append this family's faces to the IPC fontlist
michael@0 107 void AddFacesToFontList(InfallibleTArray<FontListEntry>* aFontList);
michael@0 108 };
michael@0 109
michael@0 110 class gfxFT2FontList : public gfxPlatformFontList
michael@0 111 {
michael@0 112 public:
michael@0 113 gfxFT2FontList();
michael@0 114
michael@0 115 virtual gfxFontFamily* GetDefaultFont(const gfxFontStyle* aStyle);
michael@0 116
michael@0 117 virtual gfxFontEntry* LookupLocalFont(const gfxProxyFontEntry *aProxyEntry,
michael@0 118 const nsAString& aFontName);
michael@0 119
michael@0 120 virtual gfxFontEntry* MakePlatformFont(const gfxProxyFontEntry *aProxyEntry,
michael@0 121 const uint8_t *aFontData,
michael@0 122 uint32_t aLength);
michael@0 123
michael@0 124 void GetFontList(InfallibleTArray<FontListEntry>* retValue);
michael@0 125
michael@0 126 static gfxFT2FontList* PlatformFontList() {
michael@0 127 return static_cast<gfxFT2FontList*>(gfxPlatformFontList::PlatformFontList());
michael@0 128 }
michael@0 129
michael@0 130 protected:
michael@0 131 virtual nsresult InitFontList();
michael@0 132
michael@0 133 void AppendFaceFromFontListEntry(const FontListEntry& aFLE,
michael@0 134 bool isStdFile);
michael@0 135
michael@0 136 void AppendFacesFromFontFile(const nsCString& aFileName,
michael@0 137 bool isStdFile = false,
michael@0 138 FontNameCache *aCache = nullptr);
michael@0 139
michael@0 140 void AppendFacesFromOmnijarEntry(nsZipArchive *aReader,
michael@0 141 const nsCString& aEntryName,
michael@0 142 FontNameCache *aCache,
michael@0 143 bool aJarChanged);
michael@0 144
michael@0 145 void AppendFacesFromCachedFaceList(const nsCString& aFileName,
michael@0 146 bool isStdFile,
michael@0 147 const nsCString& aFaceList);
michael@0 148
michael@0 149 void AddFaceToList(const nsCString& aEntryName, uint32_t aIndex,
michael@0 150 bool aStdFile, FT_Face aFace, nsCString& aFaceList);
michael@0 151
michael@0 152 void FindFonts();
michael@0 153
michael@0 154 void FindFontsInOmnijar(FontNameCache *aCache);
michael@0 155
michael@0 156 #ifdef ANDROID
michael@0 157 void FindFontsInDir(const nsCString& aDir, FontNameCache* aFNC);
michael@0 158 #endif
michael@0 159
michael@0 160 nsTHashtable<nsStringHashKey> mSkipSpaceLookupCheckFamilies;
michael@0 161 };
michael@0 162
michael@0 163 #endif /* GFX_FT2FONTLIST_H */

mercurial