diff options
author | Thorsten Behrens <thb@openoffice.org> | 2004-03-18 09:38:44 +0000 |
---|---|---|
committer | Thorsten Behrens <thb@openoffice.org> | 2004-03-18 09:38:44 +0000 |
commit | 6e89341b5045a01e823364633ef0fbfd44ebdfd5 (patch) | |
tree | e8bfc629f55ce0e0d31befb0b5c02233ef935705 /canvas/source/java | |
parent | aac18e0575873e71532ce77e4c2e4083e4c71b9a (diff) |
#110496# Merge from cws_srx645_canvas01: first working version of XCanvas UNO components, for now consisting of javacanvas.uno.jar, vclcanvas.uno and directxcanvas.uno (windows only)
Diffstat (limited to 'canvas/source/java')
27 files changed, 7077 insertions, 0 deletions
diff --git a/canvas/source/java/BackBuffer.java b/canvas/source/java/BackBuffer.java new file mode 100644 index 000000000000..abca8f200af6 --- /dev/null +++ b/canvas/source/java/BackBuffer.java @@ -0,0 +1,161 @@ +/************************************************************************* + * + * $RCSfile: BackBuffer.java,v $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +// UNO +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.IQueryInterface; +import com.sun.star.lang.XInitialization; +import com.sun.star.lib.uno.helper.WeakBase; + +// OOo AWT +import com.sun.star.awt.*; + +// Canvas +import drafts.com.sun.star.rendering.*; + +// Java AWT +import java.awt.*; +import java.awt.image.*; +import java.awt.geom.*; + +// system-dependent stuff +import sun.awt.*; + + +public class BackBuffer +{ + private BufferedImage backBuffer; + //private VolatileImage backBuffer; + private Graphics2D backBufferGraphics; + private Graphics2D referenceDevice; + + public BackBuffer( Graphics2D _referenceDevice, + int width, + int height ) + { + referenceDevice = _referenceDevice; + setSize( width, height ); + } + + public Graphics2D getGraphics() + { + return backBufferGraphics; + } + + public void setSize( int width, + int height ) + { + if( backBuffer != null && + width == backBuffer.getWidth() && + height == backBuffer.getHeight() ) + { + return; + } + + if( backBufferGraphics != null ) + backBufferGraphics.dispose(); + + if( backBuffer != null ) + backBuffer.flush(); + + // TODO: Maybe VolatileImage with another BufferedImage as a backup is + // a tad faster here. + backBuffer = referenceDevice.getDeviceConfiguration().createCompatibleImage(width, + height); +// backBuffer = referenceDevice.getDeviceConfiguration().createCompatibleVolatileImage(width, +// height); + + backBufferGraphics = backBuffer.createGraphics(); + CanvasUtils.initGraphics( backBufferGraphics ); + + // clear the buffer to white (to have a defined state here) + backBufferGraphics.setColor( java.awt.Color.white ); + backBufferGraphics.fillRect( 0,0,width,height ); + } + + public void redraw( Graphics2D graph ) + { + if( graph != null && + backBuffer != null ) + { + CanvasUtils.printLog("BackBuffer.redraw(): using buffer of size (" + + backBuffer.getWidth() + "," + backBuffer.getHeight() + ")" ); + + graph.drawImage(backBuffer, 0, 0, null); + + // TODO: this is just twiddled to work. I cannot be sure + // that this volatile backbuffer will survive in the first + // place, nor that it wise to leave it in VRAM. + + // only flush non-volatile images + // CanvasUtils.postRenderImageTreatment( backBuffer ); + } + } + + public java.awt.Image getBackBuffer() + { + return backBuffer; + } + + public void dispose() + { + backBufferGraphics.dispose(); + backBuffer.flush(); + } +} diff --git a/canvas/source/java/BezierPolyPolygon.java b/canvas/source/java/BezierPolyPolygon.java new file mode 100644 index 000000000000..bd13ea029ca0 --- /dev/null +++ b/canvas/source/java/BezierPolyPolygon.java @@ -0,0 +1,194 @@ +/************************************************************************* + * + * $RCSfile: BezierPolyPolygon.java,v $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +// UNO +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.AnyConverter; +import com.sun.star.lib.uno.helper.WeakBase; + +// OOo AWT +import com.sun.star.awt.*; + +// Canvas +import drafts.com.sun.star.rendering.*; +import drafts.com.sun.star.geometry.*; + +// system-dependent stuff +import sun.awt.*; + + +public class BezierPolyPolygon + extends com.sun.star.lib.uno.helper.ComponentBase + implements com.sun.star.lang.XServiceInfo, + drafts.com.sun.star.rendering.XBezierPolyPolygon2D +{ + private java.awt.geom.GeneralPath path; + + //---------------------------------------------------------------------------------- + + public BezierPolyPolygon( RealBezierSegment2D[][] points ) + { + setPoints( points, 0, 0 ); + } + + public java.awt.geom.GeneralPath getJavaPath() + { + return path; + } + + //---------------------------------------------------------------------------------- + + // + // XPolyPolygon implementation + // =========================== + // + public void addPolyPolygon( RealPoint2D position, XPolyPolygon2D polyPolygon ) + { + } + + public int getNumberOfPolygons( ) + { + return 0; + } + + public int getNumberOfPolygonPoints( int polygon ) + { + return 0; + } + + public FillRule getFillRule( ) + { + if( path.getWindingRule() == java.awt.geom.GeneralPath.WIND_EVEN_ODD ) + return FillRule.EVEN_ODD; + else + return FillRule.NON_ZERO; + } + + public void setFillRule( FillRule fillRule ) + { + if( fillRule == FillRule.EVEN_ODD ) + path.setWindingRule( java.awt.geom.GeneralPath.WIND_EVEN_ODD ); + else + path.setWindingRule( java.awt.geom.GeneralPath.WIND_NON_ZERO ); + } + + public boolean isClosed( int index ) + { + // TODO + return false; + } + + public void setClosed( int index, boolean closedState ) + { + // TODO + } + + //---------------------------------------------------------------------------------- + + // + // XBezierPolyPolygon implementation + // ================================= + // + public RealBezierSegment2D[][] getPoints( int nPolygonIndex, int nNumberOfPolygons, int nPointIndex, int nNumberOfPoints ) + { + return null; + } + + public void setPoints( RealBezierSegment2D[][] points, int nPolygonIndex, int nPointIndex ) + { + if( nPolygonIndex != 0 || nPointIndex != 0 ) + CanvasUtils.printLog( "LinePolyPolygon.setPoints: subset not yet implemented!" ); + + path = CanvasUtils.makeGenPathFromBezierPoints( points ); + } + + public RealBezierSegment2D getPoint( int nPolygonIndex, int nPointIndex ) + { + return null; + } + + public void setPoint( RealBezierSegment2D point, int nPolygonIndex, int nPointIndex ) + { + CanvasUtils.printLog( "LinePolyPolygon.setPoint: not yet implemented!" ); + } + + //---------------------------------------------------------------------------------- + + // + // XServiceInfo impl + // ================= + // + + private static final String s_implName = "XBezierPolyPolygon2D.java.impl"; + private static final String s_serviceName = "drafts.com.sun.star.rendering.BezierPolyPolygon2D"; + + public String getImplementationName() + { + return s_implName; + } + + public String [] getSupportedServiceNames() + { + return new String [] { s_serviceName }; + } + + public boolean supportsService( String serviceName ) + { + return serviceName.equals( s_serviceName ); + } +} diff --git a/canvas/source/java/BitmapCanvas.java b/canvas/source/java/BitmapCanvas.java new file mode 100644 index 000000000000..8238ece71057 --- /dev/null +++ b/canvas/source/java/BitmapCanvas.java @@ -0,0 +1,170 @@ +/************************************************************************* + * + * $RCSfile: BitmapCanvas.java,v $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +// UNO +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.IQueryInterface; +import com.sun.star.lang.XInitialization; +import com.sun.star.lib.uno.helper.WeakBase; + +// OOo AWT +import com.sun.star.awt.*; + +// Canvas +import drafts.com.sun.star.rendering.*; +import drafts.com.sun.star.geometry.*; + +// Java AWT +import java.awt.*; +import java.awt.image.*; +import java.awt.geom.*; + +// system-dependent stuff +import sun.awt.*; + + +public class BitmapCanvas + extends CanvasBase + implements drafts.com.sun.star.rendering.XBitmapCanvas, + com.sun.star.lang.XServiceInfo +{ + private Graphics2D graphics; + + public Graphics2D getGraphics() + { + return graphics; + } + + //---------------------------------------------------------------------------------- + + public BitmapCanvas( Graphics2D _graphics ) + { + graphics = _graphics; + } + + //---------------------------------------------------------------------------------- + + // + // XBitmapCanvas impl + // ================== + // + + public synchronized void copyRect( drafts.com.sun.star.rendering.XBitmapCanvas sourceCanvas, + drafts.com.sun.star.geometry.RealRectangle2D sourceRect, + drafts.com.sun.star.rendering.ViewState sourceViewState, + drafts.com.sun.star.rendering.RenderState sourceRenderState, + drafts.com.sun.star.geometry.RealRectangle2D destRect, + drafts.com.sun.star.rendering.ViewState destViewState, + drafts.com.sun.star.rendering.RenderState destRenderState ) + { + // TODO: create temp image when transform is non-trivial + + if( sourceCanvas == this ) + { + // copy rectangle within the canvas + graphics.copyArea((int)sourceRect.X1, + (int)sourceRect.Y1, + (int)(sourceRect.X2 - sourceRect.X1), + (int)(sourceRect.Y2 - sourceRect.Y1), + (int)(destRect.X1 - sourceRect.X1), + (int)(destRect.Y1 - sourceRect.Y1) ); + } + else + { + if( sourceCanvas instanceof JavaCanvas ) + { + // cache + CanvasUtils.setupGraphicsState( graphics, destViewState, destRenderState, CanvasUtils.alsoSetupPaint ); + + // TODO: really extract correct source rect here + BufferedImage backBuffer = ((BufferedGraphics2D)((JavaCanvas)sourceCanvas).getGraphics()).getBackBuffer(); + graphics.drawImage( backBuffer, 0, 0, null ); + CanvasUtils.postRenderImageTreatment( backBuffer ); + + } + // TODO: foreign canvas + } + } + + //---------------------------------------------------------------------------------- + + private static final String s_implName = "XBitmapCanvas.java.impl"; + private static final String s_serviceName = "drafts.com.sun.star.rendering.BitmapCanvas"; + + //---------------------------------------------------------------------------------- + + // + // XServiceInfo impl + // ================= + // + public String getImplementationName() + { + return s_implName; + } + + public String [] getSupportedServiceNames() + { + return new String [] { s_serviceName }; + } + + public boolean supportsService( String serviceName ) + { + return serviceName.equals( s_serviceName ); + } +} diff --git a/canvas/source/java/BufferedGraphics2D.java b/canvas/source/java/BufferedGraphics2D.java new file mode 100644 index 000000000000..53c89990b11e --- /dev/null +++ b/canvas/source/java/BufferedGraphics2D.java @@ -0,0 +1,630 @@ +/************************************************************************* + * + * $RCSfile: BufferedGraphics2D.java,v $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +0 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +// Java AWT +import java.awt.*; +import java.awt.geom.*; +import java.awt.image.*; +import java.awt.image.renderable.*; +import java.awt.font.*; +import java.text.*; +import java.util.*; + + +public class BufferedGraphics2D + extends java.awt.Graphics2D +{ + // TODO: Somehow, get rid of this duplicate graphics (the graphics member, + // and this object itself, extending a Graphics2D) + private Graphics2D graphics; + private BufferedImage backBuffer; + private Graphics2D backBufferGraphics; + + //---------------------------------------------------------------------------------- + + public BufferedGraphics2D( java.awt.Graphics2D _graphics, int width, int height ) + { + setGraphics( _graphics, Math.max(1,width), Math.max(1,height) ); + } + + public void redraw( Graphics2D graph ) + { + if( graph != null && + backBuffer != null ) + { + CanvasUtils.printLog("BufferedGraphics2D.redraw: using buffer of size (" + + backBuffer.getWidth() + "," + backBuffer.getHeight() + ")" ); + + // set transform to identity + graph.setTransform( new AffineTransform() ); + graph.drawImage(backBuffer, 0, 0, null); + CanvasUtils.postRenderImageTreatment( backBuffer ); + } + } + + public BufferedImage getBackBuffer() + { + return backBuffer; + } + + public void setSize( int width, int height ) + { + if( backBuffer != null && + width == backBuffer.getWidth() && + height == backBuffer.getHeight() ) + { + return; + } + + if( backBufferGraphics != null ) + backBufferGraphics.dispose(); + + if( backBuffer != null ) + backBuffer.flush(); + + // TODO: Maybe VolatileImage with another BufferedImage as a backup is + // a tad faster here. + backBuffer = graphics.getDeviceConfiguration().createCompatibleImage(width, + height); + + backBufferGraphics = backBuffer.createGraphics(); + CanvasUtils.initGraphics( backBufferGraphics ); + + // clear the buffer to white (to have a defined state here) + backBufferGraphics.setColor( java.awt.Color.white ); + backBufferGraphics.fillRect( 0,0,width,height ); + } + + public void setGraphics( Graphics2D _graphics, int width, int height ) + { + if( graphics != null ) + graphics.dispose(); + + graphics = _graphics; + + setSize(width,height); + } + + //---------------------------------------------------------------------------------- + + // + // Graphics + // ======== + // + public void clearRect(int x, int y, int width, int height) + { + graphics.clearRect(x,y,width,height); + backBufferGraphics.clearRect(x,y,width,height); + } + + public void clipRect(int x, int y, int width, int height) + { + graphics.clipRect(x,y,width,height); + backBufferGraphics.clipRect(x,y,width,height); + } + + public void copyArea(int x, int y, int width, int height, int dx, int dy) + { + graphics.copyArea(x,y,width,height,dx,dy); + backBufferGraphics.copyArea(x,y,width,height,dx,dy); + } + + public Graphics create() + { + return null; + } + + public Graphics create(int x, int y, int width, int height) + { + return null; + } + + public void dispose() + { + graphics.dispose(); + backBufferGraphics.dispose(); + backBuffer.flush(); + } + + public void draw3DRect(int x, int y, int width, int height, boolean raised) + { + graphics.draw3DRect(x,y,width,height,raised); + backBufferGraphics.draw3DRect(x,y,width,height,raised); + } + + public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) + { + graphics.drawArc(x,y,width,height,startAngle,arcAngle); + backBufferGraphics.drawArc(x,y,width,height,startAngle,arcAngle); + } + + public void drawBytes(byte[] data, int offset, int length, int x, int y) + { + graphics.drawBytes(data,offset,length,x,y); + backBufferGraphics.drawBytes(data,offset,length,x,y); + } + + public void drawChars(char[] data, int offset, int length, int x, int y) + { + graphics.drawChars(data,offset,length,x,y); + backBufferGraphics.drawChars(data,offset,length,x,y); + } + + public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) + { + backBufferGraphics.drawImage(img,x,y,bgcolor,observer); + return graphics.drawImage(img,x,y,bgcolor,observer); + } + + public boolean drawImage(Image img, int x, int y, ImageObserver observer) + { + backBufferGraphics.drawImage(img,x,y,observer); + return graphics.drawImage(img,x,y,observer); + } + + public boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer) + { + backBufferGraphics.drawImage(img,x,y,width,height,bgcolor,observer); + return graphics.drawImage(img,x,y,width,height,bgcolor,observer); + } + + public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer) + { + backBufferGraphics.drawImage(img,x,y,width,height,observer); + return graphics.drawImage(img,x,y,width,height,observer); + } + + public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer) + { + backBufferGraphics.drawImage(img,dx1,dy1,dx2,dy2,sx1,sy1,sx2,sy2,bgcolor,observer); + return graphics.drawImage(img,dx1,dy1,dx2,dy2,sx1,sy1,sx2,sy2,bgcolor,observer); + } + + public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) + { + backBufferGraphics.drawImage(img,dx1,dy1,dx2,dy2,sx1,sy1,sx2,sy2,observer); + return graphics.drawImage(img,dx1,dy1,dx2,dy2,sx1,sy1,sx2,sy2,observer); + } + + public void drawLine(int x1, int y1, int x2, int y2) + { + graphics.drawLine(x1,y1,x2,y2); + backBufferGraphics.drawLine(x1,y1,x2,y2); + } + + public void drawOval(int x, int y, int width, int height) + { + graphics.drawOval(x,y,width,height); + backBufferGraphics.drawOval(x,y,width,height); + } + + public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints) + { + graphics.drawPolygon(xPoints,yPoints,nPoints); + backBufferGraphics.drawPolygon(xPoints,yPoints,nPoints); + } + + public void drawPolygon(Polygon p) + { + graphics.drawPolygon(p); + backBufferGraphics.drawPolygon(p); + } + + public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) + { + graphics.drawPolyline(xPoints,yPoints,nPoints); + backBufferGraphics.drawPolyline(xPoints,yPoints,nPoints); + } + + public void drawRect(int x, int y, int width, int height) + { + graphics.drawRect(x,y,width,height); + backBufferGraphics.drawRect(x,y,width,height); + } + + public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) + { + graphics.drawRoundRect(x,y,width,height,arcWidth,arcHeight); + backBufferGraphics.drawRoundRect(x,y,width,height,arcWidth,arcHeight); + } + + public void drawString(AttributedCharacterIterator iterator, int x, int y) + { + graphics.drawString(iterator,x,y); + backBufferGraphics.drawString(iterator,x,y); + } + + public void drawString(String str, int x, int y) + { + graphics.drawString(str,x,y); + backBufferGraphics.drawString(str,x,y); + } + + public void fill3DRect(int x, int y, int width, int height, boolean raised) + { + graphics.fill3DRect(x,y,width,height,raised); + backBufferGraphics.fill3DRect(x,y,width,height,raised); + } + + public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) + { + graphics.fillArc(x,y,width,height,startAngle,arcAngle); + backBufferGraphics.fillArc(x,y,width,height,startAngle,arcAngle); + } + + public void fillOval(int x, int y, int width, int height) + { + graphics.fillOval(x,y,width,height); + backBufferGraphics.fillOval(x,y,width,height); + } + + public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints) + { + graphics.fillPolygon(xPoints,yPoints,nPoints); + backBufferGraphics.fillPolygon(xPoints,yPoints,nPoints); + } + + public void fillPolygon(Polygon p) + { + graphics.fillPolygon(p); + backBufferGraphics.fillPolygon(p); + } + + public void fillRect(int x, int y, int width, int height) + { + graphics.fillRect(x,y,width,height); + backBufferGraphics.fillRect(x,y,width,height); + } + + public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) + { + graphics.fillRoundRect(x,y,width,height,arcWidth,arcHeight); + backBufferGraphics.fillRoundRect(x,y,width,height,arcWidth,arcHeight); + } + + public Shape getClip() + { + return graphics.getClip(); + } + + public Rectangle getClipBounds() + { + return graphics.getClipBounds(); + } + + public Rectangle getClipBounds(Rectangle r) + { + return graphics.getClipBounds(r); + } + + public Rectangle getClipRect() + { + return graphics.getClipRect(); + } + + public Color getColor() + { + return getColor(); + } + + public Font getFont() + { + return getFont(); + } + + public FontMetrics getFontMetrics() + { + return getFontMetrics(); + } + + public FontMetrics getFontMetrics(Font f) + { + return getFontMetrics(f); + } + + public boolean hitClip(int x, int y, int width, int height) + { + return graphics.hitClip(x,y,width,height); + } + + public void setClip(int x, int y, int width, int height) + { + graphics.setClip(x,y,width,height); + backBufferGraphics.setClip(x,y,width,height); + } + + public void setClip(Shape clip) + { + graphics.setClip(clip); + backBufferGraphics.setClip(clip); + } + + public void setColor(Color c) + { + graphics.setColor(c); + backBufferGraphics.setColor(c); + } + + public void setFont(Font font) + { + graphics.setFont(font); + backBufferGraphics.setFont(font); + } + + public void setPaintMode() + { + graphics.setPaintMode(); + backBufferGraphics.setPaintMode(); + } + + public void setXORMode(Color c1) + { + graphics.setXORMode(c1); + backBufferGraphics.setXORMode(c1); + } + + public String toString() + { + return graphics.toString(); + } + + public void translate(int x, int y) + { + graphics.translate(x,y); + backBufferGraphics.translate(x,y); + } + + //---------------------------------------------------------------------------------- + + // + // Graphics2D + // ========== + // + public void addRenderingHints(Map hints) + { + graphics.addRenderingHints(hints); + backBufferGraphics.addRenderingHints(hints); + } + + public void clip(Shape s) + { + graphics.clip(s); + backBufferGraphics.clip(s); + } + + public void draw(Shape s) + { + graphics.draw(s); + backBufferGraphics.draw(s); + } + + public void drawGlyphVector(GlyphVector g, float x, float y) + { + graphics.drawGlyphVector(g,x,y); + backBufferGraphics.drawGlyphVector(g,x,y); + } + + public void drawImage(BufferedImage img, BufferedImageOp op, int x, int y) + { + graphics.drawImage(img,op,x,y); + backBufferGraphics.drawImage(img,op,x,y); + } + + public boolean drawImage(Image img, AffineTransform xform, ImageObserver obs) + { + backBufferGraphics.drawImage(img,xform,obs); + return graphics.drawImage(img,xform,obs); + } + + public void drawRenderableImage(RenderableImage img, AffineTransform xform) + { + graphics.drawRenderableImage(img,xform); + backBufferGraphics.drawRenderableImage(img,xform); + } + + public void drawRenderedImage(RenderedImage img, AffineTransform xform) + { + graphics.drawRenderedImage(img,xform); + backBufferGraphics.drawRenderedImage(img,xform); + } + + public void drawString(AttributedCharacterIterator iterator, float x, float y) + { + graphics.drawString(iterator,x,y); + backBufferGraphics.drawString(iterator,x,y); + } + + public void drawString(String s, float x, float y) + { + graphics.drawString(s,x,y); + backBufferGraphics.drawString(s,x,y); + } + + public void fill(Shape s) + { + graphics.fill(s); + backBufferGraphics.fill(s); + } + + public Color getBackground() + { + return graphics.getBackground(); + } + + public Composite getComposite() + { + return graphics.getComposite(); + } + + public GraphicsConfiguration getDeviceConfiguration() + { + return graphics.getDeviceConfiguration(); + } + + public FontRenderContext getFontRenderContext() + { + return graphics.getFontRenderContext(); + } + + public Paint getPaint() + { + return graphics.getPaint(); + } + + public Object getRenderingHint(RenderingHints.Key hintKey) + { + return graphics.getRenderingHint(hintKey); + } + + public RenderingHints getRenderingHints() + { + return graphics.getRenderingHints(); + } + + public Stroke getStroke() + { + return graphics.getStroke(); + } + + public AffineTransform getTransform() + { + return graphics.getTransform(); + } + + public boolean hit(Rectangle rect, Shape s, boolean onStroke) + { + return graphics.hit(rect,s,onStroke); + } + + public void rotate(double theta) + { + graphics.rotate(theta); + backBufferGraphics.rotate(theta); + } + + public void rotate(double theta, double x, double y) + { + graphics.rotate(theta,x,y); + backBufferGraphics.rotate(theta,x,y); + } + + public void scale(double sx, double sy) + { + graphics.scale(sx,sy); + backBufferGraphics.scale(sx,sy); + } + + public void setBackground(Color color) + { + graphics.setBackground(color); + backBufferGraphics.setBackground(color); + } + + public void setComposite(Composite comp) + { + graphics.setComposite(comp); + backBufferGraphics.setComposite(comp); + } + + public void setPaint(Paint paint) + { + graphics.setPaint(paint); + backBufferGraphics.setPaint(paint); + } + + public void setRenderingHint(RenderingHints.Key hintKey, Object hintValue) + { + graphics.setRenderingHint(hintKey,hintValue); + backBufferGraphics.setRenderingHint(hintKey,hintValue); + } + + public void setRenderingHints(Map hints) + { + graphics.setRenderingHints(hints); + backBufferGraphics.setRenderingHints(hints); + } + + public void setStroke(Stroke s) + { + graphics.setStroke(s); + backBufferGraphics.setStroke(s); + } + + public void setTransform(AffineTransform Tx) + { + graphics.setTransform(Tx); + backBufferGraphics.setTransform(Tx); + } + + public void shear(double shx, double shy) + { + graphics.shear(shx,shy); + backBufferGraphics.shear(shx,shy); + } + + public void transform(AffineTransform Tx) + { + graphics.transform(Tx); + backBufferGraphics.transform(Tx); + } + + public void translate(double tx, double ty) + { + graphics.translate(tx,ty); + backBufferGraphics.translate(tx,ty); + } +} diff --git a/canvas/source/java/CanvasBase.java b/canvas/source/java/CanvasBase.java new file mode 100644 index 000000000000..b57430d5b329 --- /dev/null +++ b/canvas/source/java/CanvasBase.java @@ -0,0 +1,379 @@ +/************************************************************************* + * + * $RCSfile: CanvasBase.java,v $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +// UNO +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.IQueryInterface; +import com.sun.star.lang.XInitialization; +import com.sun.star.lib.uno.helper.WeakBase; + +// OOo AWT +import com.sun.star.awt.*; + +// Canvas +import drafts.com.sun.star.rendering.*; +import drafts.com.sun.star.geometry.*; + +// Java AWT +import java.awt.*; +import java.awt.geom.*; + +// system-dependent stuff +import sun.awt.*; + + +public abstract class CanvasBase + extends com.sun.star.lib.uno.helper.ComponentBase + implements drafts.com.sun.star.rendering.XCanvas +{ + // to be overridden + public abstract Graphics2D getGraphics(); + + //---------------------------------------------------------------------------------- + + // + // XCanvas interface + // ================= + // + public synchronized void drawPoint( RealPoint2D aPoint, + ViewState viewState, + RenderState renderState ) throws com.sun.star.lang.IllegalArgumentException + { + // cache + Graphics2D graphics = getGraphics(); + + // initialize the Graphics2D + CanvasUtils.setupGraphicsState( graphics, viewState, renderState, CanvasUtils.alsoSetupPaint ); + + // calculate the domain value for a single device pixel. we're + // using delta mapping here, to avoid later subtraction of two + // mapped values (as we really only need a transformed size, + // not a transformed point). + AffineTransform transform = graphics.getTransform(); + AffineTransform inverse; + try + { + inverse = transform.createInverse(); + } + catch( NoninvertibleTransformException e ) + { + // transformation not invertible. Nothing to render then. + return; + } + + java.awt.geom.Point2D.Double pointSize = new java.awt.geom.Point2D.Double(1.0,1.0); + java.awt.geom.Point2D.Double domainPointSize = new java.awt.geom.Point2D.Double(); + inverse.deltaTransform( pointSize, domainPointSize ); + + // render a circle one device pixel wide + Ellipse2D.Double ellipse = new Ellipse2D.Double(aPoint.X, aPoint.Y, domainPointSize.x, domainPointSize.y); + + // render, at last + graphics.fill( ellipse ); + + CanvasUtils.printLog( "XCanvas: drawPoint called" ); + } + + public synchronized void drawLine( RealPoint2D aStartPoint, + RealPoint2D aEndPoint, + ViewState viewState, + RenderState renderState ) throws com.sun.star.lang.IllegalArgumentException + { + // cache + Graphics2D graphics = getGraphics(); + + // initialize the Graphics2D + CanvasUtils.setupGraphicsState( graphics, viewState, renderState, CanvasUtils.alsoSetupPaint ); + graphics.setStroke( new BasicStroke() ); + + // setup line object + Line2D.Double line = new Line2D.Double(aStartPoint.X, aStartPoint.Y, aEndPoint.X, aEndPoint.Y); + + // render, at last + graphics.draw( line ); + + CanvasUtils.printLog( "XCanvas: drawLine called" ); + } + + public synchronized void drawBezier( RealBezierSegment2D aBezierSegment, + RealPoint2D aEndPoint, + ViewState viewState, + RenderState renderState ) throws com.sun.star.lang.IllegalArgumentException + { + // cache + Graphics2D graphics = getGraphics(); + + // initialize the Graphics2D + CanvasUtils.setupGraphicsState( graphics, viewState, renderState, CanvasUtils.alsoSetupPaint ); + graphics.setStroke( new BasicStroke() ); + + // setup bezier object + CubicCurve2D.Double curve = new CubicCurve2D.Double(aBezierSegment.Px, aBezierSegment.Py, + aBezierSegment.C1x, aBezierSegment.C1y, + aBezierSegment.C2x, aBezierSegment.C2y, + aEndPoint.X, aEndPoint.Y); + + // render, at last + graphics.draw( curve ); + + CanvasUtils.printLog( "XCanvas: drawbezier called" ); + } + + public synchronized XCachedPrimitive drawPolyPolygon( XPolyPolygon2D xPolyPolygon, + ViewState viewState, + RenderState renderState ) throws com.sun.star.lang.IllegalArgumentException + { + CanvasUtils.printLog( "CanvasBase.drawPolyPolygon() called" ); + + // cache + Graphics2D graphics = getGraphics(); + + // initialize the Graphics2D + CanvasUtils.setupGraphicsState( graphics, viewState, renderState, CanvasUtils.alsoSetupPaint ); + graphics.setStroke( new BasicStroke() ); + + // render the polygon + // TODO: maybe use Graphics.drawPolyline here! + graphics.draw( CanvasUtils.makeGeneralPath(xPolyPolygon) ); + + CanvasUtils.printLog( "XCanvas: drawPolyPolygon called" ); + + return null; + } + + public synchronized XCachedPrimitive strokePolyPolygon( XPolyPolygon2D xPolyPolygon, + ViewState viewState, + RenderState renderState, + StrokeAttributes strokeAttributes ) throws com.sun.star.lang.IllegalArgumentException + { + // cache + Graphics2D graphics = getGraphics(); + + // initialize the Graphics2D + CanvasUtils.setupGraphicsState( graphics, viewState, renderState, CanvasUtils.alsoSetupPaint ); + CanvasUtils.applyStrokeAttributes( graphics, strokeAttributes ); + + // stroke the polygon + graphics.draw( CanvasUtils.makeGeneralPath(xPolyPolygon) ); + + CanvasUtils.printLog( "XCanvas: strokePolyPolygon called" ); + + return null; + } + + public synchronized XCachedPrimitive strokeTexturedPolyPolygon( XPolyPolygon2D xPolyPolygon, + ViewState viewState, + RenderState renderState, + Texture[] textures, + StrokeAttributes strokeAttributes ) throws com.sun.star.lang.IllegalArgumentException, VolatileContentDestroyedException + { + return null; + } + + public synchronized XCachedPrimitive strokeTextureMappedPolyPolygon( XPolyPolygon2D xPolyPolygon, + ViewState viewState, + RenderState renderState, + Texture[] textures, + drafts.com.sun.star.geometry.XMapping2D xMapping, + StrokeAttributes strokeAttributes ) throws com.sun.star.lang.IllegalArgumentException, VolatileContentDestroyedException + { + return null; + } + + public synchronized XPolyPolygon2D queryStrokeShapes( drafts.com.sun.star.rendering.XPolyPolygon2D xPolyPolygon, + drafts.com.sun.star.rendering.ViewState viewState, + drafts.com.sun.star.rendering.RenderState renderState, + drafts.com.sun.star.rendering.StrokeAttributes strokeAttributes ) throws com.sun.star.lang.IllegalArgumentException + { + return null; + } + + public synchronized XCachedPrimitive fillPolyPolygon( drafts.com.sun.star.rendering.XPolyPolygon2D xPolyPolygon, + drafts.com.sun.star.rendering.ViewState viewState, + drafts.com.sun.star.rendering.RenderState renderState ) throws com.sun.star.lang.IllegalArgumentException + { + CanvasUtils.printLog( "CanvasBase.fillPolyPolygon() called" ); + + // cache + Graphics2D graphics = getGraphics(); + + // initialize the Graphics2D + CanvasUtils.setupGraphicsState( graphics, viewState, renderState, CanvasUtils.alsoSetupPaint ); + + // fill the polygon + graphics.fill( CanvasUtils.makeGeneralPath(xPolyPolygon) ); + + CanvasUtils.printLog( "XCanvas: fillPolyPolygon called" ); + + return null; + } + + public synchronized XCachedPrimitive fillTexturedPolyPolygon( drafts.com.sun.star.rendering.XPolyPolygon2D xPolyPolygon, + drafts.com.sun.star.rendering.ViewState viewState, + drafts.com.sun.star.rendering.RenderState renderState, + drafts.com.sun.star.rendering.Texture [] textures ) throws com.sun.star.lang.IllegalArgumentException + { + return null; + } + + public synchronized XCachedPrimitive fillTextureMappedPolyPolygon( XPolyPolygon2D xPolyPolygon, + ViewState viewState, + RenderState renderState, + Texture[] textures, + drafts.com.sun.star.geometry.XMapping2D xMapping ) throws com.sun.star.lang.IllegalArgumentException, VolatileContentDestroyedException + { + return null; + } + + public synchronized XCanvasFont queryFont( drafts.com.sun.star.rendering.FontRequest fontRequest ) throws com.sun.star.lang.IllegalArgumentException + { + return new CanvasFont( fontRequest, this ); + } + + public synchronized XCachedPrimitive drawText( drafts.com.sun.star.rendering.StringContext text, + drafts.com.sun.star.rendering.XCanvasFont xFont, + drafts.com.sun.star.rendering.ViewState viewState, + drafts.com.sun.star.rendering.RenderState renderState, + byte textDirection ) throws com.sun.star.lang.IllegalArgumentException + { + CanvasUtils.printLog( "CanvasBase.drawText() called" ); + + // cache + Graphics2D graphics = getGraphics(); + + CanvasUtils.printLog( "XCanvas: drawText called" ); + + CanvasUtils.setupGraphicsState( graphics, viewState, renderState, CanvasUtils.alsoSetupPaint ); + CanvasUtils.setupGraphicsFont( graphics, viewState, renderState, xFont ); + + CanvasUtils.printLog( "XCanvas: drawText rendering \""+ text.Text.substring(text.StartPosition, text.StartPosition+text.Length) + "\"" ); + + graphics.drawString( text.Text.substring(text.StartPosition, text.StartPosition+text.Length), (float)0.0, (float)0.0 ); + return null; + } + + public synchronized XCachedPrimitive drawOffsettedText( drafts.com.sun.star.rendering.StringContext text, + drafts.com.sun.star.rendering.XCanvasFont xFont, + double [] offsets, + drafts.com.sun.star.rendering.ViewState viewState, + drafts.com.sun.star.rendering.RenderState renderState, + byte textDirection ) throws com.sun.star.lang.IllegalArgumentException + { + CanvasUtils.printLog( "CanvasBase.drawOffsettedText() called" ); + + CanvasUtils.preCondition( text.Length == text.Text.length() && + text.Length == offsets.length, "CanvasBase.drawOffsettedText" ); + + if( text.Length > 0 ) + { + // cache + Graphics2D graphics = getGraphics(); + + CanvasUtils.printLog( "XCanvas: drawOffsettedText called" ); + + CanvasUtils.setupGraphicsState( graphics, viewState, renderState, CanvasUtils.alsoSetupPaint ); + CanvasUtils.setupGraphicsFont( graphics, viewState, renderState, xFont ); + + CanvasUtils.printLog( "XCanvas: drawOffsettedText canvas setup done" ); + + // TODO: use proper advancement. Text direction need not be horizontal! + // TODO: given text string need not have a one-to-one relationship between code point and glyph (offset)! + graphics.drawString( text.Text.substring(text.StartPosition, text.StartPosition + 1), (float)0.0, (float)0.0 ); + for( int i=1; i<offsets.length && i<text.Length; ++i ) + { + CanvasUtils.printLog( "XCanvas: drawOffsettedText rendering a \"" + + text.Text.substring(text.StartPosition + i, + text.StartPosition + i + 1) + + "\" (position " + (text.StartPosition + i) + + " of " + text.Text + ", offset " + offsets[i] + ")" ); + + graphics.drawString( text.Text.substring(text.StartPosition + i, text.StartPosition + i + 1), (float)offsets[i-1], (float)0.0 ); + } + } + + return null; + } + + public synchronized XCachedPrimitive drawBitmap( drafts.com.sun.star.rendering.XBitmap xBitmap, + drafts.com.sun.star.rendering.ViewState viewState, + drafts.com.sun.star.rendering.RenderState renderState ) throws com.sun.star.lang.IllegalArgumentException + { + CanvasUtils.printLog( "CanvasBase.drawBitmap() called" ); + + // cache + Graphics2D graphics = getGraphics(); + + CanvasUtils.setupGraphicsState( graphics, viewState, renderState, CanvasUtils.alsoSetupPaint ); + + java.awt.image.BufferedImage bitmap = CanvasUtils.getBufferedImage( xBitmap ); + + if( !graphics.drawImage(bitmap, 0, 0, null) ) + CanvasUtils.printLog( "CanvasBase.drawBitmap: image paint incomplete" ); + + CanvasUtils.postRenderImageTreatment( bitmap ); + + return null; + } + + public synchronized XGraphicDevice getDevice() + { + CanvasUtils.printLog( "CanvasBase.getDevice() called" ); + return new CanvasGraphicDevice( getGraphics() ); + } +} diff --git a/canvas/source/java/CanvasBitmap.java b/canvas/source/java/CanvasBitmap.java new file mode 100644 index 000000000000..5fe7b0257189 --- /dev/null +++ b/canvas/source/java/CanvasBitmap.java @@ -0,0 +1,238 @@ +/************************************************************************* + * + * $RCSfile: CanvasBitmap.java,v $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +// UNO +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.AnyConverter; +import com.sun.star.lib.uno.helper.WeakBase; + +// OOo AWT +import com.sun.star.awt.*; + +// Canvas +import drafts.com.sun.star.rendering.*; +import drafts.com.sun.star.geometry.*; + +public class CanvasBitmap + extends com.sun.star.lib.uno.helper.ComponentBase + implements com.sun.star.lang.XServiceInfo, + drafts.com.sun.star.rendering.XIntegerBitmap +{ + private java.awt.image.BufferedImage bitmap; + + public CanvasBitmap( java.awt.image.BufferedImage _bitmap ) + { + bitmap = _bitmap; + } + + public CanvasBitmap( IntegerSize2D mySize ) + { + bitmap = new java.awt.image.BufferedImage(mySize.Width, mySize.Height, + java.awt.image.BufferedImage.TYPE_4BYTE_ABGR); + } + + public CanvasBitmap( RealSize2D newSize, boolean beFast, CanvasBitmap source ) + { +// java.awt.geom.AffineTransform transform = new java.awt.geom.AffineTransform(); +// transform.scale( newSize.width/size.Width, newSize.height/size.Height ); + +// // TODO: Maybe keep the image returned via +// // bitmap.getScaledInstance, and do scaling lazy. +// bitmap = new java.awt.image.BufferedImage((int)(newSize.width+.5), +// (int)(newSize.height+.5), +// java.awt.image.BufferedImage.TYPE_4BYTE_ABGR); + +// java.awt.image.AffineTransformOp transformer = +// new java.awt.image.AffineTransformOp( transform, +// java.awt.image.AffineTransformOp.TYPE_BILINEAR); + +// transformer.filter(source.getBufferedImage(), bitmap); + } + + public synchronized java.awt.image.BufferedImage getBufferedImage() + { + return bitmap; + } + + // + // XBitmap implementation + // ====================== + // + + public synchronized IntegerSize2D getSize() + { + return new IntegerSize2D( bitmap.getWidth(), + bitmap.getHeight() ); + } + + //---------------------------------------------------------------------------------- + + public synchronized XBitmapCanvas queryBitmapCanvas() + { + java.awt.Graphics2D bitmapGraphics = bitmap.createGraphics(); + CanvasUtils.initGraphics( bitmapGraphics ); + + return new BitmapCanvas( bitmapGraphics ); + } + + //---------------------------------------------------------------------------------- + + public synchronized drafts.com.sun.star.rendering.XBitmap getScaledBitmap( RealSize2D newSize, boolean beFast ) throws com.sun.star.lang.IllegalArgumentException, VolatileContentDestroyedException + { + return new CanvasBitmap( newSize, beFast, this ); + } + + //---------------------------------------------------------------------------------- + + // + // XIntegerBitmap implementation + // ============================= + // + + public synchronized byte[] getData( IntegerRectangle2D rect ) + { + int [] pixelData = bitmap.getRGB( rect.X1, rect.Y1, rect.X2 - rect.X1, rect.Y1 - rect.Y2, null, 0, 0 ); + + return CanvasUtils.int2byte( pixelData ); + } + + //---------------------------------------------------------------------------------- + + public synchronized void setData( byte[] data, IntegerRectangle2D rect ) + { + int [] pixelData = CanvasUtils.byte2int( data ); + bitmap.setRGB( rect.X1, rect.Y1, rect.X2 - rect.X1, rect.Y2 - rect.Y1, pixelData, 0, bitmap.getWidth() ); + } + + //---------------------------------------------------------------------------------- + + public synchronized void setPixel( byte[] color, IntegerPoint2D pos ) + { + if( color.length != 4 ) + CanvasUtils.printLog( "CanvasBitmap.setPixel: Wrong color format" ); + + int pixel = color[0] + (color[1] + (color[2] + color[3]*256)*256)*256; + bitmap.setRGB( pos.X, pos.Y, pixel ); + } + + //---------------------------------------------------------------------------------- + + public synchronized byte[] getPixel( IntegerPoint2D pos ) + { + int pixel = bitmap.getRGB( pos.X, pos.Y ); + + byte[] res = new byte[4]; + res[0] = (byte)(pixel & 255); + res[1] = (byte)((pixel/256) & 255); + res[2] = (byte)((pixel/256/256) & 255); + res[3] = (byte)((pixel/256/256/256) & 255); + + return res; + } + + //---------------------------------------------------------------------------------- + + public synchronized XBitmapPalette getPalette() + { + return null; + } + + //---------------------------------------------------------------------------------- + + public synchronized IntegerBitmapLayout getMemoryLayout() + { + // TODO: finish that one + IntegerBitmapLayout layout = new IntegerBitmapLayout(); + + layout.ScanLines = bitmap.getWidth(); + layout.ScanLineBytes = bitmap.getWidth()*4; + layout.ScanLineStride = layout.ScanLineBytes; + layout.Format = 0; + layout.NumComponents = 4; + layout.ComponentMasks = null; + layout.Endianness = 0; + layout.IsPseudoColor = false; + + return layout; + } + + //---------------------------------------------------------------------------------- + + // + // XServiceInfo impl + // ================= + // + + private static final String s_implName = "XIntegerBitmap.java.impl"; + private static final String s_serviceName = "drafts.com.sun.star.rendering.IntegerBitmap"; + + public String getImplementationName() + { + return s_implName; + } + + public String [] getSupportedServiceNames() + { + return new String [] { s_serviceName }; + } + + public boolean supportsService( String serviceName ) + { + return serviceName.equals( s_serviceName ); + } +} diff --git a/canvas/source/java/CanvasClonedSprite.java b/canvas/source/java/CanvasClonedSprite.java new file mode 100644 index 000000000000..ac7cdfc4a796 --- /dev/null +++ b/canvas/source/java/CanvasClonedSprite.java @@ -0,0 +1,228 @@ +/************************************************************************* + * + * $RCSfile: CanvasClonedSprite.java,v $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +// UNO +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.IQueryInterface; +import com.sun.star.lang.XInitialization; +import com.sun.star.lib.uno.helper.WeakBase; + +// OOo AWT +import com.sun.star.awt.*; + +// Canvas +import drafts.com.sun.star.rendering.*; +import drafts.com.sun.star.geometry.*; + +// Java AWT +import java.awt.*; +import java.awt.geom.*; + +// system-dependent stuff +import sun.awt.*; + + +public class CanvasClonedSprite + extends com.sun.star.lib.uno.helper.ComponentBase + implements drafts.com.sun.star.rendering.XSprite, + com.sun.star.lang.XServiceInfo, + SpriteBase +{ + private JavaCanvas canvas; + private double alpha; + private java.awt.geom.Point2D.Double outputPosition; + private SpriteRep spriteRep; + private SpriteBase original; + + //---------------------------------------------------------------------------------- + + public CanvasClonedSprite( JavaCanvas _canvas, + XSprite _original ) + { + CanvasUtils.printLog( "CanvasClonesSprite constructor called!" ); + + canvas = _canvas; + + if( _original instanceof SpriteBase ) + { + original = (SpriteBase)_original; + } + + alpha = 0.0; + outputPosition = new java.awt.geom.Point2D.Double(0.0,0.0); + + // TODO: throw on error here! + } + + //---------------------------------------------------------------------------------- + + // + // SpriteBase + // ========== + // + public SpriteRep getSpriteRep() + { + if( spriteRep == null ) + { + spriteRep = new SpriteRep( original.getSpriteRep() ); + + spriteRep.moveSprite( outputPosition ); + spriteRep.setSpriteAlpha( alpha ); + + // TODO: Check for spriteRep.buffer != null here, throw otherwise + } + return spriteRep; + } + + //---------------------------------------------------------------------------------- + + // + // XComponent + // ========== + // + public void dispose() + { + canvas = null; + spriteRep = null; + original = null; + + super.dispose(); + } + + //---------------------------------------------------------------------------------- + + // + // XSprite impl + // ================== + // + + public synchronized void setAlpha( double _alpha ) + { + alpha = _alpha; + + if( spriteRep != null ) + { + spriteRep.setSpriteAlpha( alpha ); + } + } + + public synchronized void move( RealPoint2D _aNewPos, + ViewState _viewState, + RenderState _renderState ) + { + // transform given point with concatenated transformation + AffineTransform transform = CanvasUtils.ViewConcatRenderTransform( _viewState, _renderState ); + transform.transform( new java.awt.geom.Point2D.Double(_aNewPos.X, + _aNewPos.Y), + outputPosition ); + + if( spriteRep != null ) + { + spriteRep.moveSprite( outputPosition ); + } + } + + public synchronized void transform( AffineMatrix2D aTransformation ) throws com.sun.star.lang.IllegalArgumentException + { + // TODO + } + + public synchronized void clip( XPolyPolygon2D aClip, + ViewState viewState, + RenderState renderState ) throws com.sun.star.lang.IllegalArgumentException + { + // TODO + } + + public synchronized void show() + { + canvas.showSprite( this ); + canvas.updateScreen(); + } + + public synchronized void hide() + { + canvas.hideSprite( this ); + } + //---------------------------------------------------------------------------------- + + private static final String s_implName = "XSprite.java.impl"; + private static final String s_serviceName = "drafts.com.sun.star.rendering.Sprite"; + + //---------------------------------------------------------------------------------- + + // + // XServiceInfo impl + // ================= + // + public String getImplementationName() + { + return s_implName; + } + + public String [] getSupportedServiceNames() + { + return new String [] { s_serviceName }; + } + + public boolean supportsService( String serviceName ) + { + return serviceName.equals( s_serviceName ); + } +} diff --git a/canvas/source/java/CanvasCustomSprite.java b/canvas/source/java/CanvasCustomSprite.java new file mode 100644 index 000000000000..676c14c8b21d --- /dev/null +++ b/canvas/source/java/CanvasCustomSprite.java @@ -0,0 +1,246 @@ +/************************************************************************* + * + * $RCSfile: CanvasCustomSprite.java,v $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +// UNO +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.IQueryInterface; +import com.sun.star.lang.XInitialization; +import com.sun.star.lib.uno.helper.WeakBase; + +// OOo AWT +import com.sun.star.awt.*; + +// Canvas +import drafts.com.sun.star.rendering.*; +import drafts.com.sun.star.geometry.*; + +// Java AWT +import java.awt.*; +import java.awt.geom.*; + +// system-dependent stuff +import sun.awt.*; + + +public class CanvasCustomSprite + extends com.sun.star.lib.uno.helper.ComponentBase + implements drafts.com.sun.star.rendering.XCustomSprite, + com.sun.star.lang.XServiceInfo, + SpriteBase +{ + private JavaCanvas canvas; + private RealSize2D spriteSize; + private Graphics2D referenceGraphics; + private double alpha; + private java.awt.geom.Point2D.Double outputPosition; + private SpriteRep spriteRep; + + //---------------------------------------------------------------------------------- + + public CanvasCustomSprite( RealSize2D _spriteSize, + JavaCanvas _canvas, + Graphics2D _referenceGraphics ) + { + CanvasUtils.printLog( "CanvasCustomSprite constructor called, size is (" + _spriteSize.Width + ", " + _spriteSize.Height + ")" ); + + canvas = _canvas; + spriteSize = _spriteSize; + referenceGraphics = _referenceGraphics; + alpha = 0.0; + outputPosition = new java.awt.geom.Point2D.Double(0.0,0.0); + } + + //---------------------------------------------------------------------------------- + + // + // SpriteBase + // ========== + // + public synchronized SpriteRep getSpriteRep() + { + if( spriteRep == null ) + { + spriteRep = new SpriteRep(); + + spriteRep.setupBuffer(referenceGraphics, (int)(spriteSize.Width+.5), (int)(spriteSize.Height+.5) ); + + spriteRep.moveSprite( outputPosition ); + spriteRep.setSpriteAlpha( alpha ); + } + return spriteRep; + } + + //---------------------------------------------------------------------------------- + + // + // XComponent + // ========== + // + public void dispose() + { + if( spriteRep != null ) + spriteRep.dispose(); + + canvas = null; + referenceGraphics = null; + spriteRep = null; + + super.dispose(); + } + + //---------------------------------------------------------------------------------- + + // + // XCustomSprite impl + // ================== + // + + public synchronized void setAlpha( double _alpha ) + { + CanvasUtils.printLog( "CanvasCustomSprite.setAlpha() called" ); + + alpha = _alpha; + + if( spriteRep != null ) + { + spriteRep.setSpriteAlpha( alpha ); + } + } + + public synchronized void move( RealPoint2D _aNewPos, + ViewState _viewState, + RenderState _renderState ) + { + CanvasUtils.printLog( "CanvasCustomSprite.move() called" ); + + // transform given point with concatenated transformation + AffineTransform transform = CanvasUtils.ViewConcatRenderTransform( _viewState, _renderState ); + transform.transform( new java.awt.geom.Point2D.Double(_aNewPos.X, + _aNewPos.Y), + outputPosition ); + + if( spriteRep != null ) + { + spriteRep.moveSprite( outputPosition ); + } + } + + public synchronized void transform( AffineMatrix2D aTransformation ) throws com.sun.star.lang.IllegalArgumentException + { + // TODO + } + + public synchronized void clip( XPolyPolygon2D aClip, + ViewState viewState, + RenderState renderState ) throws com.sun.star.lang.IllegalArgumentException + { + // TODO + } + + public synchronized void show() + { + CanvasUtils.printLog( "CanvasCustomSprite.show() called" ); + + canvas.showSprite( this ); + canvas.updateScreen(); + } + + public synchronized void hide() + { + CanvasUtils.printLog( "CanvasCustomSprite.hide() called" ); + + canvas.hideSprite( this ); + + // do _not_ dispose clear SpriteRep, since we cannot actively + // repaint ourselves + } + + public synchronized drafts.com.sun.star.rendering.XCanvas getContentCanvas() + { + CanvasUtils.printLog( "CanvasCustomSprite.getContentCanvas() called" ); + + return getSpriteRep().getContentCanvas(); + } + + //---------------------------------------------------------------------------------- + + private static final String s_implName = "XCustomSprite.java.impl"; + private static final String s_serviceName = "drafts.com.sun.star.rendering.CustomSprite"; + + //---------------------------------------------------------------------------------- + + // + // XServiceInfo impl + // ================= + // + public String getImplementationName() + { + return s_implName; + } + + public String [] getSupportedServiceNames() + { + return new String [] { s_serviceName }; + } + + public boolean supportsService( String serviceName ) + { + return serviceName.equals( s_serviceName ); + } +} diff --git a/canvas/source/java/CanvasFont.java b/canvas/source/java/CanvasFont.java new file mode 100644 index 000000000000..e55247afc93f --- /dev/null +++ b/canvas/source/java/CanvasFont.java @@ -0,0 +1,187 @@ +/************************************************************************* + * + * $RCSfile: CanvasFont.java,v $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +// UNO +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.AnyConverter; +import com.sun.star.lib.uno.helper.WeakBase; + +// OOo AWT +import com.sun.star.awt.*; + +// Canvas +import drafts.com.sun.star.rendering.*; +import drafts.com.sun.star.geometry.*; + +// system-dependent stuff +import sun.awt.*; + + +public class CanvasFont + extends com.sun.star.lib.uno.helper.ComponentBase + implements com.sun.star.lang.XServiceInfo, + drafts.com.sun.star.rendering.XCanvasFont +{ + private CanvasBase associatedCanvas; + private drafts.com.sun.star.rendering.FontRequest fontRequest; + private java.awt.Font font; + + //---------------------------------------------------------------------------------- + + public CanvasFont( drafts.com.sun.star.rendering.FontRequest _fontRequest, + CanvasBase _canvas ) + { + associatedCanvas = _canvas; + fontRequest = _fontRequest; + + // TODO: Use proper attributes here, first of all, use fractional point font size + font = new java.awt.Font( fontRequest.FamilyName, java.awt.Font.PLAIN, (int)(fontRequest.CellSize + .5) ); + } + + public java.awt.Font getFont() + { + return font; + } + + //---------------------------------------------------------------------------------- + + // + // XCanvasFont implementation + // =========================== + // + + public XPolyPolygon2D[] queryTextShapes( StringContext text, + ViewState viewState, + RenderState renderState, + byte direction ) throws com.sun.star.lang.IllegalArgumentException + { + return null; + } + + public RealRectangle2D[] queryTightMeasures( StringContext text, + ViewState viewState, + RenderState renderState, + byte direction ) throws com.sun.star.lang.IllegalArgumentException + { + return null; + } + + public RealRectangle2D[] queryTextMeasures( StringContext text, + ViewState viewState, + RenderState renderState, + byte direction ) throws com.sun.star.lang.IllegalArgumentException + { + return null; + } + + public double[] queryTextOffsets( StringContext text, + ViewState viewState, + RenderState renderState, + byte direction ) throws com.sun.star.lang.IllegalArgumentException + { + return null; + } + + public RealRectangle2D queryTextBounds( StringContext text, + ViewState viewState, + RenderState renderState, + byte direction ) throws com.sun.star.lang.IllegalArgumentException + { + return null; + } + + public FontRequest getFontRequest() + { + return fontRequest; + } + + public FontMetrics getFontMetrics() + { + return null; + } + + public XCanvas getAssociatedCanvas() + { + return associatedCanvas; + } + + //---------------------------------------------------------------------------------- + + // + // XServiceInfo impl + // ================= + // + + private static final String s_implName = "CanvasFont.java.impl"; + private static final String s_serviceName = "drafts.com.sun.star.rendering.XCanvasFont"; + + public String getImplementationName() + { + return s_implName; + } + + public String [] getSupportedServiceNames() + { + return new String [] { s_serviceName }; + } + + public boolean supportsService( String serviceName ) + { + return serviceName.equals( s_serviceName ); + } +} diff --git a/canvas/source/java/CanvasGraphicDevice.java b/canvas/source/java/CanvasGraphicDevice.java new file mode 100644 index 000000000000..29d6aa2494fe --- /dev/null +++ b/canvas/source/java/CanvasGraphicDevice.java @@ -0,0 +1,192 @@ +/************************************************************************* + * + * $RCSfile: CanvasGraphicDevice.java,v $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +// UNO +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.AnyConverter; +import com.sun.star.lib.uno.helper.WeakBase; + +// OOo AWT +import com.sun.star.awt.*; + +// Canvas +import drafts.com.sun.star.rendering.*; +import drafts.com.sun.star.geometry.*; + +// Java AWT +import java.awt.*; +import java.awt.geom.*; + +// system-dependent stuff +import sun.awt.*; + +// TEMP +import com.sun.star.uno.Type; + + +public class CanvasGraphicDevice + extends com.sun.star.lib.uno.helper.ComponentBase + implements com.sun.star.lang.XServiceInfo, + drafts.com.sun.star.rendering.XGraphicDevice +{ + private java.awt.GraphicsConfiguration graphicsConfig; + + //---------------------------------------------------------------------------------- + + public CanvasGraphicDevice( java.awt.Graphics2D graphics ) + { + graphicsConfig = graphics.getDeviceConfiguration(); + } + + //---------------------------------------------------------------------------------- + + // + // GraphicsDevice implementation + // ============================= + // + public synchronized XBufferController getBufferController() + { + // Use java.awt.image.BufferStrategy to implement XBufferController + CanvasUtils.printLog( "CanvasGraphicDevice.getBufferController!" ); + return null; + } + + public synchronized XColorSpace getDeviceColorSpace() + { + CanvasUtils.printLog( "CanvasGraphicDevice.getDeviceColorSpace!" ); + return null; + } + + public synchronized drafts.com.sun.star.geometry.RealSize2D getPhysicalResolution() + { + CanvasUtils.printLog( "CanvasGraphicDevice.getPhysicalResolution!" ); + // TODO: getDefaultTransform + getNormalizingTransform + return new drafts.com.sun.star.geometry.RealSize2D(100,100); + } + + public synchronized drafts.com.sun.star.geometry.RealSize2D getSize() + { + CanvasUtils.printLog( "CanvasGraphicDevice.getSize!" ); + java.awt.Rectangle bounds = graphicsConfig.getBounds(); + + return new drafts.com.sun.star.geometry.RealSize2D(bounds.width, bounds.height); + } + + public synchronized XLinePolyPolygon2D createCompatibleLinePolyPolygon( RealPoint2D[][] points ) + { + CanvasUtils.printLog( "createCompatibleLinePolyPolygon" ); + return new LinePolyPolygon( points ); + } + + public synchronized XBezierPolyPolygon2D createCompatibleBezierPolyPolygon( RealBezierSegment2D[][] points ) + { + CanvasUtils.printLog( "createCompatibleBezierPolyPolygon" ); + return new BezierPolyPolygon( points ); + } + + public synchronized drafts.com.sun.star.rendering.XBitmap createCompatibleBitmap( IntegerSize2D size ) + { + CanvasUtils.printLog( "createCompatibleBitmap called with size (" + size.Width + ", " + size.Height + ")" ); + return new CanvasBitmap( graphicsConfig.createCompatibleImage( size.Width, + size.Height, + Transparency.TRANSLUCENT ) ); + } + + public synchronized drafts.com.sun.star.rendering.XVolatileBitmap createVolatileBitmap( IntegerSize2D size ) + { + CanvasUtils.printLog( "createVolatileBitmap called with size (" + size.Width + ", " + size.Height + ")" ); + //return new CanvasBitmap( graphicsConfig.createCompatibleVolatileImage( size.Width, size.Height ) ); + return null; + } + + public synchronized boolean hasFullScreenMode() + { + return graphicsConfig.getDevice().isFullScreenSupported(); + } + + public synchronized boolean enterFullScreenMode( boolean bEnter ) + { + return false; + } + + //---------------------------------------------------------------------------------- + + // + // XServiceInfo impl + // ================= + // + + private static final String s_implName = "XGraphicsDevice.java.impl"; + private static final String s_serviceName = "drafts.com.sun.star.rendering.GraphicsDevice"; + + public String getImplementationName() + { + return s_implName; + } + + public String [] getSupportedServiceNames() + { + return new String [] { s_serviceName }; + } + + public boolean supportsService( String serviceName ) + { + return serviceName.equals( s_serviceName ); + } + +} diff --git a/canvas/source/java/CanvasSprite.java b/canvas/source/java/CanvasSprite.java new file mode 100644 index 000000000000..e28208ff0ea4 --- /dev/null +++ b/canvas/source/java/CanvasSprite.java @@ -0,0 +1,350 @@ +/************************************************************************* + * + * $RCSfile: CanvasSprite.java,v $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +// UNO +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.IQueryInterface; +import com.sun.star.lang.XInitialization; +import com.sun.star.lib.uno.helper.WeakBase; + +// OOo AWT +import com.sun.star.awt.*; + +// Canvas +import drafts.com.sun.star.rendering.*; +import drafts.com.sun.star.geometry.*; + +// Java AWT +import java.awt.*; +import java.awt.geom.*; + +// system-dependent stuff +import sun.awt.*; + + +public class CanvasSprite + extends com.sun.star.lib.uno.helper.ComponentBase + implements drafts.com.sun.star.rendering.XAnimatedSprite, + com.sun.star.lang.XServiceInfo, + SpriteBase +{ + private XAnimation spriteAnimation; + private JavaCanvas canvas; + private Graphics2D referenceGraphics; + private SpriteRunner runner; + private ViewState viewState; + private double alpha; + private java.awt.geom.Point2D.Double outputPosition; + private SpriteRep spriteRep; + + //---------------------------------------------------------------------------------- + + public CanvasSprite( XAnimation _animation, JavaCanvas _canvas, Graphics2D _referenceGraphics ) + { + CanvasUtils.printLog( "CanvasSprite constructor called!" ); + + spriteAnimation = _animation; + canvas = _canvas; + referenceGraphics = _referenceGraphics; + alpha = 0.0; + outputPosition = new java.awt.geom.Point2D.Double(0.0,0.0); + + runner = new SpriteRunner( this, spriteAnimation, canvas ); + } + + public synchronized ViewState getViewState() + { + return viewState; + } + + //---------------------------------------------------------------------------------- + + // + // SpriteBase + // ========== + // + public synchronized SpriteRep getSpriteRep() + { + if( spriteRep == null ) + { + spriteRep = new SpriteRep(); + + setupSpriteBuffering( CanvasUtils.makeTransform( getViewState().AffineTransform ) ); + + spriteRep.moveSprite( outputPosition ); + spriteRep.setSpriteAlpha( alpha ); + + // render initial sprite content + updateAnimation(); + } + return spriteRep; + } + + //---------------------------------------------------------------------------------- + + // + // XComponent + // ========== + // + public void dispose() + { + // end the animation thread + if( runner != null ) + { + runner.quit(); + try + { + runner.join(0); // and wait until it's really over + } + catch( java.lang.InterruptedException e ) {} + } + + if( spriteRep != null ) + spriteRep.dispose(); + + canvas = null; + spriteAnimation = null; + runner = null; + referenceGraphics = null; + spriteRep = null; + + super.dispose(); + } + + //---------------------------------------------------------------------------------- + + // + // XSprite impl + // ============ + // + + public synchronized void startAnimation( double speed ) + { + runner.startAnimation( speed ); + } + + public synchronized void stopAnimation() + { + runner.stopAnimation(); + } + + public synchronized void resetAnimation() + { + runner.resetAnimation(); + } + + public synchronized void updateAnimation() + { + // only call render explicitely, if animation not + // running. Otherwise, next animation render will update + // anyway. + if( spriteRep != null && + !runner.isAnimationActive() ) + { + spriteRep.renderAnimation( spriteAnimation, getViewState(), runner.getCurrentT() ); + } + } + + public synchronized void setAlpha( double _alpha ) + { + alpha = _alpha; + + if( spriteRep != null ) + { + spriteRep.setSpriteAlpha( alpha ); + } + } + + public synchronized void move( drafts.com.sun.star.geometry.RealPoint2D _aNewPos, + drafts.com.sun.star.rendering.ViewState _viewState, + drafts.com.sun.star.rendering.RenderState _renderState ) + { + // transform given point with concatenated transformation + AffineTransform transform = CanvasUtils.ViewConcatRenderTransform( _viewState, _renderState ); + transform.transform( new java.awt.geom.Point2D.Double(_aNewPos.X, + _aNewPos.Y), + outputPosition ); + + if( spriteRep != null ) + { + spriteRep.moveSprite( outputPosition ); + } + } + + public synchronized void transform( AffineMatrix2D aTransformation ) throws com.sun.star.lang.IllegalArgumentException + { + // TODO + } + + public synchronized void clip( XPolyPolygon2D aClip, + ViewState viewState, + RenderState renderState ) throws com.sun.star.lang.IllegalArgumentException + { + // TODO + } + + public synchronized void show() + { + canvas.showSprite( this ); + canvas.updateScreen(); + } + + public synchronized void hide() + { + canvas.hideSprite( this ); + + // dispose and clear SpriteRep, animation content can be + // regenerated at any time + if( spriteRep != null ) + spriteRep.dispose(); + + spriteRep = null; + } + + public synchronized void setViewState( ViewState _viewState ) + { + viewState = CanvasUtils.createAnimationViewState(_viewState, + getAnimationAttributes()); + + CanvasUtils.printTransform( CanvasUtils.makeTransform( viewState.AffineTransform ), + "CanvasSprite.setViewState" ); + + if( spriteRep != null ) + { + // calculate bounds of view-transformed animation output rectangle + setupSpriteBuffering( CanvasUtils.makeTransform(getViewState().AffineTransform) ); + updateAnimation(); + } + } + + public synchronized AnimationAttributes getAnimationAttributes() + { + return spriteAnimation.getAnimationAttributes(); + } + + public synchronized void setAll( RealPoint2D _aNewPos, + ViewState _viewState, + RenderState _renderState, + double _alpha, + boolean bUpdateAnimation ) + { + alpha = _alpha; + + // transform given point with concatenated transformation + AffineTransform transform = CanvasUtils.ViewConcatRenderTransform( _viewState, _renderState ); + transform.transform( new java.awt.geom.Point2D.Double(_aNewPos.X, + _aNewPos.Y), + outputPosition ); + + if( spriteRep != null ) + { + spriteRep.setSpriteAlpha( alpha ); + spriteRep.moveSprite( outputPosition ); + + if( bUpdateAnimation ) + updateAnimation(); + } + } + + //---------------------------------------------------------------------------------- + + private void setupSpriteBuffering( AffineTransform _viewTransform ) + { + // determine bounds of view-transformed animation output rectangle + drafts.com.sun.star.geometry.RealSize2D animSize = getAnimationAttributes().UntransformedSize; + + java.awt.geom.Rectangle2D.Double aTransformedBounds = + CanvasUtils.calcTransformedRectBounds( new java.awt.geom.Rectangle2D.Double(0.0,0.0, + animSize.Width, + animSize.Height), + _viewTransform ); + CanvasUtils.printTransform( _viewTransform, "setupSpriteBuffering" ); + CanvasUtils.printLog( "setupSpriteBuffering: bounds are (" + aTransformedBounds.width + ", " + aTransformedBounds.height + ")" ); + + // create a buffer of the appropriate size + spriteRep.setupBuffer(referenceGraphics, (int)(aTransformedBounds.width+.5), + (int)(aTransformedBounds.height+.5) ); + } + + //---------------------------------------------------------------------------------- + + private static final String s_implName = "XSprite.java.impl"; + private static final String s_serviceName = "drafts.com.sun.star.rendering.Sprite"; + + //---------------------------------------------------------------------------------- + + // + // XServiceInfo impl + // ================= + // + public String getImplementationName() + { + return s_implName; + } + + public String [] getSupportedServiceNames() + { + return new String [] { s_serviceName }; + } + + public boolean supportsService( String serviceName ) + { + return serviceName.equals( s_serviceName ); + } +} diff --git a/canvas/source/java/CanvasTest_perftest.java b/canvas/source/java/CanvasTest_perftest.java new file mode 100644 index 000000000000..61fb38590940 --- /dev/null +++ b/canvas/source/java/CanvasTest_perftest.java @@ -0,0 +1,710 @@ +/************************************************************************* + * + * $RCSfile: CanvasTest_perftest.java,v $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +// UNO +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.IQueryInterface; +import com.sun.star.lang.XInitialization; +import com.sun.star.lib.uno.helper.WeakBase; + +// OOo AWT +import com.sun.star.awt.*; + +// Canvas +import drafts.com.sun.star.rendering.*; + +// Java AWT +import java.awt.*; +import java.awt.image.*; +import java.awt.geom.*; + +// system-dependent stuff +import sun.awt.*; + + +public class CanvasTest + extends CanvasBase + implements com.sun.star.awt.XWindow, + drafts.com.sun.star.rendering.XSpriteCanvas, + com.sun.star.lang.XServiceInfo, + com.sun.star.lang.XInitialization +{ + private WindowAdapter dummyFrame; + private BackBuffer backBuffer; + private java.awt.image.BufferStrategy bufferStrategy; + + private java.awt.Font fpsFont; + private long lastTime; + + + // TEST ONLY { + private static int testWidth = 1600; + private static int testHeight = 1200; + private BufferedImage backgroundBuffer; + private BufferedImage buffer; + private BufferedImage buffer2; + private Graphics2D backBufGraphics; + private Graphics2D bufferGraphics; + private Graphics2D buffer2Graphics; + private float currAlpha; + // TEST ONLY } + + + + public Graphics2D getGraphics() + { + return backBuffer.getGraphics(); + } + + //---------------------------------------------------------------------------------- + + // + // XInitialization + // =============== + // + public void initialize( java.lang.Object[] arguments ) + { + CanvasUtils.printLog( "CanvasTest.initialize called!" ); + + // Do that as the very first thing. The Java2D internal + // classes choose their render path at initialization time, + // thus this must happen before doing _any_ GUI. + + // TODO: Put those flags into javarc/java.ini, we're maybe + // coming late into a running JVM! + + // now, we're getting slightly system dependent here. + String os = (String) System.getProperty("os.name"); + + CanvasUtils.printLog( "System detected: " + os ); + + // tweak some speed knobs... + if( os.startsWith("Windows") ) + { + System.setProperty("sun.java2d.translaccel", "true"); + System.setProperty("sun.java2d.ddforcevram", "true"); + //System.setProperty("sun.java2d.accthreshold", "0"); + + CanvasUtils.printLog( "Optimizing for Windows" ); + } + else + { + System.setProperty("sun.java2d.opengl", "true"); + + CanvasUtils.printLog( "Optimizing for Unix" ); + } + + /* we're initialized with the following array of anys: + + arguments[0] = pointer to VCL window + arguments[1] = Integer (operating system window handle) + arguments[2] = com.sun.star.awt.Rectangle (position and size within that OS window) + arguments[3] = boolean (fullsize window or not) + + We then generate a dummy Java frame with that window as the + parent, to fake a root window for the Java implementation. + */ + try + { + com.sun.star.awt.Rectangle boundRect = (com.sun.star.awt.Rectangle) arguments[2]; + + //boolean isFullScreen = arguments[1]; + boolean isFullScreen = true; + //AnyConverter.toBoolean( arguments[3] ) ); + + // fake a root for Java in VCL window. Pass the flag + // whether we shall run fullscreen, too. + dummyFrame = new WindowAdapter( AnyConverter.toInt( arguments[1] ), isFullScreen ); + + if( isFullScreen ) + { + // blow window up to fullscreen. Otherwise, we cannot clear the whole screen, + // which results in ugly flickering + Dimension screenSize = dummyFrame.frame.getToolkit().getScreenSize(); + boundRect.X = 0; + boundRect.Y = 0; + boundRect.Width = screenSize.width-1; + boundRect.Height = screenSize.height-1; + } + + dummyFrame.setPosSize( boundRect.X, boundRect.Y, boundRect.Width, boundRect.Height, (short)0 ); + CanvasUtils.printLog( "Window size: " + boundRect.Width + ", " + boundRect.Height ); + + // TEST + if( true ) + { + backBuffer = new BackBuffer( (Graphics2D) dummyFrame.frame.getGraphics(), + Math.max(1,boundRect.Width), + Math.max(1,boundRect.Height) ); + } + else + { + backBuffer = new BackBuffer( (Graphics2D) dummyFrame.frame.getGraphics(), + 10, 10 ); + } + + // TODO: Maybe delay double buffer init until first sprite creation + dummyFrame.frame.createBufferStrategy(2); + bufferStrategy = dummyFrame.frame.getBufferStrategy(); + + if( bufferStrategy.getCapabilities().isPageFlipping() ) + CanvasUtils.printLog( "CanvasTest.initialize double buffering is using page flipping!" ); + else + CanvasUtils.printLog( "CanvasTest.initialize double buffering is using blitting!" ); + + lastTime = System.currentTimeMillis(); + fpsFont = new java.awt.Font( "Times", Font.PLAIN, 20 ); + + + if( false ) + { + // TEST ONLY { + Graphics2D frameGraphics= (Graphics2D) dummyFrame.frame.getGraphics(); + backgroundBuffer = frameGraphics.getDeviceConfiguration().createCompatibleImage(testWidth,testHeight); // TODO: size dynamic + buffer = frameGraphics.getDeviceConfiguration().createCompatibleImage(testWidth,testHeight, + Transparency.TRANSLUCENT); + buffer2 = frameGraphics.getDeviceConfiguration().createCompatibleImage(testWidth,testHeight, + Transparency.TRANSLUCENT); + bufferGraphics = (Graphics2D)buffer.getGraphics(); + buffer2Graphics = (Graphics2D)buffer2.getGraphics(); + backBufGraphics = (Graphics2D)backgroundBuffer.getGraphics(); + currAlpha = 0.1f; + + // init content + Font font = new Font( "Times", Font.PLAIN, 100 ); + + bufferGraphics.setComposite( AlphaComposite.getInstance(AlphaComposite.CLEAR)); + bufferGraphics.fillRect( 0,0,testWidth,testHeight ); + + bufferGraphics.setComposite( AlphaComposite.getInstance(AlphaComposite.SRC_OVER)); + bufferGraphics.setColor( Color.red ); + bufferGraphics.fillRect( 0,0,testWidth/2,testHeight/2 ); + bufferGraphics.setColor( Color.green ); + bufferGraphics.fillRect( testWidth/2,0,testWidth,testHeight/2 ); + bufferGraphics.setColor( Color.blue ); + bufferGraphics.fillRect( 0,testHeight/2,testWidth/2,testHeight ); + + buffer2Graphics.setColor( Color.red ); + buffer2Graphics.fillRect( 0,0,testWidth/2,testHeight/2 ); + buffer2Graphics.setColor( Color.green ); + buffer2Graphics.fillRect( testWidth/2,0,testWidth,testHeight/2 ); + buffer2Graphics.setColor( Color.blue ); + buffer2Graphics.fillRect( 0,testHeight/2,testWidth/2,testHeight ); + + backBufGraphics.setColor( Color.white ); + backBufGraphics.fillRect(0,0,testWidth,testHeight); + backBufGraphics.setColor( Color.red ); + backBufGraphics.setFont( font ); + int i, turns=15; + for(i=0; i<turns; ++i) + { + backBufGraphics.drawString( "Crossfade test", testWidth*i/turns, testHeight*i/turns ); + } + // TEST ONLY } + } + + CanvasUtils.printLog( "CanvasTest.initialize finished!" ); + } + catch( com.sun.star.lang.IllegalArgumentException e ) + { + CanvasUtils.printLog( "Cannot create EmbeddedFrame within VCL window hierarchy!" ); + } + } + + //---------------------------------------------------------------------------------- + + // + // XComponent + // ========== + // + public void dispose() + { + CanvasUtils.printLog( "CanvasTest: disposed!" ); + + // destroy all active sprites + java.util.Set entries = activeSprites.entrySet(); + java.util.Iterator iter = entries.iterator(); + + while( iter.hasNext() ) + { + java.util.Map.Entry entry = (java.util.Map.Entry)iter.next(); + if( entry.getValue() != null ) + ((SpriteRep)entry.getValue()).dispose(); + } + + if( bufferStrategy != null ) + bufferStrategy.getDrawGraphics().dispose(); // really necessary? + + if( dummyFrame != null ) + dummyFrame.dispose(); + + if( backBuffer != null) + backBuffer.dispose(); + + bufferStrategy = null; + dummyFrame = null; + backBuffer = null; + + super.dispose(); + } + + //---------------------------------------------------------------------------------- + + public CanvasTest( XComponentContext xContext ) + { + CanvasUtils.printLog( "CanvasTest constructor called!" ); + activeSprites = new java.util.HashMap( 33 ); + } + + //---------------------------------------------------------------------------------- + + // + // XWindow interface + // ================= + // + // This is delegated to WindowAdapter! + // + public synchronized void setPosSize( int X, int Y, int Width, int Height, short Flags ) + { + if( dummyFrame != null ) + { + dummyFrame.setPosSize( X, Y, Width, Height, Flags ); + + Width = Math.max(1,Width); + Height= Math.max(1,Height); + + CanvasUtils.printLog( "CanvasTest graphics set to " + Width + "," + Height ); + backBuffer.setSize(Width,Height); + } + } + + public synchronized com.sun.star.awt.Rectangle getPosSize( ) + { + if( dummyFrame != null ) + return dummyFrame.getPosSize(); + + return new com.sun.star.awt.Rectangle(); + } + + public synchronized void setVisible( boolean visible ) + { + if( dummyFrame != null ) + dummyFrame.setVisible( visible ); + } + + public synchronized void setEnable( boolean enable ) + { + if( dummyFrame != null ) + dummyFrame.setEnable( enable ); + } + + public synchronized void setFocus() + { + if( dummyFrame != null ) + dummyFrame.setFocus(); + } + + public synchronized void addWindowListener( XWindowListener xListener ) + { + if( dummyFrame != null ) + dummyFrame.addWindowListener( xListener ); + } + + public synchronized void removeWindowListener( XWindowListener xListener ) + { + if( dummyFrame != null ) + dummyFrame.removeWindowListener( xListener ); + } + + public synchronized void addFocusListener( XFocusListener xListener ) + { + if( dummyFrame != null ) + dummyFrame.addFocusListener( xListener ); + } + + public synchronized void removeFocusListener( XFocusListener xListener ) + { + if( dummyFrame != null ) + dummyFrame.removeFocusListener( xListener ); + } + + public synchronized void addKeyListener( XKeyListener xListener ) + { + if( dummyFrame != null ) + dummyFrame.addKeyListener( xListener ); + } + + public synchronized void removeKeyListener( XKeyListener xListener ) + { + if( dummyFrame != null ) + dummyFrame.removeKeyListener( xListener ); + } + + public synchronized void addMouseListener( XMouseListener xListener ) + { + if( dummyFrame != null ) + dummyFrame.addMouseListener( xListener ); + } + + public synchronized void removeMouseListener( XMouseListener xListener ) + { + if( dummyFrame != null ) + dummyFrame.removeMouseListener( xListener ); + } + + public synchronized void addMouseMotionListener( XMouseMotionListener xListener ) + { + if( dummyFrame != null ) + dummyFrame.addMouseMotionListener( xListener ); + } + + public synchronized void removeMouseMotionListener( XMouseMotionListener xListener ) + { + if( dummyFrame != null ) + dummyFrame.removeMouseMotionListener( xListener ); + } + + public synchronized void addPaintListener( XPaintListener xListener ) + { + if( dummyFrame != null ) + dummyFrame.addPaintListener( xListener ); + } + + public synchronized void removePaintListener( XPaintListener xListener ) + { + if( dummyFrame != null ) + dummyFrame.removePaintListener( xListener ); + } + + //---------------------------------------------------------------------------------- + + // + // XBitmapCanvas impl + // ================== + // + + public synchronized void copyRect( drafts.com.sun.star.rendering.XBitmapCanvas sourceCanvas, + drafts.com.sun.star.rendering.Rectangle2D sourceRect, + drafts.com.sun.star.rendering.ViewState sourceViewState, + drafts.com.sun.star.rendering.RenderState sourceRenderState, + drafts.com.sun.star.rendering.Rectangle2D destRect, + drafts.com.sun.star.rendering.ViewState destViewState, + drafts.com.sun.star.rendering.RenderState destRenderState ) + { + CanvasUtils.printLog( "CanvasTest.copyRect() called" ); + + // TODO: create temp image when transform is non-trivial + + if( sourceCanvas == this ) + { + // copy rectangle within the canvas + getGraphics().copyArea((int)sourceRect.x1, + (int)sourceRect.y1, + (int)(sourceRect.x2 - sourceRect.x1), + (int)(sourceRect.y2 - sourceRect.y1), + (int)(destRect.x1 - sourceRect.x1), + (int)(destRect.y1 - sourceRect.y1) ); + } + else + { + if( sourceCanvas instanceof CanvasTest ) + { + // cache + CanvasUtils.setupGraphicsState( getGraphics(), destViewState, destRenderState, CanvasUtils.alsoSetupPaint ); + + java.awt.Image backBuffer = ((CanvasTest)sourceCanvas).backBuffer.getBackBuffer(); + + // TODO: really extract correct source rect here + getGraphics().drawImage( backBuffer, 0, 0, null); + CanvasUtils.postRenderImageTreatment( backBuffer ); + } + // TODO: foreign canvas + } + } + + //---------------------------------------------------------------------------------- + + // a map of SpriteReps, with Sprite object as keys. Contains all + // active (i.e. visible) sprites, the SpriteReps are used to + // repaint the sprite content at any time. + private java.util.HashMap activeSprites; + + // + // XSpriteCanvas impl + // ================== + // + + public synchronized drafts.com.sun.star.rendering.XAnimatedSprite createSpriteFromAnimation( XAnimation animation ) + { + CanvasUtils.printLog( "CanvasTest.createSpriteFromAnimation called" ); + + return new CanvasSprite( animation, this, (Graphics2D)dummyFrame.frame.getGraphics() ); + } + + public synchronized XAnimatedSprite createSpriteFromBitmaps( drafts.com.sun.star.rendering.XBitmap[] animationBitmaps, + short interpolationMode ) + { + return null; + } + + public synchronized XCustomSprite createCustomSprite( Size2D spriteSize ) + { + CanvasUtils.printLog( "CanvasTest.createCustomSprite called" ); + + return new CanvasCustomSprite( spriteSize, this, (Graphics2D)dummyFrame.frame.getGraphics() ); + } + + public synchronized XSprite createClonedSprite( XSprite original ) + { + return new CanvasClonedSprite( this, original ); + } + + public synchronized void updateScreen() + { + redrawAllLayers(); + } + + //---------------------------------------------------------------------------------- + + // + // XSpriteCanvas helper + // ==================== + // + public synchronized void renderAnimation( CanvasSprite sprite, XAnimation animation, double t ) + { + SpriteRep spriteRep = (SpriteRep)activeSprites.get( sprite ); + if( spriteRep != null ) + { + //Graphics2D graph = getWindowGraphics(); + + // TODO: ensure update of graphics object externally, e.g. when + // VCL moves the toplevel window. + //java.awt.Rectangle bounds = dummyFrame.frame.getBounds(); + //graphics.setGraphics(graph, bounds.width, bounds.height); + + spriteRep.renderAnimation( animation, sprite.getViewState(), t ); + } + else + { + CanvasUtils.printLog( "CanvasTest.renderAnimation sprite not active!" ); + } + } + + public synchronized void showSprite( SpriteBase sprite ) + { + CanvasUtils.printLog( "CanvasTest.showSprite() called" ); + + SpriteRep spriteRep = (SpriteRep)activeSprites.get( sprite ); + if( spriteRep != null ) + { + CanvasUtils.printLog( "CanvasTest.showSprite sprite already active!" ); + } + else + { + spriteRep = sprite.getSpriteRep(); + + // a valid SpriteRep for a given Sprite in the + // activeSprites hash denotes 'sprite active' + activeSprites.put( sprite, spriteRep ); + + // TODO: TEMP! Just for testing! Set empty cursor for presentation +// dummyFrame.frame.setCursor( dummyFrame.frame.getToolkit().createCustomCursor(new java.awt.image.BufferedImage(0,0, +// java.awt.image.BufferedImage.TYPE_INT_RGB), +// new java.awt.Point(0,0), +// "") ); + } + } + + public synchronized void hideSprite( SpriteBase sprite ) + { + CanvasUtils.printLog( "CanvasTest.hideSprite() called" ); + + SpriteRep spriteRep = (SpriteRep)activeSprites.get( sprite ); + if( spriteRep != null ) + { + activeSprites.put( sprite, null ); + redrawAllLayers(); + } + else + { + CanvasUtils.printLog( "CanvasTest.hideSprite sprite not active!" ); + } + } + + private void redrawAllLayers() + { + // fetch the Graphics object to draw into (we're doing double + // buffering here, the content is later shown via + // bufferStrategy.show(). + Graphics2D graph = null; + + try + { + graph = (Graphics2D)bufferStrategy.getDrawGraphics(); + + GraphicsDevice device = graph.getDeviceConfiguration().getDevice(); + CanvasUtils.printLog( "Available vram: " + device.getAvailableAcceleratedMemory() ); + + if( false ) + { + // TEST ONLY { + // repaint background + graph.setComposite( AlphaComposite.getInstance(AlphaComposite.SRC_OVER) ); + graph.drawImage(backgroundBuffer, 0, 0, null); + //backgroundBuffer.flush(); + + // alpha-composite foreground on top of that + graph.setComposite( AlphaComposite.getInstance(AlphaComposite.SRC_OVER, currAlpha) ); + + graph.drawImage(buffer, 0, 0, null); + //buffer.flush(); + + currAlpha += 0.1f; if( currAlpha > 1.0 ) currAlpha = 0.1f; + // TEST ONLY } + } + + if( true ) + { + // repaint background + backBuffer.redraw( graph ); + + // repaint all active sprites + java.util.Set entries = activeSprites.entrySet(); + java.util.Iterator iter = entries.iterator(); + while( iter.hasNext() ) + { + java.util.Map.Entry entry = (java.util.Map.Entry)iter.next(); + if( entry.getValue() != null ) + ((SpriteRep)entry.getValue()).redraw(graph); + } + } + + long currTime = System.currentTimeMillis(); + graph.setComposite( AlphaComposite.getInstance(AlphaComposite.SRC_OVER) ); + graph.setFont( fpsFont ); + graph.setColor( java.awt.Color.black ); + + try + { + String fps = new String( String.valueOf(1000.0/(currTime-lastTime)) ); + graph.drawString( fps.substring(0,5) + " fps", 0, 20); + CanvasUtils.printLog( fps.substring(0,5) + " fps" ); + } + catch( Exception e ) + { + graph.drawString( "0 fps", 0, 20); + } + + lastTime = currTime; + } + finally + { + if( graph != null ) + graph.dispose(); + } + + bufferStrategy.show(); + } + + //---------------------------------------------------------------------------------- + + private static final String s_implName = "XCanvas.java.impl"; + private static final String s_serviceName = "drafts.com.sun.star.rendering.Canvas"; + + //---------------------------------------------------------------------------------- + + // + // XServiceInfo impl + // ================= + // + public synchronized String getImplementationName() + { + return s_implName; + } + + public synchronized String [] getSupportedServiceNames() + { + return new String [] { s_serviceName }; + } + + public synchronized boolean supportsService( String serviceName ) + { + return serviceName.equals( s_serviceName ); + } + + public static com.sun.star.lang.XSingleServiceFactory __getServiceFactory( + String implName, + com.sun.star.lang.XMultiServiceFactory multiFactory, + com.sun.star.registry.XRegistryKey regKey ) + { + if (implName.equals( s_implName )) + { + return com.sun.star.comp.loader.FactoryHelper.getServiceFactory( + CanvasTest.class, s_serviceName, multiFactory, regKey ); + } + return null; + } + + public static boolean __writeRegistryServiceInfo( + com.sun.star.registry.XRegistryKey regKey ) + { + return com.sun.star.comp.loader.FactoryHelper.writeRegistryServiceInfo( + s_implName, s_serviceName, regKey ); + } +} diff --git a/canvas/source/java/CanvasUtils.java b/canvas/source/java/CanvasUtils.java new file mode 100644 index 000000000000..0df1f69768ca --- /dev/null +++ b/canvas/source/java/CanvasUtils.java @@ -0,0 +1,670 @@ +/************************************************************************* + * + * $RCSfile: CanvasUtils.java,v $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +// UNO +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.IQueryInterface; +import com.sun.star.lang.XInitialization; +import com.sun.star.lib.uno.helper.WeakBase; + +// OOo AWT +import com.sun.star.awt.*; + +// Canvas +import drafts.com.sun.star.rendering.*; +import drafts.com.sun.star.geometry.*; + +// Java AWT +import java.awt.*; +import java.awt.image.*; +import java.awt.geom.*; + +// system-dependent stuff +import sun.awt.*; + + +public class CanvasUtils +{ + // + // Canvas utilities + // ================ + // + public static java.awt.geom.AffineTransform makeTransform( AffineMatrix2D ooTransform ) + { + return new AffineTransform( ooTransform.m00, + ooTransform.m10, + ooTransform.m01, + ooTransform.m11, + ooTransform.m02, + ooTransform.m12 ); + } + + public static AffineMatrix2D makeAffineMatrix2D( java.awt.geom.AffineTransform transform ) + { + double[] matrix = new double[6]; + transform.getMatrix( matrix ); + + return new AffineMatrix2D( matrix[0], matrix[2], matrix[4], + matrix[1], matrix[3], matrix[5] ); + } + + public static void initGraphics( Graphics2D graphics ) + { + if( graphics != null ) + { + java.awt.RenderingHints hints = new java.awt.RenderingHints(null); + boolean hq = true; + + if( hq ) + { + hints.add( new java.awt.RenderingHints( java.awt.RenderingHints.KEY_FRACTIONALMETRICS, + java.awt.RenderingHints.VALUE_FRACTIONALMETRICS_ON ) ); +// hints.add( new java.awt.RenderingHints( java.awt.RenderingHints.KEY_ALPHA_INTERPOLATION, +// java.awt.RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY) ); + hints.add( new java.awt.RenderingHints( java.awt.RenderingHints.KEY_ALPHA_INTERPOLATION, + java.awt.RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED) ); +// hints.add( new java.awt.RenderingHints( java.awt.RenderingHints.KEY_INTERPOLATION, +// java.awt.RenderingHints.VALUE_INTERPOLATION_BICUBIC) ); + hints.add( new java.awt.RenderingHints( java.awt.RenderingHints.KEY_INTERPOLATION, + java.awt.RenderingHints.VALUE_INTERPOLATION_BILINEAR) ); +// hints.add( new java.awt.RenderingHints( java.awt.RenderingHints.KEY_RENDERING, +// java.awt.RenderingHints.VALUE_RENDER_QUALITY) ); + hints.add( new java.awt.RenderingHints( java.awt.RenderingHints.KEY_RENDERING, + java.awt.RenderingHints.VALUE_RENDER_SPEED) ); +// hints.add( new java.awt.RenderingHints( java.awt.RenderingHints.KEY_STROKE_CONTROL, +// java.awt.RenderingHints.VALUE_STROKE_NORMALIZE) ); + hints.add( new java.awt.RenderingHints( java.awt.RenderingHints.KEY_STROKE_CONTROL, + java.awt.RenderingHints.VALUE_STROKE_DEFAULT) ); + hints.add( new java.awt.RenderingHints( java.awt.RenderingHints.KEY_ANTIALIASING, + java.awt.RenderingHints.VALUE_ANTIALIAS_ON) ); + } + else + { + hints.add( new java.awt.RenderingHints( java.awt.RenderingHints.KEY_ALPHA_INTERPOLATION, + java.awt.RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED) ); + hints.add( new java.awt.RenderingHints( java.awt.RenderingHints.KEY_INTERPOLATION, + java.awt.RenderingHints.VALUE_INTERPOLATION_BILINEAR) ); + hints.add( new java.awt.RenderingHints( java.awt.RenderingHints.KEY_RENDERING, + java.awt.RenderingHints.VALUE_RENDER_SPEED) ); + hints.add( new java.awt.RenderingHints( java.awt.RenderingHints.KEY_STROKE_CONTROL, + java.awt.RenderingHints.VALUE_STROKE_DEFAULT) ); + hints.add( new java.awt.RenderingHints( java.awt.RenderingHints.KEY_ANTIALIASING, + java.awt.RenderingHints.VALUE_ANTIALIAS_OFF) ); + } + + // the least common denominator standard + hints.add( new java.awt.RenderingHints( java.awt.RenderingHints.KEY_FRACTIONALMETRICS, + java.awt.RenderingHints.VALUE_FRACTIONALMETRICS_ON) ); + hints.add( new java.awt.RenderingHints( java.awt.RenderingHints.KEY_TEXT_ANTIALIASING, + java.awt.RenderingHints.VALUE_TEXT_ANTIALIAS_ON) ); + + graphics.setRenderingHints( hints ); + } + } + + //---------------------------------------------------------------------------------- + + public static java.awt.geom.GeneralPath makeGenPathFromBezierPoints( RealBezierSegment2D [][] points ) + { + java.awt.geom.GeneralPath path = new java.awt.geom.GeneralPath(); + + // extract every polygon into GeneralPath object + for( int i=0; i<points.length; ++i ) + { + if( points[i].length > 0 ) + path.moveTo((float) points[i][0].Px, (float) points[i][0].Py); + + for( int j=1; j<points[i].length; ++j ) + { + CanvasUtils.printLog( "makeGenPathFromBezierPoints: point added." ); + path.curveTo((float)(points[i][j-1].C1x), (float)(points[i][j-1].C1y), + (float)(points[i][j-1].C2x), (float)(points[i][j-1].C2y), + (float) points[i][j].Px, (float) points[i][j].Py ); + } + + // TODO: closePath? + } + + return path; + } + + public static java.awt.geom.GeneralPath makeGenPathFromBezierPoly( drafts.com.sun.star.rendering.XBezierPolyPolygon2D poly ) + { + try + { + drafts.com.sun.star.geometry.RealBezierSegment2D [][] points = poly.getPoints(0,-1,0,-1); + + return makeGenPathFromBezierPoints( points ); + } + catch( com.sun.star.lang.IndexOutOfBoundsException e ) + { + } + + return new java.awt.geom.GeneralPath(); + } + + public static java.awt.geom.GeneralPath makeGenPathFromLinePoints( RealPoint2D [][] points ) + { + java.awt.geom.GeneralPath path = new java.awt.geom.GeneralPath(); + + // extract every polygon into GeneralPath object + for( int i=0; i<points.length; ++i ) + { + if( points[i].length > 0 ) + path.moveTo((float) points[i][0].X, (float) points[i][0].Y); + + for( int j=1; j<points[i].length; ++j ) + { + CanvasUtils.printLog( "makeGenPathFromLinePoints: point (" + + points[i][j].X + "," + points[i][j].Y + ") added." ); + path.lineTo((float) points[i][j].X, (float) points[i][j].Y ); + } + + // TODO: closePath? + } + + return path; + } + + public static java.awt.geom.GeneralPath makeGenPathFromLinePoly( drafts.com.sun.star.rendering.XLinePolyPolygon2D poly ) + { + try + { + drafts.com.sun.star.geometry.RealPoint2D [][] points = poly.getPoints(0,-1,0,-1); + + return makeGenPathFromLinePoints( points ); + } + catch( com.sun.star.lang.IndexOutOfBoundsException e ) + { + } + + return new java.awt.geom.GeneralPath(); + } + + public static java.awt.geom.GeneralPath makeGeneralPath( drafts.com.sun.star.rendering.XPolyPolygon2D poly ) + { + if( poly instanceof BezierPolyPolygon ) + { + CanvasUtils.printLog( "makeGeneralPath: bezier impl used." ); + return ((BezierPolyPolygon)poly).getJavaPath(); + } + + if( poly instanceof LinePolyPolygon ) + { + CanvasUtils.printLog( "makeGeneralPath: line impl used." ); + return ((LinePolyPolygon)poly).getJavaPath(); + } + + XBezierPolyPolygon2D bezierPoly = (XBezierPolyPolygon2D) UnoRuntime.queryInterface(XBezierPolyPolygon2D.class, poly); + + if( bezierPoly != null ) + { + // extract polygon data. Prefer bezier interface, because + // that's the more high-level data. + return makeGenPathFromBezierPoly( bezierPoly ); + } + + XLinePolyPolygon2D linePoly = (XLinePolyPolygon2D) UnoRuntime.queryInterface(XLinePolyPolygon2D.class, poly); + + if( linePoly != null ) + { + // extract polygon data. Fallback to line polygon, if no + // curves are available. + return makeGenPathFromLinePoly( linePoly ); + } + + // Only opaque general interface. No chance to get to the + // data. Empty path, then + CanvasUtils.printLog( "makeGeneralPath: Cannot access polygon data, given interface has class" + poly.getClass().getName() ); + return new GeneralPath(); + } + + public static java.awt.image.BufferedImage getBufferedImage( drafts.com.sun.star.rendering.XBitmap bitmap ) + { + if( bitmap instanceof CanvasBitmap ) + { + CanvasUtils.printLog( "getBufferedImage: CanvasBitmap impl used." ); + return ((CanvasBitmap)bitmap).getBufferedImage(); + } + + XIntegerBitmap integerBitmap = (XIntegerBitmap) UnoRuntime.queryInterface(XIntegerBitmap.class, bitmap); + + if( integerBitmap != null ) + { + // extract bitmap data. TODO. + return null; + } + + // check other types. TODO. + return null; + } + + public static byte [] int2byte( int [] input ) + { + byte [] output = new byte[4*input.length]; + + int i, j; + for( i=0, j=0; i<input.length; ++i ) + { + output[j] = (byte)(input[i] & 255); + output[j+1] = (byte)((input[i]/256) & 255); + output[j+2] = (byte)((input[i]/256/256) & 255); + output[j+3] = (byte)((input[i]/256/256/256) & 255); + j += 4; + } + + return output; + } + + public static int [] byte2int( byte [] input ) + { + int [] output = new int[(input.length+3)/4]; + + int i, j; + for( i=0,j=0; j<output.length; ++j ) + { + output[j] = input[i] + (input[i+1] + (input[i+2] + input[i+3]*256)*256)*256; + i += 4; + } + + return output; + } + + public static int javaRuleFromCompositeOp( byte compositeOp ) + { + // TODO: Finish mapping of Canvas and Java compositing magics + int rule = java.awt.AlphaComposite.SRC_OVER; + switch( compositeOp ) + { + case drafts.com.sun.star.rendering.CompositeOperation.CLEAR: + CanvasUtils.printLog( "javaRuleFromCompositeOp: clear selected" ); + rule = java.awt.AlphaComposite.CLEAR; + break; + + case drafts.com.sun.star.rendering.CompositeOperation.SOURCE: + CanvasUtils.printLog( "javaRuleFromCompositeOp: src selected" ); + rule = java.awt.AlphaComposite.SRC; + break; + + case drafts.com.sun.star.rendering.CompositeOperation.DESTINATION: + CanvasUtils.printLog( "javaRuleFromCompositeOp: dst selected" ); + rule = java.awt.AlphaComposite.DST; + break; + + case drafts.com.sun.star.rendering.CompositeOperation.OVER: + CanvasUtils.printLog( "javaRuleFromCompositeOp: over selected" ); + rule = java.awt.AlphaComposite.SRC_OVER; + break; + + case drafts.com.sun.star.rendering.CompositeOperation.UNDER: + CanvasUtils.printLog( "javaRuleFromCompositeOp: under selected" ); + rule = java.awt.AlphaComposite.DST_OVER; + break; + + case drafts.com.sun.star.rendering.CompositeOperation.INSIDE: + CanvasUtils.printLog( "javaRuleFromCompositeOp: inside selected" ); + rule = java.awt.AlphaComposite.CLEAR; + break; + + case drafts.com.sun.star.rendering.CompositeOperation.INSIDE_REVERSE: + CanvasUtils.printLog( "javaRuleFromCompositeOp: inReverse selected" ); + rule = java.awt.AlphaComposite.CLEAR; + break; + + case drafts.com.sun.star.rendering.CompositeOperation.OUTSIDE: + CanvasUtils.printLog( "javaRuleFromCompositeOp: outside selected" ); + rule = java.awt.AlphaComposite.CLEAR; + break; + + case drafts.com.sun.star.rendering.CompositeOperation.OUTSIDE_REVERSE: + CanvasUtils.printLog( "javaRuleFromCompositeOp: outReverse selected" ); + rule = java.awt.AlphaComposite.CLEAR; + break; + + case drafts.com.sun.star.rendering.CompositeOperation.XOR: + CanvasUtils.printLog( "javaRuleFromCompositeOp: xor selected" ); + rule = java.awt.AlphaComposite.CLEAR; + break; + + case drafts.com.sun.star.rendering.CompositeOperation.ADD: + CanvasUtils.printLog( "javaRuleFromCompositeOp: add selected" ); + rule = java.awt.AlphaComposite.CLEAR; + break; + + case drafts.com.sun.star.rendering.CompositeOperation.SATURATE: + CanvasUtils.printLog( "javaRuleFromCompositeOp: saturate selected" ); + rule = java.awt.AlphaComposite.CLEAR; + break; + + default: + CanvasUtils.printLog( "javaRuleFromCompositeOp: Unexpected compositing rule" ); + break; + } + + return rule; + } + + public static java.awt.AlphaComposite makeAlphaComposite( byte compositeOp ) + { + return java.awt.AlphaComposite.getInstance( javaRuleFromCompositeOp( compositeOp ) ); + } + + public static java.awt.AlphaComposite makeAlphaCompositeAlpha( byte compositeOp, double alpha ) + { + return java.awt.AlphaComposite.getInstance( javaRuleFromCompositeOp( compositeOp ), (float)alpha ); + } + + // when given to setupGraphicsState, makes that method to also + // setup the Paint with the color specified in the render state. + public static final byte alsoSetupPaint=0; + + // when given to setupGraphicsState, makes that method to _not_ + // setup the Paint with the color specified in the render state. + public static final byte dontSetupPaint=1; + + public static java.awt.geom.AffineTransform ViewConcatRenderTransform( ViewState viewState, + RenderState renderState ) + { + // calculate overall affine transform + AffineTransform transform = makeTransform( viewState.AffineTransform ); + transform.concatenate( makeTransform( renderState.AffineTransform ) ); + + printTransform( transform, "ViewConcatRenderTransform" ); + + return transform; + } + + public static void setupGraphicsState( java.awt.Graphics2D graphics, + ViewState viewState, + RenderState renderState, + byte paintTouchMode ) + { + // calculate overall affine transform + graphics.setTransform( ViewConcatRenderTransform(viewState, renderState ) ); + + // setup overall clip polyPolygon + if( viewState.Clip != null ) + { + Area clipArea = new Area( makeGeneralPath( viewState.Clip ) ); + + if( renderState.Clip != null ) + clipArea.intersect( new Area( makeGeneralPath( renderState.Clip ) ) ); + + graphics.setClip( clipArea ); + } + else if( renderState.Clip != null ) + { + Area clipArea = new Area( makeGeneralPath( renderState.Clip ) ); + graphics.setClip( clipArea ); + } + else + { + // TODO: HACK! Use true visible area here! + graphics.setClip( new java.awt.Rectangle(-1000000,-1000000,2000000,2000000) ); + } + + // setup current output color + // TODO: Complete color handling here + if( paintTouchMode == alsoSetupPaint ) + { + switch( renderState.DeviceColor.length ) + { + case 3: + CanvasUtils.printLog( "setupGraphicsState: Color(" + + renderState.DeviceColor[0] + "," + + renderState.DeviceColor[1] + "," + + renderState.DeviceColor[2] + ") set." ); + graphics.setColor( new Color( (float)renderState.DeviceColor[0], + (float)renderState.DeviceColor[1], + (float)renderState.DeviceColor[2] ) ); + break; + + case 4: + CanvasUtils.printLog( "setupGraphicsState: Color(" + + renderState.DeviceColor[0] + "," + + renderState.DeviceColor[1] + "," + + renderState.DeviceColor[2] + "," + + renderState.DeviceColor[3] + ") set." ); + graphics.setColor( new Color( (float)renderState.DeviceColor[0], + (float)renderState.DeviceColor[1], + (float)renderState.DeviceColor[2], + (float)renderState.DeviceColor[3] ) ); + break; + + default: + CanvasUtils.printLog( "setupGraphicsState: unexpected number of " + + renderState.DeviceColor.length + " color components!" ); + break; + } + } + + // setup current composite mode + graphics.setComposite( makeAlphaComposite( renderState.CompositeOperation ) ); + } + + public static void applyStrokeAttributes( java.awt.Graphics2D graphics, + StrokeAttributes attributes ) + { + int cap = java.awt.BasicStroke.CAP_BUTT; + + if( attributes.StartCapType != attributes.EndCapType ) + CanvasUtils.printLog( "applyStrokeAttributes: different start and end caps are not yet supported!" ); + + if( attributes.LineArray.length != 0 ) + CanvasUtils.printLog( "applyStrokeAttributes: multi-strokes are not yet supported!" ); + + if( attributes.StartCapType == PathCapType.BUTT ) + cap = java.awt.BasicStroke.CAP_BUTT; + else if( attributes.StartCapType == PathCapType.ROUND ) + cap = java.awt.BasicStroke.CAP_ROUND; + else if( attributes.StartCapType == PathCapType.SQUARE ) + cap = java.awt.BasicStroke.CAP_SQUARE; + + int join = java.awt.BasicStroke.JOIN_MITER; + + if( attributes.JoinType == PathJoinType.MITER ) + cap = java.awt.BasicStroke.JOIN_MITER; + else if( attributes.JoinType == PathJoinType.ROUND ) + cap = java.awt.BasicStroke.JOIN_ROUND; + else if( attributes.JoinType == PathJoinType.BEVEL ) + cap = java.awt.BasicStroke.JOIN_BEVEL; + else + CanvasUtils.printLog( "applyStrokeAttributes: current join type not yet supported!" ); + + float [] dashArray = null; + + if( attributes.DashArray.length != 0 ) + { + dashArray = new float [attributes.DashArray.length]; + + for( int i=0; i<attributes.DashArray.length; ++i ) + dashArray[i] = (float)attributes.DashArray[i]; + } + + graphics.setStroke( new java.awt.BasicStroke( (float)attributes.StrokeWidth, + cap, + join, + (float)attributes.MiterLimit, + dashArray, + 0) ); + } + + public static void setupGraphicsFont( java.awt.Graphics2D graphics, + ViewState viewState, + RenderState renderState, + drafts.com.sun.star.rendering.XCanvasFont xFont ) + { + if( xFont instanceof CanvasFont ) + { + CanvasUtils.printLog( "setupGraphicsFont: font impl used." ); + graphics.setFont( ((CanvasFont)xFont).getFont() ); + } + else + { + CanvasUtils.printLog( "setupGraphicsFont: creating Java font anew." ); + CanvasFont canvasFont; + canvasFont = new CanvasFont( xFont.getFontRequest(), null ); + graphics.setFont( canvasFont.getFont() ); + } + } + + static java.awt.geom.Rectangle2D.Double calcTransformedRectBounds( java.awt.geom.Rectangle2D.Double aRect, + AffineTransform aTransform ) + { + // transform rect by given transformation + java.awt.geom.Point2D.Double aPointTopLeft = new java.awt.geom.Point2D.Double(aRect.x, aRect.y); + aTransform.transform(aPointTopLeft, aPointTopLeft); + + java.awt.geom.Point2D.Double aPointTopRight = new java.awt.geom.Point2D.Double(aRect.x + aRect.width, + aRect.y); + aTransform.transform(aPointTopRight, aPointTopRight); + + java.awt.geom.Point2D.Double aPointBottomLeft = new java.awt.geom.Point2D.Double(aRect.x, + aRect.y + aRect.height); + aTransform.transform(aPointBottomLeft, aPointBottomLeft); + + java.awt.geom.Point2D.Double aPointBottomRight = new java.awt.geom.Point2D.Double(aRect.x + aRect.width, + aRect.y + aRect.height); + aTransform.transform(aPointBottomRight, aPointBottomRight); + + // calc bounding rect of those four points + java.awt.geom.Point2D.Double aResTopLeft = new java.awt.geom.Point2D.Double( Math.min(aPointTopLeft.x, + Math.min(aPointTopRight.x, + Math.min(aPointBottomLeft.x,aPointBottomRight.x))), + Math.min(aPointTopLeft.y, + Math.min(aPointTopRight.y, + Math.min(aPointBottomLeft.y,aPointBottomRight.y))) ); + + java.awt.geom.Point2D.Double aResBottomRight = new java.awt.geom.Point2D.Double( Math.max(aPointTopLeft.x, + Math.max(aPointTopRight.x, + Math.max(aPointBottomLeft.x,aPointBottomRight.x))), + Math.max(aPointTopLeft.y, + Math.max(aPointTopRight.y, + Math.max(aPointBottomLeft.y,aPointBottomRight.y))) ); + return new java.awt.geom.Rectangle2D.Double( aResTopLeft.x, aResTopLeft.y, + aResBottomRight.x - aResTopLeft.x, + aResBottomRight.y - aResTopLeft.y ); + } + + // Create a corrected view transformation out of the give one, + // which ensures that the rectangle given by (0,0) and + // attributes.untransformedSize is mapped with its left,top corner + // to (0,0) again. This is required to properly render sprite + // animations to buffer bitmaps. + public static ViewState createAnimationViewState( ViewState inputViewState, + AnimationAttributes attributes ) + { + // TODO: Properly respect clip here. Might have to be transformed, too. + + AffineTransform aViewTransform = makeTransform( inputViewState.AffineTransform ); + + // transform Rect(0,0,attributes.untransformedSize) by + // viewTransform + java.awt.geom.Rectangle2D.Double aTransformedRect = + calcTransformedRectBounds( new java.awt.geom.Rectangle2D.Double(0.0, 0.0, + attributes.UntransformedSize.Width, + attributes.UntransformedSize.Height), + aViewTransform ); + + printTransform( aViewTransform, "createAnimationViewState" ); + + CanvasUtils.printLog( "createAnimationViewState: transformed origin is: (" + aTransformedRect.x + ", " + aTransformedRect.y + ")" ); + + // now move resulting left,top point of bounds to (0,0) + AffineTransform animationViewTransform = new AffineTransform(); + animationViewTransform.translate( -aTransformedRect.x, -aTransformedRect.y ); + animationViewTransform.concatenate( aViewTransform ); + + printTransform( animationViewTransform, "createAnimationViewState" ); + + return new ViewState( makeAffineMatrix2D( animationViewTransform ), inputViewState.Clip ); + } + + public static void postRenderImageTreatment( Image buffer ) + { + // TODO: This is specific to Sun's JREs 1.4 and upwards. Make this more portable + buffer.flush(); // as long as we force images to VRAM, + // we need to flush them afterwards, to + // avoid eating up all VRAM. + } + + public static void printTransform( AffineTransform transform, + String stringPrefix ) + { + CanvasUtils.printLog( stringPrefix + ": Transform is" ); + double [] matrix = new double[6]; + transform.getMatrix(matrix); + int i; + for( i=0; i<6; ++i ) + System.err.print( matrix[i] + ", " ); + CanvasUtils.printLog( "" ); + } + + public static void preCondition( boolean bCondition, + String methodName ) + { + if( !bCondition ) + printLog("Precondition violated: " + methodName); + } + + public static void printLog( String s ) + { + System.err.println( s ); + } +} diff --git a/canvas/source/java/JavaCanvas.java b/canvas/source/java/JavaCanvas.java new file mode 100644 index 000000000000..a556b457a4af --- /dev/null +++ b/canvas/source/java/JavaCanvas.java @@ -0,0 +1,624 @@ +/************************************************************************* + * + * $RCSfile: JavaCanvas.java,v $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +// UNO +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.IQueryInterface; +import com.sun.star.lang.XInitialization; +import com.sun.star.lib.uno.helper.WeakBase; + +// OOo AWT +import com.sun.star.awt.*; + +// Canvas +import drafts.com.sun.star.rendering.*; +import drafts.com.sun.star.geometry.*; + +// Java AWT +import java.awt.*; +import java.awt.image.*; +import java.awt.geom.*; + +// system-dependent stuff +import sun.awt.*; + + +public class JavaCanvas + extends CanvasBase + implements com.sun.star.awt.XWindow, + drafts.com.sun.star.rendering.XSpriteCanvas, + com.sun.star.lang.XServiceInfo, + com.sun.star.lang.XInitialization +{ + private WindowAdapter dummyFrame; + private BackBuffer backBuffer; + private java.awt.image.BufferStrategy bufferStrategy; + + private java.awt.Font fpsFont; + private long lastTime; + + public Graphics2D getGraphics() + { + return backBuffer.getGraphics(); + } + + //---------------------------------------------------------------------------------- + + // + // XInitialization + // =============== + // + public void initialize( java.lang.Object[] arguments ) + { + CanvasUtils.printLog( "JavaCanvas.initialize called!" ); + + // Do that as the very first thing. The Java2D internal + // classes choose their render path at initialization time, + // thus this must happen before doing _any_ GUI. + + // TODO: Put those flags into javarc/java.ini, we're maybe + // coming late into a running JVM! + + // now, we're getting slightly system dependent here. + String os = (String) System.getProperty("os.name"); + + CanvasUtils.printLog( "System detected: " + os ); + + // tweak some speed knobs... + if( os.startsWith("Windows") ) + { + System.setProperty("sun.java2d.translaccel", "true"); + System.setProperty("sun.java2d.ddforcevram", "true"); + //System.setProperty("sun.java2d.accthreshold", "0"); + + CanvasUtils.printLog( "Optimizing for Windows" ); + } + else + { + System.setProperty("sun.java2d.opengl", "true"); + + CanvasUtils.printLog( "Optimizing for Unix" ); + } + + /* we're initialized with the following array of anys: + + arguments[0] = pointer to VCL window + arguments[1] = Integer (operating system window handle) + arguments[2] = com.sun.star.awt.Rectangle (position and size within that OS window) + arguments[3] = boolean (fullsize window or not) + + We then generate a dummy Java frame with that window as the + parent, to fake a root window for the Java implementation. + */ + try + { + com.sun.star.awt.Rectangle boundRect = (com.sun.star.awt.Rectangle) arguments[2]; + + //boolean isFullScreen = arguments[1]; + boolean isFullScreen = true; + //AnyConverter.toBoolean( arguments[3] ) ); + + // fake a root for Java in VCL window. Pass the flag + // whether we shall run fullscreen, too. + dummyFrame = new WindowAdapter( AnyConverter.toInt( arguments[1] ), isFullScreen ); + + if( isFullScreen ) + { + // blow window up to fullscreen. Otherwise, we cannot clear the whole screen, + // which results in ugly flickering + Dimension screenSize = dummyFrame.frame.getToolkit().getScreenSize(); + boundRect.X = 0; + boundRect.Y = 0; + boundRect.Width = screenSize.width-1; + boundRect.Height = screenSize.height-1; + } + + dummyFrame.setPosSize( boundRect.X, boundRect.Y, boundRect.Width, boundRect.Height, (short)0 ); + CanvasUtils.printLog( "Window size: " + boundRect.Width + ", " + boundRect.Height ); + + backBuffer = new BackBuffer( (Graphics2D) dummyFrame.frame.getGraphics(), + Math.max(1,boundRect.Width), + Math.max(1,boundRect.Height) ); + + // TODO: Maybe delay double buffer init until first sprite creation + dummyFrame.frame.createBufferStrategy(2); + bufferStrategy = dummyFrame.frame.getBufferStrategy(); + + if( bufferStrategy.getCapabilities().isPageFlipping() ) + CanvasUtils.printLog( "JavaCanvas.initialize double buffering is using page flipping!" ); + else + CanvasUtils.printLog( "JavaCanvas.initialize double buffering is using blitting!" ); + + lastTime = System.currentTimeMillis(); + fpsFont = new java.awt.Font( "Times", Font.PLAIN, 20 ); + + CanvasUtils.printLog( "JavaCanvas.initialize finished!" ); + } + catch( com.sun.star.lang.IllegalArgumentException e ) + { + CanvasUtils.printLog( "Cannot create EmbeddedFrame within VCL window hierarchy!" ); + } + } + + //---------------------------------------------------------------------------------- + + // + // XComponent + // ========== + // + public void dispose() + { + CanvasUtils.printLog( "JavaCanvas: disposed!" ); + + // destroy all active sprites + java.util.Set entries = activeSprites.entrySet(); + java.util.Iterator iter = entries.iterator(); + + while( iter.hasNext() ) + { + java.util.Map.Entry entry = (java.util.Map.Entry)iter.next(); + if( entry.getValue() != null ) + ((SpriteRep)entry.getValue()).dispose(); + } + + if( bufferStrategy != null ) + bufferStrategy.getDrawGraphics().dispose(); // really necessary? + + if( dummyFrame != null ) + dummyFrame.dispose(); + + if( backBuffer != null) + backBuffer.dispose(); + + bufferStrategy = null; + dummyFrame = null; + backBuffer = null; + + super.dispose(); + } + + //---------------------------------------------------------------------------------- + + public JavaCanvas( XComponentContext xContext ) + { + CanvasUtils.printLog( "JavaCanvas constructor called!" ); + activeSprites = new java.util.HashMap( 33 ); + } + + //---------------------------------------------------------------------------------- + + // + // XWindow interface + // ================= + // + // This is delegated to WindowAdapter! + // + public synchronized void setPosSize( int X, int Y, int Width, int Height, short Flags ) + { + if( dummyFrame != null ) + { + dummyFrame.setPosSize( X, Y, Width, Height, Flags ); + + Width = Math.max(1,Width); + Height= Math.max(1,Height); + + CanvasUtils.printLog( "JavaCanvas graphics set to " + Width + "," + Height ); + backBuffer.setSize(Width,Height); + } + } + + public synchronized com.sun.star.awt.Rectangle getPosSize( ) + { + if( dummyFrame != null ) + return dummyFrame.getPosSize(); + + return new com.sun.star.awt.Rectangle(); + } + + public synchronized void setVisible( boolean visible ) + { + if( dummyFrame != null ) + dummyFrame.setVisible( visible ); + } + + public synchronized void setEnable( boolean enable ) + { + if( dummyFrame != null ) + dummyFrame.setEnable( enable ); + } + + public synchronized void setFocus() + { + if( dummyFrame != null ) + dummyFrame.setFocus(); + } + + public synchronized void addWindowListener( XWindowListener xListener ) + { + if( dummyFrame != null ) + dummyFrame.addWindowListener( xListener ); + } + + public synchronized void removeWindowListener( XWindowListener xListener ) + { + if( dummyFrame != null ) + dummyFrame.removeWindowListener( xListener ); + } + + public synchronized void addFocusListener( XFocusListener xListener ) + { + if( dummyFrame != null ) + dummyFrame.addFocusListener( xListener ); + } + + public synchronized void removeFocusListener( XFocusListener xListener ) + { + if( dummyFrame != null ) + dummyFrame.removeFocusListener( xListener ); + } + + public synchronized void addKeyListener( XKeyListener xListener ) + { + if( dummyFrame != null ) + dummyFrame.addKeyListener( xListener ); + } + + public synchronized void removeKeyListener( XKeyListener xListener ) + { + if( dummyFrame != null ) + dummyFrame.removeKeyListener( xListener ); + } + + public synchronized void addMouseListener( XMouseListener xListener ) + { + if( dummyFrame != null ) + dummyFrame.addMouseListener( xListener ); + } + + public synchronized void removeMouseListener( XMouseListener xListener ) + { + if( dummyFrame != null ) + dummyFrame.removeMouseListener( xListener ); + } + + public synchronized void addMouseMotionListener( XMouseMotionListener xListener ) + { + if( dummyFrame != null ) + dummyFrame.addMouseMotionListener( xListener ); + } + + public synchronized void removeMouseMotionListener( XMouseMotionListener xListener ) + { + if( dummyFrame != null ) + dummyFrame.removeMouseMotionListener( xListener ); + } + + public synchronized void addPaintListener( XPaintListener xListener ) + { + if( dummyFrame != null ) + dummyFrame.addPaintListener( xListener ); + } + + public synchronized void removePaintListener( XPaintListener xListener ) + { + if( dummyFrame != null ) + dummyFrame.removePaintListener( xListener ); + } + + //---------------------------------------------------------------------------------- + + // + // XBitmapCanvas impl + // ================== + // + + public synchronized void copyRect( drafts.com.sun.star.rendering.XBitmapCanvas sourceCanvas, + drafts.com.sun.star.geometry.RealRectangle2D sourceRect, + drafts.com.sun.star.rendering.ViewState sourceViewState, + drafts.com.sun.star.rendering.RenderState sourceRenderState, + drafts.com.sun.star.geometry.RealRectangle2D destRect, + drafts.com.sun.star.rendering.ViewState destViewState, + drafts.com.sun.star.rendering.RenderState destRenderState ) + { + CanvasUtils.printLog( "JavaCanvas.copyRect() called" ); + + // TODO: create temp image when transform is non-trivial + + if( sourceCanvas == this ) + { + // copy rectangle within the canvas + getGraphics().copyArea((int)sourceRect.X1, + (int)sourceRect.Y1, + (int)(sourceRect.X2 - sourceRect.X1), + (int)(sourceRect.Y2 - sourceRect.Y1), + (int)(destRect.X1 - sourceRect.X1), + (int)(destRect.Y1 - sourceRect.Y1) ); + } + else + { + if( sourceCanvas instanceof JavaCanvas ) + { + // cache + CanvasUtils.setupGraphicsState( getGraphics(), destViewState, destRenderState, CanvasUtils.alsoSetupPaint ); + + java.awt.Image backBuffer = ((JavaCanvas)sourceCanvas).backBuffer.getBackBuffer(); + + // TODO: really extract correct source rect here + getGraphics().drawImage( backBuffer, 0, 0, null); + CanvasUtils.postRenderImageTreatment( backBuffer ); + } + // TODO: foreign canvas + } + } + + //---------------------------------------------------------------------------------- + + // a map of SpriteReps, with Sprite object as keys. Contains all + // active (i.e. visible) sprites, the SpriteReps are used to + // repaint the sprite content at any time. + private java.util.HashMap activeSprites; + + // + // XSpriteCanvas impl + // ================== + // + + public synchronized drafts.com.sun.star.rendering.XAnimatedSprite createSpriteFromAnimation( XAnimation animation ) + { + CanvasUtils.printLog( "JavaCanvas.createSpriteFromAnimation called" ); + + return new CanvasSprite( animation, this, (Graphics2D)dummyFrame.frame.getGraphics() ); + } + + public synchronized XAnimatedSprite createSpriteFromBitmaps( drafts.com.sun.star.rendering.XBitmap[] animationBitmaps, + short interpolationMode ) + { + return null; + } + + public synchronized XCustomSprite createCustomSprite( RealSize2D spriteSize ) + { + CanvasUtils.printLog( "JavaCanvas.createCustomSprite called" ); + + return new CanvasCustomSprite( spriteSize, this, (Graphics2D)dummyFrame.frame.getGraphics() ); + } + + public synchronized XSprite createClonedSprite( XSprite original ) + { + return new CanvasClonedSprite( this, original ); + } + + public synchronized boolean updateScreen() + { + redrawAllLayers(); + + return true; + } + + //---------------------------------------------------------------------------------- + + // + // XSpriteCanvas helper + // ==================== + // + public synchronized void renderAnimation( CanvasSprite sprite, XAnimation animation, double t ) + { + SpriteRep spriteRep = (SpriteRep)activeSprites.get( sprite ); + if( spriteRep != null ) + { + //Graphics2D graph = getWindowGraphics(); + + // TODO: ensure update of graphics object externally, e.g. when + // VCL moves the toplevel window. + //java.awt.Rectangle bounds = dummyFrame.frame.getBounds(); + //graphics.setGraphics(graph, bounds.width, bounds.height); + + spriteRep.renderAnimation( animation, sprite.getViewState(), t ); + } + else + { + CanvasUtils.printLog( "JavaCanvas.renderAnimation sprite not active!" ); + } + } + + public synchronized void showSprite( SpriteBase sprite ) + { + CanvasUtils.printLog( "JavaCanvas.showSprite() called" ); + + SpriteRep spriteRep = (SpriteRep)activeSprites.get( sprite ); + if( spriteRep != null ) + { + CanvasUtils.printLog( "JavaCanvas.showSprite sprite already active!" ); + } + else + { + spriteRep = sprite.getSpriteRep(); + + // a valid SpriteRep for a given Sprite in the + // activeSprites hash denotes 'sprite active' + activeSprites.put( sprite, spriteRep ); + + // TODO: TEMP! Just for testing! Set empty cursor for presentation +// dummyFrame.frame.setCursor( dummyFrame.frame.getToolkit().createCustomCursor(new java.awt.image.BufferedImage(0,0, +// java.awt.image.BufferedImage.TYPE_INT_RGB), +// new java.awt.Point(0,0), +// "") ); + } + } + + public synchronized void hideSprite( SpriteBase sprite ) + { + CanvasUtils.printLog( "JavaCanvas.hideSprite() called" ); + + SpriteRep spriteRep = (SpriteRep)activeSprites.get( sprite ); + if( spriteRep != null ) + { + activeSprites.put( sprite, null ); + redrawAllLayers(); + } + else + { + CanvasUtils.printLog( "JavaCanvas.hideSprite sprite not active!" ); + } + } + + private void redrawAllLayers() + { + // fetch the Graphics object to draw into (we're doing double + // buffering here, the content is later shown via + // bufferStrategy.show(). + Graphics2D graph = null; + + try + { + graph = (Graphics2D)bufferStrategy.getDrawGraphics(); + + GraphicsDevice device = graph.getDeviceConfiguration().getDevice(); + CanvasUtils.printLog( "Available vram: " + device.getAvailableAcceleratedMemory() ); + + // repaint background + //backBuffer.redraw( graph ); + + // repaint all active sprites + java.util.Set entries = activeSprites.entrySet(); + java.util.Iterator iter = entries.iterator(); + while( iter.hasNext() ) + { + java.util.Map.Entry entry = (java.util.Map.Entry)iter.next(); + if( entry.getValue() != null ) + ((SpriteRep)entry.getValue()).redraw(graph); + } + + long currTime = System.currentTimeMillis(); + graph.setComposite( AlphaComposite.getInstance(AlphaComposite.SRC_OVER) ); + graph.setFont( fpsFont ); + graph.setColor( java.awt.Color.black ); + + try + { + String fps = new String( String.valueOf(1000.0/(currTime-lastTime)) ); + graph.drawString( fps.substring(0,5) + " fps", 0, 20); + CanvasUtils.printLog( fps.substring(0,5) + " fps" ); + } + catch( Exception e ) + { + graph.drawString( "0 fps", 0, 20); + } + + lastTime = currTime; + } + catch( Exception e ) + { + CanvasUtils.printLog( "Exception thrown in redrawAllLayers" ); + } + finally + { + if( graph != null ) + graph.dispose(); + } + + bufferStrategy.show(); + } + + //---------------------------------------------------------------------------------- + + private static final String s_implName = "XCanvas.java.impl"; + private static final String s_serviceName = "drafts.com.sun.star.rendering.Canvas"; + + //---------------------------------------------------------------------------------- + + // + // XServiceInfo impl + // ================= + // + public synchronized String getImplementationName() + { + return s_implName; + } + + public synchronized String [] getSupportedServiceNames() + { + return new String [] { s_serviceName }; + } + + public synchronized boolean supportsService( String serviceName ) + { + return serviceName.equals( s_serviceName ); + } + + public static com.sun.star.lang.XSingleServiceFactory __getServiceFactory( + String implName, + com.sun.star.lang.XMultiServiceFactory multiFactory, + com.sun.star.registry.XRegistryKey regKey ) + { + if (implName.equals( s_implName )) + { + return com.sun.star.comp.loader.FactoryHelper.getServiceFactory( + JavaCanvas.class, s_serviceName, multiFactory, regKey ); + } + return null; + } + + public static boolean __writeRegistryServiceInfo( + com.sun.star.registry.XRegistryKey regKey ) + { + return com.sun.star.comp.loader.FactoryHelper.writeRegistryServiceInfo( + s_implName, s_serviceName, regKey ); + } +} diff --git a/canvas/source/java/LinePolyPolygon.java b/canvas/source/java/LinePolyPolygon.java new file mode 100644 index 000000000000..7f6d12c2d1b5 --- /dev/null +++ b/canvas/source/java/LinePolyPolygon.java @@ -0,0 +1,235 @@ +/************************************************************************* + * + * $RCSfile: LinePolyPolygon.java,v $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +// UNO +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.AnyConverter; +import com.sun.star.lib.uno.helper.WeakBase; + +// OOo AWT +import com.sun.star.awt.*; + +// Canvas +import drafts.com.sun.star.rendering.*; +import drafts.com.sun.star.geometry.*; + +// system-dependent stuff +import sun.awt.*; + + +public class LinePolyPolygon + extends com.sun.star.lib.uno.helper.ComponentBase + implements com.sun.star.lang.XServiceInfo, + drafts.com.sun.star.rendering.XLinePolyPolygon2D +{ + private java.awt.geom.GeneralPath path; + + //---------------------------------------------------------------------------------- + + public LinePolyPolygon( RealPoint2D[][] points ) + { + setPoints( points, 0, 0 ); + } + + public java.awt.geom.GeneralPath getJavaPath() + { + return path; + } + + //---------------------------------------------------------------------------------- + + // + // XPolyPolygon implementation + // =========================== + // + public synchronized void addPolyPolygon( RealPoint2D position, XPolyPolygon2D polyPolygon ) + { + } + + public synchronized int getNumberOfPolygons( ) + { + return 0; + } + + public synchronized int getNumberOfPolygonPoints( int polygon ) + { + return 0; + } + + public synchronized FillRule getFillRule( ) + { + if( path.getWindingRule() == java.awt.geom.GeneralPath.WIND_EVEN_ODD ) + return FillRule.EVEN_ODD; + else + return FillRule.NON_ZERO; + } + + public synchronized void setFillRule( FillRule fillRule ) + { + if( fillRule == FillRule.EVEN_ODD ) + path.setWindingRule( java.awt.geom.GeneralPath.WIND_EVEN_ODD ); + else + path.setWindingRule( java.awt.geom.GeneralPath.WIND_NON_ZERO ); + } + + public synchronized boolean isClosed( int index ) + { + // TODO + return false; + } + + public synchronized void setClosed( int index, boolean closedState ) + { + // TODO + } + + //---------------------------------------------------------------------------------- + + // + // XLinePolyPolygon implementation + // =============================== + // + public synchronized RealPoint2D[][] getPoints( int nPolygonIndex, int nNumberOfPolygons, int nPointIndex, int nNumberOfPoints ) + { + // TODO: Implement subsetting + +// double [] points = new double[6]; + +// // BAH! Use util.Vector here! + +// // find number of subpaths +// PathIterator aIter = path.getPathIterator( new AffineTransform() ); +// int nNumSubPaths = 0; +// while( !aIter.isDone() ) +// { +// if( aIter.currentSegment(points) == SEG_MOVETO ) +// ++nNumSubPaths; + +// aIter.next(); +// } + +// Point2D [][] aRes = new Point2D[nNumSubPaths][]; +// aIter = path.getPathIterator( new AffineTransform() ); +// while( !aIter.isDone() ) +// { +// switch( aIter.currentSegment(points) ) +// { +// case SEG_MOVETO: +// break; + +// case SEG_LINETO: +// break; + +// case SEG_CLOSE: +// break; + +// default: +// CanvasUtils.printLog( "LinePolyPolygon.getPoints(): unexpected path type" ); +// break; +// } + +// aIter.next(); +// } +// double [] points = new double[6]; + + return null; + } + + public synchronized void setPoints( RealPoint2D[][] points, int nPolygonIndex, int nPointIndex ) + { + if( nPolygonIndex != 0 || nPointIndex != 0 ) + CanvasUtils.printLog( "LinePolyPolygon.setPoints: subset not yet implemented!" ); + + path = CanvasUtils.makeGenPathFromLinePoints( points ); + } + + public synchronized RealPoint2D getPoint( int nPolygonIndex, int nPointIndex ) + { + return null; + } + + public synchronized void setPoint( RealPoint2D point, int nPolygonIndex, int nPointIndex ) + { + CanvasUtils.printLog( "LinePolyPolygon.setPoint: not yet implemented!" ); + } + + //---------------------------------------------------------------------------------- + + // + // XServiceInfo impl + // ================= + // + + private static final String s_implName = "XLinePolyPolygon2D.java.impl"; + private static final String s_serviceName = "drafts.com.sun.star.rendering.LinePolyPolygon2D"; + + public String getImplementationName() + { + return s_implName; + } + + public String [] getSupportedServiceNames() + { + return new String [] { s_serviceName }; + } + + public boolean supportsService( String serviceName ) + { + return serviceName.equals( s_serviceName ); + } +} diff --git a/canvas/source/java/SpriteBase.java b/canvas/source/java/SpriteBase.java new file mode 100644 index 000000000000..29d3dcc0de98 --- /dev/null +++ b/canvas/source/java/SpriteBase.java @@ -0,0 +1,84 @@ +/************************************************************************* + * + * $RCSfile: SpriteBase.java,v $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +// UNO +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.IQueryInterface; +import com.sun.star.lang.XInitialization; +import com.sun.star.lib.uno.helper.WeakBase; + +// OOo AWT +import com.sun.star.awt.*; + +// Canvas +import drafts.com.sun.star.rendering.*; + +// Java AWT +import java.awt.*; +import java.awt.geom.*; + +// system-dependent stuff +import sun.awt.*; + + +public interface SpriteBase +{ + // to be overridden + public SpriteRep getSpriteRep(); +} diff --git a/canvas/source/java/SpriteRep.java b/canvas/source/java/SpriteRep.java new file mode 100644 index 000000000000..5c9b1ce0fdb7 --- /dev/null +++ b/canvas/source/java/SpriteRep.java @@ -0,0 +1,220 @@ +/************************************************************************* + * + * $RCSfile: SpriteRep.java,v $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +// UNO +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.IQueryInterface; +import com.sun.star.lang.XInitialization; +import com.sun.star.lib.uno.helper.WeakBase; + +// OOo AWT +import com.sun.star.awt.*; + +// Canvas +import drafts.com.sun.star.rendering.*; + +// Java AWT +import java.awt.*; +import java.awt.geom.*; + +// system-dependent stuff +import sun.awt.*; + + +public class SpriteRep +{ + private java.awt.image.BufferedImage buffer; + private BitmapCanvas bitmapCanvas; + private double alpha; + private java.awt.geom.Point2D.Double outputPosition; + private boolean bufferOwned; + + //---------------------------------------------------------------------------------- + + // TODO: Everything in this class + // TODO: Implement lifetime control for buffer object, which is shared between SpriteReps + public SpriteRep() + { + CanvasUtils.printLog( "SpriteRep constructor called!" ); + + alpha = 0.0; + outputPosition = new java.awt.geom.Point2D.Double(0.0,0.0); + bufferOwned = true; // the buffer member is our own, and has to be disposed + } + + public SpriteRep( SpriteRep original ) + { + CanvasUtils.printLog( "SpriteRep clone constructor called!" ); + + alpha = 0.0; + outputPosition = new java.awt.geom.Point2D.Double(0.0,0.0); + cloneBuffer( original ); + bufferOwned = false; // the buffer member is not our own, and must not be disposed + } + + //---------------------------------------------------------------------------------- + + public synchronized void renderAnimation( XAnimation animation, ViewState viewState, double t ) + { + if( bitmapCanvas != null ) + { + // clear buffer with all transparent + Graphics2D bitmapGraphics = bitmapCanvas.getGraphics(); + + // before that, setup _everything_ we might have changed in CanvasUtils.setupGraphicsState + bitmapGraphics.setColor( new Color( 0.0f, 0.0f, 0.0f, 1.0f ) ); + bitmapGraphics.setComposite( + java.awt.AlphaComposite.getInstance(java.awt.AlphaComposite.CLEAR)); + bitmapGraphics.setTransform( new AffineTransform() ); + bitmapGraphics.setClip( new java.awt.Rectangle(0,0,buffer.getWidth(),buffer.getHeight()) ); + bitmapGraphics.fillRect(0,0,buffer.getWidth(),buffer.getHeight()); + + try + { + // now push the animation at time instance t into the + // virginal graphics + animation.render(bitmapCanvas, viewState, t); + } + catch( com.sun.star.lang.IllegalArgumentException e ) + { + CanvasUtils.printLog( "Cannot create EmbeddedFrame within VCL window hierarchy!" ); + } + } + } + + public synchronized void setSpriteAlpha( double _alpha ) + { + CanvasUtils.printLog("SpriteRep.setSpriteAlpha called with alpha=" + alpha); + alpha = _alpha; + } + + public synchronized void moveSprite( java.awt.geom.Point2D.Double aNewPos ) + { + outputPosition = aNewPos; + CanvasUtils.printLog( "SpriteRep.moveSprite: moving to (" + outputPosition.x + ", " + outputPosition.y + ")" ); + } + + public synchronized void redraw( Graphics2D output ) + { + if( buffer != null ) + { + CanvasUtils.printLog( "SpriteRep.redraw: compositing with alpha=" + alpha ); + output.setComposite( java.awt.AlphaComposite.getInstance(java.awt.AlphaComposite.SRC_OVER, (float)alpha) ); + + output.drawImage( buffer, + (int)(outputPosition.getX() + .5), + (int)(outputPosition.getY() + .5), + null ); + + //CanvasUtils.postRenderImageTreatment( buffer ); + + CanvasUtils.printLog( "SpriteRep.redraw called, output rect is (" + + outputPosition.getX() + ", " + + outputPosition.getY() + ", " + + buffer.getWidth() + ", " + + buffer.getHeight() + ")" ); + } + } + + public synchronized void setupBuffer( java.awt.Graphics2D graphics, int width, int height ) + { + if( bitmapCanvas != null ) + bitmapCanvas.dispose(); + + if( buffer != null ) + buffer.flush(); + + buffer = graphics.getDeviceConfiguration().createCompatibleImage(Math.max(1,width), + Math.max(1,height), + Transparency.TRANSLUCENT); + bitmapCanvas = new BitmapCanvas(buffer.createGraphics()); + CanvasUtils.initGraphics( bitmapCanvas.getGraphics() ); + + CanvasUtils.printLog( "SpriteRep.setupBuffer called, with dimensions (" + width + ", " + height + ")" ); + } + + public synchronized void cloneBuffer( SpriteRep original ) + { + buffer = original.buffer; + } + + public synchronized drafts.com.sun.star.rendering.XCanvas getContentCanvas() + { + CanvasUtils.printLog( "SpriteRep.getContentCanvas() called" ); + + Graphics2D graphics = bitmapCanvas.getGraphics(); + graphics.setTransform( new AffineTransform() ); + graphics.setComposite( AlphaComposite.getInstance(AlphaComposite.CLEAR)); + graphics.fillRect( 0,0,buffer.getWidth(),buffer.getHeight() ); + + return bitmapCanvas; + } + + public void dispose() + { + if( bitmapCanvas != null ) + bitmapCanvas.dispose(); + + if( buffer != null && bufferOwned ) + buffer.flush(); + + bitmapCanvas = null; + buffer = null; + } +} diff --git a/canvas/source/java/SpriteRunner.java b/canvas/source/java/SpriteRunner.java new file mode 100644 index 000000000000..d38faed5e9c0 --- /dev/null +++ b/canvas/source/java/SpriteRunner.java @@ -0,0 +1,249 @@ +/************************************************************************* + * + * $RCSfile: SpriteRunner.java,v $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +// UNO +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.IQueryInterface; +import com.sun.star.lang.XInitialization; +import com.sun.star.lib.uno.helper.WeakBase; + +// OOo AWT +import com.sun.star.awt.*; + +// Canvas +import drafts.com.sun.star.rendering.*; + +// Java AWT +import java.awt.*; +import java.awt.geom.*; + +// system-dependent stuff +import sun.awt.*; + + +// +// HOWTO get a Graphics2D from a window +// + +// import javax.swing.*; +// import java.awt.*; +// import java.awt.geom.*; + +// public class Stroke1 extends JFrame { +// Stroke drawingStroke = new BasicStroke(5); +// Rectangle2D rect = +// new Rectangle2D.Double(20, 40, 100, 40); + +// public void paint(Graphics g) { +// Graphics2D g2d = (Graphics2D)g; +// g2d.setStroke(drawingStroke); +// g2d.draw(rect); +// } + +// public static void main(String args[]) { +// JFrame frame = new Stroke1(); +// frame.setDefaultCloseOperation(EXIT_ON_CLOSE); +// frame.setSize(200, 100); +// frame.show(); +// } +// } + + +public class SpriteRunner + extends Thread +{ + private CanvasSprite sprite; + private XAnimation spriteAnimation; + private JavaCanvas canvas; + private double startTime; + private double currentSpeed; + private double currentT; + private boolean animationActive; + private boolean stayAlive; + + //---------------------------------------------------------------------------------- + + public SpriteRunner( CanvasSprite _sprite, XAnimation _animation, JavaCanvas _canvas ) + { + CanvasUtils.printLog( "SpriteRunner constructor called!" ); + + sprite = _sprite; + spriteAnimation = _animation; + canvas = _canvas; + startTime = 0.0; + currentSpeed = 0.0; + currentT = 0.0; + animationActive = false; + stayAlive = true; + + // Set priority to lower-than-normal, as this thread runs the + // animation in a busy loop. + setPriority( MIN_PRIORITY ); + } + + //---------------------------------------------------------------------------------- + + // + // Thread + // ====== + // + // Overriding + // + public void run() + { + // perform the animation rendering (as fast as possible, for now) + + while( stayAlive ) + { + while( animationActive ) + { + // to determine the current animation step to render, calc the + // elapsed time since this animation was started + double elapsedTime = getCurrentTime() - startTime; + + // the frame to render is determined by mapping the cycle + // duration (currentSpeed) to the [0,1] range of the animation. + currentT = (elapsedTime % currentSpeed) / currentSpeed; + + // delegate animation rendering to SpriteCanvas, as + // only this instance can enforce consistency (on-time + // saving of background etc.) + canvas.renderAnimation( sprite, spriteAnimation, currentT ); + + // TODO: Consolidate _all_ sprites per canvas into one + // thread, call updateScreen() only after all sprites + // have been processed. + + //Make changes visible + canvas.updateScreen(); + + // TODO: Evaluate vs. setPriority and other means +// try +// { +// // give other tasks some time to breathe (10ms - this is only meant symbolically) +// sleep(10); +// } catch( InterruptedException e ) { } + } + + // wait until animation is activated again + try + { + wait(); + } + catch( InterruptedException e ) { } + catch( IllegalMonitorStateException e ) { } + } + } + + public synchronized void startAnimation( double speed ) + { + resetAnimation(); + currentSpeed = speed; + + // start us, if not done already + if( !isAlive() ) + start(); + + // enable animation thread + animationActive = true; + + try + { + notify(); + } catch( IllegalMonitorStateException e ) { } + } + + public synchronized void stopAnimation() + { + // stop animation after the current frame has been completely + // rendered + animationActive = false; + } + + public synchronized void resetAnimation() + { + startTime = getCurrentTime(); + } + + public synchronized boolean isAnimationActive() + { + return animationActive; + } + + public synchronized void quit() + { + stayAlive = false; + stopAnimation(); + } + + public synchronized double getCurrentT() + { + return currentT; + } + + //---------------------------------------------------------------------------------- + + // helper + static double getCurrentTime() + { + // determine current time in seconds + java.util.Calendar cal = new java.util.GregorianCalendar(); + return cal.getTimeInMillis() / 1000.0; + } +} diff --git a/canvas/source/java/java_Service.java b/canvas/source/java/java_Service.java new file mode 100644 index 000000000000..6fcaa1581ca8 --- /dev/null +++ b/canvas/source/java/java_Service.java @@ -0,0 +1,118 @@ + +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.awt.*; + +public class java_Service + extends com.sun.star.lib.uno.helper.WeakBase + implements com.sun.star.lang.XServiceInfo, foo.XBar +{ + private XToolkit m_xToolkit; + private XVclWindowPeer m_xPeer; + private javax.swing.JFrame m_frame; + + public java_Service( XComponentContext xContext ) + { + try + { + m_xToolkit = + (XToolkit) UnoRuntime.queryInterface( + XToolkit.class, + xContext.getServiceManager().createInstanceWithContext( + "com.sun.star.awt.Toolkit", xContext ) ); + } + catch (com.sun.star.uno.Exception exc) + { + throw new com.sun.star.uno.RuntimeException( + "exception occured gettin toolkit: " + exc, this ); + } + } + + // XBar impl + public void raiseAndCloseWindows( foo.XBar [] seq ) + throws com.sun.star.uno.Exception + { + for ( int nPos = 0; nPos < seq.length; ++nPos ) + seq[ nPos ].raiseWindows( "called by Java code" ); + + // modal dialog before closing + javax.swing.JOptionPane.showMessageDialog( + null, "[Java] all windows created." ); + + for ( int nPos = 0; nPos < seq.length; ++nPos ) + seq[ nPos ].closeWindows(); + } + + public void raiseWindows( String msg ) + throws com.sun.star.uno.Exception + { + // create java frame + m_frame = new javax.swing.JFrame( + "[java frame created by Java code] " + msg ); + m_frame.setSize( 500, 50 ); + m_frame.setLocation( 200, 500 ); + m_frame.setVisible( true ); + + // create office workwindow + m_xPeer = (XVclWindowPeer) UnoRuntime.queryInterface( + XVclWindowPeer.class, + m_xToolkit.createWindow( + new WindowDescriptor( + WindowClass.TOP, "workwindow", null, (short) -1, + new Rectangle( 800, 500, 500, 50 ), + WindowAttribute.SHOW | + WindowAttribute.BORDER | + WindowAttribute.SIZEABLE | + WindowAttribute.MOVEABLE | + WindowAttribute.CLOSEABLE ) ) ); + m_xPeer.setProperty( + "Title", "[office window created by Java code] " + msg ); + } + + public void closeWindows() + throws com.sun.star.uno.Exception + { + m_frame.dispose(); + m_xPeer.dispose(); + } + + + private static final String s_implName = "foo.java.impl"; + private static final String s_serviceName = "foo.java"; + + // XServiceInfo impl + public String getImplementationName() + { + return s_implName; + } + + public String [] getSupportedServiceNames() + { + return new String [] { s_serviceName }; + } + + public boolean supportsService( String serviceName ) + { + return serviceName.equals( s_serviceName ); + } + + public static com.sun.star.lang.XSingleServiceFactory __getServiceFactory( + String implName, + com.sun.star.lang.XMultiServiceFactory multiFactory, + com.sun.star.registry.XRegistryKey regKey ) + { + if (implName.equals( s_implName )) + { + return com.sun.star.comp.loader.FactoryHelper.getServiceFactory( + java_Service.class, s_serviceName, multiFactory, regKey ); + } + return null; + } + + public static boolean __writeRegistryServiceInfo( + com.sun.star.registry.XRegistryKey regKey ) + { + return com.sun.star.comp.loader.FactoryHelper.writeRegistryServiceInfo( + s_implName, s_serviceName, regKey ); + } +} diff --git a/canvas/source/java/makefile.mk b/canvas/source/java/makefile.mk new file mode 100644 index 000000000000..ebd3fecc2436 --- /dev/null +++ b/canvas/source/java/makefile.mk @@ -0,0 +1,94 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.2 $ +# +# last change: $Author: thb $ $Date: 2004-03-18 10:38:33 $ +# +# The Contents of this file are made available subject to the terms of +# the BSD license. +# +# Copyright (c) 2003 by Sun Microsystems, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of Sun Microsystems, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +#************************************************************************** + +# Builds the Java Canvas implementation. + +PRJNAME = canvas +PRJ = ..$/.. +TARGET = javacanvas +PACKAGE = canvas + +# --- Settings ----------------------------------------------------- + +.INCLUDE: settings.mk + +.IF "$(SOLAR_JAVA)"=="TRUE" + +JAVAFILES = \ + SpriteBase.java \ + JavaCanvas.java \ + CanvasGraphicDevice.java \ + CanvasUtils.java \ + CanvasFont.java \ + CanvasBitmap.java \ + CanvasSprite.java \ + CanvasCustomSprite.java \ + CanvasClonedSprite.java \ + BackBuffer.java \ + LinePolyPolygon.java \ + BezierPolyPolygon.java \ + SpriteRunner.java + +.IF "$(GUIBASE)"!="unx" + +JAVAFILES += win/WindowAdapter.java + +.ELSE # "$(GUIBASE)"!="unx" + +JAVAFILES += x11/WindowAdapter.java + +.ENDIF # "$(GUIBASE)"!="unx" + +JARFILES = sandbox.jar jurt.jar unoil.jar ridl.jar juh.jar java_uno.jar +JAVACLASSFILES = $(foreach,i,$(JAVAFILES) $(CLASSDIR)$/$(PACKAGE)$/$(i:b).class) + +JARTARGET = $(TARGET).uno.jar +JARCOMPRESS = TRUE +#JARCLASSDIRS = $(PACKAGE) +CUSTOMMANIFESTFILE = manifest + +.ENDIF # "$(SOLAR_JAVA)"=="TRUE" + +# --- Targets ------------------------------------------------------ + +.INCLUDE: target.mk + +#dist: $(JAVA_FILES:b:+".class") +# +jar -cvfm $(CLASSDIR)/JavaCanvas.jar $(JARMANIFEST) $(JAVACLASSFILES) diff --git a/canvas/source/java/manifest b/canvas/source/java/manifest new file mode 100644 index 000000000000..6ddc3ab0ae51 --- /dev/null +++ b/canvas/source/java/manifest @@ -0,0 +1 @@ +RegistrationClassName: JavaCanvas diff --git a/canvas/source/java/perftest/PerfTest.java b/canvas/source/java/perftest/PerfTest.java new file mode 100644 index 000000000000..715df2559ed5 --- /dev/null +++ b/canvas/source/java/perftest/PerfTest.java @@ -0,0 +1,344 @@ +/************************************************************************* + * + * $RCSfile: PerfTest.java,v $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +import java.awt.*; +import java.awt.image.*; +import java.awt.geom.*; + + +public class PerfTest +{ + // the frame object we're generating. TODO: Remove public access. + private Frame frame; + private boolean fullscreen; + + public PerfTest() + { + fullscreen = false; + + // create a normal Java frame, and set it into fullscreen mode + frame = new javax.swing.JFrame( "PerformanceTest" ); + frame.setBounds( new Rectangle(0,0,1600,1200) ); + frame.setUndecorated( true ); + frame.setVisible( true ); + + Graphics2D graphics = (Graphics2D)frame.getGraphics(); + if( graphics.getDeviceConfiguration().getDevice().isFullScreenSupported() ) + { + System.err.println( "entering fullscreen mode" ); + graphics.getDeviceConfiguration().getDevice().setFullScreenWindow( frame ); + fullscreen = true; + } + else + { + System.err.println( "fullscreen not supported" ); + } + + graphics.dispose(); + } + + //---------------------------------------------------------------------------------- + + public void dispose() + { + if( fullscreen ) + { + Graphics2D graphics = (Graphics2D)frame.getGraphics(); + if( graphics.getDeviceConfiguration().getDevice().isFullScreenSupported() ) + { + System.err.println( "leaving fullscreen mode" ); + graphics.getDeviceConfiguration().getDevice().setFullScreenWindow( null ); + } + graphics.dispose(); + } + + if( frame != null ) + frame.dispose(); + } + + //---------------------------------------------------------------------------------- + + public static void initGraphics( Graphics2D graphics ) + { + if( graphics != null ) + { + RenderingHints hints = new RenderingHints(null); + boolean hq = true; + + if( hq ) + { + hints.add( new RenderingHints( RenderingHints.KEY_FRACTIONALMETRICS, + RenderingHints.VALUE_FRACTIONALMETRICS_ON ) ); +// hints.add( new RenderingHints( RenderingHints.KEY_ALPHA_INTERPOLATION, +// RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY) ); + hints.add( new RenderingHints( RenderingHints.KEY_ALPHA_INTERPOLATION, + RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED) ); +// hints.add( new RenderingHints( RenderingHints.KEY_INTERPOLATION, +// RenderingHints.VALUE_INTERPOLATION_BICUBIC) ); + hints.add( new RenderingHints( RenderingHints.KEY_INTERPOLATION, + RenderingHints.VALUE_INTERPOLATION_BILINEAR) ); +// hints.add( new RenderingHints( RenderingHints.KEY_RENDERING, +// RenderingHints.VALUE_RENDER_QUALITY) ); + hints.add( new RenderingHints( RenderingHints.KEY_RENDERING, + RenderingHints.VALUE_RENDER_SPEED) ); +// hints.add( new RenderingHints( RenderingHints.KEY_STROKE_CONTROL, +// RenderingHints.VALUE_STROKE_NORMALIZE) ); + hints.add( new RenderingHints( RenderingHints.KEY_STROKE_CONTROL, + RenderingHints.VALUE_STROKE_DEFAULT) ); + hints.add( new RenderingHints( RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON) ); + } + else + { + hints.add( new RenderingHints( RenderingHints.KEY_ALPHA_INTERPOLATION, + RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED) ); + hints.add( new RenderingHints( RenderingHints.KEY_INTERPOLATION, + RenderingHints.VALUE_INTERPOLATION_BILINEAR) ); + hints.add( new RenderingHints( RenderingHints.KEY_RENDERING, + RenderingHints.VALUE_RENDER_SPEED) ); + hints.add( new RenderingHints( RenderingHints.KEY_STROKE_CONTROL, + RenderingHints.VALUE_STROKE_DEFAULT) ); + hints.add( new RenderingHints( RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_OFF) ); + } + + // the least common denominator standard + hints.add( new RenderingHints( RenderingHints.KEY_FRACTIONALMETRICS, + RenderingHints.VALUE_FRACTIONALMETRICS_ON) ); + hints.add( new RenderingHints( RenderingHints.KEY_TEXT_ANTIALIASING, + RenderingHints.VALUE_TEXT_ANTIALIAS_ON) ); + + graphics.setRenderingHints( hints ); + } + } + + public void run() + { + frame.createBufferStrategy(2); + BufferStrategy bufferStrategy = frame.getBufferStrategy(); + + if( bufferStrategy.getCapabilities().isPageFlipping() ) + System.err.println( "double buffering is using page flipping" ); + else + System.err.println( "double buffering is using blitting" ); + + int width = 1600; + int height = 1200; + Graphics2D graphics = (Graphics2D)frame.getGraphics(); + VolatileImage backBuffer = graphics.getDeviceConfiguration().createCompatibleVolatileImage(width,height); // TODO: size dynamic + BufferedImage buffer = graphics.getDeviceConfiguration().createCompatibleImage(width,height, + Transparency.TRANSLUCENT); + BufferedImage buffer2 = graphics.getDeviceConfiguration().createCompatibleImage(width,height, + Transparency.TRANSLUCENT); + BufferedImage buffer3 = graphics.getDeviceConfiguration().createCompatibleImage(width,height, + Transparency.TRANSLUCENT); + + GraphicsDevice device = graphics.getDeviceConfiguration().getDevice(); + System.err.println( "Images generated. Available vram: " + device.getAvailableAcceleratedMemory() ); + + Graphics2D bufferGraphics = (Graphics2D)buffer.getGraphics(); + Graphics2D buffer2Graphics = (Graphics2D)buffer2.getGraphics(); + Graphics2D buffer3Graphics = (Graphics2D)buffer3.getGraphics(); + Graphics2D backBufGraphics = (Graphics2D)backBuffer.getGraphics(); + + System.err.println( "Image graphics generated. Available vram: " + device.getAvailableAcceleratedMemory() ); + + // init Graphics + initGraphics( graphics ); + initGraphics( bufferGraphics ); + initGraphics( buffer2Graphics ); + initGraphics( backBufGraphics ); + + // init content + Font font = new Font( "Times", Font.PLAIN, 100 ); + Font fpsFont = new Font( "Times", Font.PLAIN, 20 ); + + bufferGraphics.setComposite( AlphaComposite.getInstance(AlphaComposite.CLEAR)); + bufferGraphics.fillRect( 0,0,width,height ); + + bufferGraphics.setComposite( AlphaComposite.getInstance(AlphaComposite.SRC_OVER)); + bufferGraphics.setColor( Color.red ); + bufferGraphics.fillRect( 0,0,width/2,height/2 ); + bufferGraphics.setColor( Color.green ); + bufferGraphics.fillRect( width/2,0,width,height/2 ); + bufferGraphics.setColor( Color.blue ); + bufferGraphics.fillRect( 0,height/2,width/2,height ); + + buffer2Graphics.setColor( Color.red ); + buffer2Graphics.fillRect( 0,0,width/2,height/2 ); + buffer2Graphics.setColor( Color.green ); + buffer2Graphics.fillRect( width/2,0,width,height/2 ); + buffer2Graphics.setColor( Color.blue ); + buffer2Graphics.fillRect( 0,height/2,width/2,height ); + + buffer3Graphics.setColor( Color.blue ); + buffer3Graphics.fillRect( 0,0,width/2,height/2 ); + buffer3Graphics.setColor( Color.white ); + buffer3Graphics.fillRect( width/2,0,width,height/2 ); + buffer3Graphics.setColor( Color.gray ); + buffer3Graphics.fillRect( 0,height/2,width/2,height ); + + backBufGraphics.setColor( Color.white ); + backBufGraphics.fillRect(0,0,width,height); + backBufGraphics.setColor( Color.red ); + backBufGraphics.setFont( font ); + int i, turns=15; + for(i=0; i<turns; ++i) + { + backBufGraphics.drawString( "Crossfade test", width*i/turns, height*i/turns ); + } + + System.err.println( "Images filled with content. Available vram: " + device.getAvailableAcceleratedMemory() ); + + long lastTime = System.currentTimeMillis(); + int turn, numTurns = 100; + for(turn=0; turn<numTurns; ++turn) + { + // fetch the Graphics object to draw into (we're doing double + // buffering here, the content is later shown via + // bufferStrategy.show(). + Graphics2D graph = null; + + try + { + graph = (Graphics2D)bufferStrategy.getDrawGraphics(); + + try + { + // repaint background + graph.setComposite( AlphaComposite.getInstance(AlphaComposite.SRC_OVER) ); + graph.drawImage(backBuffer, 0, 0, null); + + // alpha-composite foreground on top of that + float alpha = turn/(float)numTurns; + graph.setComposite( AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha) ); + + graph.drawImage(buffer, 0, 0, null); + buffer.flush(); + graph.drawImage(buffer2, 100, 100, null); + buffer2.flush(); + + long currTime = System.currentTimeMillis(); + graph.setComposite( AlphaComposite.getInstance(AlphaComposite.SRC_OVER) ); + graph.setFont( fpsFont ); + graph.setColor( Color.black ); + String fps = new String( String.valueOf(1000.0/(currTime-lastTime)) ); + System.err.println( "Images composited. Framerate: " + fps + " fps" ); + graph.drawString( fps.substring(0,5) + " fps", 0, 20); + lastTime = currTime; + + System.err.println( "Available vram: " + device.getAvailableAcceleratedMemory() ); + } + catch( Exception e ) + { + } + + System.err.println( "Turn: " + turn ); + } + finally + { + if( graph != null ) + graph.dispose(); + } + + bufferStrategy.show(); + } + + try + { + Thread.sleep(2000); + } + catch( Exception e ) + { + } + } + + //---------------------------------------------------------------------------------- + + public static void main(String[] args) + { + // now, we're getting slightly system dependent here. + String os = (String) System.getProperty("os.name"); + + System.err.println( "System detected: " + os ); + + // tweak some speed knobs... + if( os.startsWith("Windows") ) + { + System.setProperty("sun.java2d.translaccel", "true"); + System.setProperty("sun.java2d.ddforcevram", "true"); + //System.setProperty("sun.java2d.accthreshold", "0"); + + System.err.println( "Optimizing for Windows" ); + } + else + { + System.setProperty("sun.java2d.opengl", "true"); + + System.err.println( "Optimizing for Unix" ); + } + + PerfTest test = new PerfTest(); + + test.run(); + + test.dispose(); + } + + //---------------------------------------------------------------------------------- + +} diff --git a/canvas/source/java/perftest/WindowAdapter.java b/canvas/source/java/perftest/WindowAdapter.java new file mode 100644 index 000000000000..978261b18fe5 --- /dev/null +++ b/canvas/source/java/perftest/WindowAdapter.java @@ -0,0 +1,227 @@ +/************************************************************************* + * + * $RCSfile: WindowAdapter.java,v $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +import sun.awt.*; +import com.sun.star.awt.*; + + +public class WindowAdapter +// defacto implementing the interface, but not deriving from it, since +// we're no real XInterface here +// implements com.sun.star.awt.XWindow +{ + // the frame object we're generating. TODO: Remove public access. + public java.awt.Frame frame; + private boolean fullscreen; + + public WindowAdapter( int windowHandle, + boolean _fullscreen ) + { + CanvasUtils.printLog( "WindowAdapter(X11): constructor called" ); + fullscreen = false; + + if( _fullscreen ) + { + // create a normal Java frame, and set it into fullscreen mode + frame = new javax.swing.JFrame( "Presentation" ); + frame.setUndecorated( true ); + frame.setVisible( true ); + + java.awt.Graphics2D graphics = (java.awt.Graphics2D)frame.getGraphics(); + if( graphics.getDeviceConfiguration().getDevice().isFullScreenSupported() ) + { + CanvasUtils.printLog( "WindowAdapter(X11): entering fullscreen mode" ); + graphics.getDeviceConfiguration().getDevice().setFullScreenWindow( frame ); + fullscreen = true; + } + else + { + CanvasUtils.printLog( "WindowAdapter(X11): fullscreen not supported" ); + } + + graphics.dispose(); + } + else + { + // we're initialized with the operating system window handle + // as the parameter. We then generate a dummy Java frame with + // that window as the parent, to fake a root window for the + // Java implementation. + + // now, we're getting slightly system dependent here. + String os = (String) System.getProperty("os.name"); + + System.err.println("WindowAdapter created"); + + // create the embedded frame + if( os.startsWith("Linux") ) + { + // create a java frame from that + // TODO: Maybe that's the reason why we crash on Linux 1.5beta + // immediately: Try XAWT here, or naked X: sun.awt.X11.XEmbeddedFrame + + //frame = new sun.awt.motif.MEmbeddedFrame( windowHandle ); + //frame = new sun.awt.X11.XEmbeddedFrame( windowHandle ); // cannot currently compile + CanvasUtils.printLog( "WindowAdapter(X11): no frame created for now" ); + frame = null; + } + else + { + throw new com.sun.star.uno.RuntimeException(); + } + } + } + + //---------------------------------------------------------------------------------- + + public void dispose() + { + if( fullscreen ) + { + java.awt.Graphics2D graphics = (java.awt.Graphics2D)frame.getGraphics(); + if( graphics.getDeviceConfiguration().getDevice().isFullScreenSupported() ) + { + CanvasUtils.printLog( "WindowAdapter(X11): leaving fullscreen mode" ); + graphics.getDeviceConfiguration().getDevice().setFullScreenWindow( null ); + } + graphics.dispose(); + } + + if( frame != null ) + frame.dispose(); + } + + //---------------------------------------------------------------------------------- + + // + // XWindow interface + // ================= + // + public void setPosSize( int X, int Y, int Width, int Height, short Flags ) + { + frame.setBounds( new java.awt.Rectangle( X, Y, Width, Height ) ); + } + + public com.sun.star.awt.Rectangle getPosSize( ) + { + java.awt.Rectangle bounds = frame.getBounds(); + + return new com.sun.star.awt.Rectangle( bounds.x, bounds.y, bounds.width, bounds.height ); + } + + public void setVisible( boolean visible ) + { + frame.setVisible( visible ); + } + + public void setEnable( boolean enable ) + { + frame.setEnabled( enable ); + } + + public void setFocus() + { + } + + public void addWindowListener( XWindowListener xListener ) + { + } + + public void removeWindowListener( XWindowListener xListener ) + { + } + + public void addFocusListener( XFocusListener xListener ) + { + } + + public void removeFocusListener( XFocusListener xListener ) + { + } + + public void addKeyListener( XKeyListener xListener ) + { + } + + public void removeKeyListener( XKeyListener xListener ) + { + } + + public void addMouseListener( XMouseListener xListener ) + { + } + + public void removeMouseListener( XMouseListener xListener ) + { + } + + public void addMouseMotionListener( XMouseMotionListener xListener ) + { + } + + public void removeMouseMotionListener( XMouseMotionListener xListener ) + { + } + + public void addPaintListener( XPaintListener xListener ) + { + } + + public void removePaintListener( XPaintListener xListener ) + { + } +} diff --git a/canvas/source/java/perftest/makefile.mk b/canvas/source/java/perftest/makefile.mk new file mode 100644 index 000000000000..d1f7fced068f --- /dev/null +++ b/canvas/source/java/perftest/makefile.mk @@ -0,0 +1,68 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.2 $ +# +# last change: $Author: thb $ $Date: 2004-03-18 10:38:34 $ +# +# The Contents of this file are made available subject to the terms of +# the BSD license. +# +# Copyright (c) 2003 by Sun Microsystems, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of Sun Microsystems, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +#************************************************************************** + +# Builds the Java Canvas implementation. + +PRJNAME = canvas +PRJ = ../../.. +TARGET = PerfTest +PACKAGE = test + +# --- Settings ----------------------------------------------------- + +.INCLUDE: settings.mk + +JAVAFILES = \ + PerfTest.java + +JARFILES = sandbox.jar jurt.jar unoil.jar ridl.jar juh.jar java_uno.jar +JAVACLASSFILES = $(foreach,i,$(JAVAFILES) $(CLASSDIR)$/$(PACKAGE)$/$(i:b).class) + +JARTARGET = $(TARGET).jar +JARCOMPRESS = TRUE +#JARCLASSDIRS = $(PACKAGE) +CUSTOMMANIFESTFILE = manifest + +# --- Targets ------------------------------------------------------ + +.INCLUDE: target.mk + +#dist: $(JAVA_FILES:b:+".class") +# +jar -cvfm $(CLASSDIR)/PerfTest.jar $(JARMANIFEST) $(JAVACLASSFILES) diff --git a/canvas/source/java/perftest/manifest b/canvas/source/java/perftest/manifest new file mode 100644 index 000000000000..805a87d47b57 --- /dev/null +++ b/canvas/source/java/perftest/manifest @@ -0,0 +1 @@ +RegistrationClassName: PerfTest diff --git a/canvas/source/java/win/WindowAdapter.java b/canvas/source/java/win/WindowAdapter.java new file mode 100644 index 000000000000..ff0636efe03b --- /dev/null +++ b/canvas/source/java/win/WindowAdapter.java @@ -0,0 +1,229 @@ +/************************************************************************* + * + * $RCSfile: WindowAdapter.java,v $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +// UNO +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.AnyConverter; +import com.sun.star.lang.XInitialization; +import com.sun.star.lib.uno.helper.WeakBase; + +// OOo AWT +import com.sun.star.awt.*; + +// system-dependent stuff +import sun.awt.*; + + +public class WindowAdapter +// defacto implementing the interface, but not deriving from it, since +// we're no real XInterface here +// implements com.sun.star.awt.XWindow +{ + public java.awt.Frame frame; + private boolean fullscreen; + + public WindowAdapter( int windowHandle, + boolean _fullscreen ) + { + fullscreen = false; + + if( _fullscreen ) + { + // create a normal Java frame, and set it into fullscreen mode + frame = new javax.swing.JFrame( "Presentation" ); + frame.setUndecorated( true ); + frame.setVisible( true ); + + java.awt.Graphics2D graphics = (java.awt.Graphics2D)frame.getGraphics(); + if( graphics.getDeviceConfiguration().getDevice().isFullScreenSupported() ) + { + CanvasUtils.printLog( "WindowAdapter(Win32): entering fullscreen mode" ); + graphics.getDeviceConfiguration().getDevice().setFullScreenWindow( frame ); + fullscreen = true; + } + else + { + CanvasUtils.printLog( "WindowAdapter(Win32): fullscreen not supported" ); + } + + graphics.dispose(); + } + else + { + // we're initialized with the operating system window handle + // as the parameter. We then generate a dummy Java frame with + // that window as the parent, to fake a root window for the + // Java implementation. + + // now, we're getting slightly system dependent here. + String os = (String) System.getProperty("os.name"); + + // create the embedded frame + if( os.startsWith("Windows") ) + frame = new sun.awt.windows.WEmbeddedFrame( windowHandle ); + else + throw new com.sun.star.uno.RuntimeException(); + + +// frame = new javax.swing.JFrame( "Test window" ); + +// // resize it according to the given bounds +// frame.setBounds( boundRect ); +// frame.setVisible( true ); + } + } + + //---------------------------------------------------------------------------------- + + public void dispose() + { + if( fullscreen ) + { + java.awt.Graphics2D graphics = (java.awt.Graphics2D)frame.getGraphics(); + if( graphics.getDeviceConfiguration().getDevice().isFullScreenSupported() ) + { + CanvasUtils.printLog( "WindowAdapter(Win32): leaving fullscreen mode" ); + graphics.getDeviceConfiguration().getDevice().setFullScreenWindow( null ); + } + graphics.dispose(); + } + + if( frame != null ) + frame.dispose(); + } + + //---------------------------------------------------------------------------------- + + // + // XWindow interface + // ================= + // + public void setPosSize( int X, int Y, int Width, int Height, short Flags ) + { + frame.setBounds( new java.awt.Rectangle( X, Y, Width, Height ) ); + } + + public com.sun.star.awt.Rectangle getPosSize( ) + { + java.awt.Rectangle bounds = frame.getBounds(); + + return new com.sun.star.awt.Rectangle( bounds.x, bounds.y, bounds.width, bounds.height ); + } + + public void setVisible( boolean visible ) + { + frame.setVisible( visible ); + } + + public void setEnable( boolean enable ) + { + frame.setEnabled( enable ); + } + + public void setFocus() + { + } + + public void addWindowListener( XWindowListener xListener ) + { + } + + public void removeWindowListener( XWindowListener xListener ) + { + } + + public void addFocusListener( XFocusListener xListener ) + { + } + + public void removeFocusListener( XFocusListener xListener ) + { + } + + public void addKeyListener( XKeyListener xListener ) + { + } + + public void removeKeyListener( XKeyListener xListener ) + { + } + + public void addMouseListener( XMouseListener xListener ) + { + } + + public void removeMouseListener( XMouseListener xListener ) + { + } + + public void addMouseMotionListener( XMouseMotionListener xListener ) + { + } + + public void removeMouseMotionListener( XMouseMotionListener xListener ) + { + } + + public void addPaintListener( XPaintListener xListener ) + { + } + + public void removePaintListener( XPaintListener xListener ) + { + } +} diff --git a/canvas/source/java/x11/WindowAdapter.java b/canvas/source/java/x11/WindowAdapter.java new file mode 100644 index 000000000000..94810215074a --- /dev/null +++ b/canvas/source/java/x11/WindowAdapter.java @@ -0,0 +1,228 @@ +/************************************************************************* + * + * $RCSfile: WindowAdapter.java,v $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +import sun.awt.*; +import com.sun.star.awt.*; + + +public class WindowAdapter +// defacto implementing the interface, but not deriving from it, since +// we're no real XInterface here +// implements com.sun.star.awt.XWindow +{ + // the frame object we're generating. TODO: Remove public access. + public java.awt.Frame frame; + private boolean fullscreen; + + public WindowAdapter( int windowHandle, + boolean _fullscreen ) + { + CanvasUtils.printLog( "WindowAdapter(X11): constructor called" ); + fullscreen = false; + + if( _fullscreen ) + { + // create a normal Java frame, and set it into fullscreen mode + frame = new javax.swing.JFrame( "Presentation" ); + frame.setUndecorated( true ); + frame.setVisible( true ); + + java.awt.Graphics2D graphics = (java.awt.Graphics2D)frame.getGraphics(); + if( graphics.getDeviceConfiguration().getDevice().isFullScreenSupported() ) + { + CanvasUtils.printLog( "WindowAdapter(X11): entering fullscreen mode" ); + graphics.getDeviceConfiguration().getDevice().setFullScreenWindow( frame ); + fullscreen = true; + } + else + { + CanvasUtils.printLog( "WindowAdapter(X11): fullscreen not supported" ); + } + + graphics.dispose(); + } + else + { + // we're initialized with the operating system window handle + // as the parameter. We then generate a dummy Java frame with + // that window as the parent, to fake a root window for the + // Java implementation. + + // now, we're getting slightly system dependent here. + String os = (String) System.getProperty("os.name"); + + System.err.println("WindowAdapter created"); + + // create the embedded frame + if( os.startsWith("Linux") ) + { + // create a java frame from that + // TODO: Maybe that's the reason why we crash on Linux 1.5beta + // immediately: Try XAWT here, or naked X: sun.awt.X11.XEmbeddedFrame + + // TODO + //frame = new sun.awt.motif.MEmbeddedFrame( windowHandle ); // Crashes 1.5, because class is unknown + //frame = new sun.awt.X11.XEmbeddedFrame( windowHandle ); // cannot currently compile, because class is not in 1.4. + CanvasUtils.printLog( "WindowAdapter(X11): no frame created for now" ); + frame = null; // disabled for now + } + else + { + throw new com.sun.star.uno.RuntimeException(); + } + } + } + + //---------------------------------------------------------------------------------- + + public void dispose() + { + if( fullscreen ) + { + java.awt.Graphics2D graphics = (java.awt.Graphics2D)frame.getGraphics(); + if( graphics.getDeviceConfiguration().getDevice().isFullScreenSupported() ) + { + CanvasUtils.printLog( "WindowAdapter(X11): leaving fullscreen mode" ); + graphics.getDeviceConfiguration().getDevice().setFullScreenWindow( null ); + } + graphics.dispose(); + } + + if( frame != null ) + frame.dispose(); + } + + //---------------------------------------------------------------------------------- + + // + // XWindow interface + // ================= + // + public void setPosSize( int X, int Y, int Width, int Height, short Flags ) + { + frame.setBounds( new java.awt.Rectangle( X, Y, Width, Height ) ); + } + + public com.sun.star.awt.Rectangle getPosSize( ) + { + java.awt.Rectangle bounds = frame.getBounds(); + + return new com.sun.star.awt.Rectangle( bounds.x, bounds.y, bounds.width, bounds.height ); + } + + public void setVisible( boolean visible ) + { + frame.setVisible( visible ); + } + + public void setEnable( boolean enable ) + { + frame.setEnabled( enable ); + } + + public void setFocus() + { + } + + public void addWindowListener( XWindowListener xListener ) + { + } + + public void removeWindowListener( XWindowListener xListener ) + { + } + + public void addFocusListener( XFocusListener xListener ) + { + } + + public void removeFocusListener( XFocusListener xListener ) + { + } + + public void addKeyListener( XKeyListener xListener ) + { + } + + public void removeKeyListener( XKeyListener xListener ) + { + } + + public void addMouseListener( XMouseListener xListener ) + { + } + + public void removeMouseListener( XMouseListener xListener ) + { + } + + public void addMouseMotionListener( XMouseMotionListener xListener ) + { + } + + public void removeMouseMotionListener( XMouseMotionListener xListener ) + { + } + + public void addPaintListener( XPaintListener xListener ) + { + } + + public void removePaintListener( XPaintListener xListener ) + { + } +} |