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.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. * @throws ConfigurationException if an error occurs while configuring the object
  43. */
  44. public void configure(PDFDocumentGraphics2D graphics, Configuration cfg)
  45. throws ConfigurationException {
  46. PDFDocument pdfDoc = graphics.getPDFDocument();
  47. //Filter map
  48. pdfDoc.setFilterMap(
  49. PDFRendererConfigurator.buildFilterMapFromConfiguration(cfg));
  50. //Fonts
  51. try {
  52. FontInfo fontInfo = createFontInfo(cfg);
  53. graphics.setFontInfo(fontInfo);
  54. } catch (FOPException e) {
  55. throw new ConfigurationException("Error while setting up fonts", e);
  56. }
  57. }
  58. /**
  59. * Creates the {@link FontInfo} instance for the given configuration.
  60. * @param cfg the configuration
  61. * @return the font collection
  62. * @throws FOPException if an error occurs while setting up the fonts
  63. */
  64. public static FontInfo createFontInfo(Configuration cfg) throws FOPException {
  65. FontInfo fontInfo = new FontInfo();
  66. final boolean strict = false;
  67. FontResolver fontResolver = FontManager.createMinimalFontResolver();
  68. //TODO The following could be optimized by retaining the FontManager somewhere
  69. FontManager fontManager = new FontManager();
  70. if (cfg != null) {
  71. FontManagerConfigurator fmConfigurator = new FontManagerConfigurator(cfg);
  72. fmConfigurator.configure(fontManager, strict);
  73. }
  74. List fontCollections = new java.util.ArrayList();
  75. fontCollections.add(new Base14FontCollection(fontManager.isBase14KerningEnabled()));
  76. if (cfg != null) {
  77. //TODO Wire in the FontEventListener
  78. FontEventListener listener = null; //new FontEventAdapter(eventBroadcaster);
  79. FontInfoConfigurator fontInfoConfigurator
  80. = new FontInfoConfigurator(cfg, fontManager, fontResolver, listener, strict);
  81. List/*<EmbedFontInfo>*/ fontInfoList = new java.util.ArrayList/*<EmbedFontInfo>*/();
  82. fontInfoConfigurator.configure(fontInfoList);
  83. fontCollections.add(new CustomFontCollection(fontResolver, fontInfoList));
  84. }
  85. fontManager.setup(fontInfo,
  86. (FontCollection[])fontCollections.toArray(
  87. new FontCollection[fontCollections.size()]));
  88. return fontInfo;
  89. }
  90. }