[PR #16035] Use MSWord compatible RTF sequence for background text color #30815

Open
opened 2026-01-31 09:43:09 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/16035

State: closed
Merged: Yes


The GenRTF(...) was using \highlight control word for sending background text color in the RTF format during a copy command. This doesn't work correctly, since many applications (E.g. MSWord) don't support full RGB with \highlight, and instead uses an approximation of what is received. For example, rgb(197, 15, 31) becomes rgb(255, 0, 255). Also, the standard way of using background colors is \cbN control word, which isn't supported as per the RTF Spec 1.9.1 in Word.

But it briefly mentioned a workaround at Pg. 23, which seems to work on all the RTF editors I tested:

image

The PR makes the changes to use \chshdng0\chcbpatN for the background coloring.

Also did some refactoring to make the implementation concise.

Validation Steps Performed

Verified that the background is correctly copied on below editors:

  • MSWord
  • WordPad
  • LibreOffice
  • Outlook
**Original Pull Request:** https://github.com/microsoft/terminal/pull/16035 **State:** closed **Merged:** Yes --- The `GenRTF(...)` was using `\highlight` control word for sending background text color in the RTF format during a copy command. This doesn't work correctly, since many applications (E.g. MSWord) don't support full RGB with `\highlight`, and instead uses an approximation of what is received. For example, `rgb(197, 15, 31)` becomes `rgb(255, 0, 255)`. Also, the standard way of using background colors is `\cbN` control word, which isn't supported as per the [RTF Spec 1.9.1](https://msopenspecs.azureedge.net/files/Archive_References/[MSFT-RTF].pdf) in Word. But it briefly mentioned a workaround at Pg. 23, which seems to work on all the RTF editors I tested: ![image](https://github.com/microsoft/terminal/assets/55626797/67b45c91-e367-4f5c-906c-b84c27283616) The PR makes the changes to use `\chshdng0\chcbpatN` for the background coloring. Also did some refactoring to make the implementation concise. ## Validation Steps Performed Verified that the background is correctly copied on below editors: - MSWord - WordPad - LibreOffice - Outlook
claunia added the pull-request label 2026-01-31 09:43:09 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#30815