aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ports
diff options
context:
space:
mode:
authorGravatar Bruce Wang <brucewang@google.com>2018-06-12 14:44:22 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-06-12 21:25:54 +0000
commit75e6490a2952849d72ecb1e59c97e36db8908884 (patch)
tree8468b08e5aec3c514c5f39189baefc040e5c76c9 /src/ports
parent2652223767c00c8b4ff5d805fd015a9b43910014 (diff)
Implement DWriteFontTypeface::onGetVariationDesignPosition on win10.
Copy into 'coordinates' (allocated by the caller) the design variation coordinates. Return the number of axes, or -1 if there is an error. Change-Id: Ie2fe88aaae358ec471aafd655b4ed0be80d43ae6 Reviewed-on: https://skia-review.googlesource.com/134329 Reviewed-by: Ben Wagner <bungeman@google.com> Commit-Queue: Bruce Wang <brucewang@google.com>
Diffstat (limited to 'src/ports')
-rw-r--r--src/ports/SkTypeface_win_dw.cpp49
-rw-r--r--src/ports/SkTypeface_win_dw.h5
2 files changed, 50 insertions, 4 deletions
diff --git a/src/ports/SkTypeface_win_dw.cpp b/src/ports/SkTypeface_win_dw.cpp
index aa88c4c911..a7bad0d24e 100644
--- a/src/ports/SkTypeface_win_dw.cpp
+++ b/src/ports/SkTypeface_win_dw.cpp
@@ -185,6 +185,55 @@ SkTypeface::LocalizedStrings* DWriteFontTypeface::onCreateFamilyNameIterator() c
return nameIter;
}
+int DWriteFontTypeface::onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[],
+ int coordinateCount) const {
+
+#if defined(NTDDI_WIN10_RS3) && NTDDI_VERSION >= NTDDI_WIN10_RS3
+
+ SkTScopedComPtr<IDWriteFontFace5> fontFace5;
+ if (FAILED(fDWriteFontFace->QueryInterface(&fontFace5))) {
+ return -1;
+ }
+
+ // Return 0 if the font is not variable font.
+ if (!fontFace5->HasVariations()) {
+ return 0;
+ }
+
+ UINT32 fontAxisCount = fontFace5->GetFontAxisValueCount();
+ SkTScopedComPtr<IDWriteFontResource> fontResource;
+ HR_GENERAL(fontFace5->GetFontResource(&fontResource), nullptr, -1);
+ int variableAxisCount = 0;
+ for (UINT32 i = 0; i < fontAxisCount; ++i) {
+ if (fontResource->GetFontAxisAttributes(i) & DWRITE_FONT_AXIS_ATTRIBUTES_VARIABLE) {
+ variableAxisCount++;
+ }
+ }
+
+ if (!coordinates || !coordinateCount || !variableAxisCount) {
+ return variableAxisCount;
+ }
+
+ SkAutoSTMalloc<8, DWRITE_FONT_AXIS_VALUE> fontAxisValue(fontAxisCount);
+ HR_GENERAL(fontFace5->GetFontAxisValues(fontAxisValue.get(), fontAxisCount), nullptr, -1);
+ UINT32 minCount = SkMin32(variableAxisCount, SkTo<UINT32>(coordinateCount));
+ UINT32 coordinatesIndex = 0;
+
+ for (UINT32 axisIndex = 0; axisIndex < fontAxisCount; ++axisIndex) {
+ if (fontResource->GetFontAxisAttributes(axisIndex) & DWRITE_FONT_AXIS_ATTRIBUTES_VARIABLE) {
+ coordinates[coordinatesIndex].axis = SkEndian_SwapBE32(fontAxisValue[axisIndex].axisTag);
+ coordinates[coordinatesIndex].value = fontAxisValue[axisIndex].value;
+ if (++coordinatesIndex == minCount) break;
+ }
+ }
+
+ return variableAxisCount;
+
+#endif
+
+ return -1;
+}
+
int DWriteFontTypeface::onGetTableTags(SkFontTableTag tags[]) const {
DWRITE_FONT_FACE_TYPE type = fDWriteFontFace->GetType();
if (type != DWRITE_FONT_FACE_TYPE_CFF &&
diff --git a/src/ports/SkTypeface_win_dw.h b/src/ports/SkTypeface_win_dw.h
index b443c28efe..2d76b39adb 100644
--- a/src/ports/SkTypeface_win_dw.h
+++ b/src/ports/SkTypeface_win_dw.h
@@ -116,10 +116,7 @@ protected:
void onGetFamilyName(SkString* familyName) const override;
SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override;
int onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[],
- int coordinateCount) const override
- {
- return -1;
- }
+ int coordinateCount) const override;
int onGetTableTags(SkFontTableTag tags[]) const override;
size_t onGetTableData(SkFontTableTag, size_t offset, size_t length, void* data) const override;