|
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_WINDOWSDWRITEFONTS_H |
|
7 #define GFX_WINDOWSDWRITEFONTS_H |
|
8 |
|
9 #include "mozilla/MemoryReporting.h" |
|
10 #include <dwrite.h> |
|
11 |
|
12 #include "gfxFont.h" |
|
13 #include "gfxUserFontSet.h" |
|
14 #include "cairo-win32.h" |
|
15 |
|
16 #include "nsDataHashtable.h" |
|
17 #include "nsHashKeys.h" |
|
18 |
|
19 /** |
|
20 * \brief Class representing a font face for a font entry. |
|
21 */ |
|
22 class gfxDWriteFont : public gfxFont |
|
23 { |
|
24 public: |
|
25 gfxDWriteFont(gfxFontEntry *aFontEntry, |
|
26 const gfxFontStyle *aFontStyle, |
|
27 bool aNeedsBold = false, |
|
28 AntialiasOption = kAntialiasDefault); |
|
29 ~gfxDWriteFont(); |
|
30 |
|
31 virtual gfxFont* CopyWithAntialiasOption(AntialiasOption anAAOption); |
|
32 |
|
33 virtual const gfxFont::Metrics& GetMetrics(); |
|
34 |
|
35 virtual uint32_t GetSpaceGlyph(); |
|
36 |
|
37 virtual bool SetupCairoFont(gfxContext *aContext); |
|
38 |
|
39 virtual bool AllowSubpixelAA() { return mAllowManualShowGlyphs; } |
|
40 |
|
41 virtual bool IsValid(); |
|
42 |
|
43 gfxFloat GetAdjustedSize() { |
|
44 return mAdjustedSize; |
|
45 } |
|
46 |
|
47 IDWriteFontFace *GetFontFace(); |
|
48 |
|
49 /* override Measure to add padding for antialiasing */ |
|
50 virtual RunMetrics Measure(gfxTextRun *aTextRun, |
|
51 uint32_t aStart, uint32_t aEnd, |
|
52 BoundingBoxType aBoundingBoxType, |
|
53 gfxContext *aContextForTightBoundingBox, |
|
54 Spacing *aSpacing); |
|
55 |
|
56 virtual bool ProvidesGlyphWidths(); |
|
57 |
|
58 virtual int32_t GetGlyphWidth(gfxContext *aCtx, uint16_t aGID); |
|
59 |
|
60 virtual mozilla::TemporaryRef<mozilla::gfx::GlyphRenderingOptions> GetGlyphRenderingOptions(); |
|
61 |
|
62 virtual void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf, |
|
63 FontCacheSizes* aSizes) const; |
|
64 virtual void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf, |
|
65 FontCacheSizes* aSizes) const; |
|
66 |
|
67 virtual FontType GetType() const { return FONT_TYPE_DWRITE; } |
|
68 |
|
69 virtual mozilla::TemporaryRef<mozilla::gfx::ScaledFont> GetScaledFont(mozilla::gfx::DrawTarget *aTarget); |
|
70 |
|
71 virtual cairo_scaled_font_t *GetCairoScaledFont(); |
|
72 |
|
73 protected: |
|
74 friend class gfxDWriteShaper; |
|
75 |
|
76 virtual void CreatePlatformShaper(); |
|
77 |
|
78 bool GetFakeMetricsForArialBlack(DWRITE_FONT_METRICS *aFontMetrics); |
|
79 |
|
80 void ComputeMetrics(AntialiasOption anAAOption); |
|
81 |
|
82 bool HasBitmapStrikeForSize(uint32_t aSize); |
|
83 |
|
84 cairo_font_face_t *CairoFontFace(); |
|
85 |
|
86 gfxFloat MeasureGlyphWidth(uint16_t aGlyph); |
|
87 |
|
88 DWRITE_MEASURING_MODE GetMeasuringMode(); |
|
89 bool GetForceGDIClassic(); |
|
90 |
|
91 nsRefPtr<IDWriteFontFace> mFontFace; |
|
92 cairo_font_face_t *mCairoFontFace; |
|
93 |
|
94 gfxFont::Metrics *mMetrics; |
|
95 |
|
96 // cache of glyph widths in 16.16 fixed-point pixels |
|
97 nsAutoPtr<nsDataHashtable<nsUint32HashKey,int32_t> > mGlyphWidths; |
|
98 |
|
99 bool mNeedsOblique; |
|
100 bool mNeedsBold; |
|
101 bool mUseSubpixelPositions; |
|
102 bool mAllowManualShowGlyphs; |
|
103 bool mAzureScaledFontIsCairo; |
|
104 }; |
|
105 |
|
106 #endif |