mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-12-22 13:00:08 +00:00
TextLineBuffer -> HTMLTextLine
This commit is contained in:
parent
fcb61a8fc4
commit
8f929a663a
@ -188,12 +188,12 @@ add_executable(pdf2htmlEX
|
||||
src/Base64Stream.cc
|
||||
src/Color.h
|
||||
src/Color.cc
|
||||
src/HTMLTextLine.h
|
||||
src/HTMLTextLine.cc
|
||||
src/Preprocessor.h
|
||||
src/Preprocessor.cc
|
||||
src/StringFormatter.h
|
||||
src/StringFormatter.cc
|
||||
src/TextLineBuffer.h
|
||||
src/TextLineBuffer.cc
|
||||
src/TmpFiles.h
|
||||
src/TmpFiles.cc
|
||||
)
|
||||
|
@ -27,7 +27,7 @@
|
||||
#include "TmpFiles.h"
|
||||
#include "Color.h"
|
||||
#include "StateManager.h"
|
||||
#include "TextLineBuffer.h"
|
||||
#include "HTMLTextLine.h"
|
||||
|
||||
#include "util/const.h"
|
||||
#include "util/misc.h"
|
||||
@ -291,7 +291,7 @@ protected:
|
||||
double draw_tx, draw_ty;
|
||||
|
||||
// some metrics have to be determined after all elements in the lines have been seen
|
||||
std::vector<std::unique_ptr<TextLineBuffer>> text_line_buffers;
|
||||
std::vector<std::unique_ptr<HTMLTextLine>> text_lines;
|
||||
|
||||
// for font reencoding
|
||||
int32_t * cur_mapping;
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
#include "pdf2htmlEX-config.h"
|
||||
#include "HTMLRenderer.h"
|
||||
#include "TextLineBuffer.h"
|
||||
#include "HTMLTextLine.h"
|
||||
#include "BackgroundRenderer/BackgroundRenderer.h"
|
||||
#include "Base64Stream.h"
|
||||
|
||||
@ -51,7 +51,7 @@ HTMLRenderer::HTMLRenderer(const Param & param)
|
||||
globalParams->setErrQuiet(gTrue);
|
||||
}
|
||||
|
||||
text_line_buffers.emplace_back(new TextLineBuffer(param, all_manager));
|
||||
text_lines.emplace_back(new HTMLTextLine(param, all_manager));
|
||||
ffw_init(param.debug);
|
||||
cur_mapping = new int32_t [0x10000];
|
||||
cur_mapping2 = new char* [0x100];
|
||||
@ -213,7 +213,7 @@ void HTMLRenderer::endPage() {
|
||||
close_text_line();
|
||||
|
||||
// dump all text
|
||||
for(auto iter = text_line_buffers.begin(); iter != text_line_buffers.end(); ++iter)
|
||||
for(auto iter = text_lines.begin(); iter != text_lines.end(); ++iter)
|
||||
(*iter)->flush(f_pages.fs);
|
||||
|
||||
// process links before the page is closed
|
||||
|
@ -335,7 +335,7 @@ void HTMLRenderer::check_state_change(GfxState * state)
|
||||
|
||||
if(merged)
|
||||
{
|
||||
text_line_buffers.back()->append_offset(dx * old_draw_text_scale);
|
||||
text_lines.back()->append_offset(dx * old_draw_text_scale);
|
||||
if(equal(dy, 0))
|
||||
{
|
||||
cur_html_state.vertical_align = 0;
|
||||
@ -458,14 +458,14 @@ void HTMLRenderer::prepare_text_line(GfxState * state)
|
||||
double target = (cur_tx - draw_tx) * draw_text_scale;
|
||||
if(!equal(target, 0))
|
||||
{
|
||||
text_line_buffers.back()->append_offset(target);
|
||||
text_lines.back()->append_offset(target);
|
||||
draw_tx += target / draw_text_scale;
|
||||
}
|
||||
}
|
||||
|
||||
if(new_line_state != NLS_NONE)
|
||||
{
|
||||
text_line_buffers.back()->append_state(cur_html_state);
|
||||
text_lines.back()->append_state(cur_html_state);
|
||||
}
|
||||
|
||||
line_opened = true;
|
||||
@ -476,7 +476,7 @@ void HTMLRenderer::close_text_line()
|
||||
if(line_opened)
|
||||
{
|
||||
line_opened = false;
|
||||
text_line_buffers.emplace_back(new TextLineBuffer(param, all_manager));
|
||||
text_lines.emplace_back(new HTMLTextLine(param, all_manager));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,13 +90,13 @@ void HTMLRenderer::drawString(GfxState * state, GooString * s)
|
||||
if(is_space && (param.space_as_offset))
|
||||
{
|
||||
// ignore horiz_scaling, as it's merged in CTM
|
||||
text_line_buffers.back()->append_offset((dx1 * cur_font_size + cur_letter_space + cur_word_space) * draw_text_scale);
|
||||
text_lines.back()->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))
|
||||
{
|
||||
text_line_buffers.back()->append_unicodes(u, uLen);
|
||||
text_lines.back()->append_unicodes(u, uLen);
|
||||
// TODO: decomposed characters may be not with the same width as the original ligature, need to fix it.
|
||||
}
|
||||
else
|
||||
@ -110,14 +110,14 @@ void HTMLRenderer::drawString(GfxState * state, GooString * s)
|
||||
{
|
||||
uu = unicode_from_font(code, font);
|
||||
}
|
||||
text_line_buffers.back()->append_unicodes(&uu, 1);
|
||||
text_lines.back()->append_unicodes(&uu, 1);
|
||||
/*
|
||||
* In PDF, word_space is appended if (n == 1 and *p = ' ')
|
||||
* but in HTML, word_space is appended if (uu == ' ')
|
||||
*/
|
||||
int space_count = (is_space ? 1 : 0) - (uu == ' ' ? 1 : 0);
|
||||
if(space_count != 0)
|
||||
text_line_buffers.back()->append_offset(cur_word_space * draw_text_scale * space_count);
|
||||
text_lines.back()->append_offset(cur_word_space * draw_text_scale * space_count);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* TextLineBuffer.cc
|
||||
* HTMLTextLine.cc
|
||||
*
|
||||
* Generate and optimized HTML for one line
|
||||
*
|
||||
@ -10,7 +10,7 @@
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
|
||||
#include "TextLineBuffer.h"
|
||||
#include "HTMLTextLine.h"
|
||||
|
||||
#include "util/namespace.h"
|
||||
#include "util/unicode.h"
|
||||
@ -29,12 +29,12 @@ using std::endl;
|
||||
using std::find;
|
||||
using std::abs;
|
||||
|
||||
void TextLineBuffer::append_unicodes(const Unicode * u, int l)
|
||||
void HTMLTextLine::append_unicodes(const Unicode * u, int l)
|
||||
{
|
||||
text.insert(text.end(), u, u+l);
|
||||
}
|
||||
|
||||
void TextLineBuffer::append_offset(double width)
|
||||
void HTMLTextLine::append_offset(double width)
|
||||
{
|
||||
/*
|
||||
* If the last offset is very thin, we can ignore it and directly use it
|
||||
@ -47,7 +47,7 @@ void TextLineBuffer::append_offset(double width)
|
||||
offsets.emplace_back(text.size(), width);
|
||||
}
|
||||
|
||||
void TextLineBuffer::append_state(const HTMLState & html_state)
|
||||
void HTMLTextLine::append_state(const HTMLState & html_state)
|
||||
{
|
||||
if(states.empty() || (states.back().start_idx != text.size()))
|
||||
{
|
||||
@ -59,7 +59,7 @@ void TextLineBuffer::append_state(const HTMLState & html_state)
|
||||
(HTMLState&)(states.back()) = html_state;
|
||||
}
|
||||
|
||||
void TextLineBuffer::flush(ostream & out)
|
||||
void HTMLTextLine::flush(ostream & out)
|
||||
{
|
||||
/*
|
||||
* Each Line is an independent absolute positioned block
|
||||
@ -266,7 +266,7 @@ void TextLineBuffer::flush(ostream & out)
|
||||
* Adjust letter space and word space in order to reduce the number of HTML elements
|
||||
* May also unmask word space
|
||||
*/
|
||||
void TextLineBuffer::optimize()
|
||||
void HTMLTextLine::optimize()
|
||||
{
|
||||
if(!(param.optimize_text))
|
||||
return;
|
||||
@ -446,7 +446,7 @@ void TextLineBuffer::optimize()
|
||||
// this state will be converted to a child node of the node of prev_state
|
||||
// dump the difference between previous state
|
||||
// also clone corresponding states
|
||||
void TextLineBuffer::State::begin (ostream & out, const State * prev_state)
|
||||
void HTMLTextLine::State::begin (ostream & out, const State * prev_state)
|
||||
{
|
||||
if(prev_state)
|
||||
{
|
||||
@ -566,13 +566,13 @@ void TextLineBuffer::State::begin (ostream & out, const State * prev_state)
|
||||
}
|
||||
}
|
||||
|
||||
void TextLineBuffer::State::end(ostream & out) const
|
||||
void HTMLTextLine::State::end(ostream & out) const
|
||||
{
|
||||
if(need_close)
|
||||
out << "</span>";
|
||||
}
|
||||
|
||||
void TextLineBuffer::State::hash(void)
|
||||
void HTMLTextLine::State::hash(void)
|
||||
{
|
||||
hash_value = 0;
|
||||
for(int i = 0; i < ID_COUNT; ++i)
|
||||
@ -581,7 +581,7 @@ void TextLineBuffer::State::hash(void)
|
||||
}
|
||||
}
|
||||
|
||||
int TextLineBuffer::State::diff(const State & s) const
|
||||
int HTMLTextLine::State::diff(const State & s) const
|
||||
{
|
||||
/*
|
||||
* A quick check based on hash_value
|
||||
@ -602,13 +602,13 @@ int TextLineBuffer::State::diff(const State & s) const
|
||||
return d;
|
||||
}
|
||||
|
||||
long long TextLineBuffer::State::umask_by_id(int id)
|
||||
long long HTMLTextLine::State::umask_by_id(int id)
|
||||
{
|
||||
return (((long long)0xff) << (8*id));
|
||||
}
|
||||
|
||||
// the order should be the same as in the enum
|
||||
const char * const TextLineBuffer::State::css_class_names [] = {
|
||||
const char * const HTMLTextLine::State::css_class_names [] = {
|
||||
CSS::FONT_FAMILY_CN,
|
||||
CSS::FONT_SIZE_CN,
|
||||
CSS::FILL_COLOR_CN,
|
@ -19,10 +19,10 @@ namespace pdf2htmlEX {
|
||||
* - State change
|
||||
* within a line
|
||||
*/
|
||||
class TextLineBuffer
|
||||
class HTMLTextLine
|
||||
{
|
||||
public:
|
||||
TextLineBuffer (const Param & param, AllStateManater & all_manager)
|
||||
HTMLTextLine (const Param & param, AllStateManater & all_manager)
|
||||
: param(param), all_manager(all_manager) { }
|
||||
|
||||
class State : public HTMLState {
|
Loading…
Reference in New Issue
Block a user