Hello,
I've got another issue that I probably already have solved, but this one requires a far more thorough explanation:
I have built an EMail-Client in an application that is based on the demo "AdvRichEditor->MailClient", meaning that it uses an TAdvRichEditor + FormatToolBar to generate the HTML-Body for an email.
While testing I encountered an interesting phenomenon: Depending on the application -VCL-style and the style of the email-client (e.g. Thunderbird), the text of the received email would be invisible, either because of white text on white background or dark text on dark background.
In my case my application had a dark style with white text and the email-client (Thunderbird) a white background, which resulted in white font color on white background.
When you look into the html that is generated by the TAdvRichEditor, the problem is obvious: Every text-element is surrounded by a font-color-attribute, which forces the email-client to use THIS font color instead of the default font color of its own style, which would be correct.
Therefore I looked into the function TAdvRichEditorBase.GetContentAsHTML, where I found two issues:
- The variable "didclr" is always false, which means that the following If-clause is always true (except in the case of an URL of course):
if (not didclr or (clr <> GetDefaultFontColor)) and (el.URL = '') then
begin
didclr := false;
fontattr := AppendAttr(fontattr, 'color', ColorToHtml(clr));
isfntclr := true;
end;
This is obviously responsible for every text-element having a font-color-attribute.
Removing "didclr" or the "nots" before it solves this issue.
- Even with the aforementioned correction there is still an issue when you are using are VCL-Style in which the default font color isn't "clBlack", because quite early in TAdvRichEditorBase.GetContentAsHTML there is the following line:
SetFontColor(clBlack);
Regardless of the style or manual changes to the TAdvRichEditor.Font.Color, this line hardcodes it to "clBlack".
Now let us assume that my VCL-style is a dark theme with the TAdvRichEditor having a dark background & the default font color being "clwhite" and take a look at the very same code snippet that has received the aforementioned correction:
if ({not didclr or }(clr <> GetDefaultFontColor)) and (el.URL = '') then
begin
didclr := false;
fontattr := AppendAttr(fontattr, 'color', ColorToHtml(clr));
isfntclr := true;
end;
Once even a single text element has been colored in a different color as for example "clRed", every following text element will receive a font-color-attribute since "GetDefaultFontColor" is de facto hardcoded to "clBlack" whereas the correct default font color in this case would be "clWhite".
In this example if the text in the TAdvRichEditor were "Test1 Test2 Test3" and the color of "Test2" were to be changed to clRed, then in the resulting html "Test1" would not have a font-color-attribute, "Test2" would have one setting its color to red and "Test3" would incorrectly have also one setting its color to white.
Removing "SetFontColor(clBlack);", whose purpose I don't understand, solves this issue and the generated HTML, when given to an email, will be displayed correctly, regardless of VCL-style and email-client.
I strongly assume those two changes to be correct, at least in the context of generating an html for an email, but if I should have overlooked something I am open for correction.