25 #include "allheaders.h"
42 x_scale_ = y_scale_ = scaling;
58 x_scale_ = y_scale_ = scaling;
59 SetSegments(seg_pts, seg_count);
73 inverse_ = src.inverse_;
77 if (src.rotation_ ==
NULL)
80 rotation_ =
new FCOORD(*src.rotation_);
81 predecessor_ = src.predecessor_;
82 SetSegments(src.segs_, src.num_segs_);
83 x_origin_ = src.x_origin_;
84 y_origin_ = src.y_origin_;
85 x_scale_ = src.x_scale_;
86 y_scale_ = src.y_scale_;
87 final_xshift_ = src.final_xshift_;
88 final_yshift_ = src.final_yshift_;
100 float x_height,
const TBOX& word_box,
103 float x_origin = (word_box.
left() + word_box.
right()) / 2.0
f;
104 float y_origin = 0.0f;
105 if (num_segs == 0 && row ==
NULL) {
106 y_origin = word_box.
bottom();
109 x_origin, y_origin, scale, scale,
146 const DENORM* predecessor,
148 float x_origin,
float y_origin,
149 float x_scale,
float y_scale,
150 float final_xshift,
float final_yshift) {
154 if (rotation ==
NULL)
157 rotation_ =
new FCOORD(*rotation);
159 SetSegments(segs, num_segs);
160 x_origin_ = x_origin;
161 y_origin_ = y_origin;
164 final_xshift_ = final_xshift;
165 final_yshift_ = final_yshift;
178 FCOORD translated(pt.
x() - x_origin_, pt.
y() - YOriginAtOrigX(pt.
x()));
179 translated.
set_x(translated.
x() * x_scale_);
180 translated.
set_y(translated.
y() * YScaleAtOrigX(pt.
x()));
181 if (rotation_ !=
NULL)
182 translated.
rotate(*rotation_);
183 transformed->
set_x(translated.
x() + final_xshift_);
184 transformed->
set_y(translated.
y() + final_yshift_);
199 if (predecessor_ !=
NULL) {
201 }
else if (block_ !=
NULL) {
203 src_pt.
rotate(fwd_rotation);
218 FCOORD rotated(pt.
x() - final_xshift_, pt.
y() - final_yshift_);
219 if (rotation_ !=
NULL) {
220 FCOORD inverse_rotation(rotation_->
x(), -rotation_->
y());
221 rotated.
rotate(inverse_rotation);
223 original->
set_x(rotated.x() / x_scale_ + x_origin_);
226 y_scale = YScaleAtOrigX(original->
x());
227 original->
set_y(rotated.y() / y_scale + YOriginAtOrigX(original->
x()));
242 if (predecessor_ !=
NULL) {
244 }
else if (block_ !=
NULL) {
253 float x_center = (blob_box.
left() + blob_box.
right()) / 2.0
f;
256 blob->
Move(translation);
259 float scale = YScaleAtOrigX(x_center);
262 if (rotation_ !=
NULL)
266 blob->
Move(translation);
283 int min_bottom, max_bottom, min_top, max_top;
292 if (bottom < min_bottom - tolerance || bottom > max_bottom + tolerance) {
301 double min_height = min_top - kBlnBaselineOffset - tolerance;
302 double max_height = max_top - kBlnBaselineOffset + tolerance;
303 if (min_height <= 0.0) {
304 if (height <= 0 || max_height > 0)
306 }
else if (height > 0) {
310 if (max_height > 0.0 && height > 0) {
320 void DENORM::Clear() {
326 if (rotation_ !=
NULL) {
333 void DENORM::Init() {
346 final_xshift_ = 0.0f;
351 float DENORM::YOriginAtOrigX(
float orig_x)
const {
353 const DENORM_SEG* seg = BinarySearchSegment(orig_x);
359 return row_->
base_line(orig_x) + y_origin_;
365 float DENORM::YScaleAtOrigX(
float orig_x)
const {
367 const DENORM_SEG* seg = BinarySearchSegment(orig_x);
385 void DENORM::SetSegments(
const DENORM_SEG* new_segs,
int seg_count) {
390 memcpy(segs_, new_segs, seg_count *
sizeof(new_segs[0]));
393 qsort(segs_, num_segs_,
sizeof(segs_[0]),
394 reinterpret_cast<int(*)(
const void*,
const void*)
>(
395 &CompareSegByXStart));
403 const DENORM_SEG* DENORM::BinarySearchSegment(
float orig_x)
const {
404 int bottom, top, middle;
408 middle = (bottom + top) / 2;
409 if (segs_[middle].xstart > orig_x)
414 while (top - bottom > 1);
415 return &segs_[bottom];