All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
blkocc.cpp File Reference
#include <ctype.h>
#include <math.h>
#include "errcode.h"
#include "drawtord.h"
#include "blkocc.h"
#include "helpers.h"

Go to the source code of this file.

Functions

BOOL8 test_underline (BOOL8 testing_on, C_BLOB *blob, inT16 baseline, inT16 xheight)
 

Variables

double textord_underline_threshold = 0.5
 

Function Documentation

BOOL8 test_underline ( BOOL8  testing_on,
C_BLOB blob,
inT16  baseline,
inT16  xheight 
)

test_underline

Check to see if the blob is an underline. Return TRUE if it is.

Definition at line 53 of file blkocc.cpp.

58  {
59  inT16 occ;
60  inT16 blob_width; //width of blob
61  TBOX blob_box; //bounding box
62  inT32 desc_occ;
63  inT32 x_occ;
64  inT32 asc_occ;
65  STATS projection;
66 
67  blob_box = blob->bounding_box ();
68  blob_width = blob->bounding_box ().width ();
69  projection.set_range (blob_box.bottom (), blob_box.top () + 1);
70  if (testing_on) {
71  // blob->plot(to_win,GOLDENROD,GOLDENROD);
72  // line_color_index(to_win,GOLDENROD);
73  // move2d(to_win,blob_box.left(),baseline);
74  // draw2d(to_win,blob_box.right(),baseline);
75  // move2d(to_win,blob_box.left(),baseline+xheight);
76  // draw2d(to_win,blob_box.right(),baseline+xheight);
77  tprintf
78  ("Testing underline on blob at (%d,%d)->(%d,%d), base=%d\nOccs:",
79  blob->bounding_box ().left (), blob->bounding_box ().bottom (),
80  blob->bounding_box ().right (), blob->bounding_box ().top (),
81  baseline);
82  }
83  horizontal_cblob_projection(blob, &projection);
84  desc_occ = 0;
85  for (occ = blob_box.bottom (); occ < baseline; occ++)
86  if (occ <= blob_box.top () && projection.pile_count (occ) > desc_occ)
87  //max in region
88  desc_occ = projection.pile_count (occ);
89  x_occ = 0;
90  for (occ = baseline; occ <= baseline + xheight; occ++)
91  if (occ >= blob_box.bottom () && occ <= blob_box.top ()
92  && projection.pile_count (occ) > x_occ)
93  //max in region
94  x_occ = projection.pile_count (occ);
95  asc_occ = 0;
96  for (occ = baseline + xheight + 1; occ <= blob_box.top (); occ++)
97  if (occ >= blob_box.bottom () && projection.pile_count (occ) > asc_occ)
98  asc_occ = projection.pile_count (occ);
99  if (testing_on) {
100  tprintf ("%d %d %d\n", desc_occ, x_occ, asc_occ);
101  }
102  if (desc_occ == 0 && x_occ == 0 && asc_occ == 0) {
103  tprintf ("Bottom=%d, top=%d, base=%d, x=%d\n",
104  blob_box.bottom (), blob_box.top (), baseline, xheight);
105  projection.print();
106  }
107  if (desc_occ > x_occ + x_occ
108  && desc_occ > blob_width * textord_underline_threshold)
109  return TRUE; //real underline
110  if (asc_occ > x_occ + x_occ
111  && asc_occ > blob_width * textord_underline_threshold)
112  return TRUE; //overline
113  return FALSE; //neither
114 }
#define tprintf(...)
Definition: tprintf.h:31
Definition: statistc.h:33
double textord_underline_threshold
Definition: blkocc.cpp:38
inT16 right() const
Definition: rect.h:75
inT16 left() const
Definition: rect.h:68
inT16 bottom() const
Definition: rect.h:61
inT16 width() const
Definition: rect.h:111
#define FALSE
Definition: capi.h:29
Definition: rect.h:30
#define TRUE
Definition: capi.h:28
bool set_range(inT32 min_bucket_value, inT32 max_bucket_value_plus_1)
Definition: statistc.cpp:62
TBOX bounding_box() const
Definition: stepblob.cpp:250
inT32 pile_count(inT32 value) const
Definition: statistc.h:78
void print() const
Definition: statistc.cpp:538
inT16 top() const
Definition: rect.h:54
short inT16
Definition: host.h:100
int inT32
Definition: host.h:102

Variable Documentation

double textord_underline_threshold = 0.5

"Fraction of width occupied"

Definition at line 38 of file blkocc.cpp.