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>
This commit is contained in:
Bruce Wang 2018-06-12 14:44:22 -04:00 committed by Skia Commit-Bot
parent 2652223767
commit 75e6490a29
3 changed files with 51 additions and 5 deletions

View File

@ -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 &&

View File

@ -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;

View File

@ -174,7 +174,7 @@ DEF_TEST(TypefaceAxes, reporter) {
// Convert to fixed for "almost equal".
SkFixed fixedRead = SkScalarToFixed(positionRead[0].value);
SkFixed fixedOriginal = SkScalarToFixed(position[1].value);
REPORTER_ASSERT(reporter, fixedRead == fixedOriginal);
REPORTER_ASSERT(reporter, SkTAbs(fixedRead - fixedOriginal) < 2);
}
DEF_TEST(TypefaceVariationIndex, reporter) {