How to apply specific formatting to some text using offsets?
Posted: Mon Jan 02, 2006 7:57 pm
Hello,
i have been thinking and reading for almost 2 days on the best way to apply some formatting to a rv or rve and i am not sure what to do.
The problem is this:
I create a document that has many paragraphs in it (let's say 100 paragraphs). Each paragraph contains some text and for each paragraph i have a list of formatting and offsets i want to apply.
For example:
- for paragraph one, i want to apply the Bold style to all characters from position 5 to position 20. Also, i want yellow background for position 10 to position 25. Obviously, the formattings can overlay one another.
- The number of possible formatting is known (bold, italic, forecolor, backcolor, underline). What i have also (for each paragraph) is the start and end offset for each one of these formattings
Now, i have thought the following solutions:
1. Get the text of the paragraph (as simple text), and then break it apart in pieces using the information of the position of formattings and for each piece create a suitable style that combines all formatting that corresponds to that piece and use the AddXXX methods. This solution seems to be the faster but has a lot of overhead.
2. Add all the paragraphs, format the rv and then go through each paragraph (using the RVLinear unit), select the appropriate text for each one of these and use the ApplyStyleConversion method, which does what i would do in solution 1. The problem i see with this solution is that the method ApplyStyleConversion actually reformats the document so if there are many formattings to be applied, this method will be extremely slow.
Is there any other way to implement the above?
It is obvious that what i try to do is to allow the user to apply some formatting to the text but instead of saving the whole text as RTF or RVF, i want each formatting to be specified with indexes so i can then apply semantic information to it (e.g. red letters are for errros, yellow background for important notes, etc).
Thanks,
Costas
i have been thinking and reading for almost 2 days on the best way to apply some formatting to a rv or rve and i am not sure what to do.
The problem is this:
I create a document that has many paragraphs in it (let's say 100 paragraphs). Each paragraph contains some text and for each paragraph i have a list of formatting and offsets i want to apply.
For example:
- for paragraph one, i want to apply the Bold style to all characters from position 5 to position 20. Also, i want yellow background for position 10 to position 25. Obviously, the formattings can overlay one another.
- The number of possible formatting is known (bold, italic, forecolor, backcolor, underline). What i have also (for each paragraph) is the start and end offset for each one of these formattings
Now, i have thought the following solutions:
1. Get the text of the paragraph (as simple text), and then break it apart in pieces using the information of the position of formattings and for each piece create a suitable style that combines all formatting that corresponds to that piece and use the AddXXX methods. This solution seems to be the faster but has a lot of overhead.
2. Add all the paragraphs, format the rv and then go through each paragraph (using the RVLinear unit), select the appropriate text for each one of these and use the ApplyStyleConversion method, which does what i would do in solution 1. The problem i see with this solution is that the method ApplyStyleConversion actually reformats the document so if there are many formattings to be applied, this method will be extremely slow.
Is there any other way to implement the above?
It is obvious that what i try to do is to allow the user to apply some formatting to the text but instead of saving the whole text as RTF or RVF, i want each formatting to be specified with indexes so i can then apply semantic information to it (e.g. red letters are for errros, yellow background for important notes, etc).
Thanks,
Costas