#include <Text.hh>
Collaboration diagram for pdf::text::CText:
this class represent a text segment. a text segment is a string with the same formatting. the formatting data is stored in a CState object. in addition to string and formatting, it also store the position of the text string in the page. the position is given as offset from the last text segment, i.e. the coordinate is relative.
primary use of this class is to construct it and add it to the CPage class by CPage::DrawText().
example:
text::CText text( "I am a line", text::CState( ) ) ; page.DrawText( text ) ;
|
construct a text segment given the text string, state and position. the "position" is specified as a reference of the CPosition class. it can be a CNullPos, which means this segment is right after the previous text segment; or it can be a COffsetPos, which specified the X-Y offset from the start of the last text segment; or it can be a CAbsolutePos, which specified the absolute coordinate of the text segment.
00069 : m_line( line ), m_state( state ), 00070 m_position( position.Dup( ) ) 00071 { 00072 } |
|
construct a text segment. unlike the other constructor, the offset can be specified.
00050 : m_line( line ), m_state( state ), 00051 m_position( new COffsetPos( offset_x, offset_y ) ) 00052 { 00053 } |
|
copy constructor is needed because I used auto_ptr internally.
00077 : m_line( text.m_line ), m_state( text.m_state ), 00078 m_position( text.m_position->Dup( ) ) 00079 { 00080 } |
|
destructor does nothing. the auto_ptr will clean up the m_position pointer.
00085 { 00086 } |
|
For internal use only. write the text segment to the PDF file. it is called by CPage::Write(). library clients should not call this directly. the "prev" text state will be passed to CState::Write().
00096 { 00097 assert( m_position.get( ) != 0 ) ; 00098 00099 // write the position of the text 00100 m_position->Write( os, m_state.Leading( ) ) ; 00101 00102 // write the formatting 00103 m_state.Write( os, prev ) ; 00104 00105 // write the string enclosed by brackets 00106 return os << '(' << EscapeString( m_line ) << ") Tj\n" ; 00107 } |
|
this function changes the text position. see the constructor for the meaning of the CPosition class.
00139 { 00140 m_position.reset( new_pos.Dup( ) ) ; 00141 } |
|
calculate the width of the text line, including all transformation. the unit is default user space, i.e. 1/72 inches.
00152 {fs} & 0 \\ 00153 0 & T_{rise} & 1 00154 \end{bmatrix} 00155 \times T_m \times CTM 00156 \f] 00157 00158 in this implementation, the \f$T_m\f$ matrix is igored for now. 00159 */ 00160 double CText::Width( ) const 00161 { 00162 double result = 0.0f ; 00163 00164 // use iterator is faster than array index 00165 typedef std::string::const_iterator iterator ; 00166 for ( iterator i = m_line.begin() ; i != m_line.end() ; ++i ) 00167 { 00168 assert( m_state.Font( ) != 0 ) ; 00169 00170 // character width in glyph space 00171 double char_width = m_state.Font( )->GlyphWidth( *i ) ; 00172 00173 // transform to user space |
|
convert the escape chars. it will put escape characters into the string and return it.
00113 { 00114 using namespace std ; 00115 00116 string escape_chars = "()\\" ; 00117 00118 string result ; 00119 result.reserve( str.size( ) + 1 ) ; 00120 00121 // use iterator is faster than array index 00122 for ( string::const_iterator i = str.begin( ) ; i != str.end( ) ; ++i ) 00123 { 00124 if ( escape_chars.find( *i ) != string::npos ) 00125 result.push_back( '\\' ) ; 00126 00127 result.push_back( *i ) ; 00128 } 00129 00130 return result ; 00131 } |
|
the content of the text segment
|
|
the formatting of the text segment
|
|
position of the text segment
|