Convert font width values from variable axes to SkFontStyle widths
A recent change added support for using the width variable axis to override the usWidthClass value from the font's OS/2 table. However, the width axis uses a different value scale. This PR converts the axis value to a usWidthClass value that is equivalent to the SkFontStyle Width enum. Change-Id: I6ce78f4dcad3abdcf3e00bd524ffb08a57e51919 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/505356 Reviewed-by: Ben Wagner <bungeman@google.com> Commit-Queue: Ben Wagner <bungeman@google.com>
This commit is contained in:
parent
07b639da6f
commit
9116bd3bee
@ -140,8 +140,8 @@ bool SkFontDescriptor::Deserialize(SkStream* stream, SkFontDescriptor* result) {
|
||||
SkFontStyle::Slant slantEnum = SkFontStyle::kUpright_Slant;
|
||||
if (slant != 0) { slantEnum = SkFontStyle::kOblique_Slant; }
|
||||
if (0 < italic) { slantEnum = SkFontStyle::kItalic_Slant; }
|
||||
int usWidth = SkScalarRoundToInt(SkScalarInterpFunc(width, &width_for_usWidth[1], usWidths, 9));
|
||||
result->fStyle = SkFontStyle(SkScalarRoundToInt(weight), usWidth, slantEnum);
|
||||
SkFontStyle::Width widthEnum = SkFontStyleWidthForWidthAxisValue(width);
|
||||
result->fStyle = SkFontStyle(SkScalarRoundToInt(weight), widthEnum, slantEnum);
|
||||
|
||||
size_t length;
|
||||
if (!stream->readPackedUInt(&length)) { return false; }
|
||||
@ -191,3 +191,8 @@ void SkFontDescriptor::serialize(SkWStream* stream) const {
|
||||
stream->writePackedUInt(0);
|
||||
}
|
||||
}
|
||||
|
||||
SkFontStyle::Width SkFontDescriptor::SkFontStyleWidthForWidthAxisValue(SkScalar width) {
|
||||
int usWidth = SkScalarRoundToInt(SkScalarInterpFunc(width, &width_for_usWidth[1], usWidths, 9));
|
||||
return static_cast<SkFontStyle::Width>(usWidth);
|
||||
}
|
||||
|
@ -94,6 +94,8 @@ public:
|
||||
return fVariation.reset(coordinateCount);
|
||||
}
|
||||
|
||||
static SkFontStyle::Width SkFontStyleWidthForWidthAxisValue(SkScalar width);
|
||||
|
||||
private:
|
||||
SkString fFamilyName;
|
||||
SkString fFullName;
|
||||
|
@ -1940,7 +1940,8 @@ bool SkTypeface_FreeType::Scanner::scanFont(
|
||||
}
|
||||
if (wdthIndex) {
|
||||
SkASSERT(*wdthIndex < numAxes);
|
||||
width = SkScalarRoundToInt(SkFixedToScalar(coords[*wdthIndex]));
|
||||
SkScalar wdthValue = SkFixedToScalar(coords[*wdthIndex]);
|
||||
width = SkFontDescriptor::SkFontStyleWidthForWidthAxisValue(wdthValue);
|
||||
}
|
||||
if (slntIndex) {
|
||||
SkASSERT(*slntIndex < numAxes);
|
||||
|
Loading…
Reference in New Issue
Block a user