]> gitweb.factorcode.org Git - factor.git/blob - unmaintained/pdf/pdf.factor
tools.test: Make the flag public. Finish porting tester changes to fuzzer.
[factor.git] / unmaintained / pdf / pdf.factor
1 ! Copyright (C) 2007 Elie CHAFTARI
2 ! See http://factorcode.org/license.txt for BSD license.
3 !
4 ! Tested with libharu2 2.0.8 on Mac OS X 10.4.9 PowerPC
5
6 USING: assocs continuations hashtables kernel math namespaces pdf.libhpdf ;
7
8 IN: pdf
9
10 SYMBOL: pdf
11 SYMBOL: page
12
13 ! =========================================================
14 ! Error handling routines
15 ! =========================================================
16
17 : check-status ( status -- )
18     dup zero? [ 
19         drop
20     ] [
21         error-code >hashtable at throw   
22     ] if ;
23
24 ! =========================================================
25 ! Document handling routines
26 ! =========================================================
27
28 : new-pdf ( error-handler user-data -- )
29     HPDF_New pdf set ;
30
31 : free-pdf ( -- )
32     pdf get HPDF_Free drop ;
33
34 : with-pdf ( quot -- )
35     [ f f new-pdf [ free-pdf ] [ ] cleanup ] with-scope ; inline
36
37 : set-compression-mode ( mode -- )
38     pdf get swap HPDF_SetCompressionMode check-status ;
39
40 : set-page-mode ( mode -- )
41     pdf get swap HPDF_SetPageMode check-status ;
42
43 : add-page ( -- )
44     pdf get HPDF_AddPage page set ;
45
46 : save-to-file ( filename -- )
47     pdf get swap HPDF_SaveToFile check-status ;
48
49 : get-font ( fontname encoding -- font )
50     pdf get -rot HPDF_GetFont ;
51
52 ! =========================================================
53 ! Page Handling routines
54 ! =========================================================
55
56 : get-page-height ( -- height )
57     page get HPDF_Page_GetHeight ;
58
59 : get-page-width ( -- width )
60     page get HPDF_Page_GetWidth ;
61
62 : page-text-width ( text -- width )
63     page get swap HPDF_Page_TextWidth ;
64
65 ! =========================================================
66 ! Graphics routines
67 ! =========================================================
68
69 : set-page-line-width ( linewidth -- )
70     page get swap HPDF_Page_SetLineWidth check-status ;
71
72 : page-rectangle ( x y width height -- )
73     >r >r >r >r page get r> r> r> r> HPDF_Page_Rectangle check-status ;
74
75 : page-stroke ( -- )
76     page get HPDF_Page_Stroke check-status ;
77
78 : set-page-font-and-size ( font size -- )
79     page get -rot HPDF_Page_SetFontAndSize check-status ;
80
81 : page-begin-text ( -- )
82     page get HPDF_Page_BeginText check-status ;
83
84 : page-text-out ( xpos ypos text -- )
85     page get -roll HPDF_Page_TextOut check-status ;
86
87 : page-end-text ( -- )
88     page get HPDF_Page_EndText check-status ;
89
90 : with-text ( -- )
91     [ page-begin-text [ page-end-text ] [ ] cleanup ] with-scope ; inline
92
93 : page-move-text-pos ( x y -- )
94     page get -rot HPDF_Page_MoveTextPos check-status ;
95
96 : page-show-text ( text -- )
97     page get swap HPDF_Page_ShowText check-status ;