Re: label at runtime
Posted: Sat Sep 30, 2017 3:08 pm
Yes, indeed Serge, thx. I wrote a post on a mobile phone I've changed that already.
Exclusive forum for HMG, a Free / Open Source xBase WIN32/64 Bits / GUI Development System
http://www.hmgforum.com/
thanks edk again, I need now to align this text on the rightedk 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
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
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
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 wrote: ↑Mon Oct 02, 2017 1:33 pm Version with vertical alignmentCode: 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 wrote: ↑Mon Oct 02, 2017 1:33 pm Version with vertical alignmentCode: 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
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
Code: Select all
parent MainForm.Tab_1[nPage]