Tesseract  3.02
ParagraphModel Class Reference

#include <ocrpara.h>

List of all members.

Public Member Functions

 ParagraphModel (tesseract::ParagraphJustification justification, int margin, int first_indent, int body_indent, int tolerance)
 ParagraphModel ()
bool ValidFirstLine (int lmargin, int lindent, int rindent, int rmargin) const
bool ValidBodyLine (int lmargin, int lindent, int rindent, int rmargin) const
tesseract::ParagraphJustification justification () const
int margin () const
int first_indent () const
int body_indent () const
int tolerance () const
bool is_flush () const
bool Comparable (const ParagraphModel &other) const
STRING ToString () const

Detailed Description

Definition at line 114 of file ocrpara.h.


Constructor & Destructor Documentation

ParagraphModel::ParagraphModel ( tesseract::ParagraphJustification  justification,
int  margin,
int  first_indent,
int  body_indent,
int  tolerance 
) [inline]

Definition at line 116 of file ocrpara.h.

      : justification_(justification),
        margin_(margin),
        first_indent_(first_indent),
        body_indent_(body_indent),
        tolerance_(tolerance) {
    // Make one of {first_indent, body_indent} is 0.
    int added_margin = first_indent;
    if (body_indent < added_margin)
      added_margin = body_indent;
    margin_ += added_margin;
    first_indent_ -= added_margin;
    body_indent_ -= added_margin;
  }
ParagraphModel::ParagraphModel ( ) [inline]

Definition at line 135 of file ocrpara.h.

      : justification_(tesseract::JUSTIFICATION_UNKNOWN),
         margin_(0),
         first_indent_(0),
         body_indent_(0),
         tolerance_(0) { }

Member Function Documentation

int ParagraphModel::body_indent ( ) const [inline]

Definition at line 169 of file ocrpara.h.

{ return body_indent_; }
bool ParagraphModel::Comparable ( const ParagraphModel other) const

Definition at line 80 of file ocrpara.cpp.

                                                                 {
  if (justification_ != other.justification_)
    return false;
  if (justification_ == JUSTIFICATION_CENTER ||
      justification_ == JUSTIFICATION_UNKNOWN)
    return true;
  int tolerance = (tolerance_ + other.tolerance_) / 4;
  return NearlyEqual(margin_ + first_indent_,
                     other.margin_ + other.first_indent_, tolerance) &&
         NearlyEqual(margin_ + body_indent_,
                     other.margin_ + other.body_indent_, tolerance);
}
int ParagraphModel::first_indent ( ) const [inline]

Definition at line 168 of file ocrpara.h.

{ return first_indent_; }
bool ParagraphModel::is_flush ( ) const [inline]

Definition at line 171 of file ocrpara.h.

                        {
    return (justification_ == tesseract::JUSTIFICATION_LEFT ||
            justification_ == tesseract::JUSTIFICATION_RIGHT) &&
        abs(first_indent_ - body_indent_) <= tolerance_;
  }
tesseract::ParagraphJustification ParagraphModel::justification ( ) const [inline]

Definition at line 164 of file ocrpara.h.

                                                        {
    return justification_;
  }
int ParagraphModel::margin ( ) const [inline]

Definition at line 167 of file ocrpara.h.

{ return margin_; }
int ParagraphModel::tolerance ( ) const [inline]

Definition at line 170 of file ocrpara.h.

{ return tolerance_; }
STRING ParagraphModel::ToString ( ) const

Definition at line 93 of file ocrpara.cpp.

                                      {
  char buffer[200];
  const STRING &alignment = ParagraphJustificationToString(justification_);
  snprintf(buffer, sizeof(buffer),
           "margin: %d, first_indent: %d, body_indent: %d, alignment: %s",
           margin_, first_indent_, body_indent_, alignment.string());
  return STRING(buffer);
}
bool ParagraphModel::ValidBodyLine ( int  lmargin,
int  lindent,
int  rindent,
int  rmargin 
) const

Definition at line 63 of file ocrpara.cpp.

                                                                   {
  switch (justification_) {
    case JUSTIFICATION_LEFT:
      return NearlyEqual(lmargin + lindent, margin_ + body_indent_,
                         tolerance_);
    case JUSTIFICATION_RIGHT:
      return NearlyEqual(rmargin + rindent, margin_ + body_indent_,
                         tolerance_);
    case JUSTIFICATION_CENTER:
      return NearlyEqual(lindent, rindent, tolerance_ * 2);
    default:
      // shouldn't happen
      return false;
  }
}
bool ParagraphModel::ValidFirstLine ( int  lmargin,
int  lindent,
int  rindent,
int  rmargin 
) const

Definition at line 46 of file ocrpara.cpp.

                                                                    {
  switch (justification_) {
    case JUSTIFICATION_LEFT:
      return NearlyEqual(lmargin + lindent, margin_ + first_indent_,
                         tolerance_);
    case JUSTIFICATION_RIGHT:
      return NearlyEqual(rmargin + rindent, margin_ + first_indent_,
                         tolerance_);
    case JUSTIFICATION_CENTER:
      return NearlyEqual(lindent, rindent, tolerance_ * 2);
    default:
      // shouldn't happen
      return false;
  }
}

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