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 #ifndef GFX_GDIFONT_H 7 #define GFX_GDIFONT_H 8 9 #include "mozilla/MemoryReporting.h" 10 #include "gfxFont.h" 11 #include "gfxGDIFontList.h" 12 13 #include "nsDataHashtable.h" 14 #include "nsHashKeys.h" 15 16 #include "cairo.h" 17 #include "usp10.h" 18 19 class gfxGDIFont : public gfxFont 20 { 21 public: 22 gfxGDIFont(GDIFontEntry *aFontEntry, 23 const gfxFontStyle *aFontStyle, 24 bool aNeedsBold, 25 AntialiasOption anAAOption = kAntialiasDefault); 26 27 virtual ~gfxGDIFont(); 28 GetHFONT()29 HFONT GetHFONT() { return mFont; } 30 CairoFontFace()31 cairo_font_face_t *CairoFontFace() { return mFontFace; } CairoScaledFont()32 cairo_scaled_font_t *CairoScaledFont() { return mScaledFont; } 33 34 /* overrides for the pure virtual methods in gfxFont */ 35 virtual uint32_t GetSpaceGlyph() override; 36 37 virtual bool SetupCairoFont(DrawTarget* aDrawTarget) override; 38 39 /* override Measure to add padding for antialiasing */ 40 virtual RunMetrics Measure(const gfxTextRun *aTextRun, 41 uint32_t aStart, uint32_t aEnd, 42 BoundingBoxType aBoundingBoxType, 43 DrawTarget *aDrawTargetForTightBoundingBox, 44 Spacing *aSpacing, 45 uint16_t aOrientation) override; 46 47 /* required for MathML to suppress effects of ClearType "padding" */ 48 virtual gfxFont* 49 CopyWithAntialiasOption(AntialiasOption anAAOption) override; 50 51 // If the font has a cmap table, we handle it purely with harfbuzz; 52 // but if not (e.g. .fon fonts), we'll use a GDI callback to get glyphs. ProvidesGetGlyph()53 virtual bool ProvidesGetGlyph() const override { 54 return !mFontEntry->HasCmapTable(); 55 } 56 57 virtual uint32_t GetGlyph(uint32_t aUnicode, 58 uint32_t aVarSelector) override; 59 ProvidesGlyphWidths()60 virtual bool ProvidesGlyphWidths() const override { return true; } 61 62 // get hinted glyph width in pixels as 16.16 fixed-point value 63 virtual int32_t GetGlyphWidth(DrawTarget& aDrawTarget, 64 uint16_t aGID) override; 65 66 virtual void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf, 67 FontCacheSizes* aSizes) const; 68 virtual void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf, 69 FontCacheSizes* aSizes) const; 70 GetType()71 virtual FontType GetType() const override { return FONT_TYPE_GDI; } 72 73 protected: 74 virtual const Metrics& GetHorizontalMetrics() override; 75 76 /* override to ensure the cairo font is set up properly */ 77 virtual bool ShapeText(DrawTarget *aDrawTarget, 78 const char16_t *aText, 79 uint32_t aOffset, 80 uint32_t aLength, 81 Script aScript, 82 bool aVertical, 83 gfxShapedText *aShapedText) override; 84 85 void Initialize(); // creates metrics and Cairo fonts 86 87 // Fill the given LOGFONT record according to our style, but don't adjust 88 // the lfItalic field if we're going to use a cairo transform for fake 89 // italics. 90 void FillLogFont(LOGFONTW& aLogFont, gfxFloat aSize, bool aUseGDIFakeItalic); 91 92 HFONT mFont; 93 cairo_font_face_t *mFontFace; 94 95 Metrics *mMetrics; 96 uint32_t mSpaceGlyph; 97 98 bool mNeedsBold; 99 100 // cache of glyph IDs (used for non-sfnt fonts only) 101 mozilla::UniquePtr<nsDataHashtable<nsUint32HashKey,uint32_t> > mGlyphIDs; 102 SCRIPT_CACHE mScriptCache; 103 104 // cache of glyph widths in 16.16 fixed-point pixels 105 mozilla::UniquePtr<nsDataHashtable<nsUint32HashKey,int32_t> > mGlyphWidths; 106 }; 107 108 #endif /* GFX_GDIFONT_H */ 109