more improvements in slide rendering
[poi.git] / src / scratchpad / src / org / apache / poi / hslf / model / Background.java
blobe2718f6acaa5551bdad9f5bf70de4e36cac01dee
1 /* ====================================================================
2 Licensed to the Apache Software Foundation (ASF) under one or more
3 contributor license agreements. See the NOTICE file distributed with
4 this work for additional information regarding copyright ownership.
5 The ASF licenses this file to You under the Apache License, Version 2.0
6 (the "License"); you may not use this file except in compliance with
7 the License. You may obtain a copy of the License at
9 http://www.apache.org/licenses/LICENSE-2.0
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 ==================================================================== */
18 package org.apache.poi.hslf.model;
20 import org.apache.poi.ddf.EscherContainerRecord;
21 import org.apache.poi.hslf.usermodel.PictureData;
22 import org.apache.poi.hslf.blip.Bitmap;
23 import org.apache.poi.util.POILogger;
25 import javax.imageio.ImageIO;
26 import java.awt.*;
27 import java.awt.image.BufferedImage;
28 import java.io.ByteArrayInputStream;
30 /**
31 * Background shape
33 * @author Yegor Kozlov
35 public class Background extends Shape {
37 protected Background(EscherContainerRecord escherRecord, Shape parent) {
38 super(escherRecord, parent);
41 protected EscherContainerRecord createSpContainer(boolean isChild) {
42 return null;
45 public void draw(Graphics2D graphics) {
46 Fill f = getFill();
47 Dimension pg = getSheet().getSlideShow().getPageSize();
48 Rectangle anchor = new Rectangle(0, 0, pg.width, pg.height);
49 switch (f.getFillType()) {
50 case Fill.FILL_SOLID:
51 Color color = f.getForegroundColor();
52 graphics.setPaint(color);
53 graphics.fill(anchor);
54 break;
55 case Fill.FILL_PICTURE:
56 PictureData data = f.getPictureData();
57 if (data instanceof Bitmap) {
58 BufferedImage img = null;
59 try {
60 img = ImageIO.read(new ByteArrayInputStream(data.getData()));
61 } catch (Exception e) {
62 logger.log(POILogger.WARN, "ImageIO failed to create image. image.type: " + data.getType());
63 return;
65 Image scaledImg = img.getScaledInstance(anchor.width, anchor.height, Image.SCALE_SMOOTH);
66 graphics.drawImage(scaledImg, anchor.x, anchor.y, null);
69 break;
70 default:
71 logger.log(POILogger.WARN, "unsuported fill type: " + f.getFillType());
72 break;