|
47 | 47 | #include <cstring> // for strcmp, strcpy
|
48 | 48 | #include <fstream> // for size_t
|
49 | 49 | #include <iostream> // for std::cin
|
| 50 | +#include <locale> // for std::locale::classic |
50 | 51 | #include <memory> // for std::unique_ptr
|
51 | 52 | #include <set> // for std::pair
|
| 53 | +#include <sstream> // for std::stringstream |
52 | 54 | #include <vector> // for std::vector
|
53 | 55 | #include "allheaders.h" // for pixDestroy, boxCreate, boxaAddBox, box...
|
54 | 56 | #include "blobclass.h" // for ExtractFontName
|
@@ -1687,19 +1689,23 @@ char* TessBaseAPI::GetOsdText(int page_number) {
|
1687 | 1689 | // clockwise rotation needed to make the page upright
|
1688 | 1690 | int rotate = OrientationIdToValue(orient_deg / 90);
|
1689 | 1691 |
|
1690 |
| - const int kOsdBufsize = 255; |
1691 |
| - char* osd_buf = new char[kOsdBufsize]; |
1692 |
| - snprintf(osd_buf, kOsdBufsize, |
1693 |
| - "Page number: %d\n" |
1694 |
| - "Orientation in degrees: %d\n" |
1695 |
| - "Rotate: %d\n" |
1696 |
| - "Orientation confidence: %.2f\n" |
1697 |
| - "Script: %s\n" |
1698 |
| - "Script confidence: %.2f\n", |
1699 |
| - page_number, orient_deg, rotate, orient_conf, script_name, |
1700 |
| - script_conf); |
1701 |
| - |
1702 |
| - return osd_buf; |
| 1692 | + std::stringstream stream; |
| 1693 | + // Use "C" locale (needed for float values orient_conf and script_conf). |
| 1694 | + stream.imbue(std::locale::classic()); |
| 1695 | + // Use fixed notation with 2 digits after the decimal point for float values. |
| 1696 | + stream.precision(2); |
| 1697 | + stream |
| 1698 | + << std::fixed |
| 1699 | + << "Page number: " << page_number << "\n" |
| 1700 | + << "Orientation in degrees: " << orient_deg << "\n" |
| 1701 | + << "Rotate: " << rotate << "\n" |
| 1702 | + << "Orientation confidence: " << orient_conf << "\n" |
| 1703 | + << "Script: " << script_name << "\n" |
| 1704 | + << "Script confidence: " << script_conf << "\n"; |
| 1705 | + const std::string& text = stream.str(); |
| 1706 | + char* result = new char[text.length() + 1]; |
| 1707 | + strcpy(result, text.c_str()); |
| 1708 | + return result; |
1703 | 1709 | }
|
1704 | 1710 |
|
1705 | 1711 | #endif // ndef DISABLED_LEGACY_ENGINE
|
|
0 commit comments