HMG_HPDF - Export to PDF made easy...

HMG Samples and Enhancements

Moderator: Rathinagiri

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 EDK:

My first impression WOOOOWWWWWWW.-
Excellent contribution.-
Thanks for share.-
Eduardo
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 have still problems after this patch ... :cry:
My problem is that I need to measure text length and fit it in the rectancle with constant width and various height.
I found such a method to measure text width in C++, but I'm not familiar with this language to adapt this solution to HMG.
Maybe BosTaurus library could be used to do that?

Code: Select all

VOID Example_MeasureString(HDC hdc)
{
   Graphics graphics(hdc);
   // Set up the string.
   WCHAR string[] = L"Measure Text";
   Font font(L"Arial", 16);
   RectF layoutRect(0, 0, 100, 50);
   RectF boundRect;
   // Measure the string.
   graphics.MeasureString(string, 12, &font, layoutRect, &boundRect);
   // Draw a rectangle that represents the size of the string.
   graphics.DrawRectangle(&Pen(Color(255, 0, 0, 0)), boundRect);
}
User avatar
bpd2000
Posts: 1207
Joined: Sat Sep 10, 2011 4:07 am
Location: India

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

Post by bpd2000 »

EduardoLuis wrote: Mon Mar 05, 2018 9:38 pm Hi EDK:

My first impression WOOOOWWWWWWW.-
Excellent contribution.-
Thanks for share.-
Eduardo
+1
BPD
Convert Dream into Reality through HMG
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 »

Is it the way to set default interline in PDF file?

When I use multiline text printing, I'm not able to detect whole area height
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:


The command to manage multiline spacing is:
SET HPDFPAGE LINESPACING TO N
N: corresponds to pixels
If you don't need to modify, you must specify this when you create HPDFDOC
Hopping this helps you
With regards
Eduardo
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 EDK:

After looking all HARU i try unsuccesfully to replicate the types that appear on attached pdf page.
Searching for that controls they exist on HPDF library.
Attachments
haru_sample.zip
(5.03 KiB) Downloaded 238 times
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: Tue Mar 06, 2018 9:39 am I have still problems after this patch ... :cry:
My problem is that I need to measure text length and fit it in the rectancle with constant width and various height.
I found such a method to measure text width in C++, but I'm not familiar with this language to adapt this solution to HMG.
Maybe BosTaurus library could be used to do that?

Code: Select all

VOID Example_MeasureString(HDC hdc)
{
   Graphics graphics(hdc);
   // Set up the string.
   WCHAR string[] = L"Measure Text";
   Font font(L"Arial", 16);
   RectF layoutRect(0, 0, 100, 50);
   RectF boundRect;
   // Measure the string.
   graphics.MeasureString(string, 12, &font, layoutRect, &boundRect);
   // Draw a rectangle that represents the size of the string.
   graphics.DrawRectangle(&Pen(Color(255, 0, 0, 0)), boundRect);
}
Marek, try this:

Code: Select all

lBold := .T.
cText := "This is a sample Text."
cFont := "Arial Narrow"
nFtnSize := 24

@120, 20 PRINT cText FONT cFont SIZE nFtnSize BOLD IF lBold
		 
@130, 20 PRINT LINE TO 130, 20 + HMG_GetTextWidthinMM (OpenPrinterGetPagedc(), cText, cFont, nFtnSize, lBold)
 
 ***************************************************************************************************
FUNCTION HMG_GetTextWidthInMM (hDC, cText, cFontName, nFontSize, lBold, lItalic, lUnderline, lStrikeout)
Local hFont
Default cText:=""
Default cFontName := _HMG_SYSDATA [ 342 ]
Default nFontSize := _HMG_SYSDATA [ 343 ]
Default lItalic := .F.
Default lUnderline := .F.
Default lStrikeout := .F.
Default lBold := .F.

hFont := HMG_CreateFont (hDC, cFontName, nFontSize, lBold, lItalic, lUnderline, lStrikeOut )
RETURN (GetTextWidth( hDC, cText, hFont ) * 25.4 ) / HMG_GetPrinterResolution( hDC )[1] 

***************************************************************************************************

FUNCTION HMG_GetTextWidthInPx (hDC, cText, cFontName, nFontSize, lBold, lItalic, lUnderline, lStrikeout)
Local hFont
Default cText:=""
Default cFontName := _HMG_SYSDATA [ 342 ]
Default nFontSize := _HMG_SYSDATA [ 343 ]
Default lItalic := .F.
Default lUnderline := .F.
Default lStrikeout := .F.
Default lBold := .F.

hFont := HMG_CreateFont (hDC, cFontName, nFontSize, lBold, lItalic, lUnderline, lStrikeOut )
RETURN GetTextWidth( hDC, cText, hFont )


***********************************************************************
#pragma begindump
#include <windows.h>
#include <hbapi.h>

HB_FUNC ( HMG_GETPRINTERRESOLUTION )
{
	hb_reta (2);
	hb_storvni ( GetDeviceCaps( (HDC) hb_parnl (1), LOGPIXELSX ),         -1, 1 ); 
	hb_storvni ( GetDeviceCaps( (HDC) hb_parnl (1), LOGPIXELSY ),         -1, 2 ); 
} 
#pragma ENDDUMP
************************************************************************************************************
 

For HPDF:

Code: Select all

@ 20, 10 HPDFPRINT "This is a sample Text in ITALIC." ITALIC 
@ 20, 10 HPDFPRINT RECTANGLE TO 26, 10 + HMG_GetPDFTextWidth ("This is a sample Text in ITALIC.", /* Default font */ , /* Default font size */ , /* Bold */, .T. /* Italic */)
		
*****************************************************************************
FUNCTION HMG_GetPDFTextWidth (cText, cFontName, nFontSize, lBold, lItalic, lUnderline, lStrikeout)
Local cFont, oFont, nWidth
default cFontName := _HMG_SYSDATA[ 150 ][ 8 ]
default nFontSize := _HMG_SYSDATA[ 150 ][ 9 ]
default lBold := .f.
default lItalic := .f.
default lUnderline := .f.
default lStrikeout := .f.

If _HMG_SYSDATA[ 150 ][ 1 ] == Nil // PDF object not found!
   _HMG_HPDF_Error( 3 )
   Return 0
endif
If _HMG_SYSDATA[ 150 ][ 7 ] == Nil // PDF Page object not found!
   _HMG_HPDF_Error( 5 )
   Return 0
endif

cFontName := AllTrim(_HMG_HPDF_SetFont( cFontName, lBold, lItalic ))
if HMG_UPPER (cFileExt (cFontName)) == '.TTF' // load ttf font
   
	cFont := HPDF_LOADTTFONTFROMFILE( _HMG_SYSDATA[ 150 ][ 1 ], cFontName, .t. )
	If HMG_LEN( alltrim( cFont ) ) == 0
		_HMG_HPDF_Error( 6 , cFontName )
		Return 0
	endif
	oFont := HPDF_GetFont( _HMG_SYSDATA[ 150 ][ 1 ], cFont, _HMG_SYSDATA[ 150 ][ 10 ] )
else
	If HMG_UPPER( alltrim( cFontName ) ) == "SYMBOL" .or. HMG_UPPER( alltrim( cFontName ) ) == "ZAPFDINGBATS"
		oFont := HPDF_GetFont( _HMG_SYSDATA[ 150 ][ 1 ], cFontName, Nil )
	else   
		oFont := HPDF_GetFont( _HMG_SYSDATA[ 150 ][ 1 ], cFontName, _HMG_SYSDATA[ 150 ][ 10 ] )
	endIf   
endif
   
If oFont == Nil
	_HMG_HPDF_Error( 6 , cFontName )
	Return 0
Else
	HPDF_Page_SetFontAndSize( _HMG_SYSDATA[ 150 ][ 7 ], oFont, nFontSize )
	nWidth := _HMG_HPDF_Pixel2MM( HPDF_Page_TextWidth( _HMG_SYSDATA[ 150 ][ 7 ], cText ) )
Endif
Return nWidth		
Last edited by edk on Tue Mar 06, 2018 3:37 pm, edited 1 time in total.
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

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

Post by edk »

EduardoLuis wrote: Tue Mar 06, 2018 1:19 pm Hi EDK:

After looking all HARU i try unsuccesfully to replicate the types that appear on attached pdf page.
Searching for that controls they exist on HPDF library.
Hola Eduardo, mi tocayo.

Unfortunately, these controls are not in HMG HPDF.
It seems to me that once I had it done. But I can not find it on the computer.
I will look into old machines, maybe it has survived somewhere.
If I do not find it, I will try to develop it in my spare time.
Stay tuned.

Edward.
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 Edward (EDK) ;)

You are not only wise, you are a multilanguage man. ;)
About my previous post, some time ago i found this HARU code associated with text inside a circle.-
I suppose it's oriented to C, and my knowledge on that language is too poor.
I try to implement it, but lots of error become like a rain.-
I copy behind part of the code, and perhaps this give's you a better idea.-
With regards, as allways.
Eduardo

/* text along a circle */
HPDF_Page_SetGrayStroke (page, 0);
HPDF_Page_Circle (page, 210, 190, 145);
HPDF_Page_Circle (page, 210, 190, 113);
HPDF_Page_Stroke (page);

angle1 = 360 / (strlen (SAMP_TXT));
angle2 = 180;

HPDF_Page_BeginText (page);
font = HPDF_GetFont (pdf, "Courier-Bold", NULL);
HPDF_Page_SetFontAndSize (page, font, 30);

for (i = 0; i < strlen (SAMP_TXT); i++) {
char buf[2];
float x;
float y;

rad1 = (angle2 - 90) / 180 * 3.141592;
rad2 = angle2 / 180 * 3.141592;

x = 210 + cos(rad2) * 122;
y = 190 + sin(rad2) * 122;

HPDF_Page_SetTextMatrix(page, cos(rad1), sin(rad1), -sin(rad1), cos(rad1), x, y);

buf[0] = SAMP_TXT;
buf[1] = 0;
HPDF_Page_ShowText (page, buf);
angle2 -= angle1;
}

HPDF_Page_EndText (page);

/* save the document to a file */
HPDF_SaveToFile (pdf, fname);
Post Reply