The whole gnomeprint API seems to be woefully under-documented, and one
can only derive so much from the examples.

Anyway, long story short, I have made some progress towards
understanding how it works on the "really basic" level.

The basic steps are:
1) Create a configuration. There is a default one available; apparently
there is a "Print Setup" dialog of some sort that can be used customize
one, as well as load/save routines.

2) Create a job. This will end up as a single job in the print queue.

3) Get the drawing context from the job. This gets passed to your "real"
print routine and exposes a postscript-like API.

4) KEY POINT - use context.pango_layout to lay out paragraphs. If you
don't do this, you end up doing your own line-breaking routines, font
formatting, etc. Which you *will* get wrong for most languages except
your native one. This is why we have pango in the first place.

5) Call job.close when finished, then pass off to print or print preview
routines. Print preview example below.

If anyone can correct me or supply better examples, please do so. I am
still figuring this stuff out.
-----
import gnomeprint, gnomeprint.ui
import pango

class SimplePrint:
        def printPreview(self):
                "Print Preview the document"
                config = gnomeprint.config_default()
                job = gnomeprint.Job(config)
                context = job.get_context()
                self.printBlock(context)
                job.close()
                gnomeprint.ui.JobPreview(job, "NPC Stat Block").show()

        def printBlock(self, context, markup):
                "Print some markup to the supplied context"
                context.beginpage("1")
                context.moveto(50, 800)
                #need to use pango.Layout to format paragraphs
                #for each block of text
                paraContext =
gnomeprint.pango_create_context(gnomeprint.pango_get_default_font_map())
                para = pango.Layout(paraContext)
                para.set_markup(markup)
                context.pango_layout(para)
                context.showpage()

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
pygtk mailing list   [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to