All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ROW Class Reference

#include <ocrrow.h>

Inheritance diagram for ROW:
ELIST_LINK

Public Member Functions

 ROW ()
 
 ROW (inT32 spline_size, inT32 *xstarts, double *coeffs, float x_height, float ascenders, float descenders, inT16 kern, inT16 space)
 
 ROW (TO_ROW *row, inT16 kern, inT16 space)
 
WERD_LIST * word_list ()
 
float base_line (float xpos) const
 
float x_height () const
 
void set_x_height (float new_xheight)
 
inT32 kern () const
 
float body_size () const
 
void set_body_size (float new_size)
 
inT32 space () const
 
float ascenders () const
 
float descenders () const
 
TBOX bounding_box () const
 
TBOX restricted_bounding_box (bool upper_dots, bool lower_dots) const
 
void set_lmargin (inT16 lmargin)
 
void set_rmargin (inT16 rmargin)
 
inT16 lmargin () const
 
inT16 rmargin () const
 
void set_has_drop_cap (bool has)
 
bool has_drop_cap () const
 
void set_para (PARA *p)
 
PARApara () const
 
void recalc_bounding_box ()
 
void move (const ICOORD vec)
 
void print (FILE *fp)
 
void plot (ScrollView *window, ScrollView::Color colour)
 
void plot (ScrollView *window)
 
void plot_baseline (ScrollView *window, ScrollView::Color colour)
 
ROWoperator= (const ROW &source)
 
- Public Member Functions inherited from ELIST_LINK
 ELIST_LINK ()
 
 ELIST_LINK (const ELIST_LINK &)
 
void operator= (const ELIST_LINK &)
 

Friends

void tweak_row_baseline (ROW *, double, double)
 

Detailed Description

Definition at line 32 of file ocrrow.h.

Constructor & Destructor Documentation

ROW::ROW ( )
inline

Definition at line 36 of file ocrrow.h.

36  {
37  } //empty constructor
ROW::ROW ( inT32  spline_size,
inT32 xstarts,
double *  coeffs,
float  x_height,
float  ascenders,
float  descenders,
inT16  kern,
inT16  space 
)

Definition at line 35 of file ocrrow.cpp.

45  : baseline(spline_size, xstarts, coeffs),
46  para_(NULL) {
47  kerning = kern; //just store stuff
48  spacing = space;
49  xheight = x_height;
50  ascrise = ascenders;
51  bodysize = 0.0f;
52  descdrop = descenders;
53  has_drop_cap_ = false;
54  lmargin_ = 0;
55  rmargin_ = 0;
56 }
inT32 space() const
Definition: ocrrow.h:76
float ascenders() const
Definition: ocrrow.h:79
float x_height() const
Definition: ocrrow.h:61
inT32 kern() const
Definition: ocrrow.h:67
float descenders() const
Definition: ocrrow.h:82
#define NULL
Definition: host.h:144
ROW::ROW ( TO_ROW row,
inT16  kern,
inT16  space 
)

Definition at line 66 of file ocrrow.cpp.

70  : para_(NULL) {
71  kerning = kern; //just store stuff
72  spacing = space;
73  xheight = to_row->xheight;
74  bodysize = to_row->body_size;
75  ascrise = to_row->ascrise;
76  descdrop = to_row->descdrop;
77  baseline = to_row->baseline;
78  has_drop_cap_ = false;
79  lmargin_ = 0;
80  rmargin_ = 0;
81 }
inT32 space() const
Definition: ocrrow.h:76
inT32 kern() const
Definition: ocrrow.h:67
#define NULL
Definition: host.h:144

Member Function Documentation

float ROW::ascenders ( ) const
inline

Definition at line 79 of file ocrrow.h.

79  { //return size
80  return ascrise;
81  }
float ROW::base_line ( float  xpos) const
inline

Definition at line 56 of file ocrrow.h.

57  { //at the position
58  //get spline value
59  return (float) baseline.y (xpos);
60  }
float ROW::body_size ( ) const
inline

Definition at line 70 of file ocrrow.h.

70  { //return body size
71  return bodysize;
72  }
TBOX ROW::bounding_box ( ) const
inline

Definition at line 85 of file ocrrow.h.

85  { //return bounding box
86  return bound_box;
87  }
float ROW::descenders ( ) const
inline

Definition at line 82 of file ocrrow.h.

82  { //return size
83  return descdrop;
84  }
bool ROW::has_drop_cap ( ) const
inline

Definition at line 108 of file ocrrow.h.

108  {
109  return has_drop_cap_;
110  }
inT32 ROW::kern ( ) const
inline

Definition at line 67 of file ocrrow.h.

67  { //return kerning
68  return kerning;
69  }
inT16 ROW::lmargin ( ) const
inline

Definition at line 98 of file ocrrow.h.

98  {
99  return lmargin_;
100  }
void ROW::move ( const ICOORD  vec)

Definition at line 148 of file ocrrow.cpp.

150  {
151  WERD_IT it(&words); // word iterator
152 
153  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
154  it.data ()->move (vec);
155 
156  bound_box.move (vec);
157  baseline.move (vec);
158 }
void move(const ICOORD vec)
Definition: rect.h:153
ROW & ROW::operator= ( const ROW source)

Definition at line 226 of file ocrrow.cpp.

226  {
227  this->ELIST_LINK::operator= (source);
228  kerning = source.kerning;
229  spacing = source.spacing;
230  xheight = source.xheight;
231  bodysize = source.bodysize;
232  ascrise = source.ascrise;
233  descdrop = source.descdrop;
234  if (!words.empty ())
235  words.clear ();
236  baseline = source.baseline; //QSPLINES must do =
237  bound_box = source.bound_box;
238  has_drop_cap_ = source.has_drop_cap_;
239  lmargin_ = source.lmargin_;
240  rmargin_ = source.rmargin_;
241  para_ = source.para_;
242  return *this;
243 }
void operator=(const ELIST_LINK &)
Definition: elst.h:101
PARA* ROW::para ( ) const
inline

Definition at line 115 of file ocrrow.h.

115  {
116  return para_;
117  }
void ROW::plot ( ScrollView window,
ScrollView::Color  colour 
)

Definition at line 188 of file ocrrow.cpp.

191  {
192  WERD *word; //current word
193  WERD_IT it = &words; //words of ROW
194 
195  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
196  word = it.data ();
197  word->plot (window, colour); //all in one colour
198  }
199 }
Definition: werd.h:60
void plot(ScrollView *window, ScrollView::Color colour)
Definition: werd.cpp:297
void ROW::plot ( ScrollView window)

Definition at line 207 of file ocrrow.cpp.

209  {
210  WERD *word; //current word
211  WERD_IT it = &words; //words of ROW
212 
213  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
214  word = it.data ();
215  word->plot (window); //in rainbow colours
216  }
217 }
Definition: werd.h:60
void plot(ScrollView *window, ScrollView::Color colour)
Definition: werd.cpp:297
void ROW::plot_baseline ( ScrollView window,
ScrollView::Color  colour 
)
inline

Definition at line 134 of file ocrrow.h.

136  { //colour to draw
137  //draw it
138  baseline.plot (window, colour);
139  }
void ROW::print ( FILE *  fp)

Definition at line 167 of file ocrrow.cpp.

169  {
170  tprintf("Kerning= %d\n", kerning);
171  tprintf("Spacing= %d\n", spacing);
172  bound_box.print();
173  tprintf("Xheight= %f\n", xheight);
174  tprintf("Ascrise= %f\n", ascrise);
175  tprintf("Descdrop= %f\n", descdrop);
176  tprintf("has_drop_cap= %d\n", has_drop_cap_);
177  tprintf("lmargin= %d, rmargin= %d\n", lmargin_, rmargin_);
178 }
#define tprintf(...)
Definition: tprintf.h:31
void print() const
Definition: rect.h:270
void ROW::recalc_bounding_box ( )

Definition at line 101 of file ocrrow.cpp.

101  { //recalculate BB
102  WERD *word; //current word
103  WERD_IT it = &words; //words of ROW
104  inT16 left; //of word
105  inT16 prev_left; //old left
106 
107  if (!it.empty ()) {
108  word = it.data ();
109  prev_left = word->bounding_box ().left ();
110  it.forward ();
111  while (!it.at_first ()) {
112  word = it.data ();
113  left = word->bounding_box ().left ();
114  if (left < prev_left) {
115  it.move_to_first ();
116  //words in BB order
117  it.sort (word_comparator);
118  break;
119  }
120  prev_left = left;
121  it.forward ();
122  }
123  }
124  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
125  word = it.data ();
126  if (it.at_first ())
127  word->set_flag (W_BOL, TRUE);
128  else
129  //not start of line
130  word->set_flag (W_BOL, FALSE);
131  if (it.at_last ())
132  word->set_flag (W_EOL, TRUE);
133  else
134  //not end of line
135  word->set_flag (W_EOL, FALSE);
136  //extend BB as reqd
137  bound_box += word->bounding_box ();
138  }
139 }
int word_comparator(const void *word1p, const void *word2p)
Definition: werd.cpp:394
TBOX bounding_box() const
Definition: werd.cpp:160
Definition: werd.h:35
Definition: werd.h:36
inT16 left() const
Definition: rect.h:68
Definition: werd.h:60
#define FALSE
Definition: capi.h:29
#define TRUE
Definition: capi.h:28
void set_flag(WERD_FLAGS mask, BOOL8 value)
Definition: werd.h:129
short inT16
Definition: host.h:100
TBOX ROW::restricted_bounding_box ( bool  upper_dots,
bool  lower_dots 
) const

Definition at line 85 of file ocrrow.cpp.

85  {
86  TBOX box;
87  // This is a read-only iteration of the words in the row.
88  WERD_IT it(const_cast<WERD_LIST *>(&words));
89  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
90  box += it.data()->restricted_bounding_box(upper_dots, lower_dots);
91  }
92  return box;
93 }
Definition: rect.h:30
inT16 ROW::rmargin ( ) const
inline

Definition at line 101 of file ocrrow.h.

101  {
102  return rmargin_;
103  }
void ROW::set_body_size ( float  new_size)
inline

Definition at line 73 of file ocrrow.h.

73  { // set body size
74  bodysize = new_size;
75  }
void ROW::set_has_drop_cap ( bool  has)
inline

Definition at line 105 of file ocrrow.h.

105  {
106  has_drop_cap_ = has;
107  }
void ROW::set_lmargin ( inT16  lmargin)
inline

Definition at line 92 of file ocrrow.h.

92  {
93  lmargin_ = lmargin;
94  }
inT16 lmargin() const
Definition: ocrrow.h:98
void ROW::set_para ( PARA p)
inline

Definition at line 112 of file ocrrow.h.

112  {
113  para_ = p;
114  }
void ROW::set_rmargin ( inT16  rmargin)
inline

Definition at line 95 of file ocrrow.h.

95  {
96  rmargin_ = rmargin;
97  }
inT16 rmargin() const
Definition: ocrrow.h:101
void ROW::set_x_height ( float  new_xheight)
inline

Definition at line 64 of file ocrrow.h.

64  { // set x height
65  xheight = new_xheight;
66  }
inT32 ROW::space ( ) const
inline

Definition at line 76 of file ocrrow.h.

76  { //return spacing
77  return spacing;
78  }
WERD_LIST* ROW::word_list ( )
inline

Definition at line 52 of file ocrrow.h.

52  { //get words
53  return &words;
54  }
float ROW::x_height ( ) const
inline

Definition at line 61 of file ocrrow.h.

61  { //return x height
62  return xheight;
63  }

Friends And Related Function Documentation

void tweak_row_baseline ( ROW ,
double  ,
double   
)
friend

Definition at line 886 of file tordmain.cpp.

888  {
889  TBOX blob_box; //bounding box
890  C_BLOB *blob; //current blob
891  WERD *word; //current word
892  inT32 blob_count; //no of blobs
893  inT32 src_index; //source segment
894  inT32 dest_index; //destination segment
895  inT32 *xstarts; //spline segments
896  double *coeffs; //spline coeffs
897  float ydiff; //baseline error
898  float x_centre; //centre of blob
899  //words of row
900  WERD_IT word_it = row->word_list ();
901  C_BLOB_IT blob_it; //blob iterator
902 
903  blob_count = 0;
904  for (word_it.mark_cycle_pt (); !word_it.cycled_list (); word_it.forward ()) {
905  word = word_it.data (); //current word
906  //get total blobs
907  blob_count += word->cblob_list ()->length ();
908  }
909  if (blob_count == 0)
910  return;
911  xstarts =
912  (inT32 *) alloc_mem ((blob_count + row->baseline.segments + 1) *
913  sizeof (inT32));
914  coeffs =
915  (double *) alloc_mem ((blob_count + row->baseline.segments) * 3 *
916  sizeof (double));
917 
918  src_index = 0;
919  dest_index = 0;
920  xstarts[0] = row->baseline.xcoords[0];
921  for (word_it.mark_cycle_pt (); !word_it.cycled_list (); word_it.forward ()) {
922  word = word_it.data (); //current word
923  //blobs in word
924  blob_it.set_to_list (word->cblob_list ());
925  for (blob_it.mark_cycle_pt (); !blob_it.cycled_list ();
926  blob_it.forward ()) {
927  blob = blob_it.data ();
928  blob_box = blob->bounding_box ();
929  x_centre = (blob_box.left () + blob_box.right ()) / 2.0;
930  ydiff = blob_box.bottom () - row->base_line (x_centre);
931  if (ydiff < 0)
932  ydiff = -ydiff / row->x_height ();
933  else
934  ydiff = ydiff / row->x_height ();
935  if (ydiff < blshift_maxshift
936  && blob_box.height () / row->x_height () > blshift_xfraction) {
937  if (xstarts[dest_index] >= x_centre)
938  xstarts[dest_index] = blob_box.left ();
939  coeffs[dest_index * 3] = 0;
940  coeffs[dest_index * 3 + 1] = 0;
941  coeffs[dest_index * 3 + 2] = blob_box.bottom ();
942  //shift it
943  dest_index++;
944  xstarts[dest_index] = blob_box.right () + 1;
945  }
946  else {
947  if (xstarts[dest_index] <= x_centre) {
948  while (row->baseline.xcoords[src_index + 1] <= x_centre
949  && src_index < row->baseline.segments - 1) {
950  if (row->baseline.xcoords[src_index + 1] >
951  xstarts[dest_index]) {
952  coeffs[dest_index * 3] =
953  row->baseline.quadratics[src_index].a;
954  coeffs[dest_index * 3 + 1] =
955  row->baseline.quadratics[src_index].b;
956  coeffs[dest_index * 3 + 2] =
957  row->baseline.quadratics[src_index].c;
958  dest_index++;
959  xstarts[dest_index] =
960  row->baseline.xcoords[src_index + 1];
961  }
962  src_index++;
963  }
964  coeffs[dest_index * 3] =
965  row->baseline.quadratics[src_index].a;
966  coeffs[dest_index * 3 + 1] =
967  row->baseline.quadratics[src_index].b;
968  coeffs[dest_index * 3 + 2] =
969  row->baseline.quadratics[src_index].c;
970  dest_index++;
971  xstarts[dest_index] = row->baseline.xcoords[src_index + 1];
972  }
973  }
974  }
975  }
976  while (src_index < row->baseline.segments
977  && row->baseline.xcoords[src_index + 1] <= xstarts[dest_index])
978  src_index++;
979  while (src_index < row->baseline.segments) {
980  coeffs[dest_index * 3] = row->baseline.quadratics[src_index].a;
981  coeffs[dest_index * 3 + 1] = row->baseline.quadratics[src_index].b;
982  coeffs[dest_index * 3 + 2] = row->baseline.quadratics[src_index].c;
983  dest_index++;
984  src_index++;
985  xstarts[dest_index] = row->baseline.xcoords[src_index];
986  }
987  //turn to spline
988  row->baseline = QSPLINE (dest_index, xstarts, coeffs);
989  free_mem(xstarts);
990  free_mem(coeffs);
991 }
double a
Definition: quadratc.h:58
float c
Definition: quadratc.h:60
void free_mem(void *oldchunk)
Definition: memry.cpp:55
float x_height() const
Definition: ocrrow.h:61
inT16 right() const
Definition: rect.h:75
float base_line(float xpos) const
Definition: ocrrow.h:56
inT16 left() const
Definition: rect.h:68
Definition: werd.h:60
inT16 bottom() const
Definition: rect.h:61
inT16 height() const
Definition: rect.h:104
Definition: rect.h:30
TBOX bounding_box() const
Definition: stepblob.cpp:250
void * alloc_mem(inT32 count)
Definition: memry.cpp:47
float b
Definition: quadratc.h:59
C_BLOB_LIST * cblob_list()
Definition: werd.h:100
WERD_LIST * word_list()
Definition: ocrrow.h:52
int inT32
Definition: host.h:102

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