2012-12-11 12:48:10 +00:00
|
|
|
#ifndef TEXTLINEBUFFER_H__
|
|
|
|
#define TEXTLINEBUFFER_H__
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace pdf2htmlEX {
|
|
|
|
|
2013-01-19 11:19:15 +00:00
|
|
|
/*
|
|
|
|
* Store a series of
|
|
|
|
* - Text
|
|
|
|
* - Shift
|
|
|
|
* - State change
|
|
|
|
* within a line
|
|
|
|
*/
|
2012-12-11 12:52:36 +00:00
|
|
|
class HTMLRenderer;
|
2012-12-11 12:48:10 +00:00
|
|
|
class HTMLRenderer::TextLineBuffer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TextLineBuffer (HTMLRenderer * renderer) : renderer(renderer) { }
|
|
|
|
|
|
|
|
class State {
|
|
|
|
public:
|
2013-01-19 11:33:29 +00:00
|
|
|
// before output
|
2012-12-11 12:48:10 +00:00
|
|
|
void begin(std::ostream & out, const State * prev_state);
|
2013-01-19 11:33:29 +00:00
|
|
|
// after output
|
2012-12-11 12:48:10 +00:00
|
|
|
void end(std::ostream & out) const;
|
2013-01-19 11:33:29 +00:00
|
|
|
// calculate the hash code
|
2012-12-11 12:48:10 +00:00
|
|
|
void hash(void);
|
2013-01-19 11:33:29 +00:00
|
|
|
// calculate the difference between another State
|
2012-12-11 12:48:10 +00:00
|
|
|
int diff(const State & s) const;
|
2013-03-21 04:18:26 +00:00
|
|
|
// the offset cause by a single ' ' char
|
|
|
|
double single_space_offset(void) const;
|
2012-12-11 12:48:10 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
FONT_ID,
|
|
|
|
FONT_SIZE_ID,
|
2013-01-31 22:21:57 +00:00
|
|
|
FILL_COLOR_ID,
|
|
|
|
STROKE_COLOR_ID,
|
2012-12-11 12:48:10 +00:00
|
|
|
LETTER_SPACE_ID,
|
|
|
|
WORD_SPACE_ID,
|
|
|
|
RISE_ID,
|
|
|
|
|
|
|
|
ID_COUNT
|
|
|
|
};
|
|
|
|
|
2013-03-25 04:23:29 +00:00
|
|
|
static long long umask_by_id(int id);
|
|
|
|
|
2012-12-11 12:48:10 +00:00
|
|
|
long long ids[ID_COUNT];
|
|
|
|
|
2013-03-20 15:46:58 +00:00
|
|
|
const FontInfo * font_info;
|
2012-12-11 12:48:10 +00:00
|
|
|
double draw_font_size;
|
2013-03-21 04:18:26 +00:00
|
|
|
double letter_space;
|
2013-03-20 15:46:58 +00:00
|
|
|
double word_space;
|
2012-12-11 12:48:10 +00:00
|
|
|
|
|
|
|
size_t start_idx; // index of the first Text using this state
|
|
|
|
// for optimzation
|
|
|
|
long long hash_value;
|
2013-03-20 15:46:58 +00:00
|
|
|
long long hash_umask; // some states may not be actually used
|
2012-12-11 12:48:10 +00:00
|
|
|
bool need_close;
|
|
|
|
|
2013-02-05 10:19:25 +00:00
|
|
|
static const char * const css_class_names []; // class names for each id
|
2012-12-11 12:48:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Offset {
|
|
|
|
public:
|
2013-01-19 12:13:31 +00:00
|
|
|
size_t start_idx; // should put this Offset right before text[start_idx];
|
2012-12-11 12:48:10 +00:00
|
|
|
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);
|
|
|
|
|
2013-03-20 15:46:58 +00:00
|
|
|
void optimize(void);
|
|
|
|
|
2012-12-11 12:48:10 +00:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace pdf2htmlEX
|
|
|
|
#endif //TEXTLINEBUFFER_H__
|