How to count printer font size?

Just starting out? Need help? Post your questions and find answers here.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Ah, the article confirms exactly what I was thinking. It was the only logical explanation as to how/why MS Word was using a slightly smaller font size!

Nice find omit59!

Must admit I tried something like this but couldn't understand why the value of tmInternalLeading never changed with the font size! I see your scaling effect! If it works, bravo!

I'm going to give this a whirl.

Back in a mo... :)
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Doesn't work here!

Dam it!

:?
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Got it!

Code: Select all

If PrintRequester() 

  If StartPrinting("Test") 

    size = 10 
    
    printer_DC.l = StartDrawing(PrinterOutput()) 
    printer_DC.l 
      tm.TEXTMETRIC      
      GLPrinterDPIX.l = GetDeviceCaps_(printer_DC,#LOGPIXELSX) 
      GLPrinterDPIY.l = GetDeviceCaps_(printer_DC,#LOGPIXELSY) 
    StopDrawing() 
    height=-MulDiv_(size, GLPrinterDPIY, 72)
    LoadFont(0, "Arial", height) 
    printer_DC.l = StartDrawing(PrinterOutput()) 
      DrawingFont(FontID(0)) 
      GetTextMetrics_(printer_DC,tm) 
    StopDrawing() 

      fontsize = height + tm\tmInternalLeading
    FreeFont(0) 
    LoadFont(0, "Arial", fontsize) 
    
    printer_DC.l = StartDrawing(PrinterOutput()) 
    If printer_DC.l 

      DrawingFont(FontID(0)) 
      DrawText(0, 30,"New Arial " + Str(size)) 

      StopDrawing() 
    EndIf 
  
    StopPrinting() 
  EndIf 
EndIf
@omit59: the problem was the fact that we were calculating the text metrics of a font with logical height 10 as opposed to the point size 10.

So, first calculate the character height, then use the text metrics function to obtain the correct internal leading etc. Your scaling factor is not required as we were both using GetTextMetrics_() at the wrong time.

This is good and is going straight into my current application as I didn't realise there was a problem until this thread was started!

I'll post this as a joint effort in the tricks and tips section as I think it's worth knowing. It certainly caught me out!

:)

Thanks again.
I may look like a mule, but I'm not a complete ass.
omit59
User
User
Posts: 63
Joined: Fri Mar 11, 2005 8:41 am
Location: Finland

Post by omit59 »

@srod,

This is really great!

Nice that you had time to clear this out, because I'm not
very good with API and so on...

And yes it might be a good idea to put this in the tricks section, because
printing can be really difficult and this help a lot.

So thank you very much :P

Timo
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Hey, my current application owes you a debt of thanks as I'd have come across this problem sooner or later and I'd have been clueless as to what was causing the problem! :)

Creating a generic procedure to calculate the font sizes is a little tricky as I have to avoid the PB LoadFont() command. It will take a little while.

Thanks again.
I may look like a mule, but I'm not a complete ass.
Post Reply