FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Class TFont different
Posts: 218
Joined: Mon Feb 07, 2022 09:54 PM
Class TFont different
Posted: Sat Apr 30, 2022 08:31 PM
Hi alll,

when printing to a pdf file I have a strange font issue.
Normally I could get the height of a font by coding oFont:nHeight.
So this is working:
Code (fw): Select all Collapse
#include "FiveWin.ch"

REQUEST FWHARU

PROCEDURE Main()
//----------------
LOCAL oPrn, oFont
LOCAL cPdfFile := CurDrive() + ":\" + curdir() + "\print.pdf"
LOCAL nRow  := 50

   TPrinter():lUseHaruPDF := .t.
   PRINT oPrn NAME "Testprint" PREVIEW
      DEFINE FONT oFont NAME "Arial" SIZE 0, -10 OF oPrn

      PAGE
         oPrn:Say( nRow, 50, "Line one", oFont )
         nRow += 1.2 * oFont:nHeight
         oPrn:Say( nRow, 50, "Line two", oFont )
      ENDPAGE
   ENDPRINT

   RELEASE FONT oFont
RETURN


But If I do the following
Code (fw): Select all Collapse
#include "FiveWin.ch"
#define _HEIGHT  2  // value of font size array for height
REQUEST FWHARU   // required for using HaruPdf

PROCEDURE Main()
//----------------
LOCAL oPrn, oFont
LOCAL cPdfFile := CurDrive() + ":\" + curdir() + "\print.pdf"
LOCAL nRow  := 50

   TPrinter():lUseHaruPDF := .t.
   PRINT oPrn NAME "Testprint" PREVIEW <strong>FILE cPdfFile</strong>
      DEFINE FONT oFont NAME "Arial" SIZE 0, -10 OF oPrn

      PAGE
         oPrn:Say( nRow, 50, "Line one", oFont )
         nRow += 1.2 * oFont:nHeight
         oPrn:Say( nRow, 50, "Line two", oFont )
      ENDPAGE
   ENDPRINT

   RELEASE FONT oFont
RETURN

That gives me the error : "Class: 'ARRAY' has no exported method: NHEIGHT"
In this case I have to write nRow += 1.2 * oFont[ _HEIGHT ]
Why is the height value of the same font in different structures?

Regards,
Detlef
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Class TFont different
Posted: Sun May 01, 2022 07:01 AM
Instead of
Code (fw): Select all Collapse
nRow += 1.2 * oFont:nHeight


Please use:
Code (fw): Select all Collapse
nRow += 1.2 * oPrn:GetTextHeight( "", oFont )
Regards



G. N. Rao.

Hyderabad, India
Posts: 218
Joined: Mon Feb 07, 2022 09:54 PM
Re: Class TFont different
Posted: Sun May 01, 2022 09:35 PM
Many thanks Mr. Rao,
this works fine now.

But i still have an issue when using either
PRINT oPrn NAME "Testprint PREVIEW" or
PRINT oPrn NAME "Testprint" PREVIEW FILE cPdfFile
I want to print a jpg logo amongst text and the vertical position of this logo is different in those two versions.
My code :
Code (fw): Select all Collapse
#include "FiveWin.ch"

REQUEST FWHARU   // required for using HaruPdf

PROCEDURE Main()
//----------------
LOCAL oPrn, oFont
LOCAL cPdfFile := CurDrive() + ":\" + curdir() + "\print.pdf"
LOCAL cDGSV    := CurDrive() + ":\" + curdir() + "\dgsv.jpg"
LOCAL nHeight, nRow, nCol, nYRes, nXRes


   TPrinter():lUseHaruPDF := .t.

   PRINT oPrn NAME "Testprint" PREVIEW FILE cPdfFile

      DEFINE FONT oFont NAME "Arial" SIZE 0, -10 OF oPrn
      nHeight := oPrn:GetTextHeight( "", oFont )

      nYRes := ( 10 * oPrn:nVertRes() / oPrn:nVertSize() ) / 10 // Faktor for mm in vertical
      nXRes := ( 10 * oPrn:nHorzRes() / oPRn:nHorzSize() ) / 10 // Faktor for mm in horizontal
      nCol  :=  144.25 * nXRes

      PAGE
         nRow := 45 * nYRes
         oPrn:Say( nRow, nCol, "Line above", oFont )

         @ 59, 148 PRINT TO oPrn IMAGE cDGSV SIZE 14.62, 4.3 MM

         nRow += 5.5 * nHeight
         oPrn:Say( nRow, nCol, "Line below", oFont )

         ENDPAGE
   ENDPRINT

   RELEASE FONT oFont
RETURN


The jpg file can be downloaded at https://www.hamelau.eu/tmp/dgsv.jpg

I know that your advice will be to let the printer do the calculation for positionimg in MM or Inches and so.
But I don't want to measure all my linefeeds in millimeters, especially when using two fonts of different heights in the same line.

Btw. When I save the pdf from the FiveWin preview as pdf file it looks correct in Adobe reader.
So there is something not quite exact in the FiveWin preview display.

Could there be an other solution?
Regards,
Detlef

Continue the discussion