Skip to content

Commit

Permalink
Emit text style changed in child
Browse files Browse the repository at this point in the history
Text styles like `font-weight`, `font-style` and `font-family`
are automatically inherited in CSS.

This commit makes the HTML export code only emit these styles when
- the text style of the cell changes in comparison to the parent cell or
- there is no parent cell.

To not disturb the inheritance, this commit also removes the default CSS text
styles from the header section.
  • Loading branch information
tobiolo committed Sep 8, 2023
1 parent a077adb commit ff701c5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/cell.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,12 @@ struct Cell {
str.Append(L"</cell>\n");
} else if (format == A_EXPHTMLT) {
wxString style;
if (text.stylebits & STYLE_BOLD) style += L"font-weight: bold;";
if (text.stylebits & STYLE_ITALIC) style += L"font-style: italic;";
if (text.stylebits & STYLE_FIXED) style += L"font-family: monospace;";
if (parent ? (text.stylebits & STYLE_BOLD) != (parent->text.stylebits & STYLE_BOLD) : true)
style += (text.stylebits & STYLE_BOLD) ? L"font-weight: bold;" : L"font-weight: normal;";
if (parent ? (text.stylebits & STYLE_ITALIC) != (parent->text.stylebits & STYLE_ITALIC) : true)
style += (text.stylebits & STYLE_ITALIC) ? L"font-style: italic;" : L"font-style: normal;";
if (parent ? (text.stylebits & STYLE_FIXED) != (parent->text.stylebits & STYLE_FIXED) : true)
style += (text.stylebits & STYLE_FIXED) ? L"font-family: monospace;" : L"font-family: sans-serif;";
if (cellcolor != (parent ? parent->cellcolor : doc->Background()))
style += wxString::Format(L"background-color: #%06X;", SwapColor(cellcolor));
if (textcolor != (parent ? parent->textcolor : 0x000000))
Expand Down
3 changes: 1 addition & 2 deletions src/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -879,8 +879,7 @@ struct Document {
L"<html>\n<head>\n<style>\n"
L"body { font-family: sans-serif; }\n"
L"table, th, td { border: 1px solid #A0A0A0; border-collapse: collapse;"
L" padding: 3px; vertical-align: top; font-weight: normal;"
L" font-style: normal; font-family: sans-serif; }\n"
L" padding: 3px; vertical-align: top; }\n"
L"li { }\n</style>\n"
L"<title>export of TreeSheets file ");
dos.WriteString(filename);
Expand Down

0 comments on commit ff701c5

Please sign in to comment.