I don't know just how you put boxes around text, but I got the boxes to
fit right by making sure that the text was all wchar before putting the
boxing characters around the text. I think that you must convert it to
U8 before putting the box around it, messing up the character count.
Doing this is not the general approach that you have talked about of
determining the character widths etc., but it might do in the interium.
This is a simple test script which shows what I mean.
NB. Works for little endian only. Used this for trying things.
surround=:3 : 0
'ul tb ur s ll lr'=.0 10 2 9 6 8{9!:6''
if. -.131072 2 e.3!:0 y do. y=.":y end.
'h w'=._2{.1,$y
if. 2=3!:0 y do. y=.6 u:,y,"0]0{a. end. NB. Make wchars.
y=.(h,w)$,y
(ul,(w#tb),ur),(s,"1 y,"1 s),(ll,(w#tb),lr)
)
r=.(6 u: 17 34{a.),' is a Sigma '
surround r
┌───────────────┐
│∑ is a Sigma │
└───────────────┘
< r
┌─────────────────┐
│∑ is a Sigma │
└─────────────────┘
The second box may not look right on your browser but it will look right
if you run it in J. And the text displayed was already wchar.
It may be that the boxing characters may need to be stored as wchars
which right now is an error.
Incidently, the types for 3!:0 in the Dictionary is incorrect for type
131072 which says it is unicode when it is really wchar. But then, I
guess wchar might be considered to be a subset of unicode. And there's
no type for U8. It always shows up as literal.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm