Skip to content

fix: preserve color codes in STL#135

Merged
asticode merged 8 commits intoasticode:masterfrom
dlecorfec:fix-stl-color-preservation
Feb 23, 2026
Merged

fix: preserve color codes in STL#135
asticode merged 8 commits intoasticode:masterfrom
dlecorfec:fix-stl-color-preservation

Conversation

@dlecorfec
Copy link
Contributor

Color information was being lost when converting WebVTT to STL and back.
The stlStyler only handled italics, underline, and boxing but ignored
color control codes (0x00-0x07).

Changes:

  • Add color field to stlStyler struct
  • Parse color control codes (0x00-0x07) in parseSpacingAttribute
  • Write color codes in LineItem.STLString() method
  • Propagate WebVTT color tags to TeletextColor for STL export
  • Handle color codes in parseOpenSubtitleRow (don't error on valid codes)
  • Export Color.Equals() method for color comparison

This ensures colors are preserved in WebVTT → STL → WebVTT conversions.

Copy link
Owner

@asticode asticode left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! ❤️

@dlecorfec
Copy link
Contributor Author

The last commit should address the issues. Thanks for the review!

@asticode
Copy link
Owner

The last commit should address the issues. Thanks for the review!

Perfect! ❤️

Could you add some tests too?

@dlecorfec
Copy link
Contributor Author

dlecorfec commented Jan 16, 2026 via email

@asticode
Copy link
Owner

I don't mind merging the PR as is now however there are conflicts to be resolved in stl_test.go. Let me know when they're resolved and I'll merge the PR 👍

Happy skying! ⛷️

@dlecorfec dlecorfec force-pushed the fix-stl-color-preservation branch from 2426d5f to 17a9032 Compare January 29, 2026 10:22
@dlecorfec
Copy link
Contributor Author

Added the color refactoring you suggested. A side effect now that TTMLColor is internally RGB rather than string: if input file was a TTML with named colors, in output TTML file I have to chose to output either named colors or hex colors. I chose hex colors for wider compatibility (in ttml.go:ttmlColorString()).

@asticode
Copy link
Owner

Added the color refactoring you suggested. A side effect now that TTMLColor is internally RGB rather than string: if input file was a TTML with named colors, in output TTML file I have to chose to output either named colors or hex colors. I chose hex colors for wider compatibility (in ttml.go:ttmlColorString()).

Sounds good 👍 I've made a comment with a solution to fix what you've mentioned, but I'd understand if you didn't feel like adding it now in this already complete PR 👍

@dlecorfec
Copy link
Contributor Author

Hi, not sure I did what you wanted with Color.HTMLString.
Maybe, to preserve most information when reading/writing the same format, a bool "HasName" or a string "Name" (which may be redundant) could be added to the Color struct, so if the source file used a color name instead of a code, the value would be set and the writer would use the name instead of the code.
Also Color.CSSString could be renamed to WebVTTString (or newColorFromWebVTTString could be renamed to newColorFromCSSString).

Copy link
Owner

@asticode asticode left a comment

Choose a reason for hiding this comment

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

Almost there! 👍

@dlecorfec
Copy link
Contributor Author

Done, are we there yet ? :)

@asticode asticode merged commit 2785085 into asticode:master Feb 23, 2026
1 check passed
@asticode
Copy link
Owner

Done, are we there yet ? :)

Mhahaha we're finally there!!

Thanks for sticking with this PR ❤️

Let me know whether you need a tag 👍

@asticode
Copy link
Owner

FYI I've created a v0.39.0 tag 👍

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