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.

TxtRendererConfig.java 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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.txt;
  19. import java.util.EnumMap;
  20. import org.apache.fop.apps.FOPException;
  21. import org.apache.fop.apps.FOUserAgent;
  22. import org.apache.fop.apps.MimeConstants;
  23. import org.apache.fop.configuration.Configuration;
  24. import org.apache.fop.fonts.DefaultFontConfig;
  25. import org.apache.fop.fonts.DefaultFontConfig.DefaultFontConfigParser;
  26. import org.apache.fop.fonts.FontEventAdapter;
  27. import org.apache.fop.render.RendererConfig;
  28. import org.apache.fop.render.RendererConfigOption;
  29. /**
  30. * The Text renderer configuration data object.
  31. */
  32. public final class TxtRendererConfig implements RendererConfig {
  33. public enum TxtRendererOption implements RendererConfigOption {
  34. ENCODING("encoding", "UTF-8");
  35. private final String name;
  36. private final Object defaultValue;
  37. private TxtRendererOption(String name, Object defaultValue) {
  38. this.name = name;
  39. this.defaultValue = defaultValue;
  40. }
  41. public String getName() {
  42. return name;
  43. }
  44. public Object getDefaultValue() {
  45. return defaultValue;
  46. }
  47. }
  48. private final EnumMap<TxtRendererOption, Object> params
  49. = new EnumMap<TxtRendererOption, Object>(TxtRendererOption.class);
  50. private final DefaultFontConfig fontConfig;
  51. private TxtRendererConfig(DefaultFontConfig fontConfig) {
  52. this.fontConfig = fontConfig;
  53. }
  54. public DefaultFontConfig getFontInfoConfig() {
  55. return fontConfig;
  56. }
  57. public String getEncoding() {
  58. return (String) params.get(TxtRendererOption.ENCODING);
  59. }
  60. /**
  61. * The Text renderer configuration data parser.
  62. */
  63. public static final class TxtRendererConfigParser implements RendererConfigParser {
  64. /** {@inheritDoc} */
  65. public TxtRendererConfig build(FOUserAgent userAgent, Configuration cfg) throws FOPException {
  66. TxtRendererConfig config = new TxtRendererConfig(new DefaultFontConfigParser().parse(cfg,
  67. userAgent.validateStrictly(), new FontEventAdapter(userAgent.getEventBroadcaster())));
  68. if (cfg != null) {
  69. TxtRendererOption option = TxtRendererOption.ENCODING;
  70. String value = cfg.getChild(option.getName(), true).getValue(null);
  71. config.params.put(option, value != null ? value : option.getDefaultValue());
  72. }
  73. return config;
  74. }
  75. /** {@inheritDoc} */
  76. public String getMimeType() {
  77. return MimeConstants.MIME_PLAIN_TEXT;
  78. }
  79. }
  80. }