Login | Register
My pages Projects Community openCollabNet

Discussions > cvs > CVS update: MODIFIED: persistence ...

gef
Discussion topic

Back to topic list

CVS update: MODIFIED: persistence ...

Reply

Author toby
Full name Toby Baier
Date 2001-06-18 01:33:56 PDT
Message User: toby
  Date: 01/06/18 01:33:56

  Modified: src/org/tigris/gef/persistence SVGWriter.java
  Log:
  svg fix by Andreas
  Obtained from:Andreas
  Submitted by:Toby
  
  Revision Changes Path
  1.3 +1 -1 gef/src/org/tigris/g​ef/base/CmdSaveSVG.j​ava
  
  http://gef.tigris.or​g/source/browse/gef/​src/org/tigris/gef/b​ase/CmdSaveSVG.java.​diff?r1=1.2&r2=1​.3
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CmdSaveSVG.java
  ====================​====================​====================​=======
  RCS file: /usr/local/tigris/da​ta/helm/cvs/reposito​ry/gef/src/org/tigri​s/gef/base/CmdSaveSV​G.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- CmdSaveSVG.java 2001/03/12 15:09:04 1.2
  +++ CmdSaveSVG.java 2001/06/18 08:33:56 1.3
  @@ -45,7 +45,7 @@
         System.out.println("Writing Scalable Vector Graphics...");
         SVGWriter writer = null;
         try {
  - writer = new SVGWriter(s);
  + writer = new SVGWriter(s, drawingArea);
         } catch (Exception e) {
             System.out.println("Whatever this exception may be..." +e);
             e.printStackTrace();
  
  
  
  1.6 +66 -28 gef/src/org/tigris/g​ef/persistence/SVGWr​iter.java
  
  http://gef.tigris.or​g/source/browse/gef/​src/org/tigris/gef/p​ersistence/SVGWriter​.java.diff?r1=1.5​&r2=1.6
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SVGWriter.java
  ====================​====================​====================​=======
  RCS file: /usr/local/tigris/da​ta/helm/cvs/reposito​ry/gef/src/org/tigri​s/gef/persistence/SV​GWriter.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -b -r1.5 -r1.6
  --- SVGWriter.java 2001/05/21 11:54:37 1.5
  +++ SVGWriter.java 2001/06/18 08:33:56 1.6
  @@ -24,7 +24,7 @@
   // File: SVGWriter.java
   // Classes: SVGWriter
   // Original Author: Andreas Rueckert <a_rueckert at gmx dot net>
  -// $Id: SVGWriter.java,v 1.5 2001/05/21 11:54:37 toby Exp $
  +// $Id: SVGWriter.java,v 1.6 2001/06/18 08:33:56 toby Exp $
   
   package org.tigris.gef.persistence;
   
  @@ -55,7 +55,15 @@
        */
       private Color _bgColor = Color.white;
   
  - private Font fFont = new Font("Helvetica",Fon​t.PLAIN,12);
  + /**
  + * The drawing area for the SVG output.
  + */
  + private Rectangle _drawingArea;
  +
  + /**
  + * The current font.
  + */
  + private Font _font = new Font("Verdana",Font.PLAIN,8);
   
       private Rectangle clip;
   
  @@ -67,8 +75,9 @@
       private double yScale = 1.0;
       private String SVGns = "http://www.w3.org/2000/SVG";
   
  - public SVGWriter(OutputStream stream) throws IOException, Exception {
  + public SVGWriter(OutputStream stream, Rectangle drawingArea) throws IOException, Exception {
           _p = new PrintWriter(stream);
  + _drawingArea = drawingArea;
   
           DocumentBuilderFactory factory = DocumentBuilderFacto​ry.newInstance();
           factory.setNamespace​Aware(false);
  @@ -78,8 +87,8 @@
   
       _root = _svg.createElement( "svg");
           _root.setAttribute("xmlns","http://www.w3.org/2000/svg");
  - _root.setAttribute( "width", "600");
  - _root.setAttribute( "height", "600");
  + _root.setAttribute( "width", "" + scaleX(_drawingArea.width));
  + _root.setAttribute( "height", "" + scaleY(_drawingArea.height));
       }
   
       public Graphics create() { return this; }
  @@ -258,38 +267,41 @@
   
       public void setXORMode(Color otherColor) {}
   
  - public Font getFont() { return fFont; }
  + public Font getFont() { return _font; }
   
       public void setFont(Font font) {
  - /*
  - if (!fFont.equals(font)) {
  - fFont = font;
  - FontMetrics metrics = getFontMetrics();
  - String name = font.getName();
  - if (font.isBold() || font.isItalic()) {
  - name += "-";
  - if (font.isBold())
  - name += "Bold";
  - if (font.isItalic())
  - name += "Oblique";
  - }
  -
  - p.println("isolatin1encoding /_" + name + " /" + name + " RE");
  - p.println("/_" + name + " findfont");
  - p.println(font.getSize() + " scalefont setfont");
  - } */
  + _font = font;
       }
   
  - /*
       public FontMetrics getFontMetrics() {
  - return getFontMetrics(fFont);
  + return getFontMetrics(_font);
       }
  - */
   
       public FontMetrics getFontMetrics(Font font) {
       return Toolkit.getDefaultTo​olkit().getFontMetri​cs(font);
       }
   
  + /**
  + * Translate the current font to a SVG 'style' attribute.
  + *
  + * @return The style of the current font as a SVG attribute.
  + */
  + private String getFontStyleSVG() {
  + String style = "font-family:" + _font.getFamily() + "; font-size:" + _font.getSize() +";";
  +
  + // If this is a bold font, add the appropriate attribute.
  + if(getFont().isBold()) {
  + style += " font-weight:bold;";
  + }
  +
  + // If this is a italic font, add the appropriate attribute.
  + if(getFont().isItalic()) {
  + style += " font-style:italic;";
  + }
  +
  + return style;
  + }
  +
       public java.awt.Rectangle getClipBounds() { return clip; }
   
       public void clipRect(int x, int y, int w, int h) { setClip(x,y,w,h); }
  @@ -512,6 +524,8 @@
       }
   
       private void drawPolygon( int xPoints[], int yPoints[], int nPoints, String style) {
  + double maxX = 0, maxY = 0;
  +
       Element polygon = _svg.createElement( "polygon");
       polygon.setAttribute( "style", style);
   
  @@ -526,6 +540,14 @@
                     + transformX( xPoints[i])
                     + ","
                     + transformY( yPoints[i]));
  +
  + if(transformX( xPoints[i]) > maxX) {
  + maxX = transformX( xPoints[i]);
  + }
  +
  + if(transformY( yPoints[i]) > maxY) {
  + maxY = transformY( yPoints[i]);
  + }
       }
   
       polygon.setAttribute( "points", pointList.toString());
  @@ -550,6 +572,7 @@
       }
   
       public void drawPolyline(int xPoints[], int yPoints[], int nPoints) {
  + double maxX = 0, maxY = 0;
       Element polyline = _svg.createElement( "polyline");
       polyline.setAttribute( "style", "fill:" + getBackgroundColorAsString() + "; stroke:" + getColorAsString() + "; stroke-width:1");
   
  @@ -564,6 +587,14 @@
                     + transformX( xPoints[i])
                     + ","
                     + transformY( yPoints[i]));
  +
  + if(transformX( xPoints[i]) > maxX) {
  + maxX = transformX( xPoints[i]);
  + }
  +
  + if(transformY( yPoints[i]) > maxY) {
  + maxY = transformY( yPoints[i]);
  + }
       }
   
       polyline.setAttribute( "points", pointList.toString());
  @@ -603,11 +634,18 @@
       this.yScale = yscale;
       }
   
  + /**
  + * Draw a string at a given position.
  + *
  + * @param t The string to draw.
  + * @param x The horizontal position of the text.
  + * @param y The vertical position of the text.
  + */
       public void drawString(String t, int x, int y) {
           Element text = _svg.createElement("text");
           text.setAttribute( "x", ""+transformX( x));
           text.setAttribute( "y", ""+transformY( y));
  - text.setAttribute( "style", "font-family:Verdana; font-size:8pt;");
  + text.setAttribute( "style", getFontStyleSVG());
           text.appendChild( _svg.createTextNode( t));
           _root.appendChild( text);
       }
  
  
  

--------------------​--------------------​--------------------​---------
To unsubscribe, e-mail: cvs-unsubscribe at gef dot tigris dot org
For additional commands, e-mail: cvs-help at gef dot tigris dot org

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

CVS update: MODIFIED: persistence ... toby Toby Baier 2001-06-18 01:33:56 PDT
Messages per page: