Exemplo n.º 1
0
    def fromwalker(cls, w, **kwArgs):
        """
        Returns a new OS_2 object from the specified walker.
        
        >>> fb = OS_2.frombytes
        >>> _testingValues[0] == fb(_testingValues[0].binaryString())
        True
        
        >>> _testingValues[1] == fb(_testingValues[1].binaryString())
        True
        """

        ver = w.unpack("H")
        assert ver == 5  # caller must be using the right class
        v = [ver]
        v.extend(w.unpack("H2h"))
        v.append(typeflags_v3.TypeFlags.fromwalker(w, **kwArgs))
        v.extend(w.unpack("10hH"))
        v.append(panose.Panose(w, **kwArgs))
        v.append(unicoderanges_v4.UnicodeRanges.fromwalker(w, **kwArgs))
        v.append(w.unpack("4s"))
        v.append(selection_v4.Selection.fromwalker(w, **kwArgs))
        v.extend(w.unpack("2H3h2H"))
        v.append(codepageranges_v2.CodePageRanges.fromwalker(w, **kwArgs))
        v.extend(w.unpack("2h3H"))
        v.extend(n / 20 for n in w.unpack("2H"))
        return cls(*v)
Exemplo n.º 2
0
def _asV2(obj, **kwArgs):
    """
    Convert obj to v2 Panose_fam2
    
    >>> p2 = Panose_fam2.fromnumber(0x02010203030406070801)
    >>> p2.stroke
    'Gradual/Vertical'
    >>> _asV2(p2).stroke
    'Gradual/Vertical'
    """

    from fontio3.OS_2 import panose

    bs = obj.binaryString()
    svmap = {0: 0, 1: 1, 2: 3, 3: 4, 4: 5, 5: 6, 6: 7, 7: 8, 8: 9}
    sv = bs[5]  # re-map stroke variation to new value
    svn = svmap.get(sv, 0)
    bn = bytes(bs[0:5] + bytes([svn]) + bs[6:])
    w = walker.StringWalker(bn)
    return panose.Panose(w, os2panver=2)
Exemplo n.º 3
0
    def fromwalker(cls, w, **kwArgs):
        """
        Returns a new OS_2 object from the specified walker.
        
        >>> _testingValues[0] == OS_2.frombytes(_testingValues[0].binaryString())
        True
        
        >>> _testingValues[1] == OS_2.frombytes(_testingValues[1].binaryString())
        True
        """

        ver = w.unpack("H")
        assert ver == 0  # caller must be using the right class
        v = [ver]
        v.extend(w.unpack("H2h"))
        v.append(typeflags_v0.TypeFlags.fromwalker(w, **kwArgs))
        v.extend(w.unpack("10hH"))
        v.append(panose.Panose(w, os2panver=0, **kwArgs))
        # 4 longs of zeroes ignored for unicode ranges, not used in v1
        w.skip(16)
        v.append(w.unpack("4s"))
        v.append(selection_v0.Selection.fromwalker(w, **kwArgs))
        v.extend(w.unpack("2H"))
        return cls(*v)