diff options
| author | 2017-01-23 17:51:29 +0000 | |
|---|---|---|
| committer | 2017-01-23 17:51:33 +0000 | |
| commit | c3f3595153a5a5b2c7bbeab628e96cf711670fd4 (patch) | |
| tree | 3247160b23da688cdcf500b6c2e52e82630d8d2f | |
| parent | 1eb7161f4573243d3ee38f40b5d4e664d6ac640d (diff) | |
| parent | 764ff2740fe49ca10a9e21b58f933e761b5b7865 (diff) | |
Merge "Delete accidentally submitted FontResourcesParser"
| -rw-r--r-- | graphics/java/android/graphics/FontResourcesParser.java | 113 |
1 files changed, 0 insertions, 113 deletions
diff --git a/graphics/java/android/graphics/FontResourcesParser.java b/graphics/java/android/graphics/FontResourcesParser.java deleted file mode 100644 index b4109cfa3296..000000000000 --- a/graphics/java/android/graphics/FontResourcesParser.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package android.graphics; - -import org.xmlpull.v1.XmlPullParser; -import org.xmlpull.v1.XmlPullParserException; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Pattern; - -/** - * Parser for xml type font resources. - * @hide - */ -public class FontResourcesParser { - private static final String ANDROID_NAMESPACE = "http://schemas.android.com/apk/res/android"; - - /* Parse fallback list (no names) */ - public static FontListParser.Config parse(XmlPullParser parser) - throws XmlPullParserException, IOException { - int type; - //noinspection StatementWithEmptyBody - while ((type=parser.next()) != XmlPullParser.START_TAG - && type != XmlPullParser.END_DOCUMENT) { - // Empty loop. - } - - if (type != XmlPullParser.START_TAG) { - throw new XmlPullParserException("No start tag found"); - } - return readFamilies(parser); - } - - private static FontListParser.Config readFamilies(XmlPullParser parser) - throws XmlPullParserException, IOException { - FontListParser.Config config = new FontListParser.Config(); - parser.require(XmlPullParser.START_TAG, null, "font-family"); - String tag = parser.getName(); - if (tag.equals("font-family")) { - config.families.add(readFamily(parser)); - } else { - skip(parser); - } - return config; - } - - private static FontListParser.Family readFamily(XmlPullParser parser) - throws XmlPullParserException, IOException { - String name = parser.getAttributeValue(null, "name"); - String lang = parser.getAttributeValue(null, "lang"); - String variant = parser.getAttributeValue(null, "variant"); - List<FontListParser.Font> fonts = new ArrayList<>(); - while (parser.next() != XmlPullParser.END_TAG) { - if (parser.getEventType() != XmlPullParser.START_TAG) continue; - String tag = parser.getName(); - if (tag.equals("font")) { - fonts.add(readFont(parser)); - } else { - skip(parser); - } - } - return new FontListParser.Family(name, fonts, lang, variant); - } - - /** Matches leading and trailing XML whitespace. */ - private static final Pattern FILENAME_WHITESPACE_PATTERN = - Pattern.compile("^[ \\n\\r\\t]+|[ \\n\\r\\t]+$"); - - private static FontListParser.Font readFont(XmlPullParser parser) - throws XmlPullParserException, IOException { - - List<FontListParser.Axis> axes = new ArrayList<>(); - - String weightStr = parser.getAttributeValue(ANDROID_NAMESPACE, "fontWeight"); - int weight = weightStr == null ? 400 : Integer.parseInt(weightStr); - - boolean isItalic = "italic".equals( - parser.getAttributeValue(ANDROID_NAMESPACE, "fontStyle")); - - String filename = parser.getAttributeValue(ANDROID_NAMESPACE, "font"); - String fullFilename = FILENAME_WHITESPACE_PATTERN.matcher(filename).replaceAll(""); - return new FontListParser.Font(fullFilename, 0, axes, weight, isItalic); - } - - private static void skip(XmlPullParser parser) throws XmlPullParserException, IOException { - int depth = 1; - while (depth > 0) { - switch (parser.next()) { - case XmlPullParser.START_TAG: - depth++; - break; - case XmlPullParser.END_TAG: - depth--; - break; - } - } - } -} |