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: 346
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Has thanked: 3 times
Been thanked: 11 times
Contact:

how to calculate height of text as content in HPDFPRINT TO

Post by jairpinho » Mon Oct 29, 2018 9:26 pm

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: 718
Joined: Mon Jun 24, 2013 11:53 am
DBs Used: DBF, MySQL, Oracle
Location: Subotica, Serbia
Has thanked: 24 times
Been thanked: 151 times

Post by dragancesu » Mon Oct 29, 2018 10:20 pm

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: 3252
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 235 times
Been thanked: 132 times
Contact:

Post by mol » Tue Oct 30, 2018 7:11 am

Edk put some functions to calculate text length some time ago. Maybe it will help you. Try to search

User avatar
jairpinho
Posts: 346
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Has thanked: 3 times
Been thanked: 11 times
Contact:

Post by jairpinho » Wed Dec 04, 2019 11:46 pm

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: 290
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany
Has thanked: 32 times
Been thanked: 39 times

Post by AUGE_OHR » Thu Dec 05, 2019 2:23 am

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

Post Reply