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.

DrawFontManager.java 3.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * ====================================================================
  3. * Licensed to the Apache Software Foundation (ASF) under one or more
  4. * contributor license agreements. See the NOTICE file distributed with
  5. * this work for additional information regarding copyright ownership.
  6. * The ASF licenses this file to You under the Apache License, Version 2.0
  7. * (the "License"); you may not use this file except in compliance with
  8. * the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. * ====================================================================
  18. */
  19. package org.apache.poi.sl.draw;
  20. import java.awt.Font;
  21. import java.awt.Graphics2D;
  22. import org.apache.poi.common.usermodel.fonts.FontInfo;
  23. import org.apache.poi.util.StringUtil;
  24. /**
  25. * Manages fonts when rendering slides.
  26. *
  27. * Use this class to handle unknown / missing fonts or to substitute fonts
  28. */
  29. public interface DrawFontManager {
  30. /**
  31. * select a font to be used to paint text
  32. *
  33. * @param graphics the graphics context to request additional rendering hints
  34. * @param fontInfo the font info object corresponding to the text run font
  35. *
  36. * @return the font to be used to paint text
  37. */
  38. FontInfo getMappedFont(Graphics2D graphics, FontInfo fontInfo);
  39. /**
  40. * In case the original font doesn't contain a glyph, use the
  41. * returned fallback font as an alternative
  42. *
  43. * @param graphics the graphics context to request additional rendering hints
  44. * @param fontInfo the font info object corresponding to the text run font
  45. *
  46. * @return the font to be used as a fallback for the original typeface
  47. */
  48. FontInfo getFallbackFont(Graphics2D graphics, FontInfo fontInfo);
  49. /**
  50. * Map text charset depending on font family.
  51. * <p>
  52. * Currently this only maps for wingdings and symbol font (into unicode private use area)
  53. * <p>
  54. * Depending if the requested font is installed in the system, tbe mapped string varies:<br>
  55. * If the font is registered into the graphics environment the characters are mapped to the
  56. * private use area. If the font is missing (and hence a AWT logical font is used), the
  57. * characters are mapped to the corresponding unicode characters
  58. *
  59. * @param graphics the graphics context to request additional rendering hints
  60. * @param fontInfo the font info object corresponding to the text run font
  61. * @param text the raw text
  62. *
  63. * @return String with mapped codepoints
  64. *
  65. * @see <a href="http://stackoverflow.com/questions/8692095">Drawing exotic fonts in a java applet</a>
  66. * @see StringUtil#mapMsCodepointString(String)
  67. */
  68. String mapFontCharset(Graphics2D graphics, FontInfo fontInfo, String text);
  69. /**
  70. * Create an AWT font object with the given attributes
  71. *
  72. * @param graphics the graphics context to request additional rendering hints
  73. * @param fontInfo the font info object corresponding to the text run font
  74. * @param size the font size in points
  75. * @param bold {@code true} if the font is bold
  76. * @param italic {@code true} if the font is italic
  77. *
  78. * @return the AWT font object
  79. */
  80. Font createAWTFont(Graphics2D graphics, FontInfo fontInfo, double size, boolean bold, boolean italic);
  81. }