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

working on state trackers

This commit is contained in:
Lu Wang 2013-02-05 14:21:07 +08:00
parent 4858f12d9b
commit dc0681ad84
8 changed files with 17 additions and 69 deletions

View File

@ -32,38 +32,6 @@
#include "util/misc.h"
#include "util/StateTracker.h"
/*
* Naming Convention
*
* CSS classes
*
* _ - white space
* a - Annot link
* b - page Box
* d - page Decoration
* l - Line
* j - Js data
* p - Page
*
* Cd - CSS Draw
*
* Numbered CSS classes
* See also: HTMLRenderer::TextLineBuffer::format_str
*
* t<hex> - Transform matrix
* f<hex> - Font (also for font names)
* s<hex> - font Size
* l<hex> - Letter spacing
* w<hex> - Word spacing
* c<hex> - Fill Color
* C<hex> - Stroke Color
* _<hex> - white space
* r<hex> - Rise
* h<hex> - Height
* L<hex> - Left
*
*/
namespace pdf2htmlEX {
// we may need more info of a font in the future
@ -198,7 +166,6 @@ class HTMLRenderer : public OutputDev
long long install_font_size(double font_size);
long long install_transform_matrix(const double * tm);
long long install_word_space(double word_space);
long long install_fill_color(const GfxRGB * rgb);
long long install_stroke_color(const GfxRGB * rgb);
long long install_whitespace(double ws_width, double & actual_width);
@ -219,7 +186,6 @@ class HTMLRenderer : public OutputDev
void export_font_size(long long fs_id, double font_size);
void export_transform_matrix(long long tm_id, const double * tm);
void export_word_space(long long ws_id, double word_space);
void export_fill_color(long long color_id, const GfxRGB * rgb);
void export_stroke_color(long long color_id, const GfxRGB * rgb);
void export_whitespace(long long ws_id, double ws_width);
@ -337,9 +303,8 @@ class HTMLRenderer : public OutputDev
LetterSpaceTracker letter_space_tracker;
// word spacing
long long cur_ws_id;
double cur_word_space;
bool word_space_changed;
WordSpaceTracker word_space_tracker;
// fill color
long long cur_fill_color_id;
@ -397,7 +362,6 @@ class HTMLRenderer : public OutputDev
std::unordered_map<long long, FontInfo> font_name_map;
std::map<double, long long> font_size_map;
std::map<Matrix, long long, Matrix_less> transform_matrix_map;
std::map<double, long long> word_space_map;
std::unordered_map<GfxRGB, long long, GfxRGB_hash, GfxRGB_equal> fill_color_map, stroke_color_map;
std::map<double, long long> whitespace_map;
std::map<double, long long> rise_map;

View File

@ -190,7 +190,7 @@ void HTMLRenderer::TextLineBuffer::set_state (State & state)
state.ids[State::FILL_COLOR_ID] = renderer->cur_fill_color_id;
state.ids[State::STROKE_COLOR_ID] = renderer->cur_stroke_color_id;
state.ids[State::LETTER_SPACE_ID] = renderer->letter_space_tracker.get_id();
state.ids[State::WORD_SPACE_ID] = renderer->cur_ws_id;
state.ids[State::WORD_SPACE_ID] = renderer->word_space_tracker.get_id();
state.ids[State::RISE_ID] = renderer->cur_rise_id;
const FontInfo * info = renderer->cur_font_info;

View File

@ -168,11 +168,6 @@ void HTMLRenderer::export_transform_matrix (long long tm_id, const double * tm)
f_css.fs << "}" << endl;
}
void HTMLRenderer::export_word_space (long long ws_id, double word_space)
{
f_css.fs << ".w" << ws_id << "{word-spacing:" << round(word_space) << "px;}" << endl;
}
void HTMLRenderer::export_fill_color (long long color_id, const GfxRGB * rgb)
{
f_css.fs << ".c" << color_id << "{color:" << *rgb << ";}" << endl;

View File

@ -24,6 +24,7 @@
#include "util/base64stream.h"
#include "util/math.h"
#include "util/path.h"
#include "util/CSSClassNames.h"
namespace pdf2htmlEX {
@ -56,7 +57,8 @@ HTMLRenderer::HTMLRenderer(const Param * param)
cur_mapping2 = new char* [0x100];
width_list = new int [0x10000];
letter_space_tracker.set_param("l", EPS);
letter_space_tracker.set_param(CSS::LETTER_SPACE_CN, EPS);
word_space_tracker .set_param(CSS::WORD_SPACE_CN , EPS);
}
HTMLRenderer::~HTMLRenderer()

View File

@ -240,18 +240,6 @@ long long HTMLRenderer::install_transform_matrix(const double * tm)
return new_tm_id;
}
long long HTMLRenderer::install_word_space(double word_space)
{
auto iter = word_space_map.lower_bound(word_space - EPS);
if((iter != word_space_map.end()) && (equal(iter->first, word_space)))
return iter->second;
long long new_ws_id = word_space_map.size();
word_space_map.insert(make_pair(word_space, new_ws_id));
export_word_space(new_ws_id, word_space);
return new_ws_id;
}
long long HTMLRenderer::install_fill_color(const GfxRGB * rgb)
{
// transparent

View File

@ -105,9 +105,7 @@ void HTMLRenderer::reset_state()
cur_ttm_id = install_transform_matrix(draw_text_tm);
letter_space_tracker.reset();
cur_word_space = 0;
cur_ws_id = install_word_space(cur_word_space);
word_space_tracker .reset();
cur_fill_color.r = cur_fill_color.g = cur_fill_color.b = 0;
cur_fill_color_id = install_fill_color(&cur_fill_color);
@ -348,15 +346,10 @@ void HTMLRenderer::check_state_change(GfxState * state)
// word space
// depends draw_text_scale
if(all_changed || word_space_changed || draw_text_scale_changed)
if((all_changed || word_space_changed || draw_text_scale_changed)
&& (word_space_tracker.install(state->getWordSpace() * draw_text_scale)))
{
double new_word_space = state->getWordSpace();
if(!equal(cur_word_space, new_word_space))
{
new_line_state = max<NewLineState>(new_line_state, NLS_SPAN);
cur_word_space = new_word_space;
cur_ws_id = install_word_space(cur_word_space * draw_text_scale);
}
new_line_state = max<NewLineState>(new_line_state, NLS_SPAN);
}
// color

View File

@ -505,6 +505,7 @@ void HTMLRenderer::drawString(GfxState * state, GooString * s)
auto font = state->getFont();
double cur_letter_space = state->getCharSpace();
double cur_word_space = state->getWordSpace();
// Writing mode fonts and Type 3 fonts are rendered as images
// I don't find a way to display writing mode fonts in HTML except for one div for each character, which is too costly

View File

@ -97,7 +97,6 @@ class FontSizeTracker : public StateTracker<double, FontSizeTracker>
{
public:
double default_value(void) { return 0; }
double get_value(GfxState * state) { return state->getFontSize(); }
void dump_value(std::ostream & out, double value) { out << "font-size:" << round(value) << "px;"; }
};
@ -105,10 +104,16 @@ class LetterSpaceTracker : public StateTracker<double, LetterSpaceTracker>
{
public:
double default_value(void) { return 0; }
double get_value(GfxState * state) { return state->getCharSpace(); }
void dump_value(std::ostream & out, double value) { out << "letter-spacing:" << round(value) << "px;"; }
};
class WordSpaceTracker : public StateTracker<double, WordSpaceTracker>
{
public:
double default_value(void) { return 0; }
void dump_value(std::ostream & out, double value) { out << "word-spacing:" << round(value) << "px;"; }
};
} // namespace pdf2htmlEX
#endif //STATETRACKER_H__