Code: Select all
#include "hmg.ch"
Function Main()
Local i
SELECT HPDFDOC "sample.pdf" ORIENTATION HPDF_ORIENT_LANDSCAPE PAPERSIZE HPDF_PAPER_A4
SET HPDFDOC ENCODING TO "WinAnsiEncoding"
START HPDFDOC
START HPDFPAGE
print_grid( 400, 150, 160, 200, 5, 5, 20 , 20 , 10 , 10 )
HPDF_RotateTextPx( 510, 200, 'MĂ-nimo: 119 -> "Mínimo: "', Nil, 7, 90 , , , , 'T' ) //units: pixels
END HPDFPAGE
END HPDFDOC
Execute File 'sample.pdf'
Return Nil
*******************************
PROCEDURE HPDF_RotateTextPx( 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 := nCol
Local nyPos := 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)
HPDF_Page_ShowText( hPage, cTxt )
HPDF_Page_EndText( hPage )
RETURN
*------------------------------------------------------------------------*
Function print_grid( nRow, nCol, height, width, nScaleLine_X, nScaleLine_Y, nScaleText_X, nScaleText_Y, nTag_x, nTag_Y )
*------------------------------------------------------------------------*
Local font,x,y, cLabel, nLabWidth
Local Pdf := _HMG_SYSDATA[ 150 ][ 1 ]
Local Page := _HMG_SYSDATA[ 150 ][ 7 ]
Local cPdfEnc := _HMG_SYSDATA[ 150 ][ 10 ]
Local nFontSize := 5
font := HPDF_GetFont (pdf, "Helvetica", cPdfEnc)
HPDF_Page_SetFontAndSize (page, font, nFontSize)
HPDF_Page_SetGrayFill (page, 0.5)
HPDF_Page_SetGrayStroke (page, 0.8)
/* Draw horizontal lines */
y := 0 // distabcia inicio primeira linha
while (y <= height )
if (y % (nScaleLine_Y*2) == 0)
HPDF_Page_SetLineWidth (page, 0.5)
else
if (HPDF_Page_GetLineWidth (page) != 0.25)
HPDF_Page_SetLineWidth (page, 0.25)
Endif
Endif
HPDF_Page_MoveTo (page, nCol, y + nRow)
HPDF_Page_LineTo (page, width + nCol, y + nRow)
HPDF_Page_Stroke (page)
if (y % nTag_Y == 0 .and. y > 0)
HPDF_Page_SetGrayStroke (page, 0.5)
HPDF_Page_MoveTo (page, nCol, y + nRow)
HPDF_Page_LineTo (page, nScaleLine_Y + nCol , y + nRow)
HPDF_Page_Stroke (page)
HPDF_Page_SetGrayStroke (page, 0.8)
Endif
y += nScaleLine_Y
End
/* Draw vertical lines */
x := 0 //distabcia inicio primeira linha
while (x <= width)
if (x % (nScaleLine_X*2) == 0)
HPDF_Page_SetLineWidth (page, 0.5)
else
if (HPDF_Page_GetLineWidth (page) != 0.25)
HPDF_Page_SetLineWidth (page, 0.25)
Endif
Endif
HPDF_Page_MoveTo (page, x + nCol, nRow)
HPDF_Page_LineTo (page, x + nCol, height + nRow)
HPDF_Page_Stroke (page)
if (x % nTag_X == 0 .and. x > 0) // linha de referencia com a tag texto linha mais forte
HPDF_Page_SetGrayStroke (page, 0.5)
//tag esquerda
HPDF_Page_MoveTo (page, x + nCol, nRow)
HPDF_Page_LineTo (page, x + nCol, nScaleLine_X + nRow )
HPDF_Page_Stroke (page)
//tag direita
HPDF_Page_MoveTo (page, x + nCol, height + nRow)
HPDF_Page_LineTo (page, x + nCol, height - nScaleLine_X + nRow)
HPDF_Page_Stroke (page)
HPDF_Page_SetGrayStroke (page, 0.8)
Endif
x += nScaleLine_X
End
/* Draw horizontal text */
y := 0 //distabcia inicio texto
while (y < height)
if (y % (nScaleText_Y) == 0 .and. y > 0)
cLabel:=ltrim(str(y))
HPDF_Page_BeginText (page)
HPDF_Page_MoveTextPos (page, nScaleLine_Y + nCol, y + nRow - (nFontSize/2) + .75 /* Middled Label */)
HPDF_Page_ShowText (page, cLabel)
HPDF_Page_EndText (page)
Endif
y += nScaleText_Y
End
/* Draw virtical text */
x := 0
while (x < width)
if (x % (nScaleText_X) == 0 .and. x > 0)
cLabel:=ltrim(str(x))
nLabWidth:=HPDF_Page_TextWidth( page, cLabel )
//tag em baixo
HPDF_Page_BeginText (page)
HPDF_Page_MoveTextPos (page, x + nCol - (nLabWidth/2) /* Centered label */, nScaleLine_X + nRow + 1)
HPDF_Page_ShowText (page, cLabel)
HPDF_Page_EndText (page)
//tag em cima
HPDF_Page_BeginText (page)
HPDF_Page_MoveTextPos (page, x + nCol - (nLabWidth/2) /* Centered label */, height - (nScaleLine_X * 2) + nRow)
HPDF_Page_ShowText (page, cLabel)
HPDF_Page_EndText (page)
Endif
x += nScaleText_X
End
HPDF_Page_SetGrayFill (page, 0)
HPDF_Page_SetGrayStroke (page, 0)
Return Nil
Do you have a .prg file saved in UTF-8? Perhaps this is a problem.