Skip to content

Commit

Permalink
Fixed #473 Add an option to prevent zooming in with the fit() service.
Browse files Browse the repository at this point in the history
  • Loading branch information
ylussaud committed Sep 19, 2023
1 parent e04cae0 commit 46fec3e
Show file tree
Hide file tree
Showing 29 changed files with 92 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016 Obeo.
* Copyright (c) 2016, 2023 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -199,7 +199,7 @@ public MImage setConserveRatio(MImage image, Boolean conserve) {

// @formatter:off
@Documentation(
value = "Fits the Image in the given rectangle width and height.",
value = "Fits the Image in the given rectangle width and height. same as myImage.fit(width, height, true)",
params = {
@Param(name = "image", value = "The Image"),
@Param(name = "width", value = "The width to fit"),
Expand All @@ -217,6 +217,44 @@ public MImage fit(MImage image, Integer width, Integer height) {
image.setHeight(height);
}

return fit(image, width, height, true);
}

// @formatter:off
@Documentation(
value = "Fits the Image in the given rectangle width and height.",
params = {
@Param(name = "image", value = "The Image"),
@Param(name = "width", value = "The width to fit"),
@Param(name = "height", value = "The height to fit"),
@Param(name = "zoomIn", value = "The image will be zoomed in if smaller"),
},
result = "the image with new dimensions",
examples = {
@Example(expression = "myImage.fit(200, 300, false)", result = "will fit the image in a rectangle (width=200, height=300) if the original image size is smaller it will not be zoomed in"),
}
)
// @formatter:on
public MImage fit(MImage image, Integer width, Integer height, boolean zoomIn) {
if (zoomIn) {
image.setWidth(width);
if (!image.conserveRatio() || image.getHeight() > height) {
image.setHeight(height);
}
} else {
if (image.getWidth() > width) {
image.setWidth(width);
if (image.getHeight() > height) {
image.setHeight(height);
}
} else if (image.getHeight() > height) {
image.setHeight(height);
if (image.getWidth() > width) {
image.setWidth(width);
}
}
}

return image;
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

=== HEADER ===

=== BODY ===

Checks ImageServices registration :
[query: .fit(.asImage('Mona_Lisa.jpg'), 300, 400, false)]
End of demonstration.
=== FOOTER ===

=== TEMPLATES ===
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="ASCII"?>
<genconf:Generation xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:genconf="http://www.obeonetwork.org/m2doc/genconf/1.0" name="fitHigh" templateFileName="fitHigh-template.docx" resultFileName="fitHigh-actual-generation.docx" validationFileName="fitHigh-actual-validation.docx"/>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

=== HEADER ===

=== BODY ===

Checks ImageServices registration :
[query: .fit(.asImage('Mona_Lisa.jpg'), 300, 150, false)]
End of demonstration.
=== FOOTER ===

=== TEMPLATES ===
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="ASCII"?>
<genconf:Generation xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:genconf="http://www.obeonetwork.org/m2doc/genconf/1.0" name="fitHigh" templateFileName="fitHigh-template.docx" resultFileName="fitHigh-actual-generation.docx" validationFileName="fitHigh-actual-validation.docx"/>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

=== HEADER ===

=== BODY ===

Checks ImageServices registration :
[query: .fit(.asImage('Mona_Lisa.jpg'), 100, 400, false)]
End of demonstration.
=== FOOTER ===

=== TEMPLATES ===
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="ASCII"?>
<genconf:Generation xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:genconf="http://www.obeonetwork.org/m2doc/genconf/1.0" name="fitHigh" templateFileName="fitHigh-template.docx" resultFileName="fitHigh-actual-generation.docx" validationFileName="fitHigh-actual-validation.docx"/>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

=== HEADER ===

=== BODY ===

Checks ImageServices registration :
[query: .fit(.asImage('Mona_Lisa.jpg'), 100, 150, false)]
End of demonstration.
=== FOOTER ===

=== TEMPLATES ===
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="ASCII"?>
<genconf:Generation xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:genconf="http://www.obeonetwork.org/m2doc/genconf/1.0" name="fitHigh" templateFileName="fitHigh-template.docx" resultFileName="fitHigh-actual-generation.docx" validationFileName="fitHigh-actual-validation.docx"/>

0 comments on commit 46fec3e

Please sign in to comment.