You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ImagePainter.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.hslf.blip;
  16. import org.apache.poi.hslf.usermodel.HSLFPictureData;
  17. import org.apache.poi.hslf.usermodel.HSLFPictureShape;
  18. import java.awt.*;
  19. /**
  20. * A common interface for objects that can render ppt picture data.
  21. * <p>
  22. * Subclasses can redefine it and use third-party libraries for actual rendering,
  23. * for example, Bitmaps can be rendered using javax.imageio.* , WMF can be rendered using Apache Batik,
  24. * PICT can be rendered using Apple QuickTime API for Java, etc.
  25. * </p>
  26. *
  27. * A typical usage is as follows:
  28. * <code>
  29. * public WMFPaiter implements ImagePainter{
  30. * public void paint(Graphics2D graphics, PictureData pict, Picture parent){
  31. * DataInputStream is = new DataInputStream(new ByteArrayInputStream(pict.getData()));
  32. * org.apache.batik.transcoder.wmf.tosvg.WMFRecordStore wmfStore =
  33. * new org.apache.batik.transcoder.wmf.tosvg.WMFRecordStore();
  34. * try {
  35. * wmfStore.read(is);
  36. * } catch (IOException e){
  37. * return;
  38. * }
  39. *
  40. * Rectangle anchor = parent.getAnchor();
  41. * float scale = (float)anchor.width/wmfStore.getWidthPixels();
  42. *
  43. * org.apache.batik.transcoder.wmf.tosvg.WMFPainter painter =
  44. * new org.apache.batik.transcoder.wmf.tosvg.WMFPainter(wmfStore, 0, 0, scale);
  45. * graphics.translate(anchor.x, anchor.y);
  46. * painter.paint(graphics);
  47. * }
  48. * }
  49. * PictureData.setImagePainter(Picture.WMF, new WMFPaiter());
  50. * ...
  51. * </code>
  52. * Subsequent calls of Slide.draw(Graphics gr) will use WMFPaiter for WMF images.
  53. *
  54. * @author Yegor Kozlov.
  55. */
  56. public interface ImagePainter {
  57. /**
  58. * Paints the specified picture data
  59. *
  60. * @param graphics the graphics to paintb into
  61. * @param pict the data to paint
  62. * @param parent the shapes that owns the picture data
  63. */
  64. public void paint(Graphics2D graphics, HSLFPictureData pict, HSLFPictureShape parent);
  65. }