Class TFont different

Class TFont different

Postby Detlef » Sat Apr 30, 2022 8: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: Select all  Expand view  RUN
#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: Select all  Expand view  RUN
#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 FILE cPdfFile
      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
User avatar
Detlef
 
Posts: 209
Joined: Mon Feb 07, 2022 9:54 pm

Re: Class TFont different

Postby nageswaragunupudi » Sun May 01, 2022 7:01 am

Instead of
Code: Select all  Expand view  RUN
nRow += 1.2 * oFont:nHeight 


Please use:
Code: Select all  Expand view  RUN
nRow += 1.2 * oPrn:GetTextHeight( "", oFont ) 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Class TFont different

Postby Detlef » Sun May 01, 2022 9: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: Select all  Expand view  RUN
#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 Image 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
User avatar
Detlef
 
Posts: 209
Joined: Mon Feb 07, 2022 9:54 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 67 guests