Bug 126533 - FILEOPEN/FILESAVE DOCX: bitmap background image not saved with document
Summary: FILEOPEN/FILESAVE DOCX: bitmap background image not saved with document
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
3.3.0 release
Hardware: All All
: medium normal
Assignee: Justin L
URL:
Whiteboard: target:24.8.0
Keywords: filter:docx
: 134822 143885 152536 (view as bug list)
Depends on: 153761 159626
Blocks: DOCX-Page
  Show dependency treegraph
 
Reported: 2019-07-25 07:25 UTC by Hugo Scott
Modified: 2024-03-27 19:48 UTC (History)
11 users (show)

See Also:
Crash report or crash signature:


Attachments
pageStyleBitmap2010.docx: minimal document with image fill for background (76.92 KB, application/vnd.openxmlformats-officedocument.wordprocessingml.document)
2024-02-01 18:05 UTC, Justin L
Details
pageStyleNoBitmap.docx: here is one to throw you for a loop - shouldn't show bitmap (62.20 KB, application/vnd.openxmlformats-officedocument.wordprocessingml.document)
2024-02-13 01:32 UTC, Justin L
Details
Visual comparison: original ODT left, exported DOCX right (67.01 KB, image/png)
2024-02-24 11:21 UTC, Gerald Pfeifer
Details
Image used as background in previous example (11.70 KB, image/png)
2024-02-24 11:21 UTC, Gerald Pfeifer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Hugo Scott 2019-07-25 07:25:31 UTC
Description:
Hi
I define a full page background image in writer by

1. View->Styles
2. Click on page tab -> create styele and then on bitmap
3. Import bitmap and save with name
4. Apply as a custom size with dimensions of 21 cm x 30 cm 

This adds the image and I can export it as a pdf with the image

When I save, close and reopen the docx file the image has disappeared and I have to re-create the style and import the image etc

Steps to Reproduce:
1. View->Styles
2. Click on page tab -> create styele and then on bitmap
3. Import bitmap and save with name
4. Apply as a custom size with dimensions of 21 cm x 30 cm 
5. save and close
6. reopen

Actual Results:
reopen the docx file the image has disappeared and I have to re-create the style and import the image etc

Expected Results:
ThHe image should still be there as a BG


Reproducible: Always


User Profile Reset: No



Additional Info:
Version: 6.3.0.2 (x64)
Build ID: 728469fa359ba8c83d812146293a0b0aa53945ba
CPU threads: 4; OS: Windows 10.0; UI render: default; VCL: win; 
Locale: en-GB (en_GB); UI-Language: en-GB
Calc: threaded
Comment 1 Dieter 2019-07-26 04:55:40 UTC
I confirm it with

Version: 6.4.0.0.alpha0+ (x64)
Build ID: 8f98a7c4e5b1f0b249c026577805a378b8a533d5
CPU threads: 4; OS: Windows 10.0; UI render: GL; VCL: win; 
TinderBox: Win-x86_64@42, Branch:master, Time: 2019-07-23_00:30:19
Locale: de-DE (de_DE); UI-Language: en-US
Calc: threaded

Also happens with other sizes of the bitmap.
Comment 2 Hugo Scott 2019-07-31 12:34:49 UTC
The background bitmap DOES remain when the doc is saved in .odt format but not in docx format, if that's any help.
If that means that it's not a bug after all, then I'm very sorry!
Comment 3 Timur 2021-05-07 08:55:19 UTC
This is DOCX bug that started with LO 3.3 in which export was added. 
Background of saved DOCX is not read in LO nor in MSO.

DOC is better, background is fine read in MSO meaning that export is fine. If original was saved as Tiled, LO opens it as Stretched. That can be another fileopen bug.
Comment 4 Robert Cabane 2021-05-09 21:25:11 UTC
Same with LO 7.1.3.2.
Agreeing with the two last comments : background is lost when exporting to DOCX, but not to DOC.
Comment 5 Gerald Pfeifer 2021-07-09 21:07:14 UTC
I saw a related report by an openSUSE user. Their report does not require
using a style, simply

 - right click
 - Page Style
 - Area
 - Bitmap

and the same observations: completely lost with DOCX, stretched with DOC.

(Cf. https://bugzilla.suse.com/show_bug.cgi?id=1133169 )
Comment 6 Timur 2021-08-16 08:58:22 UTC
*** Bug 143885 has been marked as a duplicate of this bug. ***
Comment 7 Volga 2021-08-16 16:03:23 UTC
Everyone can reproduce the bug directly with attachment 152249 [details].
Comment 8 Rizal Muttaqin 2022-07-27 04:24:26 UTC Comment hidden (obsolete)
Comment 9 Rizal Muttaqin 2022-07-27 04:26:05 UTC
(In reply to Robert Cabane from comment #4)
> Same with LO 7.1.3.2.
> Agreeing with the two last comments : background is lost when exporting to
> DOCX, but not to DOC.

I have tried also with DOC, and the issue persist (page background lost)

Version: 7.3.4.2 / LibreOffice Community
Build ID: 30(Build:2)
CPU threads: 8; OS: Linux 5.15; UI render: default; VCL: kf5 (cairo+xcb)
Locale: id-ID (id_ID.UTF-8); UI: id-ID
Ubuntu package version: 1:7.3.4~rc2-0ubuntu0.20.04.1~lo1
Calc: threaded
Comment 10 Roman Kuznetsov 2022-09-28 07:21:06 UTC
Still here in 

Version: 7.5.0.0.alpha0+ (x64) / LibreOffice Community
Build ID: 0d3dd0aa54ad792f91d0905f3d46c13df3512d89
CPU threads: 4; OS: Windows 10.0 Build 19043; UI render: Skia/Raster; VCL: win
Locale: ru-RU (ru_RU); UI: en-US
Calc: threaded

and this is very annoying
Comment 11 Roman Kuznetsov 2022-09-28 08:02:37 UTC Comment hidden (obsolete)
Comment 12 Roman Kuznetsov 2022-09-28 08:11:26 UTC Comment hidden (obsolete)
Comment 13 Justin L 2022-09-28 15:32:14 UTC
From bug 135331 comment 6
If my memory is correct, DOCX only has a single place to store the page background. So LO takes the Default Page's background and uses that as the colour. In this multi-coloured page-styled example, the default page style is "none".  [Indeed, this is what happens for both DOC and DOCX when I change the default page style (even though it is unused) to a blue background. The entire DOCX becomes blue.]
Comment 14 Justin L 2022-09-28 15:32:57 UTC
*** Bug 134822 has been marked as a duplicate of this bug. ***
Comment 15 Justin L 2024-02-01 14:54:17 UTC
Both fileopen and filesave have never worked in LO for docx or rtf. However, .doc can import(since 5.0) and export(already in 3.3). Unfortunately, no bibisect exists for 5.0.

The xml looks like this
<w:background w:color="FFFFFF">
  <v:background id="_x0000_s1025" o:bwmode="white">
    <v:fill r:id="rId3" o:title="wasta-offline" recolor="t" type="frame"/>
  </v:background>
</w:background>

For plain color, LO gained DOCX import and export in LO 4.2
commit 992da0d5cf04497bad55637f6a6ebfcdaec03e16
Author:     Miklos Vajna on Mon May 27 17:49:12 2013 +0200
    bnc#817956 DOCX import of document background color

commit 515701a1ff18d04ede235bef862c465adf41062f
Author: Adam Co on Mon Jun 3 09:59:33 2013 +0200
    fdo#65257 : DOCX not exporting background color
Comment 16 Justin L 2024-02-01 15:36:21 UTC Comment hidden (no-value)
Comment 17 Justin L 2024-02-01 16:53:21 UTC
v:background can have id, fillcolor, filled (overridden by fill child), o:bwmode, o:bwnormal o:bwpure, o:targetscreensize.

It can have a fill child: a vml shape that can be gradients, etc.

bug 78749 (which dealt with image fill on textboxes) looks like the perfect code to copy for importing the fill child. (export already worked at that point)
Comment 18 Justin L 2024-02-01 18:05:02 UTC
Created attachment 192326 [details]
pageStyleBitmap2010.docx: minimal document with image fill for background
Comment 19 Justin L 2024-02-13 01:32:24 UTC
Created attachment 192532 [details]
pageStyleNoBitmap.docx: here is one to throw you for a loop - shouldn't show bitmap
Comment 20 Justin L 2024-02-15 17:39:39 UTC
Note that page backgrounds are a bit strange in MSO, very much dependent on display DPI.

Using comment 18 as an example, when I open in MSO2003 I see about 25% of the logo, but on a different computer I see 75%.Increasing the zoom level to 200% shows 90% of the logo. Exporting to PDF shows MANY tiles of the logo. So far all my printing (to PDF) tests have printed no logo at all. So "the same background" in MSO and LO is basically impossible (and undesirable) to achieve.

Duplicate bug 134822's example document is a nice example of this. The screenshot shows only clouds, but if you zoom to 500% the background changes to show many tiles of the entire image, including lots of green ground and mountains.
Comment 21 Justin L 2024-02-16 16:10:04 UTC
*** Bug 152536 has been marked as a duplicate of this bug. ***
Comment 22 Commit Notification 2024-02-20 15:55:13 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

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

tdf#126533 docx import: page background vml fill

It will be available in 24.8.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 23 Commit Notification 2024-02-21 07:42:59 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

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

tdf#126533 docx export: page background vml fill: basic image

It will be available in 24.8.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 24 Commit Notification 2024-02-21 07:46:02 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

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

tdf#126533 docx export: page background vml fill: tiles/patterns

It will be available in 24.8.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 25 Commit Notification 2024-02-23 09:54:20 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/396ece804b3a31e4eddf56de4e557f3755331d8c

related tdf#126533 vml import: fix gradient color swapping

It will be available in 24.8.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 26 Commit Notification 2024-02-23 09:56:23 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

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

tdf#126533 DOCX: export page vml fill gradient

It will be available in 24.8.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 27 Commit Notification 2024-02-23 09:57:26 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/1a4639dd8024484971859bcce31470584bc6b973

related tdf#126533 DOCX: vml export gradientRadial instead of gradient

It will be available in 24.8.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 28 Commit Notification 2024-02-23 09:58:29 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

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

related tdf#126533 vml export: fix axial colors

It will be available in 24.8.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 29 Commit Notification 2024-02-23 19:28:49 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/6dd6891a3deed8718bf2b0fcf564f229f676f8ba

related tdf#126533 tdf#159824 VML: don't export: negative angles

It will be available in 24.8.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 30 Gerald Pfeifer 2024-02-24 11:21:11 UTC
Created attachment 192743 [details]
Visual comparison: original ODT left, exported DOCX right

Thank you, Justin, quite some improvements1 I tested this with today's
dev build

  Version: 24.8.0.0.alpha0+ (X86_64) / LibreOffice Community
  Build ID: ef57aeb9ed190e18ebc034b9a45e190aea3f8f1d
  CPU threads: 12; OS: Linux 6.7; UI render: default; VCL: gtk3
  Locale: en-US (en_US.UTF-8); UI: en-US

and can confirm that saving as DOCX no longer loses a background image.

I did note, however, that the background starts a little lower and the
tiling aligns differently - see screenshot. Is this unavoidable?
Comment 31 Gerald Pfeifer 2024-02-24 11:21:57 UTC
Created attachment 192744 [details]
Image used as background in previous example
Comment 32 Commit Notification 2024-02-24 12:14:26 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

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

tdf#126533 rtf import: page background fill

It will be available in 24.8.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 33 Justin L 2024-02-24 17:36:34 UTC
(In reply to Gerald Pfeifer from comment #30)
> I did note, however, that the background starts a little lower and the
> tiling aligns differently - see screenshot. Is this unavoidable?
Did you see comment 20?

I tried our DOC implementation. It too seems to save only in automatic mode (stretched), with no support at all for custom position/size.

So far I have been using MSO 2003 for my reference. Today I verified that MSO 2019 still has a super-minimal background UI - where only the picture can be chosen but no options whatsoever.

Note that page background is defined using the old VML markup language. All other fills are defined using the more capable and modern DML.

Reusing existing code (from textboxes) would seem to require extraordinary effort because our VML expects an SdrObject, but I didn't see any way to get an SdrObject out of our XGraphic.

So, I think it is mostly unavoidable, but I'm not that familiar with the capabilities of VML to describe graphics.
Comment 34 Commit Notification 2024-02-26 16:17:00 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/589ac948c0650a16c734db7337c6c31b950be151

related tdf#126533 doc export: don't lose "tiled" aspect of image fill.

It will be available in 24.8.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 35 Commit Notification 2024-02-27 07:41:50 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/38083e4c0b5638d69162593c3fbf599da6cd499f

related tdf#126533 dml/vml import: import radials as radials

It will be available in 24.8.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 36 Justin L 2024-02-27 13:42:52 UTC
I consider this bug report as solved (with many caveats). The basic document background (using images, gradients, textures, or patterns) can be imported and exported to the DOCX format, and many supporting VML pattern and gradient fixes were achieved.

The main caveat is related to images. For the reasons described in comment 20, there should be no expectation that the background picture in LO will look the same in MSO (unless the image is pre-sized for the intended environment). The main purpose then is just that LO is able to use the DOCX format to retain the selected document background fill for its own use.

I did not have time to do any advanced investigation into if it is possible to successfully round-trip any custom image position/size. Therefore the image needs to be pre-sized correctly so that it looks good in automatic (“stretched”) or tiled mode. The MSO UI has no options (in image or texture) for configuring how it will look anyway, so MSO has no expectation of "fancy settings".

Textures are just tiled images. These should work great and look identical to MSO.

Patterns should also work nicely because they are turned into textures.

Gradients should work as well as they work for shapes/textboxes (with the caveat that page background is VML-coded, while shapes and textboxes show DML-coded gradients, so unseen VML bugs may surface).

Hatches are unsupported by VML and MSO, and so continue to be turned into a solid color approximation. Supporting hatches would require turning them into a full-page-sized image. See https://gerrit.libreoffice.org/c/core/+/163471 for code pointers, and regression bug 153761 for the failure to do this for shapes/textboxes as well.

RTF has very poor support for background fill in general – with basically only gradient import working, so I didn’t worry about that format (although import is wired up so that any improvements should come automatically).
Comment 37 Volga 2024-02-27 17:03:53 UTC
(In reply to Justin L from comment #36)
> RTF has very poor support for background fill in general – with basically
> only gradient import working, so I didn’t worry about that format (although
> import is wired up so that any improvements should come automatically).

This should have an explanation in release notes.
Comment 38 Justin L 2024-03-27 19:48:53 UTC
(In reply to Justin L from comment #20)
> Using comment 18 as an example, when I open in MSO2003 I see about 25% of
> the logo, but on a different computer I see 75%
That is because the different computer is using display scaling of 150%. [Screen resolution has no effect, so not as bad as I first thought.]

For DOCX, MSO always tiles the background. However, for DOC formats it does honour a "stretch" round-trip. However, even is MSO2010 round-trips DOC->DOCX the background imports as tiled.

I considered doing the same with https://gerrit.libreoffice.org/c/core/+/165398.

However, it looks like a MSO bug to me (since DOC can handle it). So I decided to abandon it.