Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Re: Proportional-spaced fonts with accent marks

From: carl::cybercraft::co::nz at: 5-May-2002 22:10

Hi Louis, On 05-May-02, Dr. Louis A. Turk wrote:
> Hi rebols, > I am working to create an interlinear Greek-English book from a > Greek book. I plan to use 3 scripts to do this. The first script > simply puts a duplicate paragraph under each paragraph in the book. > The second script searches through the resulting file for each Greek > word and does 2 things: (1) in the bottom line, it replaces that > Greek word with the appropriate English word, and (2) adjusts the > spacing of the top line (if necessary) so that the top Greek words > stay over the proper English word. The third script will break the > top and bottom lines in the proper places, and (if I can figure out > how to do it) justify the lines while keeping the Greek and English > words properly aligned. > The first script is trivial provided rebol can process fonts with > accent marks. Can it?
Some with accent marks yes, though whether they cover the full Greek alphabet I wouldn't know. Anyway, the following prints out each character of your default font from the space character to character 255... for n 32 255 1 [prin to-char n]
> The third script I will worry about later. > The second script would be rather simple if I could use fixed-space > Greek letters without accent marks, but I at least need the accent > marks. This is why I have been interested in Unicode, but, Rebol > doesn't yet support Unicode, and I am needing to get on with the > project. Also, I am beginning to think unicode isn't the answer > anyway. Perhaps I just need to learn a little more about fonts so > that I can use the proportional-spaced Greek font with accent marks > that the Greek book file was created with. This would make the > finished interlinear much more compact and nicer looking. > The problem is how to line up the words when the letters vary in > width and sometimes are an extra byte long because of the accent > information.
Is this for printing out or for displaying on screen? If for printing out you could perhaps have a tab for every word in each matched line and line them up that way, though as I almost never send stuff to a printer these days others will have to tell you how to do this, if it's feasable. As to on screen, there's a 'size-text word in View that returns the size of text in a face. Using that on each word in your text for lining them up is one posible way to do it. Here's an example... rebol [] line1: ["Let's" "see" "if" "we" "can" "line" "up" "words..."] line2: [] foreach word line1 [ new-word: copy "" foreach letter word [ append new-word to-char to-integer letter + 128 ] if 3 > random 4 [append new-word "x"] append line2 new-word ] line-tabs: [0] for n 1 8 1 [ layout [origin 1x1 word1: text line1/:n font [size: 16]] layout [origin 1x1 word2: text line2/:n font [size: 18]] word-w: max first size-text word1 first size-text word2 append line-tabs 6 + word-w + last line-tabs ] view layout [ origin 0x0 space 0x0 tabs line-tabs across style tex text font [size: 16] tex line1/1 tab tex line1/2 tab tex line1/3 tab tex line1/4 tab tex line1/5 tab tex line1/6 tab tex line1/7 tab tex line1/8 return style tex text font [size: 18] tex line2/1 tab tex line2/2 tab tex line2/3 tab tex line2/4 tab tex line2/5 tab tex line2/6 tab tex line2/7 tab tex line2/8 ] That creates two blocks of words, with the second one being the words converted to the Randomalians language. (: They're then compared for length to get the longest of each matching pair and these values are then used as tabs in the layout. They line them up for me - I hope you get the same results! (Was quite fun working this out:) My biggest worry with this approach is you'll be making an awful lot of faces, (one per word in your book), just to get their length. However, if this is for on-screen display you'll only have to do it once as you'll be able to store the tab spacing along with the paragraphs to your book. I hope this is of some help. It sounds an interesting project.
> Can someone tell me how to do this, or point me to a book or article > somewhere that explains it? Is it extremely difficult? > Is rebol suitable for this project? If not, what language would be > best? I can program in C if I have to, but programming in C is so > slow for me, and I haven't used C for a long time. I would really > prefer to use rebol. > Are there any not-so-obvious problems any of you see that I might > encounter while doing this project?
PS: Just seen your second post mentioning it is to be printed out. (: But anyway, lining up tabs like I've done in View may be the way to go for printing it out too. But someone else will have to tell you how to get the widths of the words for printing them - unless multiplying the tabs by a constant value would be accurate enough to convert their pixel-width to the printer tabs... -- Carl Read