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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ The release run heads these entries with the version and opens a fresh
`ROW()`, `COLUMN()` and a reference whose position changes.
- `font-family` ends with a generic family, so a font that is not installed
falls back to one of the same kind: a sans-serif font for Calibri, not the
browser's serif default. A bare font name is quoted.
browser's serif default. A bare font name is quoted, but a generic family
such as the `monospace` of Markdown code stays a keyword.
- An editable ods or xlsx sheet page carries the formula module, where the
build has one: the npm package does, and another build names it with
`ODR_FORMULA_MODULE`. The page is about 540 KB larger.
Expand Down
4 changes: 4 additions & 0 deletions src/odr/internal/html/document_style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ bool is_font_family_list(const std::string_view value) {

std::string html::translate_font_family(const std::string_view font_name) {
const std::string_view value = util::string::trim_view(font_name);
// a keyword, which quotes would turn into the name of a font no one has
if (is_generic_font_family(value)) {
return std::string(value);
}
if (value.find_first_of("'\",") == std::string_view::npos ||
!is_font_family_list(value)) {
std::string result = "'";
Expand Down
7 changes: 7 additions & 0 deletions test/src/internal/html/document_style_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ TEST(html_document_style, font_family_quotes_a_name_and_adds_its_kind) {
"'RobotoMono-Regular',monospace");
}

// Markdown names its code `monospace`: quoted, it is a font no one has.
TEST(html_document_style, font_family_keeps_a_generic_family_a_keyword) {
EXPECT_EQ(ihtml::translate_font_family("monospace"), "monospace");
EXPECT_EQ(ihtml::translate_font_family(" serif "), "serif");
EXPECT_EQ(ihtml::translate_font_family("Sans-Serif"), "Sans-Serif");
}

TEST(html_document_style, font_family_does_not_read_a_kind_into_a_longer_word) {
EXPECT_EQ(ihtml::translate_font_family("Monotype Corsiva"),
"'Monotype Corsiva',sans-serif");
Expand Down
Loading