Skip to content

Commit bfcca39

Browse files
committed
refactor: simplify document size calculation by removing content size handling
document::width() and document::height() can be used in all cases to calculate the document size.
1 parent ec38e58 commit bfcca39

File tree

5 files changed

+8
-36
lines changed

5 files changed

+8
-36
lines changed

containers/cairo/render2png.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ namespace html2png
219219
std::swap(m_screen_width, best_width);
220220
}
221221

222-
width = cfg.get_int("width", doc->content_width() > 0 ? doc->content_width() : 1);
223-
height = cfg.get_int("height", doc->content_height() > 0 ? doc->content_height() : 1);
222+
width = cfg.get_int("width", doc->width() > 0 ? doc->width() : 1);
223+
height = cfg.get_int("height", doc->height() > 0 ? doc->height() : 1);
224224

225225
auto surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
226226
if(surface)

include/litehtml/document.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ namespace litehtml
5959
litehtml::css m_master_css;
6060
litehtml::css m_user_css;
6161
litehtml::size m_size;
62-
litehtml::size m_content_size;
6362
position::vector m_fixed_boxes;
6463
std::shared_ptr<element> m_over_element;
6564
std::shared_ptr<element> m_active_element;
@@ -84,8 +83,6 @@ namespace litehtml
8483
int to_pixels(const css_length& val, const font_metrics& metrics, int size) const;
8584
int width() const;
8685
int height() const;
87-
int content_width() const;
88-
int content_height() const;
8986
void add_stylesheet(const char* str, const char* baseurl, const char* media);
9087
bool on_mouse_over(int x, int y, int client_x, int client_y, position::vector& redraw_boxes);
9188
bool on_lbutton_down(int x, int y, int client_x, int client_y, position::vector& redraw_boxes);

include/litehtml/render_item.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ namespace litehtml
412412
std::tuple<int, int> element_static_offset(const std::shared_ptr<litehtml::render_item> &el);
413413
void add_positioned(const std::shared_ptr<litehtml::render_item> &el);
414414
void get_redraw_box(litehtml::position& pos, int x = 0, int y = 0);
415-
void calc_document_size( litehtml::size& sz, litehtml::size& content_size, int x = 0, int y = 0 );
415+
void calc_document_size( litehtml::size& sz, int x = 0, int y = 0 );
416416
virtual void get_inline_boxes( position::vector& /*boxes*/ ) const {};
417417
virtual void set_inline_boxes( position::vector& /*boxes*/ ) {};
418418
virtual void add_inline_box( const position& /*box*/ ) {};

src/document.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -512,9 +512,7 @@ int document::render( int max_width, render_type rt )
512512
}
513513
m_size.width = 0;
514514
m_size.height = 0;
515-
m_content_size.width = 0;
516-
m_content_size.height = 0;
517-
m_root_render->calc_document_size(m_size, m_content_size);
515+
m_root_render->calc_document_size(m_size);
518516
}
519517
}
520518
return ret;
@@ -612,17 +610,6 @@ int document::height() const
612610
return m_size.height;
613611
}
614612

615-
int document::content_width() const
616-
{
617-
return m_content_size.width;
618-
}
619-
620-
int document::content_height() const
621-
{
622-
return m_content_size.height;
623-
}
624-
625-
626613
void document::add_stylesheet( const char* str, const char* baseurl, const char* media )
627614
{
628615
if(str && str[0])

src/render_item.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ void litehtml::render_item::get_redraw_box(litehtml::position& pos, int x /*= 0*
707707
}
708708
}
709709

710-
void litehtml::render_item::calc_document_size( litehtml::size& sz, litehtml::size& content_size, int x /*= 0*/, int y /*= 0*/ )
710+
void litehtml::render_item::calc_document_size( litehtml::size& sz, int x /*= 0*/, int y /*= 0*/ )
711711
{
712712
if(css().get_display() != display_inline && css().get_display() != display_table_row)
713713
{
@@ -716,36 +716,24 @@ void litehtml::render_item::calc_document_size( litehtml::size& sz, litehtml::si
716716
sz.width = std::max(sz.width, x + right());
717717
sz.height = std::max(sz.height, y + bottom());
718718

719-
if (!src_el()->is_root() && !src_el()->is_body())
720-
{
721-
content_size.width = std::max(content_size.width, x + right());
722-
content_size.height = std::max(content_size.height, y + bottom());
723-
}
724-
725719
// All children of tables and blocks with style other than "overflow: visible" are inside element.
726720
// We can skip calculating size of children
727721
if (src_el()->css().get_overflow() == overflow_visible && src_el()->css().get_display() != display_table)
728722
{
729723
for (auto &el: m_children)
730724
{
731-
el->calc_document_size(sz, content_size, x + m_pos.x, y + m_pos.y);
725+
el->calc_document_size(sz, x + m_pos.x, y + m_pos.y);
732726
}
733727
}
734-
735-
if (src_el()->is_root() || src_el()->is_body())
736-
{
737-
content_size.width = std::max(content_size.width, x + right());
738-
content_size.height = std::max(content_size.height, y + bottom());
739-
}
740728
}
741729
} else
742730
{
743731
position::vector boxes;
744732
get_inline_boxes(boxes);
745733
for(auto& box : boxes)
746734
{
747-
content_size.width = std::max(content_size.width, x + box.x + box.width);
748-
content_size.height = std::max(content_size.height, y + box.y + box.height);
735+
sz.width = std::max(sz.width, x + box.x + box.width);
736+
sz.height = std::max(sz.height, y + box.y + box.height);
749737
}
750738
}
751739
}

0 commit comments

Comments
 (0)