This approach won't work with different width characters(such as in Korean)
in unicode. (Some characters are wide -- taking two-character space, others
narrow -- taking one-character space)


On Wed, Apr 30, 2014 at 6:24 AM, Don Guinn <[email protected]> wrote:

> This has bugged me for quite a while too. I tried making sure all text was
> unicode. Didn't help. The text was converted to U8 before determining the
> size of the boxes, still messing up the alignment.
>
>
> This thread prompted me to think about the problem again. Instead of trying
> to build the entire logic to box I thought of a different approach. Convert
> the text to display boxed to literal without any U8 characters. Any
> character will do. I chose 'x'. Then the boxing works just fine. Format the
> boxed 'x's into a literal array. Then take the data from the original, make
> sure it is all unicode and replace the 'x's with this data. A little work
> was needed to reorder the data for ranks greater than 1.
>
>
> This gave me a chance to study L: and S: as they simplified doing this. It
> seems to work for fixed-width fonts. Variable width fonts still mess up
> alignment.
>
>
>    box=:3 : 0
>
> to_uni=.(7 u:"1":)`]@.(131072=3!:0)
>
> try. ts=.;(<@,)S:0 t=.to_uni L:0 y catch. ts=.0 end.
>
> if. +./131072 32~:(3!:0)&>ts;<y do. y return. end.
>
> ts=.' '(I.ts e. TAB,CR,LF)}ts
>
> inc=.(3 : 'u:box_n=:>:box_n')"0
>
> i=.I.'x'=,tx=.":('x'"0)L:0 t
>
> box_n=:n1=.a.i.'@'
>
> i=.i/:n1(<#]),3 u: 7 u:"1":(inc)L:0 t
>
> ($tx)$ts i},tx
>
> )
>
>
>
>    tst=:(2 3$7 u:'ABCDΣF');i.3 4 5
>
>
>
>    box tst
>
> ┌───┬──────────────┐
>
> │ABC│ 0  1  2  3  4│
>
> │DΣF│ 5  6  7  8  9│
>
> │   │10 11 12 13 14│
>
> │   │15 16 17 18 19│
>
> │   │              │
>
> │   │20 21 22 23 24│
>
> │   │25 26 27 28 29│
>
> │   │30 31 32 33 34│
>
> │   │35 36 37 38 39│
>
> │   │              │
>
> │   │40 41 42 43 44│
>
> │   │45 46 47 48 49│
>
> │   │50 51 52 53 54│
>
> │   │55 56 57 58 59│
>
> └───┴──────────────┘
>
>
>
> The alignment in your browser may not be perfect, but it looked good in my
> ijx session.
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to