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 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. default: return "UNKNOWN_ID "+intKey();
  44. }
  45. }
  46. }
  47. /**
  48. * {@link DrawFactory} which will be used to draw objects into this graphics context
  49. */
  50. DrawableHint DRAW_FACTORY = new DrawableHint(1);
  51. /**
  52. * Key will be internally used to store affine transformation temporarily within group shapes
  53. */
  54. @Internal
  55. DrawableHint GROUP_TRANSFORM = new DrawableHint(2);
  56. /**
  57. * Use a custom image renderer of an instance of {@link ImageRenderer}
  58. */
  59. DrawableHint IMAGE_RENDERER = new DrawableHint(3);
  60. /**
  61. * how to render text:
  62. *
  63. * {@link #TEXT_AS_CHARACTERS} (default) means to draw via
  64. * {@link java.awt.Graphics2D#drawString(java.text.AttributedCharacterIterator, float, float)}.
  65. * This mode draws text as characters. Use it if the target graphics writes the actual
  66. * character codes instead of glyph outlines (PDFGraphics2D, SVGGraphics2D, etc.)
  67. *
  68. * {@link #TEXT_AS_SHAPES} means to render via
  69. * {@link java.awt.font.TextLayout#draw(java.awt.Graphics2D, float, float)}.
  70. * This mode draws glyphs as shapes and provides some advanced capabilities such as
  71. * justification and font substitution. Use it if the target graphics is an image.
  72. *
  73. */
  74. DrawableHint TEXT_RENDERING_MODE = new DrawableHint(4);
  75. /**
  76. * PathGradientPaint needs the shape to be set.
  77. * It will be achieved through setting it in the rendering hints
  78. */
  79. DrawableHint GRADIENT_SHAPE = new DrawableHint(5);
  80. /**
  81. * Internal key for caching the preset geometries
  82. */
  83. DrawableHint PRESET_GEOMETRY_CACHE = new DrawableHint(6);
  84. /**
  85. * draw text via {@link java.awt.Graphics2D#drawString(java.text.AttributedCharacterIterator, float, float)}
  86. */
  87. int TEXT_AS_CHARACTERS = 1;
  88. /**
  89. * draw text via {@link java.awt.font.TextLayout#draw(java.awt.Graphics2D, float, float)}
  90. */
  91. int TEXT_AS_SHAPES = 2;
  92. /**
  93. * Use this object to resolve unknown / missing fonts when rendering slides.
  94. * The font handler must be of type {@link DrawFontManager}.<p>
  95. *
  96. * In case a {@code FONT_HANDLER} is register, {@code FONT_FALLBACK} and {@code FONT_MAP} are ignored
  97. */
  98. DrawableHint FONT_HANDLER = new DrawableHint(7);
  99. /**
  100. * Key for a font fallback map of type {@code Map<String,String>} which maps
  101. * the original font family (key) to the fallback font family (value).
  102. * In case there is also a {@code FONT_MAP} registered, the original font
  103. * is first mapped via the font_map and then the fallback font is determined
  104. */
  105. DrawableHint FONT_FALLBACK = new DrawableHint(8);
  106. /**
  107. * Key for a font map of type {@code Map<String,String>} which maps
  108. * the original font family (key) to the mapped font family (value)
  109. */
  110. DrawableHint FONT_MAP = new DrawableHint(9);
  111. DrawableHint GSAVE = new DrawableHint(10);
  112. DrawableHint GRESTORE = new DrawableHint(11);
  113. /**
  114. * The Common SL Draw API works sometimes cascading, but there are places
  115. * where the current slide context need to be evaluated, e.g. when slide numbers
  116. * are printed. In this situation we need to have a way to access the current slide
  117. */
  118. DrawableHint CURRENT_SLIDE = new DrawableHint(12);
  119. /**
  120. * Stores a reference (WEAK_REFERENCE) to the buffered image, if the rendering is
  121. * based on a buffered image
  122. */
  123. DrawableHint BUFFERED_IMAGE = new DrawableHint(13);
  124. /**
  125. * Sets the default charset to render text elements.
  126. * Opposed to other windows libraries in POI this simply defaults to Windows-1252.
  127. * The rendering value is of type {@link java.nio.charset.Charset}
  128. */
  129. DrawableHint DEFAULT_CHARSET = new DrawableHint(14);
  130. /**
  131. * Apply 2-D transforms before drawing this shape. This includes rotation and flipping.
  132. *
  133. * @param graphics the graphics whos transform matrix will be modified
  134. */
  135. void applyTransform(Graphics2D graphics);
  136. /**
  137. * Draw this shape into the supplied canvas
  138. *
  139. * @param graphics the graphics to draw into
  140. */
  141. void draw(Graphics2D graphics);
  142. /**
  143. * draw any content within this shape (image, text, etc.).
  144. *
  145. * @param graphics the graphics to draw into
  146. */
  147. void drawContent(Graphics2D graphics);
  148. }