Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!munnari.oz.au!uniwa!fennel.cc.uwa.oz.au!a_dent From: a_dent@fennel.cc.uwa.oz.au Newsgroups: comp.sys.mac.programmer Subject: Re: Text Spacing on Laser & Fractional Font Sizes? Message-ID: <1990Nov21.234954.2636@fennel.cc.uwa.oz.au> Date: 21 Nov 90 15:49:53 GMT References: <1990Oct28.235805.2481@fennel.cc.uwa.oz.au> <1990Oct30.054006.22697@agate.berkeley.edu> Organization: University of Western Australia Lines: 94 In article <1990Oct30.054006.22697@agate.berkeley.edu>, lippin@wish-bone.berkeley.edu (The Apathist) writes: > > Rather than using SpaceExtra to do full justification, I suggest using > DrawJust, or its younger sibling, NDrawJust. Both take a slop > parameter that controls just how much to stretch the line. NDrawJust > also takes scaling parameters (like StdText does) which will help you > achieve fractional font sizes. > > The only catch lies in finding the documentation for these routines -- > they're not listed in IM. DrawJust is described in the Script Manager > 2.0 interim chapter of IM (strangely, this isn't part of IM VI). But it IS part of IM vol FIVE!!!!! (although I didn't get any better results than the methods I've been using). On a different but related note, I ran into an interesting problem with fully justified text being copied to the clipboard. Although properly justified when looked at with Clipboard Magician (GREAT tool) the text failed to justify when pasted into MacDraw II. MacDraw II has a definition of "justification" which doesn't allow single lines to be "spread" out to the length of the text box - it only justifies multiple line objects. In case anyone else is wondering how to get around a similar problem, I finally solved it by sending each word as a separate text object, the last one being Right justified. The definition of the Text record and some sample code are shown below, the main point being the use of the (IM vol 5 Script Manager) call Char2Pixel to get the start of the words. type laserJust = (leftJust, centreJust, rightJust, fullJust); someJustText = record pos: ptr; len, x, y, width, numSpaces, pointsShort: integer; { NOTE numSpaces & pointsShort only used if we're going to Fully justify field } just: laserJust; moveUpALine: boolean; end; {**** sample code for drawing fully justified text so it works with MacDraw II ***} { text is an array of someJustText, the locations "x" & "y" being calculated } { in a parsing stage earlier. "Pos" points to the text & the "just" and } { "moveUpALine" fields aren't used in this procedure. } textStyle.setStyle; i := 1; while (i < textLines) & (text[i + 1].len > 0) do with text[i] do begin lastCharInLineOffset := len - 1; charOffsetInLine := 0; startOfWord := 0; lengthOfWord := 1; charDrawingOffset := Char2Pixel(pos, len, pointsShort, charOffsetInLine, smHilite); charPtr := Plus1P(pos); charOffsetInLine := 1; while charOffsetInLine < lastCharInLineOffset do begin { remember offset's 0-based, start at 2nd char } { if get a space then end of a word so draw the word } if charAt(charPtr) = space then begin charX := x + charDrawingOffset; MoveTo(charX, y); DrawText(pos, startOfWord, lengthOfWord); repeat { skip one or more spaces after word } incI(charOffsetInLine); incP(charPtr); until (charAt(charPtr) <> space) | (charOffsetInLine = lastCharInLineOffset); { now set the start of the next word - what char it starts at and where on screen } charDrawingOffset := Char2Pixel(pos, len, pointsShort, charOffsetInLine, smHilite); startOfWord := charOffsetInLine; lengthOfWord := 1; end else begin { just a normal character } incI(lengthOfWord); incI(charOffsetInLine); incP(charPtr); end; end; { loop through single line } { last word is Right aligned except on last line } PicComment(TextBegin, rightJustPicCommentSize, handle(rightJustPicCommentHandle)); charX := x + charDrawingOffset; MoveTo(charX, y); DrawText(pos, startOfWord, lengthOfWord); PicComment(TextEnd, 0, nil); incI(i); end; { loop through lines } with text[i] do begin MoveTo(x, y); DrawText(pos, 0, len); end; end; { some lines to process } Andy Dent A.D. Software phone 09 249 2719 Mac & VAX programmer 94 Bermuda Dve, Ballajura a_dent@fennel.cc.uwa.oz Western Australia 6066 a_dent@fennel.cc.uwa.oz.AU (international)