Update ooo320-m1
[ooovba.git] / canvas / source / java / BitmapCanvas.java
blobe28027e21bb4da3b1dd6976ce1a907b14ac78443
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: BitmapCanvas.java,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // UNO
32 import com.sun.star.uno.UnoRuntime;
33 import com.sun.star.uno.XComponentContext;
34 import com.sun.star.uno.AnyConverter;
35 import com.sun.star.uno.IQueryInterface;
36 import com.sun.star.lang.XInitialization;
37 import com.sun.star.lib.uno.helper.WeakBase;
39 // OOo AWT
40 import com.sun.star.awt.*;
42 // Canvas
43 import com.sun.star.rendering.*;
44 import com.sun.star.geometry.*;
46 // Java AWT
47 import java.awt.*;
48 import java.awt.image.*;
49 import java.awt.geom.*;
51 public class BitmapCanvas
52 extends CanvasBase
53 implements com.sun.star.rendering.XBitmapCanvas,
54 com.sun.star.lang.XServiceInfo
56 private Graphics2D graphics;
58 public Graphics2D getGraphics()
60 return graphics;
63 //----------------------------------------------------------------------------------
65 public BitmapCanvas( Graphics2D _graphics )
67 graphics = _graphics;
70 //----------------------------------------------------------------------------------
73 // XBitmapCanvas impl
74 // ==================
77 public synchronized void copyRect( com.sun.star.rendering.XBitmapCanvas sourceCanvas,
78 com.sun.star.geometry.RealRectangle2D sourceRect,
79 com.sun.star.rendering.ViewState sourceViewState,
80 com.sun.star.rendering.RenderState sourceRenderState,
81 com.sun.star.geometry.RealRectangle2D destRect,
82 com.sun.star.rendering.ViewState destViewState,
83 com.sun.star.rendering.RenderState destRenderState )
85 // TODO: create temp image when transform is non-trivial
87 if( sourceCanvas == this )
89 // copy rectangle within the canvas
90 graphics.copyArea((int)sourceRect.X1,
91 (int)sourceRect.Y1,
92 (int)(sourceRect.X2 - sourceRect.X1),
93 (int)(sourceRect.Y2 - sourceRect.Y1),
94 (int)(destRect.X1 - sourceRect.X1),
95 (int)(destRect.Y1 - sourceRect.Y1) );
97 else
99 if( sourceCanvas instanceof JavaCanvas )
101 // cache
102 CanvasUtils.setupGraphicsState( graphics, destViewState, destRenderState, CanvasUtils.alsoSetupPaint );
104 // TODO: really extract correct source rect here
105 BufferedImage backBuffer = ((BufferedGraphics2D)((JavaCanvas)sourceCanvas).getGraphics()).getBackBuffer();
106 graphics.drawImage( backBuffer, 0, 0, null );
107 CanvasUtils.postRenderImageTreatment( backBuffer );
110 // TODO: foreign canvas
114 //----------------------------------------------------------------------------------
116 private static final String s_implName = "XBitmapCanvas.java.impl";
117 private static final String s_serviceName = "com.sun.star.rendering.BitmapCanvas";
119 //----------------------------------------------------------------------------------
122 // XServiceInfo impl
123 // =================
125 public String getImplementationName()
127 return s_implName;
130 public String [] getSupportedServiceNames()
132 return new String [] { s_serviceName };
135 public boolean supportsService( String serviceName )
137 return serviceName.equals( s_serviceName );