Changeset 8083 in josm for trunk/src/com/kitfox
- Timestamp:
- 2015-02-18T15:49:56+01:00 (10 years ago)
- Location:
- trunk/src/com/kitfox/svg
- Files:
-
- 3 added
- 1 deleted
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/com/kitfox/svg/Font.java
r6002 r8083 144 144 } 145 145 146 public void setFontFace(FontFace face) 147 { 148 fontFace = face; 149 } 150 146 151 public MissingGlyph getGlyph(String unicode) 147 152 { -
trunk/src/com/kitfox/svg/FontFace.java
r6002 r8083 54 54 * Em size of coordinate system font is defined in 55 55 */ 56 int unitsPerEm = 1000;57 int ascent = -1;58 int descent = -1;59 int accentHeight = -1;60 int underlinePosition = -1;61 int underlineThickness = -1;62 int strikethroughPosition = -1;63 int strikethroughThickness = -1;64 int overlinePosition = -1;65 int overlineThickness = -1;56 private int unitsPerEm = 1000; 57 private int ascent = -1; 58 private int descent = -1; 59 private int accentHeight = -1; 60 private int underlinePosition = -1; 61 private int underlineThickness = -1; 62 private int strikethroughPosition = -1; 63 private int strikethroughThickness = -1; 64 private int overlinePosition = -1; 65 private int overlineThickness = -1; 66 66 67 67 /** … … 234 234 return false; 235 235 } 236 237 /** 238 * @param unitsPerEm the unitsPerEm to set 239 */ 240 public void setUnitsPerEm(int unitsPerEm) 241 { 242 this.unitsPerEm = unitsPerEm; 243 } 244 245 /** 246 * @param ascent the ascent to set 247 */ 248 public void setAscent(int ascent) 249 { 250 this.ascent = ascent; 251 } 252 253 /** 254 * @param descent the descent to set 255 */ 256 public void setDescent(int descent) 257 { 258 this.descent = descent; 259 } 260 261 /** 262 * @param accentHeight the accentHeight to set 263 */ 264 public void setAccentHeight(int accentHeight) 265 { 266 this.accentHeight = accentHeight; 267 } 268 269 /** 270 * @param underlinePosition the underlinePosition to set 271 */ 272 public void setUnderlinePosition(int underlinePosition) 273 { 274 this.underlinePosition = underlinePosition; 275 } 276 277 /** 278 * @param underlineThickness the underlineThickness to set 279 */ 280 public void setUnderlineThickness(int underlineThickness) 281 { 282 this.underlineThickness = underlineThickness; 283 } 284 285 /** 286 * @param strikethroughPosition the strikethroughPosition to set 287 */ 288 public void setStrikethroughPosition(int strikethroughPosition) 289 { 290 this.strikethroughPosition = strikethroughPosition; 291 } 292 293 /** 294 * @param strikethroughThickness the strikethroughThickness to set 295 */ 296 public void setStrikethroughThickness(int strikethroughThickness) 297 { 298 this.strikethroughThickness = strikethroughThickness; 299 } 300 301 /** 302 * @param overlinePosition the overlinePosition to set 303 */ 304 public void setOverlinePosition(int overlinePosition) 305 { 306 this.overlinePosition = overlinePosition; 307 } 308 309 /** 310 * @param overlineThickness the overlineThickness to set 311 */ 312 public void setOverlineThickness(int overlineThickness) 313 { 314 this.overlineThickness = overlineThickness; 315 } 236 316 } -
trunk/src/com/kitfox/svg/Group.java
r7676 r8083 150 150 //Don't process if not visible 151 151 StyleAttribute styleAttrib = new StyleAttribute(); 152 if (getStyle(styleAttrib.setName("visibility"))) 153 { 154 if (!styleAttrib.getStringValue().equals("visible")) 152 //Visibility can be overridden by children 153 154 if (getStyle(styleAttrib.setName("display"))) 155 { 156 if (styleAttrib.getStringValue().equals("none")) 155 157 { 156 158 return; 157 159 } 158 160 } 159 161 160 162 //Do not process offscreen groups 161 163 boolean ignoreClip = diagram.ignoringClipHeuristic(); -
trunk/src/com/kitfox/svg/ImageSVG.java
r7676 r8083 207 207 { 208 208 if (!styleAttrib.getStringValue().equals("visible")) 209 { 210 return; 211 } 212 } 213 214 if (getStyle(styleAttrib.setName("display"))) 215 { 216 if (styleAttrib.getStringValue().equals("none")) 209 217 { 210 218 return; -
trunk/src/com/kitfox/svg/Marker.java
r6002 r8083 56 56 float refX; 57 57 float refY; 58 float markerWidth = 3;59 float markerHeight = 3;58 float markerWidth = 1; 59 float markerHeight = 1; 60 60 float orient = Float.NaN; 61 61 boolean markerUnitsStrokeWidth = true; //if set to false 'userSpaceOnUse' is assumed … … 196 196 boolean changeState = super.updateTime(curTime); 197 197 198 build(); 199 198 200 //Marker properties do not change 199 201 return changeState; -
trunk/src/com/kitfox/svg/MissingGlyph.java
r6002 r8083 59 59 60 60 //We may define a path 61 Shape path = null;61 private Shape path = null; 62 62 //Alternately, we may have child graphical elements 63 int horizAdvX = -1; //Inherits font's value if not set64 int vertOriginX = -1; //Inherits font's value if not set65 int vertOriginY = -1; //Inherits font's value if not set66 int vertAdvY = -1; //Inherits font's value if not set63 private int horizAdvX = -1; //Inherits font's value if not set 64 private int vertOriginX = -1; //Inherits font's value if not set 65 private int vertOriginY = -1; //Inherits font's value if not set 66 private int vertAdvY = -1; //Inherits font's value if not set 67 67 68 68 /** … … 242 242 return false; 243 243 } 244 245 /** 246 * @param path the path to set 247 */ 248 public void setPath(Shape path) 249 { 250 this.path = path; 251 } 252 253 /** 254 * @param horizAdvX the horizAdvX to set 255 */ 256 public void setHorizAdvX(int horizAdvX) 257 { 258 this.horizAdvX = horizAdvX; 259 } 260 261 /** 262 * @param vertOriginX the vertOriginX to set 263 */ 264 public void setVertOriginX(int vertOriginX) 265 { 266 this.vertOriginX = vertOriginX; 267 } 268 269 /** 270 * @param vertOriginY the vertOriginY to set 271 */ 272 public void setVertOriginY(int vertOriginY) 273 { 274 this.vertOriginY = vertOriginY; 275 } 276 277 /** 278 * @param vertAdvY the vertAdvY to set 279 */ 280 public void setVertAdvY(int vertAdvY) 281 { 282 this.vertAdvY = vertAdvY; 283 } 244 284 } -
trunk/src/com/kitfox/svg/SVGElement.java
r7676 r8083 588 588 static public AffineTransform parseSingleTransform(String val) throws SVGException 589 589 { 590 final Matcher matchWord = Pattern.compile("([a-zA-Z]+|-?\\d+(\\.\\d+)? |-?\\.\\d+)").matcher("");590 final Matcher matchWord = Pattern.compile("([a-zA-Z]+|-?\\d+(\\.\\d+)?(e-?\\d+)?|-?\\.\\d+(e-?\\d+)?)").matcher(""); 591 591 592 592 AffineTransform retXform = new AffineTransform(); -
trunk/src/com/kitfox/svg/Text.java
r7676 r8083 36 36 package com.kitfox.svg; 37 37 38 import com.kitfox.svg.util.FontSystem; 39 import com.kitfox.svg.util.TextBuilder; 38 40 import com.kitfox.svg.xml.StyleAttribute; 39 41 import java.awt.Graphics2D; … … 89 91 int fontWeight; 90 92 93 float textLength = -1; 94 String lengthAdjust = "spacing"; 95 91 96 /** 92 97 * Creates a new instance of Stop … … 167 172 { 168 173 fontFamily = sty.getStringValue(); 169 } else 174 } 175 else 170 176 { 171 177 fontFamily = "Sans Serif"; … … 175 181 { 176 182 fontSize = sty.getFloatValueWithUnits(); 177 } else 183 } 184 else 178 185 { 179 186 fontSize = 12f; 187 } 188 189 if (getStyle(sty.setName("textLength"))) 190 { 191 textLength = sty.getFloatValueWithUnits(); 192 } 193 else 194 { 195 textLength = -1; 196 } 197 198 if (getStyle(sty.setName("lengthAdjust"))) 199 { 200 lengthAdjust = sty.getStringValue(); 201 } 202 else 203 { 204 lengthAdjust = "spacing"; 180 205 } 181 206 … … 235 260 //text-rendering 236 261 237 buildFont(); 238 } 239 240 protected void buildFont() throws SVGException 241 { 242 int style; 243 switch (fontStyle) 244 { 245 case TXST_ITALIC: 246 style = java.awt.Font.ITALIC; 247 break; 248 default: 249 style = java.awt.Font.PLAIN; 250 break; 251 } 252 253 int weight; 254 switch (fontWeight) 255 { 256 case TXWE_BOLD: 257 case TXWE_BOLDER: 258 weight = java.awt.Font.BOLD; 259 break; 260 default: 261 weight = java.awt.Font.PLAIN; 262 break; 263 } 262 buildText(); 263 } 264 265 protected void buildText() throws SVGException 266 { 264 267 265 268 //Get font … … 269 272 // System.err.println("Could not load font"); 270 273 271 java.awt.Font sysFont = new java.awt.Font(fontFamily, style | weight, (int) fontSize); 272 buildSysFont(sysFont); 273 return; 274 font = new FontSystem(fontFamily, fontStyle, fontWeight, (int)fontSize); 275 // java.awt.Font sysFont = new java.awt.Font(fontFamily, style | weight, (int)fontSize); 276 // buildSysFont(sysFont); 277 // return; 274 278 } 275 279 … … 288 292 289 293 // AffineTransform oldXform = g.getTransform(); 294 // TextBuilder builder = new TextBuilder(); 295 // 296 // for (Iterator it = content.iterator(); it.hasNext();) 297 // { 298 // Object obj = it.next(); 299 // 300 // if (obj instanceof String) 301 // { 302 // String text = (String) obj; 303 // if (text != null) 304 // { 305 // text = text.trim(); 306 // } 307 // 308 // for (int i = 0; i < text.length(); i++) 309 // { 310 // String unicode = text.substring(i, i + 1); 311 // MissingGlyph glyph = font.getGlyph(unicode); 312 // 313 // builder.appendGlyph(glyph); 314 // } 315 // } 316 // else if (obj instanceof Tspan) 317 // { 318 // Tspan tspan = (Tspan)obj; 319 // tspan.buildGlyphs(builder); 320 // } 321 // } 322 // 323 // builder.formatGlyphs(); 324 325 326 327 328 329 330 331 290 332 AffineTransform xform = new AffineTransform(); 291 333 … … 328 370 329 371 strokeWidthScalar = 1f; 330 } else if (obj instanceof Tspan) 331 { 332 Tspan tspan = (Tspan) obj; 333 334 xform.setToIdentity(); 335 xform.setToTranslation(cursorX, cursorY); 336 xform.scale(fontScale, fontScale); 337 // tspan.setCursorX(cursorX); 338 // tspan.setCursorY(cursorY); 339 340 Shape tspanShape = tspan.getShape(); 341 tspanShape = xform.createTransformedShape(tspanShape); 342 textPath.append(tspanShape, false); 343 // tspan.render(g); 344 // cursorX = tspan.getCursorX(); 345 // cursorY = tspan.getCursorY(); 346 } 347 348 } 349 350 switch (textAnchor) 351 { 352 case TXAN_MIDDLE: 353 { 354 AffineTransform at = new AffineTransform(); 355 at.translate(-textPath.getBounds().getWidth() / 2, 0); 356 textPath.transform(at); 357 break; 358 } 359 case TXAN_END: 360 { 361 AffineTransform at = new AffineTransform(); 362 at.translate(-textPath.getBounds().getWidth(), 0); 363 textPath.transform(at); 364 break; 365 } 366 } 367 } 368 369 private void buildSysFont(java.awt.Font font) throws SVGException 370 { 371 GeneralPath textPath = new GeneralPath(); 372 textShape = textPath; 373 374 float cursorX = x, cursorY = y; 375 376 // FontMetrics fm = g.getFontMetrics(font); 377 FontRenderContext frc = new FontRenderContext(null, true, true); 378 379 // FontFace fontFace = font.getFontFace(); 380 //int unitsPerEm = fontFace.getUnitsPerEm(); 381 // int ascent = fm.getAscent(); 382 // float fontScale = fontSize / (float)ascent; 383 384 // AffineTransform oldXform = g.getTransform(); 385 AffineTransform xform = new AffineTransform(); 386 387 for (Iterator it = content.iterator(); it.hasNext();) 388 { 389 Object obj = it.next(); 390 391 if (obj instanceof String) 392 { 393 String text = (String)obj; 394 text = text.trim(); 395 396 Shape textShape = font.createGlyphVector(frc, text).getOutline(cursorX, cursorY); 397 textPath.append(textShape, false); 398 // renderShape(g, textShape); 399 // g.drawString(text, cursorX, cursorY); 400 401 Rectangle2D rect = font.getStringBounds(text, frc); 402 cursorX += (float) rect.getWidth(); 403 } else if (obj instanceof Tspan) 404 { 405 /* 406 Tspan tspan = (Tspan)obj; 407 408 xform.setToIdentity(); 409 xform.setToTranslation(cursorX, cursorY); 410 411 Shape tspanShape = tspan.getShape(); 412 tspanShape = xform.createTransformedShape(tspanShape); 413 textArea.add(new Area(tspanShape)); 414 415 cursorX += tspanShape.getBounds2D().getWidth(); 416 */ 417 418 372 } 373 else if (obj instanceof Tspan) 374 { 375 // Tspan tspan = (Tspan) obj; 376 // 377 // xform.setToIdentity(); 378 // xform.setToTranslation(cursorX, cursorY); 379 // xform.scale(fontScale, fontScale); 380 //// tspan.setCursorX(cursorX); 381 //// tspan.setCursorY(cursorY); 382 // 383 // Shape tspanShape = tspan.getShape(); 384 // tspanShape = xform.createTransformedShape(tspanShape); 385 // textPath.append(tspanShape, false); 386 //// tspan.render(g); 387 //// cursorX = tspan.getCursorX(); 388 //// cursorY = tspan.getCursorY(); 389 390 419 391 Tspan tspan = (Tspan)obj; 420 392 Point2D cursor = new Point2D.Float(cursorX, cursorY); … … 426 398 cursorX = (float)cursor.getX(); 427 399 cursorY = (float)cursor.getY(); 428 429 } 400 401 } 402 430 403 } 431 404 … … 442 415 { 443 416 AffineTransform at = new AffineTransform(); 444 at.translate(- Math.ceil(textPath.getBounds().getWidth()), 0);417 at.translate(-textPath.getBounds().getWidth(), 0); 445 418 textPath.transform(at); 446 419 break; … … 448 421 } 449 422 } 423 424 // private void buildSysFont(java.awt.Font font) throws SVGException 425 // { 426 // GeneralPath textPath = new GeneralPath(); 427 // textShape = textPath; 428 // 429 // float cursorX = x, cursorY = y; 430 // 431 //// FontMetrics fm = g.getFontMetrics(font); 432 // FontRenderContext frc = new FontRenderContext(null, true, true); 433 // 434 //// FontFace fontFace = font.getFontFace(); 435 // //int unitsPerEm = fontFace.getUnitsPerEm(); 436 //// int ascent = fm.getAscent(); 437 //// float fontScale = fontSize / (float)ascent; 438 // 439 //// AffineTransform oldXform = g.getTransform(); 440 // AffineTransform xform = new AffineTransform(); 441 // 442 // for (Iterator it = content.iterator(); it.hasNext();) 443 // { 444 // Object obj = it.next(); 445 // 446 // if (obj instanceof String) 447 // { 448 // String text = (String)obj; 449 // text = text.trim(); 450 // 451 // Shape textShape = font.createGlyphVector(frc, text).getOutline(cursorX, cursorY); 452 // textPath.append(textShape, false); 453 //// renderShape(g, textShape); 454 //// g.drawString(text, cursorX, cursorY); 455 // 456 // Rectangle2D rect = font.getStringBounds(text, frc); 457 // cursorX += (float) rect.getWidth(); 458 // } else if (obj instanceof Tspan) 459 // { 460 // /* 461 // Tspan tspan = (Tspan)obj; 462 // 463 // xform.setToIdentity(); 464 // xform.setToTranslation(cursorX, cursorY); 465 // 466 // Shape tspanShape = tspan.getShape(); 467 // tspanShape = xform.createTransformedShape(tspanShape); 468 // textArea.add(new Area(tspanShape)); 469 // 470 // cursorX += tspanShape.getBounds2D().getWidth(); 471 // */ 472 // 473 // 474 // Tspan tspan = (Tspan)obj; 475 // Point2D cursor = new Point2D.Float(cursorX, cursorY); 476 //// tspan.setCursorX(cursorX); 477 //// tspan.setCursorY(cursorY); 478 // tspan.appendToShape(textPath, cursor); 479 //// cursorX = tspan.getCursorX(); 480 //// cursorY = tspan.getCursorY(); 481 // cursorX = (float)cursor.getX(); 482 // cursorY = (float)cursor.getY(); 483 // 484 // } 485 // } 486 // 487 // switch (textAnchor) 488 // { 489 // case TXAN_MIDDLE: 490 // { 491 // AffineTransform at = new AffineTransform(); 492 // at.translate(-textPath.getBounds().getWidth() / 2, 0); 493 // textPath.transform(at); 494 // break; 495 // } 496 // case TXAN_END: 497 // { 498 // AffineTransform at = new AffineTransform(); 499 // at.translate(-Math.ceil(textPath.getBounds().getWidth()), 0); 500 // textPath.transform(at); 501 // break; 502 // } 503 // } 504 // } 450 505 451 506 public void render(Graphics2D g) throws SVGException … … 502 557 } 503 558 559 if (getStyle(sty.setName("textLength"))) 560 { 561 textLength = sty.getFloatValueWithUnits(); 562 } 563 else 564 { 565 textLength = -1; 566 } 567 568 if (getStyle(sty.setName("lengthAdjust"))) 569 { 570 lengthAdjust = sty.getStringValue(); 571 } 572 else 573 { 574 lengthAdjust = "spacing"; 575 } 576 504 577 if (getPres(sty.setName("font-family"))) 505 578 { -
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.