@BAjustTexteAuxBoεtes @P @I Ecrit et ⌐ par Don Cox en juillet 1992
@IRΘvisΘ en juillet 1993. N'est pas du Domaine Publique.
@ITous Droits RΘservΘs.
Traduit par Fabien Larini le 23/07/93.
Ce GΘnie fait rentrer tout le texte dans une boεte ou une chaεne de boεtes
en respectant les proportions des tailles de caractΦres. Tout le texte
dans la boεte sera modifiΘ. Il n'y a pas crΘation de boεtes comme dans
ImportationAuto. Il doit y avoir du texte dans la boεte avant de lancer
le GΘnie.
Remarque : les formats de styles appliquΘs au texte seront annulΘs. Le
facteur minimal de rΘduction est 1/8 point dans les tailles de caractΦres
disponibles. Ce GΘnie prΘfΦre sous-remplir une boεte que de la faire
dΘborder
*/
/*FitTextToBoxes*/
/* 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("Clickez dans les Boεtes o∙ le Texte doit Ωtre AjustΘ")
if box=0 then break
counter=counter+1
boxes.counter=box
call ppm_SelectBox(box)
end
if counter=0 then exit_msg("Pas de Boεte SΘlectionnΘe")
currentunits=ppm_GetUnits()
call ppm_SetUnits(2)
call ppm_ShowStatus("Ajustement du Texte ...")
do i=1 to counter
box=boxes.i
boxtype = upper(word(ppm_GetBoxInfo(box), 1))
if boxtype~="TEXTE" 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("Ajustement du Texte ... ItΘration "right(iter,2," ")" Rapport "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("Ajustement du Texte ... ItΘration "right(iter,2," ")" Rapport "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 */