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))
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
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)
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)
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))
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))
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
def _deprecatedWarningLowercase(txt): warnings.warn("lowercase API is deprecated use: '%s'" % txt)
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()
def _get_pageCount(self): warnings.warn("Magic variables are deprecated.'") return self.pageCount()
def _deprecatedWarningWrapInTuple(txt): warnings.warn("deprecated syntax, wrap x and y values in a tuple: '%s'" % txt)