Debian Codegraph @

src/ports/SkTypeface_mac_ct.h

raw ◀ ▶
1 Debian patch touch this file
1 /*
2 * Copyright 2020 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef SkTypeface_mac_ct_DEFINED
9 #define SkTypeface_mac_ct_DEFINED
10
11 #include "include/core/SkTypes.h"
12 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
13
14 #include "include/core/SkFontArguments.h"
15 #include "include/core/SkFontParameters.h"
16 #include "include/core/SkFontStyle.h"
17 #include "include/core/SkRefCnt.h"
18 #include "include/core/SkScalar.h"
19 #include "include/core/SkStream.h"
20 #include "include/core/SkTypeface.h"
21 #include "include/private/base/SkOnce.h"
•22 #include "src/base/SkSharedMutex.h"
23 #include "src/utils/mac/SkUniqueCFRef.h"
24
25 #ifdef SK_BUILD_FOR_MAC
26 #import <ApplicationServices/ApplicationServices.h>
27 #endif
28
29 #ifdef SK_BUILD_FOR_IOS
30 #include <CoreText/CoreText.h>
31 #include <CoreText/CTFontManager.h>
32 #include <CoreGraphics/CoreGraphics.h>
33 #include <CoreFoundation/CoreFoundation.h>
34 #endif
35
36 #include <memory>
37
38 class SkData;
39 class SkDescriptor;
40 class SkFontData;
41 class SkFontDescriptor;
42 class SkScalerContext;
43 class SkString;
44 struct SkAdvancedTypefaceMetrics;
45 struct SkScalerContextEffects;
46 struct SkScalerContextRec;
47
48 struct OpszVariation {
49 bool isSet = false;
50 double value = 0;
51 };
52
53 struct CTFontVariation {
54 SkUniqueCFRef<CFDictionaryRef> variation;
55 SkUniqueCFRef<CFDictionaryRef> wrongOpszVariation;
56 OpszVariation opsz;
57 };
58
59 SkFontStyle SkCTFontDescriptorGetSkFontStyle(CTFontDescriptorRef desc, bool fromDataProvider);
60
61 CGFloat SkCTFontCTWeightForCSSWeight(int fontstyleWeight);
62 CGFloat SkCTFontCTWidthForCSSWidth(int fontstyleWidth);
63
64 void SkStringFromCFString(CFStringRef src, SkString* dst);
65
66 class SkTypeface_Mac : public SkTypeface {
67 private:
68 SkTypeface_Mac(SkUniqueCFRef<CTFontRef> fontRef, const SkFontStyle& fs, bool isFixedPitch,
69 OpszVariation opszVariation, std::unique_ptr<SkStreamAsset> providedData)
70 : SkTypeface(fs, isFixedPitch)
71 , fFontRef(std::move(fontRef))
72 , fOpszVariation(opszVariation)
73 , fHasColorGlyphs(
74 SkToBool(CTFontGetSymbolicTraits(fFontRef.get()) & kCTFontColorGlyphsTrait))
75 , fStream(std::move(providedData))
76 , fIsFromStream(fStream)
77 {
78 SkASSERT(fFontRef);
79 }
80
81 public:
82 static sk_sp<SkTypeface> Make(SkUniqueCFRef<CTFontRef> font,
83 OpszVariation opszVariation,
84 std::unique_ptr<SkStreamAsset> providedData);
85
86 static constexpr SkTypeface::FactoryId FactoryId = SkSetFourByteTag('c','t','x','t');
87 static sk_sp<SkTypeface> SK_SPI MakeFromStream(std::unique_ptr<SkStreamAsset>,
88 const SkFontArguments&);
89
90 SkUniqueCFRef<CTFontRef> fFontRef;
91 const OpszVariation fOpszVariation;
92 const bool fHasColorGlyphs;
93
94 /**
95 * CTFontCopyVariationAxes provides the localized name of all axes, making it very slow.
96 * This is unfortunate, its result is needed just to see if there are any axes at all.
97 * To avoid calling internal APIs cache the result of CTFontCopyVariationAxes.
98 * https://github.com/WebKit/WebKit/commit/1842365d413ed87868e7d33d4fad1691fa3a8129
99 * https://bugs.webkit.org/show_bug.cgi?id=232690
100 */
101 CFArrayRef getVariationAxes() const;
102
103 protected:
104 int onGetUPEM() const override;
105 std::unique_ptr<SkStreamAsset> onOpenStream(int* ttcIndex) const override;
106 std::unique_ptr<SkStreamAsset> onOpenExistingStream(int* ttcIndex) const override;
107 bool onGlyphMaskNeedsCurrentColor() const override;
108 int onGetVariationDesignPosition(
109 SkSpan<SkFontArguments::VariationPosition::Coordinate>) const override;
110 void onGetFamilyName(SkString* familyName) const override;
111 bool onGetPostScriptName(SkString*) const override;
112 SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override;
113 int onGetTableTags(SkSpan<SkFontTableTag>) const override;
114 size_t onGetTableData(SkFontTableTag, size_t offset, size_t length, void* data) const override;
115 sk_sp<SkData> onCopyTableData(SkFontTableTag) const override;
116 std::unique_ptr<SkScalerContext> onCreateScalerContext(const SkScalerContextEffects&,
117 const SkDescriptor*) const override;
118 void onFilterRec(SkScalerContextRec*) const override;
119 void onGetFontDescriptor(SkFontDescriptor*, bool*) const override;
120 void getGlyphToUnicodeMap(SkSpan<SkUnichar>) const override;
121 std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override;
122 void onCharsToGlyphs(SkSpan<const SkUnichar>, SkSpan<SkGlyphID>) const override;
123 int onCountGlyphs() const override;
124 void getPostScriptGlyphNames(SkString*) const override {}
125 int onGetVariationDesignParameters(SkSpan<SkFontParameters::Variation::Axis>) const override;
126 sk_sp<SkTypeface> onMakeClone(const SkFontArguments&) const override;
127
128 void* onGetCTFontRef() const override { return (void*)fFontRef.get(); }
129
130 private:
131 mutable std::unique_ptr<SkStreamAsset> fStream;
132 mutable SkUniqueCFRef<CFArrayRef> fVariationAxes;
•133 mutable SkSharedMutex fStreamMutex;
134 bool fIsFromStream;
135 mutable SkOnce fInitVariationAxes;
136
137 using INHERITED = SkTypeface;
138 };
139
140 #endif
141 #endif //SkTypeface_mac_ct_DEFINED