mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-12-22 13:00:08 +00:00
css class name constants
This commit is contained in:
parent
006dfd3ab6
commit
dfa0d29e0a
@ -74,7 +74,7 @@
|
||||
background-color:white;
|
||||
overflow: hidden;
|
||||
/* margin & border-width have to be 0,
|
||||
* otherwise pdf2htmlEX may not calculate the coordinates correctly
|
||||
* otherwise pdf2htmlEX.js may not calculate the coordinates correctly
|
||||
*/
|
||||
margin:0;
|
||||
border-width:0;
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "util/namespace.h"
|
||||
#include "util/unicode.h"
|
||||
#include "util/math.h"
|
||||
#include "util/CSSClassNames.h"
|
||||
|
||||
namespace pdf2htmlEX {
|
||||
|
||||
@ -89,10 +90,10 @@ void HTMLRenderer::TextLineBuffer::flush(void)
|
||||
out << "<div style=\""
|
||||
<< "bottom:" << round(y) << "px;"
|
||||
<< "\""
|
||||
<< " class=\"l"
|
||||
<< " t" << tm_id
|
||||
<< " L" << renderer->left_manager.get_id()
|
||||
<< " h" << renderer->height_manager.get_id()
|
||||
<< " class=\"" << CSS::LINE_CN
|
||||
<< " " << CSS::TRANSFORM_MATRIX_CN << tm_id
|
||||
<< " " << CSS::LEFT_CN << renderer->left_manager.get_id()
|
||||
<< " " << CSS::HEIGHT_CN << renderer->height_manager.get_id()
|
||||
<< "\">";
|
||||
|
||||
auto cur_state_iter = states.begin();
|
||||
@ -158,7 +159,8 @@ void HTMLRenderer::TextLineBuffer::flush(void)
|
||||
auto * p = stack.back();
|
||||
double threshold = p->draw_font_size * (p->ascent - p->descent) * (renderer->param->space_threshold);
|
||||
|
||||
out << "<span class=\"_ _" << wid << "\">" << (target > (threshold - EPS) ? " " : "") << "</span>";
|
||||
out << "<span class=\"" << CSS::WHITESPACE_CN
|
||||
<< ' ' << CSS::WHITESPACE_CN << wid << "\">" << (target > (threshold - EPS) ? " " : "") << "</span>";
|
||||
|
||||
dx = target - w;
|
||||
|
||||
@ -225,11 +227,12 @@ void HTMLRenderer::TextLineBuffer::State::begin (ostream & out, const State * pr
|
||||
if (ids[i] == -1)
|
||||
{
|
||||
// transparent
|
||||
out << format_str[i] << "t";
|
||||
// TODO about "t"
|
||||
out << css_class_names[i] << "t";
|
||||
}
|
||||
else
|
||||
{
|
||||
out << format_str[i] << ids[i];
|
||||
out << css_class_names[i] << ids[i];
|
||||
}
|
||||
}
|
||||
|
||||
@ -275,5 +278,15 @@ int HTMLRenderer::TextLineBuffer::State::diff(const State & s) const
|
||||
return d;
|
||||
}
|
||||
|
||||
const char * HTMLRenderer::TextLineBuffer::State::format_str = "fscClwr";
|
||||
// the order should be the same as in the enum
|
||||
const char * const HTMLRenderer::TextLineBuffer::State::css_class_names [] = {
|
||||
CSS::FONT_NAME_CN,
|
||||
CSS::FONT_SIZE_CN,
|
||||
CSS::FILL_COLOR_CN,
|
||||
CSS::STROKE_COLOR_CN,
|
||||
CSS::LETTER_SPACE_CN,
|
||||
CSS::WORD_SPACE_CN,
|
||||
CSS::RISE_CN
|
||||
};
|
||||
|
||||
} //namespace pdf2htmlEX
|
||||
|
@ -53,7 +53,7 @@ public:
|
||||
long long hash_value;
|
||||
bool need_close;
|
||||
|
||||
static const char * format_str; // class names for each id
|
||||
static const char * const css_class_names []; // class names for each id
|
||||
};
|
||||
|
||||
|
||||
|
@ -56,13 +56,13 @@ HTMLRenderer::HTMLRenderer(const Param * param)
|
||||
cur_mapping2 = new char* [0x100];
|
||||
width_list = new int [0x10000];
|
||||
|
||||
font_size_manager .set_param(CSS::FONT_SIZE_CN , EPS );
|
||||
letter_space_manager.set_param(CSS::LETTER_SPACE_CN, EPS );
|
||||
word_space_manager .set_param(CSS::WORD_SPACE_CN , EPS );
|
||||
rise_manager .set_param(CSS::RISE_CN , param->v_eps);
|
||||
whitespace_manager .set_param(CSS::WHITESPACE_CN , param->h_eps);
|
||||
height_manager .set_param(CSS::HEIGHT_CN , EPS );
|
||||
left_manager .set_param(CSS::LEFT_CN , param->h_eps);
|
||||
font_size_manager .set_param(EPS);
|
||||
letter_space_manager.set_param(EPS);
|
||||
word_space_manager .set_param(EPS);
|
||||
rise_manager .set_param(param->v_eps);
|
||||
whitespace_manager .set_param(param->h_eps);
|
||||
height_manager .set_param(EPS);
|
||||
left_manager .set_param(param->h_eps);
|
||||
}
|
||||
|
||||
HTMLRenderer::~HTMLRenderer()
|
||||
@ -163,11 +163,12 @@ void HTMLRenderer::startPage(int pageNum, GfxState *state, XRef * xref)
|
||||
assert((!line_opened) && "Open line in startPage detected!");
|
||||
|
||||
f_pages.fs
|
||||
<< "<div class=\"d\" style=\"width:"
|
||||
<< "<div class=\"" << CSS::PAGE_DECORATION_CN
|
||||
<< "\" style=\"width:"
|
||||
<< (pageWidth) << "px;height:"
|
||||
<< (pageHeight) << "px;\">"
|
||||
<< "<div id=\"p" << pageNum << "\" data-page-no=\"" << pageNum << "\" class=\"p\">"
|
||||
<< "<div class=\"b\" style=\"";
|
||||
<< "<div id=\"" << CSS::PAGE_FRAME_CN << pageNum << "\" data-page-no=\"" << pageNum << "\" class=\"p\">"
|
||||
<< "<div class=\"" << CSS::PAGE_CONTENT_BOX_CN << "\" style=\"";
|
||||
|
||||
if(param->process_nontext)
|
||||
{
|
||||
@ -208,7 +209,7 @@ void HTMLRenderer::endPage() {
|
||||
// dump info for js
|
||||
// TODO: create a function for this
|
||||
// BE CAREFUL WITH ESCAPES
|
||||
f_pages.fs << "<div class=\"j\" data-data='{";
|
||||
f_pages.fs << "<div class=\"" << CSS::PAGE_DATA_CN << "\" data-data='{";
|
||||
|
||||
//default CTM
|
||||
f_pages.fs << "\"ctm\":[";
|
||||
|
@ -193,7 +193,7 @@ void HTMLRenderer::processLink(AnnotLink * al)
|
||||
|
||||
if(!dest_str.empty())
|
||||
{
|
||||
f_pages.fs << "<a class=\"a\" href=\"" << dest_str << "\"";
|
||||
f_pages.fs << "<a class=\"" << CSS::LINE_CN << "\" href=\"" << dest_str << "\"";
|
||||
|
||||
if(!dest_detail_str.empty())
|
||||
f_pages.fs << " data-dest-detail='" << dest_detail_str << "'";
|
||||
@ -201,7 +201,7 @@ void HTMLRenderer::processLink(AnnotLink * al)
|
||||
f_pages.fs << ">";
|
||||
}
|
||||
|
||||
f_pages.fs << "<div class=\"Cd t"
|
||||
f_pages.fs << "<div class=\"" << CSS::CSS_DRAW_CN << ' ' << CSS::TRANSFORM_MATRIX_CN
|
||||
<< install_transform_matrix(default_ctm)
|
||||
<< "\" style=\"";
|
||||
|
||||
|
@ -10,49 +10,34 @@
|
||||
namespace pdf2htmlEX {
|
||||
namespace CSS {
|
||||
|
||||
const char * FONT_SIZE_CN = "s";
|
||||
const char * LETTER_SPACE_CN = "l";
|
||||
const char * WORD_SPACE_CN = "w";
|
||||
const char * RISE_CN = "r";
|
||||
const char * WHITESPACE_CN = "_";
|
||||
const char * HEIGHT_CN = "h";
|
||||
const char * LEFT_CN = "L";
|
||||
const char * const LINE_CN = "l";
|
||||
const char * const TRANSFORM_MATRIX_CN = "t";
|
||||
|
||||
// page_decoration is for shadow etc
|
||||
// page_frame cannot have margin or border-width, pdf2htmlEX.js will use it to determine the coordinates
|
||||
// page_content holds everything inside the page, could be hidden to speed up rendering
|
||||
// page_data holds data for pdf2htmlEX.js
|
||||
const char * const PAGE_DECORATION_CN = "d";
|
||||
const char * const PAGE_FRAME_CN = "p";
|
||||
const char * const PAGE_CONTENT_BOX_CN = "b";
|
||||
const char * const PAGE_DATA_CN = "j";
|
||||
|
||||
const char * const FONT_NAME_CN = "f";
|
||||
const char * const FONT_SIZE_CN = "s";
|
||||
const char * const FILL_COLOR_CN = "c";
|
||||
const char * const STROKE_COLOR_CN = "C";
|
||||
const char * const LETTER_SPACE_CN = "l";
|
||||
const char * const WORD_SPACE_CN = "w";
|
||||
const char * const RISE_CN = "r";
|
||||
const char * const WHITESPACE_CN = "_";
|
||||
const char * const HEIGHT_CN = "h";
|
||||
const char * const LEFT_CN = "L";
|
||||
|
||||
const char * const CSS_DRAW_CN = "Cd";
|
||||
const char * const LINK_CN = "a";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Deprecated!!!
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#endif //CSSCLASSNAMES_H__
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include <map>
|
||||
|
||||
#include "util/math.h"
|
||||
#include "util/CSSClassNames.h"
|
||||
|
||||
namespace pdf2htmlEX {
|
||||
|
||||
@ -30,8 +31,7 @@ public:
|
||||
}
|
||||
|
||||
// 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;
|
||||
void set_param (double eps) {
|
||||
this->eps = eps;
|
||||
}
|
||||
|
||||
@ -58,7 +58,7 @@ public:
|
||||
void dump_css(std::ostream & out) {
|
||||
for(auto iter = value_map.begin(); iter != value_map.end(); ++iter)
|
||||
{
|
||||
out << "." << css_class_name << iter->second << "{";
|
||||
out << "." << imp->get_css_class_name() << iter->second << "{";
|
||||
imp->dump_value(out, iter->first);
|
||||
out << "}" << std::endl;
|
||||
}
|
||||
@ -83,7 +83,6 @@ protected:
|
||||
return true;
|
||||
}
|
||||
|
||||
const char * css_class_name;
|
||||
double eps;
|
||||
Imp * imp;
|
||||
|
||||
@ -96,13 +95,15 @@ protected:
|
||||
class FontSizeManager : public StateManager<double, FontSizeManager>
|
||||
{
|
||||
public:
|
||||
static const char * get_css_class_name (void) { return CSS::FONT_SIZE_CN; }
|
||||
double default_value(void) { return 0; }
|
||||
void dump_value(std::ostream & out, double value) { out << "font-size:" << round(value) << "px;"; }
|
||||
};
|
||||
|
||||
class LetterSpaceManager : public StateManager<double, LetterSpaceManager>
|
||||
class LetterSpaceManager : public StateManager<double, LetterSpaceManager>
|
||||
{
|
||||
public:
|
||||
static const char * get_css_class_name (void) { return CSS::LETTER_SPACE_CN; }
|
||||
double default_value(void) { return 0; }
|
||||
void dump_value(std::ostream & out, double value) { out << "letter-spacing:" << round(value) << "px;"; }
|
||||
};
|
||||
@ -110,6 +111,7 @@ public:
|
||||
class WordSpaceManager : public StateManager<double, WordSpaceManager>
|
||||
{
|
||||
public:
|
||||
static const char * get_css_class_name (void) { return CSS::WORD_SPACE_CN;}
|
||||
double default_value(void) { return 0; }
|
||||
void dump_value(std::ostream & out, double value) { out << "word-spacing:" << round(value) << "px;"; }
|
||||
};
|
||||
@ -117,6 +119,7 @@ public:
|
||||
class RiseManager : public StateManager<double, RiseManager>
|
||||
{
|
||||
public:
|
||||
static const char * get_css_class_name (void) { return CSS::RISE_CN; }
|
||||
double default_value(void) { return 0; }
|
||||
void dump_value(std::ostream & out, double value) { out << "top:" << round(-value) << "px;"; }
|
||||
};
|
||||
@ -124,6 +127,7 @@ public:
|
||||
class WhitespaceManager : public StateManager<double, WhitespaceManager>
|
||||
{
|
||||
public:
|
||||
static const char * get_css_class_name (void) { return CSS::WHITESPACE_CN; }
|
||||
double default_value(void) { return 0; }
|
||||
void dump_value(std::ostream & out, double value) {
|
||||
out << ((value > 0) ? "display:inline-block;width:"
|
||||
@ -135,6 +139,7 @@ public:
|
||||
class HeightManager : public StateManager<double, HeightManager>
|
||||
{
|
||||
public:
|
||||
static const char * get_css_class_name (void) { return CSS::HEIGHT_CN; }
|
||||
double default_value(void) { return 0; }
|
||||
void dump_value(std::ostream & out, double value) { out << "height:" << round(value) << "px;"; }
|
||||
};
|
||||
@ -142,6 +147,7 @@ public:
|
||||
class LeftManager : public StateManager<double, LeftManager>
|
||||
{
|
||||
public:
|
||||
static const char * get_css_class_name (void) { return CSS::LEFT_CN; }
|
||||
double default_value(void) { return 0; }
|
||||
void dump_value(std::ostream & out, double value) { out << "left:" << round(value) << "px;"; }
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user