trichview.com

trichview.support




Problem with words breaking at the end of a line.


Return to index


Author

Message

David Plock

Posted: 03/11/2005 19:48:50


Sergey - very nice control, it quickly solved a lot of display problems I

was having using a RichEdit control.


I have one remaining problem involving word breaks. The application I am

creating uses some specialized fonts and a single word can contain characters

in two different fonts, usually the first character being in one font and

the rest of the word being in the second font. The problem I am having is

if a word that uses two fonts (styles) occurs at the end of a line and the

word needs to wrap down to the next line, it breaks the word leaving the

first character (in the first font/style) on the original line and the remainder

of the word (in the second font/style) is moved to the next line.


From what I have been able to trace in the code, this happens because the

'single' word is stored in the RichView format as two different items - the

first character with one text style, the rest of the word with another text

style.


Would you have any ideas how I can keep the 'word' together in the formatted

text and retain the font information or what would be the best way to patch

the code to accomplish this?


(My first thought was to flag an item when it doesn't end in a delimiter

and then if the next item does not start with a delimiter and gets moved

to the next line, modify the previous line by removing the flagged item and

moving it onto the new line.)


To show the problem.


Drop a RVStyle and RichView control on a form.

Set the RichView align to alClient.


Add the following code in the FormShow event:


procedure TForm1.FormShow(Sender: TObject);

begin

  RichView1.Clear;

  RichView1.AddNL('T',1,0);

  RichView1.AddNL('his is a test ',0,-1);

  RichView1.AddNL('T',1,-1);

  RichView1.AddNL('his is a test ',0,-1);

  RichView1.Format;

end;


Run the program and resize the width of the window so that the width falls

in the middle of the second occurance of the word 'This'.


The 'T' (in the heading style) will remain on the first line and the 'his'

(in the normal style) will move to the next line.


Any help in this matter would be greatly appreciated.


Thank you.


David Plock





Powered by ABC Amber Outlook Express Converter