tesseract v5.3.3.20231005
tesseract::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
 
std::string ToString () const
 

Detailed Description

Definition at line 118 of file ocrpara.h.

Constructor & Destructor Documentation

◆ ParagraphModel() [1/2]

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

Definition at line 120 of file ocrpara.h.

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

◆ ParagraphModel() [2/2]

tesseract::ParagraphModel::ParagraphModel ( )
inline

Definition at line 137 of file ocrpara.h.

138 : justification_(tesseract::JUSTIFICATION_UNKNOWN)
139 , margin_(0)
140 , first_indent_(0)
141 , body_indent_(0)
142 , tolerance_(0) {}
@ JUSTIFICATION_UNKNOWN
Definition: publictypes.h:247

Member Function Documentation

◆ body_indent()

int tesseract::ParagraphModel::body_indent ( ) const
inline

Definition at line 175 of file ocrpara.h.

175 {
176 return body_indent_;
177 }

◆ Comparable()

bool tesseract::ParagraphModel::Comparable ( const ParagraphModel other) const

Definition at line 73 of file ocrpara.cpp.

73 {
74 if (justification_ != other.justification_) {
75 return false;
76 }
77 if (justification_ == JUSTIFICATION_CENTER || justification_ == JUSTIFICATION_UNKNOWN) {
78 return true;
79 }
80 int tolerance = (tolerance_ + other.tolerance_) / 4;
81 return NearlyEqual(margin_ + first_indent_, other.margin_ + other.first_indent_, tolerance) &&
82 NearlyEqual(margin_ + body_indent_, other.margin_ + other.body_indent_, tolerance);
83}
bool NearlyEqual(T x, T y, T tolerance)
Definition: host.h:51
@ JUSTIFICATION_CENTER
Definition: publictypes.h:249

◆ first_indent()

int tesseract::ParagraphModel::first_indent ( ) const
inline

Definition at line 172 of file ocrpara.h.

172 {
173 return first_indent_;
174 }

◆ is_flush()

bool tesseract::ParagraphModel::is_flush ( ) const
inline

Definition at line 181 of file ocrpara.h.

181 {
182 return (justification_ == tesseract::JUSTIFICATION_LEFT ||
183 justification_ == tesseract::JUSTIFICATION_RIGHT) &&
184 abs(first_indent_ - body_indent_) <= tolerance_;
185 }
@ JUSTIFICATION_LEFT
Definition: publictypes.h:248
@ JUSTIFICATION_RIGHT
Definition: publictypes.h:250

◆ justification()

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

Definition at line 166 of file ocrpara.h.

166 {
167 return justification_;
168 }

◆ margin()

int tesseract::ParagraphModel::margin ( ) const
inline

Definition at line 169 of file ocrpara.h.

169 {
170 return margin_;
171 }

◆ tolerance()

int tesseract::ParagraphModel::tolerance ( ) const
inline

Definition at line 178 of file ocrpara.h.

178 {
179 return tolerance_;
180 }

◆ ToString()

std::string tesseract::ParagraphModel::ToString ( ) const

Definition at line 85 of file ocrpara.cpp.

85 {
86 char buffer[200];
87 const char *alignment = ParagraphJustificationToString(justification_);
88 snprintf(buffer, sizeof(buffer), "margin: %d, first_indent: %d, body_indent: %d, alignment: %s",
89 margin_, first_indent_, body_indent_, alignment);
90 return std::string(buffer);
91}

◆ ValidBodyLine()

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

Definition at line 59 of file ocrpara.cpp.

59 {
60 switch (justification_) {
62 return NearlyEqual(lmargin + lindent, margin_ + body_indent_, tolerance_);
64 return NearlyEqual(rmargin + rindent, margin_ + body_indent_, tolerance_);
66 return NearlyEqual(lindent, rindent, tolerance_ * 2);
67 default:
68 // shouldn't happen
69 return false;
70 }
71}

◆ ValidFirstLine()

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

Definition at line 45 of file ocrpara.cpp.

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

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