Lines 22-27
package org.apache.poi.xslf.usermodel;
Link Here
|
22 |
import java.awt.Dimension; |
22 |
import java.awt.Dimension; |
23 |
import java.awt.Insets; |
23 |
import java.awt.Insets; |
24 |
import java.awt.Rectangle; |
24 |
import java.awt.Rectangle; |
|
|
25 |
import java.awt.geom.Rectangle2D; |
25 |
import java.net.URI; |
26 |
import java.net.URI; |
26 |
import javax.xml.namespace.QName; |
27 |
import javax.xml.namespace.QName; |
27 |
|
28 |
|
Lines 29-34
import org.apache.poi.POIXMLException;
Link Here
|
29 |
import org.apache.poi.openxml4j.opc.PackagePart; |
30 |
import org.apache.poi.openxml4j.opc.PackagePart; |
30 |
import org.apache.poi.openxml4j.opc.PackageRelationship; |
31 |
import org.apache.poi.openxml4j.opc.PackageRelationship; |
31 |
import org.apache.poi.sl.usermodel.PictureShape; |
32 |
import org.apache.poi.sl.usermodel.PictureShape; |
|
|
33 |
import org.apache.poi.sl.usermodel.RectAlign; |
32 |
import org.apache.poi.util.Beta; |
34 |
import org.apache.poi.util.Beta; |
33 |
import org.apache.xmlbeans.XmlCursor; |
35 |
import org.apache.xmlbeans.XmlCursor; |
34 |
import org.apache.xmlbeans.XmlObject; |
36 |
import org.apache.xmlbeans.XmlObject; |
Lines 101-106
public class XSLFPictureShape extends XSLFSimpleShape implements PictureShape {
Link Here
|
101 |
} |
103 |
} |
102 |
} |
104 |
} |
103 |
|
105 |
|
|
|
106 |
|
107 |
/** |
108 |
* Fit picture shape into the target rectangle, maintaining the aspect ratio |
109 |
* and repositioning within the target rectangle with a centered alignment. |
110 |
* |
111 |
* @param target The target rectangle |
112 |
*/ |
113 |
public void resize(Rectangle2D target) |
114 |
{ |
115 |
resize(target, RectAlign.CENTER); |
116 |
} |
117 |
|
118 |
|
119 |
/** |
120 |
* Fit picture shape into the target rectangle, maintaining the aspect ratio |
121 |
* and repositioning within the target rectangle based on the specified |
122 |
* alignment (gravity). |
123 |
* |
124 |
* @param target The target rectangle |
125 |
* @param align |
126 |
* The alignment within the target rectangle when resizing. |
127 |
* A null value corresponds to RectAlign.CENTER |
128 |
*/ |
129 |
public void resize(Rectangle2D target, RectAlign align) |
130 |
{ |
131 |
Dimension dim = getPictureData().getImageDimension(); |
132 |
if (dim.width <= 0 || dim.height <= 0) |
133 |
{ |
134 |
// nothing useful to be done for this case |
135 |
setAnchor(target); |
136 |
return; |
137 |
} |
138 |
|
139 |
double w = target.getWidth(); |
140 |
double h = target.getHeight(); |
141 |
|
142 |
// scaling |
143 |
double sx = w / dim.width; |
144 |
double sy = h / dim.height; |
145 |
|
146 |
// position adjustments |
147 |
double dx = 0, dy = 0; |
148 |
|
149 |
if (sx > sy) |
150 |
{ |
151 |
// use y-scaling for both, reposition x accordingly |
152 |
w = sy * dim.width; |
153 |
dx = target.getWidth() - w; |
154 |
} |
155 |
else if (sy > sx) |
156 |
{ |
157 |
// use x-scaling for both, reposition y accordingly |
158 |
h = sx * dim.height; |
159 |
dy = target.getHeight() - h; |
160 |
} |
161 |
else |
162 |
{ |
163 |
// uniform scaling, can use target values directly |
164 |
setAnchor(target); |
165 |
return; |
166 |
} |
167 |
|
168 |
// the positioning |
169 |
double x = target.getX(); |
170 |
double y = target.getY(); |
171 |
switch (align) |
172 |
{ |
173 |
case TOP: // X=balance, Y=ok |
174 |
x += dx/2; |
175 |
break; |
176 |
case TOP_RIGHT: // X=shift, Y=ok |
177 |
x += dx; |
178 |
break; |
179 |
case RIGHT: // X=shift, Y=balance |
180 |
x += dx; |
181 |
y += dy/2; |
182 |
break; |
183 |
case BOTTOM_RIGHT: // X=shift, Y=shift |
184 |
x += dx; |
185 |
y += dy; |
186 |
break; |
187 |
case BOTTOM: // X=balance, Y=shift |
188 |
x += dx/2; |
189 |
y += dy; |
190 |
break; |
191 |
case BOTTOM_LEFT: // X=ok, Y=shift |
192 |
y += dy; |
193 |
break; |
194 |
case LEFT: // X=ok, Y=balance |
195 |
y += dy/2; |
196 |
break; |
197 |
case TOP_LEFT: // X=ok, Y=ok |
198 |
/* no-op */ |
199 |
break; |
200 |
default: // CENTER: X=balance, Y=balance |
201 |
x += dx/2; |
202 |
y += dy/2; |
203 |
break; |
204 |
} |
205 |
|
206 |
setAnchor(new Rectangle2D.Double(x, y, w, h)); |
207 |
} |
208 |
|
209 |
|
104 |
/** |
210 |
/** |
105 |
* Is this an internal picture (image data included within |
211 |
* Is this an internal picture (image data included within |
106 |
* the PowerPoint file), or an external linked picture |
212 |
* the PowerPoint file), or an external linked picture |
107 |
- |
|
|