• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import base64
2import io
3import os
4
5from fontTools.misc.testTools import getXML
6from fontTools.ttLib import TTFont
7
8
9DATA_DIR = os.path.join(os.path.abspath(os.path.dirname(__file__)), "data")
10
11# This is a subset from NotoColorEmoji.ttf which contains an IndexTable format=3
12INDEX_FORMAT_3_TTX = os.path.join(DATA_DIR, "NotoColorEmoji.subset.index_format_3.ttx")
13# The CLBC table was compiled with Harfbuzz' hb-subset and contains the correct padding
14CBLC_INDEX_FORMAT_3 = base64.b64decode(
15    "AAMAAAAAAAEAAAA4AAAALAAAAAIAAAAAZeWIAAAAAAAAAAAAZeWIAAAAAAAAAAAAAAEAA"
16    "21tIAEAAQACAAAAEAADAAMAAAAgAAMAEQAAAAQAAAOmEQ0AAAADABEAABERAAAIUg=="
17)
18
19
20def test_compile_decompile_index_table_format_3():
21    font = TTFont()
22    font.importXML(INDEX_FORMAT_3_TTX)
23    buf = io.BytesIO()
24    font.save(buf)
25    buf.seek(0)
26    font = TTFont(buf)
27
28    assert font.reader["CBLC"] == CBLC_INDEX_FORMAT_3
29
30    assert getXML(font["CBLC"].toXML, font) == [
31        '<header version="3.0"/>',
32        '<strike index="0">',
33        "  <bitmapSizeTable>",
34        '    <sbitLineMetrics direction="hori">',
35        '      <ascender value="101"/>',
36        '      <descender value="-27"/>',
37        '      <widthMax value="136"/>',
38        '      <caretSlopeNumerator value="0"/>',
39        '      <caretSlopeDenominator value="0"/>',
40        '      <caretOffset value="0"/>',
41        '      <minOriginSB value="0"/>',
42        '      <minAdvanceSB value="0"/>',
43        '      <maxBeforeBL value="0"/>',
44        '      <minAfterBL value="0"/>',
45        '      <pad1 value="0"/>',
46        '      <pad2 value="0"/>',
47        "    </sbitLineMetrics>",
48        '    <sbitLineMetrics direction="vert">',
49        '      <ascender value="101"/>',
50        '      <descender value="-27"/>',
51        '      <widthMax value="136"/>',
52        '      <caretSlopeNumerator value="0"/>',
53        '      <caretSlopeDenominator value="0"/>',
54        '      <caretOffset value="0"/>',
55        '      <minOriginSB value="0"/>',
56        '      <minAdvanceSB value="0"/>',
57        '      <maxBeforeBL value="0"/>',
58        '      <minAfterBL value="0"/>',
59        '      <pad1 value="0"/>',
60        '      <pad2 value="0"/>',
61        "    </sbitLineMetrics>",
62        '    <colorRef value="0"/>',
63        '    <startGlyphIndex value="1"/>',
64        '    <endGlyphIndex value="3"/>',
65        '    <ppemX value="109"/>',
66        '    <ppemY value="109"/>',
67        '    <bitDepth value="32"/>',
68        '    <flags value="1"/>',
69        "  </bitmapSizeTable>",
70        "  <!-- GlyphIds are written but not read. The firstGlyphIndex and",
71        "       lastGlyphIndex values will be recalculated by the compiler. -->",
72        '  <eblc_index_sub_table_3 imageFormat="17" firstGlyphIndex="1" lastGlyphIndex="2">',
73        '    <glyphLoc id="1" name="eight"/>',
74        '    <glyphLoc id="2" name="registered"/>',
75        "  </eblc_index_sub_table_3>",
76        '  <eblc_index_sub_table_3 imageFormat="17" firstGlyphIndex="3" lastGlyphIndex="3">',
77        '    <glyphLoc id="3" name="uni2049"/>',
78        "  </eblc_index_sub_table_3>",
79        "</strike>",
80    ]
81