label at runtime

Moderator: Rathinagiri

edk
Posts: 361
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 102 times
Been thanked: 262 times

Re: label at runtime

Post by edk » Sat Sep 30, 2017 3:08 pm

Yes, indeed Serge, thx. I wrote a post on a mobile phone :oops: I've changed that already.

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

Post by jairpinho » Sat Sep 30, 2017 8:57 pm

edk wrote:
Sat Sep 30, 2017 8:51 am
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



thanks edk again, I need now to align this text on the right
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br

edk
Posts: 361
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 102 times
Been thanked: 262 times

Post by edk » Sun Oct 01, 2017 8:24 am

In the source you have all the variables to try to do it yourself. There are coordinates and text width: nTextWidth. It remains a matter of what axis you need to align the text, the absolute X-axis of the page or the base line of the rotated text?

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

Post by jairpinho » Sun Oct 01, 2017 8:17 pm

edk wrote:
Sun Oct 01, 2017 8:24 am
In the source you have all the variables to try to do it yourself. There are coordinates and text width: nTextWidth. It remains a matter of what axis you need to align the text, the absolute X-axis of the page or the base line of the rotated text?
I've tried everything I can not do, I'm trying to do based on their codes I started to play some haru codes but it's still very difficult for me to understand, I can modify some codes already ready to try to find solutions for my projects but sometimes I do not have a lot of understanding
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br

edk
Posts: 361
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 102 times
Been thanked: 262 times

Post by edk » Mon Oct 02, 2017 10:54 am

This is simple. Just calculate the value of nxPos.
Knowing the width of the text, for alignment to the right, simply move the text to the left direction. Subtract the width of the text from nxPos. To center the text, nxPos subtract half the width of the text.
Conversely, if the text is at an angle, knowing the angle and width of the text, calculate the width of the base that the triangle forms. Use the calculated triangle base to calculate the new value of nxPos. Pure math. :roll:

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, 100 HPDFPRINT LINE TO 220, 100 PENWIDTH 0.05
    	@ 10, 100 HPDFPRINT "AXIS" CENTER

    	@ 30, 100 HPDFPRINT "LEFT ALIGN"
        
	HPDF_RotateText( 50, 100, "ABCxyz123", Nil, Nil, 0 )
     HPDF_RotateText( 50, 100, "ABCxyz123", Nil, Nil, 45 )
   
     
     @ 80, 100 HPDFPRINT "RIGHT ALIGN" RIGHT
        
     HPDF_RotateText( 100, 100, "ABCxyz123", Nil, Nil, 0 , , ,{255 , 0, 0} , 'R' )
     HPDF_RotateText( 100, 100, "ABCxyz123", Nil, Nil, 45 , , ,{255 , 0, 0} , 'r' )
     

     @ 130, 100 HPDFPRINT "CENTER ALIGN" CENTER
     
     HPDF_RotateText( 150, 100, "ABCxyz123", Nil, Nil, 0 , , ,{0,255 , 0} , 'C' )
     HPDF_RotateText( 150, 100, "ABCxyz123", Nil, Nil, 45 , , ,{0,255 , 0} , 'c' )
     
    END HPDFPAGE
        

END HPDFDOC

Execute File 'sample.pdf'
Return Nil
*******************************
PROCEDURE HPDF_RotateText( nRow, nCol, cTxt, cFont, nFontSize, nAngle, lBold, lItalic, aColors, cAlign)
* 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}
   DEFAULT cAlign      :='L'

   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

   IF VALTYPE(cAlign)#'C' .OR. !(HMG_UPPER(cAlign)$'LRC')
      cAlign := 'L'		//Left as default
   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
   
   //calculate nxPos
   IF HMG_UPPER(cAlign)='R'		//Right
      nxPos:=nxPos - (nTextWidth* cos (nRad))
   ELSEIF HMG_UPPER(cAlign)='C'	//Center
   	 nxPos:=nxPos - ((nTextWidth* cos (nRad))/2)
   ENDIF
 
   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
PS. If you want to align the text vertically, you should calculate the nyPos variable, correcting the coordinates by the height of that the triangle forms. Then you have to use the sinus function.
Note also that the height of the text corresponds to the nFontSize variable.
Try it yourself, I believe you will succeed.

edk
Posts: 361
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 102 times
Been thanked: 262 times

Post by edk » Mon Oct 02, 2017 1:33 pm

Version with vertical alignment ;)

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, 100 HPDFPRINT LINE TO 220, 100 PENWIDTH 0.05
    	@ 10, 100 HPDFPRINT "AXIS" CENTER

    	@ 30, 100 HPDFPRINT "LEFT ALIGN"

    	@ 50+_HMG_HPDF_Pixel2MM( 12 ), 10 HPDFPRINT LINE TO 50+_HMG_HPDF_Pixel2MM( 12 ), 200 PENWIDTH 0.05
	HPDF_RotateText( 50, 100, "ABCxyz123", Nil, Nil, 0 )
     HPDF_RotateText( 50, 100, "ABCxyz123", Nil, Nil, 45 )
   
     HPDF_RotateText( 50, 100, "Center Middle", Nil, Nil, 135 , , ,{0 , 0, 255} , 'cM' )
     HPDF_RotateText( 50, 100, "Top", Nil, Nil, 90 , , ,{255 , 0, 255} , 'T' )
     
     
     @ 80, 100 HPDFPRINT "RIGHT ALIGN" RIGHT
        
     HPDF_RotateText( 100, 100, "ABCxyz123", Nil, Nil, 0 , , ,{255 , 0, 0} , 'R' )
     HPDF_RotateText( 100, 100, "ABCxyz123", Nil, Nil, 45 , , ,{255 , 0, 0} , 'r' )
     

     @ 130, 100 HPDFPRINT "CENTER ALIGN" CENTER
     
     HPDF_RotateText( 150, 100, "ABCxyz123", Nil, Nil, 0 , , ,{0,255 , 0} , 'C' )
     HPDF_RotateText( 150, 100, "ABCxyz123", Nil, Nil, 45 , , ,{0,255 , 0} , 'c' )
     
    END HPDFPAGE
        

END HPDFDOC

Execute File 'sample.pdf'
Return Nil
*******************************
PROCEDURE HPDF_RotateText( nRow, nCol, cTxt, cFont, nFontSize, nAngle, lBold, lItalic, aColors, cAlign)
* 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}
   DEFAULT cAlign      :=""		//Empty - Left and bottom, R - Right, C - Center, T - Top, M - Middle

   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

   
   IF VALTYPE(cAlign)#'C' 
      cAlign := ''		//Left as default
   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
   
   //calculate nxPos
   IF 'R'$HMG_UPPER(cAlign)		//Right
      nxPos:=nxPos - (nTextWidth* cos (nRad))
   ELSEIF 'C'$HMG_UPPER(cAlign)	//Center
   	 nxPos:=nxPos - ((nTextWidth* cos (nRad))/2)
   ENDIF
   
   //calculate nyPos
   IF 'T'$HMG_UPPER(cAlign)		//Top
      nyPos:=nyPos - (nTextWidth* sin (nRad))
   ELSEIF 'M'$HMG_UPPER(cAlign)	//Middle
   	 nyPos:=nyPos - ((nTextWidth* sin (nRad))/2)
   ENDIF
 
   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

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

Post by jairpinho » Mon Oct 02, 2017 8:20 pm

edk wrote:
Mon Oct 02, 2017 1:33 pm
Version with vertical alignment ;)

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, 100 HPDFPRINT LINE TO 220, 100 PENWIDTH 0.05
    	@ 10, 100 HPDFPRINT "AXIS" CENTER

    	@ 30, 100 HPDFPRINT "LEFT ALIGN"

    	@ 50+_HMG_HPDF_Pixel2MM( 12 ), 10 HPDFPRINT LINE TO 50+_HMG_HPDF_Pixel2MM( 12 ), 200 PENWIDTH 0.05
	HPDF_RotateText( 50, 100, "ABCxyz123", Nil, Nil, 0 )
     HPDF_RotateText( 50, 100, "ABCxyz123", Nil, Nil, 45 )
   
     HPDF_RotateText( 50, 100, "Center Middle", Nil, Nil, 135 , , ,{0 , 0, 255} , 'cM' )
     HPDF_RotateText( 50, 100, "Top", Nil, Nil, 90 , , ,{255 , 0, 255} , 'T' )
     
     
     @ 80, 100 HPDFPRINT "RIGHT ALIGN" RIGHT
        
     HPDF_RotateText( 100, 100, "ABCxyz123", Nil, Nil, 0 , , ,{255 , 0, 0} , 'R' )
     HPDF_RotateText( 100, 100, "ABCxyz123", Nil, Nil, 45 , , ,{255 , 0, 0} , 'r' )
     

     @ 130, 100 HPDFPRINT "CENTER ALIGN" CENTER
     
     HPDF_RotateText( 150, 100, "ABCxyz123", Nil, Nil, 0 , , ,{0,255 , 0} , 'C' )
     HPDF_RotateText( 150, 100, "ABCxyz123", Nil, Nil, 45 , , ,{0,255 , 0} , 'c' )
     
    END HPDFPAGE
        

END HPDFDOC

Execute File 'sample.pdf'
Return Nil
*******************************
PROCEDURE HPDF_RotateText( nRow, nCol, cTxt, cFont, nFontSize, nAngle, lBold, lItalic, aColors, cAlign)
* 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}
   DEFAULT cAlign      :=""		//Empty - Left and bottom, R - Right, C - Center, T - Top, M - Middle

   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

   
   IF VALTYPE(cAlign)#'C' 
      cAlign := ''		//Left as default
   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
   
   //calculate nxPos
   IF 'R'$HMG_UPPER(cAlign)		//Right
      nxPos:=nxPos - (nTextWidth* cos (nRad))
   ELSEIF 'C'$HMG_UPPER(cAlign)	//Center
   	 nxPos:=nxPos - ((nTextWidth* cos (nRad))/2)
   ENDIF
   
   //calculate nyPos
   IF 'T'$HMG_UPPER(cAlign)		//Top
      nyPos:=nyPos - (nTextWidth* sin (nRad))
   ELSEIF 'M'$HMG_UPPER(cAlign)	//Middle
   	 nyPos:=nyPos - ((nTextWidth* sin (nRad))/2)
   ENDIF
 
   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

Thank you Edk, it was perfect.
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br

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

Post by jairpinho » Mon Oct 02, 2017 9:01 pm

edk wrote:
Mon Oct 02, 2017 1:33 pm
Version with vertical alignment ;)

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, 100 HPDFPRINT LINE TO 220, 100 PENWIDTH 0.05
    	@ 10, 100 HPDFPRINT "AXIS" CENTER

    	@ 30, 100 HPDFPRINT "LEFT ALIGN"

    	@ 50+_HMG_HPDF_Pixel2MM( 12 ), 10 HPDFPRINT LINE TO 50+_HMG_HPDF_Pixel2MM( 12 ), 200 PENWIDTH 0.05
	HPDF_RotateText( 50, 100, "ABCxyz123", Nil, Nil, 0 )
     HPDF_RotateText( 50, 100, "ABCxyz123", Nil, Nil, 45 )
   
     HPDF_RotateText( 50, 100, "Center Middle", Nil, Nil, 135 , , ,{0 , 0, 255} , 'cM' )
     HPDF_RotateText( 50, 100, "Top", Nil, Nil, 90 , , ,{255 , 0, 255} , 'T' )
     
     
     @ 80, 100 HPDFPRINT "RIGHT ALIGN" RIGHT
        
     HPDF_RotateText( 100, 100, "ABCxyz123", Nil, Nil, 0 , , ,{255 , 0, 0} , 'R' )
     HPDF_RotateText( 100, 100, "ABCxyz123", Nil, Nil, 45 , , ,{255 , 0, 0} , 'r' )
     

     @ 130, 100 HPDFPRINT "CENTER ALIGN" CENTER
     
     HPDF_RotateText( 150, 100, "ABCxyz123", Nil, Nil, 0 , , ,{0,255 , 0} , 'C' )
     HPDF_RotateText( 150, 100, "ABCxyz123", Nil, Nil, 45 , , ,{0,255 , 0} , 'c' )
     
    END HPDFPAGE
        

END HPDFDOC

Execute File 'sample.pdf'
Return Nil
*******************************
PROCEDURE HPDF_RotateText( nRow, nCol, cTxt, cFont, nFontSize, nAngle, lBold, lItalic, aColors, cAlign)
* 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}
   DEFAULT cAlign      :=""		//Empty - Left and bottom, R - Right, C - Center, T - Top, M - Middle

   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

   
   IF VALTYPE(cAlign)#'C' 
      cAlign := ''		//Left as default
   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
   
   //calculate nxPos
   IF 'R'$HMG_UPPER(cAlign)		//Right
      nxPos:=nxPos - (nTextWidth* cos (nRad))
   ELSEIF 'C'$HMG_UPPER(cAlign)	//Center
   	 nxPos:=nxPos - ((nTextWidth* cos (nRad))/2)
   ENDIF
   
   //calculate nyPos
   IF 'T'$HMG_UPPER(cAlign)		//Top
      nyPos:=nyPos - (nTextWidth* sin (nRad))
   ELSEIF 'M'$HMG_UPPER(cAlign)	//Middle
   	 nyPos:=nyPos - ((nTextWidth* sin (nRad))/2)
   ENDIF
 
   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

edk, help me on this grid only missing this part for my project, you understand this mathematics well

http://www.hmgforum.com/viewtopic.php?f=40&t=5425
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br

User avatar
mol
Posts: 3062
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 176 times
Been thanked: 96 times
Contact:

Post by mol » Fri Oct 20, 2017 7:56 am

I don't want to create new topic, because my problem is creation label placed on tab.

I've defined MainForm window and Tab_1 within.
I want to create at runtime placed on tab_1

Code: Select all

   define label NewLabel
			parent MainForm.Tab_1
			row 115
			col 700
			backColor {96,96,96}
			value "BAR"
			height 180
			width  20
end label
but, MainForm.Tab_1 is unknown for application.
How to do it? Is it possible?

edk
Posts: 361
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 102 times
Been thanked: 262 times

Post by edk » Fri Oct 20, 2017 8:28 am

So on quickly:

Code: Select all

 parent MainForm.Tab_1[nPage]

Post Reply