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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « src/ports/SkFontMgr_android_parser.h ('k') | tests/FontMgrAndroidParserTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 The Android Open Source Project 2 * Copyright 2011 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 // Despite the name and location, this is portable code. 8 // Despite the name and location, this is portable code.
9 9
10 #include "SkFontMgr.h"
10 #include "SkFontMgr_android_parser.h" 11 #include "SkFontMgr_android_parser.h"
11 #include "SkStream.h" 12 #include "SkStream.h"
12 #include "SkTDArray.h" 13 #include "SkTDArray.h"
13 #include "SkTSearch.h" 14 #include "SkTSearch.h"
14 #include "SkTemplates.h" 15 #include "SkTemplates.h"
15 #include "SkTLogic.h" 16 #include "SkTLogic.h"
16 17
17 #include <dirent.h> 18 #include <dirent.h>
18 #include <expat.h> 19 #include <expat.h>
19 20
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 size_t len = end - start; 146 size_t len = end - start;
146 memmove(str, start, len); 147 memmove(str, start, len);
147 s->resize(len); 148 s->resize(len);
148 } 149 }
149 150
150 namespace lmpParser { 151 namespace lmpParser {
151 152
152 static const TagHandler axisHandler = { 153 static const TagHandler axisHandler = {
153 /*start*/[](FamilyData* self, const char* tag, const char** attributes) { 154 /*start*/[](FamilyData* self, const char* tag, const char** attributes) {
154 FontFileInfo& file = *self->fCurrentFontInfo; 155 FontFileInfo& file = *self->fCurrentFontInfo;
155 FontFileInfo::Axis& axis = file.fAxes.push_back(); 156 SkFourByteTag axisTag = SkSetFourByteTag('\0','\0','\0','\0');
157 SkFixed axisStyleValue = 0;
158 bool axisTagIsValid = false;
159 bool axisStyleValueIsValid = false;
156 for (size_t i = 0; ATTS_NON_NULL(attributes, i); i += 2) { 160 for (size_t i = 0; ATTS_NON_NULL(attributes, i); i += 2) {
157 const char* name = attributes[i]; 161 const char* name = attributes[i];
158 const char* value = attributes[i+1]; 162 const char* value = attributes[i+1];
159 size_t nameLen = strlen(name); 163 size_t nameLen = strlen(name);
160 if (MEMEQ("tag", name, nameLen)) { 164 if (MEMEQ("tag", name, nameLen)) {
161 size_t valueLen = strlen(value); 165 size_t valueLen = strlen(value);
162 if (valueLen == 4) { 166 if (valueLen == 4) {
163 SkFourByteTag tag = SkSetFourByteTag(value[0], value[1], val ue[2], value[3]); 167 axisTag = SkSetFourByteTag(value[0], value[1], value[2], val ue[3]);
168 axisTagIsValid = true;
164 for (int j = 0; j < file.fAxes.count() - 1; ++j) { 169 for (int j = 0; j < file.fAxes.count() - 1; ++j) {
165 if (file.fAxes[j].fTag == tag) { 170 if (file.fAxes[j].fTag == axisTag) {
171 axisTagIsValid = false;
166 SK_FONTCONFIGPARSER_WARNING("'%c%c%c%c' axis specifi ed more than once", 172 SK_FONTCONFIGPARSER_WARNING("'%c%c%c%c' axis specifi ed more than once",
167 (tag >> 24) & 0xFF, 173 (axisTag >> 24) & 0xFF,
168 (tag >> 16) & 0xFF, 174 (axisTag >> 16) & 0xFF,
169 (tag >> 8) & 0xFF, 175 (axisTag >> 8) & 0xFF,
170 (tag ) & 0xFF); 176 (axisTag ) & 0xFF);
171 } 177 }
172 } 178 }
173 axis.fTag = SkSetFourByteTag(value[0], value[1], value[2], v alue[3]);
174 } else { 179 } else {
175 SK_FONTCONFIGPARSER_WARNING("'%s' is an invalid axis tag", v alue); 180 SK_FONTCONFIGPARSER_WARNING("'%s' is an invalid axis tag", v alue);
176 } 181 }
177 } else if (MEMEQ("stylevalue", name, nameLen)) { 182 } else if (MEMEQ("stylevalue", name, nameLen)) {
178 if (!parse_fixed<16>(value, &axis.fValue)) { 183 if (parse_fixed<16>(value, &axisStyleValue)) {
184 axisStyleValueIsValid = true;
185 } else {
179 SK_FONTCONFIGPARSER_WARNING("'%s' is an invalid axis styleva lue", value); 186 SK_FONTCONFIGPARSER_WARNING("'%s' is an invalid axis styleva lue", value);
180 } 187 }
181 } 188 }
182 } 189 }
190 if (axisTagIsValid && axisStyleValueIsValid) {
191 SkFontMgr::FontParameters::Axis& axis = file.fAxes.push_back();
192 axis.fTag = axisTag;
193 axis.fStyleValue = SkFixedToScalar(axisStyleValue);
194 }
183 }, 195 },
184 /*end*/nullptr, 196 /*end*/nullptr,
185 /*tag*/nullptr, 197 /*tag*/nullptr,
186 /*chars*/nullptr, 198 /*chars*/nullptr,
187 }; 199 };
188 200
189 static const TagHandler fontHandler = { 201 static const TagHandler fontHandler = {
190 /*start*/[](FamilyData* self, const char* tag, const char** attributes) { 202 /*start*/[](FamilyData* self, const char* tag, const char** attributes) {
191 // 'weight' (non-negative integer) [default 0] 203 // 'weight' (non-negative integer) [default 0]
192 // 'style' ("normal", "italic") [default "auto"] 204 // 'style' ("normal", "italic") [default "auto"]
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 const char* tag = fTag.c_str(); 795 const char* tag = fTag.c_str();
784 796
785 // strip off the rightmost "-.*" 797 // strip off the rightmost "-.*"
786 const char* parentTagEnd = strrchr(tag, '-'); 798 const char* parentTagEnd = strrchr(tag, '-');
787 if (parentTagEnd == nullptr) { 799 if (parentTagEnd == nullptr) {
788 return SkLanguage(); 800 return SkLanguage();
789 } 801 }
790 size_t parentTagLen = parentTagEnd - tag; 802 size_t parentTagLen = parentTagEnd - tag;
791 return SkLanguage(tag, parentTagLen); 803 return SkLanguage(tag, parentTagLen);
792 } 804 }
OLDNEW
« 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