Hello Svante,
my original problem was not inserting the image (that's been easy), but
setting the property - the image should not "explode" the table cell.
My first appoach was creating a new StyleGraphicPropertiesElement
instance - similar to some tutorial I've found about inserting tab stops.
After I saw, it didn't work, I noticed there had already been such an
element in the style, which would have to be changed. I could achieve
editing the properties using ODFDOM, but not using Simple API. I've also
looked into the sources, but the API has not been extended, yet.
Kind regards
Peter
Am 11.01.2017 um 10:58 schrieb Svante Schubert:
Hello Peter,
What was the original problem you like to solve?
You started with inserting an image within the the paragraph of a cell.
It works for me, I added an automated test for it, which is yet not testing
just inserting the images, but it works. :)
NOTE: I usually do not work on releases and I recommend to work on the
latest sources, as I aim to use automated tests for all my fixes, I can be
quite certain that the sources are better than the previous releases.
As mentioned on http://incubator.apache.org/odftoolkit/source.html
you may get the sources from by the following SVN comand:
svn co https://svn.apache.org/repos/asf/incubator/odf/trunk
odftoolkit20170111
NOTE: The best way to find a solution for a problem is to take a look into
existing regression tests of the project you are focused on.
As you are working on the simple API level you may find regression tests
here:
odftoolkit20170111/simple/src/test/java/org/odftoolkit/simple
I combined two tests from the Simple API:
One for the cell within a text table from
odftoolkit20170111/simple/src/test/java/org/odftoolkit/simple/table/TableCellTest.java
and one for the image:
odftoolkit20170111/simple/src/test/java/org/odftoolkit/simple/common/navigation/ImageSelectionTest.java
And appened the following test to one of those test files:
@Test
public void testGraphicStyle() {
try {
Table table1 = odtdoc.getTableByName("Table1");
Cell fcell2 = table1.getCellByPosition(0, 1);
String text = fcell2.getDisplayText();
Assert.assertEquals("Aa\nbb\ncc\ndd\nee", text);
// Caution there are two cells with the same content in the
document..
Paragraph para = fcell2.getParagraphByIndex(0, true);
Image image = null;
image = Image.newImage(para,
ResourceUtilities.getURI("testA.jpg"));
image.setName("this image 1");
image.setHyperlink(new URI("http://odftoolkit.org"));
// As I have overseen the image within the first table, I added
a new paragraph (not in a table) to the end of the document and inserted
the image there
Paragraph para2 = odtdoc.addParagraph("MyImage");
Image image2 = null;
image2 = Image.newImage(para2,
ResourceUtilities.getURI("testA.jpg"));
image2.setName("this image 2");
image2.setHyperlink(new URI("http://odftoolkit.org"));
odtdoc.save(ResourceUtilities.newTestOutputFile("_newImageInParaCell.odt"));
} catch (Exception ex) {
Logger.getLogger(TableCellTest.class.getName()).log(Level.SEVERE, null, ex);
}
}
By executing the test in an IDE with mouse context, you may run your new
test solely to be able to debug some lines of interests.
Finally, for reviewing the test resuslt, you may find the new created
output document I called '_newImageInParaCell.odt' at
odftoolkit20170111/simple/target/test-classes
And to easily view into the zipped ODF document, I am using JEdit with the
Archive extension and to indent the XML document the XML extension (that I
aligned to a key short cut) making life much easier :)
NOTE: that the Simple API was donated once by IBM, but when IBM withdrawn
from Apache OpenOffice it withdraw from this project as well. I would need
to debug myself, perhaps you can give it a try.
Going to be on a train ride Thursday evening, if there are any question I
may answer them at that time.
Good luck! :)
Svante
2017-01-10 23:04 GMT+01:00 Peter Nabbefeld <[email protected]>:
Hello,
I've found out now, that I'm duplicating the StyleGraphicPropertiesElement.
Using
GraphicProperties writableGraphicsProperties =
styleHandler.getGraphicPropertiesForWrite();
I can get access to some very basic attributes, but the
StyleGraphicPropertiesElement is not accessible.
How can I get it, so I don't have to create my own?
Kind regards
Peter
Am 10.01.2017 um 13:41 schrieb Peter Nabbefeld:
Hello all,
I'm new to this list, I've joined the list because I've seen the
following misbehaviour related to images:
In my document I add an image to a paragraph contained to a table cell:
Image image = Image.newImage(para, new URI(imgParams.get("uri")));
FrameStyleHandler styleHandler = image.getStyleHandler();
OdfContentDom styles = para.getOwnerDocument().getContentDom();
StyleGraphicPropertiesElement gProperties = new
StyleGraphicPropertiesElement(styles);
[...]
gProperties.setStyleFlowWithTextAttribute(false);
writableStyleProperties.appendChild(gProperties);
Though the property is set to "false", the resulting content includes the
property as "true". I'm even more uncomfortable with this, as LibreOffice
does not behave correctly after unsetting this property manually, but only
after reloading. As I'm new to the toolkit, it's also possible that I've
misconfigured sth. - If so, do You probably know what?
Another problem I've noticed: When creating the odt file
programmatically, I can open the properties dialog only for some "card
tabs", but not for the image details alltogether. Do I have to do some
special configuration?
Kind regards
Peter
ᐧ