Code: Select all
#include "hmg.ch"
#include "harupdf.ch"
************* This part of the code can be placed in hmg_hpdf.ch **************
#xcommand @ <Row> , <Col> HPDFPRINT SKEW <cText> ;
[ <lfont : FONT> <cFontName> ] ;
[ <lsize : SIZE> <nFontSize> ] ;
[ <bold : BOLD> [ IF <lBold> ] ] ;
[ <italic : ITALIC> [ IF <lItalic> ] ] ;
[ <lcolor : COLOR> <aColor> ] ;
[ <align : CENTER,RIGHT> ] ;
[ <langle : ANGLE> <nAngle> ] ;
[ <langle2: SKEW> <nAngle2> ] ;
=> ;
HPDF_SkewText ( <Row> , <Col> , <cFontName> , <nFontSize> , <aColor>\[1\] , <aColor>\[2\] , <aColor>\[3\] , <cText> ,;
<.bold.> .AND. iif( HB_IsLogical(<lBold>), <lBold>, HB_IsNil(<lBold>) ) ,;
<.italic.> .AND. iif( HB_IsLogical(<lItalic>), <lItalic>, HB_IsNil(<lItalic>) ) ,;
<.lcolor.> , <.lfont.> , <.lsize.> , <"align"> , <nAngle> , <nAngle2> )
#xcommand @ <Row> , <Col> HPDFPRINT SCALE <cText> ;
[ <lfont : FONT> <cFontName> ] ;
[ <lsize : SIZE> <nFontSize> ] ;
[ <bold : BOLD> [ IF <lBold> ] ] ;
[ <italic : ITALIC> [ IF <lItalic> ] ] ;
[ <lcolor : COLOR> <aColor> ] ;
[ <align : CENTER,RIGHT> ] ;
[ <lxscale : XSCALE> <nxscale> ] ;
[ <lyscale : YSCALE> <nyscale> ] ;
=> ;
HPDF_ScaleText ( <Row> , <Col> , <cFontName> , <nFontSize> , <aColor>\[1\] , <aColor>\[2\] , <aColor>\[3\] , <cText> ,;
<.bold.> .AND. iif( HB_IsLogical(<lBold>), <lBold>, HB_IsNil(<lBold>) ) ,;
<.italic.> .AND. iif( HB_IsLogical(<lItalic>), <lItalic>, HB_IsNil(<lItalic>) ) ,;
<.lcolor.> , <.lfont.> , <.lsize.> , <"align"> , <nxscale> , <nyscale> )
#xcommand @ <Row> , <Col> HPDFPRINT RENDER <cText> ;
[ <lfont : FONT> <cFontName> ] ;
[ <lsize : SIZE> <nFontSize> ] ;
[ <bold : BOLD> [ IF <lBold> ] ] ;
[ <italic : ITALIC> [ IF <lItalic> ] ] ;
[ <lcolor : COLOR> <aColor> ] ;
[ <align : CENTER,RIGHT> ] ;
[ <mode : FILL, STROKE, FILL_THEN_STROKE, FILL_CLIPPING, STROKE_CLIPPING, FILL_STROKE_CLIPPING> ] ;
[ <lrim: RIM> <nrim> ] ;
=> ;
HPDF_RenderText ( <Row> , <Col> , <cFontName> , <nFontSize> , <aColor>\[1\] , <aColor>\[2\] , <aColor>\[3\] , <cText> ,;
<.bold.> .AND. iif( HB_IsLogical(<lBold>), <lBold>, HB_IsNil(<lBold>) ) ,;
<.italic.> .AND. iif( HB_IsLogical(<lItalic>), <lItalic>, HB_IsNil(<lItalic>) ) ,;
<.lcolor.> , <.lfont.> , <.lsize.> , <"align"> , HPDF_<mode> , <nrim> )
#xcommand @ <Row> , <Col> HPDFPRINT CIRCLED TEXT <cText> ;
[ <lfont : FONT> <cFontName> ] ;
[ <lsize : SIZE> <nFontSize> ] ;
[ <bold : BOLD> [ IF <lBold> ] ] ;
[ <italic : ITALIC> [ IF <lItalic> ] ] ;
[ <lcolor : COLOR> <aColor> ] ;
[ <lrad : RADIUS> <nRad> ] ;
[ <lrims: RIMS> ] ;
=> ;
HPDF_CircleText ( <Row> , <Col> , <cFontName> , <nFontSize> , <aColor>\[1\] , <aColor>\[2\] , <aColor>\[3\] , <cText> ,;
<.bold.> .AND. iif( HB_IsLogical(<lBold>), <lBold>, HB_IsNil(<lBold>) ) ,;
<.italic.> .AND. iif( HB_IsLogical(<lItalic>), <lItalic>, HB_IsNil(<lItalic>) ) ,;
<.lcolor.> , <.lfont.> , <.lsize.> , <nRad> , <.lrims.> )
*************** The end of this part of the code. *********************
Function Main()
SELECT HPDFDOC "sample.pdf" PAPERLENGTH 300 PAPERWIDTH 300 LOG
START HPDFDOC
SET HPDFDOC ENCODING TO "WinAnsiEncoding"
START HPDFPAGE
@ 20 , 10 HPDFPRINT SKEW "This is a sample Skewed Text." SIZE 22 COLOR {255,0,0} ANGLE 10 SKEW 33
@ 40 , 10 HPDFPRINT SCALE "This is a sample Scaled Text." FONT "Arial" SIZE 22 BOLD COLOR {255,0,0} XSCALE 0.5 YSCALE 2
@ 60 , 10 HPDFPRINT RENDER "This is a sample Render Stroke Text." FONT "Courier" SIZE 22 BOLD COLOR {0,255,0} STROKE RIM 0.8
@ 80 , 10 HPDFPRINT RENDER "This is a sample Render Fill Text." SIZE 22 COLOR {0,255,0} FILL RIM 0.5
@ 100 , 10 HPDFPRINT RENDER "This is a sample Render Fill Then Stroke Text." SIZE 22 COLOR {0,255,0} FILL_THEN_STROKE RIM 1
@ 120 , 10 HPDFPRINT RENDER "This is a sample Render Fill Clipping Text." SIZE 22 COLOR {0,255,0} FILL_CLIPPING RIM 0.5
@ 140 , 10 HPDFPRINT RENDER "This is a sample Render Stroke Clipping Text." SIZE 22 COLOR {0,255,0} STROKE_CLIPPING RIM 0.5
@ 160 , 10 HPDFPRINT RENDER "This is a sample Render Fill Stroke Clipping Text." SIZE 22 ITALIC COLOR {255,0,0} FILL_STROKE_CLIPPING RIM 0.5
@ 230 , 60 HPDFPRINT CIRCLED TEXT "This is a sample Circled Text." FONT "Courier" SIZE 30 BOLD COLOR {0,0,255} RADIUS 35 RIMS
@ 230 , 160 HPDFPRINT CIRCLED TEXT "This is a sample another Circled Text. " SIZE 20 BOLD COLOR {200,200,200} RADIUS 35
END HPDFPAGE
END HPDFDOC
Execute File 'sample.pdf'
Return Nil
************ This part of the code can be placed in h_HMG_HPDF.Prg **********
********************** Then, HMG needs to be rebuilt ************************
Function HPDF_SkewText( nRow, nCol, cFontName, nFontSize, nRColor, nGColor, nBColor, cText, lBold, lItalic, lColor, lFont, lSize, cAlign, nAngle1, nAngle2)
* Skewing text
Local nRad1, nRad2, nTextWidth
Local oFont := Nil
Local cFont := ''
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 cFontName := ''
default nFontSize := _HMG_SYSDATA[ 150 ][ 9 ]
default nRColor := 0
default nGColor := 0
default nBColor := 0
default lBold := .f.
default lItalic := .f.
default lColor := .f.
default lFont := .f.
default lSize := .f.
default cAlign := ''
default nAngle1 := 0
default nAngle2 := 0
IF !HB_IsNumeric( nAngle1 )
nAngle1 := 0
ENDIF
IF !HB_IsNumeric( nAngle2 )
nAngle2 := 0
ENDIF
nRad1 := nAngle1 / 180 * 3.141592 //radian value
nRad2 := nAngle2 / 180 * 3.141592 //radian value
If hPdf == Nil // PDF object not found!
_HMG_HPDF_Error( 3 )
Return Nil
endif
If hPage == Nil // PDF Page object not found!
_HMG_HPDF_Error( 5 )
Return Nil
endif
// set color
If lColor
HPDF_Page_SetRGBFill( hPage, nRColor/255, nGColor/255, nBColor/255 )
else
HPDF_Page_SetRGBFill( hPage, 0.0, 0.0, 0.0 )
endIf
// set font
cFontName := AllTrim(_HMG_HPDF_SetFont( cFontName, lBold, lItalic ))
if HMG_UPPER (cFileExt (cFontName)) == '.TTF' // load ttf font
cFont := HPDF_LOADTTFONTFROMFILE( hPdf, cFontName, .t. )
If HMG_LEN( alltrim( cFont ) ) == 0
_HMG_HPDF_Error( 6 , cFontName )
Return Nil
endif
oFont := HPDF_GetFont( hPdf, cFont, _HMG_SYSDATA[ 150 ][ 10 ] )
else
If HMG_UPPER( alltrim( cFontName ) ) == "SYMBOL" .or. HMG_UPPER( alltrim( cFontName ) ) == "ZAPFDINGBATS"
oFont := HPDF_GetFont( hPdf, cFontName, Nil )
else
oFont := HPDF_GetFont( hPdf, cFontName, _HMG_SYSDATA[ 150 ][ 10 ] )
endIf
endif
If oFont == Nil
_HMG_HPDF_Error( 6 , cFontName )
Return Nil
EndIF
HPDF_Page_SetFontAndSize( hPage, oFont, nFontSize )
nTextWidth := HPDF_Page_TextWidth( hPage, cText )
SWITCH HMG_UPPER( alltrim( cAlign ) )
CASE "RIGHT" ; nxPos := nxPos - nTextWidth; EXIT //Right
CASE "CENTER" ; nxPos := nxPos - ( nTextWidth / 2 ); EXIT //Center
ENDSWITCH
nyPos -= nFontSize
HPDF_Page_BeginText( hPage )
HPDF_Page_SetTextMatrix ( hPage, 1, tan ( nRad1 ), tan ( nRad2 ), 1, nxPos , nyPos)
HPDF_Page_ShowText( hPage, cText )
HPDF_Page_EndText( hPage )
RETURN Nil
*******************************
Function HPDF_ScaleText( nRow, nCol, cFontName, nFontSize, nRColor, nGColor, nBColor, cText, lBold, lItalic, lColor, lFont, lSize, cAlign, nxScale, nyScale)
* Scaling text
Local nTextWidth
Local oFont := Nil
Local cFont := ''
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 cFontName := ''
default nFontSize := _HMG_SYSDATA[ 150 ][ 9 ]
default nRColor := 0
default nGColor := 0
default nBColor := 0
default lBold := .f.
default lItalic := .f.
default lColor := .f.
default lFont := .f.
default lSize := .f.
default cAlign := ''
DEFAULT nxScale := 1
DEFAULT nyScale := 1
IF !HB_IsNumeric( nxScale )
nxScale := 1
ENDIF
IF !HB_IsNumeric( nyScale )
nyScale := 0
ENDIF
If hPdf == Nil // PDF object not found!
_HMG_HPDF_Error( 3 )
Return Nil
endif
If hPage == Nil // PDF Page object not found!
_HMG_HPDF_Error( 5 )
Return Nil
endif
// set color
If lColor
HPDF_Page_SetRGBFill( hPage, nRColor/255, nGColor/255, nBColor/255 )
else
HPDF_Page_SetRGBFill( hPage, 0.0, 0.0, 0.0 )
endIf
// set font
cFontName := AllTrim(_HMG_HPDF_SetFont( cFontName, lBold, lItalic ))
if HMG_UPPER (cFileExt (cFontName)) == '.TTF' // load ttf font
cFont := HPDF_LOADTTFONTFROMFILE( hPdf, cFontName, .t. )
If HMG_LEN( alltrim( cFont ) ) == 0
_HMG_HPDF_Error( 6 , cFontName )
Return Nil
endif
oFont := HPDF_GetFont( hPdf, cFont, _HMG_SYSDATA[ 150 ][ 10 ] )
else
If HMG_UPPER( alltrim( cFontName ) ) == "SYMBOL" .or. HMG_UPPER( alltrim( cFontName ) ) == "ZAPFDINGBATS"
oFont := HPDF_GetFont( hPdf, cFontName, Nil )
else
oFont := HPDF_GetFont( hPdf, cFontName, _HMG_SYSDATA[ 150 ][ 10 ] )
endIf
endif
If oFont == Nil
_HMG_HPDF_Error( 6 , cFontName )
Return Nil
EndIF
HPDF_Page_SetFontAndSize( hPage, oFont, nFontSize )
nTextWidth := HPDF_Page_TextWidth( hPage, cText )
SWITCH HMG_UPPER( alltrim( cAlign ) )
CASE "RIGHT" ; nxPos := nxPos - nTextWidth; EXIT //Right
CASE "CENTER" ; nxPos := nxPos - ( nTextWidth / 2 ); EXIT //Center
ENDSWITCH
nyPos -= nFontSize
HPDF_Page_BeginText( hPage )
HPDF_Page_SetTextMatrix ( hPage, nxScale, 0, 0, nyScale, nxPos , nyPos )
HPDF_Page_ShowText( hPage, cText )
HPDF_Page_EndText( hPage )
RETURN Nil
**********************************************************
Function HPDF_RenderText( nRow, nCol, cFontName, nFontSize, nRColor, nGColor, nBColor, cText, lBold, lItalic, lColor, lFont, lSize, cAlign, nMode, nLineW )
* Rendering text
* Modes:
*HPDF_FILL
*HPDF_STROKE
*HPDF_FILL_THEN_STROKE
*HPDF_FILL_CLIPPING
*HPDF_STROKE_CLIPPING
*HPDF_FILL_STROKE_CLIPPING
Local nTextWidth
Local oFont := Nil
Local cFont := ''
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 nLineW := 0.5
default cFontName := ''
default nFontSize := _HMG_SYSDATA[ 150 ][ 9 ]
default nRColor := 0
default nGColor := 0
default nBColor := 0
default lBold := .f.
default lItalic := .f.
default lColor := .f.
default lFont := .f.
default lSize := .f.
default cAlign := ''
DEFAULT nMode := HPDF_FILL
IF !HB_IsNumeric( nMode )
nMode := HPDF_FILL
ENDIF
IF !HB_IsNumeric( nLineW )
nLineW := 0.5
ENDIF
If hPdf == Nil // PDF object not found!
_HMG_HPDF_Error( 3 )
Return Nil
endif
If hPage == Nil // PDF Page object not found!
_HMG_HPDF_Error( 5 )
Return Nil
endif
// set color
If lColor
HPDF_Page_SetRGBFill( hPage, nRColor/255, nGColor/255, nBColor/255 )
else
HPDF_Page_SetRGBFill( hPage, 0.0, 0.0, 0.0 )
endIf
// set font
cFontName := AllTrim(_HMG_HPDF_SetFont( cFontName, lBold, lItalic ))
if HMG_UPPER (cFileExt (cFontName)) == '.TTF' // load ttf font
cFont := HPDF_LOADTTFONTFROMFILE( hPdf, cFontName, .t. )
If HMG_LEN( alltrim( cFont ) ) == 0
_HMG_HPDF_Error( 6 , cFontName )
Return Nil
endif
oFont := HPDF_GetFont( hPdf, cFont, _HMG_SYSDATA[ 150 ][ 10 ] )
else
If HMG_UPPER( alltrim( cFontName ) ) == "SYMBOL" .or. HMG_UPPER( alltrim( cFontName ) ) == "ZAPFDINGBATS"
oFont := HPDF_GetFont( hPdf, cFontName, Nil )
else
oFont := HPDF_GetFont( hPdf, cFontName, _HMG_SYSDATA[ 150 ][ 10 ] )
endIf
endif
If oFont == Nil
_HMG_HPDF_Error( 6 , cFontName )
Return Nil
EndIF
HPDF_Page_SetFontAndSize( hPage, oFont, nFontSize )
HPDF_Page_SetLineWidth ( hPage, nLineW )
HPDF_Page_GSave ( hPage )
HPDF_Page_SetTextRenderingMode ( hPage, nMode )
nTextWidth := HPDF_Page_TextWidth( hPage, cText )
SWITCH HMG_UPPER( alltrim( cAlign ) )
CASE "RIGHT" ; nxPos := nxPos - nTextWidth; EXIT //Right
CASE "CENTER" ; nxPos := nxPos - ( nTextWidth / 2 ); EXIT //Center
ENDSWITCH
nyPos -= nFontSize
HPDF_Page_BeginText (hPage)
HPDF_Page_TextOut ( hPage, nxPos, nyPos, cText )
HPDF_Page_EndText ( hPage )
IF nMode=HPDF_FILL_CLIPPING .OR. nMode=HPDF_STROKE_CLIPPING .OR. nMode=HPDF_FILL_STROKE_CLIPPING
show_stripe_pattern (hPage, nxPos, nyPos, nTextWidth)
ENDIF
HPDF_Page_GRestore ( hPage )
/* Reset text attributes */
HPDF_Page_SetTextRenderingMode ( hPage, HPDF_FILL)
HPDF_Page_SetRGBFill ( hPage, 0, 0, 0)
HPDF_Page_SetFontAndSize( hPage, HPDF_GetFont( hPdf, "Helvetica", NIL ), 12 )
HPDF_Page_SetLineWidth ( hPage, 0.1 )
HPDF_Page_BeginText (hPage)
HPDF_Page_EndText (hPage)
RETURN Nil
*************************************************************************
FUNCTION show_stripe_pattern ( hPage, x, y, nTxtW )
Local iy := 0
DO While iy < 50
HPDF_Page_SetRGBStroke (hPage, 0.0, 0.0, 0.5)
HPDF_Page_SetLineWidth (hPage, 1)
HPDF_Page_MoveTo (hPage, x, y + iy)
HPDF_Page_LineTo (hPage, x + nTxtW, y + iy)
HPDF_Page_Stroke (hPage)
iy += 3
EndDo
HPDF_Page_SetLineWidth (hPage, 2)
RETURN Nil
*************************************************************************
Function HPDF_CircleText( nRow, nCol, cFontName, nFontSize, nRColor, nGColor, nBColor, cText, lBold, lItalic, lColor, lFont, lSize, nRadial, lCircle)
/* text along a circle */
/* nRow, nCol wspolrzedne srodka */
Local nAngle1, nAngle2, nRlen
Local i, nRad1, nRad2, x, y
Local oFont := Nil
Local cFont := ''
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 )
Local nPxAng
DEFAULT lCircle := .F.
DEFAULT nRadial := 15
default cFontName := ''
default nFontSize := _HMG_SYSDATA[ 150 ][ 9 ]
default nRColor := 0
default nGColor := 0
default nBColor := 0
default lBold := .f.
default lItalic := .f.
default lColor := .f.
default lFont := .f.
default lSize := .f.
DEFAULT cText := ""
IF !HB_IsNumeric( nRadial )
nRadial := 15
ENDIF
nRLen:= _HMG_HPDF_MM2Pixel( nRadial )
// set color
If lColor
HPDF_Page_SetRGBFill( hPage, nRColor/255, nGColor/255, nBColor/255 )
else
HPDF_Page_SetRGBFill( hPage, 0.0, 0.0, 0.0 )
endIf
IF lCircle
HPDF_Page_SetRGBSTROKE( hPage, nRColor/255, nGColor/255, nBColor/255 )
//HPDF_Page_SetGrayStroke ( hPage, 0)
HPDF_Page_SetLineWidth (hPage, 1.5)
HPDF_Page_Circle ( hPage, nxPos, nyPos, nRlen + nFontSize)
HPDF_Page_Circle ( hPage, nxPos, nyPos, nRlen - (nFontSize /3))
HPDF_Page_Stroke ( hPage )
HPDF_Page_SetLineWidth (hPage, 1)
ENDIF
//nAngle1 := 360 / Len( cText ) //monospaced fonts
nAngle2 := 180
// set font
cFontName := AllTrim(_HMG_HPDF_SetFont( cFontName, lBold, lItalic ))
if HMG_UPPER (cFileExt (cFontName)) == '.TTF' // load ttf font
cFont := HPDF_LOADTTFONTFROMFILE( hPdf, cFontName, .t. )
If HMG_LEN( alltrim( cFont ) ) == 0
_HMG_HPDF_Error( 6 , cFontName )
Return Nil
endif
oFont := HPDF_GetFont( hPdf, cFont, _HMG_SYSDATA[ 150 ][ 10 ] )
else
If HMG_UPPER( alltrim( cFontName ) ) == "SYMBOL" .or. HMG_UPPER( alltrim( cFontName ) ) == "ZAPFDINGBATS"
oFont := HPDF_GetFont( hPdf, cFontName, Nil )
else
oFont := HPDF_GetFont( hPdf, cFontName, _HMG_SYSDATA[ 150 ][ 10 ] )
endIf
endif
If oFont == Nil
_HMG_HPDF_Error( 6 , cFontName )
Return Nil
EndIF
HPDF_Page_SetFontAndSize( hPage, oFont, nFontSize )
//A better solution for non monospaced fonts.
nPxAng := 360 / HPDF_Page_TextWidth( hPage, cText )
HPDF_Page_BeginText ( hPage)
FOR i=1 TO LEN(cText)
nRad1 := ( nAngle2 - 90) / 180 * 3.141592
nRad2 := nAngle2 / 180 * 3.141592
x := nxPos + cos(nRad2) * nRlen
y := nyPos + sin(nRad2) * nRlen
HPDF_Page_SetTextMatrix( hPage, cos(nRad1), sin(nRad1), -sin(nRad1), cos(nRad1), x, y)
HPDF_Page_ShowText ( hPage, SUBSTR(cText, i, 1) )
//nAngle2 -= nAngle1 //monospaced fonts
//A better solution for non monospaced fonts.
nAngle2 -= (HPDF_Page_TextWidth( hPage, SUBSTR(cText, i, 1) ) * nPxAng)
NEXT i
HPDF_Page_EndText ( hPage )
RETURN Nil
*************** The end of this part of the code. *********************
I upload as a stand alone prg, but if you want, you can successfully attach new functions to h_HMG_HPDF.Prg and the commands to hmg_hpdf.ch.
Edward.