Revision 10436 branches/simbologia/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/symbols/TextSymbol.java

View differences:

TextSymbol.java
43 43
*
44 44
* $Id$
45 45
* $Log$
46
* Revision 1.1.2.7  2007-02-16 10:54:12  jaume
46
* Revision 1.1.2.8  2007-02-21 07:34:09  jaume
47
* labeling starts working
48
*
49
* Revision 1.1.2.7  2007/02/16 10:54:12  jaume
47 50
* multilayer splitted to multilayerline, multilayermarker,and  multilayerfill
48 51
*
49 52
* Revision 1.1.2.6  2007/02/15 16:23:44  jaume
......
77 80
import java.awt.Rectangle;
78 81
import java.awt.Shape;
79 82
import java.awt.geom.AffineTransform;
83
import java.awt.geom.Point2D;
80 84

  
81 85
import javax.print.attribute.PrintRequestAttributeSet;
82 86

  
87
import org.apache.batik.ext.awt.geom.PathLength;
88

  
83 89
import com.iver.cit.gvsig.fmap.DriverException;
90
import com.iver.cit.gvsig.fmap.core.FPoint2D;
84 91
import com.iver.cit.gvsig.fmap.core.FShape;
85 92
import com.iver.cit.gvsig.fmap.core.IGeometry;
86 93
import com.iver.cit.gvsig.fmap.core.TextPath;
94
import com.iver.cit.gvsig.fmap.core.v02.FConverter;
87 95
import com.iver.cit.gvsig.fmap.rendering.styling.ITextParser;
88 96
import com.iver.utiles.XMLEntity;
97
import com.vividsolutions.jts.geom.Geometry;
98
import com.vividsolutions.jts.geom.Point;
89 99

  
90 100
/**
91 101
 * @author   jaume dominguez faus - jaume.dominguez@iver.es
......
149 159
		return this; // a text is not selectable
150 160
	}
151 161

  
162
	/**
163
	 * Draws the text according. If this symbol has the text path set, then
164
	 * it is used as the text line, otherwise shp <b>must be an FPoint2D</b> 
165
	 * indicating the starting point of the text and then the text will
166
	 * be renderized from there and following the rotation previously set. 
167
	 */
152 168
	public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp) {
153 169
		g.setFont(font);
154 170

  
155 171
		g.setColor(Color.BLACK);
156
		textPath = new TextPath(g, shp, text);
157
		//AffineTransform at = (AffineTransform) g.getTransform().clone();
158
		for (int i = 0; i < text.length; i++) {
159
			double[] pos = textPath.nextPosForGlyph(i);
160
			g.translate((int) pos[0], (int) pos[1]);
161
			g.rotate(pos[2]);
162
			g.drawChars(new char[] {text[i]}, 0, 1, 0, 0);
163
			g.rotate(-pos[2]);
164
			g.translate(-(int) pos[0], -(int) pos[1]);
172
		if (textPath != null) {
173
			//AffineTransform at = (AffineTransform) g.getTransform().clone();
174
			for (int i = 0; i < text.length; i++) {
175
				double[] pos = textPath.nextPosForGlyph(i);
176
				g.translate((int) pos[0], (int) pos[1]);
177
				g.rotate(pos[2]);
178
				g.drawChars(new char[] {text[i]}, 0, 1, 0, 0);
179
				g.rotate(-pos[2]);
180
				g.translate(-(int) pos[0], -(int) pos[1]);
181
			}
182
		} else {
183
			Point2D p = null;
184
			shp.transform(affineTransform);
185
			double rot=0;
186
			switch (shp.getShapeType()) {
187
			case FShape.POINT:
188
				FPoint2D fp=(FPoint2D) shp;
189
				p = new Point2D.Double(fp.getX(),fp.getY());
190
				break;
191
			case FShape.LINE:
192
				PathLength pathLen = new PathLength(shp);
193

  
194
				// if (pathLen.lengthOfPath() < width / mT.getScaleX()) return;
195
				float midDistance = pathLen.lengthOfPath() / 2;
196
				p = pathLen.pointAtLength(midDistance);
197
				rot = pathLen.angleAtLength(midDistance);
198
				break;
199
			case FShape.POLYGON:
200
				Geometry geo = FConverter.java2d_to_jts(shp);
201

  
202
				if (geo == null) {
203
					return;
204
				}
205

  
206
				Point pJTS = geo.getCentroid();
207

  
208
				if (pJTS != null) {
209
					FShape pLabel = FConverter.jts_to_java2d(pJTS);
210
					p= new Point2D.Double(((FPoint2D) pLabel).getX(),
211
							((FPoint2D) pLabel).getY());
212
				}
213
				break;
214
			}
215
			g.setColor(Color.BLACK);
216
			g.setFont(new Font("Arial",Font.PLAIN, 10));
217
			g.translate(p.getX(), p.getY());
218
			g.rotate(rot);
219
			g.drawString(new String(text), 0, 0);
220
			g.rotate(-rot);
221
			g.translate(-p.getX(), -p.getY());
222
			
165 223
		}
166 224
	}
167 225

  
226
	public void setTextPath(TextPath textPath) {
227
		this.textPath = textPath;
228
	}
168 229
	public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform, Shape shp) {
169 230
		// TODO Implement it
170 231
		throw new Error("Not yet implemented!");

Also available in: Unified diff