From 8c1320a2d06589b21931ad3dfa0949114fee0437 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Fri, 21 Dec 2018 23:20:59 -0800 Subject: [PATCH] renaming --- pitfall/pitfall/annotations.rkt | 2 +- pitfall/pitfall/color.rkt | 58 ++++++++++++++++----------------- pitfall/pitfall/text.rkt | 4 +-- pitfall/pitfall/vector.rkt | 6 ++-- pitfall/ptest/test11.rkt | 2 +- pitfall/ptest/test2.rkt | 2 +- pitfall/ptest/testrkt.rkt | 2 +- 7 files changed, 37 insertions(+), 39 deletions(-) diff --git a/pitfall/pitfall/annotations.rkt b/pitfall/pitfall/annotations.rkt index 06406bf6..fc743d39 100644 --- a/pitfall/pitfall/annotations.rkt +++ b/pitfall/pitfall/annotations.rkt @@ -28,7 +28,7 @@ (unless (equal? (· options Subtype) "Link") (hash-ref! options 'C (λ () - (send this _normalizeColor (or (· options color) '(0 0 0)))))) + (send this normalize-color (or (· options color) '(0 0 0)))))) (hash-remove! options 'color) (when (string? (· options Dest)) (hash-update! options 'Dest String)) diff --git a/pitfall/pitfall/color.rkt b/pitfall/pitfall/color.rkt index 84228e27..9f2d4393 100644 --- a/pitfall/pitfall/color.rkt +++ b/pitfall/pitfall/color.rkt @@ -12,7 +12,7 @@ (provide color-mixin) -(define (_normalizeColor color) +(define (normalize-color color) ;; parses color string into list of values (let loop ([color color]) (cond @@ -44,57 +44,57 @@ (field [_opacityRegistry (mhash)] [_opacityCount 0] [_gradCount 0] - [_fillColor #f]) + [_fill-color #f]) - (define/public (_setColor color-in stroke) - (define color (_normalizeColor color-in)) + (define/public (set-color color-in stroke) + (define color (normalize-color color-in)) (define op (if stroke "SCN" "scn")) (cond [(not color)] #;[(is-a? color PDFGradient) - (_setColorSpace "Pattern" stroke) + (set-color-space "Pattern" stroke) (send color apply op) #t] ; todo [else (define color-space (case (length color) [(4) "DeviceCMYK"] [(3) "DeviceRGB"] - [else (raise-argument-error '_setColor "color of length 3 or 4" color)])) - (_setColorSpace color-space stroke) + [else (raise-argument-error 'set-color "color of length 3 or 4" color)])) + (set-color-space color-space stroke) ;; 181126 don't round, to be consistent with pdfkit behavior (send this addContent (format "~a ~a" (string-join (map (λ (num) (number num #:round #false)) color) " ") op)) #t])) - (define/public (_setColorSpace space stroke) + (define/public (set-color-space space stroke) (define op (if stroke "CS" "cs")) (send this addContent (format "/~a ~a" space op))) - (define/public (fillColor color [opacity 1]) - (unless (_normalizeColor color) - (raise-argument-error 'fillColor "valid color string" color)) - (when (_setColor color #f) (fillOpacity opacity)) + (define/public (fill-color color [opacity 1]) + (unless (normalize-color color) + (raise-argument-error 'fill-color "valid color string" color)) + (when (set-color color #f) (fill-opacity opacity)) ;; save this for text wrapper, which needs to reset ;; the fill color on new pages - (set! _fillColor (list color opacity)) + (set! _fill-color (list color opacity)) this) - (define/public (strokeColor color [opacity 1]) - (unless (_normalizeColor color) - (raise-argument-error 'strokeColor "valid color string" color)) - (when (_setColor color #t) (strokeOpacity opacity)) + (define/public (stroke-color color [opacity 1]) + (unless (normalize-color color) + (raise-argument-error 'stroke-color "valid color string" color)) + (when (set-color color #t) (stroke-opacity opacity)) this) - (define/public (fillOpacity opacity) - (_doOpacity opacity #f) + (define/public (fill-opacity opacity) + (do-opacity opacity #f) this) - (define/public (strokeOpacity opacity) - (_doOpacity #f opacity) + (define/public (stroke-opacity opacity) + (do-opacity #f opacity) this) - (define/public (_doOpacity [fill-arg #f] [stroke-arg #f]) + (define/public (do-opacity [fill-arg #f] [stroke-arg #f]) (define fill-opacity (and fill-arg (bounded 0 fill-arg 1))) (define stroke-opacity (and stroke-arg (bounded 0 stroke-arg 1))) (when (or fill-opacity stroke-opacity) @@ -264,14 +264,12 @@ "yellow" '(255 255 0) "yellowgreen" '(154 205 50))) - - (module+ test (require rackunit) (define c (new (color-mixin))) - (check-equal? (_normalizeColor "#6699Cc") '(0.4 0.6 0.8)) - (check-false (_normalizeColor "#88aaCCC")) - (check-equal? (_normalizeColor "#69C") '(0.4 0.6 0.8)) - (check-equal? (_normalizeColor "#69c") '(0.4 0.6 0.8)) - (check-false (_normalizeColor "#8aCC")) - (check-equal? (_normalizeColor "aqua") '(0 1 1))) \ No newline at end of file + (check-equal? (normalize-color "#6699Cc") '(0.4 0.6 0.8)) + (check-false (normalize-color "#88aaCCC")) + (check-equal? (normalize-color "#69C") '(0.4 0.6 0.8)) + (check-equal? (normalize-color "#69c") '(0.4 0.6 0.8)) + (check-false (normalize-color "#8aCC")) + (check-equal? (normalize-color "aqua") '(0 1 1))) \ No newline at end of file diff --git a/pitfall/pitfall/text.rkt b/pitfall/pitfall/text.rkt index 44b7f18d..73ae9561 100644 --- a/pitfall/pitfall/text.rkt +++ b/pitfall/pitfall/text.rkt @@ -157,8 +157,8 @@ https://github.com/mbutterick/pdfkit/blob/master/lib/mixins/text.coffee (when (or (· options underline) (· options strike)) (send this save) (unless (· options stroke) - (define fillColorArgs (· this _fillColor)) - (send this strokeColor . fillColorArgs)) + (define fill-colorArgs (· this _fill-color)) + (send this stroke-color . fill-colorArgs)) (define lineWidth (if (< (· this _fontSize) 10) 0.5 (floor (/ (· this _fontSize) 10)))) diff --git a/pitfall/pitfall/vector.rkt b/pitfall/pitfall/vector.rkt index 5eefb837..db6d9816 100644 --- a/pitfall/pitfall/vector.rkt +++ b/pitfall/pitfall/vector.rkt @@ -186,19 +186,19 @@ (define/contract (fill this [color #f] #:rule [rule #f]) (() ((or/c color-string? #f) #:rule (or/c string? #f)) . ->*m . object?) - (when color (send this fillColor color)) ;; fillColor method is from color mixin + (when color (send this fill-color color)) ;; fill-color method is from color mixin (send this addContent (format "f~a" (_windingRule rule)))) (define/contract (stroke this [color #f]) (() ((or/c color-string? #f)) . ->*m . object?) - (when color (send this strokeColor color)) + (when color (send this stroke-color color)) (send this addContent "S")) (define/contract (fillAndStroke this [fill #f] [stroke fill] #:rule [rule #f]) (() ((or/c color-string? #f) (or/c color-string? #f) #:rule (or/c string? #f)) . ->*m . object?) - (when fill (send* this [fillColor fill] [strokeColor stroke])) + (when fill (send* this [fill-color fill] [stroke-color stroke])) (send this addContent (format "B~a" (_windingRule rule)))) diff --git a/pitfall/ptest/test11.rkt b/pitfall/ptest/test11.rkt index 8d816899..fed03773 100644 --- a/pitfall/ptest/test11.rkt +++ b/pitfall/ptest/test11.rkt @@ -3,7 +3,7 @@ (define (proc doc) (send* doc - [fillColor "blue"] + [fill-color "blue"] [font "Helvetica" 30] [translate 50 50] [text "Here is a link!" 100 100 (hash diff --git a/pitfall/ptest/test2.rkt b/pitfall/ptest/test2.rkt index 7f1b478f..9e09e24f 100644 --- a/pitfall/ptest/test2.rkt +++ b/pitfall/ptest/test2.rkt @@ -34,7 +34,7 @@ [translate 400 0] [circle 100 50 50] [lineWidth 3] - [fillOpacity 0.8] + [fill-opacity 0.8] [fillAndStroke "red" "#900"] [restore]) diff --git a/pitfall/ptest/testrkt.rkt b/pitfall/ptest/testrkt.rkt index caea3a14..94d7c7db 100644 --- a/pitfall/ptest/testrkt.rkt +++ b/pitfall/ptest/testrkt.rkt @@ -84,7 +84,7 @@ for part in tiger # Add some text with annotations doc.add-page() - .fillColor("blue") + .fill-color("blue") .text('Here is a link!', 100, 100, { link: 'http://google.com/', underline: true }) doc.end() |# \ No newline at end of file