Revision 18621 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/symbols/SimpleTextSymbol.java
SimpleTextSymbol.java | ||
---|---|---|
49 | 49 |
import java.awt.font.GlyphVector; |
50 | 50 |
import java.awt.geom.AffineTransform; |
51 | 51 |
import java.awt.geom.Point2D; |
52 |
import java.awt.geom.Rectangle2D; |
|
52 | 53 |
|
53 | 54 |
import javax.print.attribute.PrintRequestAttributeSet; |
54 | 55 |
|
55 | 56 |
import org.apache.batik.ext.awt.geom.PathLength; |
56 | 57 |
|
57 | 58 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
59 |
import com.iver.cit.gvsig.fmap.ViewPort; |
|
60 |
import com.iver.cit.gvsig.fmap.core.CartographicSupportToolkit; |
|
58 | 61 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
59 | 62 |
import com.iver.cit.gvsig.fmap.core.FPolygon2D; |
60 | 63 |
import com.iver.cit.gvsig.fmap.core.FShape; |
... | ... | |
76 | 79 |
*/ |
77 | 80 |
public class SimpleTextSymbol extends AbstractSymbol implements ITextSymbol { |
78 | 81 |
private String text = ""; |
79 |
private Font font = new Font("Arial", Font.PLAIN, 10);
|
|
82 |
private Font font = new Font("Arial", Font.PLAIN, 12);
|
|
80 | 83 |
private Color textColor = Color.BLACK; |
81 | 84 |
private double rotation; |
82 | 85 |
private FontRenderContext frc = new FontRenderContext( |
... | ... | |
130 | 133 |
// que all? no estiga fent-se tamb? -rot, si ?s aix?, ?s perqu? ac? |
131 | 134 |
// est? al reves (i en tots els llocs on es gasta) |
132 | 135 |
g.rotate(rot); |
133 |
g.drawString(getText(), 0, 0); |
|
136 |
g.drawString(getText(), 0, getBounds().height); |
|
137 |
Rectangle2D bounds = getBounds(); |
|
138 |
bounds.setFrame(0, 0, bounds.getWidth(), bounds.getHeight()); |
|
134 | 139 |
g.rotate(-rot); |
135 | 140 |
g.translate(-p.getX(), -p.getY()); |
136 | 141 |
} |
137 | 142 |
|
138 | 143 |
public void drawInsideRectangle(Graphics2D g, |
139 |
AffineTransform scaleInstance, Rectangle r) { |
|
144 |
AffineTransform scaleInstance, Rectangle r) throws SymbolDrawingException {
|
|
140 | 145 |
float fontSize = getFont().getSize(); |
141 | 146 |
float fontScaleFactor = (float) ((getText().length()*fontSize) * 0.8) // text length with a 20% margin |
142 | 147 |
/ r.width; |
143 | 148 |
g.setColor(textColor); |
144 | 149 |
g.translate(r.x, r.y); |
145 |
fontSize = fontSize / fontScaleFactor;
|
|
150 |
fontSize = fontSize /fontScaleFactor; |
|
146 | 151 |
if (fontSize > r.height) |
147 | 152 |
fontSize = r.height; |
148 | 153 |
g.setFont(new Font(getFont().getName(), getFont().getStyle(), (int)fontSize)); |
149 | 154 |
g.drawString(getText(), 0, fontSize); |
155 |
|
|
150 | 156 |
g.translate(-r.x, -r.y); |
157 |
|
|
151 | 158 |
} |
152 | 159 |
|
153 | 160 |
public int getOnePointRgb() { |
154 | 161 |
return textColor.getRGB(); |
155 | 162 |
} |
156 | 163 |
|
157 |
public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform,
|
|
158 |
Shape shp) {
|
|
164 |
public void getPixExtentPlus(FShape shp, float[] distances,
|
|
165 |
ViewPort viewPort, int dpi) {
|
|
159 | 166 |
// TODO Implement it |
160 | 167 |
throw new Error("Not yet implemented!"); |
161 | 168 |
|
... | ... | |
179 | 186 |
xml.putProperty("size", font.getSize()); |
180 | 187 |
xml.putProperty("text", text); |
181 | 188 |
xml.putProperty("textColor", StringUtilities.color2String(textColor)); |
189 |
xml.putProperty("unit", getUnit()); |
|
190 |
xml.putProperty("referenceSystem", getReferenceSystem()); |
|
182 | 191 |
return xml; |
183 | 192 |
} |
184 | 193 |
|
... | ... | |
194 | 203 |
setIsShapeVisible(xml.getBooleanProperty("isShapeVisible")); |
195 | 204 |
text = xml.getStringProperty("text"); |
196 | 205 |
textColor = StringUtilities.string2Color(xml.getStringProperty("textColor")); |
206 |
setUnit(xml.getIntProperty("unit")); |
|
207 |
setReferenceSystem(xml.getIntProperty("referenceSystem")); |
|
197 | 208 |
} |
198 | 209 |
|
199 | 210 |
public String getClassName() { |
... | ... | |
250 | 261 |
*/ |
251 | 262 |
public FShape getTextWrappingShape(FPoint2D p) { |
252 | 263 |
Font font = getFont(); |
253 |
|
|
254 |
// FontRenderContext frc = g.getFontRenderContext(); |
|
255 |
|
|
256 |
|
|
257 | 264 |
GlyphVector gv = font.createGlyphVector(frc, text); |
258 | 265 |
|
259 |
/*p.transform(affineTransform);*/ |
|
260 | 266 |
Shape shape = gv.getOutline((float) p.getX(), (float) p.getY()); |
261 |
FShape myFShape = new FPolygon2D(new GeneralPathX(shape.getBounds2D())); |
|
267 |
FShape myFShape = new FPolygon2D(new GeneralPathX(shape.getBounds())); |
|
268 |
|
|
269 |
myFShape.transform(AffineTransform.getTranslateInstance(p.getX(), p.getY())); |
|
270 |
|
|
262 | 271 |
if (rotation != 0) { |
263 |
myFShape.transform(AffineTransform.getRotateInstance(rotation, p.getX(), p.getY()));
|
|
272 |
myFShape.transform(AffineTransform.getRotateInstance(rotation)); |
|
264 | 273 |
} |
265 | 274 |
return myFShape; |
266 | 275 |
} |
276 |
|
|
277 |
public Rectangle getBounds() { |
|
278 |
Rectangle bounds = getTextWrappingShape(new FPoint2D(0,0)).getBounds(); |
|
279 |
// bounds.setLocation( |
|
280 |
// (int) Math.round(bounds.getX()), |
|
281 |
// (int) Math.round(bounds.getY()-bounds.getHeight())); |
|
282 |
// |
|
283 |
return bounds; |
|
284 |
} |
|
267 | 285 |
|
268 | 286 |
/** |
269 | 287 |
* Returns an FShape which represents a rectangle containing the text in |
... | ... | |
339 | 357 |
return myFShape; |
340 | 358 |
} |
341 | 359 |
|
360 |
|
|
361 |
public void setCartographicSize(double cartographicSize, FShape shp) { |
|
362 |
setFontSize(cartographicSize); |
|
363 |
} |
|
364 |
|
|
365 |
public double toCartographicSize(ViewPort viewPort, double dpi, FShape shp) { |
|
366 |
double oldSize = getFont().getSize(); |
|
367 |
setCartographicSize(getCartographicSize( |
|
368 |
viewPort, |
|
369 |
dpi, |
|
370 |
shp), |
|
371 |
shp); |
|
372 |
return oldSize; |
|
373 |
} |
|
374 |
|
|
375 |
public double getCartographicSize(ViewPort viewPort, double dpi, FShape shp) { |
|
376 |
return CartographicSupportToolkit. |
|
377 |
getCartographicLength(this, |
|
378 |
getFont().getSize(), |
|
379 |
viewPort, |
|
380 |
dpi); |
|
381 |
} |
|
342 | 382 |
} |
Also available in: Unified diff