Deduplicate axis value resolving code.
The code was originally written for Android, but is now implemented more generally by the FreeType scanner to be shared between all FreeType backed typefaces. This removes the now duplicate code in the Android font manager and uses the shared code instead. GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1726213004 Review URL: https://codereview.chromium.org/1726213004
This commit is contained in:
parent
26cc3f5ad0
commit
47a1e96b95
@ -198,49 +198,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
SkAutoSTMalloc<4, SkFixed> axisValues(axisDefinitions.count());
|
SkAutoSTMalloc<4, SkFixed> axisValues(axisDefinitions.count());
|
||||||
for (int i = 0; i < axisDefinitions.count(); ++i) {
|
Scanner::computeAxisValues(axisDefinitions,
|
||||||
const Scanner::AxisDefinition& axisDefinition = axisDefinitions[i];
|
fontFile.fAxes.begin(), fontFile.fAxes.count(),
|
||||||
axisValues[i] = axisDefinition.fDefault;
|
axisValues, familyName);
|
||||||
for (int j = 0; j < fontFile.fAxes.count(); ++j) {
|
|
||||||
const FontFileInfo::Axis& axisSpecified = fontFile.fAxes[j];
|
|
||||||
if (axisDefinition.fTag == axisSpecified.fTag) {
|
|
||||||
axisValues[i] = SkTPin(axisSpecified.fValue, axisDefinition.fMinimum,
|
|
||||||
axisDefinition.fMaximum);
|
|
||||||
if (axisValues[i] != axisSpecified.fValue) {
|
|
||||||
SkDEBUGF(("Requested font axis value out of range: "
|
|
||||||
"%s '%c%c%c%c' %f; pinned to %f.\n",
|
|
||||||
familyName.c_str(),
|
|
||||||
(axisDefinition.fTag >> 24) & 0xFF,
|
|
||||||
(axisDefinition.fTag >> 16) & 0xFF,
|
|
||||||
(axisDefinition.fTag >> 8) & 0xFF,
|
|
||||||
(axisDefinition.fTag ) & 0xFF,
|
|
||||||
SkFixedToDouble(axisSpecified.fValue),
|
|
||||||
SkFixedToDouble(axisValues[i])));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// TODO: warn on defaulted axis?
|
|
||||||
}
|
|
||||||
|
|
||||||
SkDEBUGCODE(
|
|
||||||
// Check for axis specified, but not matched in font.
|
|
||||||
for (int i = 0; i < fontFile.fAxes.count(); ++i) {
|
|
||||||
SkFourByteTag skTag = fontFile.fAxes[i].fTag;
|
|
||||||
bool found = false;
|
|
||||||
for (int j = 0; j < axisDefinitions.count(); ++j) {
|
|
||||||
if (skTag == axisDefinitions[j].fTag) {
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!found) {
|
|
||||||
SkDEBUGF(("Requested font axis not found: %s '%c%c%c%c'\n",
|
|
||||||
familyName.c_str(), (skTag >> 24) & 0xFF,
|
|
||||||
(skTag >> 16) & 0xFF, (skTag >> 8) & 0xFF, (skTag)&0xFF));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
fStyles.push_back().reset(new SkTypeface_AndroidSystem(
|
fStyles.push_back().reset(new SkTypeface_AndroidSystem(
|
||||||
pathName, cacheFontFiles, ttcIndex, axisValues.get(), axisDefinitions.count(),
|
pathName, cacheFontFiles, ttcIndex, axisValues.get(), axisDefinitions.count(),
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
// Despite the name and location, this is portable code.
|
// Despite the name and location, this is portable code.
|
||||||
|
|
||||||
|
#include "SkFontMgr.h"
|
||||||
#include "SkFontMgr_android_parser.h"
|
#include "SkFontMgr_android_parser.h"
|
||||||
#include "SkStream.h"
|
#include "SkStream.h"
|
||||||
#include "SkTDArray.h"
|
#include "SkTDArray.h"
|
||||||
@ -152,7 +153,10 @@ namespace lmpParser {
|
|||||||
static const TagHandler axisHandler = {
|
static const TagHandler axisHandler = {
|
||||||
/*start*/[](FamilyData* self, const char* tag, const char** attributes) {
|
/*start*/[](FamilyData* self, const char* tag, const char** attributes) {
|
||||||
FontFileInfo& file = *self->fCurrentFontInfo;
|
FontFileInfo& file = *self->fCurrentFontInfo;
|
||||||
FontFileInfo::Axis& axis = file.fAxes.push_back();
|
SkFourByteTag axisTag = SkSetFourByteTag('\0','\0','\0','\0');
|
||||||
|
SkFixed axisStyleValue = 0;
|
||||||
|
bool axisTagIsValid = false;
|
||||||
|
bool axisStyleValueIsValid = false;
|
||||||
for (size_t i = 0; ATTS_NON_NULL(attributes, i); i += 2) {
|
for (size_t i = 0; ATTS_NON_NULL(attributes, i); i += 2) {
|
||||||
const char* name = attributes[i];
|
const char* name = attributes[i];
|
||||||
const char* value = attributes[i+1];
|
const char* value = attributes[i+1];
|
||||||
@ -160,26 +164,34 @@ static const TagHandler axisHandler = {
|
|||||||
if (MEMEQ("tag", name, nameLen)) {
|
if (MEMEQ("tag", name, nameLen)) {
|
||||||
size_t valueLen = strlen(value);
|
size_t valueLen = strlen(value);
|
||||||
if (valueLen == 4) {
|
if (valueLen == 4) {
|
||||||
SkFourByteTag tag = SkSetFourByteTag(value[0], value[1], value[2], value[3]);
|
axisTag = SkSetFourByteTag(value[0], value[1], value[2], value[3]);
|
||||||
|
axisTagIsValid = true;
|
||||||
for (int j = 0; j < file.fAxes.count() - 1; ++j) {
|
for (int j = 0; j < file.fAxes.count() - 1; ++j) {
|
||||||
if (file.fAxes[j].fTag == tag) {
|
if (file.fAxes[j].fTag == axisTag) {
|
||||||
|
axisTagIsValid = false;
|
||||||
SK_FONTCONFIGPARSER_WARNING("'%c%c%c%c' axis specified more than once",
|
SK_FONTCONFIGPARSER_WARNING("'%c%c%c%c' axis specified more than once",
|
||||||
(tag >> 24) & 0xFF,
|
(axisTag >> 24) & 0xFF,
|
||||||
(tag >> 16) & 0xFF,
|
(axisTag >> 16) & 0xFF,
|
||||||
(tag >> 8) & 0xFF,
|
(axisTag >> 8) & 0xFF,
|
||||||
(tag ) & 0xFF);
|
(axisTag ) & 0xFF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
axis.fTag = SkSetFourByteTag(value[0], value[1], value[2], value[3]);
|
|
||||||
} else {
|
} else {
|
||||||
SK_FONTCONFIGPARSER_WARNING("'%s' is an invalid axis tag", value);
|
SK_FONTCONFIGPARSER_WARNING("'%s' is an invalid axis tag", value);
|
||||||
}
|
}
|
||||||
} else if (MEMEQ("stylevalue", name, nameLen)) {
|
} else if (MEMEQ("stylevalue", name, nameLen)) {
|
||||||
if (!parse_fixed<16>(value, &axis.fValue)) {
|
if (parse_fixed<16>(value, &axisStyleValue)) {
|
||||||
|
axisStyleValueIsValid = true;
|
||||||
|
} else {
|
||||||
SK_FONTCONFIGPARSER_WARNING("'%s' is an invalid axis stylevalue", value);
|
SK_FONTCONFIGPARSER_WARNING("'%s' is an invalid axis stylevalue", value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (axisTagIsValid && axisStyleValueIsValid) {
|
||||||
|
SkFontMgr::FontParameters::Axis& axis = file.fAxes.push_back();
|
||||||
|
axis.fTag = axisTag;
|
||||||
|
axis.fStyleValue = SkFixedToScalar(axisStyleValue);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
/*end*/nullptr,
|
/*end*/nullptr,
|
||||||
/*tag*/nullptr,
|
/*tag*/nullptr,
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
#ifndef SkFontMgr_android_parser_DEFINED
|
#ifndef SkFontMgr_android_parser_DEFINED
|
||||||
#define SkFontMgr_android_parser_DEFINED
|
#define SkFontMgr_android_parser_DEFINED
|
||||||
|
|
||||||
#include "SkFixed.h"
|
#include "SkFontMgr.h"
|
||||||
#include "SkString.h"
|
#include "SkString.h"
|
||||||
#include "SkTArray.h"
|
#include "SkTArray.h"
|
||||||
#include "SkTDArray.h"
|
#include "SkTDArray.h"
|
||||||
@ -73,12 +73,7 @@ struct FontFileInfo {
|
|||||||
int fIndex;
|
int fIndex;
|
||||||
int fWeight;
|
int fWeight;
|
||||||
enum class Style { kAuto, kNormal, kItalic } fStyle;
|
enum class Style { kAuto, kNormal, kItalic } fStyle;
|
||||||
struct Axis {
|
SkTArray<SkFontMgr::FontParameters::Axis, true> fAxes;
|
||||||
Axis() : fTag(SkSetFourByteTag('\0','\0','\0','\0')), fValue(0) { }
|
|
||||||
SkFourByteTag fTag;
|
|
||||||
SkFixed fValue;
|
|
||||||
};
|
|
||||||
SkTArray<Axis, true> fAxes;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -88,7 +88,16 @@ void DumpLoadedFonts(SkTDArray<FontFamily*> fontFamilies, const char* label) {
|
|||||||
}
|
}
|
||||||
for (int j = 0; j < fontFamilies[i]->fFonts.count(); ++j) {
|
for (int j = 0; j < fontFamilies[i]->fFonts.count(); ++j) {
|
||||||
const FontFileInfo& ffi = fontFamilies[i]->fFonts[j];
|
const FontFileInfo& ffi = fontFamilies[i]->fFonts[j];
|
||||||
SkDebugf(" file (%d) %s#%d\n", ffi.fWeight, ffi.fFileName.c_str(), ffi.fIndex);
|
SkDebugf(" file (%d) %s#%d", ffi.fWeight, ffi.fFileName.c_str(), ffi.fIndex);
|
||||||
|
for (const auto& axis : ffi.fAxes) {
|
||||||
|
SkDebugf(" @'%c%c%c%c'=%f",
|
||||||
|
(axis.fTag >> 24) & 0xFF,
|
||||||
|
(axis.fTag >> 16) & 0xFF,
|
||||||
|
(axis.fTag >> 8) & 0xFF,
|
||||||
|
(axis.fTag ) & 0xFF,
|
||||||
|
axis.fStyleValue);
|
||||||
|
}
|
||||||
|
SkDebugf("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SkDebugf("\n\n");
|
SkDebugf("\n\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user