Skip to content

Commit

Permalink
Merge pull request #2104 from stweil/fix
Browse files Browse the repository at this point in the history
Fix two runtime errors
  • Loading branch information
zdenop committed Dec 4, 2018
2 parents bee874a + c9e85ab commit ad40131
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 20 deletions.
54 changes: 35 additions & 19 deletions src/ccmain/ltrresultiterator.cpp
Expand Up @@ -171,27 +171,43 @@ const char* LTRResultIterator::WordFontAttributes(bool* is_bold,
bool* is_smallcaps,
int* pointsize,
int* font_id) const {
if (it_->word() == nullptr) return nullptr; // Already at the end!
float row_height = it_->row()->row->x_height() +
it_->row()->row->ascenders() - it_->row()->row->descenders();
// Convert from pixels to printers points.
*pointsize = scaled_yres_ > 0
? static_cast<int>(row_height * kPointsPerInch / scaled_yres_ + 0.5)
: 0;
if (it_->word()->fontinfo == nullptr) {
const char* result = nullptr;

if (it_->word()) {
// Already at the end!
*pointsize = 0;
} else {
float row_height = it_->row()->row->x_height() +
it_->row()->row->ascenders() - it_->row()->row->descenders();
// Convert from pixels to printers points.
*pointsize = scaled_yres_ > 0
? static_cast<int>(row_height * kPointsPerInch / scaled_yres_ + 0.5)
: 0;
const FontInfo* font_info = it_->word()->fontinfo;
if (font_info) {
// Font information available.
*font_id = font_info->universal_id;
*is_bold = font_info->is_bold();
*is_italic = font_info->is_italic();
*is_underlined = false; // TODO(rays) fix this!
*is_monospace = font_info->is_fixed_pitch();
*is_serif = font_info->is_serif();
*is_smallcaps = it_->word()->small_caps;
result = font_info->name;
}
}

if (!result) {
*is_bold = false;
*is_italic = false;
*is_underlined = false;
*is_monospace = false;
*is_serif = false;
*is_smallcaps = false;
*font_id = -1;
return nullptr; // No font information.
}
const FontInfo& font_info = *it_->word()->fontinfo;
*font_id = font_info.universal_id;
*is_bold = font_info.is_bold();
*is_italic = font_info.is_italic();
*is_underlined = false; // TODO(rays) fix this!
*is_monospace = font_info.is_fixed_pitch();
*is_serif = font_info.is_serif();
*is_smallcaps = it_->word()->small_caps;

return font_info.name;

return result;
}

// Returns the name of the language used to recognize this word.
Expand Down
5 changes: 4 additions & 1 deletion src/ccstruct/matrix.h
Expand Up @@ -81,7 +81,10 @@ class GENERIC_2D_ARRAY {

void operator=(const GENERIC_2D_ARRAY<T>& src) {
ResizeNoInit(src.dim1(), src.dim2());
memcpy(array_, src.array_, num_elements() * sizeof(array_[0]));
int size = num_elements();
if (size > 0) {
memcpy(array_, src.array_, size * sizeof(array_[0]));
}
}

// Reallocates the array to the given size. Does not keep old data, but does
Expand Down

0 comments on commit ad40131

Please sign in to comment.