"Typesetting" functions
Dave Calkins 1
davecs1 at verizon.net
Sat Dec 24 03:07:29 EST 2005
Sorry for the late post, I'm trying to catch up. I noticed that no-one
posted an actual solution so here is mine.
Don't hold your breath on getting these functions added to RR. I have
been asking for this type of improvement to add simple text handling
routines since RR 1.1 which would allow the generation of more text
processing / reports applications.
This is a routine that I use to generate a tabstop that will center a
short line or title for each line that contains a char of my choosing
in a card field called "Other Data".
Sorry I haven't completely commented it.
Merry Christmas
on doTabCenter --Align Center Command (Centers a short line or title on
the field)
put the lockscreen into tLockScreen
lock screen
put empty into fld "Other Data"
put the tabstops of cd fld "Other Data" into tTabStops
repeat while cd fld "Other Data" contains "»" -- This is the char I
chose to indicate which lines to center
put the cTabCenterLine of cd fld "Other Data" into tTabCenterLine
--Tab location to center line / self generates
put the cTabCenterLineText of cd fld "Other Data" into
tTabCenterLineText --Tab location to center line / self generates
put the item 1 of the loc of cd fld "Other Data" into tCenterTab
put lineoffset ("»",cd fld "Other Data") into tLn
put line tLn of cd fld "Other Data" into tLine
put the HTMLtext of line tLn of cd fld "Other Data" into tmpLine
put tmpLine into line tLn of tTabCenterLineText
replace "	" with empty in tmpLine
replace " " with empty in tmpLine
set the htmltext of line tLn of cd fld "Other Data" to tmpLine
delete char offset ("»",line tLn of cd fld "Other Data") of line
tLn of cd fld "Other Data"
put line tLn of cd fld "Other Data"into tText
put the formattedWidth of line tLn of cd fld "Other Data" into
tWidthOfTitle
select word 1 of line tLn of cd fld "Other Data"
put item 2 of the selectedLoc into tLocWordA
put space & "»" after line tLn of cd fld "Other Data"
repeat
put offset (tText, line tLn of cd fld "Other Data") into tLocChar2
put " " before char tLocChar2 of line tLn of cd fld "Other Data"
put offset ("»", line tLn of cd fld "Other Data") into tLocChar3
select char (tLocChar3) of line tLn of cd fld "Other Data"
put item 2 of the selectedLoc into tLocWordB
if tLocWordA <> tLocWordB then exit repeat
end repeat
delete char (tLocChar3) of line tLn of cd fld "Other Data"
subtract 1 from tLocChar3
put the formattedWidth of char 1 to (tLocChar3) of line tLn of cd
fld "Other Data" into tWidthOfLine
put number of chars of line tLn of cd fld "Other Data" into
tLocChar3
delete char (tLocChar3) of line tLn of cd fld "Other Data"
delete char 1 to ( offset (tText,line tLn of cd fld "Other Data" )
- 1) of line tLn of cd fld "Other Data"
put round (tWidthOfLine / 2) into tCenterTab1
put round (tWidthOfTitle / 2) into tTabWidth1
subtract tTabWidth1 from tCenterTab1
put tCenterTab1 into line tLn of tTabCenterLine
end repeat
repeat for each line tCenterLine in tTabCenterLine
if tCenterLine is empty then next repeat
put true into tAddStop
repeat with i = 1 to number of items of tTabStops -- i for each
item tItem in tTabStops
if item i of tTabStops = tCenterTab1 then
put false into tAddStop
exit repeat
end if
end repeat
if tAddStop then
if tTabStops is empty then put tCenterTab1 after tTabStops
else put "," & tCenterTab1 after tTabStops
end if
sort items of tTabStops ascending numeric
end repeat
set the cTabCenterLine of cd fld "Other Data" to tTabCenterLine --Tab
location to center line
set the cTabCenterLineText of cd fld "Other Data" to
tTabCenterLineText
set the tabstops of cd fld "Other Data" to tTabStops
repeat for each line tCenterTabLoc in tTabCenterLine
put lineoffset ("»",tTabCenterLineText) into tLn
if tLn = 0 then exit repeat
put line tLn of tTabCenterLine into tCenterTabLoc
put empty into line tLn of tTabCenterLineText
if tCenterTabLoc is empty then next repeat
repeat with i = 1 to number of items of tTabStops
put tab before line tLn of cd fld "Other Data"
--put the formattedWidth char 1 to ( offset (tText,line tLn of cd
fld "Other Data" ) - 1) of line tLn of cd fld "Other Data" into
tTextCenterAlign
if item i of tTabStops >= tCenterTabLoc then exit repeat
end repeat
end repeat
set the lockscreen to tLockScreen
end doTabCenter
I also have a routine that will indent a wrapped line into an indented
paragraph similar to the "increase indent" that I could post if you are
interested.
Dave Calkins
On Dec 16, 2005, at 2:26 AM, use-revolution-request at lists.runrev.com
wrote:
> From: Sivakatirswami <katir at hindu.org>
> Subject: "Typesetting" functions
> To: use-revolution at lists.runrev.com
> Message-ID: <FA40421A-B673-4B13-A1CE-8BAE1ADF0257 at hindu.org>
> Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed
>
> As one who is spoiled by options for very precise control over type
> all these years (Quark and now InDesign) the challenges of making
> text look good in a Revolution field seem daunting.
>
> I was wondering if any one had "rolled their own" typesetting
> functions. I would rather not have to create multiple flds and then
> group these with some being centered and others align left... so I
> was thinking that one could, for example, center type but getting
> some measurement of the len(the selection) and then inserting
> something like
>
> (an algorithm that needs real code:)
>
> the total length of the line -(the length of type to be centered)/2 =
> (some number of spaces to insert in front of the text)
>
> I may be dreaming about cheddar on Mars, because I don't see from the
> docs any syntax that can provide a"real" correlation between len
> (fooString) and pixelwidth(fooString) that can be translated back
> into a tab width or number of spaces...as the pixel width of
> fooString will vary by the charWidths of the chars in the string and
> again, this has no correlation to the width of a space... and tabs
> are out anyway, since you cannot set tabs on a per line basis. (I
> hope this is on the feature list as a bare minimum upgrade to text
> handling in the next version of rev) etc. etc. round in circles.
>
> a typical thing one would like to be able to do, besides centering
> type on a line in a field... would be formatting like this:
>
> someTextLeftAligned [tab or string of spaces] SomeTextRightAligned
>
> I'm hoping some of you may have already "been there done that and yes
> it can be done... here's how"
>
> My actual context is rolling credits in a single field with centered
> headers for each section followed by
>
> Correspondents
>
> staff country
>
> Photographers:
>
> photographer country
>
> etc.
>
> now I can center all this and it looks fairly decent if you give up
> aspirations for any more control and think "well the do it like that
> in the movies and if you don't care about things lining up its just
> fine..." But this may not fly when it goes up for review... or I
> will have to say "sorry, this is all we get in Rev. we have to live
> with it like this for now...
>
> TIA
>
> Sivakatirswami
>
Dave Calkins
More information about the use-livecode
mailing list