[reportlab-users] Font Helvetica always used?

Robin Becker robin at reportlab.com
Fri Jun 19 05:13:29 EDT 2015


On 18/06/2015 23:50, Glenn Linderman wrote:
> On 6/18/2015 12:59 PM, Robin Becker wrote:
>
............
> from reportlab.pdfbase.ttfonts import TTFont
> from reportlab.pdfbase.pdfmetrics import registerFont, registerFontFamily
> registerFont(TTFont('arial','arial.ttf'),)
> registerFont(TTFont('arial-bold','arialbd.ttf'),)
> registerFont(TTFont('arial-italic','ariali.ttf'),)
> registerFont(TTFont('arial-bolditalic','arialbi.ttf'),)
> registerFontFamily('arial',
>              normal='arial',
>              bold='arial-bold',
>              italic='arial-italic',
>              boldItalic='arial-bolditalic',
>              )
> canv = reportlab.pdfgen.canvas.Canvas( sys.stdout )
> canv.setFont('arial', 10 )
>
>
> before doing any other Canvas operations, that 'Helvetica' will not appear in
> the output file?
>
> That seems simpler than doing all the configuration stuff ahead of time...
> because the registration of fonts is often coded around the same time as the
> Canvas is initialized in setup code.
>
> I suppose the reason you described the configuration tricks first, is that once
> created they minimize the code changes in all the applications using that
> configuration.
.......
unfortunately not, it seems as though we are setting up the graphics state 
before you can set the font, so it really needs to be in the config stuff. Even 
though we never use the Helvetica font it still appears as a resource.

Probably it would be better to allow a canvas argument to be used to initialize 
the graphics state. There are a lot of things in there, but the one that's 
bothersome is the font.


> def init_graphics_state(self):
> 		#initial graphics state, never modify any of these in place
> 		self._x = 0
> 		self._y = 0
> 		self._fontname = rl_config.canvas_basefontname
> 		self._fontsize = 12
>
> 		self._textMode = 0	#track if between BT/ET
> 		self._leading = 14.4
> 		self._currentMatrix = (1., 0., 0., 1., 0., 0.)
> 		self._fillMode = 0	 #even-odd
>
> 		#text state
> 		self._charSpace = 0
> 		self._wordSpace = 0
> 		self._horizScale = 100
> 		self._textRenderMode = 0
> 		self._rise = 0
> 		self._textLineMatrix = (1., 0., 0., 1., 0., 0.)
> 		self._textMatrix = (1., 0., 0., 1., 0., 0.)
>
> 		# line drawing
> 		self._lineCap = 0
> 		self._lineJoin = 0
> 		self._lineDash = None  #not done
> 		self._lineWidth = 1
> 		self._mitreLimit = 0
>
> 		self._fillColorObj = self._strokeColorObj = rl_config.canvas_baseColor or (0,0,0)
> 		self._extgstate = ExtGState()





-- 
Robin Becker


More information about the reportlab-users mailing list