Skip to content

Commit

Permalink
Jeff's fixes to pdf rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
theraysmith committed Apr 28, 2017
1 parent 13b7900 commit 7701552
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions api/pdfrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ CIDToGIDMap.
OK there is a small problem there, if I use GID 0 then Acrobat gets
upset about it and complains it cannot extract the font. If I set the
CIDToGIDMap so that all the entries are 1 instead, its happy. Totally
CIDToGIDMap so that all the entries are 1 instead, it's happy. Totally
mad......
*/
Expand All @@ -169,15 +169,15 @@ namespace tesseract {
// Use for PDF object fragments. Must be large enough
// to hold a colormap with 256 colors in the verbose
// PDF representation.
const int kBasicBufSize = 2048;
static const int kBasicBufSize = 2048;

// If the font is 10 pts, nominal character width is 5 pts
const int kCharWidth = 2;
static const int kCharWidth = 2;

// Used for memory allocation. A codepoint must take no more than this
// many bytes, when written in the PDF way. e.g. "<0063>" for the
// letter 'c'
const int kMaxBytesPerCodepoint = 20;
static const int kMaxBytesPerCodepoint = 20;

/**********************************************************************
* PDF Renderer interface implementation
Expand Down Expand Up @@ -309,18 +309,19 @@ void ClipBaseline(int ppi, int x1, int y1, int x2, int y2,
*line_y1 = *line_y2 = (y1 + y2) / 2;
}

bool CodepointToUtf16be(int code, char *utf16) {
bool CodepointToUtf16be(int code, char utf16[kMaxBytesPerCodepoint]) {
if ((code > 0xD7FF && code < 0xE000) || code > 0x10FFFF) {
tprintf("Dropping invalid codepoint %d\n", code);
return false;
}
if (code < 0x10000) {
snprintf(utf16, sizeof(utf16), "%04X", code);
snprintf(utf16, kMaxBytesPerCodepoint, "%04X", code);
} else {
int a = code - 0x010000;
int high_surrogate = (0x03FF & (a >> 10)) + 0xD800;
int low_surrogate = (0x03FF & a) + 0xDC00;
snprintf(utf16, sizeof(utf16), "%04X%04X", high_surrogate, low_surrogate);
snprintf(utf16, kMaxBytesPerCodepoint,
"%04X%04X", high_surrogate, low_surrogate);
}
return true;
}
Expand Down

0 comments on commit 7701552

Please sign in to comment.