01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: /**
18: * @author Alexey A. Petrenko
19: * @version $Revision$
20: */package org.apache.harmony.awt.gl.image;
21:
22: import java.awt.Graphics;
23: import java.awt.GraphicsConfiguration;
24: import java.awt.Rectangle;
25: import java.awt.Shape;
26: import java.awt.font.GlyphVector;
27: import java.awt.image.BufferedImage;
28: import java.awt.image.ColorModel;
29: import java.awt.image.WritableRaster;
30:
31: import org.apache.harmony.awt.gl.CommonGraphics2D;
32: import org.apache.harmony.awt.gl.Surface;
33: import org.apache.harmony.awt.gl.render.JavaBlitter;
34: import org.apache.harmony.awt.gl.render.NativeImageBlitter;
35:
36: /**
37: * BufferedImageGraphics2D is implementation of CommonGraphics2D for
38: * drawing on buffered images.
39: */
40: public class BufferedImageGraphics2D extends CommonGraphics2D {
41: private BufferedImage bi = null;
42: private Rectangle bounds = null;
43:
44: public BufferedImageGraphics2D(BufferedImage bi) {
45: super ();
46: this .bi = bi;
47: this .bounds = new Rectangle(0, 0, bi.getWidth(), bi.getHeight());
48: clip(bounds);
49: dstSurf = Surface.getImageSurface(bi);
50: if (dstSurf.isNativeDrawable()) {
51: blitter = NativeImageBlitter.getInstance();
52: } else {
53: blitter = JavaBlitter.getInstance();
54: }
55: }
56:
57: @Override
58: public void copyArea(int x, int y, int width, int height, int dx,
59: int dy) {
60: }
61:
62: @Override
63: public Graphics create() {
64: BufferedImageGraphics2D res = new BufferedImageGraphics2D(bi);
65: copyInternalFields(res);
66: return res;
67: }
68:
69: @Override
70: public GraphicsConfiguration getDeviceConfiguration() {
71: return null;
72: }
73:
74: public ColorModel getColorModel() {
75: return bi.getColorModel();
76: }
77:
78: public WritableRaster getWritableRaster() {
79: return bi.getRaster();
80: }
81:
82: @Override
83: public void drawString(String str, float x, float y) {
84: Shape sh = font.createGlyphVector(this .getFontRenderContext(),
85: str).getOutline(x, y);
86: fill(sh);
87: }
88:
89: @Override
90: public void drawGlyphVector(GlyphVector gv, float x, float y) {
91: Shape sh = gv.getOutline(x, y);
92: this.fill(sh);
93: }
94: }
|