Page 2 of 2

Posted: Wed Jan 24, 2007 12:05 pm
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... :)

Posted: Wed Jan 24, 2007 12:17 pm
by srod
Doesn't work here!

Dam it!

:?

Posted: Wed Jan 24, 2007 12:51 pm
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.

Posted: Wed Jan 24, 2007 1:12 pm
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

Posted: Wed Jan 24, 2007 1:17 pm
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.