! Copyright (C) 2010 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
-USING: assocs calendar combinators environment formatting
-grouping io io.files kernel make math math.ranges sequences
-splitting xml.entities ;
+USING: assocs calendar environment formatting grouping io.files
+kernel make math ranges sequences splitting xml.entities ;
IN: text-to-pdf
"/Author " "USER" os-env "unknown" or pdf-string append ,
"/Creator (created with Factor)" ,
">>" ,
- ] { } make "\n" join ;
+ ] { } make join-lines ;
: pdf-catalog ( -- str )
{
"/Type /Catalog"
"/Pages 4 0 R"
">>"
- } "\n" join ;
+ } join-lines ;
: pdf-font ( -- str )
{
"/Subtype /Type1"
"/BaseFont /Courier"
">>"
- } "\n" join ;
+ } join-lines ;
: pdf-pages ( n -- str )
[
"/Kids [ " "]" surround ,
] bi
">>" ,
- ] { } make "\n" join ;
+ ] { } make join-lines ;
: pdf-text ( lines -- str )
[
"12 TL" ,
[ pdf-string "'" append , ] each
"ET" ,
- ] { } make "\n" join pdf-stream ;
+ ] { } make join-lines pdf-stream ;
: pdf-page ( n -- page )
[
1 + "/Contents %d 0 R" sprintf ,
"/Resources << /Font << /F1 3 0 R >> >>" ,
">>" ,
- ] { } make "\n" join ;
+ ] { } make join-lines ;
: pdf-trailer ( objects -- str )
[
"startxref" ,
[ length 1 + ] map-sum 9 + "%d" sprintf ,
"%%EOF" ,
- ] { } make "\n" join ;
+ ] { } make join-lines ;
: string>lines ( str -- lines )
- "\t" split " " join lines
+ "\t" split " " join split-lines
[ [ " " ] when-empty ] map ;
: lines>pages ( lines -- pages )
dup length 5 swap 2 range boa zip
[ pdf-page , pdf-text , ] assoc-each
] { } make
- dup length [1,b] zip [ first2 pdf-object ] map ;
+ dup length [1..b] zip [ first2 pdf-object ] map ;
: objects>pdf ( objects -- str )
- [ "\n" join "\n" append "%PDF-1.4\n" ]
+ [ join-lines "\n" append "%PDF-1.4\n" ]
[ pdf-trailer ] bi surround ;
PRIVATE>