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/. */
9 #include "mozilla/MemoryReporting.h"
11 #include "gfxGDIFontList.h"
13 #include "nsDataHashtable.h"
14 #include "nsHashKeys.h"
18 class gfxGDIFont
: public gfxFont
21 gfxGDIFont(GDIFontEntry
*aFontEntry
,
22 const gfxFontStyle
*aFontStyle
,
24 AntialiasOption anAAOption
= kAntialiasDefault
);
26 virtual ~gfxGDIFont();
28 HFONT
GetHFONT() { if (!mMetrics
) Initialize(); return mFont
; }
30 gfxFloat
GetAdjustedSize() { if (!mMetrics
) Initialize(); return mAdjustedSize
; }
32 cairo_font_face_t
*CairoFontFace() { return mFontFace
; }
33 cairo_scaled_font_t
*CairoScaledFont() { return mScaledFont
; }
35 /* overrides for the pure virtual methods in gfxFont */
36 virtual const gfxFont::Metrics
& GetMetrics();
38 virtual uint32_t GetSpaceGlyph();
40 virtual bool SetupCairoFont(gfxContext
*aContext
);
42 /* override Measure to add padding for antialiasing */
43 virtual RunMetrics
Measure(gfxTextRun
*aTextRun
,
44 uint32_t aStart
, uint32_t aEnd
,
45 BoundingBoxType aBoundingBoxType
,
46 gfxContext
*aContextForTightBoundingBox
,
49 /* required for MathML to suppress effects of ClearType "padding" */
50 virtual gfxFont
* CopyWithAntialiasOption(AntialiasOption anAAOption
);
52 virtual bool ProvidesGlyphWidths() { return true; }
54 // get hinted glyph width in pixels as 16.16 fixed-point value
55 virtual int32_t GetGlyphWidth(gfxContext
*aCtx
, uint16_t aGID
);
57 virtual void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf
,
58 FontCacheSizes
* aSizes
) const;
59 virtual void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf
,
60 FontCacheSizes
* aSizes
) const;
62 virtual FontType
GetType() const { return FONT_TYPE_GDI
; }
65 virtual void CreatePlatformShaper();
67 /* override to check for uniscribe failure and fall back to GDI */
68 virtual bool ShapeText(gfxContext
*aContext
,
69 const PRUnichar
*aText
,
73 gfxShapedText
*aShapedText
,
74 bool aPreferPlatformShaping
);
76 void Initialize(); // creates metrics and Cairo fonts
78 // Fill the given LOGFONT record according to our style, but don't adjust
79 // the lfItalic field if we're going to use a cairo transform for fake
81 void FillLogFont(LOGFONTW
& aLogFont
, gfxFloat aSize
, bool aUseGDIFakeItalic
);
83 // mPlatformShaper is used for the GDI shaper, mUniscribeShaper
84 // for the Uniscribe version if needed
85 nsAutoPtr
<gfxFontShaper
> mUniscribeShaper
;
88 cairo_font_face_t
*mFontFace
;
95 // cache of glyph widths in 16.16 fixed-point pixels
96 nsAutoPtr
<nsDataHashtable
<nsUint32HashKey
,int32_t> > mGlyphWidths
;
99 #endif /* GFX_GDIFONT_H */