(new_line_state, NLS_NEWSTATE);
+ set_line_state(new_line_state, NLS_NEWSTATE);
}
}
@@ -465,9 +483,14 @@ void HTMLRenderer::check_state_change(GfxState * state)
void HTMLRenderer::prepare_text_line(GfxState * state)
{
if(!(html_text_page.get_cur_line()))
- new_line_state = NLS_NEWLINE;
+ new_line_state = NLS_NEWCLIP;
- if(new_line_state == NLS_NEWLINE)
+ if(new_line_state >= NLS_NEWCLIP)
+ {
+ html_text_page.clip(cur_clip_state);
+ }
+
+ if(new_line_state >= NLS_NEWLINE)
{
// update position such that they will be recorded by text_line_buf
state->transform(state->getCurX(), state->getCurY(), &cur_line_state.x, &cur_line_state.y);
diff --git a/src/HTMLTextLine.cc b/src/HTMLTextLine.cc
index e2d81f7..d37269c 100644
--- a/src/HTMLTextLine.cc
+++ b/src/HTMLTextLine.cc
@@ -233,10 +233,10 @@ void HTMLTextLine::clear(void)
text.clear();
}
-void HTMLTextLine::clip(double x1, double y1, double x2, double y2)
+void HTMLTextLine::clip(const HTMLClipState & clip_state)
{
- clip_x1 = x1;
- clip_y1 = y1;
+ clip_x1 = clip_state.xmin;
+ clip_y1 = clip_state.ymin;
}
void HTMLTextLine::prepare(void)
diff --git a/src/HTMLTextLine.h b/src/HTMLTextLine.h
index 9b78bf4..c974c0f 100644
--- a/src/HTMLTextLine.h
+++ b/src/HTMLTextLine.h
@@ -81,7 +81,7 @@ public:
bool text_empty(void) const { return text.empty(); }
void clear(void);
- void clip(double x1, double y1, double x2, double y2);
+ void clip(const HTMLClipState &);
/*
* Optimize and calculate necessary values
diff --git a/src/HTMLTextPage.cc b/src/HTMLTextPage.cc
index d1e092b..e7d6c6b 100644
--- a/src/HTMLTextPage.cc
+++ b/src/HTMLTextPage.cc
@@ -30,39 +30,49 @@ void HTMLTextPage::dump_text(ostream & out)
optimize();
//push a dummy entry for convenience
- clip_boxes.emplace_back(0, 0, page_width, page_height, text_lines.size());
+ clips.emplace_back(HTMLClipState{0, 0, page_width, page_height}, text_lines.size());
- ClipBox cur_cb(0, 0, page_width, page_height, 0);
+ Clip cur_clip(HTMLClipState{0, 0, page_width, page_height}, 0);
bool has_clip = false;
auto text_line_iter = text_lines.begin();
- for(auto clip_iter = clip_boxes.begin(); clip_iter != clip_boxes.end(); ++clip_iter)
+ for(auto clip_iter = clips.begin(); clip_iter != clips.end(); ++clip_iter)
{
- if(has_clip)
- {
- out << "";
- }
-
auto next_text_line_iter = text_lines.begin() + clip_iter->start_idx;
- while(text_line_iter != next_text_line_iter)
+ if(text_line_iter != next_text_line_iter)
{
- (*text_line_iter)->clip(cur_cb.x1, cur_cb.y1, cur_cb.x2, cur_cb.y2);
- (*text_line_iter)->dump_text(out);
- ++text_line_iter;
- }
- if(has_clip)
- {
- out << "
";
+ const auto & cs = cur_clip.clip_state;
+ if(has_clip)
+ {
+ out << "";
+ }
+
+ while(text_line_iter != next_text_line_iter)
+ {
+ if(has_clip)
+ {
+ (*text_line_iter)->clip(cs);
+ }
+ (*text_line_iter)->dump_text(out);
+ ++text_line_iter;
+ }
+ if(has_clip)
+ {
+ out << "
";
+ }
}
- cur_cb = *clip_iter;
- has_clip = !(equal(0, cur_cb.x1) && equal(0, cur_cb.y1)
- && equal(page_width, cur_cb.x2) && equal(page_height, cur_cb.y2));
+ {
+ cur_clip = *clip_iter;
+ const auto & cs = cur_clip.clip_state;
+ has_clip = !(equal(0, cs.xmin) && equal(0, cs.ymin)
+ && equal(page_width, cs.xmax) && equal(page_height, cs.ymax));
+ }
}
}
@@ -74,7 +84,7 @@ void HTMLTextPage::dump_css(ostream & out)
void HTMLTextPage::clear(void)
{
text_lines.clear();
- clip_boxes.clear();
+ clips.clear();
cur_line = nullptr;
}
@@ -94,32 +104,21 @@ void HTMLTextPage::set_page_size(double width, double height)
page_height = height;
}
-void HTMLTextPage::clip(double x1, double y1, double x2, double y2)
+void HTMLTextPage::clip(const HTMLClipState & clip_state)
{
- if(!clip_boxes.empty())
+ if(!clips.empty())
{
- auto & cb = clip_boxes.back();
- if(cb.start_idx == text_lines.size())
+ auto & clip = clips.back();
+ if(clip.start_idx == text_lines.size())
{
/*
* Previous ClipBox is not used
*/
- cb.x1 = x1;
- cb.y1 = y1;
- cb.x2 = x2;
- cb.y2 = y2;
- return;
- }
- if(equal(cb.x1, x1) && equal(cb.y1, y1)
- && equal(cb.x2, x2) && equal(cb.y2, y2))
- {
- /*
- * same as previous ClipBox
- */
+ clip.clip_state = clip_state;
return;
}
}
- clip_boxes.emplace_back(x1, y1, x2, y2, text_lines.size());
+ clips.emplace_back(clip_state, text_lines.size());
}
void HTMLTextPage::optimize(void)
diff --git a/src/HTMLTextPage.h b/src/HTMLTextPage.h
index 2125519..ec01e24 100644
--- a/src/HTMLTextPage.h
+++ b/src/HTMLTextPage.h
@@ -22,7 +22,6 @@ namespace pdf2htmlEX {
*
* contains a series of HTMLTextLine
*/
-
class HTMLTextPage
{
public:
@@ -38,7 +37,7 @@ public:
/* for clipping */
void set_page_size(double width, double height);
- void clip(double x1, double y1, double x2, double y2);
+ void clip(const HTMLClipState & clip_state);
private:
void optimize(void);
@@ -50,14 +49,14 @@ private:
std::vector> text_lines;
- struct ClipBox {
- ClipBox(double x1, double y1, double x2, double y2, size_t start_idx)
- :x1(x1),y1(y1),x2(x2),y2(y2),start_idx(start_idx)
- { }
- double x1, y1, x2, y2;
+ struct Clip {
+ HTMLClipState clip_state;
size_t start_idx;
+ Clip(const HTMLClipState & clip_state, size_t start_idx)
+ :clip_state(clip_state),start_idx(start_idx)
+ { }
};
- std::vector clip_boxes;
+ std::vector clips;
};
} //namespace pdf2htmlEX