Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/odr/internal/html/document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,13 @@ class TextHtmlFragment final : public HtmlFragmentBase {
const TextRoot element = root.as_text_root();

if (state.config().text_document_margin) {
auto page_layout = element.page_layout();
page_layout.height = {};
const PageLayout page_layout = element.page_layout();

out.write_element_begin(
"div", HtmlElementOptions()
.set_class("odr-page-outer")
.set_style(translate_outer_page_style(page_layout)));
"div",
HtmlElementOptions()
.set_class("odr-page-outer")
.set_style(translate_outer_flowing_page_style(page_layout)));
out.write_element_begin(
"div", HtmlElementOptions()
.set_class("odr-page-inner")
Expand Down
13 changes: 13 additions & 0 deletions src/odr/internal/html/document_style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@ std::string html::translate_outer_page_style(const PageLayout &page_layout) {
return result;
}

std::string
html::translate_outer_flowing_page_style(const PageLayout &page_layout) {
PageLayout flowing_page_layout = page_layout;
flowing_page_layout.height = {};

std::string result = translate_outer_page_style(flowing_page_layout);
if (const std::optional<Measure> height = page_layout.height;
height.has_value()) {
result.append("min-height:").append(height->to_string()).append(";");
}
return result;
}

std::string html::translate_inner_page_style(const PageLayout &page_layout) {
std::string result;
if (const std::optional<Quantity<double>> margin_right =
Expand Down
1 change: 1 addition & 0 deletions src/odr/internal/html/document_style.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const char *translate_font_style(FontStyle font_style);
const char *translate_font_position(FontPosition font_position);

std::string translate_outer_page_style(const PageLayout &page_layout);
std::string translate_outer_flowing_page_style(const PageLayout &page_layout);
std::string translate_inner_page_style(const PageLayout &page_layout);
std::string translate_text_style(const TextStyle &text_style);
std::string translate_paragraph_style(const ParagraphStyle &paragraph_style);
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ add_executable(odr_test
"src/table_position_test.cpp"

"src/internal/html/common_test.cpp"
"src/internal/html/document_style_test.cpp"
"src/internal/html/image_file_test.cpp"
"src/internal/html/media_file_test.cpp"

Expand Down
37 changes: 37 additions & 0 deletions test/src/internal/html/document_style_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <odr/quantity.hpp>
#include <odr/style.hpp>

#include <odr/internal/html/document_style.hpp>

#include <gtest/gtest.h>

using namespace odr;
namespace ihtml = odr::internal::html;

namespace {

PageLayout a4_page_layout() {
PageLayout page_layout;
page_layout.width = Measure("21cm");
page_layout.height = Measure("29.7cm");
return page_layout;
}

} // namespace

TEST(html_document_style, outer_page_style_fixes_both_dimensions) {
EXPECT_EQ(ihtml::translate_outer_page_style(a4_page_layout()),
"width:21cm;height:29.7cm;");
}

TEST(html_document_style, outer_flowing_page_style_floors_the_height) {
EXPECT_EQ(ihtml::translate_outer_flowing_page_style(a4_page_layout()),
"width:21cm;min-height:29.7cm;");
}

TEST(html_document_style, outer_flowing_page_style_without_height) {
PageLayout page_layout = a4_page_layout();
page_layout.height = {};
EXPECT_EQ(ihtml::translate_outer_flowing_page_style(page_layout),
"width:21cm;");
}
Loading