Line Height

General TRichView support forum. Please post your questions here
Post Reply
standay
Posts: 274
Joined: Fri Jun 18, 2021 3:07 pm

Line Height

Post by standay »

Hi Sergey,

Is there a way to get the current line height? By that I mean the height of the line the caret is currently on, not necessarily the paragraph height. Those might be the same, but if the text is wrapped they are different.

What I need is the height of the largest item on the line. If the only way to do this would be to spin through the items of the single line, could you give me an example? I've been at this for hours and can't get it figured out!

Thanks Sergey.

Stan
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Line Height

Post by Sergey Tkachenko »

This function returns the line height (using undocumented methods):

Code: Select all

uses
  CRVFData, RVERVData;

function GetCurrentLineHeight(rve: TCustomRichViewEdit): TRVCoord;
var
  DItemNo: Integer;
  Y1, Y2: TRVCoord;
begin
  rve := rve.TopLevelEditor;
  DItemNo := TRVEditRVData(rve.RVData).CaretDrawItemNo;
  while not rve.RVData.IsFromNewLine(DItemNo) do
    dec(DItemNo);
  rve.RVData.GetLineVerticalBoundsOrig(DItemNo, Y1, Y2, DItemNo);
  Result := Y2 - Y1;
end;
Note 1: it returns not a height of the tallest line item, but a difference between the highest and the lowest points of the line, which is not necessary the same.
Note 2: Y1 and Y2 cannot be used to draw the caret, because they do not take into account scrolling, cell rotation, reversed cell line order.
standay
Posts: 274
Joined: Fri Jun 18, 2021 3:07 pm

Re: Line Height

Post by standay »

Hi Sergey,

Took a while to respond, I've been working on this and related line number issues for days!

The example helped a lot. It confirmed that the solution would involve both TRVEditRVData(rve.RVData).CaretDrawItemNo; and GetLineVerticalBoundsOrig. I'd actually been using both already but your example helped confirm I was on the right path.

Although GetLineVerticalBoundsOrig was close, it was not quite 100%. I was getting slightly different results from Y1 and Y2 depending on which item in the line the caret was on if the sizes of the items differed (especially on images with different alignments, or text of different sizes). However, I found that using GetLineVerticalBoundsOrigEx gave me the results I was after. I called it like this:

Code: Select all

RVData.GetLineVerticalBoundsOrigEx(CurDItem,LineTopY,LineBottomY,CurDItem,CurDItem);
"Extended" editor rve active line style
"Extended" editor rve active line style
Lineheight.png (5.41 KiB) Viewed 3575 times
Plain current line style
Plain current line style
Lineheight2.png (5.33 KiB) Viewed 3575 times

I used it directly, not in the GetCurrentLineHeight function. The color rectangles in my line number gutter now match up correctly regardless of which Item has the caret.

Thanks Sergey, you really helped me again!

Stan
Post Reply