Page 2 of 4

Re: label at runtime

Posted: Thu Sep 07, 2017 5:38 pm
by KDJ
Can be used BT_DrawText or BT_DrawTextEx function.
Sample is in: ...\hmg\SAMPLES\BosTaurus\Demo3.prg.

Re: label at runtime

Posted: Thu Sep 07, 2017 6:02 pm
by jairpinho
KDJ wrote:
Thu Sep 07, 2017 5:38 pm
Can be used BT_DrawText or BT_DrawTextEx function.
Sample is in: ...\hmg\SAMPLES\BosTaurus\Demo3.prg.


Thank you, KDJ, exactly.
nTypeText := BT_TEXT_OPAQUE + BT_TEXT_BOLD + BT_TEXT_ITALIC + BT_TEXT_UNDERLINE
nAlingText := BT_TEXT_CENTER + BT_TEXT_BASELINE
nOrientation := 90
BT_DrawText (hDC, 300, 400, " The Power of HMG 1", "Comic Sans MS", 42, WHITE, BLACK, nTypeText, nAlingText, nOrientation)

Re: label at runtime

Posted: Thu Sep 07, 2017 6:22 pm
by jairpinho
this is the result, now I just need to do this in pdf.
Main.zip
(3.51 KiB) Downloaded 89 times
Image

Re: label at runtime

Posted: Thu Sep 07, 2017 7:20 pm
by edk
I hope this will be helpful:

Code: Select all

#include "hmg.ch"

Function Main()
Local i

SELECT HPDFDOC "sample.pdf" PAPERLENGTH 300 PAPERWIDTH 300 LOG
SET HPDFDOC ENCODING TO "WinAnsiEncoding"
START HPDFDOC
    START HPDFPAGE
	    
	@10,10 HPDFPRINT "Rotate Demo"
        
        HPDF_RotateText( 50, 80, "ABCxyz123", Nil, Nil, 90 ) 
	HPDF_RotateText( 50, 80, "ABCxyz123", Nil, Nil, 180)
        HPDF_RotateText( 50, 80, "ABCxyz123", Nil, Nil, 270)
	HPDF_RotateText( 50, 80, "ABCxyz123", Nil, Nil, 0 )
	
	FOR i=100 TO 300 STEP 10
		@i,10 HPDFPRINt "Happy HMG"
	NEXT i

	FOR i=0 To 345 STEP 15
		HPDF_RotateText( 150, 150, "Happy HMG", Nil, 10, i )	
	NEXT i	


    END HPDFPAGE
        

END HPDFDOC

Execute File 'sample.pdf'
Return Nil
*******************************
PROCEDURE HPDF_RotateText( nRow, nCol, cTxt, cFont, nFontSize, nAngle )
* Rotating text

   Local nRad, nTextWidth 
   
   Local hPdf        := _HMG_SYSDATA[ 150 ][ 1 ]
   Local hPage       := _HMG_SYSDATA[ 150 ][ 7 ]

   Local nWidth      := _HMG_SYSDATA[ 150 ][ 4 ]
   Local nHeight     := _HMG_SYSDATA[ 150 ][ 5 ]
   Local nxPos       := _HMG_HPDF_MM2Pixel( nCol )
   Local nyPos       := nHeight - _HMG_HPDF_MM2Pixel( nRow )

   DEFAULT cFont       := "Helvetica"
   DEFAULT nFontSize    := 12   
   DEFAULT cTXt        := ""
   DEFAULT nAngle      := 0


   nTextWidth := HPDF_Page_TextWidth( hPage, cTxt )

   nRad := nAngle / 180 * 3.141592 	//radian value

   HPDF_Page_SetFontAndSize( hPage, HPDF_GetFont( hPdf, cFont, NIL ), nFontSize )
   HPDF_Page_BeginText( hPage )
   HPDF_Page_SetTextMatrix ( hPage, cos ( nRad ), sin ( nRad ), -sin ( nRad ), cos ( nRad ), nxPos , nyPos - nFontSize)
   HPDF_Page_ShowText( hPage, cTxt )
   HPDF_Page_EndText( hPage )

RETURN

pdf.JPG
pdf.JPG (24.92 KiB) Viewed 2449 times

Re: label at runtime

Posted: Thu Sep 07, 2017 10:04 pm
by jairpinho
edk wrote:
Thu Sep 07, 2017 7:20 pm
I hope this will be helpful:

Code: Select all

#include "hmg.ch"

Function Main()
Local i

SELECT HPDFDOC "sample.pdf" PAPERLENGTH 300 PAPERWIDTH 300 LOG
SET HPDFDOC ENCODING TO "WinAnsiEncoding"
START HPDFDOC
    START HPDFPAGE
	    
	@10,10 HPDFPRINT "Rotate Demo"
        
        HPDF_RotateText( 50, 80, "ABCxyz123", Nil, Nil, 90 ) 
	HPDF_RotateText( 50, 80, "ABCxyz123", Nil, Nil, 180)
        HPDF_RotateText( 50, 80, "ABCxyz123", Nil, Nil, 270)
	HPDF_RotateText( 50, 80, "ABCxyz123", Nil, Nil, 0 )
	
	FOR i=100 TO 300 STEP 10
		@i,10 HPDFPRINt "Happy HMG"
	NEXT i

	FOR i=0 To 345 STEP 15
		HPDF_RotateText( 150, 150, "Happy HMG", Nil, 10, i )	
	NEXT i	


    END HPDFPAGE
        

END HPDFDOC

Execute File 'sample.pdf'
Return Nil
*******************************
PROCEDURE HPDF_RotateText( nRow, nCol, cTxt, cFont, nFontSize, nAngle )
* Rotating text

   Local nRad, nTextWidth 
   
   Local hPdf        := _HMG_SYSDATA[ 150 ][ 1 ]
   Local hPage       := _HMG_SYSDATA[ 150 ][ 7 ]

   Local nWidth      := _HMG_SYSDATA[ 150 ][ 4 ]
   Local nHeight     := _HMG_SYSDATA[ 150 ][ 5 ]
   Local nxPos       := _HMG_HPDF_MM2Pixel( nCol )
   Local nyPos       := nHeight - _HMG_HPDF_MM2Pixel( nRow )

   DEFAULT cFont       := "Helvetica"
   DEFAULT nFontSize    := 12   
   DEFAULT cTXt        := ""
   DEFAULT nAngle      := 0


   nTextWidth := HPDF_Page_TextWidth( hPage, cTxt )

   nRad := nAngle / 180 * 3.141592 	//radian value

   HPDF_Page_SetFontAndSize( hPage, HPDF_GetFont( hPdf, cFont, NIL ), nFontSize )
   HPDF_Page_BeginText( hPage )
   HPDF_Page_SetTextMatrix ( hPage, cos ( nRad ), sin ( nRad ), -sin ( nRad ), cos ( nRad ), nxPos , nyPos - nFontSize)
   HPDF_Page_ShowText( hPage, cTxt )
   HPDF_Page_EndText( hPage )

RETURN

pdf.JPG
EDK thanks for the function you created to rotate the text in pdf
now and the graph in pdf the text is ok

Re: label at runtime

Posted: Fri Sep 08, 2017 4:35 pm
by EduardoLuis
HI EDK

Great job.- This expands HMGPDFPRINT possibilities.-
Tranks for your contribution and for share with us.-
With regards
Eduardo

Re: label at runtime

Posted: Fri Sep 29, 2017 7:06 pm
by jairpinho
I am doing other tests with drawtext and found problems only creates the texts when initialized in the window onpaint if create in another window triggered by a button is also not generated the text follows the project example:
demolabel90.zip
(2 KiB) Downloaded 66 times

Code: Select all

#include <hmg.ch>

declare window main
declare window Form_Label

Function Main

        Load Window Main
        Main.Center
        Main.Activate

Return

Function FORM_LABEL()

        Load Window Form_Label
        Form_Label.Center
        Form_Label.Activate

Return



PROCEDURE Proc_ON_PAINT_Main()
LOCAL hDC, BTstruct

     
  hDC := BT_CreateDC ("Main", BT_HDC_INVALIDCLIENTAREA, @BTstruct)
  

			nTypeText    := BT_TEXT_TRANSPARENT + BT_TEXT_BOLD
			nAlingText   := BT_TEXT_RIGHT + BT_TEXT_BASELINE 
     nOrientation := 90
     BT_DrawText (hDC, 50, 100, " The Power of HMG ", "Comic Sans MS", 12, BLACK ,WHITE, nTypeText, nAlingText, nOrientation)

  BT_DeleteDC (BTstruct)
  
RETURN


PROCEDURE Proc_ON_PAINT_Modal()
LOCAL hDC, BTstruct

     
  hDC := BT_CreateDC ("Main", BT_HDC_INVALIDCLIENTAREA, @BTstruct)
  

			nTypeText    := BT_TEXT_TRANSPARENT + BT_TEXT_BOLD
			nAlingText   := BT_TEXT_RIGHT + BT_TEXT_BASELINE 
     nOrientation := 90
     BT_DrawText (hDC, 50, 100, " The Power of HMG ", "Comic Sans MS", 12, BLACK ,WHITE, nTypeText, nAlingText, nOrientation)

  BT_DeleteDC (BTstruct)
  
RETURN

Re: label at runtime

Posted: Sat Sep 30, 2017 1:16 am
by jairpinho
edk wrote:
Thu Sep 07, 2017 7:20 pm
I hope this will be helpful:

Code: Select all

#include "hmg.ch"

Function Main()
Local i

SELECT HPDFDOC "sample.pdf" PAPERLENGTH 300 PAPERWIDTH 300 LOG
SET HPDFDOC ENCODING TO "WinAnsiEncoding"
START HPDFDOC
    START HPDFPAGE
	    
	@10,10 HPDFPRINT "Rotate Demo"
        
        HPDF_RotateText( 50, 80, "ABCxyz123", Nil, Nil, 90 ) 
	HPDF_RotateText( 50, 80, "ABCxyz123", Nil, Nil, 180)
        HPDF_RotateText( 50, 80, "ABCxyz123", Nil, Nil, 270)
	HPDF_RotateText( 50, 80, "ABCxyz123", Nil, Nil, 0 )
	
	FOR i=100 TO 300 STEP 10
		@i,10 HPDFPRINt "Happy HMG"
	NEXT i

	FOR i=0 To 345 STEP 15
		HPDF_RotateText( 150, 150, "Happy HMG", Nil, 10, i )	
	NEXT i	


    END HPDFPAGE
        

END HPDFDOC

Execute File 'sample.pdf'
Return Nil
*******************************
PROCEDURE HPDF_RotateText( nRow, nCol, cTxt, cFont, nFontSize, nAngle )
* Rotating text

   Local nRad, nTextWidth 
   
   Local hPdf        := _HMG_SYSDATA[ 150 ][ 1 ]
   Local hPage       := _HMG_SYSDATA[ 150 ][ 7 ]

   Local nWidth      := _HMG_SYSDATA[ 150 ][ 4 ]
   Local nHeight     := _HMG_SYSDATA[ 150 ][ 5 ]
   Local nxPos       := _HMG_HPDF_MM2Pixel( nCol )
   Local nyPos       := nHeight - _HMG_HPDF_MM2Pixel( nRow )

   DEFAULT cFont       := "Helvetica"
   DEFAULT nFontSize    := 12   
   DEFAULT cTXt        := ""
   DEFAULT nAngle      := 0


   nTextWidth := HPDF_Page_TextWidth( hPage, cTxt )

   nRad := nAngle / 180 * 3.141592 	//radian value

   HPDF_Page_SetFontAndSize( hPage, HPDF_GetFont( hPdf, cFont, NIL ), nFontSize )
   HPDF_Page_BeginText( hPage )
   HPDF_Page_SetTextMatrix ( hPage, cos ( nRad ), sin ( nRad ), -sin ( nRad ), cos ( nRad ), nxPos , nyPos - nFontSize)
   HPDF_Page_ShowText( hPage, cTxt )
   HPDF_Page_EndText( hPage )

RETURN

pdf.JPG

edk, if you do not use HPDFPRINT with some text of your HPDF_RotateText function the pdf file is not generated if you use apanes a line HPDF_RotateText (50, 80, "ABCxyz123", Nil, Nil, 90) will not generate the file. when to do the test delete the existing .pdf file

Code: Select all

#include "hmg.ch"

Function Main()
Local i

SELECT HPDFDOC "sample.pdf" PAPERLENGTH 300 PAPERWIDTH 300 LOG
SET HPDFDOC ENCODING TO "WinAnsiEncoding"
START HPDFDOC
    START HPDFPAGE
	    
     //@ 10,10 HPDFPRINT "Rotate Demo"  do not create pdf file 
        
        HPDF_RotateText( 50, 80, "ABCxyz123", Nil, Nil, 90 ) 
	HPDF_RotateText( 50, 80, "ABCxyz123", Nil, Nil, 180)
        HPDF_RotateText( 50, 80, "ABCxyz123", Nil, Nil, 270)
	HPDF_RotateText( 50, 80, "ABCxyz123", Nil, Nil, 0 )
	
	FOR i=100 TO 300 STEP 10
		@i,10 HPDFPRINt "Happy HMG"
	NEXT i

	FOR i=0 To 345 STEP 15
		HPDF_RotateText( 150, 150, "Happy HMG", Nil, 10, i )	
	NEXT i	


    END HPDFPAGE
        

END HPDFDOC

Execute File 'sample.pdf'
Return Nil

Re: label at runtime

Posted: Sat Sep 30, 2017 8:51 am
by edk
Corrected. I added font attributes, and colors.

By the way, I found a bug in the source h_HMG_HPDF.Prg
If you want to use the Bold and/or Italic attributes you need to add in h_HMG_HPDF.Prg at line #1812: cFnt := cFont (after "Otherwise"). Otherwise, cFnt variable for declared cFont: "Courier" and "Helvetica" is Nil value, which results in an error.
After the change, of course, you have to rebuild the HMG.

Code: Select all

#include "hmg.ch"

Function Main()
Local i

SELECT HPDFDOC "sample.pdf" PAPERLENGTH 300 PAPERWIDTH 300 LOG
SET HPDFDOC ENCODING TO "WinAnsiEncoding"
START HPDFDOC
    START HPDFPAGE
	    
//	@10,10 HPDFPRINT "Rotate Demo"
        
        HPDF_RotateText( 50, 80, "ABCxyz123", Nil, Nil, 90 ) 
	HPDF_RotateText( 50, 80, "ABCxyz123", Nil, Nil, 180, .T.)
        HPDF_RotateText( 50, 80, "ABCxyz123", Nil, Nil, 270, .T., .T.)
	HPDF_RotateText( 50, 80, "ABCxyz123", Nil, Nil, 0 , , .T.)
	
	FOR i=0 TO 250 STEP 10
		HPDF_RotateText( i, 10, "Happy HMG", "Courier", 15, 5, .T. , .T. , {200, i, 75})
	NEXT i

	FOR i=0 To 345 STEP 15
		HPDF_RotateText( 150, 150, "Happy HMG", Nil, 10, i, , , {255 , 255, 0} )	
	NEXT i	


    END HPDFPAGE
        

END HPDFDOC

Execute File 'sample.pdf'
Return Nil
*******************************
PROCEDURE HPDF_RotateText( nRow, nCol, cTxt, cFont, nFontSize, nAngle, lBold, lItalic, aColors)
* Rotating text

   Local nRad, nTextWidth, oFont, cFnt
   
   Local hPdf        := _HMG_SYSDATA[ 150 ][ 1 ]
   Local hPage       := _HMG_SYSDATA[ 150 ][ 7 ]
   Local cPdfEnc     := _HMG_SYSDATA[ 150 ][ 10 ]

   Local nWidth      := _HMG_SYSDATA[ 150 ][ 4 ]
   Local nHeight     := _HMG_SYSDATA[ 150 ][ 5 ]
   Local nxPos       := _HMG_HPDF_MM2Pixel( nCol )
   Local nyPos       := nHeight - _HMG_HPDF_MM2Pixel( nRow )

   DEFAULT cFont       := "Helvetica"
   DEFAULT nFontSize   := 12   
   DEFAULT cTXt        := ""
   DEFAULT nAngle      := 0
   DEFAULT lBold       := .F.
   DEFAULT lItalic     := .F.
   DEFAULT aColors     := { 0, 0, 0}

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

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


   // set color
   If VALTYPE( aColors )#'A' .OR. LEN( aColors )#3 .OR. ;
      VALTYPE( aColors[1] )#'N' .OR. VALTYPE( aColors[2] )#'N' .OR. VALTYPE( aColors[3] )#'N' .OR. ;
      aColors[1]<0 .OR. aColors[1]>255 .OR. ;
      aColors[2]<0 .OR. aColors[2]>255 .OR. ;
      aColors[3]<0 .OR. aColors[3]>255
      
      aColors     := { 0, 0, 0}
   Endif 
   HPDF_Page_SetRGBFill( hPage, aColors[1]/255, aColors[2]/255, aColors[3]/255 )   

   // set font
   If HMG_LEN( AllTrim( cFont ) ) == 0
      cFont := _HMG_HPDF_SetFont( cFont, lBold, lItalic )
      oFont := HPDF_GetFont( hPdf, cFont, cPdfEnc )

   else

      cFont := AllTrim(_HMG_HPDF_SetFont( cFont, lBold, lItalic ))
    
      if HMG_UPPER (cFileExt (cFont)) == '.TTF' // load ttf font
   
         cFnt := HPDF_LOADTTFONTFROMFILE( hPdf, cFont, .t. )

         If HMG_LEN( Alltrim( cFnt ) ) == 0
            _HMG_HPDF_Error( 6 , cFont )
            Return Nil
         endif

         oFont := HPDF_GetFont( hPdf, cFnt, cPdfEnc )
     
      else
     
         If HMG_UPPER( alltrim( cFont ) ) == "SYMBOL" .or. HMG_UPPER( alltrim( cFont ) ) == "ZAPFDINGBATS"
            oFont := HPDF_GetFont( hPdf, cFont, Nil )
         else   
            oFont := HPDF_GetFont( hPdf, cFont, cPdfEnc )
         endIf
   
      endif

   endIf
   
   If oFont == Nil
      _HMG_HPDF_Error( 6 , cFont )
      Return Nil
   Endif

   HPDF_Page_SetFontAndSize( hPage, oFont, nFontSize )
   nTextWidth := HPDF_Page_TextWidth( hPage, cTxt )

   nRad := nAngle / 180 * 3.141592 	//radian value


   HPDF_Page_BeginText( hPage )
   HPDF_Page_SetTextMatrix ( hPage, cos ( nRad ), sin ( nRad ), -sin ( nRad ), cos ( nRad ), nxPos , nyPos - nFontSize)
   HPDF_Page_ShowText( hPage, cTxt )
   HPDF_Page_EndText( hPage )

RETURN




Re: label at runtime

Posted: Sat Sep 30, 2017 1:38 pm
by serge_girard
Please note:

Code: Select all

cFnt := cFont
instead of

Code: Select all

cFnt: = cFont
!

Serge