MCPcopy Create free account
hub / github.com/creatale/node-dv / ClipBaseline

Function ClipBaseline

deps/tesseract/api/pdfrenderer.cpp:304–315  ·  view source on GitHub ↗

There are some really awkward PDF viewers in the wild, such as 'Preview' which ships with the Mac. They do a better job with text selection and highlighting when given perfectly flat baseline instead of very slightly tilted. We clip small tilts to appease these viewers. I chose this threshold large enough to absorb noise, but small enough that lines probably won't cross each other if the whole pag

Source from the content-addressed store, hash-verified

302// but small enough that lines probably won't cross each other if the
303// whole page is tilted at almost exactly the clipping threshold.
304void ClipBaseline(int ppi, int x1, int y1, int x2, int y2,
305 int *line_x1, int *line_y1,
306 int *line_x2, int *line_y2) {
307 *line_x1 = x1;
308 *line_y1 = y1;
309 *line_x2 = x2;
310 *line_y2 = y2;
311 double rise = abs(y2 - y1) * 72 / ppi;
312 double run = abs(x2 - x1) * 72 / ppi;
313 if (rise < 2.0 && 2.0 < run)
314 *line_y1 = *line_y2 = (y1 + y2) / 2;
315}
316
317bool CodepointToUtf16be(int code, char utf16[kMaxBytesPerCodepoint]) {
318 if ((code > 0xD7FF && code < 0xE000) || code > 0x10FFFF) {

Callers 1

GetPDFTextObjectsMethod · 0.85

Calls 1

absFunction · 0.50

Tested by

no test coverage detected