Exemple #1
0
    def __init__(self, bb_pt, name, defaultvalue, fontsize, font, fontleading,
        borderwidth, vcenter,
        alignflag, annotflag, formflag, fillstyles, writer, registry):

        pdfwriter.PDFobject.__init__(self, "formfield_text")

        # append this formfield to the global document form
        # and to the annotation list of the page:
        self.PDFform = None
        for object in registry.objects:
            if object.type == "form":
                object.append(self)
                self.PDFform = object
            elif object.type == "annotations":
                object.append(self)

        self.name = name
        self.bb_pt = bb_pt
        self.defaultvalue = defaultvalue
        self.fontsize = fontsize
        self.font = font
        if self.font is None:
            self.font = PDFHelvetica
        self.fontleading = fontleading
        self.borderwidth = borderwidth
        self.alignflag = alignflag
        self.formflag = formflag
        self.annotflag = annotflag

        self.registry = pdfwriter.PDFregistry()
        self.registry.addresource("Font", self.font.name, self.font, procset="Text")
        self.registry.add(self.font)

        if self.defaultvalue:
            text = self.defaultvalue.split("\n")
            self.defaulttext = PDFdefaulttext(writer, registry, self.fontsize, self.font,
                self.fontleading, text, self.bb_pt, self.borderwidth, vcenter)
            self.registry.add(self.defaulttext)
        else:
            self.defaulttext = None

        # process some fillstyles:
        fillstring = cStringIO.StringIO()
        for attr in fillstyles:
            if 1:#isinstance(attr, color.color):
                cont = pdfwriter.context()
                cont.fillattr = 1
                cont.strokeattr = 0
                attr.processPDF(fillstring, writer, cont, self.registry, bbox)
        self.fillstyles = fillstring.getvalue()
        fillstring.close()

        registry.mergeregistry(self.registry)
Exemple #2
0
    def processPDF(self, file, writer, context, registry, bbox):
        # we need to keep track of the resources used by the pattern, hence
        # we create our own registry, which we merge immediately in the main registry
        patternregistry = pdfwriter.PDFregistry()

        patternfile = cStringIO.StringIO()
        realpatternbbox = bboxmodule.empty()
        canvas.canvas.processPDF(self, patternfile, writer,
                                 pdfwriter.context(), patternregistry,
                                 realpatternbbox)
        patternproc = patternfile.getvalue()
        patternfile.close()

        registry.mergeregistry(patternregistry)

        if self.xstep is None:
            xstep = unit.topt(realpatternbbox.width())
        else:
            xstep = unit.topt(self.xstep)
        if self.ystep is None:
            ystep = unit.topt(realpatternbbox.height())
        else:
            ystep = unit.topt(self.ystep)
        if not xstep:
            raise ValueError("xstep in pattern cannot be zero")
        if not ystep:
            raise ValueError("ystep in pattern cannot be zero")
        patternbbox = self.patternbbox or realpatternbbox.enlarged(5 * unit.pt)
        patterntrafo = self.patterntrafo or trafo.trafo()

        registry.add(
            PDFpattern(self.id, self.patterntype, self.painttype,
                       self.tilingtype, patternbbox, xstep, ystep,
                       patterntrafo, patternproc, writer, registry,
                       patternregistry))

        # activate pattern
        if context.colorspace != "Pattern":
            # we only set the fill color space (see next comment)
            file.write("/Pattern cs\n")
            context.colorspace = "Pattern"
        if context.strokeattr:
            # using patterns as stroke colors doesn't seem to work, so
            # we just don't do this...
            warnings.warn("ignoring stroke color for patterns in PDF")
        if context.fillattr:
            file.write("/%s scn\n" % self.id)
Exemple #3
0
    def processPDF(self, file, writer, context, registry, bbox):
        # we need to keep track of the resources used by the pattern, hence
        # we create our own registry, which we merge immediately in the main registry
        patternregistry = pdfwriter.PDFregistry()

        patternfile = cStringIO.StringIO()
        realpatternbbox = bboxmodule.empty()
        canvas._canvas.processPDF(self, patternfile, writer, pdfwriter.context(), patternregistry, realpatternbbox)
        patternproc = patternfile.getvalue()
        patternfile.close()

        registry.mergeregistry(patternregistry)

        if self.xstep is None:
           xstep = unit.topt(realpatternbbox.width())
        else:
           xstep = unit.topt(self.xstep)
        if self.ystep is None:
            ystep = unit.topt(realpatternbbox.height())
        else:
           ystep = unit.topt(self.ystep)
        if not xstep:
            raise ValueError("xstep in pattern cannot be zero")
        if not ystep:
            raise ValueError("ystep in pattern cannot be zero")
        patternbbox = self.patternbbox or realpatternbbox.enlarged(5*unit.pt)
        patterntrafo = self.patterntrafo or trafo.trafo()

        registry.add(PDFpattern(self.id, self.patterntype, self.painttype, self.tilingtype,
                                patternbbox, xstep, ystep, patterntrafo, patternproc, writer, registry, patternregistry))

        # activate pattern
        if context.colorspace != "Pattern":
            # we only set the fill color space (see next comment)
            file.write("/Pattern cs\n")
            context.colorspace = "Pattern"
        if context.strokeattr:
            # using patterns as stroke colors doesn't seem to work, so
            # we just don't do this...
            warnings.warn("ignoring stroke color for patterns in PDF")
        if context.fillattr:
            file.write("/%s scn\n"% self.id)