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.

PCLRendererConfigurator.java 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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.render.pcl;
  19. import java.awt.Graphics2D;
  20. import java.util.List;
  21. import org.apache.avalon.framework.configuration.Configuration;
  22. import org.apache.fop.apps.FOPException;
  23. import org.apache.fop.apps.FOUserAgent;
  24. import org.apache.fop.fonts.FontCollection;
  25. import org.apache.fop.fonts.FontEventAdapter;
  26. import org.apache.fop.fonts.FontEventListener;
  27. import org.apache.fop.fonts.FontInfo;
  28. import org.apache.fop.fonts.FontManager;
  29. import org.apache.fop.fonts.FontResolver;
  30. import org.apache.fop.render.DefaultFontResolver;
  31. import org.apache.fop.render.PrintRendererConfigurator;
  32. import org.apache.fop.render.Renderer;
  33. import org.apache.fop.render.intermediate.IFDocumentHandler;
  34. import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
  35. import org.apache.fop.render.java2d.Base14FontCollection;
  36. import org.apache.fop.render.java2d.ConfiguredFontCollection;
  37. import org.apache.fop.render.java2d.InstalledFontCollection;
  38. import org.apache.fop.render.java2d.Java2DFontMetrics;
  39. /**
  40. * PCL Renderer configurator
  41. */
  42. public class PCLRendererConfigurator extends PrintRendererConfigurator
  43. implements IFDocumentHandlerConfigurator {
  44. /**
  45. * Default constructor
  46. * @param userAgent user agent
  47. */
  48. public PCLRendererConfigurator(FOUserAgent userAgent) {
  49. super(userAgent);
  50. }
  51. /**
  52. * Throws an UnsupportedOperationException.
  53. *
  54. * @param renderer not used
  55. */
  56. public void configure(Renderer renderer) {
  57. throw new UnsupportedOperationException();
  58. }
  59. private void configure(Configuration cfg, PCLRenderingUtil pclUtil) throws FOPException {
  60. String rendering = cfg.getChild("rendering").getValue(null);
  61. if (rendering != null) {
  62. try {
  63. pclUtil.setRenderingMode(PCLRenderingMode.valueOf(rendering));
  64. } catch (IllegalArgumentException e) {
  65. throw new FOPException(
  66. "Valid values for 'rendering' are 'quality', 'speed' and 'bitmap'."
  67. + " Value found: " + rendering);
  68. }
  69. }
  70. String textRendering = cfg.getChild("text-rendering").getValue(null);
  71. if ("bitmap".equalsIgnoreCase(textRendering)) {
  72. pclUtil.setAllTextAsBitmaps(true);
  73. } else if ("auto".equalsIgnoreCase(textRendering)) {
  74. pclUtil.setAllTextAsBitmaps(false);
  75. } else if (textRendering != null) {
  76. throw new FOPException(
  77. "Valid values for 'text-rendering' are 'auto' and 'bitmap'. Value found: "
  78. + textRendering);
  79. }
  80. pclUtil.setPJLDisabled(cfg.getChild("disable-pjl").getValueAsBoolean(false));
  81. }
  82. // ---=== IFDocumentHandler configuration ===---
  83. /** {@inheritDoc} */
  84. public void configure(IFDocumentHandler documentHandler) throws FOPException {
  85. Configuration cfg = super.getRendererConfig(documentHandler.getMimeType());
  86. if (cfg != null) {
  87. PCLDocumentHandler pclDocumentHandler = (PCLDocumentHandler)documentHandler;
  88. PCLRenderingUtil pclUtil = pclDocumentHandler.getPCLUtil();
  89. configure(cfg, pclUtil);
  90. }
  91. }
  92. /** {@inheritDoc} */
  93. public void setupFontInfo(IFDocumentHandler documentHandler, FontInfo fontInfo)
  94. throws FOPException {
  95. FontManager fontManager = userAgent.getFactory().getFontManager();
  96. final Java2DFontMetrics java2DFontMetrics = new Java2DFontMetrics();
  97. final List fontCollections = new java.util.ArrayList();
  98. fontCollections.add(new Base14FontCollection(java2DFontMetrics));
  99. fontCollections.add(new InstalledFontCollection(java2DFontMetrics));
  100. Configuration cfg = super.getRendererConfig(documentHandler.getMimeType());
  101. if (cfg != null) {
  102. FontResolver fontResolver = new DefaultFontResolver(userAgent);
  103. FontEventListener listener = new FontEventAdapter(
  104. userAgent.getEventBroadcaster());
  105. List fontList = buildFontList(cfg, fontResolver, listener);
  106. fontCollections.add(new ConfiguredFontCollection(fontResolver, fontList));
  107. }
  108. fontManager.setup(fontInfo,
  109. (FontCollection[])fontCollections.toArray(
  110. new FontCollection[fontCollections.size()]));
  111. documentHandler.setFontInfo(fontInfo);
  112. }
  113. }