adjust ascii-box => unicode-box algorithm so that

it only looks left and right at hyphens and only
up and down at pipes, etc. This better handles the
case where you have something like this:

  +--------------+
  | (<= a-x b-y) |
  +--------------+

Before this commit, it would have adjusted the hypens
inside the identifiers
This commit is contained in:
Robby Findler 2012-12-24 13:49:32 -06:00
parent 7041ea1d80
commit 6a69da76e2
2 changed files with 43 additions and 9 deletions

View File

@ -1499,14 +1499,15 @@
(unless (hash-ref visited pos #f)
(hash-set! visited pos #t)
(define-values (x y) (pos->xy t pos))
(define c (send t get-character pos))
(define up (xy->pos t x (- y 1)))
(define dn (xy->pos t x (+ y 1)))
(define lt (xy->pos t (- x 1) y))
(define rt (xy->pos t (+ x 1) y))
(define i-up? (i? t up))
(define i-dn? (i? t dn))
(define i-lt? (i? t lt))
(define i-rt? (i? t rt))
(define i-up? (and (i? t up) (member c up-chars)))
(define i-dn? (and (i? t dn) (member c dn-chars)))
(define i-lt? (and (i? t lt) (member c lt-chars)))
(define i-rt? (and (i? t rt) (member c rt-chars)))
(cond
[(and i-up? i-dn? i-lt? i-rt?) (set t pos "")]
[(and i-dn? i-lt? i-rt?) (set t pos "")]
@ -1539,12 +1540,37 @@
(define start (send text paragraph-start-position para))
(values (- pos start) para))
(define adjustable-chars
(define up-chars
'(#\╬
#\╩ #\╦ #\╣ #\╠
#\╝ #\╗ #\╔ #\╚
#\═ #\║
#\+ #\- #\|))
#\╩ #\╣ #\╠
#\╝ #\╚
#\║
#\+ #\|))
(define dn-chars
'(#\╬
#\╦ #\╣ #\╠
#\╗ #\╔
#\║
#\+ #\|))
(define lt-chars
'(#\╬
#\╩ #\╦ #\╣
#\╝ #\╗
#\═
#\+ #\-))
(define rt-chars
'(#\╬
#\╩ #\╦ #\╠
#\╔ #\╚
#\═
#\+ #\-))
(define adjustable-chars
(remove-duplicates
(append up-chars dn-chars lt-chars rt-chars)))
(define (xy->pos text x y)

View File

@ -290,6 +290,14 @@
(string-append "╔═╗\n"
"║ ║\n"
"╚═╝\n"))
(ascii-art-box-spec (string-append "+---+\n"
"| - |\n"
"|+ ||\n"
"+---+\n")
(string-append "╔═══╗\n"
"║ - ║\n"
"║+ |║\n"
"╚═══╝\n"))
(ascii-art-box-spec (string-append "+-+-+\n"
"| | |\n"
"+-+-+\n"