<< Click to Display Table of Contents >> Navigation: Programming > Create text under program control > Low level text creation > Measure Paragraph - calculate width |
Please note that while you add text to a TParagraph the new text is not formatted. This means that no word wrap is known.
It is however possible to force the initialization of the text to let the engine calculate the character widths. (Note: Tabstops are not calculated). To initialize a paragraph you can use WPRichText1.Memo.InitializePar(par.RTFData, par);
This example will remove all characters which do not fit into the first 5 cm:
var i, w, j : Integer;
par : TParagraph;
begin
par := .... // the working paragraph
WPRichText1.Memo.InitializePar(par.RTFData, par);
w := MulDiv( WPCentimeterToTwips(5), WPRichText1.Memo.CurrentXPixelsPerInch, 1440 );
for i := 0 to par.CharCount-1 do
begin
if w<0 then
begin
par.DeleteChars(i, par.CharCount-1);
par.Insert(i+1, '...', par.CharAttr[i]);
break;
end;
dec(w, par.CharPos[i].Width);
end;
end;