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.
height of paragraph at position
-
- Site Admin
- Posts: 17572
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
-
- Site Admin
- Posts: 17572
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
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).
A document must be formatted when you call this procedure. This procedure ignores left- and right-aligned objects.
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;