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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. default: return "UNKNOWN_ID "+intKey();
  41. }
  42. }
  43. }
  44. /**
  45. * {@link DrawFactory} which will be used to draw objects into this graphics context
  46. */
  47. DrawableHint DRAW_FACTORY = new DrawableHint(1);
  48. /**
  49. * Key will be internally used to store affine transformation temporarily within group shapes
  50. */
  51. @Internal
  52. DrawableHint GROUP_TRANSFORM = new DrawableHint(2);
  53. /**
  54. * Use a custom image renderer of an instance of {@link ImageRenderer}
  55. */
  56. DrawableHint IMAGE_RENDERER = new DrawableHint(3);
  57. /**
  58. * how to render text:
  59. *
  60. * {@link #TEXT_AS_CHARACTERS} (default) means to draw via
  61. * {@link java.awt.Graphics2D#drawString(java.text.AttributedCharacterIterator, float, float)}.
  62. * This mode draws text as characters. Use it if the target graphics writes the actual
  63. * character codes instead of glyph outlines (PDFGraphics2D, SVGGraphics2D, etc.)
  64. *
  65. * {@link #TEXT_AS_SHAPES} means to render via
  66. * {@link java.awt.font.TextLayout#draw(java.awt.Graphics2D, float, float)}.
  67. * This mode draws glyphs as shapes and provides some advanced capabilities such as
  68. * justification and font substitution. Use it if the target graphics is an image.
  69. *
  70. */
  71. DrawableHint TEXT_RENDERING_MODE = new DrawableHint(4);
  72. /**
  73. * PathGradientPaint needs the shape to be set.
  74. * It will be achieved through setting it in the rendering hints
  75. */
  76. DrawableHint GRADIENT_SHAPE = new DrawableHint(5);
  77. /**
  78. * Internal key for caching the preset geometries
  79. */
  80. DrawableHint PRESET_GEOMETRY_CACHE = new DrawableHint(6);
  81. /**
  82. * draw text via {@link java.awt.Graphics2D#drawString(java.text.AttributedCharacterIterator, float, float)}
  83. */
  84. int TEXT_AS_CHARACTERS = 1;
  85. /**
  86. * draw text via {@link java.awt.font.TextLayout#draw(java.awt.Graphics2D, float, float)}
  87. */
  88. int TEXT_AS_SHAPES = 2;
  89. /**
  90. * Use this object to resolve unknown / missing fonts when rendering slides
  91. */
  92. DrawableHint FONT_HANDLER = new DrawableHint(7);
  93. DrawableHint FONT_FALLBACK = new DrawableHint(8);
  94. DrawableHint FONT_MAP = new DrawableHint(9);
  95. DrawableHint GSAVE = new DrawableHint(10);
  96. DrawableHint GRESTORE = new DrawableHint(11);
  97. /**
  98. * Apply 2-D transforms before drawing this shape. This includes rotation and flipping.
  99. *
  100. * @param graphics the graphics whos transform matrix will be modified
  101. */
  102. void applyTransform(Graphics2D graphics);
  103. /**
  104. * Draw this shape into the supplied canvas
  105. *
  106. * @param graphics the graphics to draw into
  107. */
  108. void draw(Graphics2D graphics);
  109. /**
  110. * draw any content within this shape (image, text, etc.).
  111. *
  112. * @param graphics the graphics to draw into
  113. */
  114. void drawContent(Graphics2D graphics);
  115. }