1 ! Copyright (C) 2007 Elie CHAFTARI
2 ! See http://factorcode.org/license.txt for BSD license.
4 ! Tested with libharu2 2.0.8 on Mac OS X 10.4.9 PowerPC
6 USING: assocs continuations hashtables kernel math namespaces pdf.libhpdf ;
13 ! =========================================================
14 ! Error handling routines
15 ! =========================================================
17 : check-status ( status -- )
21 error-code >hashtable at throw
24 ! =========================================================
25 ! Document handling routines
26 ! =========================================================
28 : new-pdf ( error-handler user-data -- )
32 pdf get HPDF_Free drop ;
34 : with-pdf ( quot -- )
35 [ f f new-pdf [ free-pdf ] [ ] cleanup ] with-scope ; inline
37 : set-compression-mode ( mode -- )
38 pdf get swap HPDF_SetCompressionMode check-status ;
40 : set-page-mode ( mode -- )
41 pdf get swap HPDF_SetPageMode check-status ;
44 pdf get HPDF_AddPage page set ;
46 : save-to-file ( filename -- )
47 pdf get swap HPDF_SaveToFile check-status ;
49 : get-font ( fontname encoding -- font )
50 pdf get -rot HPDF_GetFont ;
52 ! =========================================================
53 ! Page Handling routines
54 ! =========================================================
56 : get-page-height ( -- height )
57 page get HPDF_Page_GetHeight ;
59 : get-page-width ( -- width )
60 page get HPDF_Page_GetWidth ;
62 : page-text-width ( text -- width )
63 page get swap HPDF_Page_TextWidth ;
65 ! =========================================================
67 ! =========================================================
69 : set-page-line-width ( linewidth -- )
70 page get swap HPDF_Page_SetLineWidth check-status ;
72 : page-rectangle ( x y width height -- )
73 >r >r >r >r page get r> r> r> r> HPDF_Page_Rectangle check-status ;
76 page get HPDF_Page_Stroke check-status ;
78 : set-page-font-and-size ( font size -- )
79 page get -rot HPDF_Page_SetFontAndSize check-status ;
81 : page-begin-text ( -- )
82 page get HPDF_Page_BeginText check-status ;
84 : page-text-out ( xpos ypos text -- )
85 page get -roll HPDF_Page_TextOut check-status ;
87 : page-end-text ( -- )
88 page get HPDF_Page_EndText check-status ;
91 [ page-begin-text [ page-end-text ] [ ] cleanup ] with-scope ; inline
93 : page-move-text-pos ( x y -- )
94 page get -rot HPDF_Page_MoveTextPos check-status ;
96 : page-show-text ( text -- )
97 page get swap HPDF_Page_ShowText check-status ;