From 61e180b975296a736c33f39d79de3b5f740cd847 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Fri, 19 May 2017 10:52:01 -0700 Subject: [PATCH] compare lengths of pitfall to pdfkit --- pitfall/pitfall/pdftest.rkt | 16 ++++++++- pitfall/pitfall/standard-fonts.rkt | 34 +++++++++++-------- pitfall/pitfall/test/test0.pdf | Bin 693 -> 667 bytes pitfall/pitfall/test/test0.rkt | 3 +- pitfall/pitfall/test/test0c.rkt | 3 +- pitfall/pitfall/test/test1.pdf | 51 +++++++++++++++++++---------- pitfall/pitfall/test/test1.rkt | 3 +- pitfall/pitfall/test/test1c.rkt | 3 +- pitfall/pitfall/test/test2.rkt | 3 +- pitfall/pitfall/test/test2c.rkt | 3 +- pitfall/pitfall/test/test3.rkt | 3 +- pitfall/pitfall/test/test3c.rkt | 3 +- pitfall/pitfall/test/test4.rkt | 3 +- pitfall/pitfall/test/test4c.rkt | 3 +- pitfall/pitfall/test/test5.rkt | 3 +- pitfall/pitfall/test/test5c.rkt | 3 +- 16 files changed, 93 insertions(+), 44 deletions(-) diff --git a/pitfall/pitfall/pdftest.rkt b/pitfall/pitfall/pdftest.rkt index 1424f709..ac030689 100644 --- a/pitfall/pitfall/pdftest.rkt +++ b/pitfall/pitfall/pdftest.rkt @@ -1,5 +1,6 @@ #lang pitfall/racket (provide (all-from-out pitfall/racket)) +(provide check-copy-equal? check-pdfkit?) (test-mode #t) @@ -7,10 +8,23 @@ (define (this->control this) (path-add-extension this #"" #" copy.")) -(provide check-copy-equal?) +(define (this->pdfkit-control this) + (string->path (string-replace (path->string this) "rkt." "."))) + +(module+ test + (require rackunit) + (check-equal? (this->pdfkit-control (string->path "test1crkt.pdf")) (string->path "test1c.pdf"))) + + (define-syntax-rule (check-copy-equal? this) (check-equal? (file->bytes this) (file->bytes (this->control this)))) + +(define-syntax-rule (check-pdfkit? this) + (check-equal? (bytes-length (file->bytes this)) + (bytes-length (file->bytes (this->pdfkit-control this))))) + + (module reader syntax/module-reader #:language 'pitfall/pdftest #:read read diff --git a/pitfall/pitfall/standard-fonts.rkt b/pitfall/pitfall/standard-fonts.rkt index 18603d9f..f1e1db2d 100644 --- a/pitfall/pitfall/standard-fonts.rkt +++ b/pitfall/pitfall/standard-fonts.rkt @@ -1,24 +1,32 @@ #lang pitfall/racket -(require racket/runtime-path (for-syntax racket/base racket/path racket/syntax)) +(require racket/runtime-path (for-syntax racket/base racket/path racket/syntax sugar/debug)) (provide isStandardFont standard-fonts) + (define (isStandardFont name) (hash-ref standard-fonts name #f)) (define-syntax (define-afm-table stx) (syntax-case stx () - [(_ hashid dir) - (let* ([path-strings (for/list ([p (in-directory (syntax->datum #'dir) #t)] - #:when (and (file-exists? p) (path-has-extension? p #"afm") p)) - (path->string p))] - [id-strings (for/list ([pstr (in-list path-strings)]) - (path->string (cadr (explode-path (path-replace-extension pstr #"")))))]) - (with-syntax ([(PATH-STR ...) path-strings] - [(ID-STR ...) id-strings] - [(ID ...) (map (λ (id-str) (format-id #'hashid "~a" id-str)) id-strings)]) - #'(begin (define-runtime-path ID PATH-STR) ... - (define hashid (make-hash (list (cons ID-STR (procedure-rename (λ () (file->string ID)) 'ID)) ...))))))])) + [(_ HASH-ID FONT-ID ...) + (with-syntax ([(PATH-STR ...) (map (λ (stx) (format "data/~a.afm" (syntax->datum stx))) (syntax->list #'(FONT-ID ...)))]) + #'(begin (define-runtime-path FONT-ID PATH-STR) ... + (define HASH-ID (make-hash (list (cons (symbol->string 'FONT-ID) (procedure-rename (λ () (file->string FONT-ID)) 'FONT-ID)) ...)))))])) -(define-afm-table standard-fonts "data") +(define-afm-table standard-fonts + Courier-Bold + Courier-BoldOblique + Courier-Oblique + Courier + Helvetica-Bold + Helvetica-BoldOblique + Helvetica-Oblique + Helvetica + Symbol + Times-Bold + Times-BoldItalic + Times-Italic + Times-Roman + ZapfDingbats) (module+ test diff --git a/pitfall/pitfall/test/test0.pdf b/pitfall/pitfall/test/test0.pdf index 9cbba60e8d1cbf2bf45c4a409b6e8fbdff1a9dda..50affe87988f785b6bab45d0636dd1923fb3d13a 100644 GIT binary patch delta 151 zcmdnWI-7OEE*oP71BLvgEG`=xE`6WWy!4U`1w#uiJ3Fr8lA_eaTrNYPyn%u)h%&b{ zQb^9_;!4d+fk;l=6u@q2Xl`O=Vmz6Xv3&A9MpZ3KQw0MMP{>o@0y7K@j7`ii#0)LW bChIa;G8>tiOwMF-<}@|pQdM>JcjE#8>)<5t delta 161 zcmbQux|Mapu8IFV*ewh#Obt!UC;Kv%PuwN!Y-G%(@0OWUl3Jvo@0OETlIoJ0oS%}) zWoO4#TvC*pn9Ef$$2i1*!70{RAu%s=$%HwlSs7$KnPa$8^HLxxChuX?)iN?yFaQCC pJOwT=!@$7E+yX<)*urG8Fq7qE0VdwbkxZ7H<`!J4s;>TSTmb3eEVuvw diff --git a/pitfall/pitfall/test/test0.rkt b/pitfall/pitfall/test/test0.rkt index 8e24c70b..9dda3950 100644 --- a/pitfall/pitfall/test/test0.rkt +++ b/pitfall/pitfall/test/test0.rkt @@ -7,4 +7,5 @@ (send doc pipe (open-output-file this #:exists 'replace)) (send doc end))) -(check-copy-equal? this) \ No newline at end of file +(check-copy-equal? this) +(check-pdfkit? this) \ No newline at end of file diff --git a/pitfall/pitfall/test/test0c.rkt b/pitfall/pitfall/test/test0c.rkt index e2189098..42fcd4ae 100644 --- a/pitfall/pitfall/test/test0c.rkt +++ b/pitfall/pitfall/test/test0c.rkt @@ -7,4 +7,5 @@ (send doc pipe (open-output-file this #:exists 'replace)) (send doc end))) -(check-copy-equal? this) \ No newline at end of file +(check-copy-equal? this) +(check-pdfkit? this) \ No newline at end of file diff --git a/pitfall/pitfall/test/test1.pdf b/pitfall/pitfall/test/test1.pdf index f05b02e9..8496d23c 100644 --- a/pitfall/pitfall/test/test1.pdf +++ b/pitfall/pitfall/test/test1.pdf @@ -23,11 +23,38 @@ endobj >> >> endobj +3 0 obj +<< +/Length 294 +>> +stream +1 0 0 -1 0 792 cm +q +100 150 m +100 250 l +200 250 l +/DeviceRGB cs +1 0.2 0 scn +/Gs1 gs +f +230 200 m +230 172.385763 252.385763 150 280 150 c +307.614237 150 330 172.385763 330 200 c +330 227.614237 307.614237 250 280 250 c +252.385763 250 230 227.614237 230 200 c +h +/DeviceRGB cs +0.4 0 1 scn +/Gs1 gs +f + +endstream +endobj 7 0 obj << /Producer (PDFKit) /Creator (PDFKit) -/CreationDate (D:20170518183426Z) +/CreationDate (D:20170519175138Z) >> endobj 2 0 obj @@ -43,28 +70,16 @@ endobj /Kids [5 0 R] >> endobj -3 0 obj -<< -/Length 151 -/Filter /FlateDecode ->> -stream -x]] -0@Z - -@-@&C2 #Įp3}It`MNWnDpj$NPss&d%^.j*sS${i<>+|Yz71<ަ|caaE= -endstream -endobj xref 0 8 0000000000 65535 f -0000000399 00000 n -0000000350 00000 n -0000000456 00000 n +0000000744 00000 n +0000000695 00000 n +0000000258 00000 n 0000000163 00000 n 0000000059 00000 n 0000000015 00000 n -0000000258 00000 n +0000000603 00000 n trailer << /Size 8 @@ -72,5 +87,5 @@ trailer /Info 7 0 R >> startxref -679 +801 %%EOF diff --git a/pitfall/pitfall/test/test1.rkt b/pitfall/pitfall/test/test1.rkt index ee56a92d..484e0ea7 100644 --- a/pitfall/pitfall/test/test1.rkt +++ b/pitfall/pitfall/test/test1.rkt @@ -19,4 +19,5 @@ (send doc end))) -(check-copy-equal? this) \ No newline at end of file +(check-copy-equal? this) +(check-pdfkit? this) \ No newline at end of file diff --git a/pitfall/pitfall/test/test1c.rkt b/pitfall/pitfall/test/test1c.rkt index 0d809fc7..0ed8b757 100644 --- a/pitfall/pitfall/test/test1c.rkt +++ b/pitfall/pitfall/test/test1c.rkt @@ -19,4 +19,5 @@ (send doc end))) -(check-copy-equal? this) \ No newline at end of file +(check-copy-equal? this) +(check-pdfkit? this) \ No newline at end of file diff --git a/pitfall/pitfall/test/test2.rkt b/pitfall/pitfall/test/test2.rkt index 7325924c..cfd6c4d4 100644 --- a/pitfall/pitfall/test/test2.rkt +++ b/pitfall/pitfall/test/test2.rkt @@ -74,4 +74,5 @@ (send doc end))) -(check-copy-equal? this) \ No newline at end of file +(check-copy-equal? this) +(check-pdfkit? this) \ No newline at end of file diff --git a/pitfall/pitfall/test/test2c.rkt b/pitfall/pitfall/test/test2c.rkt index 61f7fab0..48656a70 100644 --- a/pitfall/pitfall/test/test2c.rkt +++ b/pitfall/pitfall/test/test2c.rkt @@ -74,4 +74,5 @@ (send doc end))) -(check-copy-equal? this) \ No newline at end of file +(check-copy-equal? this) +(check-pdfkit? this) \ No newline at end of file diff --git a/pitfall/pitfall/test/test3.rkt b/pitfall/pitfall/test/test3.rkt index 0391b3f5..ba72a7c3 100644 --- a/pitfall/pitfall/test/test3.rkt +++ b/pitfall/pitfall/test/test3.rkt @@ -7,4 +7,5 @@ (send doc text "Hello world") (send doc end))) -(check-copy-equal? this) \ No newline at end of file +(check-copy-equal? this) +(check-pdfkit? this) \ No newline at end of file diff --git a/pitfall/pitfall/test/test3c.rkt b/pitfall/pitfall/test/test3c.rkt index eb0c045a..1366d815 100644 --- a/pitfall/pitfall/test/test3c.rkt +++ b/pitfall/pitfall/test/test3c.rkt @@ -7,4 +7,5 @@ (send doc text "Hello world") (send doc end))) -(check-copy-equal? this) \ No newline at end of file +(check-copy-equal? this) +(check-pdfkit? this) \ No newline at end of file diff --git a/pitfall/pitfall/test/test4.rkt b/pitfall/pitfall/test/test4.rkt index ecf2d2e9..86952713 100644 --- a/pitfall/pitfall/test/test4.rkt +++ b/pitfall/pitfall/test/test4.rkt @@ -65,4 +65,5 @@ (send doc end))) -(check-copy-equal? this) \ No newline at end of file +(check-copy-equal? this) +(check-pdfkit? this) \ No newline at end of file diff --git a/pitfall/pitfall/test/test4c.rkt b/pitfall/pitfall/test/test4c.rkt index 7674f064..5267673e 100644 --- a/pitfall/pitfall/test/test4c.rkt +++ b/pitfall/pitfall/test/test4c.rkt @@ -65,4 +65,5 @@ (send doc end))) -(check-copy-equal? this) \ No newline at end of file +(check-copy-equal? this) +(check-pdfkit? this) \ No newline at end of file diff --git a/pitfall/pitfall/test/test5.rkt b/pitfall/pitfall/test/test5.rkt index a02c4fe4..803c8349 100644 --- a/pitfall/pitfall/test/test5.rkt +++ b/pitfall/pitfall/test/test5.rkt @@ -17,4 +17,5 @@ (send doc end))) -;(check-copy-equal? this) \ No newline at end of file +;(check-copy-equal? this) +;(check-pdfkit? this) \ No newline at end of file diff --git a/pitfall/pitfall/test/test5c.rkt b/pitfall/pitfall/test/test5c.rkt index 3428c4ad..4eb89ee4 100644 --- a/pitfall/pitfall/test/test5c.rkt +++ b/pitfall/pitfall/test/test5c.rkt @@ -17,4 +17,5 @@ (send doc end))) -;(check-copy-equal? this) \ No newline at end of file +;(check-copy-equal? this) +;(check-pdfkit? this) \ No newline at end of file