1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
Procedure TForm1.InsertTexte(Texte:string;Dest:Tlabel);
var i,y,p:integer;
st,st1:string;
begin
// insertion espace insecable en fonction de la ponctuation française
i:=0;
repeat
inc(i);
if (i>1) and (texte[i] in [';',':','?','!','»']) and (texte[i-1]=' ') then texte[i-1]:='§'; // §; §: §? §! §»
if (i<length(texte)) and (texte[i] in ['«','-']) and (texte[i+1]=' ') then texte[i+1]:='§'; // «§ -§
until i=length(texte);
Y:=0;
repeat
st:='';
// compose les lignes en fonction de la lageur du label
repeat
P:=Pos(' ',texte);
if P<>0 then
begin // ajoute les mots et calcule la taille
St:=st+copy(texte,1,P);
if Dest.Canvas.TextWidth(St)<Dest.Width then
begin
st1:=st;
delete(texte,1,p);
end else break;
end
else
begin // traite fin du texte sans espace en fin de ligne
st1:=st1+texte;
texte:='';
break;
end;
until false;
// retire caractères "insécable"
for i:=1 to length(st1) do if st1[i]='§' then st1[i]:=' ';
Dest.Canvas.TextOut(0,Y,st1);
Y:=Y+Dest.Canvas.TextHeight('M')+2;
until texte='';
end; |
Partager