HMG_HPDF - Export to PDF made easy...

HMG Samples and Enhancements

Moderator: Rathinagiri

edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: HMG_HPDF - Export to PDF made easy...

Post by edk »

franco wrote: Fri Mar 02, 2018 1:47 am Hi, all
I finally have hpdfprint working nicely, but have problem to set globle font size from 12 to 10. is there a way like
SET HPDFDOC FONT SIZE TO 10 at start of document. Must be a way.
Thanks in advance, Franco
Unfortunately, this can not be done without modifying the source code.
The default font size is fixed to 12.

You can try to change in the h_HMG_HPDF.Prg file:
from:

Code: Select all

Function _HMG_HPDF_PRINT ( nRow, nCol, cFontName, nFontSize, nRColor, nGColor, nBColor, cText, lBold, lItalic, lUnderline, lStrikeout, lColor, lFont, lSize, cAlign )
Local nWidth := _HMG_SYSDATA[ 150 ][ 4 ]
Local nHeight := _HMG_SYSDATA[ 150 ][ 5 ]
Local nTextWidth := 0
Local nxPos := _HMG_HPDF_MM2Pixel( nCol )
Local nyPos := nHeight - _HMG_HPDF_MM2Pixel( nRow )
Local oFont := Nil
Local cFont := ''
Local cTtfFnt
default cFontName := ''
default nFontSize := 12
to:

Code: Select all

Function _HMG_HPDF_PRINT ( nRow, nCol, cFontName, nFontSize, nRColor, nGColor, nBColor, cText, lBold, lItalic, lUnderline, lStrikeout, lColor, lFont, lSize, cAlign )
Local nWidth := _HMG_SYSDATA[ 150 ][ 4 ]
Local nHeight := _HMG_SYSDATA[ 150 ][ 5 ]
Local nTextWidth := 0
Local nxPos := _HMG_HPDF_MM2Pixel( nCol )
Local nyPos := nHeight - _HMG_HPDF_MM2Pixel( nRow )
Local oFont := Nil
Local cFont := ''
Local cTtfFnt
default cFontName := ''
default nFontSize := _HMG_SYSDATA[ 150 ][ 9 ]
and from:

Code: Select all

Function _HMG_HPDF_MULTILINE_PRINT ( nRow, nCol, nToRow, nToCol, cFontName, nFontSize, nRColor, nGColor, nBColor, cText, lBold, lItalic, lUnderline, lStrikeout, lColor, lFont, lSize, cAlign )
Local nWidth := _HMG_SYSDATA[ 150 ][ 4 ]
Local nHeight := _HMG_SYSDATA[ 150 ][ 5 ]
Local nTextWidth := 0
Local nxPos := _HMG_HPDF_MM2Pixel( nCol )
Local nyPos := nHeight - _HMG_HPDF_MM2Pixel( nRow )
Local nToxPos := nxPos + _HMG_HPDF_MM2Pixel( nToCol - nCol )
Local nToyPos := nyPos - _HMG_HPDF_MM2Pixel( nToRow - nRow )
Local oFont := Nil
Local cFont := ''
Local cTtfFnt // Pablo June, 2014

default cFontName := ''
default nFontSize := 12
to:

Code: Select all

Function _HMG_HPDF_MULTILINE_PRINT ( nRow, nCol, nToRow, nToCol, cFontName, nFontSize, nRColor, nGColor, nBColor, cText, lBold, lItalic, lUnderline, lStrikeout, lColor, lFont, lSize, cAlign )
Local nWidth := _HMG_SYSDATA[ 150 ][ 4 ]
Local nHeight := _HMG_SYSDATA[ 150 ][ 5 ]
Local nTextWidth := 0
Local nxPos := _HMG_HPDF_MM2Pixel( nCol )
Local nyPos := nHeight - _HMG_HPDF_MM2Pixel( nRow )
Local nToxPos := nxPos + _HMG_HPDF_MM2Pixel( nToCol - nCol )
Local nToyPos := nyPos - _HMG_HPDF_MM2Pixel( nToRow - nRow )
Local oFont := Nil
Local cFont := ''
Local cTtfFnt // Pablo June, 2014

default cFontName := ''
default nFontSize := _HMG_SYSDATA[ 150 ][ 9 ]
Add a new function:

Code: Select all

***************************************************************
Function _HMG_HPDF_SetFontSize( nFontSize )
default nFontSize := _HMG_SYSDATA[ 150 ][ 9 ]
If _HMG_SYSDATA[ 150 ][ 1 ] == Nil // PDF object not found!
   _HMG_HPDF_Error( 3 )
   Return Nil
Endif
_HMG_SYSDATA[ 150 ] [ 9 ] := nFontSize
Return Nil
And add a new command in the hmg_hpdf.ch file:

Code: Select all

#xcommand SET HPDFDOC FONT SIZE TO <nFontSize> ;
	=> ;
	_HMG_HPDF_SetFontSize( <nFontSize> )
Then you need to rebuild HMG.

Note. I did not test it. ;)
EduardoLuis
Posts: 682
Joined: Tue Jun 04, 2013 6:33 pm
Location: Argentina

Re: HMG_HPDF - Export to PDF made easy...

Post by EduardoLuis »

Hi Mol:

About your request, i've been looking how to get de fontfilename, and nothing.-
Getfonlist returns the name of the font not the name of the file (which you need to your hpdfprint definition).
Getfont does the same.-
My knowledge about these topics is not enough to give you the solution.
I think that the only way to do what you need, is create a routine that search for *.ttf file instaled on win system, and fill a table or array where you put each fontfilename.-
These routine must be triggered when your app initiates to avoid long time waiting.-
Hopping these give's you a better solution, with regards
Eduardo
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: HMG_HPDF - Export to PDF made easy...

Post by edk »

mol wrote: Thu Mar 01, 2018 6:48 am It's stange - when I select other exotic font to print text - pdf contains this font.
When I use "Arial Narrow" - it uses ordinary ARIAL
It seems to me that here is a "culprit": (in h_HMG_HPDF.Prg file):

Code: Select all

Function _HMG_HPDF_SeekEquivalences(FontName,lBold,lItalic)
Local cFldWindows := GetSpecialFolder(CSIDL_FONTS)
Local cRet:=""

Default lBold := .f., lItalic := .f.

Do Case
   Case "COUR" $ HMG_Upper(FontName)
        cRet:="cour"
   Case "TIMES" $ HMG_Upper(FontName)
        cRet:="times"
   Case "ARIAL" $ HMG_Upper(FontName)		* <------ a "culprit"
        cRet:="arial"
   Case "VERDANA" $ HMG_Upper(FontName)
        cRet:="verdana"
EndCase
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: HMG_HPDF - Export to PDF made easy...

Post by mol »

I've changed sources of h_hmg_hpdf.prg

Code: Select all

   Case "ARIAL" $ HMG_Upper(FontName) .and. ! ("ARIAL NARROW" $ HMG_Upper(FontName) )
        cRet:="arial"
and still generated PDF file does not contain NARROW font. What's goind on?
EduardoLuis
Posts: 682
Joined: Tue Jun 04, 2013 6:33 pm
Location: Argentina

Re: HMG_HPDF - Export to PDF made easy...

Post by EduardoLuis »

Hi Mol:

As i see on your DO CASE, you referr to FONTFILENAME, for example on "COUR" , "TIMES" , "VERDANA" , etc..-
These makes me think that each specification match the FONTFILENAME.-
So i think you must refer to Arial Narrow as "ARIALN" which is the FONTFILENAME.-
One thing must be clear is that FONTFILENAME is case sensitive, so it must be exactly, nor UPPER nor LOWER.
Just an opinion.-
franco
Posts: 816
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: HMG_HPDF - Export to PDF made easy...

Post by franco »

Thanks, Edward, I'll take a look at it.
Franco.
All The Best,
Franco
Canada
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: HMG_HPDF - Export to PDF made easy...

Post by mol »

We should retrieve list fonts from windows registry HKLM\Software\Microsoft\Windows NT\CurrentVersion\Fonts
It contains font name and file name.
So, correctly written _HMG_HPDF_SeekEquivalences function should translate fonts to filenames in this way.

The only problem is that I don't know how to read table from registry :(
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: HMG_HPDF - Export to PDF made easy...

Post by mol »

We can use such a code to find font file name:

Code: Select all

if lBold
  FontName += " Bold"
endif
if lItalic
  FontName += " Italic"
endif
cRet := RegistryRead( 'HKLM\Software\Microsoft\Windows NT\CurrentVersion\Fonts\' + FontName + ' (TrueType)' )
[code]
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: HMG_HPDF - Export to PDF made easy...

Post by edk »

mol wrote: Fri Mar 02, 2018 3:15 pm I've changed sources of h_hmg_hpdf.prg

Code: Select all

   Case "ARIAL" $ HMG_Upper(FontName) .and. ! ("ARIAL NARROW" $ HMG_Upper(FontName) )
        cRet:="arial"
and still generated PDF file does not contain NARROW font. What's goind on?
Try this, it's works for me:

Code: Select all

Do Case
   Case "COUR" $ HMG_Upper(FontName)
        cRet:="cour"
   Case "TIMES" $ HMG_Upper(FontName)
        cRet:="times"
   Case "ARIAL NARROW" $ HMG_Upper(FontName)
        cRet:="arialn"
   Case "ARIAL" $ HMG_Upper(FontName)
        cRet:="arial"
   Case "VERDANA" $ HMG_Upper(FontName)
        cRet:="verdana"
EndCase
Post Reply