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.

PDFDocumentGraphics2DConfigurator.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.svg;
  19. import java.util.List;
  20. import org.apache.avalon.framework.configuration.Configuration;
  21. import org.apache.avalon.framework.configuration.ConfigurationException;
  22. import org.apache.fop.apps.FOPException;
  23. import org.apache.fop.fonts.CustomFontCollection;
  24. import org.apache.fop.fonts.FontCollection;
  25. import org.apache.fop.fonts.FontEventListener;
  26. import org.apache.fop.fonts.FontInfo;
  27. import org.apache.fop.fonts.FontInfoConfigurator;
  28. import org.apache.fop.fonts.FontManager;
  29. import org.apache.fop.fonts.FontManagerConfigurator;
  30. import org.apache.fop.fonts.FontResolver;
  31. import org.apache.fop.fonts.base14.Base14FontCollection;
  32. import org.apache.fop.pdf.PDFDocument;
  33. import org.apache.fop.render.pdf.PDFRendererConfigurator;
  34. /**
  35. * Configurator class for PDFDocumentGraphics2D.
  36. */
  37. public class PDFDocumentGraphics2DConfigurator {
  38. /**
  39. * Configures a PDFDocumentGraphics2D instance using an Avalon Configuration object.
  40. * @param graphics the PDFDocumentGraphics2D instance
  41. * @param cfg the configuration
  42. * @param useComplexScriptFeatures true if complex script features enabled
  43. * @throws ConfigurationException if an error occurs while configuring the object
  44. */
  45. public void configure(PDFDocumentGraphics2D graphics, Configuration cfg,
  46. boolean useComplexScriptFeatures )
  47. throws ConfigurationException {
  48. PDFDocument pdfDoc = graphics.getPDFDocument();
  49. //Filter map
  50. pdfDoc.setFilterMap(
  51. PDFRendererConfigurator.buildFilterMapFromConfiguration(cfg));
  52. //Fonts
  53. try {
  54. FontInfo fontInfo = createFontInfo(cfg, useComplexScriptFeatures);
  55. graphics.setFontInfo(fontInfo);
  56. } catch (FOPException e) {
  57. throw new ConfigurationException("Error while setting up fonts", e);
  58. }
  59. }
  60. /**
  61. * Creates the {@link FontInfo} instance for the given configuration.
  62. * @param cfg the configuration
  63. * @param useComplexScriptFeatures true if complex script features enabled
  64. * @return the font collection
  65. * @throws FOPException if an error occurs while setting up the fonts
  66. */
  67. public static FontInfo createFontInfo(Configuration cfg, boolean useComplexScriptFeatures)
  68. throws FOPException {
  69. FontInfo fontInfo = new FontInfo();
  70. final boolean strict = false;
  71. FontResolver fontResolver = FontManager.createMinimalFontResolver(useComplexScriptFeatures);
  72. //TODO The following could be optimized by retaining the FontManager somewhere
  73. FontManager fontManager = new FontManager();
  74. if (cfg != null) {
  75. FontManagerConfigurator fmConfigurator = new FontManagerConfigurator(cfg);
  76. fmConfigurator.configure(fontManager, strict);
  77. }
  78. List fontCollections = new java.util.ArrayList();
  79. fontCollections.add(new Base14FontCollection(fontManager.isBase14KerningEnabled()));
  80. if (cfg != null) {
  81. //TODO Wire in the FontEventListener
  82. FontEventListener listener = null; //new FontEventAdapter(eventBroadcaster);
  83. FontInfoConfigurator fontInfoConfigurator
  84. = new FontInfoConfigurator(cfg, fontManager, fontResolver, listener, strict);
  85. List/*<EmbedFontInfo>*/ fontInfoList = new java.util.ArrayList/*<EmbedFontInfo>*/();
  86. fontInfoConfigurator.configure(fontInfoList);
  87. fontCollections.add(new CustomFontCollection(fontResolver, fontInfoList,
  88. fontResolver.isComplexScriptFeaturesEnabled()));
  89. }
  90. fontManager.setup(fontInfo,
  91. (FontCollection[])fontCollections.toArray(
  92. new FontCollection[fontCollections.size()]));
  93. return fontInfo;
  94. }
  95. }