Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Unified Diff: src/ports/SkFontMgr_android_parser.cpp

Issue 1726213004: Deduplicate axis value resolving code. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Convince gcc that the values are assigned before use. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/ports/SkFontMgr_android_parser.h ('k') | tests/FontMgrAndroidParserTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ports/SkFontMgr_android_parser.cpp
diff --git a/src/ports/SkFontMgr_android_parser.cpp b/src/ports/SkFontMgr_android_parser.cpp
index 1d1a3b7ddb67236b8f3c9d2e76e29bc625c8f5aa..3f9c90cf318c045fd4be681042f390201c4a5d4b 100644
--- a/src/ports/SkFontMgr_android_parser.cpp
+++ b/src/ports/SkFontMgr_android_parser.cpp
@@ -7,6 +7,7 @@
// Despite the name and location, this is portable code.
+#include "SkFontMgr.h"
#include "SkFontMgr_android_parser.h"
#include "SkStream.h"
#include "SkTDArray.h"
@@ -152,7 +153,10 @@ namespace lmpParser {
static const TagHandler axisHandler = {
/*start*/[](FamilyData* self, const char* tag, const char** attributes) {
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) {
const char* name = attributes[i];
const char* value = attributes[i+1];
@@ -160,26 +164,34 @@ static const TagHandler axisHandler = {
if (MEMEQ("tag", name, nameLen)) {
size_t valueLen = strlen(value);
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) {
- 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",
- (tag >> 24) & 0xFF,
- (tag >> 16) & 0xFF,
- (tag >> 8) & 0xFF,
- (tag ) & 0xFF);
+ (axisTag >> 24) & 0xFF,
+ (axisTag >> 16) & 0xFF,
+ (axisTag >> 8) & 0xFF,
+ (axisTag ) & 0xFF);
}
}
- axis.fTag = SkSetFourByteTag(value[0], value[1], value[2], value[3]);
} else {
SK_FONTCONFIGPARSER_WARNING("'%s' is an invalid axis tag", value);
}
} 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);
}
}
}
+ if (axisTagIsValid && axisStyleValueIsValid) {
+ SkFontMgr::FontParameters::Axis& axis = file.fAxes.push_back();
+ axis.fTag = axisTag;
+ axis.fStyleValue = SkFixedToScalar(axisStyleValue);
+ }
},
/*end*/nullptr,
/*tag*/nullptr,
« no previous file with comments | « src/ports/SkFontMgr_android_parser.h ('k') | tests/FontMgrAndroidParserTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698