Files
harbour-core/harbour/contrib/hbcairo/tests/fancytxt.prg
Viktor Szakats f6c08520e4 2012-07-21 18:31 UTC+0200 Viktor Szakats (vszakats syenar.net)
+ tests/stripeol.hb
    + added script to strip spaces at EOL

  * contrib/gtalleg/tests/test.prg
  * contrib/gtwvg/tests/demoxbp.prg
  * contrib/gtwvg/tests/wvgactivex.prg
  * contrib/gtwvg/tests/wvgxbp.prg
  * contrib/gtwvg/wvgclass.prg
  * contrib/hbamf/tests/tstendin.prg
  * contrib/hbbz2/tests/test.prg
  * contrib/hbcairo/tests/fancytxt.prg
  * contrib/hbcairo/tests/table.prg
  * contrib/hbct/ctrand.prg
  * contrib/hbct/doc/en/addascii.txt
  * contrib/hbct/doc/en/atadjust.txt
  * contrib/hbct/doc/en/count.txt
  * contrib/hbct/doc/en/ct.txt
  * contrib/hbct/doc/en/ctc.txt
  * contrib/hbct/doc/en/ctmath.txt
  * contrib/hbct/doc/en/ctmath2.txt
  * contrib/hbct/doc/en/ctpad.txt
  * contrib/hbct/doc/en/ctstr.txt
  * contrib/hbct/doc/en/datetime.txt
  * contrib/hbct/doc/en/dattime2.txt
  * contrib/hbct/doc/en/exponent.txt
  * contrib/hbct/doc/en/finan.txt
  * contrib/hbct/doc/en/ftoc.txt
  * contrib/hbct/doc/en/justify.txt
  * contrib/hbct/doc/en/keyset.txt
  * contrib/hbct/doc/en/misc1.txt
  * contrib/hbct/doc/en/num1.txt
  * contrib/hbct/doc/en/numat.txt
  * contrib/hbct/doc/en/numconv.txt
  * contrib/hbct/doc/en/pos1.txt
  * contrib/hbct/doc/en/pos2.txt
  * contrib/hbct/doc/en/posdiff.txt
  * contrib/hbct/doc/en/print.txt
  * contrib/hbct/doc/en/range.txt
  * contrib/hbct/doc/en/relation.txt
  * contrib/hbct/doc/en/remove.txt
  * contrib/hbct/doc/en/replace.txt
  * contrib/hbct/doc/en/screen1.txt
  * contrib/hbct/doc/en/strdiff.txt
  * contrib/hbct/doc/en/strswap.txt
  * contrib/hbct/doc/en/token1.txt
  * contrib/hbct/doc/en/token2.txt
  * contrib/hbct/doc/en/trig.txt
  * contrib/hbct/doc/en/video.txt
  * contrib/hbct/doc/en/wordtoch.txt
  * contrib/hbct/getinfo.prg
  * contrib/hbfimage/tests/fitest.prg
  * contrib/hbgd/gdimage.prg
  * contrib/hbgd/tests/counter.prg
  * contrib/hbgd/tests/gdtest.prg
  * contrib/hbgd/tests/gdtestcl.prg
  * contrib/hbgd/tests/test_out.prg
  * contrib/hbide/idetags.prg
  * contrib/hblzf/tests/test2.prg
  * contrib/hbmisc/doc/en/ht_conv.txt
  * contrib/hbmisc/fcomma.prg
  * contrib/hbmisc/fileread.prg
  * contrib/hbmisc/hbedit.prg
  * contrib/hbnf/anomatch.prg
  * contrib/hbnf/calendar.prg
  * contrib/hbnf/clrsel.prg
  * contrib/hbnf/dispmsg.prg
  * contrib/hbnf/doc/en/aading.txt
  * contrib/hbnf/doc/en/aavg.txt
  * contrib/hbnf/doc/en/acctadj.txt
  * contrib/hbnf/doc/en/acctmnth.txt
  * contrib/hbnf/doc/en/acctqtr.txt
  * contrib/hbnf/doc/en/acctweek.txt
  * contrib/hbnf/doc/en/acctyear.txt
  * contrib/hbnf/doc/en/adessort.txt
  * contrib/hbnf/doc/en/aemaxlen.txt
  * contrib/hbnf/doc/en/aeminlen.txt
  * contrib/hbnf/doc/en/amedian.txt
  * contrib/hbnf/doc/en/anomatch.txt
  * contrib/hbnf/doc/en/any2any.txt
  * contrib/hbnf/doc/en/aredit.txt
  * contrib/hbnf/doc/en/asum.txt
  * contrib/hbnf/doc/en/at2.txt
  * contrib/hbnf/doc/en/bitclr.txt
  * contrib/hbnf/doc/en/bitset.txt
  * contrib/hbnf/doc/en/blink.txt
  * contrib/hbnf/doc/en/byt2bit.txt
  * contrib/hbnf/doc/en/byt2hex.txt
  * contrib/hbnf/doc/en/byteand.txt
  * contrib/hbnf/doc/en/byteneg.txt
  * contrib/hbnf/doc/en/bytenot.txt
  * contrib/hbnf/doc/en/bytexor.txt
  * contrib/hbnf/doc/en/calendar.txt
  * contrib/hbnf/doc/en/chdir.txt
  * contrib/hbnf/doc/en/cntryset.txt
  * contrib/hbnf/doc/en/color2n.txt
  * contrib/hbnf/doc/en/d2e.txt
  * contrib/hbnf/doc/en/datecnfg.txt
  * contrib/hbnf/doc/en/dayofyr.txt
  * contrib/hbnf/doc/en/daytobow.txt
  * contrib/hbnf/doc/en/dfile.txt
  * contrib/hbnf/doc/en/diskfunc.txt
  * contrib/hbnf/doc/en/dispc.txt
  * contrib/hbnf/doc/en/dispmsg.txt
  * contrib/hbnf/doc/en/dosver.txt
  * contrib/hbnf/doc/en/e2d.txt
  * contrib/hbnf/doc/en/easter.txt
  * contrib/hbnf/doc/en/elapsed.txt
  * contrib/hbnf/doc/en/findith.txt
  * contrib/hbnf/doc/en/floptst.txt
  * contrib/hbnf/doc/en/ftattr.txt
  * contrib/hbnf/doc/en/ftidle.txt
  * contrib/hbnf/doc/en/ftisprn.txt
  * contrib/hbnf/doc/en/ftround.txt
  * contrib/hbnf/doc/en/fttext.txt
  * contrib/hbnf/doc/en/gcd.txt
  * contrib/hbnf/doc/en/getenvrn.txt
  * contrib/hbnf/doc/en/hex2dec.txt
  * contrib/hbnf/doc/en/iamidle.txt
  * contrib/hbnf/doc/en/isbit.txt
  * contrib/hbnf/doc/en/isbiton.txt
  * contrib/hbnf/doc/en/isshare.txt
  * contrib/hbnf/doc/en/kspeed.txt
  * contrib/hbnf/doc/en/linked.txt
  * contrib/hbnf/doc/en/madd.txt
  * contrib/hbnf/doc/en/menutonf.txt
  * contrib/hbnf/doc/en/metaph.txt
  * contrib/hbnf/doc/en/miltime.txt
  * contrib/hbnf/doc/en/month.txt
  * contrib/hbnf/doc/en/netpv.txt
  * contrib/hbnf/doc/en/nooccur.txt
  * contrib/hbnf/doc/en/ntow.txt
  * contrib/hbnf/doc/en/nwlstat.txt
  * contrib/hbnf/doc/en/nwsem.txt
  * contrib/hbnf/doc/en/nwuid.txt
  * contrib/hbnf/doc/en/ontick.txt
  * contrib/hbnf/doc/en/origin.txt
  * contrib/hbnf/doc/en/page.txt
  * contrib/hbnf/doc/en/pchr.txt
  * contrib/hbnf/doc/en/peek.txt
  * contrib/hbnf/doc/en/pending.txt
  * contrib/hbnf/doc/en/poke.txt
  * contrib/hbnf/doc/en/popadder.txt
  * contrib/hbnf/doc/en/proper.txt
  * contrib/hbnf/doc/en/prtesc.txt
  * contrib/hbnf/doc/en/putkey.txt
  * contrib/hbnf/doc/en/qtr.txt
  * contrib/hbnf/doc/en/rand1.txt
  * contrib/hbnf/doc/en/savearr.txt
  * contrib/hbnf/doc/en/scregion.txt
  * contrib/hbnf/doc/en/setdate.txt
  * contrib/hbnf/doc/en/setkeys.txt
  * contrib/hbnf/doc/en/setlastk.txt
  * contrib/hbnf/doc/en/settime.txt
  * contrib/hbnf/doc/en/sinkey.txt
  * contrib/hbnf/doc/en/sleep.txt
  * contrib/hbnf/doc/en/sqzn.txt
  * contrib/hbnf/doc/en/sysmem.txt
  * contrib/hbnf/doc/en/tbwhile.txt
  * contrib/hbnf/doc/en/tempfile.txt
  * contrib/hbnf/doc/en/vertmenu.txt
  * contrib/hbnf/doc/en/vidcur.txt
  * contrib/hbnf/doc/en/vidmode.txt
  * contrib/hbnf/doc/en/wda.txt
  * contrib/hbnf/doc/en/week.txt
  * contrib/hbnf/doc/en/workdays.txt
  * contrib/hbnf/doc/en/woy.txt
  * contrib/hbnf/doc/en/xbox.txt
  * contrib/hbnf/doc/en/year.txt
  * contrib/hbnf/ftround.prg
  * contrib/hbnf/metaph.prg
  * contrib/hbnf/nwsem.prg
  * contrib/hbnf/nwuid.prg
  * contrib/hbnf/pending.prg
  * contrib/hbnf/popadder.prg
  * contrib/hbnf/scregion.prg
  * contrib/hbnf/tbwhile.prg
  * contrib/hbnf/workdays.prg
  * contrib/hbodbc/browodbc.prg
  * contrib/hbqt/tests/browqt.prg
  * contrib/hbqt/tests/dbfbrowserclass.prg
  * contrib/hbqt/tests/testbrow.prg
  * contrib/hbsqlit3/tests/blob.prg
  * contrib/hbsqlit3/tests/sl3_test.prg
  * contrib/hbxbp/tests/demoxbp.prg
  * contrib/hbxbp/tests/dialogqt.prg
  * contrib/hbxbp/xbpdataref.prg
  * contrib/hbxbp/xbpmenubar.prg
  * contrib/hbxbp/xbpprintdialog.prg
  * contrib/hbxbp/xbpprinter.prg
  * contrib/hbxbp/xbprtf.prg
  * contrib/hbxbp/xbpscrollbar.prg
  * contrib/xhb/cstruct.prg
  * contrib/xhb/hblog.prg
  * contrib/xhb/hterrsys.prg
  * contrib/xhb/htjlist.prg
  * contrib/xhb/sprintf.prg
  * contrib/xhb/stream.prg
  * contrib/xhb/tcgi.prg
  * contrib/xhb/tedit.prg
  * contrib/xhb/tfile.prg
  * contrib/xhb/thtm.prg
  * contrib/xhb/trpc.prg
  * contrib/xhb/trpccli.prg
  * contrib/xhb/ttable.prg
  * contrib/xhb/txml.prg
  * contrib/xhb/xcstr.prg
  * contrib/xhb/xhberr.prg
  * contrib/xhb/xhbmt.prg
  * doc/cmpopt.txt
  * doc/en/dbstrux.txt
  * examples/hbapollo/array.prg
  * examples/hbvpdf/hbvpdf.prg
  * examples/hbvpdf/hbvpdft.prg
  * examples/hbxlsxml/xlsxml_s.prg
  * examples/hbxlsxml/xlsxml_y.prg
  * examples/httpsrv/cgifunc.prg
  * examples/httpsrv/cookie.prg
  * examples/httpsrv/modules/cookie.prg
  * examples/httpsrv/modules/info.prg
  * examples/httpsrv/modules/showcounter.prg
  * examples/httpsrv/modules/tableservletdb.prg
  * examples/httpsrv/modules/testajax.prg
  * examples/httpsrv/session.prg
  * examples/httpsrv/uhttpd.prg
  * include/hbclass.ch
  * include/hbtrace.ch
  * src/debug/dbgtinp.prg
  * src/debug/debugger.prg
  * src/debug/tbrwtext.prg
  * src/rdd/usrrdd/rdds/hscdx.prg
  * src/rtl/hbi18n2.prg
  * src/rtl/valtoexp.prg
    * formatting, fixed indentation, cleanups, deleting system specific information,
      optimizing out platform dependent code, using hb_ntos()
2012-07-21 16:48:00 +00:00

185 lines
6.0 KiB
Plaintext

/*
* $Id$
*/
#include "hbcairo.ch"
PROC main()
LOCAL hSurface
hSurface := cairo_pdf_surface_create( "fancytxt.pdf", 566.9, 793.7 ) // 200x280 mm in pt
draw( hSurface )
cairo_surface_destroy( hSurface )
hSurface := cairo_image_surface_create( "fancytxt.pdf", 567, 794 )
draw( hSurface )
cairo_surface_write_to_png( hSurface, "fancytxt.png" )
cairo_surface_destroy( hSurface )
RETURN
PROC draw( hSurface )
LOCAL hCairo, hPath
hCairo := cairo_create( hSurface )
cairo_set_tolerance( hCairo, 0.01 )
// Draw base line
cairo_move_to( hCairo, 50, 650 )
cairo_rel_line_to( hCairo, 250, 50 )
cairo_rel_curve_to( hCairo, 100, 20, 200, -50, 200, -150 )
cairo_rel_curve_to( hCairo, 0, -400, -300, -100, -400, -300 )
hPath := cairo_copy_path_flat( hCairo )
cairo_set_line_width( hCairo, 1 )
cairo_set_source_rgb( hCairo, 0.6, 0.0, 0.0 )
cairo_stroke( hCairo )
// Draw text
cairo_new_path( hCairo )
cairo_select_font_face( hCairo, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL )
cairo_set_font_size( hCairo, 72 )
cairo_move_to( hCairo, 0, -5 )
cairo_text_path( hCairo, "Welcome to the world of Harbour..." )
// Transform
map_path_onto( hCairo, hPath )
cairo_path_destroy( hPath )
// Paint
cairo_set_line_cap( hCairo, CAIRO_LINE_CAP_ROUND )
cairo_set_source_rgb( hCairo, 0.2, 0.1, 0.8 )
cairo_fill_preserve( hCairo )
cairo_set_line_width( hCairo, 1 )
cairo_set_source_rgb( hCairo, 0.2, 0.2, 0.2 )
cairo_stroke( hCairo )
cairo_show_page( hCairo )
cairo_destroy( hCairo )
RETURN
PROC map_path_onto( hCairo, hPath )
LOCAL hCurrentPath, aLengths, hIterator, nI, aPoints
hCurrentPath := cairo_copy_path( hCairo )
aLengths := path_lengths( hPath )
hIterator := cairo_path_iterator_create( hCurrentPath )
DO WHILE cairo_path_iterator_next( hIterator ) != NIL
IF LEN( aPoints := cairo_path_iterator_get_points( hIterator ) ) > 0
FOR nI := 1 TO LEN( aPoints )
transform_point( @aPoints[ nI, 1 ], @aPoints[ nI, 2 ], hPath, aLengths )
NEXT
cairo_path_iterator_set_points( hIterator, aPoints )
ENDIF
ENDDO
cairo_path_iterator_destroy( hIterator )
cairo_append_path( hCairo, hCurrentPath )
RETURN
STATIC PROC transform_point( nX, nY, hPath, aLengths )
LOCAL hIterator, nI, nNX, nNY, nDX, nDY, nRatio, nType, aLast, aPoints, nK1, nK2
nNX := nX
nNY := nY
hIterator := cairo_path_iterator_create( hPath )
nI := 1
DO WHILE ( nType := cairo_path_iterator_next( hIterator ) ) != NIL
aPoints := cairo_path_iterator_get_points( hIterator )
IF nNX <= aLengths[ nI ] .AND. nType != CAIRO_PATH_MOVE_TO
EXIT
ENDIF
nNX -= aLengths[ nI ]
nI++
IF nType == CAIRO_PATH_MOVE_TO .OR. nType == CAIRO_PATH_LINE_TO
aLast := aPoints[ 1 ]
ELSEIF nType == CAIRO_PATH_CURVE_TO
aLast := aPoints[ 3 ]
ENDIF
ENDDO
IF nType == CAIRO_PATH_MOVE_TO
ELSEIF nType == CAIRO_PATH_LINE_TO
nRatio := nNX / aLengths[ nI ]
nX := aLast[ 1 ] * (1 - nRatio) + aPoints[ 1, 1 ] * nRatio
nY := aLast[ 2 ] * (1 - nRatio) + aPoints[ 1, 2 ] * nRatio
nDX := -(aLast[ 1 ] - aPoints[ 1, 1 ])
nDY := -(aLast[ 2 ] - aPoints[ 1, 2 ])
nRatio := nNY / aLengths[ nI ]
nX += -nDY * nRatio
nY += nDX * nRatio
ELSEIF nType == CAIRO_PATH_CURVE_TO
nX := aLast[ 1 ] * (1 - nRatio)^3 + 3 * aPoints[ 1, 1 ] * (1 - nRatio)^2 * nRatio + 3 * aPoints[ 2, 1 ] * (1 - nRatio) * nRatio^2 + aPoints[ 3, 1 ] * nRatio^3
nY := aLast[ 2 ] * (1 - nRatio)^3 + 3 * aPoints[ 1, 2 ] * (1 - nRatio)^2 * nRatio + 3 * aPoints[ 2, 2 ] * (1 - nRatio) * nRatio^2 + aPoints[ 3, 2 ] * nRatio^3
nK1 := 1 - 4 * nRatio + 3 * nRatio^2
nK2 := 2 * nRatio - 3 * nRatio^2
nDX := -3 * aLast[ 1 ] * (1 - nRatio)^2 + 3 * aPoints[ 1, 1 ] * nK1 + 3 * aPoints[ 2, 1 ] * nK2 + 3 * aPoints[ 3, 1 ] * nRatio^2
nDY := -3 * aLast[ 2 ] * (1 - nRatio)^2 + 3 * aPoints[ 1, 2 ] * nK1 + 3 * aPoints[ 2, 2 ] * nK2 + 3 * aPoints[ 3, 2 ] * nRatio^2
nRatio := nNY / SQRT( nDX * nDX + nDY * nDY )
nX += -nDY * nRatio
nY += nDX * nRatio
ENDIF
cairo_path_iterator_destroy( hIterator )
RETURN
STATIC FUNC path_lengths( hPath )
LOCAL hIterator, nType, aLast, aRet, aPoints, nLen
aRet := {}
hIterator := cairo_path_iterator_create( hPath )
DO WHILE ( nType := cairo_path_iterator_next( hIterator ) ) != NIL
aPoints := cairo_path_iterator_get_points( hIterator )
nLen := 0
IF nType == CAIRO_PATH_MOVE_TO
aLast := aPoints[ 1 ]
ELSEIF nType == CAIRO_PATH_LINE_TO
nLen := distance( aLast[ 1 ], aLast[ 2 ], aPoints[ 1, 1 ], aPoints[ 1, 2 ] )
aLast := aPoints[ 1 ]
ELSEIF nType == CAIRO_PATH_CURVE_TO
nLen := curve_length( aLast[ 1 ], aLast[ 2 ], aPoints[ 1, 1 ], aPoints[ 1, 2 ], ;
aPoints[ 2, 1 ], aPoints[ 2, 2 ], aPoints[ 3, 1 ], aPoints[ 3, 2 ] )
aLast := aPoints[ 3 ]
ENDIF
AADD( aRet, nLen )
ENDDO
cairo_path_iterator_destroy( hIterator )
RETURN aRet
STATIC FUNC distance( nX1, nY1, nX2, nY2 )
RETURN sqrt( (nX1-nX2)^2 + (nY1-nY2)^2 )
STATIC FUNC curve_length( nX1, nY1, nX2, nY2, nX3, nY3, nX4, nY4 )
LOCAL nLength := 0, hSurface, hCairo, hPath, hIterator, nType, aLast, aPoints
hSurface := cairo_image_surface_create( CAIRO_FORMAT_A8, 0, 0 )
hCairo := cairo_create( hSurface )
cairo_move_to( hCairo, nX1, nY1 )
cairo_curve_to( hCairo, nX2, nY2, nX3, nY3, nX4, nY4 )
hPath := cairo_copy_path_flat( hCairo )
hIterator := cairo_path_iterator_create( hPath )
DO WHILE ( nType := cairo_path_iterator_next( hIterator, @aPoints ) ) != NIL
IF nType == CAIRO_PATH_MOVE_TO
aLast := aPoints
ELSEIF nType == CAIRO_PATH_LINE_TO
nLength += distance( aLast[ 1 ], aLast[ 2 ], aPoints[ 1 ], aPoints[ 2 ] )
aLast := aPoints
ENDIF
ENDDO
cairo_path_iterator_destroy( hIterator )
cairo_path_destroy( hPath )
cairo_destroy( hCairo )
cairo_surface_destroy( hSurface )
RETURN nLength