Bug 32485 - Settings on the image frame style lost when caption is applied
Summary: Settings on the image frame style lost when caption is applied
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords: needsDevAdvice
: 73385 (view as bug list)
Depends on:
Blocks: Anchor-and-Text-Wrap Writer-Styles-Frame
  Show dependency treegraph
 
Reported: 2010-12-17 16:44 UTC by RGB
Modified: 2024-02-04 13:13 UTC (History)
7 users (show)

See Also:
Crash report or crash signature:


Attachments
Files (ODT/PDF/JPEG) for 4-step process outlining captioning. (294.56 KB, application/zip)
2013-05-24 05:48 UTC, Owen Genat (retired)
Details

Note You need to log in before you can comment on or make changes to this bug.
Description RGB 2010-12-17 16:44:57 UTC
When applying a caption, frame styles are not honoured.

Steps to reproduce the issue:
In a new Writer document, edit the "Graphics" frame style in order to add space
below any inserted image.
Insert two dummy paragraphs and between them insert an image. When the image is inserted, the spacing works as expected.
Now, right click over the image and select "caption". Type any text and press
enter.

Expected behavior: 
The space set in the Graphics frame style keep a distance between the image and the caption.

Result: 
The space below the image is "transferred" to the new external frame and
no space is left between the image and the caption. Below the external frame a
space NOT set by the user is inserted while the configured space below the image
get lost.

Notice: By re-applying the Graphics frame style to the image only, the space is
recreated.
Everything behave as if direct formatting were applied to both, Graphics and
"external" frame style reverting the spacing settings introduced by the user. In
fact, the frame that contains both image and caption is a "variation" of he
"Frame" frame style, but with "direct formatting" applied on it: There is no way
to control the default properties for that frame.
This behavior goes against the whole idea of frame styles.
Comment 1 Björn Michaelsen 2011-12-23 11:33:44 UTC Comment hidden (obsolete)
Comment 2 RGB 2011-12-23 16:43:21 UTC
The problem is present on 3.5 beta2.
Comment 3 Owen Genat (retired) 2013-05-24 05:48:42 UTC
Created attachment 79733 [details]
Files (ODT/PDF/JPEG) for 4-step process outlining captioning.

I am attaching a series of working examples and providing some further detail in order to better illustrate the point being made by the OP. This problem still occurs under v4.0.3.3 (Build ID: 0eaa50a932c8f2199a615e1eb30f7ac74279539). In summary, as indicated by the OP, the visual display of elements (after captioning) does not indicate the underlying XML frame style definitions. Hopefully the detail here is helpful.

My attached example includes several files, which are relatively self-explanatory by their names. They indicate a 4-step process of:
1_ Two text paragraphs and the "Graphics" and "Frame" styles formatted as required (both with No Wrap, 18pt above/below for Graphics, 0pt above/below for Frame, both with width 100%, height Auto, and position Left/Top).
2_ A single graphic inserted between the two paragraphs (JPEG is included separately).
3_ The single graphic captioned via right-click > Caption... method i.e., graphic is enclosed in a text box.
4_ "Graphics" frame style is re-applied to graphic in text box.
There is a PDF of each ODT for clarity.

The following is an overview of the XML during critical stages of this process. 

Step 2 - Uncaptioned graphic
When a graphic is inserted it is placed in a <draw:frame> element and given a corresponding <style:style> element (in content.xml), which in turn links to a <style:style> and <style:graphic-properties> element pair for the "Graphics" frame style (in styles.xml) where the fo:margin-top and fo:margin-bottom attributes are set. For example in the attached file 2_inserted_graphic.odt the XML appears thus:

content.xml:
<style:style style:name="fr1" style:family="graphic" style:parent-style-name="Graphics">
	<style:graphic-properties style:vertical-pos="top" style:vertical-rel="paragraph-content" style:mirror="none" fo:clip="rect(0pt, 0pt, 0pt, 0pt)" draw:luminance="0%" draw:contrast="0%" draw:red="0%" draw:green="0%" draw:blue="0%" draw:gamma="100%" draw:color-inversion="false" draw:image-opacity="100%" draw:color-mode="standard"/>
</style:style>

<draw:frame draw:style-name="fr1" draw:name="graphics1" text:anchor-type="paragraph" svg:width="299.99pt" svg:height="150.01pt" draw:z-index="0">
	<draw:image xlink:href="Pictures/1000000000000190000000C86E44B4CA.jpg" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
</draw:frame>

styles.xml:
<style:style style:name="Graphics" style:family="graphic">
	<style:graphic-properties svg:width="481.89pt" style:rel-width="100%" fo:min-height="1.16pt" text:anchor-type="paragraph" svg:x="0pt" svg:y="0pt" fo:margin-top="18pt" fo:margin-bottom="18pt" style:wrap="none" style:vertical-pos="top" style:vertical-rel="paragraph-content" style:horizontal-pos="left" style:horizontal-rel="paragraph"/>
</style:style>

Note the initial definition for above / below margins surrounding the graphic are handled via the "Graphics" frame style in styles.xml. This is expected and matches that in 1_text_only_edited_frame_styles.odt.

Step 3 - Captioned graphic
When a graphic is given a caption via the right-click > Caption... method an additional text box is added around the existing frame. The original <draw:frame> element is enclosed in a subsequent <draw:frame> and <draw:text-box> element pair, with the text-box linking to the "Frame" frame style in styles.xml. For example in the attached file 3_inserted_graphic_with_caption.odt the XML appears thus:

content.xml:
<style:style style:name="fr1" style:family="graphic" style:parent-style-name="Frame">
	<style:graphic-properties fo:margin-top="18pt" fo:margin-bottom="18pt" style:vertical-pos="top" style:vertical-rel="paragraph-content" style:horizontal-pos="left" style:horizontal-rel="paragraph" fo:padding="0pt" fo:border="none"/>
</style:style>
<style:style style:name="fr2" style:family="graphic" style:parent-style-name="Graphics">
	<style:graphic-properties fo:margin-left="0pt" fo:margin-right="0pt" fo:margin-top="0pt" fo:margin-bottom="0pt" style:run-through="foreground" style:wrap="none" style:vertical-pos="from-top" style:vertical-rel="paragraph-content" style:horizontal-pos="from-left" style:horizontal-rel="paragraph-content" fo:padding="0pt" fo:border="none" style:shadow="none" style:mirror="none" fo:clip="rect(0pt, 0pt, 0pt, 0pt)" draw:luminance="0%" draw:contrast="0%" draw:red="0%" draw:green="0%" draw:blue="0%" draw:gamma="100%" draw:color-inversion="false" draw:image-opacity="100%" draw:color-mode="standard"/>
</style:style>

<draw:frame draw:style-name="fr1" draw:name="Frame1" text:anchor-type="paragraph" svg:width="299.99pt" draw:z-index="0">
	<draw:text-box fo:min-height="150.01pt">
		<text:p text:style-name="Figure">
			<draw:frame draw:style-name="fr2" draw:name="graphics1" text:anchor-type="paragraph" svg:x="0.11pt" svg:y="0.06pt" svg:width="299.99pt" style:rel-width="100%" svg:height="150.01pt" style:rel-height="scale" draw:z-index="1">
				<draw:image xlink:href="Pictures/1000000000000190000000C86E44B4CA.jpg" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
			</draw:frame>Figure 
			<text:sequence text:ref-name="refFigure0" text:name="Figure" text:formula="ooow:Figure+1" style:num-format="1">1</text:sequence>. Bar scene.
		</text:p>
	</draw:text-box>
</draw:frame>

style.xml:
<style:style style:name="Graphics" style:family="graphic">
	<style:graphic-properties svg:width="481.89pt" style:rel-width="100%" fo:min-height="1.16pt" text:anchor-type="paragraph" svg:x="0pt" svg:y="0pt" fo:margin-top="18pt" fo:margin-bottom="18pt" style:wrap="none" style:vertical-pos="top" style:vertical-rel="paragraph-content" style:horizontal-pos="left" style:horizontal-rel="paragraph"/>
</style:style>
<style:style style:name="Frame" style:family="graphic">
	<style:graphic-properties svg:width="481.89pt" style:rel-width="100%" fo:min-height="9.75pt" text:anchor-type="paragraph" svg:x="0pt" svg:y="0pt" fo:margin-left="0pt" fo:margin-right="0pt" fo:margin-top="0pt" fo:margin-bottom="0pt" style:wrap="none" style:vertical-pos="top" style:vertical-rel="paragraph-content" style:horizontal-pos="left" style:horizontal-rel="paragraph-content" fo:padding="4.25pt" fo:border="0.06pt solid #000000"/>
</style:style>

As can been seen the inner graphics frame (style name "fr1" originally) has become "fr2" and the associated "Graphics" frame style in styles.xml has maintained the fo:margin-top and fo:margin-bottom settings ("18pt" in the example) as expected. Similarly the "Frame" frame style in styles.xml has maintained its fo:margin-top and fo:margin-bottom settings ("0pt" in the example). However the style:graphic-properties element for the "Frame" frame style in content.xml now also has fo:margin-top and fo:margin-bottom set to "18pt". As the OP mentions the spacing appears "transferred" from the graphic to the enclosing text box.

Step 4 - Re-applied "Graphics" frame style
Re-applying the "Graphics" frame style to the enclosed graphic brings back the space between the graphic and surrounding frame. The differences in content.xml and style.xml between 3_inserted_graphic_with_caption.odt and 4_inserted_graphic_with_caption_with_reapplied_style.odt are:

content.xml:
The <style:graphic-properties> element for the "fr2" (graphic) frame removes these attributes in step 4:
fo:margin-left="0pt" fo:margin-right="0pt" fo:margin-top="0pt" fo:margin-bottom="0pt" style:run-through="foreground" style:wrap="none" style:horizontal-pos="from-left" style:horizontal-rel="paragraph-content" fo:padding="0pt" fo:border="none" style:shadow="none" 

The same element also has a change in attribute from style:vertical-pos="from-top" to style:vertical-pos="top".

The <draw:frame> element for the "fr2" (graphic) frame includes these additional attributes in step 4:
svg:x="0.11pt" svg:y="0.06pt"

styles.xml:
A new style is included: <style:style style:name="Frame_20_contents" style:display-name="Frame contents" style:family="paragraph" style:parent-style-name="Text_20_body" style:class="extra"/>
Comment 4 QA Administrators 2014-10-23 17:31:45 UTC Comment hidden (obsolete)
Comment 5 Owen Genat (retired) 2015-03-14 13:11:23 UTC
Tested under GNU/Linux using 4.2.8.2, 4.3.5.2, and 4.4.1.2. All versions exhibit the problem.
Comment 6 tommy27 2016-04-16 07:26:04 UTC Comment hidden (obsolete)
Comment 7 RGB 2016-04-16 09:59:02 UTC
Still a problem on v5.1.2.2 on Linux 64bits (openSUSE 13.2)
Comment 8 Cor Nouws 2016-09-28 08:06:23 UTC
*** Bug 73385 has been marked as a duplicate of this bug. ***
Comment 9 Xisco Faulí 2017-09-29 08:48:26 UTC Comment hidden (obsolete)
Comment 10 RGB 2017-09-29 10:26:22 UTC
Still a problem on Version 5.4.1.2
Comment 11 QA Administrators 2018-09-30 02:48:00 UTC Comment hidden (obsolete)
Comment 12 RGB 2018-09-30 08:06:25 UTC
Problem still present in 6.1.2.1
Comment 13 QA Administrators 2019-10-01 03:02:58 UTC Comment hidden (obsolete)
Comment 14 RGB 2019-10-01 09:35:29 UTC
Problem still present in LibreOffice 6.3.2
Comment 15 QA Administrators 2021-10-01 03:51:16 UTC Comment hidden (obsolete)
Comment 16 RGB 2021-10-01 18:26:54 UTC
Problem still present in LibreOffice 7.2.1.2.
Comment 17 Heiko Tietze 2022-11-30 05:35:28 UTC
*** Bug 152302 has been marked as a duplicate of this bug. ***
Comment 18 Stéphane Guillou (stragu) 2022-11-30 21:09:11 UTC
In my humble opinion, it makes sense to "transfer" that spacing from the image frame to the caption frame.

If users change the spacing around an image before captioning it (per image, or using the Graphics style so it affects many images at once), they most likely want to keep that same spacing around the frame once the image is captioned, without needing to go through the whole process again. If it weren't transferred, they would end up with a caption that's closer to the surrounding text when I suspect most would want the caption to be closer to the picture.

However, it is difficult to then change spacing around all graphics at once: editing the style to add extra spacing under all graphics would also affect the captioned graphics.

My suggestion would be to:

- keep the transfer of properties as is (from graphics properties to surrounding frame properties); however:
- add a "Captioned graphic" style that is automatically applied to a captioned graphic, and
- add a "Caption frame" style that is automatically applied to the surrounding frame.

That way, it would be easy to handle these elements' styling separately, for example changing a property for all captioned graphics but not other graphics, or for all caption frames but not other frames.
Of course, one would be able to set inheritance between those if they want them to be consistent. For example, making "Caption frame" inherit properties from "Graphics" so the spacing for the whole document can be set all at once.

Thoughts? Maybe that feels even more heretic: automatically changing the style of the object. And I am focusing on spacing around an image, but it might not make sense for all properties (e.g. a custom frame border. Does one want to keep it surrounding only the image? Or the caption as well?)
Comment 19 Eyal Rozenberg 2022-12-07 20:47:37 UTC
Let me first address the caption issue, then the more general one which is more complicated.

(In reply to Stéphane Guillou (stragu) from comment #18)
> In my humble opinion, it makes sense to "transfer" that spacing from the
> image frame to the caption frame.

I would say that both options _partly_ make sense. That's because with a caption, you have two lengths of space: From the image to the caption and from the image+caption, or from the image, to the outside flow of content. With no caption, these coincide or alias each other - so different users will make different choices between the two. 

> My suggestion would be to:
> 
> - keep the transfer of properties as is (from graphics properties to
> surrounding frame properties); however:
> - add a "Captioned graphic" style that is automatically applied to a
> captioned graphic, and
> - add a "Caption frame" style that is automatically applied to the
> surrounding frame.

I'm not sure I agree - because all sorts of frames can have captions. Do you want to triplicate all frame styles accordingly? What about styles the user has created? e.g. "Fancy Graphic" and "Subdued Graphic" or whatever?

The larger issue is how transformations of frames are affected by styles of the original frames; and whether a family of related frames (e.g. outer frame, inner frame for captioned content, inner frame for caption) should have a style as a triplet, or a triplet of styles; and whether such styles need to be strongly linked; etc.
Comment 20 Heiko Tietze 2022-12-08 08:50:33 UTC
We discussed the topic in the design meeting. There are a lot of related issues.

Inserted graphic receives a Graphic frame style (FS) with anchor To Paragraph but is anchored To Character (as defined in Tools > Options > Writer > Formatting Aids).
The same is true on adding a caption with a Frame FS - it is defined as To Paragraph but is direct formatted as To Character.

The actual problem here is the distance below the graphic. If set to some value it's kept if the caption is added - and while the distance between graphic and text was desired it's now to the caption, which in turn needs some distance to the text.

Plus, the default is zero distance, which is not appealing.

Solutions:
* Frame styles should follow the definition.
* We should not apply direct formatting. => needsDevAdvice
* The default below a "Graphic" (and Frame) is better something like 0.2cm.
Comment 21 sdc.blanco 2023-02-07 13:43:09 UTC
(In reply to Heiko Tietze from comment #20)
> Solutions:
or when adding a caption, do not add a frame with images (and charts) as suggested in bug 115318?
Comment 22 Heiko Tietze 2023-02-08 11:30:10 UTC
Don't think bug 115318 is going to fly. Commented there (essentially that floating objects need a frame).