[reportlab-users] WYSIWYG with reportlab and pygtk
Robin Becker
robin at reportlab.com
Mon Feb 5 19:15:42 EST 2007
Tobias Ceglarek wrote:
> hello,
>
> my goal is to create a little tool to interactively produce simple
> documents with the principle of "What You See Is What You Get".
>
> 1. the user interface i have implemented with pygtk:
>
> there is a textview connected to a textbuffer with a fonttag:
>
> size:
> myTextView.set_size_request(298,210) # = 10.5*cm,7.4*cm
>
> font:
> myFontTag.set_property("font","Century Schoolbook L 10")
>
> 2. i register a type-1 font and use it within a paragraphstyle
>
> folder = '/usr/share/fonts/type1/gsfonts/'
> afmFile = folder + 'c059013l.afm'
> pfbFile = folder + 'c059013l.pfb'
> justFace = pdfmetrics.EmbeddedType1Face(afmFile, pfbFile)
> faceName = 'CenturySchL-Roma' # pulled from AFM file
> pdfmetrics.registerTypeFace(justFace)
> justFont = pdfmetrics.Font('CenturySchL-Roma', faceName,
> 'WinAnsiEncoding')
> pdfmetrics.registerFont(justFont)
>
> ...
>
> docPagesize = (10.5*cm,7.4*cm)
>
> ...
>
> style1 = ParagraphStyle(
> "VorderseiteStyle",
> fontName="CenturySchL-Roma",
> fontSize=10,
> #leading=16,
> leftIndent=0,
> rightIndent=0,
> firstLineIndent=0,
> alignment=TA_CENTER,
> spaceBefore=0,
> spaceAfter=0,
> bulletFontName="CenturySchL-Roma",
> bulletFontSize=10,
> bulletIndent=0,
> textColor=black,
> backColor=None
> )
>
> the effect is the same font (in the user interface and the pdf output).
> but the fonts have not exactly the same size and/or spaces between words
> and/or letters.
>
> i would be glad if anyone can help me or just give a hint.
>
> perhaps my attempt is wrong/too complicated - how would you make a
> simple wysiwyg document?
>
> regards,
>
> prinz igor
>
.......
well I suppose we're in the area of what 10 means. Have you measured the
length of a string on the screen and compared what
reportlab.pdfmetrics.stringWidth says about the same string. Type 1
fonts are supposed to be sized in termos of a 1000 point box. I'm not
exactly sure what
myFontTag.set_property("font","Century Schoolbook L 10")
is supposed to do, but I suspect the outcome may depend on 1) whether
the 10 implies points or pixels & 2) what the dpi is for the screen.
The implication is that there should be a constant scale factor bwteen
what reportlab/pdf thinks a string width should be and how your graphics
framework draws it. If the 10 is pixels and not points then a 72 point
widestring will become dpi pixels wide where dpi is probably 96.
--
Robin Becker
More information about the reportlab-users
mailing list