jferard / fastods

A very fast and lightweight (no dependency) library for creating ODS (Open Document Spreadsheet, mainly for Calc) files in Java. It's a Martin Schulz's SimpleODS fork
GNU General Public License v3.0
36 stars 6 forks source link

Feature suggestion: support for comments with background bitmaps #169

Closed GregorySokoloff closed 4 years ago

GregorySokoloff commented 4 years ago

The only way I know to insert an image in a document is to create a comment for a cell and then add a background image to the comment. I'm not an expert and will be happy to hear of other alternatives.

jferard commented 4 years ago

Don't know if this answers your question, but in LO, you can use: Insert > Image and select your image instead of creating a comment with a background.

In FastODS, that is possible to implement. An image can already be added to the archive as in: https://github.com/jferard/fastods/blob/master/fastods-examples/src/main/java/com/github/jferard/fastods/examples, but we need to add some tags to FastODS.

Regular image

First, we need a new style of family graphic, and a style:graphic-properties tag representation, to describe the container. Example:

<style:style style:name="gr1" style:family="graphic"><style:graphic-properties
            draw:stroke="none"
            draw:fill="none"
            draw:textarea-horizontal-align="center"
            draw:textarea-vertical-align="middle"
            draw:color-mode="standard"
            draw:luminance="0%"
            draw:contrast="0%"
            draw:gamma="100%"
            draw:red="0%"
            draw:green="0%"
            draw:blue="0%"
            fo:clip="rect(0mm, 0mm, 0mm, 0mm)"
            draw:image-opacity="100%"
            style:mirror="none"/></style:style>

Second, we need a table:shapes tag for the image itself:

<table:shapes>
              <draw:frame draw:z-index="2" draw:name="Image 1" draw:style-name="gr1" draw:text-style-name="P1" svg:width="246.42mm" svg:height="98mm" svg:x="45.15mm" svg:y="70.67mm">
        <draw:image xlink:href="Pictures/y.png" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"><text:p/></draw:image>
        </draw:frame>
        </table:shapes>

Comment background

We need also a draw:fill-image tag in styles.xml > office:styles (reference given by the attribute draw:fill-image-name): <draw:fill-image draw:name="DN" xlink:href="Pictures/x.png" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>

jferard commented 4 years ago

The table:shapes tag would help for #159.

jferard commented 4 years ago

Inserting an image: see https://github.com/jferard/fastods/blob/master/fastods-examples/src/main/java/com/github/jferard/fastods/examples/I_Misc.java#L300.

jferard commented 4 years ago

More on comment background:

<office:annotation draw:style-name="gr1" ...>

<office:automatic-styles><style:style style:name="gr1" style:family="graphic"><style:graphic-properties draw:fill-image-name="DSCF2917" .../></style:style>

<office:styles>...<draw:fill-image draw:name="DSCF2917" xlink:href="Pictures/.....jpg" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/></office:styles>
GregorySokoloff commented 4 years ago

@jferard Hi Julien, I'm back finally to try embedding an image (but not a background image to a tooltip!). A few thoughts:

  1. The Tutorial says, "First, we'll see how to embed a file into the ods archive, then we'll discover the available FastODS functions to hook this file to the document." However, I don't believe there is any explanation of how to hook an image file to a cell in the document. You might want to edit this to avoid any confusion or disappointment for your readers.
  2. The comment of Oct 11 has a dead link.
  3. You have some good info in this discussion of what is needed to embed the image. Is that something that you might do, or a polite suggestion for help?
  4. Is there some way to experiment with your library without having to modify the library and rebuild it from source? For example, is there any way to provide an external implementation of a TableCell that could be inserted in a table?
  5. I feel a little embarrassed that you might have implemented a feature at my request, and here I am asking for something different! If so, I ask for forgiveness (not justice). Cheers, Gregory
jferard commented 4 years ago

Hi @GregorySokoloff. Short answer, the long one will come soon:

jferard commented 4 years ago

(Not so) long answer:

1,2,3. I hope the short answer is enough.

  1. This is a wonderful idea. There's already a TableCell interface, but you can't insert an instance in the table. I will think about it, and look if there is no impediment.
  2. A written, no problem: it's always interesting to have some good feedback.
jferard commented 4 years ago

Opened #181 for 4.