Skip to content

feat: support for font color#12

Closed
mimai-hen wants to merge 3 commits into
cbeyls:mainfrom
mimai-hen:support-font-color
Closed

feat: support for font color#12
mimai-hen wants to merge 3 commits into
cbeyls:mainfrom
mimai-hen:support-font-color

Conversation

@mimai-hen

@mimai-hen mimai-hen commented May 13, 2025

Copy link
Copy Markdown

Hi,
I've added support for font tag with attribute color in hexadecimal format (no support for other font attributes)
It can be very useful for displaying multicolor text.
I need it for my project, and waiting for your remarks / approval
Many thanks !

@mimai-hen

Copy link
Copy Markdown
Author

Finally, as font is deprecated in HTML5, I've changed the pull request to support span tag with attribute style color in hexadecimal format (no support for other span or style attributes)

@cbeyls

cbeyls commented May 14, 2025

Copy link
Copy Markdown
Owner

Thank you for the submission!

I agree this is an important feature because the Android OS supports it, at least partially. Before adding the feature, I want to make sure it's as efficient as possible and provides at least the same level of support as the Android implementation. I'll probably do it myself when I have time but you can already check my comments if you want to improve the code.

@mimai-hen
mimai-hen force-pushed the support-font-color branch from 4826c11 to 6bae7ff Compare May 14, 2025 19:11
@cbeyls

cbeyls commented Jun 22, 2025

Copy link
Copy Markdown
Owner

Sorry for the delay, I took time to think this through and do my own implementation in #15.
I made the following changes compared to your implementation:

  • Text colors support is opt-in, because we want to respect the compose theme colors by default and make sure the text always contrasts properly with the background color in case of unsanitized HTML
  • I added support for RRGGBB, RRGGBBAA, RGB and RGBA hex colors formats
  • I added support for all CSS named colors
  • I rolled my own hex color parser which is fast and allocation-free because I was not happy with the 2 implementations available in the Kotlin standard library
  • I added text color support for all HTML inline tags, not just <span>. In case of <a>, I made sure the custom text colors properly override the link style color
  • I noticed that link colors are not properly overridden in Compose 1.7 so I updated the minimum compose version to 1.8.0

Even if I won't merge this PR I will still credit your work in the release notes. Thank you for your contribution!

@cbeyls cbeyls closed this Jun 23, 2025
@mimai-hen

Copy link
Copy Markdown
Author

Thank you very much @cbeyls 🙏 You're doing a great work 👍

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.

3 participants