1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-12-22 13:00:08 +00:00

make sure contents are cleared in TextLineBuffer::flush

This commit is contained in:
Lu Wang 2013-04-03 16:28:06 +08:00
parent eaa3b35cfd
commit 5102e8c3e0
2 changed files with 12 additions and 4 deletions

View File

@ -66,7 +66,12 @@ void HTMLRenderer::TextLineBuffer::flush(void)
* Each Line is an independent absolute positioned block * Each Line is an independent absolute positioned block
* so even we have a few states or offsets, we may omit them * so even we have a few states or offsets, we may omit them
*/ */
if(text.empty()) return; if(text.empty())
{
states.clear();
offsets.clear();
return;
}
while((!states.empty()) && (states.back().start_idx >= text.size())) while((!states.empty()) && (states.back().start_idx >= text.size()))
states.pop_back(); states.pop_back();
@ -74,6 +79,8 @@ void HTMLRenderer::TextLineBuffer::flush(void)
if(states.empty() || (states[0].start_idx != 0)) if(states.empty() || (states[0].start_idx != 0))
{ {
cerr << "Warning: text without a style! Must be a bug in pdf2htmlEX" << endl; cerr << "Warning: text without a style! Must be a bug in pdf2htmlEX" << endl;
text.clear();
offsets.clear();
return; return;
} }
@ -265,7 +272,7 @@ void HTMLRenderer::TextLineBuffer::optimize()
ws_manager.set_eps(EPS); ws_manager.set_eps(EPS);
// statistics of widths // statistics of widths
std::map<double, int> width_map; std::map<double, size_t> width_map;
// store optimized offsets // store optimized offsets
std::vector<Offset> new_offsets; std::vector<Offset> new_offsets;
new_offsets.reserve(offsets.size()); new_offsets.reserve(offsets.size());
@ -320,7 +327,7 @@ void HTMLRenderer::TextLineBuffer::optimize()
} }
double most_used_width = 0; double most_used_width = 0;
int max_count = 0; size_t max_count = 0;
for(auto iter = width_map.begin(); iter != width_map.end(); ++iter) for(auto iter = width_map.begin(); iter != width_map.end(); ++iter)
{ {
if(iter->second > max_count) if(iter->second > max_count)
@ -385,7 +392,7 @@ void HTMLRenderer::TextLineBuffer::optimize()
double threshold = (state_iter1->em_size()) * (renderer->param->space_threshold); double threshold = (state_iter1->em_size()) * (renderer->param->space_threshold);
// set word_space for the most frequently used offset // set word_space for the most frequently used offset
double most_used_width = 0; double most_used_width = 0;
int max_count = 0; size_t max_count = 0;
// if offset_count > 0, we must have updated width_map in the previous step // if offset_count > 0, we must have updated width_map in the previous step
// find the most frequent width, with new letter space applied // find the most frequent width, with new letter space applied

View File

@ -26,6 +26,7 @@ void HTMLRenderer::drawString(GfxState * state, GooString * s)
return; return;
auto font = state->getFont(); auto font = state->getFont();
// unscaled
double cur_letter_space = state->getCharSpace(); double cur_letter_space = state->getCharSpace();
double cur_word_space = state->getWordSpace(); double cur_word_space = state->getWordSpace();