Dillo
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
dw::Textblock::BadnessAndPenalty Class Reference

Public Member Functions

void calcBadness (int totalWidth, int idealWidth, int totalStretchability, int totalShrinkability)
 
void setPenalty (int penalty)
 
void setPenalties (int penalty1, int penalty2)
 
int getPenalty (int i)
 
bool lineLoose ()
 
bool lineTight ()
 
bool lineTooTight ()
 
bool lineMustBeBroken (int penaltyIndex)
 
bool lineCanBeBroken (int penaltyIndex)
 
int compareTo (int penaltyIndex, BadnessAndPenalty *other)
 
void intoStringBuffer (lout::misc::StringBuffer *sb)
 

Private Types

enum  { NOT_STRETCHABLE, QUITE_LOOSE, BADNESS_VALUE, TOO_TIGHT }
 
enum  {
  INF_VALUE = 0, INF_LARGE, INF_NOT_STRETCHABLE, INF_TOO_TIGHT,
  INF_PENALTIES, INF_MAX = INF_PENALTIES
}
 

Private Member Functions

void setSinglePenalty (int index, int penalty)
 
int badnessValue (int infLevel)
 
int penaltyValue (int index, int infLevel)
 

Private Attributes

enum
dw::Textblock::BadnessAndPenalty:: { ... }  
badnessState
 
int ratio
 
int badness
 
int penalty [2]
 

Member Enumeration Documentation

anonymous enum
private
Enumerator
NOT_STRETCHABLE 
QUITE_LOOSE 
BADNESS_VALUE 
TOO_TIGHT 
anonymous enum
private
Enumerator
INF_VALUE 
INF_LARGE 
INF_NOT_STRETCHABLE 
INF_TOO_TIGHT 
INF_PENALTIES 
INF_MAX 

Member Function Documentation

int dw::Textblock::BadnessAndPenalty::badnessValue ( int  infLevel)
private

References lout::misc::assertNotReached().

Referenced by compareTo().

void dw::Textblock::BadnessAndPenalty::calcBadness ( int  totalWidth,
int  idealWidth,
int  totalStretchability,
int  totalShrinkability 
)
int dw::Textblock::BadnessAndPenalty::compareTo ( int  penaltyIndex,
BadnessAndPenalty other 
)
int dw::Textblock::BadnessAndPenalty::getPenalty ( int  i)
inline
void dw::Textblock::BadnessAndPenalty::intoStringBuffer ( lout::misc::StringBuffer sb)
bool dw::Textblock::BadnessAndPenalty::lineCanBeBroken ( int  penaltyIndex)
bool dw::Textblock::BadnessAndPenalty::lineLoose ( )
bool dw::Textblock::BadnessAndPenalty::lineMustBeBroken ( int  penaltyIndex)
bool dw::Textblock::BadnessAndPenalty::lineTight ( )
bool dw::Textblock::BadnessAndPenalty::lineTooTight ( )
int dw::Textblock::BadnessAndPenalty::penaltyValue ( int  index,
int  infLevel 
)
private

Referenced by compareTo().

void dw::Textblock::BadnessAndPenalty::setPenalties ( int  penalty1,
int  penalty2 
)

Sets the penalty, multiplied by 100. Multiplication is necessary to deal with fractional numbers, without having to use floating point numbers. So, to set a penalty to 0.5, pass 50.

INT_MAX and INT_MIN (representing inf and -inf, respectively) are also allowed.

The definition of penalties depends on the definition of badness, which adheres to the description in Changes in Line-Breaking and Hyphenation, section "Criteria for Line-Breaking". The exact calculation may vary, but this definition of should be rather stable: (i) A perfectly fitting line has a badness of 0. (ii) A line, where all spaces are extended by exactly the stretchability, as well as a line, where all spaces are reduced by the shrinkability, have a badness of 1.

(TODO plural: penalties, not penalty. Correct above comment)

Referenced by dw::Textblock::hyphenateWord(), dw::Textblock::setBreakOption(), and setPenalty().

void dw::Textblock::BadnessAndPenalty::setPenalty ( int  penalty)
inline
void dw::Textblock::BadnessAndPenalty::setSinglePenalty ( int  index,
int  penalty 
)
private

Member Data Documentation

int dw::Textblock::BadnessAndPenalty::badness
private
enum { ... } dw::Textblock::BadnessAndPenalty::badnessState
int dw::Textblock::BadnessAndPenalty::penalty[2]
private
int dw::Textblock::BadnessAndPenalty::ratio
private

The documentation for this class was generated from the following files: