コード例 #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))
コード例 #2
0
    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))
コード例 #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
コード例 #4
0
    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
コード例 #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)
コード例 #6
0
 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)
コード例 #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)
コード例 #8
0
ファイル: drawBotDrawingTools.py プロジェクト: imclab/drawbot
    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))
コード例 #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))
コード例 #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
コード例 #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
コード例 #12
0
def _deprecatedWarningLowercase(txt):
    warnings.warn("lowercase API is deprecated use: '%s'" % txt)
コード例 #13
0
 def _get_height(self):
     warnings.warn("Magic variables are deprecated.'")
     return self.height()
コード例 #14
0
 def _get_height(self):
     warnings.warn("Magic variables are deprecated.'")
     return self.height()
コード例 #15
0
 def _get_width(self):
     warnings.warn("Magic variables are deprecated.'")
     return self.width()
コード例 #16
0
 def _get_width(self):
     warnings.warn("Magic variables are deprecated.'")
     return self.width()
コード例 #17
0
 def _get_pageCount(self):
     warnings.warn("Magic variables are deprecated.'")
     return self.pageCount()
コード例 #18
0
 def _get_pageCount(self):
     warnings.warn("Magic variables are deprecated.'")
     return self.pageCount()
コード例 #19
0
def _deprecatedWarningLowercase(txt):
    warnings.warn("lowercase API is deprecated use: '%s'" % txt)
コード例 #20
0
def _deprecatedWarningWrapInTuple(txt):
    warnings.warn("deprecated syntax, wrap x and y values in a tuple: '%s'" %
                  txt)
コード例 #21
0
def _deprecatedWarningWrapInTuple(txt):
    warnings.warn("deprecated syntax, wrap x and y values in a tuple: '%s'" % txt)