Page 1 of 1
height of paragraph at position
Posted: Mon Nov 28, 2011 11:04 pm
by blsstdok
What is the best way to get the pixel height of a paragraph at any given point in the document? I assume this would be two steps -- 1. Get the paragraph and 2. find it's height.
Thanks.
Posted: Tue Nov 29, 2011 7:10 am
by Sergey Tkachenko
It's possible by calculating positions of all items, but may be a more simple solution possible.
What do you want to implement?
Posted: Tue Nov 29, 2011 3:04 pm
by blsstdok
It's complicated, but basically I want to make subtle adjustments to the indentation, reformat, and test to be sure I haven't changed the vertical size of the paragraph due to wrapping. I also need to know the horizontal size of each line in the paragraph.
Posted: Sun Dec 04, 2011 8:48 pm
by Sergey Tkachenko
This calculation requires using "drawing items" which are undocumented.
The example is shown below. It calculates the height of the current paragraph (the paragraph containing the caret).
If you have the specified position in the document - (RVData, ItemNo), you can use them instead of (rve.RVData, rve.CurItemNo).
Code: Select all
uses DLines;
var FirstItemNo, LastItemNo: Integer;
i, FirstDItemNo, LastDItemNo: Integer;
rve: TCustomRichViewEdit;
Top, Bottom: Integer;
DrawItem: TRVDrawLineInfo;
ParaStyle: TParaInfo;
begin
rve := RichViewEdit1.TopLevelEditor;
rve.RVData.ExpandToPara(rve.CurItemNo, rve.CurItemNo, FirstItemNo, LastItemNo);
rve.RVData.Item2FirstDrawItem(FirstItemNo, FirstDItemNo);
rve.RVData.Item2LastDrawItem(LastItemNo, LastDItemNo);
DrawItem := rve.RVData.DrawItems[FirstDItemNo];
Top := DrawItem.Top-DrawItem.ExtraSpaceAbove;
Bottom := DrawItem.Top+DrawItem.Height+DrawItem.ExtraSpaceBelow;
for i := FirstDItemNo+1 to LastDItemNo do begin
DrawItem := rve.RVData.DrawItems[i];
if Top>DrawItem.Top-DrawItem.ExtraSpaceAbove then
Top := DrawItem.Top-DrawItem.ExtraSpaceAbove;
if Bottom<DrawItem.Top+DrawItem.Height+DrawItem.ExtraSpaceBelow then
Bottom := DrawItem.Top+DrawItem.Height+DrawItem.ExtraSpaceBelow;
end;
ParaStyle := rve.Style.ParaStyles[rve.GetItemPara(FirstItemNo)];
dec(Top, ParaStyle.SpaceBefore);
inc(Bottom, ParaStyle.SpaceAfter);
Caption := 'Current paragraph height: '+IntToStr(Bottom-Top);
end;
A document must be formatted when you call this procedure. This procedure ignores left- and right-aligned objects.