Index ¦ Archives ¦ RSS

Writer embedded objects: reliably update object previews

Estimated read time: 2 minutes

Embedded objects in Writer consist of a native data part and a preview part. Until now, there was no way to force the update of the preview part in case it was empty.

Now the Tools → Update → Update all menu item updates such previews as well. This is especially useful if you manipulate the ZIP/XML document directly to insert native data, then load it into Writer to generate a preview.

First, thanks Vector who made this work by Collabora possible.

Motivation

The Update all menu item already updates all sorts of generated content: fields, table of contents, charts, the document layout, but not the preview of embedded objects. You could work this around by double-clicking on the embedded object to re-generate the preview, but doing this manually for a larger document is not efficient. This is especially useful for hand-crafted documents which have proper native data, but no preview image yet.

Results so far

Here is how an embedded object without a preview looks like:

https://share.vmiklos.hu/blog/sw-ole-update/old.png
Figure 1. Writer embedded object with no preview

Now using the Update all menu item turns a sample document into this preview:

https://share.vmiklos.hu/blog/sw-ole-update/new.png
Figure 2. Writer embedded object with a preview

How is this implemented?

If you would like to know a bit more about how this works, continue reading… :-)

sw: update previews of OLE objects on "update all" is the change implementing this small feature. It works by:

  • Iterating over the frame formats ("special" formats) of the document

  • Filter out shapes

  • Filter out objects which are only reachable from the undo stack

  • Filter out objects which are not embedded ("OLE") objects

  • Once we have access to the OLE node, jump to its SwOLEObj, then to its svt::EmbeddedObjectRef, which knows how to re-calculate the preview bitmap

  • Finally notify the OLE node that the preview was updated, so the necessary repaint can happen

Want to start using this?

Collabora intends to continue supporting and contributing to LibreOffice, the code is merged so we expect all of this work will be available in TDF’s next release (7.4).

© Miklos Vajna. Built using Pelican. Theme by Giulio Fidente on github.