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

Unified Diff: src/ports/SkFontConfigParser_android.cpp

Issue 1027373002: Font variations. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Android and tests. Created 5 years, 7 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
Index: src/ports/SkFontConfigParser_android.cpp
diff --git a/src/ports/SkFontConfigParser_android.cpp b/src/ports/SkFontConfigParser_android.cpp
index e60f4e4ea307a3e74e58495c4ca6f80be0f2b668..cb49bd8aa224ed16d0d4519880c33ace572fdb46 100644
--- a/src/ports/SkFontConfigParser_android.cpp
+++ b/src/ports/SkFontConfigParser_android.cpp
@@ -14,9 +14,7 @@
#include <expat.h>
#include <dirent.h>
-#include <stdio.h>
-#include <limits>
#include <stdlib.h>
// From Android version LMP onwards, all font files collapse into
@@ -82,32 +80,6 @@ struct FamilyData {
const char* fFilename; // The name of the file currently being parsed.
};
-/** Parses a null terminated string into an integer type, checking for overflow.
- * http://www.w3.org/TR/html-markup/datatypes.html#common.data.integer.non-negative-def
- *
- * If the string cannot be parsed into 'value', returns false and does not change 'value'.
- */
-template <typename T> static bool parse_non_negative_integer(const char* s, T* value) {
- SK_COMPILE_ASSERT(std::numeric_limits<T>::is_integer, T_must_be_integer);
- const T nMax = std::numeric_limits<T>::max() / 10;
- const T dMax = std::numeric_limits<T>::max() - (nMax * 10);
- T n = 0;
- for (; *s; ++s) {
- // Check if digit
- if (*s < '0' || '9' < *s) {
- return false;
- }
- int d = *s - '0';
- // Check for overflow
- if (n > nMax || (n == nMax && d > dMax)) {
- return false;
- }
- n = (n * 10) + d;
- }
- *value = n;
- return true;
-}
-
static bool memeq(const char* s1, const char* s2, size_t n1, size_t n2) {
return n1 == n2 && 0 == memcmp(s1, s2, n1);
}
@@ -158,6 +130,38 @@ static void XMLCALL font_file_name_handler(void* data, const char* s, int len) {
self->fCurrentFontInfo->fFileName.append(s, len);
}
+static void axis_element_handler(FamilyData* self, const char** attributes) {
+ FontFileInfo& file = *self->fCurrentFontInfo;
+ FontFileInfo::Axis& axis = file.fAxes.push_back();
+ for (size_t i = 0; ATTS_NON_NULL(attributes, i); i += 2) {
+ const char* name = attributes[i];
+ const char* value = attributes[i+1];
+ size_t nameLen = strlen(name);
+ if (MEMEQ("tag", name, nameLen)) {
+ size_t valueLen = strlen(value);
+ if (valueLen == 4) {
+ SkFourByteTag tag = SkSetFourByteTag(value[0], value[1], value[2], value[3]);
+ for (int j = 0; j < file.fAxes.count() - 1; ++j) {
+ if (file.fAxes[j].fTag == tag) {
+ SK_FONTCONFIGPARSER_WARNING("'%c%c%c%c' axis specified more than once",
+ (tag >> 24) & 0xFF,
+ (tag >> 16) & 0xFF,
+ (tag >> 8) & 0xFF,
+ (tag ) & 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)) {
+ SK_FONTCONFIGPARSER_WARNING("'%s' is an invalid axis stylevalue", value);
+ }
+ }
+ }
+}
+
static void font_element_handler(FamilyData* self, const char** attributes) {
// A <font> element should be contained in a <family> element.
// The element may have 'weight' (non-negative integer), 'style' ("normal", "italic"),
@@ -260,6 +264,8 @@ static void XMLCALL start_element_handler(void* data, const char* tag, const cha
font_element_handler(self, attributes);
} else if (MEMEQ("alias", tag, len)) {
alias_element_handler(self, attributes);
+ } else if (MEMEQ("axis", tag, len)) {
+ axis_element_handler(self, attributes);
}
}

Powered by Google App Engine
This is Rietveld 408576698