trichview.com Forum Index trichview.com
TRichView support forums
 

height of paragraph at position


 
Post new topic   Reply to topic    trichview.com Forum Index -> Support
    View previous topic :: View next topic  
Author Message
blsstdok



Joined: 07 Jun 2011
Posts: 25

PostPosted: Mon Nov 28, 2011 11:04 pm    Post subject: height of paragraph at position Reply with quote

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
View user's profile Send private message
Sergey Tkachenko
Site Admin


Joined: 27 Aug 2005
Posts: 10702

PostPosted: Tue Nov 29, 2011 7:10 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
blsstdok



Joined: 07 Jun 2011
Posts: 25

PostPosted: Tue Nov 29, 2011 3:04 pm    Post subject: Reply with quote

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
View user's profile Send private message
Sergey Tkachenko
Site Admin


Joined: 27 Aug 2005
Posts: 10702

PostPosted: Sun Dec 04, 2011 8:48 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    trichview.com Forum Index -> Support All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group