def __init__(self, graph, data, styles): self.data = data self.title = data.title addstyles = [None] while addstyles: # add styles to ensure all needs of the given styles provided = [] # already provided sharedata variables addstyles = [] # a list of style instances to be added in front for s in styles: for n in s.needsdata: if n not in provided: defaultprovider = getdefaultprovider(n) addstyles.append(defaultprovider) provided.extend(defaultprovider.providesdata) provided.extend(s.providesdata) styles = addstyles + styles self.styles = styles self.sharedata = styledata() self.dataaxisnames = {} self.privatedatalist = [styledata() for s in self.styles] # perform setcolumns to all styles self.usedcolumnnames = pycompat.set() for privatedata, s in zip(self.privatedatalist, self.styles): self.usedcolumnnames.update(pycompat.set(s.columnnames(privatedata, self.sharedata, graph, self.data.columnnames, self.dataaxisnames)))
def __init__(self, t1file, glyphnames, charcodes): """ include type 1 font t1file stripped to the given glyphnames""" self.type = "t1file" self.t1file = t1file self.id = t1file.name self.glyphnames = pycompat.set(glyphnames) self.charcodes = pycompat.set(charcodes)
def __init__(self, fontname, basefontname, charcodes, fontdescriptor, encoding, metric): pdfwriter.PDFobject.__init__(self, "font", fontname) self.fontname = fontname self.basefontname = basefontname self.charcodes = pycompat.set(charcodes) self.fontdescriptor = fontdescriptor self.encoding = encoding self.metric = metric
def getstrippedfont(self, glyphs, charcodes): """create a T1file instance containing only certain glyphs glyphs is a set of the glyph names. It might be modified *in place*! """ # TODO: we could also strip othersubrs to those actually used if not self.encoding: self._encoding() for charcode in charcodes: glyphs.add(self.encoding[charcode]) # collect information about used glyphs and subrs seacglyphs = pycompat.set() subrs = pycompat.set() othersubrs = pycompat.set() for glyph in glyphs: self.gatherglyphcalls(glyph, seacglyphs, subrs, othersubrs, T1context(self)) # while we have gathered all subrs for the seacglyphs alreadys, we # might have missed the glyphs themself (when they are not used stand-alone) glyphs.update(seacglyphs) glyphs.add(".notdef") # strip data1 if self.encoding is adobestandardencoding: data1 = self.data1 else: encodingstrings = [] for char, glyph in enumerate(self.encoding): if glyph in glyphs: encodingstrings.append("dup %i /%s put\n" % (char, glyph)) data1 = self.data1[:self.encodingstart] + "".join(encodingstrings) + self.data1[self.encodingend:] data1 = self.newlinepattern.subn("\n", data1)[0] data1 = self.uniqueidpattern.subn("", data1)[0] # strip data2 data2 = self.uniqueidpattern.subn("", self.getdata2(subrs, glyphs))[0] # strip data3 data3 = self.newlinepattern.subn("\n", self.data3)[0] # create and return the new font instance return T1file(data1.rstrip() + "\n", self._eexecencode(data2), data3.rstrip() + "\n")
def getencodingname(self, encodings): """returns the name of the encoding (in encodings) mapping self.glyphnames to codepoints If no such encoding can be found or extended, a new encoding is added to encodings """ glyphnames = pycompat.set(self.glyphnames) if len(glyphnames) > 256: raise ValueError("glyphs do not fit into one single encoding") for encodingname, encoding in encodings.items(): glyphsmissing = [] for glyphname in glyphnames: if glyphname not in encoding.keys(): glyphsmissing.append(glyphname) if len(glyphsmissing) + len(encoding) < 256: # new glyphs fit in existing encoding which will thus be extended for glyphname in glyphsmissing: encoding[glyphname] = len(encoding) return encodingname # create a new encoding for the glyphnames encodingname = "encoding%d" % len(encodings) encodings[encodingname] = dict([(glyphname, i) for i, glyphname in enumerate(glyphnames)]) return encodingname
def getencodingname(self, encodings): """returns the name of the encoding (in encodings) mapping self.glyphnames to codepoints If no such encoding can be found or extended, a new encoding is added to encodings """ glyphnames = pycompat.set(self.glyphnames) if len(glyphnames) > 256: raise ValueError("glyphs do not fit into one single encoding") for encodingname, encoding in encodings.items(): glyphsmissing = [] for glyphname in glyphnames: if glyphname not in encoding.keys(): glyphsmissing.append(glyphname) if len(glyphsmissing) + len(encoding) < 256: # new glyphs fit in existing encoding which will thus be extended for glyphname in glyphsmissing: encoding[glyphname] = len(encoding) return encodingname # create a new encoding for the glyphnames encodingname = "encoding%d" % len(encodings) encodings[encodingname] = dict([ (glyphname, i) for i, glyphname in enumerate(glyphnames) ]) return encodingname
def merge_lists(self, lists): "merges list items w/o duplications, resulting order is arbitraty" result = pycompat.set() for l in lists: result.update(pycompat.set(l)) return builtinlist(result)
def __init__(self, t1file, glyphnames, charcodes): pdfwriter.PDFobject.__init__(self, "fontfile", t1file.name) self.t1file = t1file self.glyphnames = pycompat.set(glyphnames) self.charcodes = pycompat.set(charcodes)