From J Wiki
Jump to navigation Jump to search

Addon: format/sbox - Displaying boxed nouns containing Unicode glyphs


Has anyone else felt the need to display a boxed noun which contains Unicode glyphs? Such as:

   < u: 9017 32 9054


   a=: 'dom⌹'
   b=: 'qqd⍞ & domino⌹'
   c=: (2 3) ; a ; b
   d=: '⍞and⌹' ; c ; 99

You'll know that the box structure breaks up, because J wants to treat '⌹' as 3 letters, whereas it only takes up one glyph on the screen.

Check out my new (beta) Addon: format/sbox, which lets you input (say):

  sbox < u: 9017 32 9054
│⌹ ⍞│

to see a corrected display, instead of:

     < u: 9017 32 9054
│⌹ ⍞│

Proviso: font needs to be consistently fixed-width

You must of course set your session font to a "genuinely" fixed-width font, which actually has the same-width glyphs for all the code points you want to use. (So few of them do!) Otherwise of course the whole idea is a total lost cause, whatever you do.

Here, for instance, are the planetary glyphs:

│Sun    │☼│
│Moon   │☽│
│Venus  │♀│
│Mars   │♂│
│Saturn │♄│
│Uranus │♅│
│Pluto  │♇│

The right-hand edge actually lines up in font: "Menlo", but in no other "fixed-width" font I've tried. This is because the planet signs themselves vary in width.

Here are two screen shots...

Ss1.png Spacer.png Ss2.png

My demos use mixed ASCII and APL chars, plus a little French, so they work best with "APL385 Unicode". You can try "Courier" and "Courier New" too. JGTK seems to set the session font to "Andale Mono" -- which in JGTK on the Mac collapses the APL glyphs. (Although "Andale Mono" works just fine in j602... curious!)

So it won't look good until you set the Session Font to one of those mentioned, by using: Menu: Edit > Session Font ...

None of the "fixed width" fonts I've tried work with Chinese glyphs: they are all wider than the "fixed width" of the ASCII glyphs -- or more significantly, the box-drawing characters.

Bill Lam suggests [1] that Chinese (CJK) glyphs are usually twice the width of Roman, which makes it easy to box them using the standard linedraw glyphs. But of the fonts I've tried (those above, plus "MS Mincho" and "PCMyungjo") only for the last two is that true. With the traditional Western fonts the width ratio of CJK glyphs to Latin is 3:5 -- and that can only be relied upon for a point size of a power of 2 (try: 128).

   sbox <e
│12345678901234567890│ --showing 20 Latin glyphs aligning with 12 CJK glyphs

Installing and testing the Addon: sbox

Use Package Manager to download the Addon: format/sbox. Then restart J and run the test script:

   load 'format/sbox/test'

which shows you an assortment of nouns, first uncorrected, then corrected. Thus...

│TABLE Français Arménien Hébreu Thâna│

followed by the same series of nouns shown using sbox ...

│TABLE   │
│Hébreu  │
│Thâna   │

In operational use:

   require 'format/sbox'

creates a verb: sbox in the z-locale (plus its own private work-locale: 'sbox'). Then you can run:

  sbox < u: 9017 32 9054
│⌹ ⍞│

Lab: Displaying boxed nouns containing Unicode glyphs

A Lab gets installed with the Addon:

  • Category: Format
  • Lab: Displaying boxed nouns containing Unicode glyphs

Or, if you don't want to fuss about with the dialog boxes, run it directly by:

   require '~system/extras/util/lab.ijs'
   0 labinit_jlab_ jpath '~addons/format/sbox/sbox.ijt'

Send me any nouns which sbox fails to correct. Also any missing words which my J predefines, but yours doesn't. If you get a corrupted display, check the font isn't making glyphs disappear, or writing them out with the wrong width, because I can't do anything about that.

-- Ian Clark <<DateTime(2012-10-16T01:23:47Z)>>