The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: Mr Earl on March 26, 2008, 11:08:14 AM

Title: LOGFONT increase lines per page
Post by: Mr Earl on March 26, 2008, 11:08:14 AM
This is my current LOGFONT setting:

INVOKE lstrcpy,addr lf.lfFaceName,addr szCourier
mov    lf.lfHeight, 120
mov    lf.lfWidth,  45  ;gives 12 CPI
mov    lf.lfWeight, 600
mov    lf.lfCharSet, ANSI_CHARSET
mov    lf.lfPitchAndFamily, FIXED_PITCH or FF_MODERN

It gives 56 lines per page.  I would like to be able to double or at least increase the lines per page.
Adjusting lfHeight & lfWidth does change the size of the characters, but the line height remains the same.
so that I still only get 56 lines/page.

Is the line height fixed by the font, or is there a way to get more lines/page?

I need a fixed pitch font so that I can line up columns.
Title: Re: LOGFONT increase lines per page
Post by: MichaelW on March 27, 2008, 06:00:52 PM
I'm assuming that "page" here means a printed page. Using this test code with a 5-point font, and my DeskJet 1000C, I can easily get 150 lines on an 8.5x11 page. If I drop down to a 1-point font I can easily get 750 lines on the page (and the fixed-pitch/variable-pitch does not matter, because both are unreadable :lol).

; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
    include \masm32\include\winspool.inc
    includelib \masm32\lib\winspool.lib
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data

      hFont       dd 0
      hFontPrev   dd 0
      hPrinterDC  dd 0
      docinfo     DOCINFO <>
      rc          RECT <>
      blen        dd 100
      printerName db 100 dup(0)

      ; -----------------------------------------------------------
      ; Create our formatted test data as a null-terminated string.
      ; -----------------------------------------------------------

      txt LABEL BYTE
      n=1
      REPEAT 150
        tmp TEXTEQU <">,%n,<">
        % db tmp,13,10
        n = n + 1
      ENDM
      db 0

    .code
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

MakeFont proc dc:DWORD,ptSize:DWORD,weight:DWORD,italic:DWORD,lpFontName:DWORD

    ; ----------------------------------------
    ; Convert the point size to a font height.
    ; ----------------------------------------

    invoke GetDeviceCaps, dc, LOGPIXELSY
    mul ptSize
    xor edx, edx
    mov ecx, 72
    div ecx

    ; ---------------------------------------------
    ; Specify 0 in the nWidth parameter so the font
    ; mapper will choose the closest match.
    ; ---------------------------------------------

    invoke CreateFont, eax, 0, NULL, NULL, weight, italic, NULL, NULL,
                       DEFAULT_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS,
                       PROOF_QUALITY, DEFAULT_PITCH or FF_DONTCARE,
                       lpFontName
    ret

MakeFont endp

; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    ; ------------------------
    ; Use the default printer.
    ; ------------------------

    invoke GetDefaultPrinter, ADDR printerName, ADDR blen
    print "printerName: "
    print ADDR printerName,13,10

    invoke CreateDC, NULL, ADDR printerName, NULL, NULL
    mov hPrinterDC, eax
    print "hPrinterDC: "
    print uhex$(hPrinterDC),13,10

    ; -----------------------
    ; Specify a 5-point font.
    ; -----------------------

    invoke MakeFont, hPrinterDC, 5, FW_NORMAL, 0, chr$("Courier New")
    mov hFont, eax
    print "hFont: "
    print uhex$(hFont),13,10

    invoke SelectObject, hPrinterDC, hFont
    mov hFontPrev, eax
    print "hFontPrev: "
    print uhex$(hFontPrev),13,10

    mov docinfo.cbSize, SIZEOF DOCINFO
    mov docinfo.lpszDocName, chr$("Print Test")
    print "StartDoc rval: "
    invoke StartDoc, hPrinterDC, ADDR docinfo
    print uhex$(eax),13,10

    print "StartPage rval: "
    invoke StartPage, hPrinterDC
    print uhex$(eax),13,10

    ; -----------------------------------------------------
    ; Initialize the formatting dimensions for the DrawText
    ; function to the printable area of the page.
    ; -----------------------------------------------------

    mov rc.left, 0
    mov rc.top, 0
    invoke GetDeviceCaps, hPrinterDC, HORZRES
    mov rc.right, eax
    invoke GetDeviceCaps, hPrinterDC, VERTRES
    mov rc.bottom, eax

    ; -------------------------------------
    ; Use the DrawText function to draw the
    ; formatted text to the printer.
    ; -------------------------------------

    invoke DrawText, hPrinterDC, ADDR txt,-1, ADDR rc, DT_LEFT

    print "EndPage rval: "
    invoke EndPage, hPrinterDC
    print uhex$(eax),13,10

    print "EndDoc rval: "
    invoke EndDoc, hPrinterDC
    print uhex$(eax),13,10

    ; ---------
    ; Clean up.
    ; ---------

    print "SelectObject rval: "
    invoke SelectObject, hPrinterDC, hFontPrev
    print uhex$(eax),13,10

    print "DeleteDC rval: "
    invoke DeleteDC, hPrinterDC
    print uhex$(eax),13,10

    print "DeleteObject rval: "
    invoke DeleteObject, hFont
    print uhex$(eax),13,10

    inkey "Press any key to exit..."
    exit
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start


QuoteIs the line height fixed by the font, or is there a way to get more lines/page?

AFAIK the line height is generally fixed by the font. Are you controlling the printer in your code, or depending on some other application to do it?


Title: Re: LOGFONT increase lines per page
Post by: Mr Earl on March 27, 2008, 06:21:31 PM
Thanks for the example Michael.  Works great, just what I needed.