tesseract  4.00.00dev
ParagraphModel Class Reference

#include <ocrpara.h>

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() [1/2]

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

Definition at line 116 of file ocrpara.h.

121  : justification_(justification),
122  margin_(margin),
123  first_indent_(first_indent),
124  body_indent_(body_indent),
125  tolerance_(tolerance) {
126  // Make one of {first_indent, body_indent} is 0.
127  int added_margin = first_indent;
128  if (body_indent < added_margin)
129  added_margin = body_indent;
130  margin_ += added_margin;
131  first_indent_ -= added_margin;
132  body_indent_ -= added_margin;
133  }
tesseract::ParagraphJustification justification() const
Definition: ocrpara.h:164
int tolerance() const
Definition: ocrpara.h:170
int body_indent() const
Definition: ocrpara.h:169
int first_indent() const
Definition: ocrpara.h:168
int margin() const
Definition: ocrpara.h:167

◆ ParagraphModel() [2/2]

ParagraphModel::ParagraphModel ( )
inline

Definition at line 135 of file ocrpara.h.

136  : justification_(tesseract::JUSTIFICATION_UNKNOWN),
137  margin_(0),
138  first_indent_(0),
139  body_indent_(0),
140  tolerance_(0) { }

Member Function Documentation

◆ body_indent()

int ParagraphModel::body_indent ( ) const
inline

Definition at line 169 of file ocrpara.h.

169 { return body_indent_; }

◆ Comparable()

bool ParagraphModel::Comparable ( const ParagraphModel other) const

Definition at line 80 of file ocrpara.cpp.

80  {
81  if (justification_ != other.justification_)
82  return false;
83  if (justification_ == JUSTIFICATION_CENTER ||
84  justification_ == JUSTIFICATION_UNKNOWN)
85  return true;
86  int tolerance = (tolerance_ + other.tolerance_) / 4;
87  return NearlyEqual(margin_ + first_indent_,
88  other.margin_ + other.first_indent_, tolerance) &&
89  NearlyEqual(margin_ + body_indent_,
90  other.margin_ + other.body_indent_, tolerance);
91 }
int tolerance() const
Definition: ocrpara.h:170
bool NearlyEqual(T x, T y, T tolerance)
Definition: host.h:87

◆ first_indent()

int ParagraphModel::first_indent ( ) const
inline

Definition at line 168 of file ocrpara.h.

168 { return first_indent_; }

◆ is_flush()

bool ParagraphModel::is_flush ( ) const
inline

Definition at line 171 of file ocrpara.h.

171  {
172  return (justification_ == tesseract::JUSTIFICATION_LEFT ||
173  justification_ == tesseract::JUSTIFICATION_RIGHT) &&
174  abs(first_indent_ - body_indent_) <= tolerance_;
175  }

◆ justification()

tesseract::ParagraphJustification ParagraphModel::justification ( ) const
inline

Definition at line 164 of file ocrpara.h.

164  {
165  return justification_;
166  }

◆ margin()

int ParagraphModel::margin ( ) const
inline

Definition at line 167 of file ocrpara.h.

167 { return margin_; }

◆ tolerance()

int ParagraphModel::tolerance ( ) const
inline

Definition at line 170 of file ocrpara.h.

170 { return tolerance_; }

◆ ToString()

STRING ParagraphModel::ToString ( ) const

Definition at line 93 of file ocrpara.cpp.

93  {
94  char buffer[200];
95  const STRING &alignment = ParagraphJustificationToString(justification_);
96  snprintf(buffer, sizeof(buffer),
97  "margin: %d, first_indent: %d, body_indent: %d, alignment: %s",
98  margin_, first_indent_, body_indent_, alignment.string());
99  return STRING(buffer);
100 }
const char * string() const
Definition: strngs.cpp:198
Definition: strngs.h:45

◆ ValidBodyLine()

bool ParagraphModel::ValidBodyLine ( int  lmargin,
int  lindent,
int  rindent,
int  rmargin 
) const

Definition at line 63 of file ocrpara.cpp.

64  {
65  switch (justification_) {
66  case JUSTIFICATION_LEFT:
67  return NearlyEqual(lmargin + lindent, margin_ + body_indent_,
68  tolerance_);
70  return NearlyEqual(rmargin + rindent, margin_ + body_indent_,
71  tolerance_);
73  return NearlyEqual(lindent, rindent, tolerance_ * 2);
74  default:
75  // shouldn't happen
76  return false;
77  }
78 }
bool NearlyEqual(T x, T y, T tolerance)
Definition: host.h:87

◆ ValidFirstLine()

bool ParagraphModel::ValidFirstLine ( int  lmargin,
int  lindent,
int  rindent,
int  rmargin 
) const

Definition at line 46 of file ocrpara.cpp.

47  {
48  switch (justification_) {
49  case JUSTIFICATION_LEFT:
50  return NearlyEqual(lmargin + lindent, margin_ + first_indent_,
51  tolerance_);
53  return NearlyEqual(rmargin + rindent, margin_ + first_indent_,
54  tolerance_);
56  return NearlyEqual(lindent, rindent, tolerance_ * 2);
57  default:
58  // shouldn't happen
59  return false;
60  }
61 }
bool NearlyEqual(T x, T y, T tolerance)
Definition: host.h:87

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