home *** CD-ROM | disk | FTP | other *** search
Wrap
/* This Genie will fit text into a box or chain of boxes, keeping the proportions of differing sizes of text in a box. All the text in a box or linked chain will be changed. No new boxes are created, unlike AutoImport. The text must be already in the box before running the genie. Note that any style tags applying to the text will be cancelled. The limiting factor for accurate fitting is the 1/8 point step in the available font sizes. I have set the genie to underflow rather than overflow. Written by Don Cox July 92 Revised July 93 Not Public Domain. All rights reserved. */ trace n signal on error signal on syntax address command call SafeEndEdit.rexx() call ppm_AutoUpdate(0) cr="0a"x cpage = ppm_CurrentPage() counter=0 do forever box=ppm_ClickOnBox("Click on boxes to be fitted") if box=0 then break counter=counter+1 boxes.counter=box call ppm_SelectBox(box) end if counter=0 then exit_msg("No boxes selected") currentunits=ppm_GetUnits() call ppm_SetUnits(2) call ppm_ShowStatus(" Fitting text...") do i=1 to counter box=boxes.i boxtype = upper(word(ppm_GetBoxInfo(box), 1)) if boxtype~="TEXT" then iterate box = ppm_ArtFirstBox(box) text = ppm_GetArticleText(box,1) iter = 1 factor = 0.5 /* first find max size quickly */ do 9 /* 9 is enough doublings */ factor2 = factor /* format number for display */ if pos(".",factor2) = 0 then factor2 = factor||"." factor2 = left(factor2,8,"0") call ppm_ShowStatus(" Fitting text... Iteration "right(iter,2," ")" Size factor "factor2) oldfactor = factor factor = factor*2 newtext = text /* go back to original each time */ newtext = ResizeFonts(newtext,factor) if newtext~="" then do /* ResizeFonts returns empty string if over size limit (720 points) */ gone = ppm_DeleteContents(box) overflow = ppm_TextIntoBox(box,newtext) end if newtext="" | overflow = 1 then break end max = factor factor = (oldfactor+factor)/2 min = 0 do 18 /* Don't go on iterating for ever... */ factor2 = factor /* format number for display */ if pos(".",factor2) = 0 then factor2 = factor||"." factor2 = left(factor2,8,"0") call ppm_ShowStatus(" Fitting text... Iteration "right(iter,2," ")" Size factor "factor2) iter = iter+1 newtext = text /* go back to original each time */ newtext = ResizeFonts(newtext,factor) if newtext~="" then do /* ResizeFonts returns empty string if over size limit (720 points) */ gone = ppm_DeleteContents(box) overflow = ppm_TextIntoBox(box,newtext) end if overflow = 1 | newtext = "" then do max = factor factor = (factor+min)/2 end else do min = factor factor = (factor+max)/2 end end factor = min /* just reduce a little at the end to cover the oscillations */ newtext = ResizeFonts(text,factor) /* go back to original each time */ gone = ppm_DeleteContents(box) overflow = ppm_TextIntoBox(box,newtext) end newpage = ppm_GoToPage(cpage) call ppm_SetUnits(currentunits) call exit_msg() end /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ ResizeFonts: procedure parse arg text, factor position = 1 position2 = 1 do forever /* we have to open up style tags to get sizes */ position = pos("\dS<",text,position2) if position = 0 then break position2 = pos(">",text,position) if position2 = 0 then break styletag = substr(text,position+4, position2-position-4) styledef = ppm_GetStyleTagData(styletag) styledef = left(styledef,pos("}",styledef)-1) /* remove name of tag */ styledef = substr(styledef,pos("{",styledef)+1) text = delstr(text,position, (position2-position+1)) /* delete tag name */ text = insert("\ds"styledef,text,(position-1)) end position2 = 1 do forever /* first change font sizes */ position = pos("\fs<",text,position2)+4 if position = 4 then break /* would be 0 but we added 4 */ position2 = pos(">",text,position) if position2 = 0 then break oldsize = substr(text,position, position2-position) text = delstr(text,position, position2-position) /* delete old size */ newsize = oldsize*factor if newsize>720 then do text = "" /* return empty text if over limit - this is different from the standard Text Resize module used in other genies */ break end oddsize = newsize//0.125 /* round correctly to nearest 1/8 point - PPage always rounds down */ if oddsize>0.0625 then newsize = newsize-oddsize+0.125 else newsize = newsize-oddsize text = insert(newsize,text,position-1) end if text = "" then return text /* again, different from standard module */ position2 = 1 do forever /* now fixed line spacings */ position = pos("\lf<",text,position2)+4 if position = 4 then break /* would be 0 but we added 4 */ position2 = pos(">",text,position) if position2 = 0 then break oldsize = substr(text,position, position2-position) text = delstr(text,position, position2-position) /* delete old size */ newsize = oldsize*factor if newsize>720 then newsize = 720 oddsize = newsize//0.125 /* round correctly to nearest 1/8 point - PPage always rounds down */ if oddsize>0.0625 then newsize = newsize-oddsize+0.125 else newsize = newsize-oddsize text = insert(newsize,text,position-1) end position2 = 1 do forever /* and fixed leading */ position = pos("\ll<",text,position2)+4 if position = 4 then break /* would be 0 but we added 4 */ position2 = pos(">",text,position) if position2 = 0 then break oldsize = substr(text,position, position2-position) text = delstr(text,position, position2-position) /* delete old size */ newsize = oldsize*factor if newsize>720 then newsize = 720 oddsize = newsize//0.125 /* round correctly to nearest 1/8 point - PPage always rounds down */ if oddsize>0.0625 then newsize = newsize-oddsize+0.125 else newsize = newsize-oddsize text = insert(newsize,text,position-1) end return text /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ error: syntax: do exit_msg("Genie failed due to error: "errortext(rc)) end exit_msg: do parse arg message if message ~= "" then call ppm_Inform(1,message,"Resume") call ppm_ClearStatus() call ppm_AutoUpdate(1) exit end