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.

Drawable.java 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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.sl.draw;
  16. import java.awt.Graphics2D;
  17. import java.awt.RenderingHints;
  18. import org.apache.poi.util.Internal;
  19. public interface Drawable {
  20. class DrawableHint extends RenderingHints.Key {
  21. protected DrawableHint(int id) {
  22. super(id);
  23. }
  24. public boolean isCompatibleValue(Object val) {
  25. return true;
  26. }
  27. public String toString() {
  28. switch (intKey()) {
  29. case 1: return "DRAW_FACTORY";
  30. case 2: return "GROUP_TRANSFORM";
  31. case 3: return "IMAGE_RENDERER";
  32. case 4: return "TEXT_RENDERING_MODE";
  33. case 5: return "GRADIENT_SHAPE";
  34. case 6: return "PRESET_GEOMETRY_CACHE";
  35. case 7: return "FONT_HANDLER";
  36. case 8: return "FONT_FALLBACK";
  37. case 9: return "FONT_MAP";
  38. case 10: return "GSAVE";
  39. case 11: return "GRESTORE";
  40. case 12: return "CURRENT_SLIDE";
  41. case 13: return "BUFFERED_IMAGE";
  42. case 14: return "DEFAULT_CHARSET";
  43. case 15: return "EMF_FORCE_HEADER_BOUNDS";
  44. case 16: return "CACHE_IMAGE_SOURCE";
  45. default: return "UNKNOWN_ID "+intKey();
  46. }
  47. }
  48. }
  49. /**
  50. * {@link DrawFactory} which will be used to draw objects into this graphics context
  51. */
  52. DrawableHint DRAW_FACTORY = new DrawableHint(1);
  53. /**
  54. * Key will be internally used to store affine transformation temporarily within group shapes
  55. */
  56. @Internal
  57. DrawableHint GROUP_TRANSFORM = new DrawableHint(2);
  58. /**
  59. * Use a custom image renderer of an instance of {@link ImageRenderer}
  60. */
  61. DrawableHint IMAGE_RENDERER = new DrawableHint(3);
  62. /**
  63. * how to render text:
  64. *
  65. * {@link #TEXT_AS_CHARACTERS} (default) means to draw via
  66. * {@link java.awt.Graphics2D#drawString(java.text.AttributedCharacterIterator, float, float)}.
  67. * This mode draws text as characters. Use it if the target graphics writes the actual
  68. * character codes instead of glyph outlines (PDFGraphics2D, SVGGraphics2D, etc.)
  69. *
  70. * {@link #TEXT_AS_SHAPES} means to render via
  71. * {@link java.awt.font.TextLayout#draw(java.awt.Graphics2D, float, float)}.
  72. * This mode draws glyphs as shapes and provides some advanced capabilities such as
  73. * justification and font substitution. Use it if the target graphics is an image.
  74. *
  75. */
  76. DrawableHint TEXT_RENDERING_MODE = new DrawableHint(4);
  77. /**
  78. * PathGradientPaint needs the shape to be set.
  79. * It will be achieved through setting it in the rendering hints
  80. */
  81. DrawableHint GRADIENT_SHAPE = new DrawableHint(5);
  82. /**
  83. * Internal key for caching the preset geometries
  84. */
  85. DrawableHint PRESET_GEOMETRY_CACHE = new DrawableHint(6);
  86. /**
  87. * draw text via {@link java.awt.Graphics2D#drawString(java.text.AttributedCharacterIterator, float, float)}
  88. */
  89. int TEXT_AS_CHARACTERS = 1;
  90. /**
  91. * draw text via {@link java.awt.font.TextLayout#draw(java.awt.Graphics2D, float, float)}
  92. */
  93. int TEXT_AS_SHAPES = 2;
  94. /**
  95. * Use this object to resolve unknown / missing fonts when rendering slides.
  96. * The font handler must be of type {@link DrawFontManager}.<p>
  97. *
  98. * In case a {@code FONT_HANDLER} is register, {@code FONT_FALLBACK} and {@code FONT_MAP} are ignored
  99. */
  100. DrawableHint FONT_HANDLER = new DrawableHint(7);
  101. /**
  102. * Key for a font fallback map of type {@code Map<String,String>} which maps
  103. * the original font family (key) to the fallback font family (value).
  104. * In case there is also a {@code FONT_MAP} registered, the original font
  105. * is first mapped via the font_map and then the fallback font is determined
  106. */
  107. DrawableHint FONT_FALLBACK = new DrawableHint(8);
  108. /**
  109. * Key for a font map of type {@code Map<String,String>} which maps
  110. * the original font family (key) to the mapped font family (value)
  111. */
  112. DrawableHint FONT_MAP = new DrawableHint(9);
  113. DrawableHint GSAVE = new DrawableHint(10);
  114. DrawableHint GRESTORE = new DrawableHint(11);
  115. /**
  116. * The Common SL Draw API works sometimes cascading, but there are places
  117. * where the current slide context need to be evaluated, e.g. when slide numbers
  118. * are printed. In this situation we need to have a way to access the current slide
  119. */
  120. DrawableHint CURRENT_SLIDE = new DrawableHint(12);
  121. /**
  122. * Stores a reference (WEAK_REFERENCE) to the buffered image, if the rendering is
  123. * based on a buffered image
  124. */
  125. DrawableHint BUFFERED_IMAGE = new DrawableHint(13);
  126. /**
  127. * Sets the default charset to render text elements.
  128. * Opposed to other windows libraries in POI this simply defaults to Windows-1252.
  129. * The rendering value is of type {@link java.nio.charset.Charset}
  130. */
  131. DrawableHint DEFAULT_CHARSET = new DrawableHint(14);
  132. /**
  133. * A boolean value to force the usage of the bounding box, which is specified in the EMF header.
  134. * Defaults to {@code FALSE} - in this case the records are scanned for window and
  135. * viewport records to determine the initial bounding box by using the following
  136. * condition: {@code isValid(viewport) ? viewport : isValid(window) ? window : headerBounds }
  137. * <p>
  138. * This is a workaround switch, which might be removed in future releases, when the bounding box
  139. * determination for the special cases is fixed.
  140. * In most cases it's recommended to leave the default value.
  141. */
  142. DrawableHint EMF_FORCE_HEADER_BOUNDS = new DrawableHint(15);
  143. /**
  144. * A boolean value to instruct the bitmap image renderer to keep the original image bytes.
  145. * Defaults to {@code false} if unset.
  146. */
  147. DrawableHint CACHE_IMAGE_SOURCE = new DrawableHint(16);
  148. /**
  149. * Apply 2-D transforms before drawing this shape. This includes rotation and flipping.
  150. *
  151. * @param graphics the graphics whose transform matrix will be modified
  152. */
  153. void applyTransform(Graphics2D graphics);
  154. /**
  155. * Draw this shape into the supplied canvas
  156. *
  157. * @param graphics the graphics to draw into
  158. */
  159. void draw(Graphics2D graphics);
  160. /**
  161. * draw any content within this shape (image, text, etc.).
  162. *
  163. * @param graphics the graphics to draw into
  164. */
  165. void drawContent(Graphics2D graphics);
  166. }