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

pdf::text::CState Class Reference

stores text formatting info More...

#include <State.hh>

Collaboration diagram for pdf::text::CState:

Collaboration graph
[legend]
List of all members.

Public Methods

Private Attributes


Detailed Description

stores text formatting info

in the PDF specs, the formatting of a text segment is called the text state. this class represents a text state. it stores information like font, font size, leading and spacing.

when writing a CState object to an output stream, the previous state must be given for comparison. only the individual properties that are difference from the previous state will be written.


Constructor & Destructor Documentation

pdf::text::CState::CState  
 

default constructor will set everything to default values. scale is set to 1.0f which means no scale. default values are given by the PDF specs.

when calling Write() for the first text state in the start of an "BI" operator section, there is no such "previous" state. a default constructed CState object can be used as its previous state.

00051     : m_font( 0 ), m_font_size( 0 ), m_char_space( 0 ),
00052       m_word_space( 0 ), m_scale( 1.0f ), m_leading( 0 ),
00053       m_render( 0 ), m_rise( 0 )
00054 {
00055 }

pdf::text::CState::CState const font::CFont   font,
double    font_size,
double    leading = 0,
double    char_space = 0,
double    word_space = 0,
double    scale = 1.0f,
int    render = 0,
double    rise = 0
 

construct a text state with the given parameters. if the leading is zero, it will be set to the font size.

Parameters:
font  the font used.
font_size  size of the font, in points
leading  lead size, in user space units. default value is font size.
word_space  extra spacings between words, in user space units. default value is zero.
scale  horizonal scaling for every character. default value is 1.0, which means no scaling. if set to 2.0, that means the character are twice as wide.
render  rendering mode. default value is normal.
rise  text rise, in user space units. default value is zero.

00076     : m_font( font ), m_font_size( font_size ),
00077       m_char_space( char_space ), m_word_space( word_space ),
00078       m_scale( scale ), m_leading( leading == 0 ? font_size : leading ),
00079       m_render( render ), m_rise( rise )
00080 {
00081     assert( m_font != 0 ) ;
00082 }

pdf::text::CState::CState const CState &    text
 

copy constructor.

00087     : m_font( text.m_font ), m_font_size( text.m_font_size ),
00088       m_char_space( text.m_char_space ), m_word_space( text.m_word_space ),
00089       m_scale( text.m_scale ), m_leading( text.m_leading ),
00090       m_render( text.m_render ), m_rise( text.m_rise ),
00091       m_colour( text.m_colour )
00092 {
00093 }


Member Function Documentation

CState & pdf::text::CState::operator= const CState &    state
 

assignment operator. calls copy constructor and Swap()

00144 {
00145     CState temp( state ) ;
00146     Swap( temp ) ;
00147     return *this ;
00148 }

void pdf::text::CState::Swap CState &    state
 

swap two objects. swaps all members.

00153 {
00154     using namespace std ;
00155     
00156     swap( m_font, state.m_font ) ;
00157     swap( m_font_size, state.m_font_size ) ;
00158     swap( m_char_space, state.m_char_space ) ;
00159     swap( m_word_space, state.m_word_space ) ;
00160     swap( m_scale, state.m_scale ) ;
00161     swap( m_leading, state.m_leading ) ;
00162     swap( m_render, state.m_render ) ;
00163     swap( m_rise, state.m_rise ) ;
00164 }

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

write the text state to the output. only those parameter which is different from the previous state will be output, in order to save spaces.

Parameters:
os  the output stream. should be a PDF file
prev  the previous state. used to compare for differences

00103 {
00104     assert( m_font != 0 ) ;
00105     
00106     if ( m_font->Name( ).empty( ) )
00107         throw CFontError( CFontError::invalid_font ) ;
00108 
00109     if ( m_font != prev.m_font || m_font_size != prev.m_font_size )
00110     {
00111         assert( m_font != 0 ) ;
00112         os << core::CName( m_font->Name( ) ) << ' ' << m_font_size << " Tf " ;
00113     }
00114     
00115     if ( m_char_space != prev.m_char_space )
00116         os << m_char_space << " Tc " ;
00117 
00118     if ( m_word_space != prev.m_word_space )
00119         os << m_word_space << " Tw " ;
00120 
00121     // according to the PDF spec, normal width is 100.
00122     // but we store the ratio.
00123     if ( m_scale != prev.m_scale )
00124         os << m_scale * 100 << " Tz " ;
00125 
00126     if ( m_leading != prev.m_leading )
00127         os << m_leading << " TL " ;
00128 
00129     if ( m_render != prev.m_render )
00130         os << m_render << " Tr " ;
00131 
00132     if ( m_rise != prev.m_rise )
00133         os << m_rise << " Ts " ;
00134 
00135     if ( m_colour != prev.m_colour )
00136         os << m_colour << "rg " ;
00137 
00138     return os ;
00139 }

double pdf::text::CState::Leading   const [inline]
 

return the leading size

00091 { return m_leading ; }

void pdf::text::CState::Colour const util::CColour   colour
 

change the text colour.

00169 {
00170     m_colour = colour ;
00171 }

const util::CColour pdf::text::CState::Colour   const
 

return the current text colour.

00176 {
00177     return m_colour ;
00178 }


Member Data Documentation

const font::CFont* pdf::text::CState::m_font [private]
 

text font. the font object is NOT owned by this class.

double pdf::text::CState::m_font_size [private]
 

font size

double pdf::text::CState::m_char_space [private]
 

character spacing

double pdf::text::CState::m_word_space [private]
 

word spacing

double pdf::text::CState::m_scale [private]
 

horizonal spacing

double pdf::text::CState::m_leading [private]
 

leading size

int pdf::text::CState::m_render [private]
 

rendering mode

double pdf::text::CState::m_rise [private]
 

text rise

util::CColour pdf::text::CState::m_colour [private]
 

text colour


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