コード例 #1
0
 def test_buildAnchor_format3(self):
     anchor = builder.buildAnchor(
         23,
         42,
         deviceX=builder.buildDevice({
             1: 1,
             0: 0
         }),
         deviceY=builder.buildDevice({7: 7}),
     )
     assert getXML(anchor.toXML) == [
         '<Anchor Format="3">',
         '  <XCoordinate value="23"/>',
         '  <YCoordinate value="42"/>',
         "  <XDeviceTable>",
         '    <StartSize value="0"/>',
         '    <EndSize value="1"/>',
         '    <DeltaFormat value="1"/>',
         '    <DeltaValue value="[0, 1]"/>',
         "  </XDeviceTable>",
         "  <YDeviceTable>",
         '    <StartSize value="7"/>',
         '    <EndSize value="7"/>',
         '    <DeltaFormat value="2"/>',
         '    <DeltaValue value="[7]"/>',
         "  </YDeviceTable>",
         "</Anchor>",
     ]
コード例 #2
0
ファイル: builder.py プロジェクト: jamesgk/fonttools
def makeOpenTypeAnchor(anchor):
    """ast.Anchor --> otTables.Anchor"""
    if anchor is None:
        return None
    deviceX, deviceY = None, None
    if anchor.xDeviceTable is not None:
        deviceX = otl.buildDevice(dict(anchor.xDeviceTable))
    if anchor.yDeviceTable is not None:
        deviceY = otl.buildDevice(dict(anchor.yDeviceTable))
    return otl.buildAnchor(anchor.x, anchor.y, anchor.contourpoint, deviceX, deviceY)
コード例 #3
0
ファイル: builder.py プロジェクト: shannonyu/fonttools
def makeOpenTypeAnchor(anchor):
    """ast.Anchor --> otTables.Anchor"""
    if anchor is None:
        return None
    deviceX, deviceY = None, None
    if anchor.xDeviceTable is not None:
        deviceX = otl.buildDevice(dict(anchor.xDeviceTable))
    if anchor.yDeviceTable is not None:
        deviceY = otl.buildDevice(dict(anchor.yDeviceTable))
    return otl.buildAnchor(anchor.x, anchor.y, anchor.contourpoint,
                           deviceX, deviceY)
コード例 #4
0
ファイル: builder_test.py プロジェクト: graphicore/fonttools
 def test_buildDevice_format2(self):
     device = builder.buildDevice([(1, 2), (-1, 1), (0, 0)])
     self.assertEqual(getXML(device.toXML),
                      '<Device>'
                      '  <StartSize value="-1"/>'
                      '  <EndSize value="1"/>'
                      '  <DeltaFormat value="2"/>'
                      '  <DeltaValue value="[1, 0, 2]"/>'
                      '</Device>')
コード例 #5
0
ファイル: builder_test.py プロジェクト: graphicore/fonttools
 def test_buildDevice_format3(self):
     device = builder.buildDevice([(5, 3), (1, 77)])
     self.assertEqual(getXML(device.toXML),
                      '<Device>'
                      '  <StartSize value="1"/>'
                      '  <EndSize value="5"/>'
                      '  <DeltaFormat value="3"/>'
                      '  <DeltaValue value="[77, 0, 0, 0, 3]"/>'
                      '</Device>')
コード例 #6
0
 def test_buildDevice_format3(self):
     device = builder.buildDevice({5:3, 1:77})
     self.assertEqual(getXML(device.toXML),
                      '<Device>'
                      '  <StartSize value="1"/>'
                      '  <EndSize value="5"/>'
                      '  <DeltaFormat value="3"/>'
                      '  <DeltaValue value="[77, 0, 0, 0, 3]"/>'
                      '</Device>')
コード例 #7
0
 def test_buildDevice_format2(self):
     device = builder.buildDevice({2:2, 0:1, 1:0})
     self.assertEqual(getXML(device.toXML),
                      '<Device>'
                      '  <StartSize value="0"/>'
                      '  <EndSize value="2"/>'
                      '  <DeltaFormat value="2"/>'
                      '  <DeltaValue value="[1, 0, 2]"/>'
                      '</Device>')
コード例 #8
0
 def test_buildDevice_format1(self):
     device = builder.buildDevice({1:1, 0:0})
     self.assertEqual(getXML(device.toXML),
                      '<Device>'
                      '  <StartSize value="0"/>'
                      '  <EndSize value="1"/>'
                      '  <DeltaFormat value="1"/>'
                      '  <DeltaValue value="[0, 1]"/>'
                      '</Device>')
コード例 #9
0
 def test_buildDevice_format3(self):
     device = builder.buildDevice({5: 3, 1: 77})
     assert getXML(device.toXML) == [
         "<Device>",
         '  <StartSize value="1"/>',
         '  <EndSize value="5"/>',
         '  <DeltaFormat value="3"/>',
         '  <DeltaValue value="[77, 0, 0, 0, 3]"/>',
         "</Device>",
     ]
コード例 #10
0
 def test_buildDevice_format2(self):
     device = builder.buildDevice({2: 2, 0: 1, 1: 0})
     assert getXML(device.toXML) == [
         "<Device>",
         '  <StartSize value="0"/>',
         '  <EndSize value="2"/>',
         '  <DeltaFormat value="2"/>',
         '  <DeltaValue value="[1, 0, 2]"/>',
         "</Device>",
     ]
コード例 #11
0
 def test_buildDevice_format1(self):
     device = builder.buildDevice({1: 1, 0: 0})
     assert getXML(device.toXML) == [
         "<Device>",
         '  <StartSize value="0"/>',
         '  <EndSize value="1"/>',
         '  <DeltaFormat value="1"/>',
         '  <DeltaValue value="[0, 1]"/>',
         "</Device>",
     ]
コード例 #12
0
 def test_getSinglePosValueKey(self):
     device = builder.buildDevice({10: 1, 11: 3})
     a1 = builder.buildValue({"XPlacement": 500, "XPlaDevice": device})
     a2 = builder.buildValue({"XPlacement": 500, "XPlaDevice": device})
     b = builder.buildValue({"XPlacement": 500})
     keyA1 = builder._getSinglePosValueKey(a1)
     keyA2 = builder._getSinglePosValueKey(a1)
     keyB = builder._getSinglePosValueKey(b)
     assert keyA1 == keyA2
     assert hash(keyA1) == hash(keyA2)
     assert keyA1 != keyB
     assert hash(keyA1) != hash(keyB)
コード例 #13
0
ファイル: builder_test.py プロジェクト: graphicore/fonttools
 def test_getSinglePosValueKey(self):
     device = builder.buildDevice([(10, 1), (11, 3)])
     a1 = builder.buildValue({"XPlacement": 500, "XPlaDevice": device})
     a2 = builder.buildValue({"XPlacement": 500, "XPlaDevice": device})
     b = builder.buildValue({"XPlacement": 500})
     keyA1 = builder._getSinglePosValueKey(a1)
     keyA2 = builder._getSinglePosValueKey(a1)
     keyB = builder._getSinglePosValueKey(b)
     self.assertEqual(keyA1, keyA2)
     self.assertEqual(hash(keyA1), hash(keyA2))
     self.assertNotEqual(keyA1, keyB)
     self.assertNotEqual(hash(keyA1), hash(keyB))
コード例 #14
0
 def test_getSinglePosValueKey(self):
     device = builder.buildDevice({10:1, 11:3})
     a1 = builder.buildValue({"XPlacement": 500, "XPlaDevice": device})
     a2 = builder.buildValue({"XPlacement": 500, "XPlaDevice": device})
     b = builder.buildValue({"XPlacement": 500})
     keyA1 = builder._getSinglePosValueKey(a1)
     keyA2 = builder._getSinglePosValueKey(a1)
     keyB = builder._getSinglePosValueKey(b)
     self.assertEqual(keyA1, keyA2)
     self.assertEqual(hash(keyA1), hash(keyA2))
     self.assertNotEqual(keyA1, keyB)
     self.assertNotEqual(hash(keyA1), hash(keyB))
コード例 #15
0
ファイル: builder_test.py プロジェクト: graphicore/fonttools
 def test_buildAnchor_format3(self):
     anchor = builder.buildAnchor(
         23, 42,
         deviceX=builder.buildDevice([(1, 1), (0, 0)]),
         deviceY=builder.buildDevice([(7, 7)]))
     self.assertEqual(getXML(anchor.toXML),
                      '<Anchor Format="3">'
                      '  <XCoordinate value="23"/>'
                      '  <YCoordinate value="42"/>'
                      '  <XDeviceTable>'
                      '    <StartSize value="0"/>'
                      '    <EndSize value="1"/>'
                      '    <DeltaFormat value="1"/>'
                      '    <DeltaValue value="[0, 1]"/>'
                      '  </XDeviceTable>'
                      '  <YDeviceTable>'
                      '    <StartSize value="7"/>'
                      '    <EndSize value="7"/>'
                      '    <DeltaFormat value="2"/>'
                      '    <DeltaValue value="[7]"/>'
                      '  </YDeviceTable>'
                      '</Anchor>')
コード例 #16
0
ファイル: builder.py プロジェクト: jamesgk/fonttools
def makeOpenTypeValueRecord(v):
    """ast.ValueRecord --> (otBase.ValueRecord, int ValueFormat)"""
    if v is None:
        return None, 0

    vr = {}
    for astName, (otName, isDevice) in _VALUEREC_ATTRS.items():
        val = getattr(v, astName, None)
        if val:
            vr[otName] = otl.buildDevice(dict(val)) if isDevice else val

    valRec = otl.buildValue(vr)
    return valRec, valRec.getFormat()
コード例 #17
0
ファイル: builder.py プロジェクト: shannonyu/fonttools
def makeOpenTypeValueRecord(v):
    """ast.ValueRecord --> (otBase.ValueRecord, int ValueFormat)"""
    if v is None:
        return None, 0

    vr = {}
    for astName, (otName, isDevice) in _VALUEREC_ATTRS.items():
        val = getattr(v, astName, None)
        if val:
            vr[otName] = otl.buildDevice(dict(val)) if isDevice else val

    valRec = otl.buildValue(vr)
    return valRec, valRec.getFormat()