mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-10-05 19:41:40 +00:00
working
This commit is contained in:
parent
4364a5d322
commit
429ff6bcd6
@ -10,6 +10,7 @@
|
|||||||
#ifndef STATETRACKER_H__
|
#ifndef STATETRACKER_H__
|
||||||
#define STATETRACKER_H__
|
#define STATETRACKER_H__
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include <GfxState.h>
|
#include <GfxState.h>
|
||||||
@ -19,19 +20,25 @@ namespace pdf2htmlEX {
|
|||||||
template<class ValueType, class Imp> class StateTracker {};
|
template<class ValueType, class Imp> class StateTracker {};
|
||||||
|
|
||||||
template<class Imp>
|
template<class Imp>
|
||||||
class StateTracker<double>
|
class StateTracker<double, Imp>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// values no father than eps are treated as equal
|
StateTracker()
|
||||||
StateTracker(const char * css_class_prefix, double eps)
|
: eps(0)
|
||||||
: css_class_prefix(css_class_prefix)
|
|
||||||
, eps(eps)
|
|
||||||
, changed(false)
|
, changed(false)
|
||||||
, imp(static_cast<Imp>(this))
|
, imp(static_cast<Imp>(this))
|
||||||
{ }
|
{
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
// values no father than eps are treated as equal
|
||||||
|
void set_param (const char * css_class_name, double eps) {
|
||||||
|
this->css_class_name = css_class_name;
|
||||||
|
this->eps = eps;
|
||||||
|
}
|
||||||
|
|
||||||
// usually called at the beginning of a page
|
// usually called at the beginning of a page
|
||||||
void reset(void) { imp->reset(); }
|
void reset(void) { value = imp->default_value(); }
|
||||||
|
|
||||||
// is called when PDF updates the state
|
// is called when PDF updates the state
|
||||||
void update(GfxState * state) { changed = true; }
|
void update(GfxState * state) { changed = true; }
|
||||||
@ -39,7 +46,7 @@ public:
|
|||||||
* retrive the new state if update() is called recently, or force == true
|
* retrive the new state if update() is called recently, or force == true
|
||||||
* return if the state has been indeed changed
|
* return if the state has been indeed changed
|
||||||
*/
|
*/
|
||||||
bool sync(GfxState * state, bool force)| {
|
bool sync(GfxState * state, bool force) {
|
||||||
if(!(changed || force))
|
if(!(changed || force))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -53,12 +60,14 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double get_actual_value (void) const { return actual_value; }
|
||||||
|
|
||||||
long long install(double new_value) {
|
long long install(double new_value) {
|
||||||
value = new_value;
|
value = new_value;
|
||||||
|
|
||||||
auto iter = value_map.lower_bound(new_value - eps);
|
auto iter = value_map.lower_bound(new_value - eps);
|
||||||
if((iter != value_map.end()) && (abs(iter->first - value) <= eps)) {
|
if((iter != value_map.end()) && (abs(iter->first - value) <= eps))
|
||||||
|
{
|
||||||
actual_value = iter->first;
|
actual_value = iter->first;
|
||||||
return iter->second;
|
return iter->second;
|
||||||
}
|
}
|
||||||
@ -67,23 +76,59 @@ public:
|
|||||||
long long new_id = map.size();
|
long long new_id = map.size();
|
||||||
map.insert(make_pair(new_value, new_id));
|
map.insert(make_pair(new_value, new_id));
|
||||||
|
|
||||||
imp->create(new_id, new_value);
|
|
||||||
|
|
||||||
return new_id;
|
return new_id;
|
||||||
}
|
}
|
||||||
private:
|
|
||||||
const char * css_class_prefix;
|
void dump_css(std::ostream & out) {
|
||||||
const double eps;
|
for(auto iter = map.begin(); iter != map.end(); ++iter)
|
||||||
|
{
|
||||||
|
out << "." << css_class_name << iter->second << "{";
|
||||||
|
imp->dump_value(out, iter->first);
|
||||||
|
out << "}" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
const char * css_class_name;
|
||||||
|
double eps;
|
||||||
bool changed;
|
bool changed;
|
||||||
Imp * imp;
|
Imp * imp;
|
||||||
|
|
||||||
|
|
||||||
long long id;
|
long long id;
|
||||||
double value; // the value we are tracking
|
double value; // the value we are tracking
|
||||||
double actual_value; // the value we actually exported to HTML
|
double actual_value; // the value we actually exported to HTML
|
||||||
std::map<double, long long> value_map;
|
std::map<double, long long> value_map;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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;"; }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
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 "font-size:" << round(value) << "px;"; }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
std::map<Matrix, long long, Matrix_less> transform_matrix_map;
|
||||||
|
std::map<double, long long> letter_space_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;
|
||||||
|
std::map<double, long long> height_map;
|
||||||
|
std::map<double, long long> left_map;
|
||||||
|
|
||||||
|
|
||||||
} // namespace pdf2htmlEX
|
} // namespace pdf2htmlEX
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user