Announcement

Collapse
No announcement yet.

Printed output font/graphics size

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Printed output font/graphics size

    I have (with a great amount of help from Timm Motl) succeeded in
    producing exactly what I require -- on an HP 5p laserjet printer.
    The same programme module, using a Mannesmann Tally 904, prints tyhe
    same output but very much larger, about four times larger font
    and boxes etc. Only one quarter of the output fits onto the A4
    sheet. The driver for the printer is present and works with
    MS Word, Excel etc.

    Does anyone know what needs to be adjusted?

    ------------------

  • #2
    Probably your font or image size. You'll need to calculate it based on the physical resolution of your printer. Check out the DeviceDeviceCaps() API with the %HORZRES and %VERTRES parameters.

    Dieny, do yourself a favor and get yourself a Windows programming book - you'll be amazed how much easier it will become once you get a good grip on GDI programming (not to mention GUI programming!) Petzold's book covers these things in detail.

    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


    • #3
      Lance, I have (for the third time) the Petzold Edition 5 on order.
      The first two just couldn't deliver - this one wants three weeks,
      and of that half is gone, so with GREAT good luck I'll have it
      before the month is out. Believe me, I know I need it!

      ------------------

      Comment


      • #4
        DienyduToit...

        I have no experience with Mannesmann Tally printers, but like Lance said... you'll probably need to calculate
        your font sizes based on the information returned from the GetDeviceCaps() API call. The following routine should
        help you learn more about GetDeviceCaps() for printers...
        Code:
        #COMPILE EXE
        #REGISTER NONE
        #INCLUDE "Win32Api.Inc"
        
        
        FUNCTION PBMAIN
           DIM PInfo5(0:2) AS PRINTER_INFO_5
           EnumPrinters %PRINTER_ENUM_LOCAL, BYVAL %NULL, 5, BYVAL VARPTR(PInfo5(0)), 0, Needed&, Returned&
           Upper& = Needed& \ SIZEOF(pInfo5(0))
           REDIM pInfo5(0:Upper&)
           EnumPrinters %PRINTER_ENUM_LOCAL, BYVAL %NULL, 5, BYVAL VARPTR(pInfo5(0)), (Upper& + 1) * SIZEOF(pInfo5(0)), Needed&, Returned&
           '
           MSGBOX STR$(Returned&) + " Printers found"
           '
           FOR LoopVar& = 0 TO (Returned& - 1)
              Printer_hDC& = CreateDC(BYVAL %Null, PInfo5(LoopVar&)[email protected], BYVAL %Null, BYVAL %Null)
              PrnWidth& = GetDeviceCaps(Printer_hDC&, %PHYSICALWIDTH)
              PrnHeight& = GetDeviceCaps(Printer_hDC&, %PHYSICALHEIGHT)
              IF PrnWidth& < PrnHeight& THEN
                 Orientation$ = "Portrait"
              ELSE
                 Orientation$ = "Landscape"
              END IF
              DeleteDc Printer_hDC&
              Attribute$ = ""
              IF (PInfo5(LoopVar&).Attributes AND %PRINTER_ATTRIBUTE_LOCAL) THEN
                 Attribute$ = "Local "
              END IF
              IF (PInfo5(LoopVar&).Attributes AND %PRINTER_ATTRIBUTE_NETWORK) THEN
                 Attribute$ = "Network "
              END IF
              IF (PInfo5(LoopVar&).Attributes AND %PRINTER_ATTRIBUTE_DEFAULT) THEN
                 Attribute$ = Attribute$ + "Default "
              END IF
              IF (PInfo5(LoopVar&).Attributes AND %PRINTER_ATTRIBUTE_DIRECT) THEN
                 Attribute$ = Attribute$ + "Direct "
              ELSE
                 Attribute$ = Attribute$ + "Spooled "
              END IF
              IF (PInfo5(LoopVar&).Attributes AND %PRINTER_ATTRIBUTE_QUEUED) THEN
                 Attribute$ = Attribute$ + "Queued "
              END IF
              IF (PInfo5(LoopVar&).Attributes AND %PRINTER_ATTRIBUTE_SHARED) THEN
                 Attribute$ = Attribute$ + "Shared "
              END IF
              IF (PInfo5(LoopVar&).Attributes AND %PRINTER_ATTRIBUTE_WORK_OFFLINE) THEN
                 Attribute$ = Attribute$ + "Work Offline "
              END IF
              IF (PInfo5(LoopVar&).Attributes AND %PRINTER_ATTRIBUTE_HIDDEN) THEN
                 Attribute$ = Attribute$ + "Hidden"
              END IF
              MSGBOX "Printer #" + STR$(LoopVar&+1) + $CRLF + $CRLF + PInfo5(LoopVar&)[email protected] + $CRLF + _
                     PInfo5(LoopVar&)[email protected] + $CRLF + Attribute$ + $CRLF + Orientation$ + $CRLF + _
                     "Width:  " + STR$(PrnWidth&) + $CRLF + "Height: " + STR$(PrnHeight&)
           NEXT
        END FUNCTION
        To print in different font sizes and weights, you may have to do a little trial and error to find the
        correct settings for the different printer device capabilities. Then, simply use different settings
        or try a "modifier" variable to change the font height, width (and weight, if needed) for the different
        printers you're using.
        Code:
        #COMPILE EXE
        #REGISTER NONE
        #INCLUDE "WIN32API.INC"
        
        
        FUNCTION MakeFont(FHeight AS LONG, FWidth AS LONG, FWeight AS LONG, FName AS STRING) AS LONG
           DIM Font AS LOGFONT
           Font.lfHeight   = FHeight
           Font.lfWidth    = FWidth
           Font.lfWeight   = FWeight
           Font.lfFaceName = FName
           FUNCTION = CreateFontIndirect(Font)
        END FUNCTION
        
        
        FUNCTION PrintSomething() AS LONG
           LOCAL FHeight   AS LONG
           LOCAL FWidth    AS LONG
           LOCAL FWeight   AS LONG
           LOCAL FName     AS STRING
           LOCAL hDc       AS LONG
           LOCAL Di        AS DocInfo
           LOCAL DocName   AS ASCIIZ * 32
           LOCAL TempText  AS ASCIIZ * 1024
           LOCAL PInfo5()  AS PRINTER_INFO_5
           DIM PInfo5(0:2) AS PRINTER_INFO_5
           EnumPrinters %PRINTER_ENUM_DEFAULT, BYVAL %NULL, 5, BYVAL VARPTR(PInfo5(0)), SIZEOF(PInfo5(0)) * 3, Needed&, Returned&
           hDC = CreateDC(BYVAL %Null, BYVAL PInfo5(0).pPrinterName, BYVAL %Null, BYVAL %Null)
           IF hDC THEN
              DocName = "Test Print Job"
              Di.lpszDocName = VARPTR(DocName)
              Di.cbSize = SIZEOF(Di)
              IF StartDoc(hDC, Di) THEN
                 SetBkMode hDc, %TRANSPARENT
                 StartPage hDC
                    '
                    FHeight = 50
                    FWidth  = 25
                    FWeight = 0
                    FName   = "Ariel"
                    TempText = "Testing Different Font Sizes ..."
                    '
                    hFont& = MakeFont(FHeight, FWidth, FWeight, FName)
                    SelectObject hDc, hFont&
                    TextOut hDc, 30, 7, TempText, BYVAL LEN(TempText)
                    '
                    FHeight = 36
                    FWidth  = 13
                    '
                    hFont& = MakeFont(FHeight, FWidth, FWeight, FName)
                    SelectObject hDc, hFont&
                    TextOut hDc, 30, 107, TempText, BYVAL LEN(TempText)
                    '
                 EndPage hDc
                 EndDoc hDc
                 TempText = ""
                 DeleteDC hDc
              ELSE
                 DeleteDC hDC
              END IF
           END IF
        END FUNCTION
        
        
        CALLBACK FUNCTION DlgProc
           SELECT CASE CBCTL
           CASE 100
              CALL PrintSomething
           END SELECT
        END FUNCTION
        
        
        FUNCTION PBMAIN
           LOCAL hDlg AS LONG
           DIALOG NEW 0, "Printer Test",,, 200, 60, %WS_SYSMENU TO hDlg
           CONTROL ADD BUTTON, hDlg, 100, "Print", 80, 15, 40, 14
           DIALOG SHOW MODAL hDlg, CALL DlgProc
        END FUNCTION
        To more fully understand the degree of control you have over fonts, check out the LOGFONT structure
        in the Win32 Help file (it defines the attributes of a font). In any event, don't be surprised if
        the font you try to create comes out different. Windows will try to produce what you ask for, but
        if the named font doesn't support the size/weight you requested, Windows will substitute something
        close. It's up to you to experiment with this and decide what fonts/sizes/weights will work best
        for your app.

        Good luck.

        Timm
        mailto:[email protected]
        Tsunami Record Manager

        Comment


        • #5
          For less than 25% of Petzold's book you can purchase ddoc by Don Dickinson. ddoc gives you complete control over the output of any Windows printer. I highly recommend it.

          That being said, Petzold's book provides a considerable amount of information over and above the subject of printing through the WinAPI. But for the price, it's hard to beat the results ddoc will give you.

          Frank

          ------------------

          Comment

          Working...
          X