def doTest(self): go_on = False if len(fl) > 0: if self.OutPath == '': if self.showDialog == OK: go_on = True else: if os.path.isdir(os.path.dirname(self.OutPath)): go_on = True if go_on: fl.BeginProgress('checking fonts', len(self)) self.XMLwriter = XMLWriter(self.OutPath, self.indentStr) procInst = '<?xml-stylesheet type="text/xsl" href="%s"?>' % XSL_FileName self.XMLwriter.writeraw(procInst) self.XMLwriter.newline() timeStr = time.strftime('%Y.%m.%d-%H:%M:%S', time.localtime()) self.XMLwriter.begintag(self.name, RunDateTime=timeStr) self.XMLwriter.newline() self.XMLwriter.begintag('FontList') self.XMLwriter.newline() for anyFont in self.testFontList: self.XMLwriter.simpletag('Font', FullName=anyFont.full_name, Path=anyFont.file_name) self.XMLwriter.newline() self.XMLwriter.endtag('FontList') self.XMLwriter.newline() self.XMLwriter.begintag('TestSuite') self.XMLwriter.newline() counter = 1 for anyBlock in self.testBlockList: if anyBlock.isSelected: anyBlock.XMLwriter = self.XMLwriter anyBlock._doTest() fl.TickProgress(counter) counter += 1 self.XMLwriter.endtag('TestSuite') self.XMLwriter.newline() self.XMLwriter.endtag(self.name) self.XMLwriter.newline() self.XMLwriter.close() fl.EndProgress() styleSheetTargetPath = os.path.join(os.path.dirname(self.OutPath), XSL_FileName) if os.path.isfile(styleSheetTargetPath): os.remove(styleSheetTargetPath) shutil.copy2(XSL_FilePath, styleSheetTargetPath) if self.showReport: webbrowser.open(self.OutPath)
def _newPage(self, width, height): if hasattr(self, "_svgContext"): self._svgContext.endtag("svg") self.reset() self.size(width, height) self._svgData = self._svgFileClass() self._pages.append(self._svgData) self._svgContext = XMLWriter(self._svgData, encoding="utf-8") self._svgContext.width = self.width self._svgContext.height = self.height self._svgContext.begintag("svg", width=self.width, height=self.height, **self._svgTagArguments) self._svgContext.newline() self._state.transformMatrix = self._state.transformMatrix.scale( 1, -1).translate(0, -self.height)
def writeGlyphToString(glyphName, glyphObject=None, drawPointsFunc=None, writer=None): """Return .glif data for a glyph as a UTF-8 encoded string. The 'glyphObject' argument can be any kind of object (even None); the writeGlyphToString() method will attempt to get the following attributes from it: "width" the advance with of the glyph "unicodes" a list of unicode values for this glyph "note" a string "lib" a dictionary containing custom data All attributes are optional: if 'glyphObject' doesn't have the attribute, it will simply be skipped. To write outline data to the .glif file, writeGlyphToString() needs a function (any callable object actually) that will take one argument: an object that conforms to the PointPen protocol. The function will be called by writeGlyphToString(); it has to call the proper PointPen methods to transfer the outline to the .glif file. """ if writer is None: try: from xmlWriter import XMLWriter except ImportError: # try the other location from fontTools.misc.xmlWriter import XMLWriter aFile = StringIO() writer = XMLWriter(aFile, encoding="UTF-8") else: aFile = None writer.begintag("glyph", [("name", glyphName), ("format", "1")]) writer.newline() width = getattr(glyphObject, "width", None) if width is not None: if not isinstance(width, (int, float)): raise GlifLibError, "width attribute must be int or float" writer.simpletag("advance", width=repr(width)) writer.newline() unicodes = getattr(glyphObject, "unicodes", None) if unicodes: if isinstance(unicodes, int): unicodes = [unicodes] for code in unicodes: if not isinstance(code, int): raise GlifLibError, "unicode values must be int" hexCode = hex(code)[2:].upper() if len(hexCode) < 4: hexCode = "0" * (4 - len(hexCode)) + hexCode writer.simpletag("unicode", hex=hexCode) writer.newline() note = getattr(glyphObject, "note", None) if note is not None: if not isinstance(note, (str, unicode)): raise GlifLibError, "note attribute must be str or unicode" note = note.encode('utf-8') writer.begintag("note") writer.newline() for line in note.splitlines(): writer.write(line.strip()) writer.newline() writer.endtag("note") writer.newline() if drawPointsFunc is not None: writer.begintag("outline") writer.newline() pen = GLIFPointPen(writer) drawPointsFunc(pen) writer.endtag("outline") writer.newline() lib = getattr(glyphObject, "lib", None) if lib: from robofab.plistlib import PlistWriter if not isinstance(lib, dict): lib = dict(lib) writer.begintag("lib") writer.newline() plistWriter = PlistWriter(writer.file, indentLevel=writer.indentlevel, indent=writer.indentwhite, writeHeader=False) plistWriter.writeValue(lib) writer.endtag("lib") writer.newline() writer.endtag("glyph") writer.newline() if aFile is not None: return aFile.getvalue() else: return None
def __init__(self): self._file = StringIO() self._writer = XMLWriter(self._file, encoding="utf-8")