def create_hatch(self, hatch): sidelen = 72 if self._hatches.has_key(hatch): return self._hatches[hatch] name = 'H%d' % len(self._hatches) self._pswriter.write("""\ << /PatternType 1 /PaintType 2 /TilingType 2 /BBox[0 0 %(sidelen)d %(sidelen)d] /XStep %(sidelen)d /YStep %(sidelen)d /PaintProc { pop 0 setlinewidth """ % locals()) self._pswriter.write( self._convert_path(Path.hatch(hatch), Affine2D().scale(72.0))) self._pswriter.write("""\ stroke } bind >> matrix makepattern /%(name)s exch def """ % locals()) self._hatches[hatch] = name return name
def _writeHatches(self): hatchDict = dict() sidelen = 72.0 for hatch_style, name in six.iteritems(self.hatchPatterns): ob = self.reserveObject('hatch pattern') hatchDict[name] = ob res = { 'Procsets': [Name(x) for x in "PDF Text ImageB ImageC ImageI".split()] } self.beginStream( ob.id, None, { 'Type': Name('Pattern'), 'PatternType': 1, 'PaintType': 1, 'TilingType': 1, 'BBox': [0, 0, sidelen, sidelen], 'XStep': sidelen, 'YStep': sidelen, 'Resources': res }) # lst is a tuple of stroke color, fill color, # number of - lines, number of / lines, # number of | lines, number of \ lines rgb = hatch_style[0] self.output(rgb[0], rgb[1], rgb[2], Op.setrgb_stroke) if hatch_style[1] is not None: rgb = hatch_style[1] self.output(rgb[0], rgb[1], rgb[2], Op.setrgb_nonstroke, 0, 0, sidelen, sidelen, Op.rectangle, Op.fill) self.output(customWidth, Op.setlinewidth) ###the new width### # TODO: We could make this dpi-dependent, but that would be # an API change self.output(*self.pathOperations(Path.hatch(hatch_style[2]), Affine2D().scale(sidelen), simplify=False)) self.output(Op.stroke) self.endStream() self.writeObject(self.hatchObject, hatchDict)
def _writeHatches(self): hatchDict = dict() sidelen = 72.0 for hatch_style, name in self.hatchPatterns.iteritems(): ob = self.reserveObject('hatch pattern') hatchDict[name] = ob res = { 'Procsets': [Name(x) for x in "PDF Text ImageB ImageC ImageI".split()] } self.beginStream( ob.id, None, { 'Type': Name('Pattern'), 'PatternType': 1, 'PaintType': 1, 'TilingType': 1, 'BBox': [0, 0, sidelen, sidelen], 'XStep': sidelen, 'YStep': sidelen, 'Resources': res }) stroke_rgb, fill_rgb, path = hatch_style self.output(stroke_rgb[0], stroke_rgb[1], stroke_rgb[2], Op.setrgb_stroke) if fill_rgb is not None: self.output(fill_rgb[0], fill_rgb[1], fill_rgb[2], Op.setrgb_nonstroke, 0, 0, sidelen, sidelen, Op.rectangle, Op.fill) self.output(customWidth, Op.setlinewidth) # TODO: We could make this dpi-dependent, but that would be # an API change self.output(*self.pathOperations( Path.hatch(path), Affine2D().scale(sidelen), simplify=False)) self.output(Op.stroke) self.endStream() self.writeObject(self.hatchObject, hatchDict)