Ejemplo n.º 1
0
    def text(self, txt, x, y=None):
        """
        Draw a text at a provided position.

        .. showcode:: /../examples/text.py
        """
        if isinstance(txt, (str, unicode)):
            try:
                txt = txt.decode("utf-8")
            except UnicodeEncodeError:
                pass
        if y is None:
            x, y = x
        else:
            warnings.warn("position must a tuple: text('%s', (%s, %s))" %
                          (txt, x, y))
        attrString = self._dummyContext.attributedString(txt)
        w, h = attrString.size()
        setter = CoreText.CTFramesetterCreateWithAttributedString(attrString)
        path = Quartz.CGPathCreateMutable()
        Quartz.CGPathAddRect(path, None, Quartz.CGRectMake(x, y, w * 2, h))
        box = CoreText.CTFramesetterCreateFrame(setter, (0, 0), path, None)
        ctLines = CoreText.CTFrameGetLines(box)
        origins = CoreText.CTFrameGetLineOrigins(box, (0, len(ctLines)), None)
        if origins:
            x -= origins[-1][0]
            y -= origins[-1][1]
        self.textBox(txt, (x, y - h, w * 2, h * 2))
    def text(self, txt, x, y=None):
        """
        Draw a text at a provided position.

        .. showcode:: /../examples/text.py
        """
        try:
            txt = txt.decode("utf-8")
        except:
            pass
        if isinstance(x, (tuple, list)):
            x, y = x
        else:
            warnings.warn("postion must a tuple: text('%s', (%s, %s))" % (txt, x, y))
        attrString = self._dummyContext.attributedString(txt)
        w, h = attrString.size()
        setter = CoreText.CTFramesetterCreateWithAttributedString(attrString)
        path = Quartz.CGPathCreateMutable()
        Quartz.CGPathAddRect(path, None, Quartz.CGRectMake(x, y, w*2, h))
        box = CoreText.CTFramesetterCreateFrame(setter, (0, 0), path, None)
        ctLines = CoreText.CTFrameGetLines(box)
        origins = CoreText.CTFrameGetLineOrigins(box, (0, len(ctLines)), None)
        if origins:
            x -= origins[-1][0]
            y -= origins[-1][1]
        self.textBox(txt, (x, y-h, w*2, h*2))
Ejemplo n.º 3
0
    def installFont(self, path):
        """
        Install a font with a given path and the postscript font name will be returned.
        The postscript font name can be used to set the font as the active font.

        Fonts are installed only for the current process.
        Fonts will not be accesible outside the scope of drawBot.

        All installed fonts will automatically be uninstalled when the script is done.

        .. showcode:: /../examples/installFont.py
        """
        success, error = self._dummyContext.installFont(path)
        self._installedFontPaths.add(path)
        self._addInstruction("installFont", path)

        from fontTools.ttLib import TTFont, TTLibError
        try:
            font = TTFont(path)
            psName = font["name"].getName(6, 1, 0)
            if psName is None:
                psName = font["name"].getName(6, 3, 1)
            font.close()
        except IOError:
            raise DrawBotError("Font '%s' does not exist." % path)
        except TTLibError:
            raise DrawBotError("Font '%s' is not a valid font." % path)
        if psName is not None:
            psName = psName.toUnicode()

        if not success:
            warnings.warn("install font: %s" % error)
        return psName
    def installFont(self, path):
        """
        Install a font with a given path.
        """
        success, error = self._dummyContext.installFont(path)
        self._installedFontPaths.add(path)
        self._addInstruction("installFont", path)

        from fontTools.ttLib import TTFont, TTLibError
        try:
            font = TTFont(path)
            psName = font["name"].getName(6, 1, 0)
            if psName is None:
                psName = font["name"].getName(6, 3, 1)
            font.close()
        except IOError:
            raise DrawBotError("Font '%s' does not exist." % path)
        except TTLibError:
            raise DrawBotError("Font '%s' is not a valid font." % path)
        if psName is not None:
            psName = psName.toUnicode()

        if not success:
            warnings.warn("install font: %s" % error)
        return psName
Ejemplo n.º 5
0
 def uninstallFont(self, path):
     """
     Uninstall a font with a given path.
     """
     succes, error = self._dummyContext.uninstallFont(path)
     if not succes:
         warnings.warn("uninstall font: %s" % error)
     self._addInstruction("uninstallFont", path)
 def uninstallFont(self, path):
     """
     Uninstall a font with a given path.
     All installed fonts will automatically be uninstalled when the script is done.
     """
     succes, error = self._dummyContext.uninstallFont(path)
     if not succes:
         warnings.warn("uninstall font: %s" % error)
     self._addInstruction("uninstallFont", path)
Ejemplo n.º 7
0
 def uninstallFont(self, path):
     """
     Uninstall a font with a given path.
     """
     success, error = self._dummyContext.uninstallFont(path)
     if path in self._tempInstalledFonts:
         del self._tempInstalledFonts[path]
     if not success:
         warnings.warn("uninstall font: %s" % error)
     self._addInstruction("uninstallFont", path)
Ejemplo n.º 8
0
    def text(self, txt, x, y=None):
        """
        Draw a text at a provided position.

        .. showcode:: /../examples/text.py
        """
        if isinstance(x, (tuple, list)):
            x, y = x
        else:
            warnings.warn("postion must a tuple: text('%s', (%s, %s))" % (txt, x, y))
        w, h = self.textSize(txt)
        self.textBox(txt, (x, y, w*1.3, h))
Ejemplo n.º 9
0
    def text(self, txt, x, y=None):
        """
        Draw a text at a provided position.

        .. showcode:: /../examples/text.py
        """
        if isinstance(x, (tuple, list)):
            x, y = x
        else:
            warnings.warn("postion must a tuple: text('%s', (%s, %s))" %
                          (txt, x, y))
        w, h = self.textSize(txt)
        self.textBox(txt, (x, y, w * 1.3, h))
Ejemplo n.º 10
0
    def installFont(self, path):
        """
        Install a font with a given path and the postscript font name will be returned.
        The postscript font name can be used to set the font as the active font.

        Fonts are installed only for the current process.
        Fonts will not be accesible outside the scope of drawBot.

        All installed fonts will automatically be uninstalled when the script is done.

        .. showcode:: /../examples/installFont.py
        """
        if path in self._tempInstalledFonts:
            return self._tempInstalledFonts[path]

        success, error = self._dummyContext.installFont(path)
        self._addInstruction("installFont", path)

        psName = self._dummyContext._fontNameForPath(path)
        self._tempInstalledFonts[path] = psName

        if not success:
            warnings.warn("install font: %s" % error)
        return psName
Ejemplo n.º 11
0
    def installFont(self, path):
        """
        Install a font with a given path and the postscript font name will be returned.
        The postscript font name can be used to set the font as the active font.

        Fonts are installed only for the current process.
        Fonts will not be accesible outside the scope of drawBot.

        All installed fonts will automatically be uninstalled when the script is done.

        .. showcode:: /../examples/installFont.py
        """
        if path in self._tempInstalledFonts:
            return self._tempInstalledFonts[path]

        success, error = self._dummyContext.installFont(path)
        self._addInstruction("installFont", path)

        psName = self._dummyContext._fontNameForPath(path)
        self._tempInstalledFonts[path] = psName

        if not success:
            warnings.warn("install font: %s" % error)
        return psName
Ejemplo n.º 12
0
def _deprecatedWarningLowercase(txt):
    warnings.warn("lowercase API is deprecated use: '%s'" % txt)
Ejemplo n.º 13
0
 def _get_height(self):
     warnings.warn("Magic variables are deprecated.'")
     return self.height()
 def _get_height(self):
     warnings.warn("Magic variables are deprecated.'")
     return self.height()
 def _get_width(self):
     warnings.warn("Magic variables are deprecated.'")
     return self.width()
Ejemplo n.º 16
0
 def _get_width(self):
     warnings.warn("Magic variables are deprecated.'")
     return self.width()
 def _get_pageCount(self):
     warnings.warn("Magic variables are deprecated.'")
     return self.pageCount()
Ejemplo n.º 18
0
 def _get_pageCount(self):
     warnings.warn("Magic variables are deprecated.'")
     return self.pageCount()
def _deprecatedWarningLowercase(txt):
    warnings.warn("lowercase API is deprecated use: '%s'" % txt)
Ejemplo n.º 20
0
def _deprecatedWarningWrapInTuple(txt):
    warnings.warn("deprecated syntax, wrap x and y values in a tuple: '%s'" %
                  txt)
def _deprecatedWarningWrapInTuple(txt):
    warnings.warn("deprecated syntax, wrap x and y values in a tuple: '%s'" % txt)