| 332 | } |
| 333 | |
| 334 | char* TessPDFRenderer::GetPDFTextObjects(TessBaseAPI* api, |
| 335 | double width, double height) { |
| 336 | STRING pdf_str(""); |
| 337 | double ppi = api->GetSourceYResolution(); |
| 338 | |
| 339 | // These initial conditions are all arbitrary and will be overwritten |
| 340 | double old_x = 0.0, old_y = 0.0; |
| 341 | int old_fontsize = 0; |
| 342 | tesseract::WritingDirection old_writing_direction = |
| 343 | WRITING_DIRECTION_LEFT_TO_RIGHT; |
| 344 | bool new_block = true; |
| 345 | int fontsize = 0; |
| 346 | double a = 1; |
| 347 | double b = 0; |
| 348 | double c = 0; |
| 349 | double d = 1; |
| 350 | |
| 351 | // TODO(jbreiden) This marries the text and image together. |
| 352 | // Slightly cleaner from an abstraction standpoint if this were to |
| 353 | // live inside a separate text object. |
| 354 | pdf_str += "q "; |
| 355 | pdf_str.add_str_double("", prec(width)); |
| 356 | pdf_str += " 0 0 "; |
| 357 | pdf_str.add_str_double("", prec(height)); |
| 358 | pdf_str += " 0 0 cm"; |
| 359 | if (!textonly_) { |
| 360 | pdf_str += " /Im1 Do"; |
| 361 | } |
| 362 | pdf_str += " Q\n"; |
| 363 | |
| 364 | int line_x1 = 0; |
| 365 | int line_y1 = 0; |
| 366 | int line_x2 = 0; |
| 367 | int line_y2 = 0; |
| 368 | |
| 369 | ResultIterator *res_it = api->GetIterator(); |
| 370 | while (!res_it->Empty(RIL_BLOCK)) { |
| 371 | if (res_it->IsAtBeginningOf(RIL_BLOCK)) { |
| 372 | pdf_str += "BT\n3 Tr"; // Begin text object, use invisible ink |
| 373 | old_fontsize = 0; // Every block will declare its fontsize |
| 374 | new_block = true; // Every block will declare its affine matrix |
| 375 | } |
| 376 | |
| 377 | if (res_it->IsAtBeginningOf(RIL_TEXTLINE)) { |
| 378 | int x1, y1, x2, y2; |
| 379 | res_it->Baseline(RIL_TEXTLINE, &x1, &y1, &x2, &y2); |
| 380 | ClipBaseline(ppi, x1, y1, x2, y2, &line_x1, &line_y1, &line_x2, &line_y2); |
| 381 | } |
| 382 | |
| 383 | if (res_it->Empty(RIL_WORD)) { |
| 384 | res_it->Next(RIL_WORD); |
| 385 | continue; |
| 386 | } |
| 387 | |
| 388 | // Writing direction changes at a per-word granularity |
| 389 | tesseract::WritingDirection writing_direction; |
| 390 | { |
| 391 | tesseract::Orientation orientation; |
nothing calls this directly
no test coverage detected