mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-12-22 04:50:09 +00:00
separate TextLineBuffer
This commit is contained in:
parent
add1d1e28e
commit
5842d2279d
@ -151,7 +151,8 @@ add_executable(pdf2htmlEX
|
||||
src/HTMLRenderer/general.cc
|
||||
src/HTMLRenderer/image.cc
|
||||
src/HTMLRenderer/install.cc
|
||||
src/HTMLRenderer/LineBuffer.cc
|
||||
src/HTMLRenderer/TextLineBuffer.h
|
||||
src/HTMLRenderer/TextLineBuffer.cc
|
||||
src/HTMLRenderer/link.cc
|
||||
src/HTMLRenderer/state.cc
|
||||
src/HTMLRenderer/text.cc
|
||||
|
@ -379,73 +379,9 @@ class HTMLRenderer : public OutputDev
|
||||
double draw_tx, draw_ty;
|
||||
|
||||
// some metrics have to be determined after all elements in the lines have been seen
|
||||
class LineBuffer {
|
||||
public:
|
||||
LineBuffer (HTMLRenderer * renderer) : renderer(renderer) { }
|
||||
|
||||
class State {
|
||||
public:
|
||||
void begin(std::ostream & out, const State * prev_state);
|
||||
void end(std::ostream & out) const;
|
||||
void hash(void);
|
||||
int diff(const State & s) const;
|
||||
|
||||
enum {
|
||||
FONT_ID,
|
||||
FONT_SIZE_ID,
|
||||
COLOR_ID,
|
||||
LETTER_SPACE_ID,
|
||||
WORD_SPACE_ID,
|
||||
RISE_ID,
|
||||
|
||||
ID_COUNT
|
||||
};
|
||||
|
||||
long long ids[ID_COUNT];
|
||||
|
||||
double ascent;
|
||||
double descent;
|
||||
double draw_font_size;
|
||||
|
||||
size_t start_idx; // index of the first Text using this state
|
||||
// for optimzation
|
||||
long long hash_value;
|
||||
bool need_close;
|
||||
|
||||
static const char * format_str; // class names for each id
|
||||
};
|
||||
|
||||
|
||||
class Offset {
|
||||
public:
|
||||
size_t start_idx; // should put this idx before text[start_idx];
|
||||
double width;
|
||||
};
|
||||
|
||||
void reset(GfxState * state);
|
||||
void append_unicodes(const Unicode * u, int l);
|
||||
void append_offset(double width);
|
||||
void append_state(void);
|
||||
void flush(void);
|
||||
|
||||
private:
|
||||
// retrieve state from renderer
|
||||
void set_state(State & state);
|
||||
|
||||
HTMLRenderer * renderer;
|
||||
|
||||
double x, y;
|
||||
long long tm_id;
|
||||
|
||||
std::vector<State> states;
|
||||
std::vector<Offset> offsets;
|
||||
std::vector<Unicode> text;
|
||||
|
||||
// for flush
|
||||
std::vector<State*> stack;
|
||||
|
||||
} line_buf;
|
||||
friend class LineBuffer;
|
||||
class TextLineBuffer;
|
||||
friend class TextLineBuffer;
|
||||
TextLineBuffer * text_line_buf;
|
||||
|
||||
// for font reencoding
|
||||
int32_t * cur_mapping;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* LineBuffer.cc
|
||||
* TextLineBuffer.cc
|
||||
*
|
||||
* Generate and optimized HTML for one line
|
||||
*
|
||||
@ -10,6 +10,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "HTMLRenderer.h"
|
||||
#include "TextLineBuffer.h"
|
||||
#include "util/namespace.h"
|
||||
#include "util/unicode.h"
|
||||
#include "util/math.h"
|
||||
@ -23,18 +24,18 @@ using std::ostream;
|
||||
using std::cerr;
|
||||
using std::endl;
|
||||
|
||||
void HTMLRenderer::LineBuffer::reset(GfxState * state)
|
||||
void HTMLRenderer::TextLineBuffer::reset(GfxState * state)
|
||||
{
|
||||
state->transform(state->getCurX(), state->getCurY(), &x, &y);
|
||||
tm_id = renderer->cur_ttm_id;
|
||||
}
|
||||
|
||||
void HTMLRenderer::LineBuffer::append_unicodes(const Unicode * u, int l)
|
||||
void HTMLRenderer::TextLineBuffer::append_unicodes(const Unicode * u, int l)
|
||||
{
|
||||
text.insert(text.end(), u, u+l);
|
||||
}
|
||||
|
||||
void HTMLRenderer::LineBuffer::append_offset(double width)
|
||||
void HTMLRenderer::TextLineBuffer::append_offset(double width)
|
||||
{
|
||||
if((!offsets.empty()) && (offsets.back().start_idx == text.size()))
|
||||
offsets.back().width += width;
|
||||
@ -42,7 +43,7 @@ void HTMLRenderer::LineBuffer::append_offset(double width)
|
||||
offsets.push_back(Offset({text.size(), width}));
|
||||
}
|
||||
|
||||
void HTMLRenderer::LineBuffer::append_state(void)
|
||||
void HTMLRenderer::TextLineBuffer::append_state(void)
|
||||
{
|
||||
if(states.empty() || (states.back().start_idx != text.size()))
|
||||
{
|
||||
@ -53,7 +54,7 @@ void HTMLRenderer::LineBuffer::append_state(void)
|
||||
set_state(states.back());
|
||||
}
|
||||
|
||||
void HTMLRenderer::LineBuffer::flush(void)
|
||||
void HTMLRenderer::TextLineBuffer::flush(void)
|
||||
{
|
||||
/*
|
||||
* Each Line is an independent absolute positioined block
|
||||
@ -181,7 +182,7 @@ void HTMLRenderer::LineBuffer::flush(void)
|
||||
|
||||
}
|
||||
|
||||
void HTMLRenderer::LineBuffer::set_state (State & state)
|
||||
void HTMLRenderer::TextLineBuffer::set_state (State & state)
|
||||
{
|
||||
state.ids[State::FONT_ID] = renderer->cur_font_info->id;
|
||||
state.ids[State::FONT_SIZE_ID] = renderer->cur_fs_id;
|
||||
@ -196,7 +197,7 @@ void HTMLRenderer::LineBuffer::set_state (State & state)
|
||||
state.draw_font_size = renderer->draw_font_size;
|
||||
}
|
||||
|
||||
void HTMLRenderer::LineBuffer::State::begin (ostream & out, const State * prev_state)
|
||||
void HTMLRenderer::TextLineBuffer::State::begin (ostream & out, const State * prev_state)
|
||||
{
|
||||
bool first = true;
|
||||
for(int i = 0; i < ID_COUNT; ++i)
|
||||
@ -229,13 +230,13 @@ void HTMLRenderer::LineBuffer::State::begin (ostream & out, const State * prev_s
|
||||
}
|
||||
}
|
||||
|
||||
void HTMLRenderer::LineBuffer::State::end(ostream & out) const
|
||||
void HTMLRenderer::TextLineBuffer::State::end(ostream & out) const
|
||||
{
|
||||
if(need_close)
|
||||
out << "</span>";
|
||||
}
|
||||
|
||||
void HTMLRenderer::LineBuffer::State::hash(void)
|
||||
void HTMLRenderer::TextLineBuffer::State::hash(void)
|
||||
{
|
||||
hash_value = 0;
|
||||
for(int i = 0; i < ID_COUNT; ++i)
|
||||
@ -244,7 +245,7 @@ void HTMLRenderer::LineBuffer::State::hash(void)
|
||||
}
|
||||
}
|
||||
|
||||
int HTMLRenderer::LineBuffer::State::diff(const State & s) const
|
||||
int HTMLRenderer::TextLineBuffer::State::diff(const State & s) const
|
||||
{
|
||||
/*
|
||||
* A quick check based on hash_value
|
||||
@ -260,5 +261,5 @@ int HTMLRenderer::LineBuffer::State::diff(const State & s) const
|
||||
return d;
|
||||
}
|
||||
|
||||
const char * HTMLRenderer::LineBuffer::State::format_str = "fsclwr";
|
||||
const char * HTMLRenderer::TextLineBuffer::State::format_str = "fsclwr";
|
||||
} //namespace pdf2htmlEX
|
@ -14,6 +14,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "HTMLRenderer.h"
|
||||
#include "TextLineBuffer.h"
|
||||
#include "pdf2htmlEX-config.h"
|
||||
#include "BackgroundRenderer/BackgroundRenderer.h"
|
||||
#include "util/namespace.h"
|
||||
@ -41,7 +42,7 @@ static void dummy(void *, enum ErrorCategory, int pos, char *)
|
||||
HTMLRenderer::HTMLRenderer(const Param * param)
|
||||
:OutputDev()
|
||||
,line_opened(false)
|
||||
,line_buf(this)
|
||||
,text_line_buf(new TextLineBuffer(this))
|
||||
,preprocessor(param)
|
||||
,tmp_files(*param)
|
||||
,param(param)
|
||||
@ -60,6 +61,7 @@ HTMLRenderer::HTMLRenderer(const Param * param)
|
||||
|
||||
HTMLRenderer::~HTMLRenderer()
|
||||
{
|
||||
delete text_line_buf;
|
||||
ffw_finalize();
|
||||
delete [] cur_mapping;
|
||||
delete [] cur_mapping2;
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include "HTMLRenderer.h"
|
||||
#include "TextLineBuffer.h"
|
||||
#include "util/namespace.h"
|
||||
#include "util/math.h"
|
||||
|
||||
@ -342,7 +343,7 @@ void HTMLRenderer::prepare_text_line(GfxState * state)
|
||||
{
|
||||
close_text_line();
|
||||
|
||||
line_buf.reset(state);
|
||||
text_line_buf->reset(state);
|
||||
|
||||
//resync position
|
||||
draw_ty = cur_ty;
|
||||
@ -359,14 +360,14 @@ void HTMLRenderer::prepare_text_line(GfxState * state)
|
||||
}
|
||||
else
|
||||
{
|
||||
line_buf.append_offset(target);
|
||||
text_line_buf->append_offset(target);
|
||||
draw_tx += target / draw_text_scale;
|
||||
}
|
||||
}
|
||||
|
||||
if(new_line_state != NLS_NONE)
|
||||
{
|
||||
line_buf.append_state();
|
||||
text_line_buf->append_state();
|
||||
}
|
||||
|
||||
line_opened = true;
|
||||
@ -377,7 +378,7 @@ void HTMLRenderer::close_text_line()
|
||||
if(line_opened)
|
||||
{
|
||||
line_opened = false;
|
||||
line_buf.flush();
|
||||
text_line_buf->flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include <fofi/FoFiTrueType.h>
|
||||
|
||||
#include "HTMLRenderer.h"
|
||||
#include "TextLineBuffer.h"
|
||||
#include "util/ffw.h"
|
||||
#include "util/namespace.h"
|
||||
#include "util/unicode.h"
|
||||
@ -555,25 +556,25 @@ void HTMLRenderer::drawString(GfxState * state, GooString * s)
|
||||
if(is_space && (param->space_as_offset))
|
||||
{
|
||||
// ignore horiz_scaling, as it's merged in CTM
|
||||
line_buf.append_offset((dx1 * cur_font_size + cur_letter_space + cur_word_space) * draw_text_scale);
|
||||
text_line_buf->append_offset((dx1 * cur_font_size + cur_letter_space + cur_word_space) * draw_text_scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
if((param->decompose_ligature) && (uLen > 1) && all_of(u, u+uLen, isLegalUnicode))
|
||||
{
|
||||
line_buf.append_unicodes(u, uLen);
|
||||
text_line_buf->append_unicodes(u, uLen);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(cur_font_info->use_tounicode)
|
||||
{
|
||||
Unicode uu = check_unicode(u, uLen, code, font);
|
||||
line_buf.append_unicodes(&uu, 1);
|
||||
text_line_buf->append_unicodes(&uu, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
Unicode uu = unicode_from_font(code, font);
|
||||
line_buf.append_unicodes(&uu, 1);
|
||||
text_line_buf->append_unicodes(&uu, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user