diff --git a/CMakeLists.txt b/CMakeLists.txt index 27f8980e..a4f467fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -200,7 +200,7 @@ else () ExternalProject_Add( litehtml-tests GIT_REPOSITORY https://github.com/litehtml/litehtml-tests.git - GIT_TAG 7511158e62cdac071de9071e060828e9e3c0bcc6 + GIT_TAG ab4a66548126bce74ecf2dc8027c116701d157c4 SOURCE_DIR "${CMAKE_BINARY_DIR}/litehtml-tests-src" BINARY_DIR "${CMAKE_BINARY_DIR}/litehtml-tests-build" CMAKE_ARGS -DLITEHTML_PATH=${CMAKE_CURRENT_SOURCE_DIR} diff --git a/include/litehtml/html_tag.h b/include/litehtml/html_tag.h index d8c9dfa4..4ea09da7 100644 --- a/include/litehtml/html_tag.h +++ b/include/litehtml/html_tag.h @@ -105,7 +105,7 @@ namespace litehtml string dump_get_name() override; protected: - void draw_list_marker( uint_ptr hdc, const position &pos ); + void draw_list_marker( uint_ptr hdc, const position &pos, const std::shared_ptr &ri ); string get_list_marker_text(int index); element::ptr get_element_before(const style& style, bool create); element::ptr get_element_after(const style& style, bool create); diff --git a/src/html_tag.cpp b/src/html_tag.cpp index 08f289df..3568f0ae 100644 --- a/src/html_tag.cpp +++ b/src/html_tag.cpp @@ -314,7 +314,7 @@ void litehtml::html_tag::draw(uint_ptr hdc, int x, int y, const position *clip, get_document()->container()->set_clip(pos, bdr_radius); } - draw_list_marker(hdc, pos); + draw_list_marker(hdc, pos, ri); if(m_css.get_overflow() > overflow_visible) { @@ -1047,7 +1047,7 @@ bool litehtml::html_tag::is_replaced() const return false; } -void litehtml::html_tag::draw_list_marker( uint_ptr hdc, const position& pos ) +void litehtml::html_tag::draw_list_marker( uint_ptr hdc, const position& pos, const std::shared_ptr &ri ) { list_marker lm; @@ -1072,8 +1072,10 @@ void litehtml::html_tag::draw_list_marker( uint_ptr hdc, const position& pos ) if (css().get_list_style_type() >= list_style_type_armenian) { - lm.pos.y = pos.y; - lm.pos.height = pos.height; + auto li_baseline = pos.y + ri->get_first_baseline() - ri->content_offset_top(); + lm.pos.y = li_baseline - css().get_font_metrics().ascent; + lm.pos.height = css().get_font_metrics().height; + lm.index = atoi(get_attr("list_index", "0")); } else @@ -1121,7 +1123,6 @@ void litehtml::html_tag::draw_list_marker( uint_ptr hdc, const position& pos ) if (m_css.get_list_style_type() >= list_style_type_armenian) { auto marker_text = get_list_marker_text(lm.index); - lm.pos.height = ln_height; if (marker_text.empty()) { get_document()->container()->draw_list_marker(hdc, lm); diff --git a/src/line_box.cpp b/src/line_box.cpp index 20aed39f..0fe1cab0 100644 --- a/src/line_box.cpp +++ b/src/line_box.cpp @@ -535,7 +535,14 @@ std::list< std::unique_ptr > litehtml::line_box::finish // We have inline items top_shift = std::abs(line_max_height.top); const int top_shift_correction = (line_height.value() - line_max_height.height()) / 2; - m_baseline = line_max_height.bottom + top_shift_correction; + // We have to calculate the baseline from the top of the line box due to possible round errors. + // The top_shift_correction is actually text offset from the top of the line box. + // The (top_shift_correction + line_max_height.height()): is the bottom of the text with shift (text_bottom). + // The line_max_height.bottom is the text baseline here. + // So the formula is: + // baseline = line_height - text_bottom + text_baseline + // The linebox baseline is the length from the bottom of the line box to the text baseline. + m_baseline = line_height.value() - (top_shift_correction + line_max_height.height()) + line_max_height.bottom; top_shift += top_shift_correction; if(inline_boxes_dims.count) {