diff options
Diffstat (limited to 'canvas/source')
45 files changed, 11129 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 ) + { + } +} diff --git a/canvas/source/tools/canvastools.cxx b/canvas/source/tools/canvastools.cxx new file mode 100644 index 000000000000..3e6bf5334c38 --- /dev/null +++ b/canvas/source/tools/canvastools.cxx @@ -0,0 +1,389 @@ +/************************************************************************* + * + * $RCSfile: canvastools.cxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: thb $ $Date: 2004-03-18 10:38:36 $ + * + * 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): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _DRAFTS_COM_SUN_STAR_GEOMETRY_AFFINEMATRIX2D_HPP_ +#include <drafts/com/sun/star/geometry/AffineMatrix2D.hpp> +#endif + +#ifndef _DRAFTS_COM_SUN_STAR_RENDERING_RENDERSTATE_HPP__ +#include <drafts/com/sun/star/rendering/RenderState.hpp> +#endif +#ifndef _DRAFTS_COM_SUN_STAR_RENDERING_VIEWSTATE_HPP__ +#include <drafts/com/sun/star/rendering/ViewState.hpp> +#endif +#ifndef _DRAFTS_COM_SUN_STAR_RENDERING_XCANVAS_HPP__ +#include <drafts/com/sun/star/rendering/XCanvas.hpp> +#endif +#ifndef _DRAFTS_COM_SUN_STAR_RENDERING_COMPOSITEOPERATION_HPP__ +#include <drafts/com/sun/star/rendering/CompositeOperation.hpp> +#endif + +#ifndef _BGFX_MATRIX_B2DHOMMATRIX_HXX +#include <basegfx/matrix/b2dhommatrix.hxx> +#endif +#ifndef _BGFX_RANGE_B2DRANGE_HXX +#include <basegfx/range/b2drange.hxx> +#endif +#ifndef _BGFX_RANGE_B2DRECTANGLE_HXX +#include <basegfx/range/b2drectangle.hxx> +#endif +#ifndef _BGFX_POINT_B2DPOINT_HXX +#include <basegfx/point/b2dpoint.hxx> +#endif +#ifndef _BGFX_TOOLS_CANVASTOOLS_HXX +#include <basegfx/tools/canvastools.hxx> +#endif + +#include <canvas/canvastools.hxx> + +#include <memory> +#include <algorithm> + + +using namespace ::drafts::com::sun::star; +using namespace ::com::sun::star; + +namespace canvas +{ + + namespace tools + { + rendering::RenderState& initRenderState( rendering::RenderState& renderState ) + { + // setup identity transform + setIdentityAffineMatrix2D( renderState.AffineTransform ); + renderState.Clip = uno::Reference< rendering::XPolyPolygon2D >(); + renderState.DeviceColor = uno::Sequence< double >(); + renderState.CompositeOperation = rendering::CompositeOperation::OVER; + + return renderState; + } + + rendering::ViewState& initViewState( rendering::ViewState& viewState ) + { + // setup identity transform + setIdentityAffineMatrix2D( viewState.AffineTransform ); + viewState.Clip = uno::Reference< rendering::XPolyPolygon2D >(); + + return viewState; + } + + ::basegfx::B2DHomMatrix& getViewStateTransform( ::basegfx::B2DHomMatrix& transform, + const rendering::ViewState& viewState ) + { + return ::basegfx::unotools::homMatrixFromAffineMatrix( transform, viewState.AffineTransform ); + } + + rendering::ViewState& setViewStateTransform( rendering::ViewState& viewState, + const ::basegfx::B2DHomMatrix& transform ) + { + ::basegfx::unotools::affineMatrixFromHomMatrix( viewState.AffineTransform, transform ); + + return viewState; + } + + ::basegfx::B2DHomMatrix& getRenderStateTransform( ::basegfx::B2DHomMatrix& transform, + const rendering::RenderState& renderState ) + { + return ::basegfx::unotools::homMatrixFromAffineMatrix( transform, renderState.AffineTransform ); + } + + rendering::RenderState& setRenderStateTransform( rendering::RenderState& renderState, + const ::basegfx::B2DHomMatrix& transform ) + { + ::basegfx::unotools::affineMatrixFromHomMatrix( renderState.AffineTransform, transform ); + + return renderState; + } + + rendering::RenderState& appendToRenderState( rendering::RenderState& renderState, + const ::basegfx::B2DHomMatrix& rTransform ) + { + ::basegfx::B2DHomMatrix transform; + + getRenderStateTransform( transform, renderState ); + return setRenderStateTransform( renderState, transform * rTransform ); + } + + rendering::ViewState& appendToViewState( rendering::ViewState& viewState, + const ::basegfx::B2DHomMatrix& rTransform ) + { + ::basegfx::B2DHomMatrix transform; + + getViewStateTransform( transform, viewState ); + return setViewStateTransform( viewState, transform * rTransform ); + } + + rendering::RenderState& prependToRenderState( rendering::RenderState& renderState, + const ::basegfx::B2DHomMatrix& rTransform ) + { + ::basegfx::B2DHomMatrix transform; + + getRenderStateTransform( transform, renderState ); + return setRenderStateTransform( renderState, rTransform * transform ); + } + + rendering::ViewState& prependToViewState( rendering::ViewState& viewState, + const ::basegfx::B2DHomMatrix& rTransform ) + { + ::basegfx::B2DHomMatrix transform; + + getViewStateTransform( transform, viewState ); + return setViewStateTransform( viewState, rTransform * transform ); + } + + ::basegfx::B2DHomMatrix& mergeViewAndRenderTransform( ::basegfx::B2DHomMatrix& combinedTransform, + const rendering::ViewState& viewState, + const rendering::RenderState& renderState ) + { + ::basegfx::B2DHomMatrix viewTransform; + + ::basegfx::unotools::homMatrixFromAffineMatrix( combinedTransform, renderState.AffineTransform ); + ::basegfx::unotools::homMatrixFromAffineMatrix( viewTransform, viewState.AffineTransform ); + + // this statement performs combinedTransform = viewTransform * combinedTransform + combinedTransform *= viewTransform; + + return combinedTransform; + } + + rendering::ViewState& mergeViewAndRenderState( rendering::ViewState& resultViewState, + const rendering::ViewState& viewState, + const rendering::RenderState& renderState, + const uno::Reference< rendering::XCanvas > xCanvas ) + { + ::basegfx::B2DHomMatrix aTmpMatrix; + geometry::AffineMatrix2D convertedMatrix; + + resultViewState.Clip = NULL; // TODO: intersect clippings + + return setViewStateTransform( + resultViewState, + mergeViewAndRenderTransform( aTmpMatrix, + viewState, + renderState ) ); + } + + geometry::AffineMatrix2D& setIdentityAffineMatrix2D( geometry::AffineMatrix2D& matrix ) + { + matrix.m00 = 1.0; + matrix.m01 = 0.0; + matrix.m02 = 0.0; + matrix.m10 = 0.0; + matrix.m11 = 1.0; + matrix.m12 = 0.0; + + return matrix; + } + + bool operator==( const rendering::RenderState& renderState1, + const rendering::RenderState& renderState2 ) + { + if( renderState1.Clip != renderState2.Clip ) + return false; + + if( renderState1.DeviceColor != renderState2.DeviceColor ) + return false; + + if( renderState1.CompositeOperation != renderState2.CompositeOperation ) + return false; + + ::basegfx::B2DHomMatrix mat1, mat2; + getRenderStateTransform( mat1, renderState1 ); + getRenderStateTransform( mat2, renderState2 ); + if( mat1 != mat2 ) + return false; + + return true; + } + + bool operator==( const rendering::ViewState& viewState1, + const rendering::ViewState& viewState2 ) + { + if( viewState1.Clip != viewState2.Clip ) + return false; + + ::basegfx::B2DHomMatrix mat1, mat2; + getViewStateTransform( mat1, viewState1 ); + getViewStateTransform( mat2, viewState2 ); + if( mat1 != mat2 ) + return false; + + return true; + } + + // Create a corrected view transformation out of the give one, + // which ensures that the rectangle given by (0,0) and + // rSpriteSize is mapped with its left,top corner to (0,0) + // again. This is required to properly render sprite + // animations to buffer bitmaps. + ::basegfx::B2DHomMatrix& calcRectToOriginTransform( ::basegfx::B2DHomMatrix& o_transform, + const ::basegfx::B2DRange& i_srcRect, + const ::basegfx::B2DHomMatrix& i_transformation ) + { + // transform by given transformation + ::basegfx::B2DRectangle aTransformedRect; + + calcTransformedRectBounds( aTransformedRect, + i_srcRect, + i_transformation ); + + // now move resulting left,top point of bounds to (0,0) + ::basegfx::B2DHomMatrix aCorrectedTransform; + aCorrectedTransform.translate( -aTransformedRect.getMinX(), + -aTransformedRect.getMinY() ); + + // prepend to original transformation + o_transform = aCorrectedTransform * i_transformation; + + return o_transform; + } + + ::basegfx::B2DRange& calcTransformedRectBounds( ::basegfx::B2DRange& outRect, + const ::basegfx::B2DRange& inRect, + const ::basegfx::B2DHomMatrix& transformation ) + { + double left, top, bottom, right; + + // transform all four extremal points of the rectangle, + // take bounding rect of those. + ::basegfx::B2DPoint aPoint; + + // transform left-top point + aPoint.setX( inRect.getMinX() ); + aPoint.setY( inRect.getMinY() ); + + aPoint *= transformation; + left = right = aPoint.getX(); + top = bottom = aPoint.getY(); + + // transform bottom-right point + aPoint.setX( inRect.getMaxX() ); + aPoint.setY( inRect.getMaxY() ); + + aPoint *= transformation; + left = ::std::min(left, aPoint.getX()); + top = ::std::min(top, aPoint.getY()); + right = ::std::max(right, aPoint.getX()); + bottom = ::std::max(bottom, aPoint.getY()); + + // transform top-right point + aPoint.setX( inRect.getMaxX() ); + aPoint.setY( inRect.getMinY() ); + + aPoint *= transformation; + left = ::std::min(left, aPoint.getX()); + top = ::std::min(top, aPoint.getY()); + right = ::std::max(right, aPoint.getX()); + bottom = ::std::max(bottom, aPoint.getY()); + + // transform bottom-left point + aPoint.setX( inRect.getMinX() ); + aPoint.setY( inRect.getMaxY() ); + + aPoint *= transformation; + left = ::std::min(left, aPoint.getX()); + top = ::std::min(top, aPoint.getY()); + right = ::std::max(right, aPoint.getX()); + bottom = ::std::max(bottom, aPoint.getY()); + + // over and out. + outRect = ::basegfx::B2DRectangle( left, top, right, bottom ); + return outRect; + } + + ::basegfx::B2DHomMatrix& calcRectToRectTransform( ::basegfx::B2DHomMatrix& o_transform, + const ::basegfx::B2DRange& destRect, + const ::basegfx::B2DRange& srcRect, + const ::basegfx::B2DHomMatrix& transformation ) + { + // transform inputRect by transformation + ::basegfx::B2DRectangle aTransformedRect; + calcTransformedRectBounds( aTransformedRect, + srcRect, + transformation ); + + // now move resulting left,top point of bounds to (0,0) + ::basegfx::B2DHomMatrix aCorrectedTransform; + aCorrectedTransform.translate( -aTransformedRect.getMinX(), + -aTransformedRect.getMinY() ); + + // scale to match outRect + const double xDenom( aTransformedRect.getWidth() ); + const double yDenom( aTransformedRect.getHeight() ); + if( xDenom != 0.0 && yDenom != 0.0 ) + aCorrectedTransform.scale( destRect.getWidth() / xDenom, + destRect.getHeight() / yDenom ); + // TODO: error handling + + // translate to final position + aCorrectedTransform.translate( destRect.getMinX(), + destRect.getMinY() ); + + ::basegfx::B2DHomMatrix transform( transformation ); + o_transform = aCorrectedTransform * transform; + + return o_transform; + } + + } // namespace tools + +} // namespace canvas diff --git a/canvas/source/tools/canvastools.flt b/canvas/source/tools/canvastools.flt new file mode 100644 index 000000000000..90ec48c26d4e --- /dev/null +++ b/canvas/source/tools/canvastools.flt @@ -0,0 +1,4 @@ +__CT +Impl +IMP +internal diff --git a/canvas/source/tools/elapsedtime.cxx b/canvas/source/tools/elapsedtime.cxx new file mode 100644 index 000000000000..bbc4b1d6dcb5 --- /dev/null +++ b/canvas/source/tools/elapsedtime.cxx @@ -0,0 +1,184 @@ +/************************************************************************* + * + * $RCSfile: elapsedtime.cxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: thb $ $Date: 2004-03-18 10:38:37 $ + * + * 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): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _OSL_TIME_H_ +#include <osl/time.h> +#endif + +#include <canvas/elapsedtime.hxx> + +#ifdef WIN + +// TEMP!!! +// Awaiting corresponding functionality in OSL +// +#define WIN32_LEAN_AND_MEAN +#include <windows.h> +#include <winbase.h> +#include <mmsystem.h> +#endif + + +namespace canvas +{ + namespace tools + { + namespace + { +#ifdef WIN + static double fTimeFactor; +#endif + + double getTimeFactor() + { +#ifndef WIN + // value is in nanoseconds + return 1.0/10e9; +#else + // value is hardware-dependent + return fTimeFactor; +#endif + } + + sal_uInt64 getCurrentTime() + { +#ifndef WIN + TimeValue aTimeVal; + sal_uInt64 bRet( 0 ); + + if( osl_getSystemTime( &aTimeVal ) ) + { + // combine to seconds + fraction of second + bRet = ((sal_uInt64)aTimeVal.Seconds) * (sal_uInt64)1000000000 + (sal_uInt64)aTimeVal.Nanosec; + } +#else + sal_uInt64 bRet( 0 ); + + // TEMP!!! + // Awaiting corresponding functionality in OSL + // + + // is there a performance counter available? + static bool bTimeSetupDone( false ); + static bool bPerfTimerAvailable; + + if( !bTimeSetupDone ) + { + LONGLONG nPerfCount; + if( QueryPerformanceFrequency((LARGE_INTEGER *) &nPerfCount) ) + { + // yes, timer choice flag + bPerfTimerAvailable = true; + + // set scaling factor + fTimeFactor = 1.0/nPerfCount; + } + else + { + // no performance counter, read in using timeGetTime + bPerfTimerAvailable = false; + + // set timer scaling factor + fTimeFactor = 0.001; + } + + bTimeSetupDone = true; + } + + if( bPerfTimerAvailable ) + { + LONGLONG nCurrTime; + + // read initial time + QueryPerformanceCounter((LARGE_INTEGER *) &nCurrTime); + + bRet = nCurrTime; + } + else + { + bRet = timeGetTime(); + } +#endif + + return bRet; // TODO: is 0 okay for the failure case here? + } + } + + ElapsedTime::ElapsedTime() : + mnStartTime( getCurrentTime() ), + mfTimeFactor( getTimeFactor() ) + { + } + + void ElapsedTime::reset() + { + mnStartTime = getCurrentTime(); + } + + double ElapsedTime::getElapsedTime() + { + sal_uInt64 nCurrTime( getCurrentTime() ); + + return mfTimeFactor * (nCurrTime - mnStartTime); + } + + } +} diff --git a/canvas/source/tools/makefile.mk b/canvas/source/tools/makefile.mk new file mode 100644 index 000000000000..013d5a03bf4d --- /dev/null +++ b/canvas/source/tools/makefile.mk @@ -0,0 +1,104 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.2 $ +# +# last change: $Author: thb $ $Date: 2004-03-18 10:38:37 $ +# +# 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): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. + +PRJNAME=canvas +TARGET=canvastools +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------------- + +.INCLUDE : settings.mk + +# --- Common ---------------------------------------------------------- + +.IF "$(verbose)"!="" || "$(VERBOSE)"!="" +CDEFS+= -DVERBOSE +.ENDIF + +SLOFILES = $(SLO)$/canvastools.obj $(SLO)$/elapsedtime.obj + +SHL1TARGET= $(TARGET)$(UPD)$(DLLPOSTFIX) +SHL1IMPLIB= i$(TARGET) +SHL1STDLIBS= $(SALLIB) $(CPPULIB) $(BASEGFXLIB) + +SHL1LIBS= $(SLB)$/$(TARGET).lib + +SHL1DEF= $(MISC)$/$(SHL1TARGET).def +DEF1NAME =$(SHL1TARGET) +DEF1DEPN =$(MISC)$/$(SHL1TARGET).flt \ + $(LIB1TARGET) + +DEF1DES =Canvastools +DEFLIB1NAME =$(TARGET) + +.IF "$(GUI)" == "WNT" +SHL1STDLIBS += winmm.lib kernel32.lib +.ENDIF + +# ========================================================================== + +.INCLUDE : target.mk + +$(MISC)$/$(SHL1TARGET).flt : makefile.mk + @+$(TYPE) $(TARGET).flt > $@ diff --git a/canvas/source/vcl/canvasbitmap.cxx b/canvas/source/vcl/canvasbitmap.cxx new file mode 100644 index 000000000000..ed5fbab62737 --- /dev/null +++ b/canvas/source/vcl/canvasbitmap.cxx @@ -0,0 +1,451 @@ +/************************************************************************* + * + * $RCSfile: canvasbitmap.cxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: thb $ $Date: 2004-03-18 10:38:39 $ + * + * 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): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _SV_BMPACC_HXX +#include <vcl/bmpacc.hxx> +#endif +#ifndef _VCL_CANVASTOOLS_HXX +#include <vcl/canvastools.hxx> +#endif + +#include <canvas/canvastools.hxx> + +#include "canvasbitmap.hxx" +#include "bitmapcanvas.hxx" +#include "impltools.hxx" + +using namespace ::com::sun::star; +using namespace ::drafts::com::sun::star; + +namespace vclcanvas +{ + // Currently, the only way to generate an XBitmap is from + // XGraphicDevice.getCompatibleBitmap(). Therefore, we don't even + // take a bitmap here, but a VDev directly. + CanvasBitmap::CanvasBitmap( const ::Size& rSize, + const OutDevProvider::ImplRef& rReferenceCanvas ) : + mpReferenceCanvas( rReferenceCanvas ), + mpBitmapCanvas( new BitmapCanvas( rSize, + rReferenceCanvas ) ) + { + } + + CanvasBitmap::CanvasBitmap( const BitmapEx& rBitmap, + const OutDevProvider::ImplRef& rReferenceCanvas ) : + mpReferenceCanvas( rReferenceCanvas ), + mpBitmapCanvas( new BitmapCanvas( rBitmap.GetSizePixel(), + rReferenceCanvas ) ) + { + // TODO: Support alpha canvas here + VirtualDevice& rVDev( getVirDev() ); + rVDev.EnableMapMode( FALSE ); + const Point aEmptyPoint(0,0); + rVDev.DrawBitmapEx(aEmptyPoint, rBitmap); + } + + CanvasBitmap::~CanvasBitmap() + { + } + + geometry::IntegerSize2D SAL_CALL CanvasBitmap::getSize( ) throw (uno::RuntimeException) + { + tools::LocalGuard aGuard; + return ::vcl::unotools::integerSize2DFromSize( getVirDev().GetOutputSizePixel() ); + } + + uno::Reference< rendering::XBitmapCanvas > SAL_CALL CanvasBitmap::queryBitmapCanvas( ) throw (uno::RuntimeException) + { + return mpBitmapCanvas.getRef(); + } + + uno::Reference< rendering::XBitmap > SAL_CALL CanvasBitmap::getScaledBitmap( const geometry::RealSize2D& newSize, sal_Bool beFast ) throw (uno::RuntimeException) + { + tools::LocalGuard aGuard; + +#if 0 + // TODO: To be used when dealing with real bitmaps here + BitmapEx aRes( *maBitmap ); + + aRes.Scale( ::canvas::tools::sizeFromRealSize2D(newSize), + beFast ? BMP_SCALE_FAST : BMP_SCALE_INTERPOLATE ); + + return uno::Reference< rendering::XBitmap >( new CanvasBitmap( aRes ) ); +#else + // TODO: Support alpha canvas here + VirtualDevice& rVDev( getVirDev() ); + const Point aEmptyPoint(0,0); + const Size aBmpSize( rVDev.GetOutputSizePixel() ); + + Bitmap aBitmap( rVDev.GetBitmap(aEmptyPoint, aBmpSize) ); + + aBitmap.Scale( ::vcl::unotools::sizeFromRealSize2D(newSize), + beFast ? BMP_SCALE_FAST : BMP_SCALE_INTERPOLATE ); + + return uno::Reference< rendering::XBitmap >( new CanvasBitmap( aBitmap, + mpReferenceCanvas ) ); +#endif + } + + uno::Sequence< sal_Int8 > SAL_CALL CanvasBitmap::getData( const geometry::IntegerRectangle2D& rect ) throw (lang::IndexOutOfBoundsException, rendering::VolatileContentDestroyedException,uno::RuntimeException) + { + tools::LocalGuard aGuard; + +#if 0 + // TODO: To be used when dealing with real bitmaps here + Bitmap aBitmap( maBitmap->GetBitmap() ); + Bitmap aAlpha( maBitmap->GetAlpha().GetBitmap() ); +#else + // TODO: Support alpha canvas here + VirtualDevice& rVDev( getVirDev() ); + const Point aEmptyPoint(0,0); + const Size aBmpSize( rVDev.GetOutputSizePixel() ); + + Bitmap aBitmap( rVDev.GetBitmap(aEmptyPoint, aBmpSize) ); + Bitmap aAlpha( Bitmap( aBmpSize, 8) ); +#endif + + ScopedBitmapReadAccess pReadAccess( aBitmap.AcquireReadAccess(), + aBitmap ); + ScopedBitmapReadAccess pAlphaReadAccess( aAlpha.AcquireReadAccess(), + aAlpha ); + + if( pReadAccess.get() != NULL && + pAlphaReadAccess.get() != NULL ) + { + // TODO: Support more formats. + const Size aBmpSize( aBitmap.GetSizePixel() ); + + // for the time being, always return as BGRA + uno::Sequence< sal_Int8 > aRes( 4*aBmpSize.Width()*aBmpSize.Height() ); + + int nCurrPos(0); + for( int y=rect.Y1; + y<aBmpSize.Height() && y<rect.Y2; + ++y ) + { + for( int x=rect.X1; + x<aBmpSize.Width() && x<rect.X2; + ++x ) + { + aRes[ nCurrPos++ ] = pReadAccess->GetColor( y, x ).GetBlue(); + aRes[ nCurrPos++ ] = pReadAccess->GetColor( y, x ).GetGreen(); + aRes[ nCurrPos++ ] = pReadAccess->GetColor( y, x ).GetRed(); + aRes[ nCurrPos++ ] = pAlphaReadAccess->GetPixel( y, x ).GetIndex(); + } + } + + return aRes; + } + + return uno::Sequence< sal_Int8 >(); + } + + void SAL_CALL CanvasBitmap::setData( const uno::Sequence< sal_Int8 >& data, const geometry::IntegerRectangle2D& rect ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, uno::RuntimeException) + { + tools::LocalGuard aGuard; + +#if 0 + // TODO: To be used when dealing with real bitmaps here + + // retrieve local copies from the BitmapEx, which are later + // stored back. Unfortunately, the BitmapEx does not permit + // in-place modifications, as they are necessary here. + Bitmap aBitmap( maBitmap->GetBitmap() ); + Bitmap aAlpha( maBitmap->GetAlpha().GetBitmap() ); +#else + // TODO: Support alpha canvas here + VirtualDevice& rVDev( getVirDev() ); + const Point aEmptyPoint(0,0); + const Size aBmpSize( rVDev.GetOutputSizePixel() ); + + Bitmap aBitmap( rVDev.GetBitmap(aEmptyPoint, aBmpSize) ); + Bitmap aAlpha( Bitmap( aBmpSize, 8) ); +#endif + + bool bCopyBack( false ); // only copy something back, if we + // actually changed pixel + + { + ScopedBitmapWriteAccess pWriteAccess( aBitmap.AcquireWriteAccess(), + aBitmap ); + ScopedBitmapWriteAccess pAlphaWriteAccess( aAlpha.AcquireWriteAccess(), + aAlpha ); + + if( pWriteAccess.get() != NULL && + pAlphaWriteAccess.get() != NULL ) + { + // TODO: Support more formats. + const Size aBmpSize( aBitmap.GetSizePixel() ); + + // for the time being, always read as BGRA + int nCurrPos(0); + for( int y=rect.Y1; + y<aBmpSize.Height() && y<rect.Y2; + ++y ) + { + for( int x=rect.X1; + x<aBmpSize.Width() && x<rect.X2; + ++x ) + { + pWriteAccess->SetPixel( y, x, BitmapColor( data[ nCurrPos+2 ], + data[ nCurrPos+1 ], + data[ nCurrPos ] ) ); + nCurrPos += 3; + + pAlphaWriteAccess->SetPixel( y, x, BitmapColor( 255 - data[ nCurrPos++ ] ) ); + } + } + + bCopyBack = true; + } + } + + // copy back only here, since the BitmapAccessors must be + // destroyed beforehand + if( bCopyBack ) + { +#if 0 + // TODO: To be used when dealing with real bitmaps here + maBitmap = BitmapEx( aBitmap, + AlphaMask( aAlpha ) ); +#else + // TODO: Support alpha canvas here + VirtualDevice& rVDev( getVirDev() ); + rVDev.EnableMapMode( FALSE ); + const Point aEmptyPoint(0,0); + rVDev.DrawBitmap(aEmptyPoint, aBitmap); +#endif + } + } + + void SAL_CALL CanvasBitmap::setPixel( const uno::Sequence< sal_Int8 >& color, const geometry::IntegerPoint2D& pos ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, uno::RuntimeException) + { + tools::LocalGuard aGuard; + +#if 0 + // TODO: To be used when dealing with real bitmaps here + const Size aBmpSize( maBitmap->GetSizePixel() ); +#else + const Size aBmpSize( getVirDev().GetOutputSizePixel() ); +#endif + + OSL_ENSURE( pos.X >= 0 && pos.X < aBmpSize.Width(), "CanvasBitmap::setPixel: X coordinate out of bounds" ); + OSL_ENSURE( pos.Y >= 0 && pos.Y < aBmpSize.Height(), "CanvasBitmap::setPixel: Y coordinate out of bounds" ); + OSL_ENSURE( color.getLength() > 3, "CanvasBitmap::setPixel: not enough color components" ); + +#if 0 + // TODO: To be used when dealing with real bitmaps here + // retrieve local copies from the BitmapEx, which are later + // stored back. Unfortunately, the BitmapEx does not permit + // in-place modifications, as they are necessary here. + Bitmap aBitmap( maBitmap->GetBitmap() ); + Bitmap aAlpha( maBitmap->GetAlpha().GetBitmap() ); + + bool bCopyBack( false ); // only copy something back, if we + // actually changed a pixel + + { + ScopedBitmapWriteAccess pWriteAccess( aBitmap.AcquireWriteAccess(), + aBitmap ); + ScopedBitmapWriteAccess pAlphaWriteAccess( aAlpha.AcquireWriteAccess(), + aAlpha ); + + if( pWriteAccess.get() != NULL && + pAlphaWriteAccess.get() != NULL ) + { + pWriteAccess->SetPixel( pos.Y, pos.X, BitmapColor( color[ 2 ], + color[ 1 ], + color[ 0 ] ) ); + pAlphaWriteAccess->SetPixel( pos.Y, pos.X, BitmapColor( 255 - color[ 3 ] ) ); + } + } + + // copy back only here, since the BitmapAccessors must be + // destroyed beforehand + if( bCopyBack ) + { + maBitmap = BitmapEx( aBitmap, + AlphaMask( aAlpha ) ); + } +#else + VirtualDevice& rVDev( getVirDev() ); + rVDev.EnableMapMode( FALSE ); + + uno::Reference< rendering::XCanvas > xCanvas( mpBitmapCanvas.getRef(), + uno::UNO_QUERY ); + OSL_ENSURE( xCanvas.is(), "CanvasBitmap::setPixel(): Invalid reference canvas" ); + + getVirDev().DrawPixel( ::vcl::unotools::pointFromIntegerPoint2D( pos ), + ::vcl::unotools::sequenceToColor( + xCanvas->getDevice(), + color ) ); +#endif + } + + uno::Sequence< sal_Int8 > SAL_CALL CanvasBitmap::getPixel( const geometry::IntegerPoint2D& pos ) throw (lang::IndexOutOfBoundsException, rendering::VolatileContentDestroyedException, uno::RuntimeException) + { + tools::LocalGuard aGuard; + +#if 0 + // TODO: To be used when dealing with real bitmaps here + const Size aBmpSize( maBitmap->GetSizePixel() ); +#else + const Size aBmpSize( getVirDev().GetOutputSizePixel() ); +#endif + + OSL_ENSURE( pos.X >= 0 && pos.X < aBmpSize.Width(), "CanvasBitmap::getPixel: X coordinate out of bounds" ); + OSL_ENSURE( pos.Y >= 0 && pos.Y < aBmpSize.Height(), "CanvasBitmap::getPixel: Y coordinate out of bounds" ); + +#if 0 + // TODO: To be used when dealing with real bitmaps here + Bitmap aBitmap( maBitmap->GetBitmap() ); + Bitmap aAlpha( maBitmap->GetAlpha().GetBitmap() ); + ScopedBitmapReadAccess pReadAccess( aBitmap.AcquireReadAccess(), + aBitmap ); + ScopedBitmapReadAccess pAlphaReadAccess( aAlpha.AcquireReadAccess(), + aAlpha ); + + if( pReadAccess.get() != NULL && + pAlphaReadAccess.get() != NULL ) + { + // for the time being, always return as BGRA + uno::Sequence< sal_Int8 > aRes( 4 ); + + const BitmapColor aColor( pReadAccess->GetColor( pos.Y, pos.X ) ); + aRes[ 3 ] = aColor.GetRed(); + aRes[ 2 ] = aColor.GetGreen(); + aRes[ 1 ] = aColor.GetBlue(); + + aRes[ 3 ] = pAlphaReadAccess->GetPixel( pos.Y, pos.X ).GetIndex(); + + return aRes; + } + + return uno::Sequence< sal_Int8 >(); +#else + VirtualDevice& rVDev( getVirDev() ); + rVDev.EnableMapMode( FALSE ); + + uno::Reference< rendering::XCanvas > xCanvas(mpBitmapCanvas.getRef(), + uno::UNO_QUERY); + + OSL_ENSURE( xCanvas.is(), "CanvasBitmap::getPixel(): Invalid reference canvas" ); + + return ::vcl::unotools::colorToIntSequence( + xCanvas->getDevice(), + getVirDev().GetPixel( ::vcl::unotools::pointFromIntegerPoint2D( pos ) ) ); +#endif + } + + uno::Reference< rendering::XBitmapPalette > SAL_CALL CanvasBitmap::getPalette( ) throw (uno::RuntimeException) + { + return uno::Reference< rendering::XBitmapPalette >(); + } + + rendering::IntegerBitmapLayout SAL_CALL CanvasBitmap::getMemoryLayout( ) throw (uno::RuntimeException) + { + // TODO: finish that one + rendering::IntegerBitmapLayout aLayout; + +#if 0 + // TODO: To be used when dealing with real bitmaps here + const Size aBmpSize( maBitmap->GetSizePixel() ); +#else + const Size aBmpSize( getVirDev().GetOutputSizePixel() ); +#endif + + aLayout.ScanLines = aBmpSize.Height(); + aLayout.ScanLineBytes = aBmpSize.Width()*4; + aLayout.ScanLineStride = aLayout.ScanLineBytes; + aLayout.Format = 0; + aLayout.NumComponents = 4; + aLayout.ComponentMasks = uno::Sequence<sal_Int64>(); + aLayout.Endianness = 0; + aLayout.IsPseudoColor = false; + + return aLayout; + } + +#define SERVICE_NAME "drafts.com.sun.star.rendering.CanvasBitmap" + + ::rtl::OUString SAL_CALL CanvasBitmap::getImplementationName( ) throw (uno::RuntimeException) + { + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CANVASBITMAP_IMPLEMENTATION_NAME ) ); + } + + sal_Bool SAL_CALL CanvasBitmap::supportsService( const ::rtl::OUString& ServiceName ) throw (uno::RuntimeException) + { + return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) ); + } + + uno::Sequence< ::rtl::OUString > SAL_CALL CanvasBitmap::getSupportedServiceNames( ) throw (uno::RuntimeException) + { + uno::Sequence< ::rtl::OUString > aRet(1); + aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) ); + + return aRet; + } + + VirtualDevice& CanvasBitmap::getVirDev() + { + return mpBitmapCanvas->getVirDev(); + } +} diff --git a/canvas/source/vcl/canvasbitmap.hxx b/canvas/source/vcl/canvasbitmap.hxx new file mode 100644 index 000000000000..7bceb6abcc77 --- /dev/null +++ b/canvas/source/vcl/canvasbitmap.hxx @@ -0,0 +1,137 @@ +/************************************************************************* + * + * $RCSfile: canvasbitmap.hxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: thb $ $Date: 2004-03-18 10:38:39 $ + * + * 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): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _VCLCANVAS_CANVASBITMAP_HXX +#define _VCLCANVAS_CANVASBITMAP_HXX + +#include <memory> + +#ifndef _CPPUHELPER_IMPLBASE2_HXX_ +#include <cppuhelper/implbase2.hxx> +#endif +#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_ +#include <com/sun/star/lang/XServiceInfo.hpp> +#endif + +#ifndef _DRAFTS_COM_SUN_STAR_RENDERING_XINTEGERBITMAP_HPP_ +#include <drafts/com/sun/star/rendering/XIntegerBitmap.hpp> +#endif + +#ifndef _SV_BITMAPEX_HXX +#include <vcl/bitmapex.hxx> +#endif + +#include "spritecanvas.hxx" +#include "bitmapcanvas.hxx" +#include "impltools.hxx" + +#define CANVASBITMAP_IMPLEMENTATION_NAME "VCLCanvas::CanvasBitmap" + +/* Definition of CanvasBitmap class */ + +namespace vclcanvas +{ + class CanvasBitmap : public ::cppu::WeakImplHelper2< ::drafts::com::sun::star::rendering::XIntegerBitmap, + ::com::sun::star::lang::XServiceInfo > + { + public: + // Must be called with locked Solar mutex + CanvasBitmap( const ::Size& rSize, + const OutDevProvider::ImplRef& rReferenceCanvas ); + + // XBitmap + virtual ::drafts::com::sun::star::geometry::IntegerSize2D SAL_CALL getSize( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XBitmapCanvas > SAL_CALL queryBitmapCanvas( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XBitmap > SAL_CALL getScaledBitmap( const ::drafts::com::sun::star::geometry::RealSize2D& newSize, sal_Bool beFast ) throw (::com::sun::star::uno::RuntimeException); + + // XIntegerBitmap + virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getData( const ::drafts::com::sun::star::geometry::IntegerRectangle2D& rect ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::drafts::com::sun::star::rendering::VolatileContentDestroyedException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setData( const ::com::sun::star::uno::Sequence< sal_Int8 >& data, const ::drafts::com::sun::star::geometry::IntegerRectangle2D& rect ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setPixel( const ::com::sun::star::uno::Sequence< sal_Int8 >& color, const ::drafts::com::sun::star::geometry::IntegerPoint2D& pos ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getPixel( const ::drafts::com::sun::star::geometry::IntegerPoint2D& pos ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::drafts::com::sun::star::rendering::VolatileContentDestroyedException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XBitmapPalette > SAL_CALL getPalette( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::drafts::com::sun::star::rendering::IntegerBitmapLayout SAL_CALL getMemoryLayout( ) throw (::com::sun::star::uno::RuntimeException); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException); + + VirtualDevice& getVirDev(); + + protected: + ~CanvasBitmap(); // we're a ref-counted UNO class. _We_ destroy ourselves. + + private: + // default: disabled copy/assignment + CanvasBitmap(const CanvasBitmap&); + CanvasBitmap& operator=( const CanvasBitmap& ); + + // only needed internally + CanvasBitmap( const BitmapEx& rBitmap, + const OutDevProvider::ImplRef& rReferenceCanvas ); + + OutDevProvider::ImplRef mpReferenceCanvas; + BitmapCanvas::ImplRef mpBitmapCanvas; + }; +} + +#endif /* _VCLCANVAS_CANVASBITMAP_HXX */ diff --git a/canvas/source/vcl/canvascustomsprite.cxx b/canvas/source/vcl/canvascustomsprite.cxx new file mode 100644 index 000000000000..b228e67b3506 --- /dev/null +++ b/canvas/source/vcl/canvascustomsprite.cxx @@ -0,0 +1,444 @@ +/************************************************************************* + * + * $RCSfile: canvascustomsprite.cxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: thb $ $Date: 2004-03-18 10:38:40 $ + * + * 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): _______________________________________ + * + * + ************************************************************************/ + +#ifndef INCLUDED_RTL_MATH_HXX +#include <rtl/math.hxx> +#endif + +#include <canvas/canvastools.hxx> + +#include "canvascustomsprite.hxx" +#include "spritecanvas.hxx" +#include "impltools.hxx" + +#ifndef _SV_OUTDEV_HXX +#include <vcl/outdev.hxx> +#endif +#ifndef _SV_BITMAP_HXX +#include <vcl/bitmap.hxx> +#endif +#ifndef _SV_GDIMTF_HXX +#include <vcl/gdimtf.hxx> +#endif +#ifndef _SV_METAACT_HXX +#include <vcl/metaact.hxx> +#endif +#ifndef _VCL_CANVASTOOLS_HXX +#include <vcl/canvastools.hxx> +#endif + +#ifndef _BGFX_MATRIX_B2DHOMMATRIX_HXX +#include <basegfx/matrix/b2dhommatrix.hxx> +#endif +#ifndef _BGFX_POINT_B2DPOINT_HXX +#include <basegfx/point/b2dpoint.hxx> +#endif +#ifndef _BGFX_TOOLS_CANVASTOOLS_HXX +#include <basegfx/tools/canvastools.hxx> +#endif + +using namespace ::com::sun::star; +using namespace ::drafts::com::sun::star; + +namespace vclcanvas +{ + + CanvasCustomSprite::CanvasCustomSprite( const geometry::RealSize2D& rSpriteSize, + const SpriteCanvas::ImplRef& rSpriteCanvas ) : + maVDev( new VirtualDevice( rSpriteCanvas->getOutDev() ) ), // create from reference device + maMaskVDev( new VirtualDevice( rSpriteCanvas->getOutDev(), 1) ), // create from reference device, bit depth: one + maCanvasHelper(), + mpSpriteCanvas( rSpriteCanvas ), + maPosition(0.0, 0.0), + maSize( ::vcl::unotools::sizeFromRealSize2D( rSpriteSize ) ), + mfAlpha(0.0), + mbActive( false ) + { + // setup outdev sizes to total sprite size + maVDev->SetOutputSizePixel( maSize ); + maMaskVDev->SetOutputSizePixel( maSize ); + + // set mask vdev drawmode, such that everything is painted + // black. That leaves us with a binary image, white for + // background, black for painted content + maMaskVDev->SetDrawMode( DRAWMODE_BLACKLINE | DRAWMODE_BLACKFILL | DRAWMODE_BLACKTEXT | + DRAWMODE_BLACKGRADIENT | DRAWMODE_BLACKBITMAP ); + + maCanvasHelper.setOutDev( *maVDev ); + maCanvasHelper.setBackgroundOutDev( *maMaskVDev ); + } + + CanvasCustomSprite::~CanvasCustomSprite() + { + hide(); + } + + OutDevProvider::ImplRef CanvasCustomSprite::getImplRef() + { + return OutDevProvider::ImplRef::createFromQuery( this ); + } + + void SAL_CALL CanvasCustomSprite::drawPoint( const geometry::RealPoint2D& aPoint, + const rendering::ViewState& viewState, + const rendering::RenderState& renderState ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + // TODO: You might consider copying the SpriteCanvas + // background VDev behaviour here, notably the call to + // SpriteSurface::updateSprite(). But on the other hand, there + // are enough external cases that could mess that up (see + // comment on XCustomSprite), that we're maybe wise to keep it + // like this (i.e. invalidating the sprite content only once, + // for the call to getContentCanvas). This way, the inevitable + // errors will show up earlier, not only when multi-threading + // the updateScreen. + maCanvasHelper.drawPoint( aPoint, viewState, renderState, getImplRef() ); + } + + void SAL_CALL CanvasCustomSprite::drawLine( const geometry::RealPoint2D& aStartPoint, const geometry::RealPoint2D& aEndPoint, const rendering::ViewState& viewState, const rendering::RenderState& renderState ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + maCanvasHelper.drawLine(aStartPoint, aEndPoint, viewState, renderState, getImplRef()); + } + + void SAL_CALL CanvasCustomSprite::drawBezier( const ::drafts::com::sun::star::geometry::RealBezierSegment2D& aBezierSegment, + const ::drafts::com::sun::star::geometry::RealPoint2D& aEndPoint, + const rendering::ViewState& viewState, + const rendering::RenderState& renderState ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + maCanvasHelper.drawBezier(aBezierSegment, aEndPoint, viewState, renderState, getImplRef()); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL CanvasCustomSprite::drawPolyPolygon( const uno::Reference< rendering::XPolyPolygon2D >& xPolyPolygon, const rendering::ViewState& viewState, const rendering::RenderState& renderState ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + return maCanvasHelper.drawPolyPolygon(xPolyPolygon, viewState, renderState, getImplRef()); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL CanvasCustomSprite::strokePolyPolygon( const uno::Reference< rendering::XPolyPolygon2D >& xPolyPolygon, const rendering::ViewState& viewState, const rendering::RenderState& renderState, const rendering::StrokeAttributes& strokeAttributes ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + return maCanvasHelper.strokePolyPolygon(xPolyPolygon, viewState, renderState, strokeAttributes, getImplRef()); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL CanvasCustomSprite::strokeTexturedPolyPolygon( const uno::Reference< rendering::XPolyPolygon2D >& xPolyPolygon, const rendering::ViewState& viewState, const rendering::RenderState& renderState, const uno::Sequence< rendering::Texture >& textures, const rendering::StrokeAttributes& strokeAttributes ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + return maCanvasHelper.strokeTexturedPolyPolygon(xPolyPolygon, viewState, renderState, textures, strokeAttributes, getImplRef()); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL CanvasCustomSprite::strokeTextureMappedPolyPolygon( const uno::Reference< rendering::XPolyPolygon2D >& xPolyPolygon, const rendering::ViewState& viewState, const rendering::RenderState& renderState, const uno::Sequence< rendering::Texture >& textures, const uno::Reference< geometry::XMapping2D >& xMapping, const rendering::StrokeAttributes& strokeAttributes ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + return maCanvasHelper.strokeTextureMappedPolyPolygon(xPolyPolygon, viewState, renderState, textures, xMapping, strokeAttributes, getImplRef()); + } + + uno::Reference< rendering::XPolyPolygon2D > SAL_CALL CanvasCustomSprite::queryStrokeShapes( const uno::Reference< rendering::XPolyPolygon2D >& xPolyPolygon, const rendering::ViewState& viewState, const rendering::RenderState& renderState, const rendering::StrokeAttributes& strokeAttributes ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + return maCanvasHelper.queryStrokeShapes(xPolyPolygon, viewState, renderState, strokeAttributes, getImplRef()); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL CanvasCustomSprite::fillPolyPolygon( const uno::Reference< rendering::XPolyPolygon2D >& xPolyPolygon, const rendering::ViewState& viewState, const rendering::RenderState& renderState ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + return maCanvasHelper.fillPolyPolygon(xPolyPolygon, viewState, renderState, getImplRef() ); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL CanvasCustomSprite::fillTexturedPolyPolygon( const uno::Reference< rendering::XPolyPolygon2D >& xPolyPolygon, const rendering::ViewState& viewState, const rendering::RenderState& renderState, const uno::Sequence< rendering::Texture >& textures ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + return maCanvasHelper.fillTexturedPolyPolygon(xPolyPolygon, viewState, renderState, textures, getImplRef()); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL CanvasCustomSprite::fillTextureMappedPolyPolygon( const uno::Reference< rendering::XPolyPolygon2D >& xPolyPolygon, const rendering::ViewState& viewState, const rendering::RenderState& renderState, const uno::Sequence< rendering::Texture >& textures, const uno::Reference< geometry::XMapping2D >& xMapping ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + return maCanvasHelper.fillTextureMappedPolyPolygon(xPolyPolygon, viewState, renderState, textures, xMapping, getImplRef()); + } + + uno::Reference< rendering::XCanvasFont > SAL_CALL CanvasCustomSprite::queryFont( const rendering::FontRequest& fontRequest ) throw (uno::RuntimeException) + { + return maCanvasHelper.queryFont( fontRequest, getImplRef() ); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL CanvasCustomSprite::drawText( const rendering::StringContext& text, + const uno::Reference< rendering::XCanvasFont >& xFont, + const rendering::ViewState& viewState, + const rendering::RenderState& renderState, + sal_Int8 textDirection ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + return maCanvasHelper.drawText(text, xFont, viewState, renderState, textDirection, getImplRef()); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL CanvasCustomSprite::drawOffsettedText( const rendering::StringContext& text, const uno::Reference< rendering::XCanvasFont >& xFont, const uno::Sequence< double >& offsets, const rendering::ViewState& viewState, const rendering::RenderState& renderState, sal_Int8 textDirection ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + return maCanvasHelper.drawOffsettedText(text, xFont, offsets, viewState, renderState, textDirection, getImplRef()); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL CanvasCustomSprite::drawBitmap( const uno::Reference< rendering::XBitmap >& xBitmap, const rendering::ViewState& viewState, const rendering::RenderState& renderState ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + return maCanvasHelper.drawBitmap(xBitmap, viewState, renderState, getImplRef()); + } + + uno::Reference< rendering::XGraphicDevice > SAL_CALL CanvasCustomSprite::getDevice() throw (uno::RuntimeException) + { + return maCanvasHelper.getDevice( getImplRef() ); + } + + void SAL_CALL CanvasCustomSprite::copyRect( const uno::Reference< rendering::XBitmapCanvas >& sourceCanvas, + const geometry::RealRectangle2D& sourceRect, + const rendering::ViewState& sourceViewState, + const rendering::RenderState& sourceRenderState, + const geometry::RealRectangle2D& destRect, + const rendering::ViewState& destViewState, + const rendering::RenderState& destRenderState ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + tools::LocalGuard aGuard; + } + + void SAL_CALL CanvasCustomSprite::setAlpha( double alpha ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + ::canvas::tools::checkRange(alpha, 0.0, 1.0); + + if( alpha != mfAlpha ) + { + if( mbActive ) + mpSpriteCanvas->updateSprite( Sprite::ImplRef( this ), + ::vcl::unotools::pointFromB2DPoint( maPosition ), + Rectangle( ::vcl::unotools::pointFromB2DPoint( maPosition ), + maSize ) ); + + mfAlpha = alpha; + } + } + + void SAL_CALL CanvasCustomSprite::move( const ::drafts::com::sun::star::geometry::RealPoint2D& aNewPos, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + ::basegfx::B2DHomMatrix aTransform; + ::canvas::tools::mergeViewAndRenderTransform(aTransform, + viewState, + renderState); + + ::basegfx::B2DPoint aPoint( ::basegfx::unotools::b2DPointFromRealPoint2D(aNewPos) ); + aPoint *= aTransform; + + if( aPoint != maPosition ) + { + if( mbActive ) + mpSpriteCanvas->moveSprite( Sprite::ImplRef( this ), + ::vcl::unotools::pointFromB2DPoint( maPosition ), + ::vcl::unotools::pointFromB2DPoint( aPoint ) ); + + maPosition = aPoint; + } + } + + void SAL_CALL CanvasCustomSprite::transform( const geometry::AffineMatrix2D& aTransformation ) throw (lang::IllegalArgumentException, + uno::RuntimeException) + { + // TODO + } + + void SAL_CALL CanvasCustomSprite::clip( const uno::Reference< rendering::XPolyPolygon2D >& aClip, + const rendering::ViewState& viewState, + const rendering::RenderState& renderState ) throw (lang::IllegalArgumentException, + uno::RuntimeException) + { + // TODO + } + + void SAL_CALL CanvasCustomSprite::show( ) throw (::com::sun::star::uno::RuntimeException) + { + if( !mbActive ) + { + mpSpriteCanvas->showSprite( Sprite::ImplRef( this ) ); + mbActive = true; + + if( mfAlpha != 0.0 ) + { + mpSpriteCanvas->updateSprite( Sprite::ImplRef( this ), + ::vcl::unotools::pointFromB2DPoint( maPosition ), + Rectangle( ::vcl::unotools::pointFromB2DPoint( maPosition ), + maSize ) ); + } + } + } + + void SAL_CALL CanvasCustomSprite::hide( ) throw (::com::sun::star::uno::RuntimeException) + { + if( mbActive ) + { + mpSpriteCanvas->hideSprite( Sprite::ImplRef( this ) ); + mbActive = false; + + if( mfAlpha != 0.0 ) + { + mpSpriteCanvas->updateSprite( Sprite::ImplRef( this ), + ::vcl::unotools::pointFromB2DPoint( maPosition ), + Rectangle( ::vcl::unotools::pointFromB2DPoint( maPosition ), + maSize ) ); + } + } + } + + uno::Reference< rendering::XCanvas > SAL_CALL CanvasCustomSprite::getContentCanvas() throw (uno::RuntimeException) + { + if( mbActive ) + { + // the client is about to render into the sprite. Thus, + // potentially the whole sprite area has changed. + mpSpriteCanvas->updateSprite( Sprite::ImplRef( this ), + ::vcl::unotools::pointFromB2DPoint( maPosition ), + Rectangle( ::vcl::unotools::pointFromB2DPoint( maPosition ), + maSize ) ); + } + + // TODO: Locking! Everywhere! + tools::LocalGuard aGuard; + + // clear surface + maVDev->EnableMapMode( FALSE ); + maVDev->SetFillColor( Color( COL_WHITE ) ); + maVDev->SetLineColor(); + maVDev->DrawRect( Rectangle(Point(), maSize) ); + + maMaskVDev->SetDrawMode( DRAWMODE_DEFAULT ); + maMaskVDev->EnableMapMode( FALSE ); + maMaskVDev->SetFillColor( Color( COL_WHITE ) ); + maMaskVDev->SetLineColor(); + maMaskVDev->DrawRect( Rectangle(Point(), maSize) ); + maMaskVDev->SetDrawMode( DRAWMODE_BLACKLINE | DRAWMODE_BLACKFILL | DRAWMODE_BLACKTEXT | + DRAWMODE_BLACKGRADIENT | DRAWMODE_BLACKBITMAP ); + + return this; + } + +#define SERVICE_NAME "drafts.com.sun.star.rendering.Canvas" + + ::rtl::OUString SAL_CALL CanvasCustomSprite::getImplementationName() throw( uno::RuntimeException ) + { + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CANVASCUSTOMSPRITE_IMPLEMENTATION_NAME ) ); + } + + sal_Bool SAL_CALL CanvasCustomSprite::supportsService( const ::rtl::OUString& ServiceName ) throw( uno::RuntimeException ) + { + return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) ); + } + + uno::Sequence< ::rtl::OUString > SAL_CALL CanvasCustomSprite::getSupportedServiceNames() throw( uno::RuntimeException ) + { + uno::Sequence< ::rtl::OUString > aRet(1); + aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) ); + + return aRet; + } + + // Sprite + void CanvasCustomSprite::redraw( OutputDevice& rTargetSurface ) const + { + redraw( rTargetSurface, + ::vcl::unotools::pointFromB2DPoint( maPosition ) ); + } + + void CanvasCustomSprite::redraw( OutputDevice& rTargetSurface, const Point& rOutputPos ) const + { + tools::OutDevStateKeeper aStateKeeper(rTargetSurface); + + const Point aEmptyPoint; + const Bitmap aMaskBitmap( maMaskVDev->GetBitmap( aEmptyPoint, maSize ) ); + const Bitmap aContentBitmap( maVDev->GetBitmap( aEmptyPoint, maSize ) ); + + // TODO: Support for alpha-VDev + rTargetSurface.EnableMapMode( FALSE ); + + if( ::rtl::math::approxEqual(mfAlpha, 1.0) ) + { + // copy to output + rTargetSurface.DrawBitmapEx( rOutputPos, + BitmapEx( aContentBitmap, aMaskBitmap ) ); + } + else if( mfAlpha != 0.0 ) // TODO: be a little bit more tolerant here + { + // Only draw something if we're not completely transparent + BYTE nColor( static_cast<UINT8>(255.0*(1.0 - mfAlpha) + .5) ); + AlphaMask aAlpha( maSize, &nColor ); + + // mask out fully transparent areas + aAlpha.Replace( aMaskBitmap, 255 ); + + // alpha-blend to output + rTargetSurface.DrawBitmapEx( rOutputPos, + BitmapEx( aContentBitmap, aAlpha ) ); + } + } + + ::basegfx::B2DSize CanvasCustomSprite::getSize() const + { + // TODO: Use AW's wrappers once resynced + return ::basegfx::B2DSize( maSize.Width(), + maSize.Height() ); + } + + // OutDevProvider + ::OutputDevice& CanvasCustomSprite::getOutDev() + { + return *maVDev; + } + + const ::OutputDevice& CanvasCustomSprite::getOutDev() const + { + return *maVDev; + } + +} diff --git a/canvas/source/vcl/canvascustomsprite.hxx b/canvas/source/vcl/canvascustomsprite.hxx new file mode 100644 index 000000000000..4414ea6150ec --- /dev/null +++ b/canvas/source/vcl/canvascustomsprite.hxx @@ -0,0 +1,258 @@ +/************************************************************************* + * + * $RCSfile: canvascustomsprite.hxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: thb $ $Date: 2004-03-18 10:38:40 $ + * + * 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): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _VCLCANVAS_CANVASCUSTOMSPRITE_HXX +#define _VCLCANVAS_CANVASCUSTOMSPRITE_HXX + +#ifndef _CPPUHELPER_IMPLBASE3_HXX_ +#include <cppuhelper/implbase3.hxx> +#endif +#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_ +#include <com/sun/star/lang/XServiceInfo.hpp> +#endif + +#ifndef _DRAFTS_COM_SUN_STAR_RENDERING_XCUSTOMSPRITE_HPP_ +#include <drafts/com/sun/star/rendering/XCustomSprite.hpp> +#endif + +#ifndef _BGFX_POINT_B2DPOINT_HXX +#include <basegfx/point/b2dpoint.hxx> +#endif + +#ifndef _SV_VIRDEV_HXX +#include <vcl/virdev.hxx> +#endif + +#include <canvas/vclwrapper.hxx> + +#include "outdevprovider.hxx" +#include "spritecanvas.hxx" +#include "bitmapcanvas.hxx" +#include "sprite.hxx" + +#define CANVASCUSTOMSPRITE_IMPLEMENTATION_NAME "VCLCanvas::CanvasCustomSprite" + +namespace vclcanvas +{ + typedef ::cppu::WeakImplHelper3< ::drafts::com::sun::star::rendering::XCustomSprite, + ::drafts::com::sun::star::rendering::XBitmapCanvas, + ::com::sun::star::lang::XServiceInfo > CanvasCustomSprite_Base; + + /* Definition of CanvasCustomSprite class */ + + class CanvasCustomSprite : public Sprite, + public OutDevProvider, + public CanvasCustomSprite_Base + { + public: + CanvasCustomSprite( const ::drafts::com::sun::star::geometry::RealSize2D& rSpriteSize, + const SpriteCanvas::ImplRef& rSpriteCanvas ); + + // XInterface + + // Need to implement that, because Sprite and OutDevProvider + // both come with an unimplemented version of XInterface. + + // Forwarding the XInterface implementation to the + // cppu::ImplHelper templated base, which does the refcounting and + // queryInterface for us: Classname Base doing refcount and handling queryInterface + // | | + // V V + DECLARE_UNO3_AGG_DEFAULTS( CanvasCustomSprite, CanvasCustomSprite_Base ); + + // XCanvas + virtual void SAL_CALL drawPoint( const ::drafts::com::sun::star::geometry::RealPoint2D& aPoint, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL drawLine( const ::drafts::com::sun::star::geometry::RealPoint2D& aStartPoint, + const ::drafts::com::sun::star::geometry::RealPoint2D& aEndPoint, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL drawBezier( const ::drafts::com::sun::star::geometry::RealBezierSegment2D& aBezierSegment, + const ::drafts::com::sun::star::geometry::RealPoint2D& aEndPoint, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + drawPolyPolygon( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + strokePolyPolygon( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState, + const ::drafts::com::sun::star::rendering::StrokeAttributes& strokeAttributes ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + strokeTexturedPolyPolygon( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState, + const ::com::sun::star::uno::Sequence< ::drafts::com::sun::star::rendering::Texture >& textures, + const ::drafts::com::sun::star::rendering::StrokeAttributes& strokeAttributes ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + strokeTextureMappedPolyPolygon( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState, + const ::com::sun::star::uno::Sequence< ::drafts::com::sun::star::rendering::Texture >& textures, + const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::geometry::XMapping2D >& xMapping, + const ::drafts::com::sun::star::rendering::StrokeAttributes& strokeAttributes ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D > SAL_CALL + queryStrokeShapes( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState, + const ::drafts::com::sun::star::rendering::StrokeAttributes& strokeAttributes ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + fillPolyPolygon( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + fillTexturedPolyPolygon( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState, + const ::com::sun::star::uno::Sequence< ::drafts::com::sun::star::rendering::Texture >& textures ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + fillTextureMappedPolyPolygon( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState, + const ::com::sun::star::uno::Sequence< ::drafts::com::sun::star::rendering::Texture >& textures, + const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::geometry::XMapping2D >& xMapping ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCanvasFont > SAL_CALL + queryFont( const ::drafts::com::sun::star::rendering::FontRequest& fontRequest ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + drawText( const ::drafts::com::sun::star::rendering::StringContext& text, + const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCanvasFont >& xFont, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState, + sal_Int8 textDirection ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + drawOffsettedText( const ::drafts::com::sun::star::rendering::StringContext& text, + const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCanvasFont >& xFont, + const ::com::sun::star::uno::Sequence< double >& offsets, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState, + sal_Int8 textDirection ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + drawBitmap( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XBitmap >& xBitmap, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XGraphicDevice > SAL_CALL + getDevice() throw (::com::sun::star::uno::RuntimeException); + + // XBitmapCanvas (only providing, not implementing the + // interface. Also note subtle method parameter differences) + virtual void SAL_CALL copyRect( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XBitmapCanvas >& sourceCanvas, + const ::drafts::com::sun::star::geometry::RealRectangle2D& sourceRect, + const ::drafts::com::sun::star::rendering::ViewState& sourceViewState, + const ::drafts::com::sun::star::rendering::RenderState& sourceRenderState, + const ::drafts::com::sun::star::geometry::RealRectangle2D& destRect, + const ::drafts::com::sun::star::rendering::ViewState& destViewState, + const ::drafts::com::sun::star::rendering::RenderState& destRenderState ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + + // XSprite + virtual void SAL_CALL setAlpha( double alpha ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL move( const ::drafts::com::sun::star::geometry::RealPoint2D& aNewPos, const ::drafts::com::sun::star::rendering::ViewState& viewState, const ::drafts::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL transform( const ::drafts::com::sun::star::geometry::AffineMatrix2D& aTransformation ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL clip( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D >& aClip, const ::drafts::com::sun::star::rendering::ViewState& viewState, const ::drafts::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL show( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL hide( ) throw (::com::sun::star::uno::RuntimeException); + + // XCustomSprite + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCanvas > SAL_CALL + getContentCanvas( ) throw (::com::sun::star::uno::RuntimeException); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw( ::com::sun::star::uno::RuntimeException ); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw( ::com::sun::star::uno::RuntimeException ); + + // OutDevProvider + virtual OutputDevice& getOutDev(); + virtual const OutputDevice& getOutDev() const; + + // Sprite + virtual void redraw( OutputDevice& rTargetSurface ) const; + virtual void redraw( OutputDevice& rTargetSurface, const Point& rOutputPosition ) const; + virtual ::basegfx::B2DSize getSize() const; + + protected: + ~CanvasCustomSprite(); // we're a ref-counted UNO class. _We_ destroy ourselves. + + private: + // default: disabled copy/assignment + CanvasCustomSprite(const CanvasCustomSprite&); + CanvasCustomSprite& operator=( const CanvasCustomSprite& ); + + OutDevProvider::ImplRef getImplRef(); + + // for the integrated bitmap canvas implementation + ::canvas::vcltools::VCLObject<VirtualDevice> maVDev; + ::canvas::vcltools::VCLObject<VirtualDevice> maMaskVDev; + CanvasBase maCanvasHelper; + + SpriteCanvas::ImplRef mpSpriteCanvas; + + // sprite state + ::basegfx::B2DPoint maPosition; + Size maSize; + double mfAlpha; + bool mbActive; + }; +} + +#endif /* _VCLCANVAS_CANVASCUSTOMSPRITE_HXX */ diff --git a/canvas/source/vcl/canvasfont.cxx b/canvas/source/vcl/canvasfont.cxx new file mode 100644 index 000000000000..3f4d88efcd2b --- /dev/null +++ b/canvas/source/vcl/canvasfont.cxx @@ -0,0 +1,174 @@ +/************************************************************************* + * + * $RCSfile: canvasfont.cxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: thb $ $Date: 2004-03-18 10:38:40 $ + * + * 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): _______________________________________ + * + * + ************************************************************************/ + +#include "canvasfont.hxx" +#include "spritecanvas.hxx" + +#ifndef _DRAFTS_COM_SUN_STAR_RENDERING_XSPRITECANVAS_HPP_ +#include <drafts/com/sun/star/rendering/XSpriteCanvas.hpp> +#endif + +using namespace ::com::sun::star; +using namespace ::drafts::com::sun::star; + +namespace vclcanvas +{ + CanvasFont::CanvasFont( const rendering::FontRequest& rFontRequest, + const OutDevProvider::ImplRef& rCanvas ) : + maFont( Font( rFontRequest.FamilyName, rFontRequest.StyleName, ::Size( 0, + static_cast<long>(rFontRequest.CellSize + .5)) ) ), + maFontRequest( rFontRequest ), + mpCanvas( rCanvas ) + { + maFont->SetAlign( ALIGN_BASELINE ); + maFont->SetHeight( static_cast<long>(rFontRequest.CellSize + .5) ); + } + + CanvasFont::~CanvasFont() + { + } + + uno::Sequence< uno::Reference< rendering::XPolyPolygon2D > > SAL_CALL CanvasFont::queryTextShapes( const rendering::StringContext& text, + const rendering::ViewState& viewState, + const rendering::RenderState& renderState, + sal_Int8 direction ) throw (uno::RuntimeException) + { + // TODO + return uno::Sequence< uno::Reference< rendering::XPolyPolygon2D > >(); + } + + uno::Sequence< geometry::RealRectangle2D > SAL_CALL CanvasFont::queryTightMeasures( const rendering::StringContext& text, + const rendering::ViewState& viewState, + const rendering::RenderState& renderState, + sal_Int8 direction ) throw (uno::RuntimeException) + { + // TODO + return uno::Sequence< geometry::RealRectangle2D >(); + } + + uno::Sequence< geometry::RealRectangle2D > SAL_CALL CanvasFont::queryTextMeasures( const rendering::StringContext& text, + const rendering::ViewState& viewState, + const rendering::RenderState& renderState, + sal_Int8 direction ) throw (uno::RuntimeException) + { + // TODO + return uno::Sequence< geometry::RealRectangle2D >(); + } + + uno::Sequence< double > SAL_CALL CanvasFont::queryTextOffsets( const rendering::StringContext& text, + const rendering::ViewState& viewState, + const rendering::RenderState& renderState, + sal_Int8 direction ) throw (uno::RuntimeException) + { + // TODO + return uno::Sequence< double >(); + } + + geometry::RealRectangle2D SAL_CALL CanvasFont::queryTextBounds( const rendering::StringContext& text, + const rendering::ViewState& viewState, + const rendering::RenderState& renderState, + sal_Int8 direction ) throw (uno::RuntimeException) + { + // TODO + return geometry::RealRectangle2D(); + } + + rendering::FontRequest SAL_CALL CanvasFont::getFontRequest( ) throw (uno::RuntimeException) + { + return maFontRequest; + } + + rendering::FontMetrics SAL_CALL CanvasFont::getFontMetrics( ) throw (uno::RuntimeException) + { + return rendering::FontMetrics(); + } + + uno::Reference< rendering::XCanvas > SAL_CALL CanvasFont::getAssociatedCanvas( ) throw (uno::RuntimeException) + { + return uno::Reference< rendering::XCanvas >( mpCanvas.getRef(), + uno::UNO_QUERY ); + } + +#define SERVICE_NAME "drafts.com.sun.star.rendering.CanvasFont" + + ::rtl::OUString SAL_CALL CanvasFont::getImplementationName() throw( uno::RuntimeException ) + { + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CANVASFONT_IMPLEMENTATION_NAME ) ); + } + + sal_Bool SAL_CALL CanvasFont::supportsService( const ::rtl::OUString& ServiceName ) throw( uno::RuntimeException ) + { + return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) ); + } + + uno::Sequence< ::rtl::OUString > SAL_CALL CanvasFont::getSupportedServiceNames() throw( uno::RuntimeException ) + { + uno::Sequence< ::rtl::OUString > aRet(1); + aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) ); + + return aRet; + } + + ::Font CanvasFont::getVCLFont() const + { + return *maFont; + } +} diff --git a/canvas/source/vcl/canvasfont.hxx b/canvas/source/vcl/canvasfont.hxx new file mode 100644 index 000000000000..3bbbe5f21bd9 --- /dev/null +++ b/canvas/source/vcl/canvasfont.hxx @@ -0,0 +1,134 @@ +/************************************************************************* + * + * $RCSfile: canvasfont.hxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: thb $ $Date: 2004-03-18 10:38:40 $ + * + * 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): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CANVASFONT_HXX +#define _CANVASFONT_HXX + +#ifndef _CPPUHELPER_IMPLBASE2_HXX_ +#include <cppuhelper/implbase2.hxx> +#endif +#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_ +#include <com/sun/star/lang/XServiceInfo.hpp> +#endif + +#ifndef _DRAFTS_COM_SUN_STAR_RENDERING_XCANVASFONT_HPP_ +#include <drafts/com/sun/star/rendering/XCanvasFont.hpp> +#endif + +#ifndef _SV_FONT_HXX +#include <vcl/font.hxx> +#endif + +#include <canvas/vclwrapper.hxx> + +#include "canvasbase.hxx" +#include "outdevprovider.hxx" +#include "impltools.hxx" + + +#define CANVASFONT_IMPLEMENTATION_NAME "VCLCanvas::CanvasFont" + +/* Definition of CanvasFont class */ + +namespace vclcanvas +{ + class SpriteCanvas; + + class CanvasFont : public ::cppu::WeakImplHelper2< ::drafts::com::sun::star::rendering::XCanvasFont, + ::com::sun::star::lang::XServiceInfo > + { + public: + CanvasFont( const ::drafts::com::sun::star::rendering::FontRequest& fontRequest, + const OutDevProvider::ImplRef& rCanvas ); + + // XCanvasFont + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D > > SAL_CALL queryTextShapes( const ::drafts::com::sun::star::rendering::StringContext& text, const ::drafts::com::sun::star::rendering::ViewState& viewState, const ::drafts::com::sun::star::rendering::RenderState& renderState, sal_Int8 direction ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::drafts::com::sun::star::geometry::RealRectangle2D > SAL_CALL queryTightMeasures( const ::drafts::com::sun::star::rendering::StringContext& text, const ::drafts::com::sun::star::rendering::ViewState& viewState, const ::drafts::com::sun::star::rendering::RenderState& renderState, sal_Int8 direction ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::drafts::com::sun::star::geometry::RealRectangle2D > SAL_CALL queryTextMeasures( const ::drafts::com::sun::star::rendering::StringContext& text, const ::drafts::com::sun::star::rendering::ViewState& viewState, const ::drafts::com::sun::star::rendering::RenderState& renderState, sal_Int8 direction ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< double > SAL_CALL queryTextOffsets( const ::drafts::com::sun::star::rendering::StringContext& text, const ::drafts::com::sun::star::rendering::ViewState& viewState, const ::drafts::com::sun::star::rendering::RenderState& renderState, sal_Int8 direction ) throw (::com::sun::star::uno::RuntimeException); + virtual ::drafts::com::sun::star::geometry::RealRectangle2D SAL_CALL queryTextBounds( const ::drafts::com::sun::star::rendering::StringContext& text, const ::drafts::com::sun::star::rendering::ViewState& viewState, const ::drafts::com::sun::star::rendering::RenderState& renderState, sal_Int8 direction ) throw (::com::sun::star::uno::RuntimeException); + virtual ::drafts::com::sun::star::rendering::FontRequest SAL_CALL getFontRequest( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::drafts::com::sun::star::rendering::FontMetrics SAL_CALL getFontMetrics( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCanvas > SAL_CALL getAssociatedCanvas( ) throw (::com::sun::star::uno::RuntimeException); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw( ::com::sun::star::uno::RuntimeException ); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw( ::com::sun::star::uno::RuntimeException ); + + ::Font getVCLFont() const; + + protected: + ~CanvasFont(); // we're a ref-counted UNO class. _We_ destroy ourselves. + + private: + // default: disabled copy/assignment + CanvasFont(const CanvasFont&); + CanvasFont& operator=( const CanvasFont& ); + + ::canvas::vcltools::VCLObject<Font> maFont; + ::drafts::com::sun::star::rendering::FontRequest maFontRequest; + OutDevProvider::ImplRef mpCanvas; + }; + +} + +#endif /* _CANVASFONT_HXX */ diff --git a/canvas/source/vcl/exports.dxp b/canvas/source/vcl/exports.dxp new file mode 100644 index 000000000000..0c2e3e7cddd7 --- /dev/null +++ b/canvas/source/vcl/exports.dxp @@ -0,0 +1,3 @@ +component_getImplementationEnvironment +component_writeInfo +component_getFactory
\ No newline at end of file diff --git a/canvas/source/vcl/impltools.cxx b/canvas/source/vcl/impltools.cxx new file mode 100644 index 000000000000..75a492665a74 --- /dev/null +++ b/canvas/source/vcl/impltools.cxx @@ -0,0 +1,414 @@ +/************************************************************************* + * + * $RCSfile: impltools.cxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: thb $ $Date: 2004-03-18 10:38:41 $ + * + * 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): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _DRAFTS_COM_SUN_STAR_GEOMETRY_REALSIZE2D_HPP__ +#include <drafts/com/sun/star/geometry/RealSize2D.hpp> +#endif +#ifndef _DRAFTS_COM_SUN_STAR_GEOMETRY_REALPOINT2D_HPP__ +#include <drafts/com/sun/star/geometry/RealPoint2D.hpp> +#endif +#ifndef _DRAFTS_COM_SUN_STAR_GEOMETRY_REALRECTANGLE2D_HPP__ +#include <drafts/com/sun/star/geometry/RealRectangle2D.hpp> +#endif + +#ifndef _DRAFTS_COM_SUN_STAR_RENDERING_RENDERSTATE_HPP__ +#include <drafts/com/sun/star/rendering/RenderState.hpp> +#endif +#ifndef _DRAFTS_COM_SUN_STAR_RENDERING_XCANVAS_HPP__ +#include <drafts/com/sun/star/rendering/XCanvas.hpp> +#endif +#ifndef _DRAFTS_COM_SUN_STAR_RENDERING_XBITMAP_HPP__ +#include <drafts/com/sun/star/rendering/XBitmap.hpp> +#endif +#ifndef _DRAFTS_COM_SUN_STAR_RENDERING_XPOLYPOLYGON2D_HPP__ +#include <drafts/com/sun/star/rendering/XPolyPolygon2D.hpp> +#endif +#ifndef _DRAFTS_COM_SUN_STAR_GEOMETRY_REALBEZIERSEGMENT2D_HPP__ +#include <drafts/com/sun/star/geometry/RealBezierSegment2D.hpp> +#endif +#ifndef _DRAFTS_COM_SUN_STAR_RENDERING_XINTEGERBITMAP_HPP__ +#include <drafts/com/sun/star/rendering/XIntegerBitmap.hpp> +#endif + +#ifndef _TL_POLY_HXX +#include <tools/poly.hxx> +#endif +#ifndef _SV_SALBTYPE_HXX +#include <vcl/salbtype.hxx> +#endif +#ifndef _SV_BMPACC_HXX +#include <vcl/bmpacc.hxx> +#endif +#ifndef _SV_BITMAPEX_HXX +#include <vcl/bitmapex.hxx> +#endif +#ifndef _SV_METRIC_HXX +#include <vcl/metric.hxx> +#endif +#ifndef _VCL_CANVASTOOLS_HXX +#include <vcl/canvastools.hxx> +#endif + +#ifndef _BGFX_TUPLE_B2DTUPLE_HXX +#include <basegfx/tuple/b2dtuple.hxx> +#endif +#ifndef _BGFX_MATRIX_B2DHOMMATRIX_HXX +#include <basegfx/matrix/b2dhommatrix.hxx> +#endif +#ifndef _BGFX_TOOLS_CANVASTOOLS_HXX +#include <basegfx/tools/canvastools.hxx> +#endif + +#ifndef INCLUDED_RTL_MATH_HXX +#include <rtl/math.hxx> +#endif + +#include <cmath> // for fmod + +#include <canvas/canvastools.hxx> + +#include "impltools.hxx" +#include "linepolypolygon.hxx" +#include "canvasbitmap.hxx" + + +using namespace ::com::sun::star; +using namespace ::drafts::com::sun::star; + +namespace vclcanvas +{ + namespace tools + { + ::PolyPolygon polyPolygonFromXPolyPolygon2D( const uno::Reference< rendering::XPolyPolygon2D >& xPoly ) + { + uno::Reference< lang::XServiceInfo > xRef( xPoly, + uno::UNO_QUERY ); + + if( xRef.is() && + xRef->getImplementationName().equals( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(LINEPOLYPOLYGON_IMPLEMENTATION_NAME))) ) + { + // TODO: Maybe use dynamic_cast here + + // TODO: Provide true beziers here! + return static_cast<LinePolyPolygon*>(xPoly.get())->getVCLPolyPolygon(); + } + else + { + // TODO: extract points from polygon interface + } + + return ::PolyPolygon(); + } + + ::BitmapEx bitmapExFromXBitmap( const uno::Reference< rendering::XBitmap >& xBitmap ) + { + uno::Reference< lang::XServiceInfo > xRef( xBitmap, + uno::UNO_QUERY ); + + if( xRef.is() && + xRef->getImplementationName().equals( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(CANVASBITMAP_IMPLEMENTATION_NAME))) ) + { + // TODO: Maybe use dynamic_cast here + VirtualDevice& rVDev( static_cast<CanvasBitmap*>(xBitmap.get())->getVirDev() ); + const Point aEmptyPoint(0,0); + const Size aBmpSize(rVDev.GetOutputSizePixel()); + + // TODO: handle alpha vDev here + return rVDev.GetBitmap(aEmptyPoint, aBmpSize); + } + else + { + // TODO: extract points from polygon interface + } + + return ::BitmapEx(); + } + + ::Point setupFontTransform( ::Font& aVCLFont, + const rendering::ViewState& rViewState, + const rendering::RenderState& rRenderState, + OutputDevice& rOutDev ) + { + ::basegfx::B2DHomMatrix aMatrix; + + ::canvas::tools::mergeViewAndRenderTransform(aMatrix, + rViewState, + rRenderState); + + ::basegfx::B2DTuple aScale; + ::basegfx::B2DTuple aTranslate; + double nRotate, nShearX; + + aMatrix.decompose( aScale, aTranslate, nRotate, nShearX ); + + // query font metric _before_ tampering with width and height + if( !::rtl::math::approxEqual(aScale.getX(), aScale.getY()) ) + { + // retrieve true font width + const int aFontWidth( rOutDev.GetFontMetric( aVCLFont ).GetWidth() ); + + aVCLFont.SetWidth( static_cast<long>(aFontWidth * aScale.getX() + .5) ); + } + + if( !::rtl::math::approxEqual(aScale.getY(), 1.0) ) + { + const int nFontHeight( aVCLFont.GetHeight() ); + aVCLFont.SetHeight( static_cast<long>(nFontHeight * aScale.getY() + .5) ); + } + + aVCLFont.SetOrientation( static_cast< short >(-fmod(nRotate, 2*F_PI)*(1800.0/F_PI) + .5) ); + + // TODO: Missing functionality in VCL: shearing + return ::Point( static_cast<long>(aTranslate.getX() + .5), + static_cast<long>(aTranslate.getY() + .5) ); + } + + // VCL-Canvas related + //--------------------------------------------------------------------- + + ::Point mapRealPoint2D( const geometry::RealPoint2D& rPoint, + const rendering::ViewState& rViewState, + const rendering::RenderState& rRenderState ) + { + ::basegfx::B2DPoint aPoint( ::basegfx::unotools::b2DPointFromRealPoint2D(rPoint) ); + + ::basegfx::B2DHomMatrix aMatrix; + aPoint *= ::canvas::tools::mergeViewAndRenderTransform(aMatrix, + rViewState, + rRenderState); + + return ::vcl::unotools::pointFromB2DPoint( aPoint ); + } + + ::PolyPolygon mapPolyPolygon( const ::PolyPolygon& rPoly, + const rendering::ViewState& rViewState, + const rendering::RenderState& rRenderState ) + { + PolyPolygon aRes; + ::basegfx::B2DHomMatrix aMatrix; + ::canvas::tools::mergeViewAndRenderTransform(aMatrix, + rViewState, + rRenderState); + + int nCurrPoly, nCurrPoint; + for( nCurrPoly=0; nCurrPoly<rPoly.Count(); ++nCurrPoly ) + { + Polygon aDest(rPoly[nCurrPoly].GetSize()); + + for( nCurrPoint=0; nCurrPoint<aDest.GetSize(); ++nCurrPoint ) + { + ::basegfx::B2DPoint aPoint( ::vcl::unotools::b2DPointFromPoint( rPoly[nCurrPoly][nCurrPoint] ) ); + + aPoint *= aMatrix; + + aDest[nCurrPoint] = ::vcl::unotools::pointFromB2DPoint( aPoint ); + } + + aRes.Insert(aDest); + } + + return aRes; + } + + ::BitmapEx transformBitmap( const BitmapEx& rBitmap, + const rendering::ViewState& rViewState, + const rendering::RenderState& rRenderState ) + { + // calc transformation and size of bitmap to be + // generated. Note, that the translational components are + // deleted from the transformation; this can be handled by + // an offset when painting the bitmap + ::basegfx::B2DHomMatrix aTransform; + ::canvas::tools::mergeViewAndRenderTransform(aTransform, + rViewState, + rRenderState); + aTransform.set(0,2,0.0); + aTransform.set(1,2,0.0); + + const Size aBmpSize( rBitmap.GetSizePixel() ); + ::basegfx::B2DRectangle aDestRect; + + bool bCopyBack( false ); + + ::canvas::tools::calcTransformedRectBounds( aDestRect, + ::basegfx::B2DRectangle(0, + 0, + aBmpSize.Width(), + aBmpSize.Height()), + aTransform ); + + Bitmap aSrcBitmap( rBitmap.GetBitmap() ); + Bitmap aSrcAlpha; + + // differentiate mask and alpha channel (on-off + // vs. multi-level transparency) + if( rBitmap.IsTransparent() ) + { + if( rBitmap.IsAlpha() ) + aSrcAlpha = rBitmap.GetAlpha().GetBitmap(); + else + aSrcAlpha = rBitmap.GetMask(); + } + + Bitmap aDstBitmap( aSrcBitmap ); + Bitmap aDstAlpha( rBitmap.IsTransparent() ? aSrcAlpha : Bitmap( Size(1,1), 8) ); + aDstBitmap.SetSizePixel( Size( FRound( aDestRect.getMaxX() ), + FRound( aDestRect.getMaxY() ) ) ); + aDstAlpha.SetSizePixel( Size(FRound( aDestRect.getMaxX() ), + FRound( aDestRect.getMaxY() ) ) ); + { + // just to be on the safe side: let the + // ScopedAccessors get destructed before + // copy-constructing the resulting bitmap. This will + // rule out the possibility that cached accessor data + // is not yet written back. + ScopedBitmapReadAccess pReadAccess( aSrcBitmap.AcquireReadAccess(), + aSrcBitmap ); + ScopedBitmapReadAccess pAlphaReadAccess( rBitmap.IsTransparent() ? aSrcAlpha.AcquireReadAccess() : NULL, + aSrcAlpha ); + + ScopedBitmapWriteAccess pWriteAccess( aDstBitmap.AcquireWriteAccess(), + aDstBitmap ); + ScopedBitmapWriteAccess pAlphaWriteAccess( aDstAlpha.AcquireWriteAccess(), + aDstAlpha ); + + + if( pReadAccess.get() != NULL && + (pAlphaReadAccess.get() != NULL || !rBitmap.IsTransparent()) && + pWriteAccess.get() != NULL && + pAlphaWriteAccess.get() != NULL && + aTransform.isInvertible() ) + { + // we're doing inverse mapping here, i.e. mapping + // points from the destination bitmap back to the + // source + aTransform.invert(); + + const Size aDestBmpSize( aDstBitmap.GetSizePixel() ); + + // for the time being, always read as ARGB + for( int y=0; y<aDestBmpSize.Height(); ++y ) + { + // differentiate mask and alpha channel (on-off + // vs. multi-level transparency) + if( rBitmap.IsTransparent() ) + { + // Handling alpha and mask just the same... + for( int x=0; x<aDestBmpSize.Width(); ++x ) + { + ::basegfx::B2DPoint aPoint(x,y); + aPoint *= aTransform; + + const int nSrcX( FRound( aPoint.getX() + .5 ) ); + const int nSrcY( FRound( aPoint.getY() + .5 ) ); + if( nSrcX < 0 || nSrcX >= aBmpSize.Width() || + nSrcY < 0 || nSrcX >= aBmpSize.Height() ) + { + pAlphaWriteAccess->SetPixel( y, x, BitmapColor(255) ); + } + else + { + pAlphaWriteAccess->SetPixel( y, x, pAlphaReadAccess->GetPixel( nSrcY, + nSrcX ) ); + pWriteAccess->SetPixel( y, x, pReadAccess->GetPixel( nSrcY, + nSrcX ) ); + } + } + } + else + { + for( int x=0; x<aDestBmpSize.Width(); ++x ) + { + ::basegfx::B2DPoint aPoint(x,y); + aPoint *= aTransform; + + const int nSrcX( FRound( aPoint.getX() + .5 ) ); + const int nSrcY( FRound( aPoint.getY() + .5 ) ); + if( nSrcX < 0 || nSrcX >= aBmpSize.Width() || + nSrcY < 0 || nSrcX >= aBmpSize.Height() ) + { + pAlphaWriteAccess->SetPixel( y, x, BitmapColor(255) ); + } + else + { + pAlphaWriteAccess->SetPixel( y, x, BitmapColor(0) ); + pWriteAccess->SetPixel( y, x, pReadAccess->GetPixel( nSrcY, + nSrcX ) ); + } + } + } + } + + bCopyBack = true; + } + else + { + // TODO: Error handling! + } + } + + if( bCopyBack ) + return BitmapEx( aDstBitmap, AlphaMask( aDstAlpha ) ); + else + return BitmapEx(); + } + } +} diff --git a/canvas/source/vcl/impltools.hxx b/canvas/source/vcl/impltools.hxx new file mode 100644 index 000000000000..92157cb6556f --- /dev/null +++ b/canvas/source/vcl/impltools.hxx @@ -0,0 +1,195 @@ +/************************************************************************* + * + * $RCSfile: impltools.hxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: thb $ $Date: 2004-03-18 10:38:42 $ + * + * 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): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _VCLCANVAS_TOOLS_HXX +#define _VCLCANVAS_TOOLS_HXX + +#ifndef _OSL_MUTEX_HXX_ +#include <osl/mutex.hxx> +#endif +#ifndef _VOS_MUTEX_HXX_ +#include <vos/mutex.hxx> +#endif +#ifndef _SV_SVAPP_HXX +#include <vcl/svapp.hxx> +#endif + +#ifndef _SV_OUTDEV_HXX +#include <vcl/outdev.hxx> +#endif + +#ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_ +#include <com/sun/star/uno/Reference.hxx> +#endif +#ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_ +#include <com/sun/star/uno/Sequence.hxx> +#endif + +namespace basegfx +{ + namespace matrix + { + class B2DHomMatrix; + } + namespace vector + { + class B2DVector; + } + namespace point + { + class B2DPoint; + } +} + +namespace com { namespace sun { namespace star { namespace awt +{ + struct Point; + struct Size; + struct Rectangle; +} } } } + +namespace com { namespace sun { namespace star { namespace drawing +{ + struct HomogenMatrix3; +} } } } + +namespace drafts { namespace com { namespace sun { namespace star { namespace rendering +{ + struct RealPoint2D; + struct RealSize2D; + struct RealRectangle2D; + struct RenderState; + struct ViewState; + class XCanvas; + class XBitmap; + class XPolyPolygon2D; +} } } } } + + +namespace vclcanvas +{ + namespace tools + { + ::PolyPolygon + polyPolygonFromXPolyPolygon2D( const ::com::sun::star::uno::Reference< + ::drafts::com::sun::star::rendering::XPolyPolygon2D >& ); + + ::BitmapEx + bitmapExFromXBitmap( const ::com::sun::star::uno::Reference< + ::drafts::com::sun::star::rendering::XBitmap >& ); + + ::Point setupFontTransform( ::Font& aVCLFont, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState, + ::OutputDevice& rOutDev ); + + + // Little helper to encapsulate locking into policy class + class LocalGuard + { + public: + LocalGuard() : + aGuard( Application::GetSolarMutex() ) + { + } + + private: + ::vos::OGuard aGuard; + }; + + class OutDevStateKeeper + { + public: + explicit OutDevStateKeeper( OutputDevice& rOutDev ) : + mrOutDev( rOutDev ), + mbMappingWasEnable( rOutDev.IsMapModeEnabled() ) + { + mrOutDev.Push(); + mrOutDev.EnableMapMode(FALSE); + } + + ~OutDevStateKeeper() + { + mrOutDev.EnableMapMode( mbMappingWasEnable ); + mrOutDev.Pop(); + } + + private: + OutputDevice& mrOutDev; + const bool mbMappingWasEnable; + }; + + ::Point mapRealPoint2D( const ::drafts::com::sun::star::geometry::RealPoint2D& rPoint, + const ::drafts::com::sun::star::rendering::ViewState& rViewState, + const ::drafts::com::sun::star::rendering::RenderState& rRenderState ); + + ::PolyPolygon mapPolyPolygon( const ::PolyPolygon& rPoly, + const ::drafts::com::sun::star::rendering::ViewState& rViewState, + const ::drafts::com::sun::star::rendering::RenderState& rRenderState ); + + ::BitmapEx transformBitmap( const BitmapEx& rBitmap, + const ::drafts::com::sun::star::rendering::ViewState& rViewState, + const ::drafts::com::sun::star::rendering::RenderState& rRenderState ); + + } +} + +#endif /* _VCLCANVAS_TOOLS_HXX */ diff --git a/canvas/source/vcl/makefile.mk b/canvas/source/vcl/makefile.mk new file mode 100644 index 000000000000..d748dfcb81dc --- /dev/null +++ b/canvas/source/vcl/makefile.mk @@ -0,0 +1,106 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.2 $ +# +# last change: $Author: thb $ $Date: 2004-03-18 10:38:43 $ +# +# 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): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. + +PRJNAME=canvas +TARGET=vclcanvas +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------------- + +.INCLUDE : settings.mk +DLLPRE = + +# --- Common ---------------------------------------------------------- + +.IF "$(verbose)"!="" || "$(VERBOSE)"!="" +CDEFS+= -DVERBOSE +.ENDIF + +SLOFILES = $(SLO)$/spritecanvas.obj \ + $(SLO)$/linepolypolygon.obj \ + $(SLO)$/canvasfont.obj \ + $(SLO)$/graphicdevice.obj \ + $(SLO)$/canvasbitmap.obj \ + $(SLO)$/canvasbase.obj \ + $(SLO)$/bitmapcanvas.obj \ + $(SLO)$/canvascustomsprite.obj \ + $(SLO)$/redrawmanager.obj \ + $(SLO)$/impltools.obj + +SHL1TARGET=$(TARGET).uno + +SHL1STDLIBS= $(TOOLSLIB) $(CPPULIB) $(SALLIB) $(VCLLIB) $(COMPHELPERLIB) $(CPPUHELPERLIB) $(BASEGFXLIB) $(CANVASTOOLSLIB) + +#SHL1VERSIONMAP=$(TARGET).map + +SHL1IMPLIB=i$(TARGET) +SHL1LIBS=$(SLB)$/$(TARGET).lib +SHL1DEF=$(MISC)$/$(SHL1TARGET).def + +DEF1NAME=$(SHL1TARGET) +DEF1EXPORTFILE=exports.dxp + +# ========================================================================== + +.INCLUDE : target.mk diff --git a/canvas/source/vcl/outdevprovider.hxx b/canvas/source/vcl/outdevprovider.hxx new file mode 100644 index 000000000000..266a66f91e59 --- /dev/null +++ b/canvas/source/vcl/outdevprovider.hxx @@ -0,0 +1,124 @@ +/************************************************************************* + * + * $RCSfile: outdevprovider.hxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: thb $ $Date: 2004-03-18 10:38:43 $ + * + * 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): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _VCLCANVAS_OUTDEVPROVIDER_HXX +#define _VCLCANVAS_OUTDEVPROVIDER_HXX + +#ifndef _COMPHELPER_IMPLEMENTATIONREFERENCE_HXX +#include <comphelper/implementationreference.hxx> +#endif + +#ifndef _DRAFTS_COM_SUN_STAR_RENDERING_XCANVAS_HPP_ +#include <drafts/com/sun/star/rendering/XCanvas.hpp> +#endif + +class OutputDevice; + +namespace vclcanvas +{ + /* Definition of OutDevProvider interface */ + + /** Helper interface to connect CanvasBase with its various + clients. + */ + + // The problem here is the fact that first of all, XCanvas and its + // specialised interfaces form an inheritance hierarchy. Thus, + // every client of a base class implementing the commons of + // canvases, will have to implement all interface methods, and + // forward them to the base class. Thus, there's no real gain in + // using implementation inheritance here. If we instead use a + // helper class to be held as a member by its client, we have the + // problem that several base methods serve as object factories, + // generating objects which require links to the canvas + // implementation object _and_ a UNO reference. The latter is for + // lifetime issues, and should better be directly from the client + // object. + + // Therefore, every client of CanvasBase must implement this + // interface and pass a pointer to it to the CanvasBase + // instance. The XInterface base class is necessary to have basic + // UNO reference semantics. + + class OutDevProvider : public ::com::sun::star::uno::XInterface + { + public: + /** Use this type to store a C++ pointer alongside a UNO + reference to this interface. + + This is advantageous e.g. for CanvasBase, where several + helper methods (color conversion etc.) need access to the + XCanvas UNO interface. Performing a QueryInterface + everytime is a real performance killer there. + */ + typedef ::comphelper::ImplementationReference< + OutDevProvider, + ::drafts::com::sun::star::rendering::XCanvas, + ::com::sun::star::uno::XInterface > ImplRef; + + virtual ~OutDevProvider() {} + + virtual OutputDevice& getOutDev() = 0; + virtual const OutputDevice& getOutDev() const = 0; + }; +} + +#endif /* _VCLCANVAS_OUTDEVPROVIDER_HXX */ diff --git a/canvas/source/vcl/sprite.hxx b/canvas/source/vcl/sprite.hxx new file mode 100644 index 000000000000..97114e31ab58 --- /dev/null +++ b/canvas/source/vcl/sprite.hxx @@ -0,0 +1,101 @@ +/************************************************************************* + * + * $RCSfile: sprite.hxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: thb $ $Date: 2004-03-18 10:38:44 $ + * + * 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): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _VCLCANVAS_SPRITE_HXX +#define _VCLCANVAS_SPRITE_HXX + +#ifndef _RTL_REF_HXX_ +#include <rtl/ref.hxx> +#endif + +#ifndef _DRAFTS_COM_SUN_STAR_RENDERING_XCANVAS_HPP_ +#include <drafts/com/sun/star/rendering/XCanvas.hpp> +#endif + +#ifndef _BGFX_POINT_B2DSIZE_HXX +#include <basegfx/vector/b2dsize.hxx> +#endif + +class OutputDevice; + +namespace vclcanvas +{ + /* Definition of Sprite class */ + + /** Helper interface to connect SpriteCanvas with various + sprite implementations. + */ + + class Sprite : public ::com::sun::star::uno::XInterface + { + public: + typedef ::rtl::Reference< Sprite > ImplRef; + + virtual ~Sprite() {} + + virtual void redraw( OutputDevice& rTargetSurface ) const = 0; + virtual void redraw( OutputDevice& rTargetSurface, const Point& rOutputPosition ) const = 0; + + virtual ::basegfx::B2DSize getSize() const = 0; + }; +} + +#endif /* _VCLCANVAS_SPRITE_HXX */ diff --git a/canvas/source/vcl/spritecanvas.cxx b/canvas/source/vcl/spritecanvas.cxx new file mode 100644 index 000000000000..c2dfb89c69f8 --- /dev/null +++ b/canvas/source/vcl/spritecanvas.cxx @@ -0,0 +1,532 @@ +/************************************************************************* + * + * $RCSfile: spritecanvas.cxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: thb $ $Date: 2004-03-18 10:38:44 $ + * + * 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): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif + +#ifndef _OSL_MUTEX_HXX_ +#include <osl/mutex.hxx> +#endif +#ifndef _VOS_MUTEX_HXX_ +#include <vos/mutex.hxx> +#endif +#ifndef _SV_SVAPP_HXX +#include <vcl/svapp.hxx> +#endif + +#ifndef _SV_OUTDEV_HXX +#include <vcl/outdev.hxx> +#endif +#ifndef _SV_WINDOW_HXX +#include <vcl/window.hxx> +#endif +#ifndef _SV_BITMAPEX_HXX +#include <vcl/bitmapex.hxx> +#endif + +#ifndef _COM_SUN_STAR_REGISTRY_XREGISTRYKEY_HPP_ +#include <com/sun/star/registry/XRegistryKey.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_ +#include <com/sun/star/lang/XInitialization.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_ +#include <com/sun/star/lang/XServiceInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XSERVICENAME_HPP_ +#include <com/sun/star/lang/XServiceName.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XCOMPONENTCONTEXT_HPP_ +#include <com/sun/star/uno/XComponentContext.hpp> +#endif + +#ifndef _CPPUHELPER_FACTORY_HXX_ +#include <cppuhelper/factory.hxx> +#endif +#ifndef _CPPUHELPER_IMPLBASE4_HXX_ +#include <cppuhelper/implbase4.hxx> +#endif +#ifndef _CPPUHELPER_IMPLEMENTATIONENTRY_HXX_ +#include <cppuhelper/implementationentry.hxx> +#endif +#ifndef _CPPUHELPER_IMPLEMENTATIONENTRY_HXX_ +#include <cppuhelper/implementationentry.hxx> +#endif + +#ifndef _DRAFTS_COM_SUN_STAR_RENDERING_XSPRITECANVAS_HPP_ +#include <drafts/com/sun/star/rendering/XSpriteCanvas.hpp> +#endif + +#ifndef BOOST_SCOPED_ARRAY_HPP_INCLUDED +#include <external/boost/scoped_array.hpp> +#endif + +#ifndef _BGFX_MATRIX_B2DHOMMATRIX_HXX +#include <basegfx/matrix/b2dhommatrix.hxx> +#endif +#ifndef _BGFX_POINT_B2DPOINT_HXX +#include <basegfx/point/b2dpoint.hxx> +#endif +#ifndef _BGFX_TOOLS_CANVASTOOLS_HXX +#include <basegfx/tools/canvastools.hxx> +#endif + +#include <algorithm> + +#include <canvas/verbosetrace.hxx> + +#include <canvas/canvastools.hxx> + +#include "impltools.hxx" +#include "canvasfont.hxx" +#include "spritecanvas.hxx" +#include "graphicdevice.hxx" +#include "outdevprovider.hxx" +#include "canvascustomsprite.hxx" +#include "bitmapcanvas.hxx" + +using namespace ::com::sun::star; +using namespace ::drafts::com::sun::star; + +#define IMPLEMENTATION_NAME "VCLCanvas::SpriteCanvas" +#define SERVICE_NAME "drafts.com.sun.star.rendering.Canvas" + +namespace +{ + static ::rtl::OUString SAL_CALL getImplementationName_SpriteCanvas() + { + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) ); + } + + static uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_SpriteCanvas() + { + uno::Sequence< ::rtl::OUString > aRet(1); + aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) ); + + return aRet; + } + +} + +namespace vclcanvas +{ + SpriteCanvas::SpriteCanvas( const uno::Reference< uno::XComponentContext >& rxContext ) : + SpriteCanvas_Base( m_aMutex ) + { + } + + SpriteCanvas::~SpriteCanvas() + { + } + + OutDevProvider::ImplRef SpriteCanvas::getImplRef() + { + return OutDevProvider::ImplRef::createFromQuery( this ); + } + + void SAL_CALL SpriteCanvas::drawPoint( const geometry::RealPoint2D& aPoint, + const rendering::ViewState& viewState, + const rendering::RenderState& renderState ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + checkOurState(); + + mpRedrawManager->backgroundDirty(); + maCanvasHelper.drawPoint( aPoint, viewState, renderState, getImplRef() ); + } + + void SAL_CALL SpriteCanvas::drawLine( const geometry::RealPoint2D& aStartPoint, const geometry::RealPoint2D& aEndPoint, const rendering::ViewState& viewState, const rendering::RenderState& renderState ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + checkOurState(); + + mpRedrawManager->backgroundDirty(); + maCanvasHelper.drawLine(aStartPoint, aEndPoint, viewState, renderState, getImplRef()); + } + + void SAL_CALL SpriteCanvas::drawBezier( const geometry::RealBezierSegment2D& aBezierSegment, + const geometry::RealPoint2D& aEndPoint, + const rendering::ViewState& viewState, + const rendering::RenderState& renderState ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + checkOurState(); + + mpRedrawManager->backgroundDirty(); + maCanvasHelper.drawBezier(aBezierSegment, aEndPoint, viewState, renderState, getImplRef()); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL SpriteCanvas::drawPolyPolygon( const uno::Reference< rendering::XPolyPolygon2D >& xPolyPolygon, const rendering::ViewState& viewState, const rendering::RenderState& renderState ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + checkOurState(); + + // TODO: Remember to handle backgroundDirty also for XCachedPrimitive redraw! + mpRedrawManager->backgroundDirty(); + return maCanvasHelper.drawPolyPolygon(xPolyPolygon, viewState, renderState, getImplRef()); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL SpriteCanvas::strokePolyPolygon( const uno::Reference< rendering::XPolyPolygon2D >& xPolyPolygon, const rendering::ViewState& viewState, const rendering::RenderState& renderState, const rendering::StrokeAttributes& strokeAttributes ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + checkOurState(); + + mpRedrawManager->backgroundDirty(); + return maCanvasHelper.strokePolyPolygon(xPolyPolygon, viewState, renderState, strokeAttributes, getImplRef()); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL SpriteCanvas::strokeTexturedPolyPolygon( const uno::Reference< rendering::XPolyPolygon2D >& xPolyPolygon, const rendering::ViewState& viewState, const rendering::RenderState& renderState, const uno::Sequence< rendering::Texture >& textures, const rendering::StrokeAttributes& strokeAttributes ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + checkOurState(); + + mpRedrawManager->backgroundDirty(); + return maCanvasHelper.strokeTexturedPolyPolygon(xPolyPolygon, viewState, renderState, textures, strokeAttributes, getImplRef()); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL SpriteCanvas::strokeTextureMappedPolyPolygon( const uno::Reference< rendering::XPolyPolygon2D >& xPolyPolygon, const rendering::ViewState& viewState, const rendering::RenderState& renderState, const uno::Sequence< rendering::Texture >& textures, const uno::Reference< geometry::XMapping2D >& xMapping, const rendering::StrokeAttributes& strokeAttributes ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + checkOurState(); + + mpRedrawManager->backgroundDirty(); + return maCanvasHelper.strokeTextureMappedPolyPolygon(xPolyPolygon, viewState, renderState, textures, xMapping, strokeAttributes, getImplRef()); + } + + uno::Reference< rendering::XPolyPolygon2D > SAL_CALL SpriteCanvas::queryStrokeShapes( const uno::Reference< rendering::XPolyPolygon2D >& xPolyPolygon, const rendering::ViewState& viewState, const rendering::RenderState& renderState, const rendering::StrokeAttributes& strokeAttributes ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + return maCanvasHelper.queryStrokeShapes(xPolyPolygon, viewState, renderState, strokeAttributes, getImplRef()); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL SpriteCanvas::fillPolyPolygon( const uno::Reference< rendering::XPolyPolygon2D >& xPolyPolygon, const rendering::ViewState& viewState, const rendering::RenderState& renderState ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + checkOurState(); + + mpRedrawManager->backgroundDirty(); + return maCanvasHelper.fillPolyPolygon(xPolyPolygon, viewState, renderState, getImplRef() ); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL SpriteCanvas::fillTexturedPolyPolygon( const uno::Reference< rendering::XPolyPolygon2D >& xPolyPolygon, const rendering::ViewState& viewState, const rendering::RenderState& renderState, const uno::Sequence< rendering::Texture >& textures ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + checkOurState(); + + mpRedrawManager->backgroundDirty(); + return maCanvasHelper.fillTexturedPolyPolygon(xPolyPolygon, viewState, renderState, textures, getImplRef()); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL SpriteCanvas::fillTextureMappedPolyPolygon( const uno::Reference< rendering::XPolyPolygon2D >& xPolyPolygon, const rendering::ViewState& viewState, const rendering::RenderState& renderState, const uno::Sequence< rendering::Texture >& textures, const uno::Reference< geometry::XMapping2D >& xMapping ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + checkOurState(); + + mpRedrawManager->backgroundDirty(); + return maCanvasHelper.fillTextureMappedPolyPolygon(xPolyPolygon, viewState, renderState, textures, xMapping, getImplRef()); + } + + uno::Reference< rendering::XCanvasFont > SAL_CALL SpriteCanvas::queryFont( const rendering::FontRequest& fontRequest ) throw (uno::RuntimeException) + { + return maCanvasHelper.queryFont( fontRequest, getImplRef() ); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL SpriteCanvas::drawText( const rendering::StringContext& text, + const uno::Reference< rendering::XCanvasFont >& xFont, + const rendering::ViewState& viewState, + const rendering::RenderState& renderState, + sal_Int8 textDirection ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + checkOurState(); + + mpRedrawManager->backgroundDirty(); + return maCanvasHelper.drawText(text, xFont, viewState, renderState, textDirection, getImplRef()); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL SpriteCanvas::drawOffsettedText( const rendering::StringContext& text, const uno::Reference< rendering::XCanvasFont >& xFont, const uno::Sequence< double >& offsets, const rendering::ViewState& viewState, const rendering::RenderState& renderState, sal_Int8 textDirection ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + checkOurState(); + + mpRedrawManager->backgroundDirty(); + return maCanvasHelper.drawOffsettedText(text, xFont, offsets, viewState, renderState, textDirection, getImplRef()); + } + + uno::Reference< rendering::XCachedPrimitive > SAL_CALL SpriteCanvas::drawBitmap( const uno::Reference< rendering::XBitmap >& xBitmap, const rendering::ViewState& viewState, const rendering::RenderState& renderState ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + checkOurState(); + + mpRedrawManager->backgroundDirty(); + return maCanvasHelper.drawBitmap(xBitmap, viewState, renderState, getImplRef()); + } + + uno::Reference< rendering::XGraphicDevice > SAL_CALL SpriteCanvas::getDevice() throw (uno::RuntimeException) + { + return maCanvasHelper.getDevice( getImplRef() ); + } + + void SAL_CALL SpriteCanvas::copyRect( const uno::Reference< rendering::XBitmapCanvas >& sourceCanvas, + const geometry::RealRectangle2D& sourceRect, + const rendering::ViewState& sourceViewState, + const rendering::RenderState& sourceRenderState, + const geometry::RealRectangle2D& destRect, + const rendering::ViewState& destViewState, + const rendering::RenderState& destRenderState ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + checkOurState(); + + tools::LocalGuard aGuard; + + mpRedrawManager->backgroundDirty(); + } + + uno::Reference< rendering::XAnimatedSprite > SAL_CALL SpriteCanvas::createSpriteFromAnimation( const uno::Reference< rendering::XAnimation >& animation ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + tools::LocalGuard aGuard; + + return uno::Reference< rendering::XAnimatedSprite >(NULL); + } + + uno::Reference< rendering::XAnimatedSprite > SAL_CALL SpriteCanvas::createSpriteFromBitmaps( const uno::Sequence< uno::Reference< rendering::XBitmap > >& animationBitmaps, + sal_Int16 interpolationMode ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + tools::LocalGuard aGuard; + + return uno::Reference< rendering::XAnimatedSprite >(NULL); + } + + uno::Reference< rendering::XCustomSprite > SAL_CALL SpriteCanvas::createCustomSprite( const geometry::RealSize2D& spriteSize ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + tools::LocalGuard aGuard; + + return uno::Reference< rendering::XCustomSprite >( + new CanvasCustomSprite( spriteSize, + ImplRef(this)) ); + } + + uno::Reference< rendering::XSprite > SAL_CALL SpriteCanvas::createClonedSprite( const uno::Reference< rendering::XSprite >& original ) throw (lang::IllegalArgumentException, uno::RuntimeException) + { + tools::LocalGuard aGuard; + + return uno::Reference< rendering::XSprite >(NULL); + } + + sal_Bool SAL_CALL SpriteCanvas::updateScreen() throw (uno::RuntimeException) + { + checkOurState(); + + tools::LocalGuard aGuard; + + mpRedrawManager->updateScreen(); + + // commit to screen + maCanvasHelper.flush(); + + return sal_True; + } + + void SAL_CALL SpriteCanvas::initialize( const uno::Sequence< uno::Any >& aArguments ) throw( uno::Exception, + uno::RuntimeException) + { + VERBOSE_TRACE( "SpriteCanvas::initialize called" ); + + OSL_ENSURE( aArguments.getLength() >= 1, + "SpriteCanvas::initialize: wrong number of arguments" ); + + // We expect a single Any here, containing a pointer to a valid + // VCL window, on which to output + if( aArguments.getLength() >= 1 && + aArguments[0].getValueTypeClass() == uno::TypeClass_HYPER ) + { + mpOutputWindow = *(Window**)(aArguments[0].getValue()); + OSL_ENSURE( mpOutputWindow != NULL, + "SpriteCanvas::initialize: invalid Window pointer" ); + + // setup back buffer + maVDev->SetOutputSizePixel( mpOutputWindow->GetOutputSizePixel() ); + + // always render into back buffer + maCanvasHelper.setOutDev( *maVDev ); + + mpRedrawManager = ::std::auto_ptr< RedrawManager >( new RedrawManager( *mpOutputWindow, + *maVDev ) ); + } + } + + ::rtl::OUString SAL_CALL SpriteCanvas::getImplementationName() throw( uno::RuntimeException ) + { + return getImplementationName_SpriteCanvas(); + } + + sal_Bool SAL_CALL SpriteCanvas::supportsService( const ::rtl::OUString& ServiceName ) throw( uno::RuntimeException ) + { + return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) ); + } + + uno::Sequence< ::rtl::OUString > SAL_CALL SpriteCanvas::getSupportedServiceNames() throw( uno::RuntimeException ) + { + return getSupportedServiceNames_SpriteCanvas(); + } + + ::rtl::OUString SAL_CALL SpriteCanvas::getServiceName( ) throw (::com::sun::star::uno::RuntimeException) + { + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICE_NAME ) ); + } + + uno::Reference< uno::XInterface > SAL_CALL SpriteCanvas::createInstance( const uno::Reference< uno::XComponentContext >& xContext ) throw ( uno::Exception ) + { + return uno::Reference< uno::XInterface >( static_cast<cppu::OWeakObject*>(new SpriteCanvas( xContext )) ); + } + + // SpriteSurface + void SpriteCanvas::showSprite( const Sprite::ImplRef& sprite ) + { + checkOurState(); + + tools::LocalGuard aGuard; + mpRedrawManager->showSprite( sprite ); + } + + void SpriteCanvas::hideSprite( const Sprite::ImplRef& sprite ) + { + checkOurState(); + + // strictly speaking, the solar mutex here is overkill, and a + // object mutex would suffice. But on the other hand, nearly + // every other method needs the solar mutex anyway, so it's no + // big loss (and much simpler) here. + tools::LocalGuard aGuard; + mpRedrawManager->hideSprite( sprite ); + } + + void SpriteCanvas::moveSprite( const Sprite::ImplRef& sprite, + const Point& rOldPos, + const Point& rNewPos ) + { + checkOurState(); + + tools::LocalGuard aGuard; + mpRedrawManager->moveSprite( sprite, rOldPos, rNewPos ); + } + + void SpriteCanvas::updateSprite( const Sprite::ImplRef& sprite, + const Point& rPos, + const Rectangle& rUpdateArea ) + { + checkOurState(); + + tools::LocalGuard aGuard; + mpRedrawManager->updateSprite( sprite, rPos, rUpdateArea ); + } + + // OutDevProvider + ::OutputDevice& SpriteCanvas::getOutDev() + { + return maCanvasHelper.getOutDev(); + } + + const ::OutputDevice& SpriteCanvas::getOutDev() const + { + return maCanvasHelper.getOutDev(); + } + + void SpriteCanvas::checkOurState() + { + if( mpOutputWindow == NULL || + mpRedrawManager.get() == NULL ) + throw uno::RuntimeException(); + } + +} + +namespace +{ + /* shared lib exports implemented with helpers */ + static struct ::cppu::ImplementationEntry s_component_entries [] = + { + { + vclcanvas::SpriteCanvas::createInstance, getImplementationName_SpriteCanvas, + getSupportedServiceNames_SpriteCanvas, ::cppu::createSingleComponentFactory, + 0, 0 + }, + { 0, 0, 0, 0, 0, 0 } + }; +} + + +/* Exported UNO methods for registration and object creation. + ========================================================== + */ +extern "C" +{ + void SAL_CALL component_getImplementationEnvironment( const sal_Char** ppEnvTypeName, + uno_Environment** ppEnv ) + { + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; + } + + sal_Bool SAL_CALL component_writeInfo( lang::XMultiServiceFactory* xMgr, + registry::XRegistryKey* xRegistry ) + { + return ::cppu::component_writeInfoHelper( + xMgr, xRegistry, s_component_entries ); + } + + void * SAL_CALL component_getFactory( sal_Char const* implName, + lang::XMultiServiceFactory* xMgr, + registry::XRegistryKey* xRegistry ) + { + return ::cppu::component_getFactoryHelper( + implName, xMgr, xRegistry, s_component_entries ); + } +} diff --git a/canvas/source/vcl/spritecanvas.hxx b/canvas/source/vcl/spritecanvas.hxx new file mode 100644 index 000000000000..3ef72a84bea9 --- /dev/null +++ b/canvas/source/vcl/spritecanvas.hxx @@ -0,0 +1,298 @@ +/************************************************************************* + * + * $RCSfile: spritecanvas.hxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: thb $ $Date: 2004-03-18 10:38:44 $ + * + * 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): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _VCLCANVAS_SPRITECANVAS_HXX_ +#define _VCLCANVAS_SPRITECANVAS_HXX_ + +#include <memory> + +#ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_ +#include <com/sun/star/uno/Reference.hxx> +#endif +#ifndef _COM_SUN_STAR_UNO_ANY_HXX_ +#include <com/sun/star/uno/Any.hxx> +#endif + +#ifndef _CPPUHELPER_COMPBASE4_HXX_ +#include <cppuhelper/compbase4.hxx> +#endif +#ifndef _COMPHELPER_BROADCASTHELPER_HXX_ +#include <comphelper/broadcasthelper.hxx> +#endif +#ifndef _COMPHELPER_UNO3_HXX +#include <comphelper/uno3.hxx> +#endif + +#ifndef _RTL_REF_HXX_ +#include <rtl/ref.hxx> +#endif + +#ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_ +#include <com/sun/star/lang/XInitialization.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_ +#include <com/sun/star/lang/XServiceInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XSERVICENAME_HPP_ +#include <com/sun/star/lang/XServiceName.hpp> +#endif + +#ifndef _SV_VIRDEV_HXX +#include <vcl/virdev.hxx> +#endif + +#ifndef _DRAFTS_COM_SUN_STAR_RENDERING_XSPRITECANVAS_HPP_ +#include <drafts/com/sun/star/rendering/XSpriteCanvas.hpp> +#endif + +#include <canvas/vclwrapper.hxx> + +#include "redrawmanager.hxx" +#include "spritesurface.hxx" +#include "outdevprovider.hxx" +#include "canvasbase.hxx" +#include "impltools.hxx" + +class OutputDevice; +class Point; + +namespace com { namespace sun { namespace star { namespace uno +{ + class XComponentContext; + class RuntimeException; +} } } } + +class Window; + +namespace vclcanvas +{ + typedef ::cppu::WeakComponentImplHelper4< ::drafts::com::sun::star::rendering::XSpriteCanvas, + ::com::sun::star::lang::XInitialization, + ::com::sun::star::lang::XServiceInfo, + ::com::sun::star::lang::XServiceName > SpriteCanvas_Base; + + class SpriteCanvas : public ::comphelper::OBaseMutex, + public SpriteSurface, + public OutDevProvider, + public SpriteCanvas_Base + + { + public: + typedef ::rtl::Reference< SpriteCanvas > ImplRef; + + SpriteCanvas( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext ); + + // XInterface + + // Need to implement that, because OutDevProvide comes with an + // unimplemented version of XInterface. + + // Forwarding the XInterface implementation to the + // cppu::ImplHelper templated base, which does the refcounting and + // queryInterface for us: Classname Base doing refcount and handling queryInterface + // | | + // V V + DECLARE_UNO3_AGG_DEFAULTS( SpriteCanvas, SpriteCanvas_Base ); + + // XCanvas + virtual void SAL_CALL drawPoint( const ::drafts::com::sun::star::geometry::RealPoint2D& aPoint, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL drawLine( const ::drafts::com::sun::star::geometry::RealPoint2D& aStartPoint, + const ::drafts::com::sun::star::geometry::RealPoint2D& aEndPoint, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL drawBezier( const ::drafts::com::sun::star::geometry::RealBezierSegment2D& aBezierSegment, + const ::drafts::com::sun::star::geometry::RealPoint2D& aEndPoint, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + drawPolyPolygon( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + strokePolyPolygon( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState, + const ::drafts::com::sun::star::rendering::StrokeAttributes& strokeAttributes ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + strokeTexturedPolyPolygon( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState, + const ::com::sun::star::uno::Sequence< ::drafts::com::sun::star::rendering::Texture >& textures, + const ::drafts::com::sun::star::rendering::StrokeAttributes& strokeAttributes ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + strokeTextureMappedPolyPolygon( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState, + const ::com::sun::star::uno::Sequence< ::drafts::com::sun::star::rendering::Texture >& textures, + const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::geometry::XMapping2D >& xMapping, + const ::drafts::com::sun::star::rendering::StrokeAttributes& strokeAttributes ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D > SAL_CALL + queryStrokeShapes( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState, + const ::drafts::com::sun::star::rendering::StrokeAttributes& strokeAttributes ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + fillPolyPolygon( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + fillTexturedPolyPolygon( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState, + const ::com::sun::star::uno::Sequence< ::drafts::com::sun::star::rendering::Texture >& textures ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + fillTextureMappedPolyPolygon( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState, + const ::com::sun::star::uno::Sequence< ::drafts::com::sun::star::rendering::Texture >& textures, + const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::geometry::XMapping2D >& xMapping ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCanvasFont > SAL_CALL + queryFont( const ::drafts::com::sun::star::rendering::FontRequest& fontRequest ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + drawText( const ::drafts::com::sun::star::rendering::StringContext& text, + const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCanvasFont >& xFont, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState, + sal_Int8 textDirection ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + drawOffsettedText( const ::drafts::com::sun::star::rendering::StringContext& text, + const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCanvasFont >& xFont, + const ::com::sun::star::uno::Sequence< double >& offsets, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState, + sal_Int8 textDirection ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCachedPrimitive > SAL_CALL + drawBitmap( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XBitmap >& xBitmap, + const ::drafts::com::sun::star::rendering::ViewState& viewState, + const ::drafts::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XGraphicDevice > SAL_CALL + getDevice() throw (::com::sun::star::uno::RuntimeException); + + // XBitmapCanvas (only providing, not implementing the + // interface. Also note subtle method parameter differences) + virtual void SAL_CALL copyRect( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XBitmapCanvas >& sourceCanvas, + const ::drafts::com::sun::star::geometry::RealRectangle2D& sourceRect, + const ::drafts::com::sun::star::rendering::ViewState& sourceViewState, + const ::drafts::com::sun::star::rendering::RenderState& sourceRenderState, + const ::drafts::com::sun::star::geometry::RealRectangle2D& destRect, + const ::drafts::com::sun::star::rendering::ViewState& destViewState, + const ::drafts::com::sun::star::rendering::RenderState& destRenderState ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + + // XSpriteCanvas + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XAnimatedSprite > SAL_CALL createSpriteFromAnimation( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XAnimation >& animation ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XAnimatedSprite > SAL_CALL createSpriteFromBitmaps( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XBitmap > >& animationBitmaps, + sal_Int16 interpolationMode ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XCustomSprite > SAL_CALL createCustomSprite( const ::drafts::com::sun::star::geometry::RealSize2D& spriteSize ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XSprite > SAL_CALL createClonedSprite( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::rendering::XSprite >& original ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL updateScreen() throw (::com::sun::star::uno::RuntimeException); + + // XInitialization + virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw( ::com::sun::star::uno::Exception, + ::com::sun::star::uno::RuntimeException); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw( ::com::sun::star::uno::RuntimeException ); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw( ::com::sun::star::uno::RuntimeException ); + + // XServiceName + virtual ::rtl::OUString SAL_CALL getServiceName( ) throw (::com::sun::star::uno::RuntimeException); + + // factory + static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext ) throw ( ::com::sun::star::uno::Exception ); + + // SpriteSurface + virtual void showSprite( const Sprite::ImplRef& sprite ); + virtual void hideSprite( const Sprite::ImplRef& sprite ); + virtual void moveSprite( const Sprite::ImplRef& sprite, + const Point& rOldPos, + const Point& rNewPos ); + virtual void updateSprite( const Sprite::ImplRef& sprite, + const Point& rPos, + const Rectangle& rUpdateArea ); + + // OutDevProvider + virtual OutputDevice& getOutDev(); + virtual const OutputDevice& getOutDev() const; + + protected: + ~SpriteCanvas(); // we're a ref-counted UNO class. _We_ destroy ourselves. + + private: + // default: disabled copy/assignment + SpriteCanvas(const SpriteCanvas&); + SpriteCanvas& operator=( const SpriteCanvas& ); + + void checkOurState(); // throws + OutDevProvider::ImplRef getImplRef(); + + // TODO: Lifetime issue. Cannot control pointer validity over + // object lifetime, since we're a UNO component + Window* mpOutputWindow; // for the screen output + ::canvas::vcltools::VCLObject<VirtualDevice> maVDev; // for the back-buffer + ::std::auto_ptr< RedrawManager > mpRedrawManager; // handles smooth screen updates for us + CanvasBase maCanvasHelper; // for the basic canvas implementation + }; +} + +#endif |