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.

BitmapRendererConfigurator.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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.bitmap;
  19. import java.util.ArrayList;
  20. import java.util.List;
  21. import org.apache.fop.apps.FOPException;
  22. import org.apache.fop.apps.FOUserAgent;
  23. import org.apache.fop.apps.io.URIResolverWrapper;
  24. import org.apache.fop.fonts.EmbedFontInfo;
  25. import org.apache.fop.fonts.FontCollection;
  26. import org.apache.fop.render.RendererConfig.RendererConfigParser;
  27. import org.apache.fop.render.bitmap.BitmapRendererConfig.BitmapRendererConfigParser;
  28. import org.apache.fop.render.intermediate.IFDocumentHandler;
  29. import org.apache.fop.render.java2d.Base14FontCollection;
  30. import org.apache.fop.render.java2d.ConfiguredFontCollection;
  31. import org.apache.fop.render.java2d.InstalledFontCollection;
  32. import org.apache.fop.render.java2d.Java2DFontMetrics;
  33. import org.apache.fop.render.java2d.Java2DRendererConfigurator;
  34. /**
  35. * Configurator for bitmap output.
  36. */
  37. public class BitmapRendererConfigurator extends Java2DRendererConfigurator {
  38. /**
  39. * Default constructor
  40. * @param userAgent user agent
  41. */
  42. public BitmapRendererConfigurator(FOUserAgent userAgent, RendererConfigParser rendererConfigParser) {
  43. super(userAgent, rendererConfigParser);
  44. }
  45. // ---=== IFDocumentHandler configuration ===---
  46. /** {@inheritDoc} */
  47. public void configure(IFDocumentHandler documentHandler) throws FOPException {
  48. AbstractBitmapDocumentHandler bitmapHandler = (AbstractBitmapDocumentHandler) documentHandler;
  49. BitmapRenderingSettings settings = bitmapHandler.getSettings();
  50. // TODO: magic strings!
  51. configure(documentHandler, settings, new BitmapRendererConfigParser("image/bitmap"));
  52. }
  53. void configure(IFDocumentHandler documentHandler, BitmapRenderingSettings settings,
  54. BitmapRendererConfigParser parser) throws FOPException {
  55. BitmapRendererConfig config = (BitmapRendererConfig) userAgent.getRendererConfig(
  56. documentHandler.getMimeType(), parser);
  57. configure(config, settings);
  58. }
  59. private void configure(BitmapRendererConfig config, BitmapRenderingSettings settings)
  60. throws FOPException {
  61. if (config.hasTransparentBackround()) {
  62. settings.setPageBackgroundColor(null);
  63. } else if (config.getBackgroundColor() != null) {
  64. settings.setPageBackgroundColor(config.getBackgroundColor());
  65. }
  66. if (config.hasAntiAliasing() != null) {
  67. settings.setAntiAliasing(config.hasAntiAliasing());
  68. }
  69. if (config.isRenderHighQuality() != null) {
  70. settings.setQualityRendering(config.isRenderHighQuality());
  71. }
  72. if (config.getColorMode() != null) {
  73. settings.setBufferedImageType(config.getColorMode());
  74. }
  75. }
  76. @Override
  77. protected FontCollection createCollectionFromFontList(URIResolverWrapper uriResolverWrapper,
  78. List<EmbedFontInfo> fontList) {
  79. return new ConfiguredFontCollection(uriResolverWrapper, fontList, userAgent.isComplexScriptFeaturesEnabled());
  80. }
  81. @Override
  82. protected List<FontCollection> getDefaultFontCollection() {
  83. final Java2DFontMetrics java2DFontMetrics = new Java2DFontMetrics();
  84. final List<FontCollection> fontCollection = new ArrayList<FontCollection>();
  85. fontCollection.add(new Base14FontCollection(java2DFontMetrics));
  86. fontCollection.add(new InstalledFontCollection(java2DFontMetrics));
  87. return fontCollection;
  88. }
  89. }