Lino Website

Fixed bugs

Font height/width ratio with Win32TextPrinter

Friday, 22. September 2006 15:39.

Win32TextPrinter.setCpi() rendered the characters a little bit bigger than they should.

The new file 3.prn demonstrates the problem. It uses the new method TextPrinter.insertDebugRulers().

lino prnprint -o c:\temp\ -p "Lexmark Optra PS" 3.prn

Here is the result of this command: As you can see in this result, for example for the 10 cpi ruler: we expect to get 78 characters per line, but we get less than 74.

The problem was located in Win32TextPrinter.setCpi().

def setCpi(self,cpi):

"""Set font size by specifying characters per inch. """ self.cpi=cpi w = int(inch/cpi) self.logfont.lfWidth=w self.logfont.lfHeight=int(w*RATIO) self.cpl = int(self.lineWidth()/inch*cpi) self.font = None

Until revision 399 we used a fontDict: Win32TextPrinter and font width/height ratio (02.06.05)

def setCpi(self,cpi):
    w = int(inch/cpi)
    self.fontDict['width'] = w
    self.fontDict['height'] = int(w*RATIO)
    self.cpl = int(self.lineWidth()/inch*cpi)
    self.font = None

Until 12.08.06 we used self.fontDict and CreateFont() from win32ui to create the actual font, but since then (new method) we use LOGFONT() and CreateFontIndirect() from win32gui.

It seems that the two methods have slightly different interpretations of the height and/or width parameter.

The MSDN documentation for CreateFont() helped me find the solution. It says that a positive height means that you mean the cell height, while a negative height means that you mean the character height (where character height = cell height - internal leading leading).

I tried to specify the height as a negative value:


... and it worked:

It seems that one of the methods inverses the sign of the height parameter and the other not.

Refering articles:

Copyright 2001-2007 Luc Saffre.
Generated 2007-06-07 16:22:50