I want to "fill" a RichViewEdit with text from another RichViewEdit until it has maximum height but without exceeding the height of the window (of the first RichViewEdit).
I do this:
Code: Select all
var Stream: TStream;
i: Integer;
begin
Rve1.BeginUpdate;
Rve1.UndoLimit := 0;
Rve2.BeginUpdate;
while True do
begin
Stream.Clear;
//copy the text from the second RichViewEdit
Rve2.SetSelectionBounds(Item1, Offs1, Item2, Offs2);
Rve2.SaveRVFToStream(Stream, True);
//load the text in the first RichViewEdit
Stream.Position := 0;
Rve1.Clear;
Rve1.DeleteUnusedStyles(True, True, True);
Rve1.LoadRVFFromStream(Stream);
//I increase the size of the text
for i := 0 to Rve1.Style.TextStyles.Count - 1 do
Rev1.Style.TextStyles[i].Size := Round(1.5 * Rve1.Style.TextStyles[i].Size);
Rve1.Format;
if (Rve1.DocumentHeight >= Rve1.Height) or (//no more text to add) then
Break;
//here I decrease Item1/Offs1 and I increase Item2/Offs2 (with the same "step")
...
end;
Rve1.EndUpdate;
Rve1.UndoLimit := -1;
Rve2.EndUpdate;
end;
One way is to increase the size of the "step" (how much I decrease Item1/Offs1 and increase Item2/Offs2). But I can't increase it much because the result will not be so "accurate".
Another way is to use a method called "double and/or half of the interval": first I double the "step" until Rve1.DocumentHeight > Rve1.Height. Then I use the interval between the previous value and the current value: I "chop" it into 2 until I found the best value possible.
It helped, but just a little.
Maybe someone knows a better way...
Thank you in advance for your help.
Best regards, David Brenner