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.

FontManagerConfigurator.java 3.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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.fonts;
  19. import java.net.MalformedURLException;
  20. import org.apache.avalon.framework.configuration.Configuration;
  21. import org.apache.avalon.framework.configuration.ConfigurationException;
  22. import org.apache.commons.logging.Log;
  23. import org.apache.commons.logging.LogFactory;
  24. import org.apache.fop.apps.FOPException;
  25. import org.apache.fop.fonts.substitute.FontSubstitutions;
  26. import org.apache.fop.fonts.substitute.FontSubstitutionsConfigurator;
  27. import org.apache.fop.util.LogUtil;
  28. /**
  29. * Configurator of the FontManager
  30. */
  31. public class FontManagerConfigurator {
  32. /** logger instance */
  33. private static Log log = LogFactory.getLog(FontManagerConfigurator.class);
  34. private Configuration cfg;
  35. /**
  36. * Main constructor
  37. * @param cfg the font manager configuration object
  38. */
  39. public FontManagerConfigurator(Configuration cfg) {
  40. this.cfg = cfg;
  41. }
  42. /**
  43. * Initializes font settings from the user configuration
  44. * @param fontManager a font manager
  45. * @throws FOPException fop exception
  46. */
  47. public void configure(FontManager fontManager) throws FOPException {
  48. // caching (fonts)
  49. if (cfg.getChild("use-cache", false) != null) {
  50. try {
  51. fontManager.setUseCache(
  52. cfg.getChild("use-cache").getValueAsBoolean());
  53. } catch (ConfigurationException mfue) {
  54. LogUtil.handleException(log, mfue, true);
  55. }
  56. }
  57. if (cfg.getChild("font-base", false) != null) {
  58. try {
  59. fontManager.setFontBaseURL(
  60. cfg.getChild("font-base").getValue(null));
  61. } catch (MalformedURLException mfue) {
  62. LogUtil.handleException(log, mfue, true);
  63. }
  64. }
  65. // global font configuration
  66. Configuration fontsCfg = cfg.getChild("fonts", false);
  67. if (fontsCfg != null) {
  68. // font substitution
  69. Configuration substitutionsCfg = fontsCfg.getChild("substitutions", false);
  70. if (substitutionsCfg != null) {
  71. FontSubstitutionsConfigurator fontSubstitutionsConfigurator
  72. = new FontSubstitutionsConfigurator(substitutionsCfg);
  73. FontSubstitutions substitutions = new FontSubstitutions();
  74. fontSubstitutionsConfigurator.configure(substitutions);
  75. fontManager.setFontSubstitutions(substitutions);
  76. }
  77. }
  78. }
  79. }