parse / render
parent
f847785c60
commit
ef57171447
@ -0,0 +1,22 @@
|
||||
#lang racket/base
|
||||
(require pitfall/struct pitfall/render)
|
||||
|
||||
(define (io1)
|
||||
(hasheq 'Pages "2 0 R" 'Type 'Catalog))
|
||||
|
||||
(define (io2)
|
||||
(hasheq 'Count 1 'Kids '("3 0 R") 'Type 'Pages 'MediaBox '(0 0 300 144)))
|
||||
|
||||
(define (io3)
|
||||
(hasheq 'Resources
|
||||
(hasheq 'Font
|
||||
(hasheq 'F1 (hasheq 'Subtype 'Type1 'BaseFont 'Times-Roman
|
||||
'Type 'Font)))
|
||||
'Parent "2 0 R"
|
||||
'Contents "4 0 R"
|
||||
'Type 'Page))
|
||||
|
||||
(define (io4)
|
||||
($stream (hasheq 'Length 55) #" BT\n /F1 18 Tf\n 0 0 Td\n (Hello World) Tj\n ET"))
|
||||
|
||||
(display (cosexpr->string (list io1 io2 io3 io4)))
|
@ -0,0 +1,46 @@
|
||||
#lang pitfall/parse
|
||||
%PDF-1.1
|
||||
%¥±ë
|
||||
|
||||
1 0 obj
|
||||
<< /Type /Catalog
|
||||
/Pages 2 0 R
|
||||
>>
|
||||
endobj
|
||||
|
||||
2 0 obj
|
||||
<< /Type /Pages
|
||||
/Kids [3 0 R]
|
||||
/Count 1
|
||||
/MediaBox [0 0 300 144]
|
||||
>>
|
||||
endobj
|
||||
|
||||
3 0 obj
|
||||
<< /Type /Page
|
||||
/Parent 2 0 R
|
||||
/Resources
|
||||
<< /Font
|
||||
<< /F1
|
||||
<< /Type /Font
|
||||
/Subtype /Type1
|
||||
/BaseFont /Times-Roman
|
||||
>>
|
||||
>>
|
||||
>>
|
||||
/Contents 4 0 R
|
||||
>>
|
||||
endobj
|
||||
|
||||
4 0 obj
|
||||
<< /Length 55 >>
|
||||
stream
|
||||
BT
|
||||
/F1 18 Tf
|
||||
0 0 Td
|
||||
(Hello World) Tj
|
||||
ET
|
||||
endstream
|
||||
endobj
|
||||
|
||||
%%EOF
|
@ -0,0 +1,58 @@
|
||||
%PDF-1.1
|
||||
%¥±ë
|
||||
|
||||
1 0 obj
|
||||
<< /Type /Catalog
|
||||
/Pages 2 0 R
|
||||
>>
|
||||
endobj
|
||||
|
||||
2 0 obj
|
||||
<< /Type /Pages
|
||||
/Kids [3 0 R]
|
||||
/Count 1
|
||||
/MediaBox [0 0 300 144]
|
||||
>>
|
||||
endobj
|
||||
|
||||
3 0 obj
|
||||
<< /Type /Page
|
||||
/Parent 2 0 R
|
||||
/Resources
|
||||
<< /Font
|
||||
<< /F1
|
||||
<< /Type /Font
|
||||
/Subtype /Type1
|
||||
/BaseFont /Times-Roman
|
||||
>>
|
||||
>>
|
||||
>>
|
||||
/Contents 4 0 R
|
||||
>>
|
||||
endobj
|
||||
|
||||
4 0 obj
|
||||
<< /Length 55 >>
|
||||
stream
|
||||
BT
|
||||
/F1 18 Tf
|
||||
0 0 Td
|
||||
(Hello World) Tj
|
||||
ET
|
||||
endstream
|
||||
endobj
|
||||
|
||||
xref
|
||||
0 5
|
||||
0000000000 65535 f
|
||||
0000000018 00000 n
|
||||
0000000077 00000 n
|
||||
0000000178 00000 n
|
||||
0000000457 00000 n
|
||||
trailer
|
||||
<< /Root 1 0 R
|
||||
/Size 5
|
||||
>>
|
||||
startxref
|
||||
565
|
||||
%%EOF
|
@ -1,14 +1,15 @@
|
||||
#lang brag
|
||||
|
||||
pf-program : pf-thing*
|
||||
@pf-thing : pf-null | CHAR | BOOLEAN | INT | REAL | pf-name | pf-string | pf-array | pf-dict | pf-stream | pf-indirect-object | pf-indirect-object-ref
|
||||
pf-program : pf-object*
|
||||
@pf-object : pf-null | CHAR | BOOLEAN | INT | REAL | pf-name | pf-string | pf-array | pf-dict | pf-stream | pf-indirect-object | pf-indirect-object-ref | pf-version
|
||||
@pf-null : NULL
|
||||
pf-name : NAME
|
||||
pf-string : STRING-TOK | /"<" HEX-DIGIT-PAIR+ /">"
|
||||
pf-array : /"[" pf-thing* /"]"
|
||||
pf-dict : /"<<" (pf-dict-key pf-dict-value)* /">>"
|
||||
@pf-dict-key : pf-thing
|
||||
@pf-dict-value : pf-thing
|
||||
pf-string : STRING-TOK | /"<" HEX-DIGIT-PAIR* /">"
|
||||
pf-array : /"[" pf-object* /"]"
|
||||
pf-dict : /"<" /"<" (pf-dict-key pf-dict-value)* /">" /">"
|
||||
@pf-dict-key : pf-object
|
||||
@pf-dict-value : pf-object
|
||||
pf-stream : pf-dict STREAM-DATA
|
||||
pf-indirect-object : INT INT /"obj" pf-thing /"endobj"
|
||||
pf-indirect-object-ref : INDIRECT-OBJECT-REF-TOK
|
||||
pf-indirect-object : INT INT /"obj" pf-object /"endobj"
|
||||
pf-indirect-object-ref : INDIRECT-OBJECT-REF-TOK
|
||||
pf-version : PDF-VERSION
|
@ -0,0 +1,22 @@
|
||||
#lang racket/base
|
||||
(require racket/string pitfall/struct)
|
||||
(provide (all-defined-out))
|
||||
|
||||
(define (cosexpr->string x)
|
||||
(define str
|
||||
(let loop ([x x])
|
||||
(cond
|
||||
[(list? x) (string-append "[" (string-join (map loop x) " ") "]")]
|
||||
[(procedure? x) (string-join (list (string-append (x #:name #t) " obj") (loop (x)) "endobj\n\n") "\n")]
|
||||
[(string? x) x]
|
||||
[(hash? x) (string-append
|
||||
"\n<< "
|
||||
(string-join
|
||||
(for/list ([(k v) (in-hash x)])
|
||||
(string-join (list (loop k) (loop v)) " ")) " ")
|
||||
" >> ")]
|
||||
[(symbol? x) (format "/~a" x)]
|
||||
[(number? x) (number->string x)]
|
||||
[($stream? x) (string-append (loop ($stream-dict x)) (string-join (list "\nstream" (format "~a" ($stream-data x)) "endstream") "\n"))]
|
||||
[else x])))
|
||||
(string-join (list "%%PDF1.1" str "%%EOF") "\n"))
|
@ -0,0 +1,3 @@
|
||||
#lang racket/base
|
||||
(provide (struct-out $stream))
|
||||
(struct $stream (dict data) #:transparent)
|
Loading…
Reference in New Issue