HMG_HPDF - Export to PDF made easy...

HMG Samples and Enhancements

Moderator: Rathinagiri

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 »

Now it works :)
I'm too much tired. Time to start weekend :)
-10 deg C outside - so time to start winter swimming - water is so hot at this time :D
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 think this simple solution should be included in next hmg version...
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 5:41 pm 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)' )
Tu może być pewien problem, bo w moim Windows 10 PL nazwy fontów w rejestrze są w jęz. polskim, np.
Arial Narrow Kursywa (TrueType)
Arial Narrow Pogrubiona kursywa (TrueType)
Arial Narrow Pogrubiony (TrueType)
Bell MT Kursywa (TrueType)
Tak więc dodanie do podstawowej nazwy atrybutu "Bold" i/lub "Italic" dla niektórych czcionek nie da prawidłowego wyniku odczytu nazwy pliku z rejestru.

There may be a problem, because in my Windows 10 PL font names in the registry are in Polish, for example:
Arial Narrow Kursywa (TrueType)
Arial Narrow Pogrubiona kursywa (TrueType)
Arial Narrow Pogrubiony (TrueType)
Bell MT Kursywa (TrueType)
So adding the "Bold" and/or "Italic" attribute to the base font name for some fonts can not be a valid result of reading the file name from the registry.
Last edited by edk on Sat Mar 03, 2018 9:41 am, edited 1 time in total.
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 »

Jak to rozwiązać? Gdzieś w rejestrze musi być translacja nazw czcionek na nazwy plików. W programie piszesz Arial Bold, w rejestrze masz Arial Pogrubiona a system wie, że chodzi o arialb.ttf
How to solve it? Somewhere in the windows registry there must be a translation of font names into file names. In the program you write Arial Bold, you have Arial Pogrubiona in the registry and the system knows that it is about arialb.ttf
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

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

Post by edk »

I went through the register and found nothing interesting.
Well, how Windows recognizes which font file should be used if, for example, the 'Bold' attribute is selected. :?:
I thought there was a rigid scheme where 'bd' characters are appended to the base font file name.
For example, Arial = arial.ttf, Arial Bold = arialbd.ttf
But this is not the case, because for the Arial Narrow Bold font the file is called arialnb.ttf and not as expected arialnbd.ttf :?

In order for the "Bold" attribute to work properly with the Arial Narrow font, you must replace the function:

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 NARROW" $ HMG_Upper(FontName)
        cRet:="arialn"
   Case "ARIAL" $ HMG_Upper(FontName)
        cRet:="arial"
   Case "VERDANA" $ HMG_Upper(FontName)
        cRet:="verdana"
EndCase


If !Empty(cRet)
   //cRet := cFldWindows + "\" + cRet
   If lBold .and. lItalic
      cRet := cRet + 'bi.ttf'
   ElseIf lBold
	If cRet="arialn"
      cRet := cRet + 'b.ttf'
	Else
	  cRet := cRet + 'bd.ttf'
	Endif
   ElseIf lItalic
      cRet := cRet + 'i.ttf'
   Else
      cRet := cRet + '.ttf'
   Endif
   cRet := cFldWindows + "\" + cRet
   cRet := _HMG_HPDF_ExistInLocal(cRet)
Endif

Return cRet
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 »

In this case, this function should have to call user defined function to translate other, non-standard windows fonts.
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 »

There is Windows function EnumFontFamiliesEx which enumerates installed fonts with its options.
But, I can't find if there is a font filename for font name.
HMG sources contains call to older version of the function EnumFontFamilies (this one is for compatibility wit 16-bit versions).
c_controlmisc.c file contains definition of EnumFonts.
EnumFontFamilies returns LogFont structure:

Code: Select all

typedef struct tagLOGFONT {
  LONG  lfHeight;
  LONG  lfWidth;
  LONG  lfEscapement;
  LONG  lfOrientation;
  LONG  lfWeight;
  BYTE  lfItalic;
  BYTE  lfUnderline;
  BYTE  lfStrikeOut;
  BYTE  lfCharSet;
  BYTE  lfOutPrecision;
  BYTE  lfClipPrecision;
  BYTE  lfQuality;
  BYTE  lfPitchAndFamily;
  TCHAR lfFaceName[LF_FACESIZE];
} LOGFONT, *PLOGFONT;
It is desciped on https://msdn.microsoft.com/pl-pl/librar ... s.85).aspx page

Some fonts have only English names, some of them can have English and native (Polish, Chinese ) names too.

I think Claudio Soto should know sth. about it. (His name is places as comment in sources :) )
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

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

Post by edk »

New features:

***********************************************************
HMG HPDF

HPDFPRINT command improvements:
- UNDERLINE style support added (simulation).
- STRIKEOUT style support added (simulation).
- ANGLE <nAngle> attribute has been added - text rotation by angle <nAngle>
- TOP | MIDDLE vertical alignment style has been added for the ANGLE attribute
- optionally define styles BOLD | ITALIC | UNDERLINE | STRIKEOUT has been added - optional attribute IF <lValid>

New commands:
- SET HPDFDOC FONT NAME TO <cFontName> - set the default font as <cFontName>.
- SET HPDFDOC FONT SIZE TO <nFontSize> - set the default font size to <nFontSize>.

Removal of noticed bugs.

Sample:
sample-1.png
sample-1.png (138.19 KiB) Viewed 4449 times

Code: Select all

#include "hmg.ch"
#include "harupdf.ch"

Function Main()

SELECT HPDFDOC "sample.pdf" PAPERLENGTH 300 PAPERWIDTH 300 LOG
START HPDFDOC
	START HPDFPAGE
		SET HPDFDOC ENCODING TO "WinAnsiEncoding"

		@  5, 10 HPDFPRINT "Default font and size." UNDERLINE
		
		@ 10,100 HPDFPRINT "This is a sample Text CENTER." CENTER 
		@ 15,200 HPDFPRINT "This is a sample Text in BOLD RIGHT." BOLD RIGHT
		@ 20, 10 HPDFPRINT "This is a sample Text in ITALIC." ITALIC 

		SET HPDFDOC FONT SIZE TO 8
		SET HPDFDOC FONT NAME TO "Arial Narrow"
		
		@ 30, 10 HPDFPRINT "Arial Narrow 8" FONT "Helvetica" SIZE 12 UNDERLINE IF .T. 
		@ 35, 10 HPDFPRINT "This is a sample Text." 
		@ 40, 10 HPDFPRINT "This is a sample Text in BOLD IF .T." BOLD IF .T.
		@ 45, 10 HPDFPRINT "This is a sample Text in ITALIC IF .T. " ITALIC IF .T.
		
		SET HPDFDOC FONT SIZE TO 10
		SET HPDFDOC FONT NAME TO "Courier"
		
		@ 55, 10 HPDFPRINT "Courier 10" FONT "Helvetica" SIZE 12 UNDERLINE
		@ 60, 10 HPDFPRINT "This is a sample Text." 
		@ 65, 10 HPDFPRINT "This is a sample Text in BOLD IF .F." BOLD IF .F. 
		@ 70, 10 HPDFPRINT "This is a sample Text in ITALIC IF .F." ITALIC IF .F.
		
		SET HPDFDOC FONT SIZE TO 18
		SET HPDFDOC FONT NAME TO "Times-Roman"
		
		lBold := .T.
		@ 85, 10 HPDFPRINT "Times-Roman (built-in) 18" FONT "Helvetica" SIZE 12 UNDERLINE STRIKEOUT IF .F.
		@ 90, 10 HPDFPRINT "This is a sample Text BOLD IF lBold ITALIC UNDERLINE STRIKEOUT" BOLD IF lBold ITALIC UNDERLINE STRIKEOUT
    
		SET HPDFDOC FONT NAME TO "Times"
		
		@ 115, 10 HPDFPRINT "Times 18" FONT "Helvetica" SIZE 12 UNDERLINE
		@ 120, 10 HPDFPRINT "This is a sample Text baseline................................................................"
		@ 120, 150 HPDFPRINT "Sample Text BOLD IF .T. ANGLE 90" BOLD IF .T. COLOR {255,0,0} ANGLE 90
		@ 120, 150 HPDFPRINT "Sample Text BOLD IF .F. ANGLE -90" BOLD IF .F. COLOR {255,0,0} ANGLE -90
		@ 120, 170 HPDFPRINT "Sample Text UNDERLINE ANGLE 90 TOP" UNDERLINE COLOR {0,255,0} ANGLE 90 TOP
		@ 120, 190 HPDFPRINT "Sample Text ITALIC IF .T. STRIKEOUT ANGLE 90 MIDDLE" ITALIC IF .T. STRIKEOUT COLOR {0,0,255} ANGLE 90 MIDDLE
        
		SET HPDFDOC FONT SIZE TO 13
		SET HPDFDOC FONT NAME TO "Symbol"
		
		@ 135, 10 HPDFPRINT "Symbol 13" FONT "Helvetica" SIZE 12 UNDERLINE
		@ 140, 10 HPDFPRINT "This is a sample Text." 
        
		SET HPDFDOC FONT SIZE TO 6
		SET HPDFDOC FONT NAME TO "ZapfDingbats"
		
		@ 150, 10 HPDFPRINT "ZapfDingbats 6" FONT "Helvetica" SIZE 12 UNDERLINE
		@ 155, 10 HPDFPRINT "This is a sample Text." 
		
		SET HPDFDOC FONT SIZE TO 22
		SET HPDFDOC FONT NAME TO "MAIAN.TTF"
		
		@ 170, 10 HPDFPRINT "MAIAN.TTF 22" FONT "Helvetica" SIZE 12 UNDERLINE
		@ 175, 10 HPDFPRINT "This is a sample Text." 
		
		SET HPDFDOC FONT SIZE TO 
		SET HPDFDOC FONT NAME TO 
		
		@ 190, 10 HPDFPRINT "Back to Defaults"
      
	END HPDFPAGE
END HPDFDOC
Execute File 'sample.pdf'
Return Nil
***********************************************************
PRINT SYSTEM

1) For SELECT PRINTER <cPrinter> | DEFAULT ... and SELECT PRINTER DIALOG ... :

PRINT command improvements:
- optionally define styles BOLD | ITALIC | UNDERLINE | STRIKEOUT has been added - optional attribute IF <lValid>

Sample:

Code: Select all

#include "hmg.ch"

Function Main()
	DEFINE WINDOW Win_1 ;
		AT 0,0 ;
		WIDTH 400 ;
		HEIGHT 400 ;
		TITLE 'Test' ;
		MAIN 

		@ 50, 50 BUTTON Button_1 CAPTION "Test" ACTION PrintTest()

	END WINDOW
	CENTER WINDOW Win_1
	ACTIVATE WINDOW Win_1
Return


*------------------------------------------------------------------------------*
Procedure PrintTest
*------------------------------------------------------------------------------*
LOCAL lSuccess, IsPreview, xTab := 50, aList:={ {"Code","000001"} , {"Description","#PEPPER MARMALADE"} , {"Price", 2.35} , {"Code","000002"} , {"Description","!NEW"} , {"Price", 123.45} }, i, xRow := 20

SELECT PRINTER DIALOG TO lSuccess PREVIEW

If lSuccess == .F.
	MsgInfo('Print Error')
	Return
EndIf 

START PRINTDOC

	START PRINTPAGE
		 
		FOR i=1 TO LEN(aList)
			@ xRow,20 PRINT aList[i][1] + REPLICATE(".", 100) TO xRow + 5, xTab + .5 ;
				FONT "Arial" ;
				SIZE 10
				
			@ xRow,xTab PRINT ": " + ALLTRIM(hb_ValToStr( aList [i][2] )) ;
				FONT "Arial" ;
				SIZE 10 BOLD IF ALLTRIM(hb_ValToStr( aList [i][2] ))='!' STRIKEOUT IF ALLTRIM(hb_ValToStr( aList [i][2] ))='#'
					
			xRow += 5
		Next i
	   
	END PRINTPAGE

END PRINTDOC
	 
Return

2) For SELECT PRINTER PDF <PDF File> TO <Success>:

PRINT command improvements:
- UNDERLINE style support added (simulation).
- STRIKEOUT style support added (simulation).
- ANGLE <nAngle> attribute has been added - text rotation by angle <nAngle>
- TOP | MIDDLE vertical alignment style has been added for the ANGLE attribute
- optionally define styles BOLD | ITALIC | UNDERLINE | STRIKEOUT has been added - optional attribute IF <lValid>

Sample:

Code: Select all

#include "hmg.ch"

Function Main()
	DEFINE WINDOW Win_1 ;
		AT 0,0 ;
		WIDTH 400 ;
		HEIGHT 400 ;
		TITLE 'Test' ;
		MAIN 

		@ 50, 50 BUTTON Button_1 CAPTION "Test" ACTION PrintTest()

	END WINDOW
	CENTER WINDOW Win_1
	ACTIVATE WINDOW Win_1
Return


*------------------------------------------------------------------------------*
Procedure PrintTest
*------------------------------------------------------------------------------*
LOCAL lSuccess

SELECT PRINTER PDF "test.pdf" TO lSuccess

If lSuccess == .F.
	MsgInfo('Print Error')
	Return
EndIf 

START PRINTDOC

	START PRINTPAGE
		 
		@  5, 10 PRINT "Default font and size." UNDERLINE
		
		@ 10,100 PRINT "This is a sample Text CENTER." CENTER 
		@ 15,200 PRINT "This is a sample Text in BOLD RIGHT." BOLD RIGHT
		@ 20, 10 PRINT "This is a sample Text in ITALIC." ITALIC 

		SET HPDFDOC FONT SIZE TO 8
		SET HPDFDOC FONT NAME TO "Arial Narrow"
		
		@ 30, 10 PRINT "Arial Narrow 8" FONT "Helvetica" SIZE 12 UNDERLINE IF .T. 
		@ 35, 10 PRINT "This is a sample Text." 
		@ 40, 10 PRINT "This is a sample Text in BOLD IF .T." BOLD IF .T.
		@ 45, 10 PRINT "This is a sample Text in ITALIC IF .T. " ITALIC IF .T.
		
		SET HPDFDOC FONT SIZE TO 10
		SET HPDFDOC FONT NAME TO "Courier"
		
		@ 55, 10 PRINT "Courier 10" FONT "Helvetica" SIZE 12 UNDERLINE
		@ 60, 10 PRINT "This is a sample Text." 
		@ 65, 10 PRINT "This is a sample Text in BOLD IF .F." BOLD IF .F. 
		@ 70, 10 PRINT "This is a sample Text in ITALIC IF .F." ITALIC IF .F.
		
		SET HPDFDOC FONT SIZE TO 18
		SET HPDFDOC FONT NAME TO "Times-Roman"
		
		lBold := .T.
		@ 85, 10 PRINT "Times-Roman (built-in) 18" FONT "Helvetica" SIZE 12 UNDERLINE STRIKEOUT IF .F.
		@ 90, 10 PRINT "This is a sample Text BOLD IF lBold ITALIC UNDERLINE STRIKEOUT" BOLD IF lBold ITALIC UNDERLINE STRIKEOUT
    
		SET HPDFDOC FONT NAME TO "Times"
		
		@ 115, 10 PRINT "Times 18" FONT "Helvetica" SIZE 12 UNDERLINE
		@ 120, 10 PRINT "This is a sample Text baseline................................................................"
		@ 120, 150 PRINT "Sample Text BOLD IF .T. ANGLE 90" BOLD IF .T. COLOR {255,0,0} ANGLE 90
		@ 120, 150 PRINT "Sample Text BOLD IF .F. ANGLE -90" BOLD IF .F. COLOR {255,0,0} ANGLE -90
		@ 120, 170 PRINT "Sample Text UNDERLINE ANGLE 90 TOP" UNDERLINE COLOR {0,255,0} ANGLE 90 TOP
		@ 120, 190 PRINT "Sample Text ITALIC IF .T. STRIKEOUT ANGLE 90 MIDDLE" ITALIC IF .T. STRIKEOUT COLOR {0,0,255} ANGLE 90 MIDDLE
        
		SET HPDFDOC FONT SIZE TO 13
		SET HPDFDOC FONT NAME TO "Symbol"
		
		@ 135, 10 PRINT "Symbol 13" FONT "Helvetica" SIZE 12 UNDERLINE
		@ 140, 10 PRINT "This is a sample Text." 
        
		SET HPDFDOC FONT SIZE TO 6
		SET HPDFDOC FONT NAME TO "ZapfDingbats"
		
		@ 150, 10 PRINT "ZapfDingbats 6" FONT "Helvetica" SIZE 12 UNDERLINE
		@ 155, 10 PRINT "This is a sample Text." 
		
		SET HPDFDOC FONT SIZE TO 22
		SET HPDFDOC FONT NAME TO "MAIAN.TTF"
		
		@ 170, 10 PRINT "MAIAN.TTF 22" FONT "Helvetica" SIZE 12 UNDERLINE
		@ 175, 10 PRINT "This is a sample Text." 
		
		SET HPDFDOC FONT SIZE TO 
		SET HPDFDOC FONT NAME TO 
		
		@ 190, 10 PRINT "Back to Defaults"
	   
	END PRINTPAGE

END PRINTDOC
	 
Return
Sources:
New_features.7z
(16.84 KiB) Downloaded 276 times
Files from the attachment should be copied to the folder where HMG 3.4.4 is installed, and then rebuild HMG (BuildLib32.bat).
Remember to make a backup copy of the replaced files.


==========================================================
References:
==========================================================
PRINT DATA
----------------------------------------------------------
Prints Data


@ <Row> , <Col> PRINT [ DATA ] <xData>
[ TO <nToRow> , <nToCol> ]
[ FONT <cFontName> ]
[ SIZE <nFontSize> ]
[ BOLD [ IF lBold ] ]
[ ITALIC [ IF lItalic ] ]
[ UNDERLINE [ IF lUnderline ] ]
[ STRIKEOUT [ IF lStrikeout ] ]
[ COLOR <aColor> ]
[ RIGHT | CENTER ]
[ ANGLE <nAngleInDegrees> ]
[ TOP | MIDDLE ]

- <xData> type can be character, numeric, date, logical or memo.
- Logical data is shown as 'Yes' or 'No' (translated according selected language).
- If <xData> is multi-line text (character or memo types), you must specify TO <nToRow> , <nToCol> optional parameters.
- When <xData> type is numeric, digits are printed begining exactly at specified position (without leading spaces).
- If optional RIGHT clause is used <Row> , <Col> indicates the right coordinates of <xData> (unless TO <nToRow> , <nToCol> is specified.)
- If optional CENTER clause is used <Row> , <Col> indicates the center coordinates of <xData> (unless TO <nToRow> , <nToCol> is specified.)
- If optional IF clause for the styles: BOLD | ITALIC | UNDERLINE | STRIKEOUT is used, then the style will be active when the expression given after IF return "true".
- Support for the UNDERLINE and STRIKEOUT style for PDF has been added. (Style simulation). (Unless TO <nToRow> , <nToCol> is specified.)
- Support for the ANGLE rotation for PDF has been added. (Unless TO <nToRow> , <nToCol> is specified.)
- If optional TOP clause is used <Row> , <Col> indicates the top coordinates of rotated <xData> (unless TO <nToRow> , <nToCol> is specified) (only supported by SELECT PRINTER PDF <PDF File> TO <Success>).
- If optional MIDDLE clause is used <Row> , <Col> indicates the middle coordinates of rotated <xData> (unless TO <nToRow> , <nToCol> is specified.) (only supported by SELECT PRINTER PDF <PDF File> TO <Success>).

Units: <Row> , <Col> units are milimeters.

Sample:
@ 10, 10 PRINT "Test BOLD" FONT "Arial" SIZE 10 BOLD IF lBold ITALIC
Prints "Test BOLD" as italicised and bolded, when lBold is "true".


========================================================== HMG HPDF
----------------------------------------------------------
HPDFPRINT Prints Data


@ <Row> , <Col> HPDFPRINT [ DATA ] <xData>
[ TO <nToRow> , <nToCol> ]
[ FONT <cFontName> ]
[ SIZE <nFontSize> ]
[ BOLD [ IF lBold ] ]
[ ITALIC [ IF lItalic ] ]
[ UNDERLINE [ IF lUnderline ] ]
[ STRIKEOUT [ IF lStrikeout ] ]
[ COLOR <aColor> ]
[ RIGHT | CENTER | JUSTIFY]
[ ANGLE <nAngleInDegrees> ]
[ TOP | MIDDLE ]

- If <xData> is multi-line text (character or memo types), you must specify TO <nToRow> , <nToCol> optional parameters.
- If optional RIGHT clause is used <Row> , <Col> indicates the right coordinates of <xData> (unless TO <nToRow> , <nToCol> is specified.)
- If optional CENTER clause is used <Row> , <Col> indicates the center coordinates of <xData> (unless TO <nToRow> , <nToCol> is specified.)
- Optional JUSTIFY clause is valid when TO <nToRow> , <nToCol> is specified.
- If optional IF clause for the styles: BOLD | ITALIC | UNDERLINE | STRIKEOUT is used, then the style will be active when the expression given after IF return "true".
- Support for the UNDERLINE and STRIKEOUT style has been added. (Style simulation). (Unless TO <nToRow> , <nToCol> is specified.)
- Support for the ANGLE rotation has been added. (Unless TO <nToRow> , <nToCol> is specified.)
- If optional TOP clause is used <Row> , <Col> indicates the top coordinates of rotated <xData> (unless TO <nToRow> , <nToCol> is specified)
- If optional MIDDLE clause is used <Row> , <Col> indicates the middle coordinates of rotated <xData> (unless TO <nToRow> , <nToCol> is specified.)

Units: <Row> , <Col> units are milimeters.

Sample:
@ 10, 10 HPDFPRINT "Test BOLD" FONT "Arial" SIZE 10 BOLD IF lBold ITALIC
Prints "Test BOLD" as italicised and bolded, when lBold is "true".


----------------------------------------------------------
SET HPDFDOC FONT NAME TO <cFontName>


Set the default font as <cFontName>.

SET HPDFDOC FONT NAME TO - restores the "Helvetica" font as the default.


----------------------------------------------------------
SET HPDFDOC FONT SIZE TO <nFontSize>


Set the default font size to <nFontSize>.

SET HPDFDOC FONT SIZE TO - restores font size 12 as the default.


==========================================================
Post Reply