Revision 38405 branches/v2_0_0_prep/libraries/org.gvsig.symbology/org.gvsig.symbology.lib/org.gvsig.symbology.lib.impl/src/main/java/org/gvsig/symbology/fmap/mapcontext/rendering/symbol/style/SVGStyle.java
SVGStyle.java | ||
---|---|---|
132 | 132 |
} |
133 | 133 |
} else { |
134 | 134 |
Rectangle2D bounds = gvtRoot.getBounds(); |
135 |
double xOffset = 0; |
|
136 |
double yOffset = 0; |
|
137 |
double scale; |
|
138 |
scale = |
|
139 |
Math.min(rect.getWidth() / bounds.getWidth(), |
|
140 |
rect.getHeight() / bounds.getHeight()); |
|
141 |
xOffset = 0.5 * (rect.getWidth() - bounds.getWidth() * scale); |
|
142 |
yOffset = 0.5 * (rect.getHeight() - bounds.getHeight() * scale); |
|
143 |
|
|
144 |
ataux = AffineTransform.getTranslateInstance(xOffset, yOffset); |
|
145 |
|
|
146 |
ataux.concatenate(AffineTransform.getScaleInstance(scale, scale)); |
|
147 |
|
|
135 |
|
|
136 |
ataux = getNoRotationTransform( |
|
137 |
bounds, |
|
138 |
new Rectangle2D.Double( |
|
139 |
rect.x, |
|
140 |
rect.y, |
|
141 |
rect.width, |
|
142 |
rect.height), |
|
143 |
true); |
|
148 | 144 |
} |
149 | 145 |
RenderingHints renderingHints = new RenderingHints(null); |
150 | 146 |
renderingHints.putAll(defaultRenderingHints); |
... | ... | |
155 | 151 |
} else { |
156 | 152 |
|
157 | 153 |
Rectangle2D bounds = gvtRoot.getBounds(); |
158 |
|
|
159 |
double xOffset = 0; |
|
160 |
double yOffset = 0; |
|
161 |
double xScale = 1; |
|
162 |
double yScale = 1; |
|
163 |
xScale = rect.getWidth() / bounds.getWidth(); |
|
164 |
yScale = rect.getHeight() / bounds.getHeight(); |
|
165 |
xOffset = 0.5 * (rect.getWidth() - bounds.getWidth() * xScale); |
|
166 |
yOffset = 0.5 * (rect.getHeight() - bounds.getHeight() * yScale); |
|
167 |
|
|
168 |
AffineTransform ataux; |
|
169 |
|
|
170 |
ataux = AffineTransform.getTranslateInstance(xOffset, yOffset); |
|
171 |
|
|
172 |
ataux.concatenate(AffineTransform.getScaleInstance(xScale, yScale)); |
|
173 |
|
|
154 |
AffineTransform ataux = getNoRotationTransform( |
|
155 |
bounds, |
|
156 |
new Rectangle2D.Double(rect.x, rect.y, rect.width, rect.height), |
|
157 |
false); |
|
158 |
|
|
174 | 159 |
RenderingHints renderingHints = new RenderingHints(null); |
175 | 160 |
renderingHints.putAll(defaultRenderingHints); |
176 | 161 |
g.setRenderingHints(renderingHints); |
... | ... | |
261 | 246 |
} |
262 | 247 |
|
263 | 248 |
} |
249 |
|
|
250 |
|
|
251 |
private AffineTransform getNoRotationTransform( |
|
252 |
Rectangle2D from_rect, |
|
253 |
Rectangle2D to_rect, |
|
254 |
boolean keep_aspect) { |
|
255 |
|
|
256 |
double scalex = to_rect.getWidth() / from_rect.getWidth(); |
|
257 |
double scaley = to_rect.getHeight() / from_rect.getHeight(); |
|
258 |
|
|
259 |
if (keep_aspect) { |
|
260 |
// force min value for both |
|
261 |
scalex = Math.min(scalex, scaley); |
|
262 |
scaley = scalex; |
|
263 |
} |
|
264 |
|
|
265 |
double from_new_center_x = scalex * from_rect.getCenterX(); |
|
266 |
double from_new_center_y = scaley * from_rect.getCenterY(); |
|
267 |
|
|
268 |
double offx = to_rect.getCenterX() - from_new_center_x; |
|
269 |
double offy = to_rect.getCenterY() - from_new_center_y; |
|
270 |
|
|
271 |
AffineTransform resp = |
|
272 |
AffineTransform.getTranslateInstance(offx, offy); |
|
273 |
|
|
274 |
// this composition is equivalent to: |
|
275 |
// first scale, then move |
|
276 |
resp.concatenate( |
|
277 |
AffineTransform.getScaleInstance(scalex, scaley)); |
|
278 |
return resp; |
|
279 |
} |
|
264 | 280 |
} |
Also available in: Unified diff