how to calculate height of text as content in HPDFPRINT TO

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
jairpinho
Posts: 420
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Contact:

how to calculate height of text as content in HPDFPRINT TO

Post by jairpinho »

I can not calculate height of text as content of variable in HPDFPRINT TO follows example of a text table where I can not fit the text of the description of the material.

Code: Select all

for nPos := 1 to Form_Novo_Orcamento.Grid_1.ItemCount  			&& pega o total de item na grid
			
		aLinha := GetProperty ( 'Form_Novo_Orcamento' , 'Grid_1' , 'ITEM' , nPos )
		cDescricao := Alltrim(aLinha [2]) + "  " + Alltrim(aLinha [3]) + "  " + Alltrim(aLinha [11]) + "  " + Alltrim(aLinha [8]) + "  Marca " + Alltrim(aLinha [7])
 		
		nCharacters := LEN(Alltrim(cDescricao))  // altrim retirar espaçoas em branco da variavel
		nLinhas := nCharacters / 60
		nResto := (nCharacters % 60) // resto da divisão por 60
		
		if nLinhas < 1
			nDesc_size :=  5
		elseif nResto != 0 .and. nLinhas > 1
			nDesc_size := (1 + int(nLinhas)) * 5
		elseif nResto == 0 .and. nLinhas > 1
			nDesc_size := nLinhas * 5
		endif
		 msgdebug(LEN(Alltrim(cDescricao)),"-",Alltrim(cDescricao) )
		  msgdebug(nCharacters)
		 msgdebug(nLinhas)
		 msgdebug(nResto)
		 msgdebug(nDesc_size)

		  
		@ F, 13 HPDFPRINT Alltrim(STR(npos))  FONT cFonte1 size nFonte_size1 COLOR { 0, 0, 0 } // COLUNA ITEM
		@ F, 25 HPDFPRINT Alltrim(aLinha [4])  FONT cFonte1 size nFonte_size1 COLOR { 0, 0, 0 } // COLUNA ITEM
        @ F, 35 HPDFPRINT cDescricao to F+nDesc_size, 150 FONT cFonte1 size nFonte_size1 COLOR { 0, 0, 0 } // COLUNA DESCRIÇÃO
		
		IF Form_Novo_Orcamento.Check_4.Value == .F.
			@ F, 155 HPDFPRINT MoedaMysql(VAL(Alltrim(aLinha [5])))  FONT cFonte1 size nFonte_size1 COLOR { 0, 0, 0 } // COLUNA DESCRIÇÃO
			@ F, 180 HPDFPRINT MoedaMysql(VAL(Alltrim(aLinha [6])))  FONT cFonte1 size nFonte_size1 COLOR { 0, 0, 0 } // COLUNA DESCRIÇÃO
			nTotal_material := nTotal_material + val(aLinha [6])
		else
			@ F, 155 HPDFPRINT Alltrim("0,00")  FONT cFonte1 size nFonte_size1 COLOR { 0, 0, 0 } // COLUNA DESCRIÇÃO
			@ F, 180 HPDFPRINT Alltrim("0,00")  FONT cFonte1 size nFonte_size1 COLOR { 0, 0, 0 } // COLUNA DESCRIÇÃO
			nTotal_material := 0
		ENDIF
 
          F:= IIF(nDesc_size > 5 , F + nDesc_size, F+5)
next

Last edited by jairpinho on Wed Dec 04, 2019 11:50 pm, edited 1 time in total.
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br
User avatar
dragancesu
Posts: 920
Joined: Mon Jun 24, 2013 11:53 am
DBs Used: DBF, MySQL, Oracle
Location: Subotica, Serbia

Re: to calculate height of text as content in HPDFPRINT TO

Post by dragancesu »

Maybe it's hard, maybe it's not
These are windows fonts and they are standard,
write what you want in WORD, print and measure
That is all

It's my start with hmg report
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: to calculate height of text as content in HPDFPRINT TO

Post by mol »

Edk put some functions to calculate text length some time ago. Maybe it will help you. Try to search
User avatar
jairpinho
Posts: 420
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Contact:

Re: to calculate height of text as content in HPDFPRINT TO

Post by jairpinho »

hello, can edk help me
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br
User avatar
AUGE_OHR
Posts: 2060
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: how to calculate height of text as content in HPDFPRINT TO

Post by AUGE_OHR »

hi,

what you need is in Source of c:\hmg.3.4.4\SOURCE\c_controlmisc.c

Code: Select all

HB_FUNC( GETTEXTWIDTH )  // returns the Width of a string in pixels
{
   HDC   hDC         = (HDC)    HMG_parnl (1);
   TCHAR *Text       = (TCHAR*) HMG_parc  (2);
   HFONT hFont       = (HFONT)  HMG_parnl (3);
   HWND  hWnd = NULL ;
   HFONT hOldFont = NULL;
   BOOL  bDestroyDC = FALSE;
   SIZE sz;

   if ( hDC == NULL )
   {
      bDestroyDC = TRUE;
      hWnd = GetActiveWindow();
      hDC = GetDC( hWnd );
   }

   if ( hFont )
      hOldFont = ( HFONT ) SelectObject( hDC, hFont );

   GetTextExtentPoint32( hDC, Text, lstrlen (Text), &sz );

   if ( hFont )
      SelectObject( hDC, hOldFont );

   if ( bDestroyDC )
       ReleaseDC( hWnd, hDC );

   hb_retni ((INT) sz.cx );
}

Code: Select all

HB_FUNC( GETTEXTHEIGHT )  // returns the Height of a string in pixels
{
   HDC   hDC         = (HDC)    HMG_parnl (1);
   TCHAR *Text       = (TCHAR*) HMG_parc  (2);
   HFONT hFont       = (HFONT)  HMG_parnl (3);
   HWND  hWnd = NULL ;
   HFONT hOldFont = NULL;
   BOOL  bDestroyDC = FALSE;
   SIZE sz;

   if ( hDC == NULL )
   {
      bDestroyDC = TRUE;
      hWnd = GetActiveWindow();
      hDC = GetDC( hWnd );
   }

   if ( hFont )
      hOldFont = ( HFONT ) SelectObject( hDC, hFont );

   GetTextExtentPoint32( hDC, Text, lstrlen (Text), &sz );

   if ( hFont )
      SelectObject( hDC, hOldFont );

   if ( bDestroyDC )
       ReleaseDC( hWnd, hDC );

   hb_retni ((INT) sz.cy );
}
have fun
have fun
Jimmy
User avatar
hmgchang
Posts: 273
Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia

Re: how to calculate height of text as content in HPDFPRINT TO

Post by hmgchang »

Hola Masters,

The function GetTextWidth() and GetTextHeight() return the width and height in Pixel.
How do we measure when it is printed on the paper ( in millimeter unit) ?

Thks and Rgds
Chang
Just Hmg It !
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: how to calculate height of text as content in HPDFPRINT TO

Post by edk »

hmgchang wrote: Sun Mar 21, 2021 9:14 am Hola Masters,

The function GetTextWidth() and GetTextHeight() return the width and height in Pixel.
How do we measure when it is printed on the paper ( in millimeter unit) ?

Thks and Rgds
Chang
_HMG_HPDF_Pixel2MM()

See also http://hmgforum.com/viewtopic.php?p=57057#p57057
Post Reply