Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   Related Pages  

pdf::text::CText Class Reference

the text segment class More...

#include <Text.hh>

Collaboration diagram for pdf::text::CText:

Collaboration graph
[legend]
List of all members.

Public Methods

Static Private Methods

Private Attributes


Detailed Description

the text segment class

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 ) ;


Constructor & Destructor Documentation

pdf::text::CText::CText const std::string &    line,
const CState   state,
const CPosition   position = CNullPos( )
 

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.

Parameters:
line  the text string
state  the formatting of this string
position  the position of the string.
See also:
Move( )

00069     : m_line( line ), m_state( state ),
00070       m_position( position.Dup( ) )
00071 {
00072 }

pdf::text::CText::CText const std::string &    line,
const CState   state,
double    offset_x,
double    offset_y
 

construct a text segment. unlike the other constructor, the offset can be specified.

Parameters:
line  the text string
state  the formatting of this string
x_offset  the horizonal offset from the previous text segment in the page. i.e. relative.
y_offset  relative vertical offset
Note:
specifying an offset of (0,0) is different from no offset. since the offset is relative to the starting point of the previous text segment. setting an offset of (0,0) will make two segments overlap.
See also:
Move( )

00050     : m_line( line ), m_state( state ),
00051       m_position( new COffsetPos( offset_x, offset_y ) )
00052 {
00053 }

pdf::text::CText::CText const CText &    text
 

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 }

pdf::text::CText::~CText  
 

destructor does nothing. the auto_ptr will clean up the m_position pointer.

00085 {
00086 }


Member Function Documentation

std::ostream & pdf::text::CText::Write std::ostream &    os,
const CState   prev
const
 

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().

Parameters:
os  the I/O stream of the PDF file
prev  text state

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 }

void pdf::text::CText::Move const CPosition   new_pos
 

this function changes the text position. see the constructor for the meaning of the CPosition class.

See also:
CText( )

00139 {
00140     m_position.reset( new_pos.Dup( ) ) ;
00141 }

double pdf::text::CText::Width   const
 

calculate the width of the text line, including all transformation. the unit is default user space, i.e. 1/72 inches.

Note:
currently the width is not calculated by the matrix formula from the PDF spec. the formula is

in this implementation, the matrix is igored for now.

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

const std::string pdf::text::CText::EscapeString const std::string &    str [static, private]
 

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 }


Member Data Documentation

std::string pdf::text::CText::m_line [private]
 

the content of the text segment

CState pdf::text::CText::m_state [private]
 

the formatting of the text segment

std::auto_ptr<CPosition> pdf::text::CText::m_position [private]
 

position of the text segment


The documentation for this class was generated from the following files:
Generated on Sun Feb 2 09:17:35 2003 for libpdf++ by doxygen1.2.16