예제 #1
0
def _writeBbox(font, svgFontFaceAttrib):
    """
    >>> from defcon import Font
    >>> font = Font()
    >>> svgFontFaceAttrib = {}
    >>> _writeBbox(font, svgFontFaceAttrib)
    >>> svgFontFaceAttrib
    {'bbox': '0 0 0 0'}
    >>> font.newGlyph("A")
    >>> glyph = font["A"]
    >>> pen = glyph.getPen()
    >>> pen.moveTo((-10, -10))
    >>> pen.lineTo((-10, 10))
    >>> pen.lineTo((10, 10))
    >>> pen.lineTo((10, -10))
    >>> pen.closePath()
    >>> _writeBbox(font, svgFontFaceAttrib)
    >>> svgFontFaceAttrib
    {'bbox': '-10 -10 10 10'}
    """
    rect = font.bounds
    if rect is None:
        rect = (0, 0, 0, 0)
    rect = [valueToString(i) for i in rect]
    svgFontFaceAttrib["bbox"] = " ".join(rect)
예제 #2
0
def _writeBbox(font, svgFontFaceAttrib):
    """
    >>> from defcon import Font
    >>> font = Font()
    >>> svgFontFaceAttrib = {}
    >>> _writeBbox(font, svgFontFaceAttrib)
    >>> svgFontFaceAttrib
    {'bbox': '0 0 0 0'}
    >>> font.newGlyph("A")
    >>> glyph = font["A"]
    >>> pen = glyph.getPen()
    >>> pen.moveTo((-10, -10))
    >>> pen.lineTo((-10, 10))
    >>> pen.lineTo((10, 10))
    >>> pen.lineTo((10, -10))
    >>> pen.closePath()
    >>> _writeBbox(font, svgFontFaceAttrib)
    >>> svgFontFaceAttrib
    {'bbox': '-10 -10 10 10'}
    """
    rect = font.bounds
    if rect is None:
        rect = (0, 0, 0, 0)
    rect = [valueToString(i) for i in rect]
    svgFontFaceAttrib["bbox"] = " ".join(rect)
예제 #3
0
파일: glyphs.py 프로젝트: musca1997/ufo2svg
def _writeHorizAdvX(glyph, attrib):
    """
    >>> from defcon import Glyph
    >>> attrib = {}
    >>> glyph = Glyph()
    >>> glyph.width = 100
    >>> _writeHorizAdvX(glyph, attrib)
    >>> attrib
    {'horiz-adv-x': '100'}
    """
    assert glyph.width >= 0
    attrib["horiz-adv-x"] = valueToString(glyph.width)
예제 #4
0
def _writeDescent(font, svgFontFaceAttrib):
    """
    >>> from defcon import Font
    >>> font = Font()
    >>> svgFontFaceAttrib = {}
    >>> _writeDescent(font, svgFontFaceAttrib)
    >>> svgFontFaceAttrib
    {}
    >>> font.info.descender = -250
    >>> _writeDescent(font, svgFontFaceAttrib)
    >>> svgFontFaceAttrib
    {'descent': '-250'}
    """
    if font.info.descender is not None:
        svgFontFaceAttrib["descent"] = valueToString(font.info.descender)
예제 #5
0
def _writeXHeight(font, svgFontFaceAttrib):
    """
    >>> from defcon import Font
    >>> font = Font()
    >>> svgFontFaceAttrib = {}
    >>> _writeXHeight(font, svgFontFaceAttrib)
    >>> svgFontFaceAttrib
    {}
    >>> font.info.xHeight = 400
    >>> _writeXHeight(font, svgFontFaceAttrib)
    >>> svgFontFaceAttrib
    {'x-height': '400'}
    """
    if font.info.xHeight is not None:
        svgFontFaceAttrib["x-height"] = valueToString(font.info.xHeight)
예제 #6
0
def _writeCapHeight(font, svgFontFaceAttrib):
    """
    >>> from defcon import Font
    >>> font = Font()
    >>> svgFontFaceAttrib = {}
    >>> _writeCapHeight(font, svgFontFaceAttrib)
    >>> svgFontFaceAttrib
    {}
    >>> font.info.capHeight = 750
    >>> _writeCapHeight(font, svgFontFaceAttrib)
    >>> svgFontFaceAttrib
    {'cap-height': '750'}
    """
    if font.info.capHeight is not None:
        svgFontFaceAttrib["cap-height"] = valueToString(font.info.capHeight)
예제 #7
0
def _writeUnitsPerEm(font, svgFontFaceAttrib):
    """
    >>> from defcon import Font
    >>> font = Font()
    >>> svgFontFaceAttrib = {}
    >>> _writeUnitsPerEm(font, svgFontFaceAttrib)
    >>> svgFontFaceAttrib
    {}
    >>> font.info.unitsPerEm = 1000
    >>> _writeUnitsPerEm(font, svgFontFaceAttrib)
    >>> svgFontFaceAttrib
    {'units-per-em': '1000'}
    """
    if font.info.unitsPerEm is not None:
        svgFontFaceAttrib["units-per-em"] = valueToString(font.info.unitsPerEm)
예제 #8
0
def _writeUnitsPerEm(font, svgFontFaceAttrib):
    """
    >>> from defcon import Font
    >>> font = Font()
    >>> svgFontFaceAttrib = {}
    >>> _writeUnitsPerEm(font, svgFontFaceAttrib)
    >>> svgFontFaceAttrib
    {}
    >>> font.info.unitsPerEm = 1000
    >>> _writeUnitsPerEm(font, svgFontFaceAttrib)
    >>> svgFontFaceAttrib
    {'units-per-em': '1000'}
    """
    if font.info.unitsPerEm is not None:
        svgFontFaceAttrib["units-per-em"] = valueToString(font.info.unitsPerEm)
예제 #9
0
def _writeFontWeight(font, svgFontFaceAttrib):
    """
    >>> from defcon import Font
    >>> font = Font()
    >>> svgFontFaceAttrib = {}
    >>> _writeFontWeight(font, svgFontFaceAttrib)
    >>> svgFontFaceAttrib
    {}
    >>> font.info.openTypeOS2WeightClass = 100
    >>> _writeFontWeight(font, svgFontFaceAttrib)
    >>> svgFontFaceAttrib
    {'font-weight': '100'}
    """
    if font.info.openTypeOS2WeightClass is not None:
        svgFontFaceAttrib["font-weight"] = valueToString(font.info.openTypeOS2WeightClass)
예제 #10
0
def _writeDescent(font, svgFontFaceAttrib):
    """
    >>> from defcon import Font
    >>> font = Font()
    >>> svgFontFaceAttrib = {}
    >>> _writeDescent(font, svgFontFaceAttrib)
    >>> svgFontFaceAttrib
    {}
    >>> font.info.descender = -250
    >>> _writeDescent(font, svgFontFaceAttrib)
    >>> svgFontFaceAttrib
    {'descent': '-250'}
    """
    if font.info.descender is not None:
        svgFontFaceAttrib["descent"] = valueToString(font.info.descender)
예제 #11
0
def _writeXHeight(font, svgFontFaceAttrib):
    """
    >>> from defcon import Font
    >>> font = Font()
    >>> svgFontFaceAttrib = {}
    >>> _writeXHeight(font, svgFontFaceAttrib)
    >>> svgFontFaceAttrib
    {}
    >>> font.info.xHeight = 400
    >>> _writeXHeight(font, svgFontFaceAttrib)
    >>> svgFontFaceAttrib
    {'x-height': '400'}
    """
    if font.info.xHeight is not None:
        svgFontFaceAttrib["x-height"] = valueToString(font.info.xHeight)
예제 #12
0
def _writeCapHeight(font, svgFontFaceAttrib):
    """
    >>> from defcon import Font
    >>> font = Font()
    >>> svgFontFaceAttrib = {}
    >>> _writeCapHeight(font, svgFontFaceAttrib)
    >>> svgFontFaceAttrib
    {}
    >>> font.info.capHeight = 750
    >>> _writeCapHeight(font, svgFontFaceAttrib)
    >>> svgFontFaceAttrib
    {'cap-height': '750'}
    """
    if font.info.capHeight is not None:
        svgFontFaceAttrib["cap-height"] = valueToString(font.info.capHeight)
예제 #13
0
def _writeFontWeight(font, svgFontFaceAttrib):
    """
    >>> from defcon import Font
    >>> font = Font()
    >>> svgFontFaceAttrib = {}
    >>> _writeFontWeight(font, svgFontFaceAttrib)
    >>> svgFontFaceAttrib
    {}
    >>> font.info.openTypeOS2WeightClass = 100
    >>> _writeFontWeight(font, svgFontFaceAttrib)
    >>> svgFontFaceAttrib
    {'font-weight': '100'}
    """
    if font.info.openTypeOS2WeightClass is not None:
        svgFontFaceAttrib["font-weight"] = valueToString(
            font.info.openTypeOS2WeightClass)
예제 #14
0
파일: glyphs.py 프로젝트: musca1997/ufo2svg
def _writeDefaultMissingGlyphAttrib(font):
    """
    >>> from defcon import Font
    >>> font = Font()
    >>> _writeDefaultMissingGlyphAttrib(font)
    {'horiz-adv-x': '500'}
    >>> font.info.unitsPerEm = 2048
    >>> _writeDefaultMissingGlyphAttrib(font)
    {'horiz-adv-x': '1024'}
    >>> font.info.postscriptDefaultWidthX = 250
    >>> _writeDefaultMissingGlyphAttrib(font)
    {'horiz-adv-x': '250'}
    """
    if font.info.postscriptDefaultWidthX is not None:
        width = font.info.postscriptDefaultWidthX
    elif not font.info.unitsPerEm:
        width = 500
    else:
        width = int(font.info.unitsPerEm * .5)
    return {"horiz-adv-x" : valueToString(width)}
예제 #15
0
    def _lineTo(self, pt):
        """
        # duplicate point
        >>> pen = SVGPathPen(None)
        >>> pen.moveTo((10, 10))
        >>> pen.lineTo((10, 10))
        >>> pen._commands
        ['M10 10']

        # vertical line
        >>> pen = SVGPathPen(None)
        >>> pen.moveTo((10, 10))
        >>> pen.lineTo((10, 0))
        >>> pen._commands
        ['M10 10', 'V0']

        # horizontal line
        >>> pen = SVGPathPen(None)
        >>> pen.moveTo((10, 10))
        >>> pen.lineTo((0, 10))
        >>> pen._commands
        ['M10 10', 'H0']

        # basic
        >>> pen = SVGPathPen(None)
        >>> pen.lineTo((70, 80))
        >>> pen._commands
        ['L70 80']

        # basic following a moveto
        >>> pen = SVGPathPen(None)
        >>> pen.moveTo((0, 0))
        >>> pen.lineTo((10, 10))
        >>> pen._commands
        ['M0 0', ' 10 10']
        """
        x, y = pt
        # duplicate point
        if x == self._lastX and y == self._lastY:
            return
        # vertical line
        elif x == self._lastX:
            cmd = "V"
            pts = valueToString(y)
        # horizontal line
        elif y == self._lastY:
            cmd = "H"
            pts = valueToString(x)
        # previous was a moveto
        elif self._lastCommand == "M":
            cmd = None
            pts = " " + pointToString(pt)
        # basic
        else:
            cmd = "L"
            pts = pointToString(pt)
        # write the string
        t = ""
        if cmd:
            t += cmd
            self._lastCommand = cmd
        t += pts
        self._commands.append(t)
        # store for future reference
        self._lastX, self._lastY = pt
예제 #16
0
    def _lineTo(self, pt):
        """
        # duplicate point
        >>> pen = SVGPathPen(None)
        >>> pen.moveTo((10, 10))
        >>> pen.lineTo((10, 10))
        >>> pen._commands
        ['M10 10']

        # vertical line
        >>> pen = SVGPathPen(None)
        >>> pen.moveTo((10, 10))
        >>> pen.lineTo((10, 0))
        >>> pen._commands
        ['M10 10', 'V0']

        # horizontal line
        >>> pen = SVGPathPen(None)
        >>> pen.moveTo((10, 10))
        >>> pen.lineTo((0, 10))
        >>> pen._commands
        ['M10 10', 'H0']

        # basic
        >>> pen = SVGPathPen(None)
        >>> pen.lineTo((70, 80))
        >>> pen._commands
        ['L70 80']

        # basic following a moveto
        >>> pen = SVGPathPen(None)
        >>> pen.moveTo((0, 0))
        >>> pen.lineTo((10, 10))
        >>> pen._commands
        ['M0 0', ' 10 10']
        """
        x, y = pt
        # duplicate point
        if x == self._lastX and y == self._lastY:
            return
        # vertical line
        elif x == self._lastX:
            cmd = "V"
            pts = valueToString(y)
        # horizontal line
        elif y == self._lastY:
            cmd = "H"
            pts = valueToString(x)
        # previous was a moveto
        elif self._lastCommand == "M":
            cmd = None
            pts = " " + pointToString(pt)
        # basic
        else:
            cmd = "L"
            pts = pointToString(pt)
        # write the string
        t = ""
        if cmd:
            t += cmd
            self._lastCommand = cmd
        t += pts
        self._commands.append(t)
        # store for future reference
        self._lastX, self._lastY = pt