<p>Word wrap is one of the must-have features in a modern text editor.</p>

<p>How word wrap be handled? What is the best algorithm for word-wrap?</p>

<p>If text is several million lines, how can I make word-wrap very fast?</p>

<p>Why do I need the solution? Because my projects must draw text with various zoom level and simultaneously beautiful appearance.</p>

<p>The running environment is Windows Mobile devices. The maximum 600&nbsp;MHz speed with very small memory size.</p>

<p>How should I handle line information? Let's assume original data has three lines.</p>

<pre><code>THIS IS LINE 1.
THIS IS LINE 2.
THIS IS LINE 3.
</code></pre>

<p>Afterwards, the break text will be shown like this:</p>

<pre><code>THIS IS
LINE 1.
THIS IS
LINE 2.
THIS IS
LINE 3.
</code></pre>

<p>Should I allocate three lines more? Or any other suggestions?
­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­</p>

With or without hyphenation?
Without it's easy. Just encapsulate your text as wordobjects per word and give them a method getWidth(). Then start at the first word adding up the rowlength until it is greater than the available space. If so, wrap the last word and start counting again for the next row starting with this one, etc.
With hyphenation you need hyphenation rules in a common format like: hy-phen-a-tion
Then it's the same as the above except you need to split the last word which has caused the overflow.
A good example and tutorial of how to structure your code for an excellent text editor is given in the Gang of Four
Design Patterns
book. It's one of the main samples on which they show the patterns.