Changeset 8083 in josm for trunk/src/com/kitfox/svg/Tspan.java
- Timestamp:
- 2015-02-18T15:49:56+01:00 (11 years ago)
- File:
-
- 1 edited
-
trunk/src/com/kitfox/svg/Tspan.java (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/com/kitfox/svg/Tspan.java
r7676 r8083 36 36 package com.kitfox.svg; 37 37 38 import com.kitfox.svg.util.FontSystem; 38 39 import com.kitfox.svg.xml.StyleAttribute; 39 40 import java.awt.Graphics2D; … … 168 169 public void appendToShape(GeneralPath addShape, Point2D cursor) throws SVGException 169 170 { 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 // }185 186 171 StyleAttribute sty = new StyleAttribute(); 187 172 … … 203 188 { 204 189 letterSpacing = sty.getFloatValueWithUnits(); 190 } 191 192 int fontStyle = 0; 193 if (getStyle(sty.setName("font-style"))) 194 { 195 String s = sty.getStringValue(); 196 if ("normal".equals(s)) 197 { 198 fontStyle = Text.TXST_NORMAL; 199 } else if ("italic".equals(s)) 200 { 201 fontStyle = Text.TXST_ITALIC; 202 } else if ("oblique".equals(s)) 203 { 204 fontStyle = Text.TXST_OBLIQUE; 205 } 206 } else 207 { 208 fontStyle = Text.TXST_NORMAL; 209 } 210 211 int fontWeight = 0; 212 if (getStyle(sty.setName("font-weight"))) 213 { 214 String s = sty.getStringValue(); 215 if ("normal".equals(s)) 216 { 217 fontWeight = Text.TXWE_NORMAL; 218 } else if ("bold".equals(s)) 219 { 220 fontWeight = Text.TXWE_BOLD; 221 } 222 } else 223 { 224 fontWeight = Text.TXWE_NORMAL; 205 225 } 206 226 … … 210 230 if (font == null) 211 231 { 212 addShapeSysFont(addShape, font, fontFamily, fontSize, letterSpacing, cursor); 213 return; 232 font = new FontSystem(fontFamily, fontStyle, fontWeight, (int)fontSize); 233 // addShapeSysFont(addShape, font, fontFamily, fontSize, letterSpacing, cursor); 234 // return; 214 235 } 215 236 … … 275 296 } 276 297 277 private void addShapeSysFont(GeneralPath addShape, Font font, 278 String fontFamily, float fontSize, float letterSpacing, Point2D cursor) 279 { 280 281 java.awt.Font sysFont = new java.awt.Font(fontFamily, java.awt.Font.PLAIN, (int) fontSize); 282 283 FontRenderContext frc = new FontRenderContext(null, true, true); 284 String renderText = this.text.trim(); 285 286 AffineTransform xform = new AffineTransform(); 287 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 310 xform.setToIdentity(); 311 xform.setToTranslation(cursorX, cursorY); 312 if (rotate != null) 313 { 314 xform.rotate(rotate[Math.min(i, rotate.length - 1)]); 315 } 316 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); 321 322 glyphOutline = xform.createTransformedShape(glyphOutline); 323 addShape.append(glyphOutline, false); 324 325 326 // cursorX += fontScale * glyph.getHorizAdvX() + letterSpacing; 327 cursorX += glyphMetrics.getAdvance() + letterSpacing; 328 } 329 330 cursor.setLocation(cursorX, cursorY); 331 } 298 // private void addShapeSysFont(GeneralPath addShape, Font font, 299 // String fontFamily, float fontSize, float letterSpacing, Point2D cursor) 300 // { 301 // 302 // java.awt.Font sysFont = new java.awt.Font(fontFamily, java.awt.Font.PLAIN, (int) fontSize); 303 // 304 // FontRenderContext frc = new FontRenderContext(null, true, true); 305 // String renderText = this.text.trim(); 306 // 307 // AffineTransform xform = new AffineTransform(); 308 // 309 // float cursorX = (float)cursor.getX(); 310 // float cursorY = (float)cursor.getY(); 311 //// int i = 0; 312 // for (int i = 0; i < renderText.length(); i++) 313 // { 314 // if (x != null && i < x.length) 315 // { 316 // cursorX = x[i]; 317 // } else if (dx != null && i < dx.length) 318 // { 319 // cursorX += dx[i]; 320 // } 321 // 322 // if (y != null && i < y.length) 323 // { 324 // cursorY = y[i]; 325 // } else if (dy != null && i < dy.length) 326 // { 327 // cursorY += dy[i]; 328 // } 329 //// i++; 330 // 331 // xform.setToIdentity(); 332 // xform.setToTranslation(cursorX, cursorY); 333 // if (rotate != null) 334 // { 335 // xform.rotate(rotate[Math.min(i, rotate.length - 1)]); 336 // } 337 // 338 //// String unicode = renderText.substring(i, i + 1); 339 // GlyphVector textVector = sysFont.createGlyphVector(frc, renderText.substring(i, i + 1)); 340 // Shape glyphOutline = textVector.getGlyphOutline(0); 341 // GlyphMetrics glyphMetrics = textVector.getGlyphMetrics(0); 342 // 343 // glyphOutline = xform.createTransformedShape(glyphOutline); 344 // addShape.append(glyphOutline, false); 345 // 346 // 347 //// cursorX += fontScale * glyph.getHorizAdvX() + letterSpacing; 348 // cursorX += glyphMetrics.getAdvance() + letterSpacing; 349 // } 350 // 351 // cursor.setLocation(cursorX, cursorY); 352 // } 332 353 333 354 public void render(Graphics2D g) throws SVGException
Note:
See TracChangeset
for help on using the changeset viewer.
