| View previous topic :: View next topic |
| Author |
Message |
blsstdok
Joined: 07 Jun 2011 Posts: 25
|
Posted: Mon Nov 28, 2011 11:04 pm Post subject: height of paragraph at position |
|
|
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. |
|
| Back to top |
|
 |
Sergey Tkachenko Site Admin
Joined: 27 Aug 2005 Posts: 9921
|
Posted: Tue Nov 29, 2011 7:10 am Post subject: |
|
|
It's possible by calculating positions of all items, but may be a more simple solution possible.
What do you want to implement? |
|
| Back to top |
|
 |
blsstdok
Joined: 07 Jun 2011 Posts: 25
|
Posted: Tue Nov 29, 2011 3:04 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
Sergey Tkachenko Site Admin
Joined: 27 Aug 2005 Posts: 9921
|
Posted: Sun Dec 04, 2011 8:48 pm Post subject: |
|
|
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: | 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. |
|
| Back to top |
|
 |
|