Bug 153341 - Copied HTML text which uses the alpha channel is pasted either without it (when rgb(r g b / a) notation is used) or without any color (when rgba(r, g, b, a) notation is used)
Summary: Copied HTML text which uses the alpha channel is pasted either without it (wh...
Status: VERIFIED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
7.4.4.2 release
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: Julien Nabet
URL:
Whiteboard: target:7.6.0 target:7.5.1
Keywords:
Depends on:
Blocks:
 
Reported: 2023-02-03 07:12 UTC by Fabio Pesari
Modified: 2023-02-10 14:58 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fabio Pesari 2023-02-03 07:12:34 UTC
Description:
Hello,

copying-and-pasting HTML text whose inline style contains color into LibreOffice Writer does not work properly, as the pasted text will not always show its actual color.

When the rgb(r g b / a) CSS notation is used, the alpha channel is ignored and rgb(r, g, b) is used instead.

When the rgba(r, g, b, a) CSS format is used, the color is ignored entirely.

Only text using the rgb(r, g, b) CSS format (without an alpha channel) will show the correct color in LibreOffice writer.

Steps to Reproduce:
1. Copy this HTML markup inside a file:

<!DOCTYPE html>
<html lang="">
  <head>
    <meta charset="utf-8">
    <title>Color test</title>
  </head>
  <body>
    <p style="color: rgb(255, 0, 0)">1) This text is pasted with color</p>
    <p style="color: rgb(255 0 0 / 50%)">2) This text is also pasted with color, but the text pasted has a color which ignores the alpha channel</p>
    <p style="color: rgba(255, 0, 0, 0.3)">3) This text is pasted without color</p>
  </body>
</html>

2. Open the created HTML file with a web browser
3. Copy the three lines of text into the clipboard
4. Paste the clipboard into LibreOffice Writer

Actual Results:
Pasting line 1) (which uses the rgb(r, g, b) format) into LibreOffice Writer will show the right color.

Pasting line 2) (which used the rgb(r g b / a) format) into LibreOffice Writer will show a wrong color (in this case, rgb(r, g, b) without the alpha channel).

Pasting line 3) into LibreOffice Writer will not show any color.

Expected Results:
All three lines should show the correct color.


Reproducible: Always


User Profile Reset: No

Additional Info:
Please note that an alpha channel is not needed to show rgba text. The algorithm in https://marcodiiga.github.io/rgba-to-rgb-conversion can be used to turn a RGBA color into RGB.

So, from my example,

rgba(255, 0, 0, 0.3)

can be rendered as:

rgb(255,179,179)

by setting white as the background color.
Comment 1 Julien Nabet 2023-02-03 18:03:49 UTC
On pc Debian x86-64 with master sources updated today, I could reproduce this.

I gave a try with https://gerrit.libreoffice.org/c/core/+/146546
Comment 2 Commit Notification 2023-02-04 17:34:55 UTC
Julien Nabet committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/a21aad5e084e3901a1e216ef9006b0f8b6132c39

tdf#153341: try to parse alpha value when copying HTML text

It will be available in 7.6.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 3 Julien Nabet 2023-02-06 07:49:37 UTC
Cherry-pick for 7.5 waiting for review here:
https://gerrit.libreoffice.org/c/core/+/146524
Comment 4 Commit Notification 2023-02-07 11:31:06 UTC
Julien Nabet committed a patch related to this issue.
It has been pushed to "libreoffice-7-5":

https://git.libreoffice.org/core/commit/879db444dbc072a43fa0df460b48558ea4d9def5

tdf#153341: try to parse alpha value when copying HTML text

It will be available in 7.5.1.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 5 Xisco Faulí 2023-02-10 12:04:10 UTC
Verified in

Version: 7.6.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: 00b9b33334791079c2dc26b1ed4c123450cabf7d
CPU threads: 8; OS: Linux 5.10; UI render: default; VCL: gtk3
Locale: es-ES (es_ES.UTF-8); UI: en-US
Calc: threaded

@Julien, thanks for fixing this issue!!
Comment 6 Commit Notification 2023-02-10 14:58:20 UTC
Xisco Fauli committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/cc685e16b5325384268ddd52f24293b6e4bf3502

tdf#153341: sw_htmlimport: Add unittest

It will be available in 7.6.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.