|
||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionI wrote this code back in times where most of the user interfaces were text based. But some years ago, I again had to use this code for formatting emails which were automatically generated and sent to our customers. So I grabbed the change, and rewrote the whole thing in C++. The outcome of this refactoring process is an easy to use class called How does it work?The idea behind the row justification is, to automatically wrap the words if the length of one row is greater than the given block size. The diagram below shows the technique of wrapping the line into parts where each part's length is less than the block size. This job is done in
Once each row isn't greater than block size anymore, spaces are inserted between words by calculating the amount of characters needed to let the row fit exactly into the block size.
Using the classThe constructor of void CTextformatterDialogDlg::OnButTesttable() { std::stringstream out; TF::TextFormatter tf(out, m_ColumnWidthControl.GetPos()); tf.print(standard_text); tf.newLines(3); tf.createTable(); tf.addColumn("Name", 10); tf.addColumn("First Name", 14); tf.addColumn("Age", 6); tf.setColumnAlignment(2, TF::TextFormatter::right); tf.printHeader(true); tf.printRow(3, "Kandinsky", "Wassily", "139"); tf.printRow(3, "Marc", "Franz", "125"); tf.printRow(3, "Mueller", "Otto", "1131"); tf.printRow(3, "Dali", "Salvador", "101"); tf.printRowLine(); tf.print("Mr.Mueller's age was slightly modified."); tf.newLines(5); tf.setBlockMax(m_ColumnWidthControl.GetPos()*2); tf.print(standard_text); m_Output = out.str().c_str(); this->UpdateData(FALSE); }
|
|||||||||||||||||||||||||||||||||||||||||||||||