From 9195f4218c5e93a9fbc98dc1e98628a01ff49af7 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Sat, 22 Dec 2018 22:03:15 -0800 Subject: [PATCH] renaming --- pitfall/pitfall/document.rkt | 4 ++-- pitfall/pitfall/embedded.rkt | 4 ++-- pitfall/pitfall/font.rkt | 6 +++--- pitfall/pitfall/fonts.rkt | 2 +- pitfall/pitfall/images.rkt | 4 ++-- pitfall/pitfall/standard-font.rkt | 2 +- pitfall/pitfall/text.rkt | 30 +++++++++++++++--------------- pitfall/ptest/testrkt.rkt | 2 +- 8 files changed, 27 insertions(+), 27 deletions(-) diff --git a/pitfall/pitfall/document.rkt b/pitfall/pitfall/document.rkt index f234cac4..20c9c110 100644 --- a/pitfall/pitfall/document.rkt +++ b/pitfall/pitfall/document.rkt @@ -40,8 +40,8 @@ ;; initialize mixins (inherit-field @ctm) ; from vector mixin (inherit-field @font-families) (inherit font) ; from font mixin - (send this initText) - (send this initImages) + (send this init-text) + (send this init-images) ;; initialize params (current-compress-streams? (hash-ref @options 'compress #t)) diff --git a/pitfall/pitfall/embedded.rkt b/pitfall/pitfall/embedded.rkt index 6d0cf342..e5cf6705 100644 --- a/pitfall/pitfall/embedded.rkt +++ b/pitfall/pitfall/embedded.rkt @@ -54,7 +54,7 @@ https://github.com/mbutterick/pdfkit/blob/master/lib/font/embedded.coffee [@dictionary dictionary] [@document document]) - (define/override (widthOfString string size [features #f]) + (define/override (string-width string size [features #f]) ; #f disables features ; null enables default features ; list adds features (hash-ref! width-cache (list string size (and features (sort features symbolm void?) (set-field! _imageRegistry this (mhash)) (set-field! _imageCount this 0)) diff --git a/pitfall/pitfall/standard-font.rkt b/pitfall/pitfall/standard-font.rkt index a4e797cf..d890f8c7 100644 --- a/pitfall/pitfall/standard-font.rkt +++ b/pitfall/pitfall/standard-font.rkt @@ -48,7 +48,7 @@ (+glyph-position advance 0 0 0 (send font widthOfGlyph glyph)))) (list encoded positions)) - (define/override (widthOfString str size [options #f]) + (define/override (string-width str size [options #f]) (define glyphs (send font glyphsForString str)) (define advances (send font advancesForGlyphs glyphs)) (define width (apply + advances)) diff --git a/pitfall/pitfall/text.rkt b/pitfall/pitfall/text.rkt index bca25654..e8820ff9 100644 --- a/pitfall/pitfall/text.rkt +++ b/pitfall/pitfall/text.rkt @@ -26,17 +26,17 @@ https://github.com/mbutterick/pdfkit/blob/master/lib/mixins/text.coffee [_textOptions #f]) (as-methods - initText - _initOptions + init-text + init-options line-gap - moveDown - moveUp + move-down + move-up _text _fragment text - widthOfString))) + string-width))) -(define/contract (initText this) +(define/contract (init-text this) (->m void?) (set-field! x this 0) (set-field! y this 0) @@ -50,21 +50,21 @@ https://github.com/mbutterick/pdfkit/blob/master/lib/mixins/text.coffee this) -(define/contract (moveDown this [lines 1] #:factor [factor 1]) +(define/contract (move-down this [lines 1] #:factor [factor 1]) (() (number? #:factor number?) . ->*m . object?) (increment-field! y this (* factor (send this current-line-height #t) (+ lines (· this _line-gap)))) this) -(define/contract (moveUp this [lines 1]) +(define/contract (move-up this [lines 1]) (() (number?) . ->*m . object?) - (moveDown this #:factor -1)) + (move-down this #:factor -1)) (define/contract (_text this text x y options lineCallback) (string? (or/c number? #f) (or/c number? #f) hash? procedure? . ->m . object?) - (let* ([options (send this _initOptions options x y)] + (let* ([options (send this init-options options x y)] [text (format "~a" text)] ;; Convert text to a string ;; if the wordSpacing option is specified, remove multiple consecutive spaces [text (if (hash-ref options 'wordSpacing #f) @@ -86,14 +86,14 @@ https://github.com/mbutterick/pdfkit/blob/master/lib/mixins/text.coffee (send this _text text-string x y options (λ args (apply _line this args)))) -(define/contract (widthOfString this str [options (mhash)]) +(define/contract (string-width this str [options (mhash)]) ((string?) (hash?) . ->*m . number?) #;(report str 'measuring-width-of) - (+ (send (· this current-font) widthOfString str (· this current-font-size) (hash-ref options 'features #f)) + (+ (send (· this current-font) string-width str (· this current-font-size) (hash-ref options 'features #f)) (* (hash-ref options 'characterSpacing 0) (sub1 (string-length str))))) -(define/contract (_initOptions this [options (mhash)] [x #f] [y #f]) +(define/contract (init-options this [options (mhash)] [x #f] [y #f]) (() (hash? (or/c number? #f) (or/c number? #f)) . ->*m . hash?) ;; clone options object @@ -127,7 +127,7 @@ https://github.com/mbutterick/pdfkit/blob/master/lib/mixins/text.coffee ;; 180325 suppress the size tracking: we'll do our own line measurement ;; 181120 unsuppress the size tracking for now because it breaks test 04 (if (not wrapper) - (increment-field! x this (send this widthOfString text)) + (increment-field! x this (send this string-width text)) (increment-field! y (+ (send this current-line-height #t) line-gap))) (void)) @@ -144,7 +144,7 @@ https://github.com/mbutterick/pdfkit/blob/master/lib/mixins/text.coffee (define renderedWidth ;; wrap this in delay so it's only calculated if needed (delay - (+ (or (· options textWidth) (widthOfString this text options)) + (+ (or (· options textWidth) (string-width this text options)) (* wordSpacing (sub1 (or (· options wordCount) 0))) (* characterSpacing (sub1 (string-length text)))))) diff --git a/pitfall/ptest/testrkt.rkt b/pitfall/ptest/testrkt.rkt index c046886e..dc1be727 100644 --- a/pitfall/ptest/testrkt.rkt +++ b/pitfall/ptest/testrkt.rkt @@ -54,7 +54,7 @@ Mauris at ante tellus. Vestibulum a metus lectus. Praesent tempor purus a lacus # Draw some text wrapped to 412 points wide doc.text('And here is some wrapped text...', 100, 300) .font('Charter', 13) - .moveDown() # move down 1 line + .move-down() # move down 1 line .text(loremIpsum, width: 412, align: 'justify', indent: 30, paragraphGap: 5) # Add another page, and set the font back