Page 1 of 1

how to calculate height of text as content in HPDFPRINT TO

Posted: Mon Oct 29, 2018 9:26 pm
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


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

Posted: Mon Oct 29, 2018 10:20 pm
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

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

Posted: Tue Oct 30, 2018 7:11 am
by mol
Edk put some functions to calculate text length some time ago. Maybe it will help you. Try to search

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

Posted: Wed Dec 04, 2019 11:46 pm
by jairpinho
hello, can edk help me

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

Posted: Thu Dec 05, 2019 2:23 am
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

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

Posted: Sun Mar 21, 2021 9:14 am
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

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

Posted: Sun Mar 21, 2021 3:11 pm
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