resume in images

main
Matthew Butterick 8 years ago
parent 70b121ce12
commit 56e63b5663

@ -1,9 +1,9 @@
#lang pitfall/racket
(require "reference.rkt" "object.rkt" "page.rkt")
(require "vector.rkt" "color.rkt" "fonts.rkt" "text.rkt")
(require "vector.rkt" "color.rkt" "fonts.rkt" "text.rkt" "images.rkt")
(provide PDFDocument)
(define mixed% (text-mixin (fonts-mixin (color-mixin (vector-mixin object%)))))
(define mixed% (image-mixin (text-mixin (fonts-mixin (color-mixin (vector-mixin object%))))))
(define PDFDocument
(class mixed% ; actually is an instance of readable.Stream, which is an input port
@ -42,7 +42,7 @@
(· this initVector)
(· this initFonts)
(· this initText)
#;(· this initImages) ; todo
(· this initImages)
(as-methods
addPage

@ -0,0 +1,27 @@
#lang pitfall/racket
(provide PDFImage)
(define PDFImage
(class object%
(super-new)
(as-methods
open)))
(define/contract (open this src label)
(any/c any/c . ->m . bytes?)
(define data (cond
[(isBuffer? src) src]
;;else if src instanceof ArrayBuffer
;;data = new Buffer(new Uint8Array(src))
[(regexp-match #rx"^data:.+;base64,(.*)$" src)
(void)] ;; base64 ; todo
[else (file->bytes src)]))
(cond
[(equal? (subbytes data 0 2) (bytes #xff #xd8))
'doJpeg]
[(equal? (subbytes data 0 4) (apply bytes (cons #x89 (map char->integer '(#\P #\N #\G)))))
'doPNG]
[else (raise-argument-error 'PDFImage-open "valid image format" src)]))

@ -0,0 +1,21 @@
#lang pitfall/racket
(require "image.rkt")
(provide image-mixin)
(define (image-mixin [% mixin-tester%])
(class %
(super-new)
#;(field [_opacityRegistry #f]
[_opacityCount #f]
[_gradCount #f]
[_fillColor #f])
(as-methods
)))
#;(define/contract (initColor this)
(->m void?)
(set-field! _opacityRegistry this (mhash))
(set-field! _opacityCount this 0)
(set-field! _gradCount this 0))
Loading…
Cancel
Save