Date: prev next · Thread: first prev next last
2019 Archives by date, by thread · List index


Hello everybody, 
        I thank you for your answers. Yes I want to add an image with a caption programmatically 
and I want a caption like this "Illustration 1 : My caption"
To my mind, it would be better/cleaner if I was able to generate the same thing than I do the UI. 
Thanks to you, I succeed to build the expected structure for the image and to set a text below it, 
but I still have some problems, mainly with the GetReference.

The GetReference generates :
<text:reference-ref text:reference-format="text" text:ref-name="refIllustration0">Erreur : source 
de la référence non trouvée</text:reference-ref>  (sorry my Libo is in French, it is written "Sorry 
: source of the reference not found").

And I would like to get a text:sequence instead of a text:reference, to get this result:
<text:sequence text:ref-name="refIllustration0" text:name="Illustration" 
text:formula="ooow:Illustration+1" style:num-format="1">1</text:sequence>

Please, do you know how I can build a text:sequence  ?
 
Please found in attachment the java code I wrote [1], the expect xml structure [2] and the current 
xml structure [3].
I know I have some difference between [2] and [3] with the width/height properties and inside the 
draw frame, but it is not the subject of this thread. 

[1] insertImage.java
[2] expectedResult.xml
[3] currentResult.xml

In addition, I have more generic question, do you know if it exists a documentation, indicating 
mapping, between the xml elements and how to get/create them from java ? For example, in xml 
svg:width is called Height in the java API, and my Textframe becomes <draw:text-box...<

Best regards, 
--
Vincent Lorenzo









-----Message d'origine-----
De : Kaganski Mike [mailto:mikekaganski@hotmail.com] 
Envoyé : mercredi 13 février 2019 11:42
À : Miklos Vajna <vmiklos@collabora.com>; LORENZO Vincent <vincent.lorenzo@cea.fr>
Cc : libreoffice@lists.freedesktop.org
Objet : Re: need help to insert an image with a caption with the Libo java API

On 13.02.2019 12:45, Miklos Vajna via LibreOffice wrote:
Hi,

On Tue, Feb 12, 2019 at 09:27:15AM +0000, LORENZO Vincent <vincent.lorenzo@cea.fr> wrote:
I would like to add a caption, to an inserted image in a text 
document, but I don't find how to do that... Please do you have 
pointer/documentation for me ?

I think captions are just a UI feature. The doc model just stores a 
text frame around the image and the image is followed by the caption itself.

(I.e. later it's not possible to reliably detect if some content 
around an image in a frame was created by hand or using the captions 
UI code.)

So you can do the same "manually" using the UNO API. When in doubt, 
see what UNO API the ODT import uses to create the doc model based on 
the input markup.

And actually, if an image is not intended to be floating, but (as seen in majority of cases) is a 
part of normal text flow, then the frame could be not needed at all - simply add an image anchored 
as character, then add a paragraph with required style and numbering range field, then continue 
with other paragraphs. This makes the document structure clearer. Just an advise based on own 
experience.

--
Best regards,
Mike Kaganski

Attachment: InsertImage.java
Description: InsertImage.java

<draw:frame draw:style-name="fr1" draw:name="Cadre1"
        text:anchor-type="as-char" svg:width="16.431cm" draw:z-index="1">
        <draw:text-box fo:min-height="0cm">
                <text:p text:style-name="Illustration">
                        <draw:frame draw:style-name="fr2" draw:name="Image1"
                                text:anchor-type="as-char" svg:width="16.431cm"
                                svg:height="14.843cm" draw:z-index="0">
                                <draw:image
                                        
xlink:href="Pictures/100029BE0000402F000039FBD1046F0E9597691C.svg"
                                        xlink:type="simple" xlink:show="embed" 
xlink:actuate="onLoad"
                                        loext:mime-type="image/svg+xml" />
                                <draw:image
                                        
xlink:href="Pictures/100002010000026D00000231B948D997B1182A15.png"
                                        xlink:type="simple" xlink:show="embed" 
xlink:actuate="onLoad" />
                        </draw:frame>
                        Illustration
                        <text:line-break />
                        <text:reference-ref text:reference-format="text"
                                text:ref-name="refIllustration0">Erreur : source de la
                                référence non trouvée</text:reference-ref>
                        a nice Figure
                </text:p>
        </draw:text-box>
</draw:frame>
<draw:frame draw:style-name="fr1" draw:name="Cadre1"
        text:anchor-type="char" svg:width="16.432cm" draw:z-index="0">
        <draw:text-box fo:min-height="14.841cm">
                <text:p text:style-name="Illustration">
                        <draw:frame draw:style-name="fr2" draw:name="Image1"
                                text:anchor-type="as-char" svg:width="16.432cm"
                                style:rel-width="100%" svg:height="14.841cm"
                                style:rel-height="scale" draw:z-index="1">
                                <draw:image
                                        
xlink:href="Pictures/100002010000026D000002310710B29486C9E685.png"
                                        xlink:type="simple" xlink:show="embed" 
xlink:actuate="onLoad"
                                        loext:mime-type="image/png" />
                        </draw:frame>
                        <text:span text:style-name="T1">
                                <text:line-break />
                        </text:span>
                        Illustration
                        <text:sequence text:ref-name="refIllustration0"
                                text:name="Illustration" text:formula="ooow:Illustration+1"
                                style:num-format="1">1</text:sequence>
                        : My caption
                </text:p>
        </draw:text-box>
</draw:frame>

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.