diff options
author | Ben Wagner <bungeman@google.com> | 2017-02-17 18:38:52 +0000 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-02-17 18:39:09 +0000 |
commit | 7d07d4663822c05e421f1f50460a985ab43adac4 (patch) | |
tree | 708aca529955646b35468d4364dd75517765ad9a /src/ports/SkFontHost_mac.cpp | |
parent | 87e7f820f74a990a59fb8f1d5c182584ce586ecf (diff) |
Revert "Add SkTypeface::getVariationDesignPosition."
This reverts commit 87e7f820f74a990a59fb8f1d5c182584ce586ecf.
Reason for revert: Failed a test on Mac
Original change's description:
> Add SkTypeface::getVariationDesignPosition.
>
> Allow users to query a typeface's position in variation design space.
>
> Change-Id: I5d80c8ff658708a5d1aa386ec5b7396dcb621198
> Reviewed-on: https://skia-review.googlesource.com/7130
> Commit-Queue: Ben Wagner <bungeman@google.com>
> Reviewed-by: Mike Reed <reed@google.com>
>
TBR=bungeman@google.com,reed@google.com,reviews@skia.org,drott@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
Change-Id: Ia65792083642dbe9333a62eb75d162931b57cffd
Reviewed-on: https://skia-review.googlesource.com/8670
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
Diffstat (limited to 'src/ports/SkFontHost_mac.cpp')
-rw-r--r-- | src/ports/SkFontHost_mac.cpp | 163 |
1 files changed, 59 insertions, 104 deletions
diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp index 5ec6b6e600..7a46d40ec6 100644 --- a/src/ports/SkFontHost_mac.cpp +++ b/src/ports/SkFontHost_mac.cpp @@ -492,8 +492,6 @@ protected: int onGetUPEM() const override; SkStreamAsset* onOpenStream(int* ttcIndex) const override; std::unique_ptr<SkFontData> onMakeFontData() const override; - int onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[], - int coordinateCount) const override; void onGetFamilyName(SkString* familyName) const override; SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override; int onGetTableTags(SkFontTableTag tags[]) const override; @@ -1697,14 +1695,13 @@ static void set_non_default_axes(CFTypeRef key, CFTypeRef value, void* context) } self->axisValue[keyIndex] = SkDoubleToFixed(valueDouble); } -static bool get_variations(CTFontRef ctFont, CFIndex* cgAxisCount, +static bool get_variations(CTFontRef fFontRef, CFIndex* cgAxisCount, SkAutoSTMalloc<4, SkFixed>* axisValues) { - // In 10.10 and earlier, CTFontCopyVariationAxes and CTFontCopyVariation do not work when - // applied to fonts which started life with CGFontCreateWithDataProvider (they simply always - // return nullptr). As a result, we are limited to CGFontCopyVariationAxes and - // CGFontCopyVariations here until support for 10.10 and earlier is removed. - UniqueCFRef<CGFontRef> cgFont(CTFontCopyGraphicsFont(ctFont, nullptr)); + // CTFontCopyVariationAxes and CTFontCopyVariation do not work when applied to fonts which + // started life with CGFontCreateWithDataProvider (they simply always return nullptr). + // As a result, we are limited to CGFontCopyVariationAxes and CGFontCopyVariations. + UniqueCFRef<CGFontRef> cgFont(CTFontCopyGraphicsFont(fFontRef, nullptr)); if (!cgFont) { return false; } @@ -1769,74 +1766,6 @@ std::unique_ptr<SkFontData> SkTypeface_Mac::onMakeFontData() const { return skstd::make_unique<SkFontData>(std::move(stream), index, nullptr, 0); } -int SkTypeface_Mac::onGetVariationDesignPosition( - SkFontArguments::VariationPosition::Coordinate coordinates[], int coordinateCount) const -{ - // The CGFont variation data does not contain the tag. - - // This call always returns nullptr on 10.10 and under for CGFontCreateWithDataProvider fonts. - // When this happens, there is no API to provide the tag. - UniqueCFRef<CFArrayRef> ctAxes(CTFontCopyVariationAxes(fFontRef.get())); - if (!ctAxes) { - return -1; - } - CFIndex axisCount = CFArrayGetCount(ctAxes.get()); - if (!coordinates || coordinateCount < axisCount) { - return axisCount; - } - - // This call always returns nullptr on 10.10 and under for CGFontCreateWithDataProvider fonts. - // When this happens, there is no API to provide the tag. - // On 10.12 and later, this only returns non-default variations. - UniqueCFRef<CFDictionaryRef> ctVariations(CTFontCopyVariation(fFontRef.get())); - if (!ctVariations) { - return -1; - } - - for (int i = 0; i < axisCount; ++i) { - CFTypeRef axisInfo = CFArrayGetValueAtIndex(ctAxes.get(), i); - if (CFDictionaryGetTypeID() != CFGetTypeID(axisInfo)) { - return -1; - } - CFDictionaryRef axisInfoDict = static_cast<CFDictionaryRef>(axisInfo); - - CFTypeRef tag = CFDictionaryGetValue(axisInfoDict, kCTFontVariationAxisIdentifierKey); - if (!tag || CFGetTypeID(tag) != CFNumberGetTypeID()) { - return -1; - } - CFNumberRef tagNumber = static_cast<CFNumberRef>(tag); - int64_t tagLong; - if (!CFNumberGetValue(tagNumber, kCFNumberSInt64Type, &tagLong)) { - return -1; - } - coordinates[i].axis = tagLong; - - CGFloat variationCGFloat; - CFTypeRef variationValue = CFDictionaryGetValue(ctVariations.get(), tagNumber); - if (variationValue) { - if (CFGetTypeID(variationValue) != CFNumberGetTypeID()) { - return -1; - } - CFNumberRef variationNumber = static_cast<CFNumberRef>(variationValue); - if (!CFNumberGetValue(variationNumber, kCFNumberCGFloatType, &variationCGFloat)) { - return -1; - } - } else { - CFTypeRef def = CFDictionaryGetValue(axisInfoDict, kCTFontVariationAxisDefaultValueKey); - if (!def || CFGetTypeID(def) != CFNumberGetTypeID()) { - return -1; - } - CFNumberRef defNumber = static_cast<CFNumberRef>(def); - if (!CFNumberGetValue(defNumber, kCFNumberCGFloatType, &variationCGFloat)) { - return -1; - } - } - coordinates[i].value = CGToScalar(variationCGFloat); - - } - return axisCount; -} - /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// @@ -2330,23 +2259,52 @@ protected: return create_from_dataProvider(std::move(pr)); } - /** Creates a dictionary suitable for setting the axes on a CGFont. */ - static UniqueCFRef<CFDictionaryRef> copy_axes(CGFontRef cg, const SkFontArguments& args) { - // The CGFont variation data is keyed by name, but lacks the tag. + static CFNumberRef get_tag_for_name(CFStringRef name, CFArrayRef ctAxes) { + CFIndex ctAxisCount = CFArrayGetCount(ctAxes); + for (int i = 0; i < ctAxisCount; ++i) { + CFTypeRef ctAxisInfo = CFArrayGetValueAtIndex(ctAxes, i); + if (CFDictionaryGetTypeID() != CFGetTypeID(ctAxisInfo)) { + return nullptr; + } + CFDictionaryRef ctAxisInfoDict = static_cast<CFDictionaryRef>(ctAxisInfo); + + CFTypeRef ctAxisName = CFDictionaryGetValue(ctAxisInfoDict, + kCTFontVariationAxisNameKey); + if (!ctAxisName || CFGetTypeID(ctAxisName) != CFStringGetTypeID()) { + return nullptr; + } + + if (CFEqual(name, ctAxisName)) { + CFTypeRef tag = CFDictionaryGetValue(ctAxisInfoDict, + kCTFontVariationAxisIdentifierKey); + if (!tag || CFGetTypeID(tag) != CFNumberGetTypeID()) { + return nullptr; + } + return static_cast<CFNumberRef>(tag); + } + } + return nullptr; + } + static UniqueCFRef<CFDictionaryRef> copy_axes(CGFontRef cg, const FontParameters& params) { + UniqueCFRef<CFArrayRef> cgAxes(CGFontCopyVariationAxes(cg)); + if (!cgAxes) { + return nullptr; + } + CFIndex axisCount = CFArrayGetCount(cgAxes.get()); + + // The CGFont variation data is keyed by name, and lacks the tag. // The CTFont variation data is keyed by tag, and also has the name. - // We would like to work with CTFont variations, but creating a CTFont font with + // We would like to work with CTFont variaitons, but creating a CTFont font with // CTFont variation dictionary runs into bugs. So use the CTFont variation data // to match names to tags to create the appropriate CGFont. UniqueCFRef<CTFontRef> ct(CTFontCreateWithGraphicsFont(cg, 0, nullptr, nullptr)); - // This call always returns nullptr on 10.10 and under. - // When this happens, there is no API to provide the tag. UniqueCFRef<CFArrayRef> ctAxes(CTFontCopyVariationAxes(ct.get())); - if (!ctAxes) { + if (!ctAxes || CFArrayGetCount(ctAxes.get()) != axisCount) { return nullptr; } - CFIndex axisCount = CFArrayGetCount(ctAxes.get()); - const SkFontArguments::VariationPosition position = args.getVariationDesignPosition(); + int paramAxisCount; + const FontParameters::Axis* paramAxes = params.getAxes(¶mAxisCount); UniqueCFRef<CFMutableDictionaryRef> dict( CFDictionaryCreateMutable(kCFAllocatorDefault, axisCount, @@ -2354,25 +2312,24 @@ protected: &kCFTypeDictionaryValueCallBacks)); for (int i = 0; i < axisCount; ++i) { - CFTypeRef axisInfo = CFArrayGetValueAtIndex(ctAxes.get(), i); + CFTypeRef axisInfo = CFArrayGetValueAtIndex(cgAxes.get(), i); if (CFDictionaryGetTypeID() != CFGetTypeID(axisInfo)) { return nullptr; } CFDictionaryRef axisInfoDict = static_cast<CFDictionaryRef>(axisInfo); - // The assumption is that values produced by kCTFontVariationAxisNameKey and - // kCGFontVariationAxisName will always be equal. - // If they are ever not, seach the project history for "get_tag_for_name". - CFTypeRef axisName = CFDictionaryGetValue(axisInfoDict, kCTFontVariationAxisNameKey); + CFTypeRef axisName = CFDictionaryGetValue(axisInfoDict, kCGFontVariationAxisName); if (!axisName || CFGetTypeID(axisName) != CFStringGetTypeID()) { return nullptr; } - CFTypeRef tag = CFDictionaryGetValue(axisInfoDict, kCTFontVariationAxisIdentifierKey); - if (!tag || CFGetTypeID(tag) != CFNumberGetTypeID()) { - return nullptr; + CFNumberRef tagNumber = + get_tag_for_name(static_cast<CFStringRef>(axisName), ctAxes.get()); + if (!tagNumber) { + // Could not find a tag to go with the name of this index. + // This would be a bug in CG/CT. + continue; } - CFNumberRef tagNumber = static_cast<CFNumberRef>(tag); int64_t tagLong; if (!CFNumberGetValue(tagNumber, kCFNumberSInt64Type, &tagLong)) { return nullptr; @@ -2380,9 +2337,9 @@ protected: // The variation axes can be set to any value, but cg will effectively pin them. // Pin them here to normalize. - CFTypeRef min = CFDictionaryGetValue(axisInfoDict, kCTFontVariationAxisMinimumValueKey); - CFTypeRef max = CFDictionaryGetValue(axisInfoDict, kCTFontVariationAxisMaximumValueKey); - CFTypeRef def = CFDictionaryGetValue(axisInfoDict, kCTFontVariationAxisDefaultValueKey); + CFTypeRef min = CFDictionaryGetValue(axisInfoDict, kCGFontVariationAxisMinValue); + CFTypeRef max = CFDictionaryGetValue(axisInfoDict, kCGFontVariationAxisMaxValue); + CFTypeRef def = CFDictionaryGetValue(axisInfoDict, kCGFontVariationAxisDefaultValue); if (!min || CFGetTypeID(min) != CFNumberGetTypeID() || !max || CFGetTypeID(max) != CFNumberGetTypeID() || !def || CFGetTypeID(def) != CFNumberGetTypeID()) @@ -2403,10 +2360,9 @@ protected: } double value = defDouble; - for (int j = 0; j < position.coordinateCount; ++j) { - if (position.coordinates[j].axis == tagLong) { - value = SkTPin(SkScalarToDouble(position.coordinates[j].value), - minDouble, maxDouble); + for (int j = 0; j < paramAxisCount; ++j) { + if (paramAxes[j].fTag == tagLong) { + value = SkTPin(SkScalarToDouble(paramAxes[j].fStyleValue),minDouble,maxDouble); break; } } @@ -2416,7 +2372,7 @@ protected: } return std::move(dict); } - SkTypeface* onCreateFromStream(SkStreamAsset* bs, const SkFontArguments& args) const override { + SkTypeface* onCreateFromStream(SkStreamAsset* bs, const FontParameters& params) const override { std::unique_ptr<SkStreamAsset> s(bs); UniqueCFRef<CGDataProviderRef> provider(SkCreateDataProviderFromStream(std::move(s))); if (!provider) { @@ -2427,7 +2383,7 @@ protected: return nullptr; } - UniqueCFRef<CFDictionaryRef> cgVariations = copy_axes(cg.get(), args); + UniqueCFRef<CFDictionaryRef> cgVariations = copy_axes(cg.get(), params); // The CGFontRef returned by CGFontCreateCopyWithVariations when the passed CGFontRef was // created from a data provider does not appear to have any ownership of the underlying // data. The original CGFontRef must be kept alive until the copy will no longer be used. @@ -2446,7 +2402,6 @@ protected: return create_from_CTFontRef(std::move(ct), std::move(cg), true); } - /** Creates a dictionary suitable for setting the axes on a CGFont. */ static UniqueCFRef<CFDictionaryRef> copy_axes(CGFontRef cg, SkFontData* fontData) { UniqueCFRef<CFArrayRef> cgAxes(CGFontCopyVariationAxes(cg)); if (!cgAxes) { |