Revision 26986 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/symbols/SimpleTextSymbol.java
SimpleTextSymbol.java | ||
---|---|---|
86 | 86 |
new AffineTransform(), false, true); |
87 | 87 |
private boolean autoresize; |
88 | 88 |
private Rectangle bounds = null; |
89 |
private FShape horizontalTextWrappingShape = null; |
|
89 | 90 |
|
90 | 91 |
public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp, Cancellable cancel) { |
91 | 92 |
if (!isShapeVisible()) return; |
... | ... | |
95 | 96 |
g.translate(((FPoint2D) shp).getX(), ((FPoint2D) shp).getY()); |
96 | 97 |
|
97 | 98 |
g.rotate(rotation); |
98 |
Rectangle2D bounds = getBounds(); |
|
99 |
// getBounds devuelve el bounds de un texto dibujado de manera que
|
|
100 |
// la linea base de la primera letra est? en el punto (0,0).
|
|
101 |
// Por eso, si queremos alinear el texto de manera que la parte superior |
|
102 |
// izquierda de la primera letra est? en (0,0) debemos moverlo seg?n
|
|
103 |
// el valor de la ordenada, en lugar de seg?n su altura.
|
|
104 |
g.drawString(getText(), 0, (int)-bounds.getY());//(int) bounds.getHeight());
|
|
99 |
Rectangle2D bounds = getHorizontalTextWrappingShape(new FPoint2D(0,0)).getBounds();
|
|
100 |
// Antes tomabamos el resultado de getBounds pero ya se le hab?a aplicado
|
|
101 |
// la rotaci?n, con lo que no obten?amos el la altura correcta de la fuente.
|
|
102 |
|
|
103 |
// Alineamos el texto de manera que la parte superior
|
|
104 |
// izquierda de la primera letra est? en (0,0).
|
|
105 |
g.drawString(getText(), 0, (int)-bounds.getY()); |
|
105 | 106 |
g.rotate(-rotation); |
106 | 107 |
g.translate(-((FPoint2D) shp).getX(), -((FPoint2D) shp).getY()); |
107 | 108 |
} |
... | ... | |
191 | 192 |
setReferenceSystem(xml.getIntProperty("referenceSystem")); |
192 | 193 |
setAutoresizeEnabled(xml.getBooleanProperty("autoresizeFlag")); |
193 | 194 |
this.bounds = null; |
195 |
this.horizontalTextWrappingShape = null; |
|
194 | 196 |
} |
195 | 197 |
|
196 | 198 |
public String getClassName() { |
... | ... | |
220 | 222 |
if(text != null && !text.equals(this.text)){ |
221 | 223 |
this.text = text; |
222 | 224 |
this.bounds = null; |
225 |
this.horizontalTextWrappingShape = null; |
|
223 | 226 |
} |
224 | 227 |
} |
225 | 228 |
|
... | ... | |
227 | 230 |
if (font != null && !font.equals(this.font)){ |
228 | 231 |
this.font = font; |
229 | 232 |
this.bounds = null; |
233 |
this.horizontalTextWrappingShape = null; |
|
230 | 234 |
} |
231 | 235 |
} |
232 | 236 |
|
... | ... | |
238 | 242 |
if (size != this.font.getSize2D()){ |
239 | 243 |
this.font = this.font.deriveFont((float) size); |
240 | 244 |
this.bounds = null; |
245 |
this.horizontalTextWrappingShape = null; |
|
241 | 246 |
} |
242 | 247 |
// this.font = new Font(this.font.getName(),this.font.getStyle(),(int)size); |
243 | 248 |
} |
... | ... | |
262 | 267 |
* Returns an FShape which represents a rectangle containing the text in |
263 | 268 |
* <b>screen</b> units. |
264 | 269 |
*/ |
265 |
public FShape getTextWrappingShape(FPoint2D p) { |
|
266 |
Font font = getFont(); |
|
267 |
/* Para tama?os de fuente de letras excesivamente grandes obtenemos |
|
268 |
* shapes con todas las coordenadas a 0, por eso limitamos el tama?o |
|
269 |
* a 1000 y despu?s reescalamos el bounds. |
|
270 |
*/ |
|
271 |
double scale = 1; |
|
272 |
float fontSize = font.getSize2D(); |
|
273 |
if (fontSize > 1000){ |
|
274 |
scale = fontSize/1000; |
|
275 |
fontSize = 1000; |
|
270 |
private FShape getHorizontalTextWrappingShape(FPoint2D p) { |
|
271 |
if (this.horizontalTextWrappingShape == null){ |
|
272 |
Font font = getFont(); |
|
273 |
/* Para tama?os de fuente de letras excesivamente grandes obtenemos |
|
274 |
* shapes con todas las coordenadas a 0, por eso limitamos el tama?o |
|
275 |
* a 1000 y despu?s reescalamos el bounds. |
|
276 |
*/ |
|
277 |
double scale = 1; |
|
278 |
float fontSize = font.getSize2D(); |
|
279 |
if (fontSize > 1000){ |
|
280 |
scale = fontSize/1000; |
|
281 |
fontSize = 1000; |
|
282 |
} |
|
283 |
font = font.deriveFont(fontSize); |
|
284 |
GlyphVector gv = font.createGlyphVector(frc, text); |
|
285 |
Shape shape = gv.getOutline((float) p.getX(), (float) p.getY()); |
|
286 |
FShape myFShape = new FPolygon2D(new GeneralPathX(shape.getBounds2D())); |
|
287 |
|
|
288 |
if(scale != 1){ |
|
289 |
myFShape.transform(AffineTransform.getScaleInstance(scale, scale)); |
|
290 |
} |
|
291 |
|
|
292 |
this.horizontalTextWrappingShape = myFShape; |
|
276 | 293 |
} |
277 |
font = font.deriveFont(fontSize); |
|
278 |
GlyphVector gv = font.createGlyphVector(frc, text); |
|
279 |
Shape shape = gv.getOutline((float) p.getX(), (float) p.getY()); |
|
280 |
FShape myFShape = new FPolygon2D(new GeneralPathX(shape.getBounds2D())); |
|
294 |
return this.horizontalTextWrappingShape; |
|
295 |
} |
|
281 | 296 |
|
282 |
myFShape.transform(AffineTransform.getScaleInstance(scale, scale)); |
|
297 |
/** |
|
298 |
* Returns an FShape which represents a rectangle containing the text in |
|
299 |
* <b>screen</b> units. |
|
300 |
*/ |
|
301 |
public FShape getTextWrappingShape(FPoint2D p) { |
|
302 |
|
|
303 |
FShape myFShape = getHorizontalTextWrappingShape(p); |
|
283 | 304 |
myFShape.transform(AffineTransform.getTranslateInstance(p.getX(), p.getY())); |
284 | 305 |
|
285 | 306 |
if (rotation != 0) { |
Also available in: Unified diff