You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by fo...@locus.apache.org on 2000/03/19 11:29:42 UTC

cvs commit: xml-fop/src/org/apache/fop/render/awt AWTRenderer.java

fotis       00/03/19 02:29:42

  Modified:    src/org/apache/fop/render/awt AWTRenderer.java
  Log:
  adds border support (contributed by Jon Smirl) also to the awt rendering (Jon Smirl, Fotis Jannidis)
  
  Revision  Changes    Path
  1.3       +276 -182  xml-fop/src/org/apache/fop/render/awt/AWTRenderer.java
  
  Index: AWTRenderer.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/render/awt/AWTRenderer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AWTRenderer.java	2000/01/25 13:51:55	1.2
  +++ AWTRenderer.java	2000/03/19 10:29:41	1.3
  @@ -9,7 +9,6 @@
     Stanislav Gorkhover: Stanislav.Gorkhover@af-software.de
    */
   
  -
   import org.apache.fop.layout.*;
   import org.apache.fop.datatypes.*;
   import org.apache.fop.image.*;
  @@ -18,9 +17,6 @@
   import org.apache.fop.viewer.*;
   import org.apache.fop.apps.*;
   
  -
  -
  -
   import java.awt.*;
   import java.awt.image.*;
   import java.awt.geom.*;
  @@ -45,17 +41,16 @@
   
     protected Hashtable fontNames = new Hashtable();
     protected Hashtable fontStyles = new Hashtable();
  +  protected Color saveColor;
   
   
     // Key - Font name, Value - java Font name.
     protected static Hashtable JAVA_FONT_NAMES;
   
  -
     protected Graphics2D graphics = null;
   
     protected DocumentPanel documentPanel = null;
   
  -
     /** the current (internal) font name */
     protected String currentFontName;
   
  @@ -83,7 +78,6 @@
   
     // String oldFontName = null;
   
  -
     static {
       JAVA_FONT_NAMES = new Hashtable();
       JAVA_FONT_NAMES.put("Times", "serif");
  @@ -93,7 +87,6 @@
       // JAVA_FONT_NAMES.put("Serif", "sansserif");
     }
   
  -
     public AWTRenderer(Translator aRes) {
       res = aRes;
     }
  @@ -130,6 +123,63 @@
     }
   
   
  +    /**
  +     * add a line to the current stream
  +     *
  +     * @param x1 the start x location in millipoints
  +     * @param y1 the start y location in millipoints
  +     * @param x2 the end x location in millipoints
  +     * @param y2 the end y location in millipoints
  +     * @param th the thickness in millipoints
  +     * @param r the red component
  +     * @param g the green component
  +     * @param b the blue component
  +     */
  +    protected void addLine(int x1, int y1, int x2, int y2, int th,
  +      float r, float g, float b) {
  +      graphics.setColor(new Color (r,g,b));
  +      graphics.drawLine((int)(x1/1000f), pageHeight - (int)(y1/1000f), (int)(x2/1000f), pageHeight - (int)(y2/1000f));
  +    }
  +
  +
  +    /**
  +     * draw a filled rectangle
  +     *
  +     * @param x the x position of left edge in millipoints
  +     * @param y the y position of top edge in millipoints
  +     * @param w the width in millipoints
  +     * @param h the height in millipoints
  +     * @param r the red component
  +     * @param g the green component
  +     * @param b the blue component
  +     */
  +    protected void addRect(int x, int y, int w, int h,
  +         float r, float g, float b) {
  +      graphics.setColor(new Color (r,g,b));
  +      graphics.fill3DRect((int) (x/1000f),pageHeight - (int) (y/1000f),(int) (w/1000f),-(int) (h/1000f),false);
  +    }
  +
  +    /**
  +     * draw a filled rectangle
  +     *
  +     * @param x the x position of left edge in millipoints
  +     * @param y the y position of top edge in millipoints
  +     * @param w the width in millipoints
  +     * @param h the height in millipoints
  +     * @param r the red component of edges
  +     * @param g the green component of edges
  +     * @param b the blue component of edges
  +     * @param fr the red component of the fill
  +     * @param fg the green component of the fill
  +     * @param fb the blue component of the fill
  +     */
  +    protected void addRect(int x, int y, int w, int h,
  +         float r, float g, float b,
  +         float fr, float fg, float fb) {
  +      graphics.setColor(new Color (r,g,b));
  +      graphics.fill3DRect((int) (x/1000f),pageHeight - (int) (y/1000f),(int) (w/1000f),-(int) (h/1000f),true);
  +    }
  +
     /**
      * Vor dem Druck einzustellen:
      *
  @@ -158,7 +208,6 @@
   
       graphics.drawLine(0, height+2, width+2, height+2);
       graphics.drawLine(1, height+3, width+3, height+3);
  -
     }
   
   
  @@ -184,74 +233,122 @@
     }
   
     public void renderPage(Page page) {
  -	AreaContainer body, before, after;
  +    AreaContainer body, before, after;
   
  -	body = page.getBody();
  -	before = page.getBefore();
  -	after = page.getAfter();
  +    body = page.getBody();
  +    before = page.getBefore();
  +    after = page.getAfter();
   
  -	this.currentFontName = "";
  -	this.currentFontSize = 0;
  +    this.currentFontName = "";
  +    this.currentFontSize = 0;
   
  -	renderAreaContainer(body);
  +    renderAreaContainer(body);
   
  -	if (before != null) {
  -	    renderAreaContainer(before);
  -	}
  -
  -	if (after != null) {
  -	    renderAreaContainer(after);
  -	}
  +    if (before != null) {
  +        renderAreaContainer(before);
  +    }
   
  +    if (after != null) {
  +        renderAreaContainer(after);
  +    }
     }
   
  -
     public void renderAreaContainer(AreaContainer area) {
   
  +    int saveY = this.currentYPosition;
  +    int saveX = this.currentAreaContainerXPosition;
   
  -	this.currentYPosition = area.getYPosition();
  -	this.currentAreaContainerXPosition = area.getXPosition();
  +    if (area.getPosition() == org.apache.fop.fo.properties.Position.ABSOLUTE) {
  +        // Y position is computed assuming positive Y axis, adjust for negative postscript one
  +      this.currentYPosition = area.getYPosition() - 2 * area.getPaddingTop() - 2 * area.borderWidthTop;
  +      this.currentAreaContainerXPosition = area.getXPosition();
  +    } else if (area.getPosition() == org.apache.fop.fo.properties.Position.RELATIVE) {
  +      this.currentYPosition -= area.getYPosition();
  +       this.currentAreaContainerXPosition += area.getXPosition();
  +    } else if (area.getPosition() == org.apache.fop.fo.properties.Position.STATIC) {
  +      this.currentYPosition -= area.getPaddingTop() + area.borderWidthTop;
  +      this.currentAreaContainerXPosition += area.getPaddingLeft() + area.borderWidthLeft;
  +    }
  +
  +    doFrame(area);
  +
  +    Enumeration e = area.getChildren().elements();
  +    while (e.hasMoreElements()) {
  +     org.apache.fop.layout.Box b = (org.apache.fop.layout.Box) e.nextElement();
  +     b.render(this);
  +    }
  +
  +    if (area.getPosition() != org.apache.fop.fo.properties.Position.STATIC) {
  +      this.currentYPosition = saveY;
  +      this.currentAreaContainerXPosition = saveX;
  +    } else {
  +      this.currentYPosition -= area.getHeight();
  +    }
  +  }
   
  -	Enumeration e = area.getChildren().elements();
  -	while (e.hasMoreElements()) {
  -	    org.apache.fop.layout.Box b = (org.apache.fop.layout.Box) e.nextElement();
  -	    b.render(this);
  -	}
  +  private void doFrame(org.apache.fop.layout.Area area) {
  +    int w, h;
  +    int rx = this.currentAreaContainerXPosition;
  +    w = area.getContentWidth();
  +    if (area instanceof BlockArea)
  +    rx += ((BlockArea)area).getStartIndent();
  +    h = area.getContentHeight();
  +    int ry = this.currentYPosition;
  +    ColorType bg = area.getBackgroundColor();
  +
  +    rx = rx - area.getPaddingLeft();
  +    ry = ry + area.getPaddingTop();
  +    w = w + area.getPaddingLeft() + area.getPaddingRight();
  +    h = h + area.getPaddingTop() + area.getPaddingBottom();
  +
  +    // I'm not sure I should have to check for bg being null
  +    // but I do
  +    if ((bg != null) && (bg.alpha() == 0)) {
  +      this.addRect(rx, ry, w, -h,
  +      bg.red(), bg.green(), bg.blue(),
  +      bg.red(), bg.green(), bg.blue());
  +    }
  +
  +    rx = rx - area.borderWidthLeft;
  +    ry = ry + area.borderWidthTop;
  +    w = w + area.borderWidthLeft + area.borderWidthRight;
  +    h = h + area.borderWidthTop + area.borderWidthBottom;
  +
  +    if (area.borderWidthTop != 0)
  +      addLine(rx, ry, rx + w, ry,
  +          area.borderWidthTop,
  +          area.borderColorTop.red(), area.borderColorTop.green(), area.borderColorTop.blue());
  +    if (area.borderWidthLeft != 0)
  +      addLine(rx, ry, rx, ry - h,
  +          area.borderWidthLeft,
  +          area.borderColorLeft.red(), area.borderColorLeft.green(), area.borderColorLeft.blue());
  +    if (area.borderWidthRight != 0)
  +      addLine(rx + w, ry, rx + w, ry - h,
  +          area.borderWidthRight,
  +          area.borderColorRight.red(), area.borderColorRight.green(), area.borderColorRight.blue());
  +    if (area.borderWidthBottom != 0)
  +      addLine(rx, ry - h, rx + w, ry - h,
  +          area.borderWidthBottom,
  +          area.borderColorBottom.red(), area.borderColorBottom.green(), area.borderColorBottom.blue());
     }
   
   
   
     protected Rectangle2D getBounds(org.apache.fop.layout.Area a) {
       return new Rectangle2D.Double(currentAreaContainerXPosition,
  -                                  currentYPosition,
  -                                  a.getAllocationWidth(),
  -                                  a.getHeight());
  +                            currentYPosition,
  +                            a.getAllocationWidth(),
  +                            a.getHeight());
     }
  -
  -    public void renderBlockArea(BlockArea area) {
  -	int rx = this.currentAreaContainerXPosition
  -	    + area.getStartIndent();
  -	int ry = this.currentYPosition;
  -	int w = area.getContentWidth();
  -	int h = area.getHeight();
  -    ColorType bg = area.getBackgroundColor();
  -  	if ((bg != null) && (bg.alpha() == 0)) {
  -      Color oldColor = graphics.getColor();
  -      // Color bgColor = new Color(bg.red(), bg.green(), bg.blue());
  -      Color bgColor = colorType2Color(bg);
  -      graphics.setColor(bgColor);
  -      graphics.fillRect((int)(rx / 1000f), (int)(pageHeight - ry/ 1000f),
  -                        (int)(w / 1000f), (int)(h / 1000f));
  -      graphics.setColor(oldColor);
  -    }
   
  -	Enumeration e = area.getChildren().elements();
  -	while (e.hasMoreElements()) {
  -	    org.apache.fop.layout.Box b = (org.apache.fop.layout.Box) e.nextElement();
  -	    b.render(this);
  -	}
  +  public void renderBlockArea(BlockArea area) {
  +    doFrame(area);
  +    Enumeration e = area.getChildren().elements();
  +    while (e.hasMoreElements()) {
  +      org.apache.fop.layout.Box b = (org.apache.fop.layout.Box) e.nextElement();
  +      b.render(this);
       }
  -
  +  }
   
     public void setupFontInfo(FontInfo fontInfo) {
       FontSetup.setup(fontInfo);
  @@ -286,77 +383,76 @@
   
   
   
  -    public void renderDisplaySpace(DisplaySpace space) {
  -	int d = space.getSize();
  -	this.currentYPosition -= d;
  -    }
  -
  +  public void renderDisplaySpace(DisplaySpace space) {
  +    int d = space.getSize();
  +    this.currentYPosition -= d;
  +  }
   
  -    public void renderImageArea(ImageArea area) {
  -	int x = this.currentAreaContainerXPosition +
  -	    area.getXOffset();
  -	int y = this.currentYPosition;
  -	int w = area.getContentWidth();
  -	int h = area.getHeight();
   
  +  public void renderImageArea(ImageArea area) {
  +    int x = this.currentAreaContainerXPosition +
  +        area.getXOffset();
  +    int y = this.currentYPosition;
  +    int w = area.getContentWidth();
  +    int h = area.getHeight();
   
  -	FopImage img = area.getImage();
  +    FopImage img = area.getImage();
   
  -    if (img == null) {
  -      System.out.println("area.getImage() is null");
  -    }
  +      if (img == null) {
  +        System.out.println("area.getImage() is null");
  +      }
   
  -    int[] map = img.getimagemap();
  +      int[] map = img.getimagemap();
   
  -    String path = img.gethref();
  -    // path = "c:/any.gif";
  +      String path = img.gethref();
  +      // path = "c:/any.gif";
   
  -    ImageIcon icon = new ImageIcon(path);
  +      ImageIcon icon = new ImageIcon(path);
   
  -    Image imgage = icon.getImage();
  +      Image imgage = icon.getImage();
   
  -    graphics.drawImage(imgage, currentXPosition / 1000,
  -                       pageHeight - y / 1000,
  -                       img.getWidth() / 1000,
  -                       img.getHeight() / 1000,
  -                       null);
  +      graphics.drawImage(imgage, currentXPosition / 1000,
  +                         pageHeight - y / 1000,
  +                         img.getWidth() / 1000,
  +                         img.getHeight() / 1000,
  +                         null);
   
  -	currentYPosition -= h;
  -    }
  +    currentYPosition -= h;
  +  }
   
   
   
   
     public void renderInlineArea(InlineArea area) {
  -	char ch;
  -	StringBuffer pdf = new StringBuffer();
  +    char ch;
  +    StringBuffer pdf = new StringBuffer();
   
  -	String name = area.getFontState().getFontName();
  -	int size = area.getFontState().getFontSize();
  +    String name = area.getFontState().getFontName();
  +    int size = area.getFontState().getFontSize();
   
  -	float red = area.getRed();
  -	float green = area.getGreen();
  -	float blue = area.getBlue();
  -
  -	if ((!name.equals(this.currentFontName))
  -	    || (size != this.currentFontSize)) {
  -	    this.currentFontName = name;
  -	    this.currentFontSize = size;
  -	}
  -
  -	if ((red != this.currentRed)
  -	    || (green != this.currentGreen)
  -	    || (blue != this.currentBlue)) {
  -	    this.currentRed = red;
  -	    this.currentGreen = green;
  -	    this.currentBlue = blue;
  -	}
  +    float red = area.getRed();
  +    float green = area.getGreen();
  +    float blue = area.getBlue();
   
  -	int rx = this.currentXPosition;
  -	int bl = this.currentYPosition;
  +    if ((!name.equals(this.currentFontName))
  +        || (size != this.currentFontSize)) {
  +        this.currentFontName = name;
  +        this.currentFontSize = size;
  +    }
  +
  +    if ((red != this.currentRed)
  +        || (green != this.currentGreen)
  +        || (blue != this.currentBlue)) {
  +        this.currentRed = red;
  +        this.currentGreen = green;
  +        this.currentBlue = blue;
  +    }
   
  +    int rx = this.currentXPosition;
  +    int bl = this.currentYPosition;
   
  -	String s = area.getText();
  +
  +    String s = area.getText();
       Color oldColor = graphics.getColor();
       java.awt.Font oldFont = graphics.getFont();
       String aFontName = fontNames.get(name).toString();
  @@ -390,51 +486,52 @@
       graphics.setColor(oldColor);
   
   
  -	this.currentXPosition += area.getContentWidth();
  -    }
  +    this.currentXPosition += area.getContentWidth();
  +  }
   
  -    public void renderInlineSpace(InlineSpace space) {
  -	this.currentXPosition += space.getSize();
  -    }
   
  +  public void renderInlineSpace(InlineSpace space) {
  +    this.currentXPosition += space.getSize();
  +  }
   
  -    public void renderLineArea(LineArea area) {
  -	int rx = this.currentAreaContainerXPosition
  -	    + area.getStartIndent();
  -	int ry = this.currentYPosition;
  -	int w = area.getContentWidth();
  -	int h = area.getHeight();
   
  -	this.currentYPosition -= area.getPlacementOffset();
  -	this.currentXPosition = rx;
  +  public void renderLineArea(LineArea area) {
  +    int rx = this.currentAreaContainerXPosition
  +        + area.getStartIndent();
  +    int ry = this.currentYPosition;
  +    int w = area.getContentWidth();
  +    int h = area.getHeight();
   
  -	int bl = this.currentYPosition;
  +    this.currentYPosition -= area.getPlacementOffset();
  +    this.currentXPosition = rx;
   
  -	Enumeration e = area.getChildren().elements();
  -	while (e.hasMoreElements()) {
  -	    org.apache.fop.layout.Box b = (org.apache.fop.layout.Box) e.nextElement();
  -	    b.render(this);
  -	}
  +    int bl = this.currentYPosition;
   
  -	this.currentYPosition = ry-h;
  +    Enumeration e = area.getChildren().elements();
  +    while (e.hasMoreElements()) {
  +        org.apache.fop.layout.Box b = (org.apache.fop.layout.Box) e.nextElement();
  +        b.render(this);
       }
   
  -    /**
  -     * render rule area into PDF
  -     *
  -     * @param area area to render
  -     */
  -    public void renderRuleArea(RuleArea area) {
  -	int rx = this.currentAreaContainerXPosition
  -	    + area.getStartIndent();
  -	int ry = this.currentYPosition;
  -	int w = area.getContentWidth();
  -	int h = area.getHeight();
  -	int th = area.getRuleThickness();
  -	float r = area.getRed();
  -	float g = area.getGreen();
  -	float b = area.getBlue();
  +    this.currentYPosition = ry-h;
  +  }
   
  +  /**
  +   * render rule area into PDF
  +   *
  +   * @param area area to render
  +   */
  +  public void renderRuleArea(RuleArea area) {
  +    int rx = this.currentAreaContainerXPosition
  +        + area.getStartIndent();
  +    int ry = this.currentYPosition;
  +    int w = area.getContentWidth();
  +    int h = area.getHeight();
  +    int th = area.getRuleThickness();
  +    float r = area.getRed();
  +    float g = area.getGreen();
  +    float b = area.getBlue();
  +
   
       Color oldColor = graphics.getColor();
   
  @@ -444,42 +541,42 @@
                         (int)(w / 1000f), (int)(th / 1000f));
       graphics.setColor(oldColor);
   
  -    }
  +  }
   
   
  -    public void renderSVGArea(SVGArea area) {
  -	int x = this.currentAreaContainerXPosition;
  -	int y = this.currentYPosition;
  -	int w = area.getContentWidth();
  -	int h = area.getHeight();
  -	this.currentYPosition -= h;
  -  /*
  -	Enumeration e = area.getChildren().elements();
  -	while (e.hasMoreElements()) {
  -	    Object o = e.nextElement();
  -	    if (o instanceof RectGraphic) {
  -		int rx = ((RectGraphic)o).x;
  -		int ry = ((RectGraphic)o).y;
  -		int rw = ((RectGraphic)o).width;
  -		int rh = ((RectGraphic)o).height;
  -		addRect(x+rx,y-ry,rw,-rh,0,0,0);
  -	    } else if (o instanceof LineGraphic) {
  -		int x1 = ((LineGraphic)o).x1;
  -		int y1 = ((LineGraphic)o).y1;
  -		int x2 = ((LineGraphic)o).x2;
  -		int y2 = ((LineGraphic)o).y2;
  -		addLine(x+x1,y-y1,x+x2,y-y2,0,0,0,0);
  -	    } else if (o instanceof TextGraphic) {
  -		int tx = ((TextGraphic)o).x;
  -		int ty = ((TextGraphic)o).y;
  -		String s = ((TextGraphic)o).s;
  -		currentStream.add("1 0 0 1 "
  -				  + ((x+tx)/1000f) + " "
  -				  + ((y-ty)/1000f) + " Tm "
  -				  + "(" + s + ") Tj\n");
  -	    }
  -	} */
  -    }
  +  public void renderSVGArea(SVGArea area) {
  +    int x = this.currentAreaContainerXPosition;
  +    int y = this.currentYPosition;
  +    int w = area.getContentWidth();
  +    int h = area.getHeight();
  +    this.currentYPosition -= h;
  +    /*
  +    Enumeration e = area.getChildren().elements();
  +    while (e.hasMoreElements()) {
  +        Object o = e.nextElement();
  +        if (o instanceof RectGraphic) {
  +          int rx = ((RectGraphic)o).x;
  +          int ry = ((RectGraphic)o).y;
  +          int rw = ((RectGraphic)o).width;
  +          int rh = ((RectGraphic)o).height;
  +          addRect(x+rx,y-ry,rw,-rh,0,0,0);
  +        } else if (o instanceof LineGraphic) {
  +          int x1 = ((LineGraphic)o).x1;
  +          int y1 = ((LineGraphic)o).y1;
  +          int x2 = ((LineGraphic)o).x2;
  +          int y2 = ((LineGraphic)o).y2;
  +          addLine(x+x1,y-y1,x+x2,y-y2,0,0,0,0);
  +        } else if (o instanceof TextGraphic) {
  +          int tx = ((TextGraphic)o).x;
  +          int ty = ((TextGraphic)o).y;
  +          String s = ((TextGraphic)o).s;
  +          currentStream.add("1 0 0 1 "
  +                + ((x+tx)/1000f) + " "
  +                + ((y-ty)/1000f) + " Tm "
  +                + "(" + s + ") Tj\n");
  +        }
  +    } */
  +  }
   
   
   
  @@ -543,14 +640,11 @@
     }
   
     public static Color colorType2Color(ColorType ct) {
  -    if (ct == null)
  +    if (ct == null) {
         return null;
  +    }
       return new Color(ct.red(), ct.green(), ct.blue());
     }
   
   }
  -
  -
  -
  -
   
  
  
  

problem using XTCommandLine in fop 0.11.0 version

Posted by SWARANGI MURALIDHAR <sw...@tatainfotech.com>.
When I try to use XTCommandLine of fop 0.11.0 the following messages
are thrown on to screen

FOP 0.11.0
using SAX parser com.jclark.xml.sax.Driver
Exception in thread "main" java.lang.NoSuchMethodError:
com.jclark.xsl.sax.XSLProcessorImpl:method <init>()V not found
at com.jtauber.fop.apps.XTCommandLine.main(Unknown Source)

I have xt.jar in my classpath along with other required files
Why the above error ?
Please can someone help me out

S.MuraliDhar
swarangi.muralidhar@tatainfotech.com