Skip to content

Commit

Permalink
Added image fit support for ODT
Browse files Browse the repository at this point in the history
  • Loading branch information
VladFlorinIlie committed Aug 26, 2022
1 parent e08856f commit ec6022f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,24 +195,44 @@ else if ( isDrawFrame( uri, localName, name ) )
//
String newWith = null;
String newHeight = null;
String defaultWidth = null;
String defaultHeight = null;
int widthIndex = attributes.getIndex( SVG_NS, WIDTH_ATTR );
if ( widthIndex != -1 )
{
String defaultWidth = attributes.getValue( widthIndex );
defaultWidth = attributes.getValue( widthIndex );
}
int heightIndex = attributes.getIndex( SVG_NS, HEIGHT_ATTR );
if ( heightIndex != -1 )
{
defaultHeight = attributes.getValue( heightIndex );
}

// get the parameters for the get width and height methods
String[] parameters = null;
if (defaultWidth != null && defaultHeight != null) {
parameters = new String[]{IImageRegistry.IMAGE_INFO, "'" + defaultWidth + "'", "'" + defaultHeight + "'"};
} else if (defaultWidth != null) {
parameters = new String[]{IImageRegistry.IMAGE_INFO, "'" + defaultWidth + "'"};
} else if (defaultHeight != null) {
parameters = new String[]{IImageRegistry.IMAGE_INFO, "'" + defaultHeight + "'"};
}

if ( defaultWidth != null )
{
newWith =
formatter.getFunctionDirective( TemplateContextHelper.IMAGE_REGISTRY_KEY,
IImageRegistry.GET_WIDTH_METHOD,
IImageRegistry.IMAGE_INFO, "'" + defaultWidth + "'" );
parameters );
}
int heightIndex = attributes.getIndex( SVG_NS, HEIGHT_ATTR );
if ( heightIndex != -1 )
if ( defaultHeight != null )
{
String defaultHeight = attributes.getValue( heightIndex );
newHeight =
formatter.getFunctionDirective( TemplateContextHelper.IMAGE_REGISTRY_KEY,
IImageRegistry.GET_HEIGHT_METHOD,
IImageRegistry.IMAGE_INFO, "'" + defaultHeight + "'" );
parameters );
}

if ( newWith != null || newHeight != null )
{
AttributesImpl attr = toAttributesImpl( attributes );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ public void testImageWithSimpleField()

+ "<draw:frame draw:style-name=\"fr1\" draw:name=\"logo\" text:anchor-type=\"paragraph\" svg:x=\"69.96pt\" svg:y=\"18.31pt\" "
// + "svg:width=\"21pt\" "
+ "svg:width=\"${___ImageRegistry.getWidth(___imageInfo,'21pt')}\" "
+ "svg:width=\"${___ImageRegistry.getWidth(___imageInfo,'21pt','22.51pt')}\" "
// + "svg:height=\"22.51pt\" "
+ "svg:height=\"${___ImageRegistry.getHeight(___imageInfo,'22.51pt')}\" " + "draw:z-index=\"0\">"
+ "svg:height=\"${___ImageRegistry.getHeight(___imageInfo,'21pt','22.51pt')}\" " + "draw:z-index=\"0\">"
+ "<draw:image "

+ "xlink:href=\"${___ImageRegistry.getPath(___imageInfo,'Pictures/100000000000001C0000001EE8812A78.png')}\" "
Expand Down Expand Up @@ -246,9 +246,9 @@ public void testImageWithListFieldInTable()

+ "<draw:frame draw:style-name=\"fr1\" draw:name=\"developers.Photo\" text:anchor-type=\"paragraph\" "
// + "svg:width=\"21pt\" "
+ "svg:width=\"${___ImageRegistry.getWidth(___imageInfo,'21pt')}\" "
+ "svg:width=\"${___ImageRegistry.getWidth(___imageInfo,'21pt','22.51pt')}\" "
// + "svg:height=\"22.51pt\" "
+ "svg:height=\"${___ImageRegistry.getHeight(___imageInfo,'22.51pt')}\" " + "draw:z-index=\"0\">"
+ "svg:height=\"${___ImageRegistry.getHeight(___imageInfo,'21pt','22.51pt')}\" " + "draw:z-index=\"0\">"
+ "<draw:image "

+ "xlink:href=\"${___ImageRegistry.getPath(___imageInfo,'Pictures/100000000000001C0000001EE8812A78.png')}\" "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ public void testImageWithSimpleField()

+ "<draw:frame draw:style-name=\"fr1\" draw:name=\"logo\" text:anchor-type=\"paragraph\" svg:x=\"69.96pt\" svg:y=\"18.31pt\" "
// + "svg:width=\"21pt\" "
+ "svg:width=\"${___ImageRegistry.getWidth($___imageInfo,'21pt')}\" "
+ "svg:width=\"${___ImageRegistry.getWidth($___imageInfo,'21pt','22.51pt')}\" "
// + "svg:height=\"22.51pt\" "
+ "svg:height=\"${___ImageRegistry.getHeight($___imageInfo,'22.51pt')}\" " + "draw:z-index=\"0\">"
+ "svg:height=\"${___ImageRegistry.getHeight($___imageInfo,'21pt','22.51pt')}\" " + "draw:z-index=\"0\">"
+ "<draw:image "

+ "xlink:href=\"${___ImageRegistry.getPath($___imageInfo,'Pictures/100000000000001C0000001EE8812A78.png')}\" "
Expand Down Expand Up @@ -246,9 +246,9 @@ public void testImageWithListFieldInTable()

+ "<draw:frame draw:style-name=\"fr1\" draw:name=\"developers.Photo\" text:anchor-type=\"paragraph\" "
// + "svg:width=\"21pt\" "
+ "svg:width=\"${___ImageRegistry.getWidth($___imageInfo,'21pt')}\" "
+ "svg:width=\"${___ImageRegistry.getWidth($___imageInfo,'21pt','22.51pt')}\" "
// + "svg:height=\"22.51pt\" "
+ "svg:height=\"${___ImageRegistry.getHeight($___imageInfo,'22.51pt')}\" " + "draw:z-index=\"0\">"
+ "svg:height=\"${___ImageRegistry.getHeight($___imageInfo,'21pt','22.51pt')}\" " + "draw:z-index=\"0\">"
+ "<draw:image "

+ "xlink:href=\"${___ImageRegistry.getPath($___imageInfo,'Pictures/100000000000001C0000001EE8812A78.png')}\" "
Expand Down

0 comments on commit ec6022f

Please sign in to comment.