Skip to content

Conversation

SoftWyer
Copy link

@SoftWyer SoftWyer commented Aug 3, 2019

Initial go at adding HEX colour support for the font tag as well as adding the font tag to the Rich Text parser.

Added some tests and fixed the footer test.

Added a utils file to hold the HexColor class and support functions. Happy to rename this or site it elsewhere in the codebase, just let me know.

@SoftWyer
Copy link
Author

The build fails with the font 'golden' file. I would change this, but almost all the golden file tests fail on my windows DEV box so it's likely that my golden font PNG file would not match the one generated by the CI tests.

@SoftWyer
Copy link
Author

This PR might be redundant now that v1 is coming out. Whilst v1 doesn't directly support color on the font tag, it can be replicated by a custom renderer to some extent.

The following custom renderer will color some children directly:

Map<String, CustomRender> customRenderer = {
  "font": (renderContext, child, attributes, element) {
    if (attributes.containsKey('color')) {
      Style newStyle = renderContext.style.copyWith(
        color: Colors.red, // hardcoded example
      );
      return ContainerSpan(
        newContext:
            RenderContext(buildContext: renderContext.buildContext, style: newStyle, parser: renderContext.parser),
        style: newStyle,
        children: (child as ContainerSpan)?.children,
        child: (child as ContainerSpan)?.child,
      );
    }
    return child;
  },
};

However, it doesn't work if the child is a <b> tag, e.g.

<font color='red'><b>some text</b></font>

The text is still rendered in black, albeit bolded. I don't know if this is a bug? I suspect that the children do not inherit the styles as they've already been parsed.

I did play around with the nodes/elements directly, and could re-parse the html but it rendered a new document within the current one so all the spacings and margins were out. It would be nice to have some utility functions to re-render a partial node with new styles and drop it into the current document as part of the custom renderer if that is possible?

@tneotia
Copy link
Contributor

tneotia commented Feb 4, 2021

Hi there, thanks for this PR! It looks like this code applies to the old parser and thus is incompatible with the latest changes on the branch. As a result, we may close this PR.
Also, we have already added hex color support (and rgb support) into the library with inline styles (e.g. <span style='color: #FF0000;'>text will be red</span>).
Later we may decide to add the font tag, but I think for the majority of people the inline styles are good enough. Again thanks for contributing! :)

CC @erickok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request low-priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants