Changeset 7676 in josm for trunk/src/com/kitfox/svg/Tspan.java
- Timestamp:
- 2014-10-30T11:39:47+01:00 (11 years ago)
- File:
-
- 1 edited
-
trunk/src/com/kitfox/svg/Tspan.java (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/com/kitfox/svg/Tspan.java
r6002 r7676 44 44 import java.awt.geom.AffineTransform; 45 45 import java.awt.geom.GeneralPath; 46 import java.awt.geom.Point2D; 46 47 import java.awt.geom.Rectangle2D; 47 48 … … 60 61 float[] rotate = null; 61 62 private String text = ""; 62 float cursorX; 63 float cursorY; 63 // float cursorX; 64 // float cursorY; 64 65 65 66 // Shape tspanShape; … … 76 77 } 77 78 78 public float getCursorX() 79 { 80 return cursorX; 81 } 82 83 public float getCursorY() 84 { 85 return cursorY; 86 } 87 88 public void setCursorX(float cursorX) 89 { 90 this.cursorX = cursorX; 91 } 92 93 public void setCursorY(float cursorY) 94 { 95 this.cursorY = cursorY; 96 } 79 // public float getCursorX() 80 // { 81 // return cursorX; 82 // } 83 // 84 // public float getCursorY() 85 // { 86 // return cursorY; 87 // } 88 // 89 // public void setCursorX(float cursorX) 90 // { 91 // this.cursorX = cursorX; 92 // } 93 // 94 // public void setCursorY(float cursorY) 95 // { 96 // this.cursorY = cursorY; 97 // } 97 98 /* 98 99 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent) … … 165 166 } 166 167 167 public void a ddShape(GeneralPath addShape) throws SVGException168 { 169 if (x != null) 170 { 171 cursorX = x[0]; 172 } else if (dx != null) 173 { 174 cursorX += dx[0]; 175 } 176 177 if (y != null) 178 { 179 cursorY = y[0]; 180 } else if (dy != null) 181 { 182 cursorY += dy[0]; 183 } 168 public void appendToShape(GeneralPath addShape, Point2D cursor) throws SVGException 169 { 170 // if (x != null) 171 // { 172 // cursorX = x[0]; 173 // } else if (dx != null) 174 // { 175 // cursorX += dx[0]; 176 // } 177 // 178 // if (y != null) 179 // { 180 // cursorY = y[0]; 181 // } else if (dy != null) 182 // { 183 // cursorY += dy[0]; 184 // } 184 185 185 186 StyleAttribute sty = new StyleAttribute(); … … 209 210 if (font == null) 210 211 { 211 addShapeSysFont(addShape, font, fontFamily, fontSize, letterSpacing); 212 addShapeSysFont(addShape, font, fontFamily, fontSize, letterSpacing, cursor); 212 213 return; 213 214 } … … 221 222 strokeWidthScalar = 1f / fontScale; 222 223 223 int posPtr = 1; 224 225 for (int i = 0; i < text.length(); i++) 226 { 224 float cursorX = (float)cursor.getX(); 225 float cursorY = (float)cursor.getY(); 226 227 // int i = 0; 228 229 String drawText = this.text; 230 drawText = drawText.trim(); 231 for (int i = 0; i < drawText.length(); i++) 232 { 233 if (x != null && i < x.length) 234 { 235 cursorX = x[i]; 236 } else if (dx != null && i < dx.length) 237 { 238 cursorX += dx[i]; 239 } 240 241 if (y != null && i < y.length) 242 { 243 cursorY = y[i]; 244 } else if (dy != null && i < dy.length) 245 { 246 cursorY += dy[i]; 247 } 248 // i++; 249 227 250 xform.setToIdentity(); 228 251 xform.setToTranslation(cursorX, cursorY); … … 230 253 if (rotate != null) 231 254 { 232 xform.rotate(rotate[ posPtr]);233 } 234 235 String unicode = text.substring(i, i + 1);255 xform.rotate(rotate[i]); 256 } 257 258 String unicode = drawText.substring(i, i + 1); 236 259 MissingGlyph glyph = font.getGlyph(unicode); 237 260 … … 243 266 } 244 267 245 if (x != null && posPtr < x.length)246 {247 cursorX = x[posPtr];248 cursorY = y[posPtr++];249 } else if (dx != null && posPtr < dx.length)250 {251 cursorX += dx[posPtr];252 cursorY += dy[posPtr++];253 }254 255 268 cursorX += fontScale * glyph.getHorizAdvX() + letterSpacing; 256 269 } 257 270 271 //Save final draw point so calling method knows where to begin next 272 // text draw 273 cursor.setLocation(cursorX, cursorY); 258 274 strokeWidthScalar = 1f; 259 275 } 260 276 261 277 private void addShapeSysFont(GeneralPath addShape, Font font, 262 String fontFamily, float fontSize, float letterSpacing) 263 { 278 String fontFamily, float fontSize, float letterSpacing, Point2D cursor) 279 { 280 264 281 java.awt.Font sysFont = new java.awt.Font(fontFamily, java.awt.Font.PLAIN, (int) fontSize); 265 282 266 283 FontRenderContext frc = new FontRenderContext(null, true, true); 267 GlyphVector textVector = sysFont.createGlyphVector(frc, text);284 String renderText = this.text.trim(); 268 285 269 286 AffineTransform xform = new AffineTransform(); 270 287 271 int posPtr = 1; 272 for (int i = 0; i < text.length(); i++) 273 { 288 float cursorX = (float)cursor.getX(); 289 float cursorY = (float)cursor.getY(); 290 // int i = 0; 291 for (int i = 0; i < renderText.length(); i++) 292 { 293 if (x != null && i < x.length) 294 { 295 cursorX = x[i]; 296 } else if (dx != null && i < dx.length) 297 { 298 cursorX += dx[i]; 299 } 300 301 if (y != null && i < y.length) 302 { 303 cursorY = y[i]; 304 } else if (dy != null && i < dy.length) 305 { 306 cursorY += dy[i]; 307 } 308 // i++; 309 274 310 xform.setToIdentity(); 275 xform.setToTranslation(cursorX + i * letterSpacing, cursorY);311 xform.setToTranslation(cursorX, cursorY); 276 312 if (rotate != null) 277 313 { … … 279 315 } 280 316 281 String unicode = text.substring(i, i + 1); 282 Shape glyphOutline = textVector.getGlyphOutline(i); 283 GlyphMetrics glyphMetrics = textVector.getGlyphMetrics(i); 317 // String unicode = renderText.substring(i, i + 1); 318 GlyphVector textVector = sysFont.createGlyphVector(frc, renderText.substring(i, i + 1)); 319 Shape glyphOutline = textVector.getGlyphOutline(0); 320 GlyphMetrics glyphMetrics = textVector.getGlyphMetrics(0); 284 321 285 322 glyphOutline = xform.createTransformedShape(glyphOutline); 286 323 addShape.append(glyphOutline, false); 287 324 288 if (x != null && posPtr < x.length) 289 { 290 cursorX = x[posPtr]; 291 cursorY = y[posPtr++]; 292 } else if (dx != null && posPtr < dx.length) 293 { 294 cursorX += dx[posPtr]; 295 cursorY += dy[posPtr++]; 296 } 297 } 325 326 // cursorX += fontScale * glyph.getHorizAdvX() + letterSpacing; 327 cursorX += glyphMetrics.getAdvance() + letterSpacing; 328 } 329 330 cursor.setLocation(cursorX, cursorY); 298 331 } 299 332 300 333 public void render(Graphics2D g) throws SVGException 301 334 { 335 float cursorX = 0; 336 float cursorY = 0; 337 302 338 if (x != null) 303 339 { … … 385 421 protected void renderSysFont(Graphics2D g, java.awt.Font font) throws SVGException 386 422 { 423 float cursorX = 0; 424 float cursorY = 0; 425 387 426 int posPtr = 1; 388 427 FontRenderContext frc = g.getFontRenderContext();
Note:
See TracChangeset
for help on using the changeset viewer.
