Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit cellcolor and/or textcolor in X(HT)ML #503

Merged

Conversation

tobiolo
Copy link
Collaborator

@tobiolo tobiolo commented Sep 8, 2023

No description provided.

@tobiolo tobiolo force-pushed the emit-cellcolor-textcolor-on-child-change branch 3 times, most recently from dae5801 to bbeddfd Compare September 8, 2023 17:40
@tobiolo tobiolo changed the title Emit cellcolor and/or textcolor in X(HT)ML export when it differs fro… Emit cellcolor and/or textcolor in X(HT)ML Sep 8, 2023
@tobiolo
Copy link
Collaborator Author

tobiolo commented Sep 8, 2023

@aardappel This is ready to go from my side. Could you review?

src/cell.h Outdated
@@ -260,9 +260,9 @@ struct Cell {
if (text.stylebits & STYLE_BOLD) style += L"font-weight: bold;";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you make a similar change for uses of stylebits ?

Copy link
Collaborator Author

@tobiolo tobiolo Sep 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I can try. 😄

@tobiolo tobiolo force-pushed the emit-cellcolor-textcolor-on-child-change branch from bbeddfd to 6ff1489 Compare September 8, 2023 22:19
When `cellcolor` or `textcolor` in a cell differs
from the one of the parent cell, emit its value.

See aardappel#502
for more details.
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.
@tobiolo tobiolo force-pushed the emit-cellcolor-textcolor-on-child-change branch from 6ff1489 to ff701c5 Compare September 8, 2023 22:24
@tobiolo
Copy link
Collaborator Author

tobiolo commented Sep 8, 2023

@aardappel
What do you think of these two commits?
Caution: This will work fine with a HTML export of the whole TreeSheets document, but not with a partial one like when you copy the HTML export of the selection to clipboard (because the inheritered information is outside of the selection).

@@ -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"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this deleted?

Copy link
Collaborator Author

@tobiolo tobiolo Sep 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how I got it: Because if we do inheritance and we have parent and child cell share e.g. same font-style that is not the default one (e.g. bold instead of normal), then the code will not add that font-style again for the child as it shall be inherited (this is the goal). But because no font-style is supplied in the child's style attribute then but a default one is defined in the style section in the header, that one is prioritized over the inherited one. In order to avoid that situation, do not create this overriding styles in the header.

@@ -237,12 +237,12 @@ struct Cell {
str.Prepend(wxString() << text.stylebits);
str.Prepend(L" stylebits=\"");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please also check for these stylebits

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok please see last commit. It XORs the stylebits from child and parent. Only if they differ, stylebits will be emitted in XML export.

src/cell.h Outdated
if (text.stylebits & STYLE_ITALIC) style += L"font-style: italic;";
if (text.stylebits & STYLE_FIXED) style += L"font-family: monospace;";
if (cellcolor != doc->Background())
if (parent ? (text.stylebits & STYLE_BOLD) != (parent->text.stylebits & STYLE_BOLD) : true)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be simplified to !parent || (text.stylebits & STYLE_BOLD) != (parent->text.stylebits & STYLE_BOLD)

Copy link
Collaborator Author

@tobiolo tobiolo Sep 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah thanks!

Style inheritance should be used for the HTML export of the entire
document but not for the HTML export of the selection to the clipboard.

This commit adds the capability for both ways.
@tobiolo
Copy link
Collaborator Author

tobiolo commented Sep 8, 2023

@aardappel So I added two commits. They are good to go for a next review round from my side.
I am looking forward for your feedback.

@aardappel
Copy link
Owner

LGTM!

@aardappel aardappel merged commit 3994f4c into aardappel:master Sep 9, 2023
4 checks passed
@tobiolo tobiolo deleted the emit-cellcolor-textcolor-on-child-change branch September 9, 2023 07:59
@tobiolo
Copy link
Collaborator Author

tobiolo commented Sep 9, 2023

LGTM!

Thanks for your highly valuable review and your time spent! I highly appreciate this.

I wish you a wunderful weekend!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants