tesseract  5.0.0-alpha-619-ge9db
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  }

◆ 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 79 of file ocrpara.cpp.

79  {
80  if (justification_ != other.justification_)
81  return false;
82  if (justification_ == JUSTIFICATION_CENTER ||
83  justification_ == JUSTIFICATION_UNKNOWN)
84  return true;
85  int tolerance = (tolerance_ + other.tolerance_) / 4;
86  return NearlyEqual(margin_ + first_indent_,
87  other.margin_ + other.first_indent_, tolerance) &&
88  NearlyEqual(margin_ + body_indent_,
89  other.margin_ + other.body_indent_, tolerance);
90 }

◆ 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 92 of file ocrpara.cpp.

92  {
93  char buffer[200];
94  const STRING &alignment = ParagraphJustificationToString(justification_);
95  snprintf(buffer, sizeof(buffer),
96  "margin: %d, first_indent: %d, body_indent: %d, alignment: %s",
97  margin_, first_indent_, body_indent_, alignment.c_str());
98  return STRING(buffer);
99 }

◆ ValidBodyLine()

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

Definition at line 62 of file ocrpara.cpp.

63  {
64  switch (justification_) {
65  case JUSTIFICATION_LEFT:
66  return NearlyEqual(lmargin + lindent, margin_ + body_indent_,
67  tolerance_);
69  return NearlyEqual(rmargin + rindent, margin_ + body_indent_,
70  tolerance_);
72  return NearlyEqual(lindent, rindent, tolerance_ * 2);
73  default:
74  // shouldn't happen
75  return false;
76  }
77 }

◆ ValidFirstLine()

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

Definition at line 45 of file ocrpara.cpp.

46  {
47  switch (justification_) {
48  case JUSTIFICATION_LEFT:
49  return NearlyEqual(lmargin + lindent, margin_ + first_indent_,
50  tolerance_);
52  return NearlyEqual(rmargin + rindent, margin_ + first_indent_,
53  tolerance_);
55  return NearlyEqual(lindent, rindent, tolerance_ * 2);
56  default:
57  // shouldn't happen
58  return false;
59  }
60 }

The documentation for this class was generated from the following files:
ParagraphModel::body_indent
int body_indent() const
Definition: ocrpara.h:169
JUSTIFICATION_UNKNOWN
Definition: capi.h:132
tesseract::JUSTIFICATION_RIGHT
Definition: publictypes.h:252
NearlyEqual
bool NearlyEqual(T x, T y, T tolerance)
Definition: host.h:36
STRING
Definition: strngs.h:45
JUSTIFICATION_LEFT
Definition: capi.h:133
ParagraphModel::first_indent
int first_indent() const
Definition: ocrpara.h:168
tesseract::JUSTIFICATION_LEFT
Definition: publictypes.h:250
ParagraphModel::tolerance
int tolerance() const
Definition: ocrpara.h:170
STRING::c_str
const char * c_str() const
Definition: strngs.cpp:192
tesseract::JUSTIFICATION_UNKNOWN
Definition: publictypes.h:249
JUSTIFICATION_CENTER
Definition: capi.h:134
JUSTIFICATION_RIGHT
Definition: capi.h:135
ParagraphModel::justification
tesseract::ParagraphJustification justification() const
Definition: ocrpara.h:164
ParagraphModel::margin
int margin() const
Definition: ocrpara.h:167