|
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_MACFONT_H |
|
7 #define GFX_MACFONT_H |
|
8 |
|
9 #include "mozilla/MemoryReporting.h" |
|
10 #include "gfxFont.h" |
|
11 #include "cairo.h" |
|
12 #include <ApplicationServices/ApplicationServices.h> |
|
13 |
|
14 class MacOSFontEntry; |
|
15 |
|
16 class gfxMacFont : public gfxFont |
|
17 { |
|
18 public: |
|
19 gfxMacFont(MacOSFontEntry *aFontEntry, const gfxFontStyle *aFontStyle, |
|
20 bool aNeedsBold); |
|
21 |
|
22 virtual ~gfxMacFont(); |
|
23 |
|
24 CGFontRef GetCGFontRef() const { return mCGFont; } |
|
25 |
|
26 /* overrides for the pure virtual methods in gfxFont */ |
|
27 virtual const gfxFont::Metrics& GetMetrics() { |
|
28 return mMetrics; |
|
29 } |
|
30 |
|
31 virtual uint32_t GetSpaceGlyph() { |
|
32 return mSpaceGlyph; |
|
33 } |
|
34 |
|
35 virtual bool SetupCairoFont(gfxContext *aContext); |
|
36 |
|
37 /* override Measure to add padding for antialiasing */ |
|
38 virtual RunMetrics Measure(gfxTextRun *aTextRun, |
|
39 uint32_t aStart, uint32_t aEnd, |
|
40 BoundingBoxType aBoundingBoxType, |
|
41 gfxContext *aContextForTightBoundingBox, |
|
42 Spacing *aSpacing); |
|
43 |
|
44 virtual mozilla::TemporaryRef<mozilla::gfx::ScaledFont> GetScaledFont(mozilla::gfx::DrawTarget *aTarget); |
|
45 |
|
46 virtual void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf, |
|
47 FontCacheSizes* aSizes) const; |
|
48 virtual void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf, |
|
49 FontCacheSizes* aSizes) const; |
|
50 |
|
51 virtual FontType GetType() const { return FONT_TYPE_MAC; } |
|
52 |
|
53 protected: |
|
54 virtual void CreatePlatformShaper(); |
|
55 |
|
56 // override to prefer CoreText shaping with fonts that depend on AAT |
|
57 virtual bool ShapeText(gfxContext *aContext, |
|
58 const char16_t *aText, |
|
59 uint32_t aOffset, |
|
60 uint32_t aLength, |
|
61 int32_t aScript, |
|
62 gfxShapedText *aShapedText, |
|
63 bool aPreferPlatformShaping = false); |
|
64 |
|
65 void InitMetrics(); |
|
66 void InitMetricsFromPlatform(); |
|
67 |
|
68 // Get width and glyph ID for a character; uses aConvFactor |
|
69 // to convert font units as returned by CG to actual dimensions |
|
70 gfxFloat GetCharWidth(CFDataRef aCmap, char16_t aUniChar, |
|
71 uint32_t *aGlyphID, gfxFloat aConvFactor); |
|
72 |
|
73 // a weak reference to the CoreGraphics font: this is owned by the |
|
74 // MacOSFontEntry, it is not retained or released by gfxMacFont |
|
75 CGFontRef mCGFont; |
|
76 |
|
77 cairo_font_face_t *mFontFace; |
|
78 |
|
79 Metrics mMetrics; |
|
80 uint32_t mSpaceGlyph; |
|
81 }; |
|
82 |
|
83 #endif /* GFX_MACFONT_H */ |