No announcement yet.

Fun with Fonts...

  • Filter
  • Time
  • Show
Clear All
new posts

  • Fun with Fonts...

    Hi everyone,

    Now that I've got my header / footer function working
    without crashing, I need to correctly determine the height (in
    device units) of any given header / footer that I will be

    I'm assuming that I will need to create a 10 point Arial font
    (my preference for now), select it into the supplied hDC (device
    context is initialized by a DLL), and then somehow calculate the
    height based upon how many lines of text I require. Is there a
    standard way of doing this?

    Bernard Ertl
    Bernard Ertl
    InterPlan Systems

  • #2
    DrawText using %DT_CALCRECT I believe.




    • #3

      To start, here is how you calculate the font height using a
      Point size , to be used with the CreateFont API call :

      hDC = GetDC(%HWND_DESKTOP)
      PSY&=GetDeviceCaps(hDC, %LOGPIXELSY)
      ReleaseDC %HWND_DESKTOP, hDC      
      FUNCTION=-MulDiv(PSize&, PSY&, 72)
      The code above will autoscale the font based on the end users system
      wide font setting (small fonts/large fonts), which is the proper way
      to do it. The MulDiv (API) function is the proper way suggested by
      Microsoft to do the conversion from Point size to Font height.
      The function returns a negative value since that will force the
      CreateFont function to use the value as the Character height and not
      the cell height.

      The code above used the Desktop DC, so it is assumed the device units
      are pixels (MM_TEXT). If you are using a DC which does not use pixels
      as device units, then use that DC in the calculation rather than the
      desktop DC.

      This should give you a start !

      Chris Boss
      Computer Workshop
      Developer of "EZGUI"


      • #4

        Yes, thanks. That was exactly what I was looking for.

        Onwards to the next "problem". My header / footer callback
        function needs to scale the font(s) for the header/footer
        according to the current "zoom status" of the preview control.

        The control is providing a bounding RECT for the header/footer
        which is sized according to the current zoom status. It also
        provides a bounding RECT for the header/footer according to the
        printer device. The docs claim I should be able to scale the
        fonts based upon that info only.

        I've tried :

        'Get 10 pt font for Printer Device
        tFont.lfHeight = -MulDiv( 10, GetDeviceCaps( hPrinterDC&, %LOGPIXELSY), 72)
        'Scale font????
        'CurrentRect = Preview RECT
        tFont.lfHeight = (CSNG(tFont.lfHeight) *  _
                         ((CurrentRect.nBottom - CurrentRect.nTop) / _
                         (@ptrPrintInfo.RectPrinter.nBottom - @ptrPrintInfo.RectPrinter.nTop)))
        hFont = CreateFontIndirect( tFont)
        'SelectObject, Drawtext, etc.
        and it did not affect the font at all. Are there any other LOGFONT
        elements that need to be adjusted in order to change the font size?

        Am I doing something obviously wrong?

        Bernard Ertl
        Bernard Ertl
        InterPlan Systems


        • #5
          A little bit of progress...

          I found that resetting the tFont.lfWidth to zero forced the fonts
          to be resized according to the lfHeight.

          Now I'm just trying yo figure out how I'm supposed to calculate
          the correct scaling.

          Farpoint sent me this advice:

          The parameters RectPreview helps you to scale your fonts when
          previewing the Spread. You can use the GetDeviceCaps() API to get the HORZRES and
          VERTRES of the printer and then use the RectPreview to calculate a scale to use
          in your fonts in the PrintHeader and PrintFooter when previewing the
          I don't have a clue as to how the printer device's HORZRES and
          VERTRES correlate to the Preview Control's RECT....

          Bernard Ertl
          Bernard Ertl
          InterPlan Systems


          • #6
            bern, a good place to start might be:
            and the printpage() function in this print source code:
            printing with dialogs

            [email protected]
            :) IRC :)


            • #7
              hi ian,

              thanks for the tip. i think i figured it out. i posted my
              solution here:

              thanks everyone!

              bernard ertl
              Bernard Ertl
              InterPlan Systems