How to Get Line/Paragraph Breaks

General TRichView support forum. Please post your questions here
Post Reply
viperpix
Posts: 39
Joined: Sat Jan 15, 2011 9:38 am

How to Get Line/Paragraph Breaks

Post by viperpix »

Hi,
I wanna know how can i get the item number before each line/paragraph break in RVE.

im going to find words which have a space after and also the last word of lines which has a line/parag break after.

for example:

Hello world<LB>
Sup there?

the function should returns:
"Hello", "World" and "Sup"
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

First, about document structure that does not depend on word wrapping.
Document consists of items, numbered from 0 to ItemCount-1.
The type of item returned by GetItemStyle(i), the text for text items is returned by GetItemText(i).
If the item starts a new paragraph, GetItemPara(i)=True.
If the item starts a line inside a paragraph (for example, added with Shift+Enter), GetItemPara(i)=False, but IsFromNewLine(i)=True.

About line wrapping. This information is not documented.
Line wrapping depend on window width.
There is a collection of drawing items: RichView.RVData.DrawItems. Each object represents an object on the screen. For non-text objects, one drawing item correspond to one item. For text items, one drawing object is created for each line (but for justify alignment, one drawing object is created for each word). Hidden items do not have corresponding drawing items.
Item in RVData.DrawItems have the following properties:
ItemNo - index of the corresponding item
Offs - for text items, index of the first character of text in GetItemText(ItemNo), from 1
Length - length of text belonging to this drawing item.
FromNewLine - true if this drawing items starts a new line (does not matter why, because of paragraph break or because of line wrapping).
Note that drawing items may not cover the whole range of text of item: in place of line breaks, space character may be omitted.

This information is enough to calculate line break positions.
viperpix
Posts: 39
Joined: Sat Jan 15, 2011 9:38 am

Thanks

Post by viperpix »

best regards Sergey
I can calculate that word now, but i wish there was another way without need to a linear search in rve, cuz im doing this for many many large texts and this cause a killing situations!
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

If you need to get a drawing item for the item, you can use RichViewEdit.RVData methods Item2DrawItem.
It implements a binary search.
Post Reply