xref: /aosp_15_r20/frameworks/base/data/fonts/script/generate_fonts_xml_main.py (revision d57664e9bc4670b3ecf6748a746a57c557b6bc9e)
1#!/usr/bin/env python
2
3#
4# Copyright (C) 2024 The Android Open Source Project
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10#      http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18
19"""A main module for generating XML from font config JSONs.
20
21The following is a JSON format of the font configuration.
22
23[  // Top level element is a list to be able to hold multiple families
24    { // Dict for defining single family entry
25
26        // Optional String: unique identifier.
27        // This can be used for identifying this family instance.
28        // Currently this is ued only for specifying the target of the fallback
29        // family.
30        "id": "Roboto",
31
32        // Optional String: name of this family if this family creates a new
33        // fallback. If multiple families define the same name, it is a build
34        // error.
35        "name": "sans-serif",
36
37        // Optional String: language tag of this family if this family is a
38        // fallback family. Only language tags declared in fallback_order.json
39        // can be used. Specifying unknown language tags is a build error.
40        "lang": "und-Latn",
41
42        // Optional String: variant of the family
43        // Currently only “compact”, “elegant” are supported.
44        "variant": "compact",
45
46        // Optional String: specify the fallback target used for this family.
47        // If this key is specified, "target" attribute must also be specified.
48        // If this key is specified, "name" and "lang" must not be specified.
49        // If the specified fallback target is not defined, it is a build error.
50        "fallbackFor": "roboto-flex",
51
52        // Optional String: specify the family target to include this family.
53        // If this key is specified, "fallbackFor" attribute must also be
54        // specified. If this key is specified, "name" and "lang" must not be
55        // specified. If the specified family target is not defined, it is a
56        // build error.
57        "target": "RobotoMain",
58
59        // Optional Integer: specify the priority of the family.
60        // The priority order is determined by fallback_order.json.
61        // This priority is only used when two or more font families are
62        // assigned to the same rank: e.g. NotoColorEmoji.ttf and
63        // NotoColorEmojiFlags.ttf.
64        // All families have priority 0 by default and any value from -100 to
65        // 100 is valid. Lowering priority value increases the priority.
66        "priority": 0,
67
68        // Mandatory List: specify list of fonts. At least one font is required.
69        "fonts": [
70            {  // Dict for defining a single font entry.
71
72                // Mandatory String: specify font file name in the system.
73                // This must be the file name in the system image.
74                "file": "Roboto-Regular.ttf",
75
76                // Optional String: specify the PostScript name of the font.
77                // This can be optional if the filename without extension is the
78                // same as the PostScript name.
79                "postScriptName": "Roboto",
80
81                // Optional String: specify weight of the font.
82                "weight": "100",
83
84                // Optional String: specify style of the font.
85                // Currently, only "normal" or "italic" is supported.
86                "style": "normal",
87
88                // Optional String: specify supported axes for automatic
89                // adjustment. Currently, only "wght" or "wght,ital" is
90                // supported.
91                "supportedAxes": "wght"
92
93                // Optional Dict: specify variation settings for this font.
94                "axes": {
95                    // Optional key to float dictionaty entry for speicying axis
96                    // values.
97                    "wdth": 100.0,
98                }
99            },
100        ]
101    }
102]
103"""
104
105import sys
106
107from commandline import parse_commandline
108from xml_builder import main
109
110if __name__ == "__main__":
111  args = parse_commandline(sys.argv[1:])
112  main(args)
113