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.

FontSubstitutions.java 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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.substitute;
  19. import java.util.Iterator;
  20. import java.util.List;
  21. import org.apache.commons.logging.Log;
  22. import org.apache.commons.logging.LogFactory;
  23. import org.apache.fop.fonts.FontInfo;
  24. import org.apache.fop.fonts.FontTriplet;
  25. /**
  26. * Font substitutions
  27. */
  28. public class FontSubstitutions extends java.util.ArrayList/*<Substitutions>*/ {
  29. private static final long serialVersionUID = -9173104935431899722L;
  30. /** logging instance */
  31. protected static final Log log = LogFactory.getLog(FontSubstitutions.class);
  32. /**
  33. * Adjusts a given fontInfo using this font substitution catalog
  34. * @param fontInfo font info
  35. */
  36. public void adjustFontInfo(FontInfo fontInfo) {
  37. for (Iterator/*<FontSubstitution>*/ subsIt = super.iterator(); subsIt.hasNext();) {
  38. FontSubstitution substitution = (FontSubstitution)subsIt.next();
  39. // find the best matching font triplet
  40. FontQualifier toQualifier = substitution.getToQualifier();
  41. FontTriplet fontTriplet = toQualifier.bestMatch(fontInfo);
  42. if (fontTriplet == null) {
  43. log.error("Unable to match font substitution for destination qualifier "
  44. + toQualifier);
  45. continue;
  46. }
  47. String internalFontKey = fontInfo.getInternalFontKey(fontTriplet);
  48. FontQualifier fromQualifier = substitution.getFromQualifier();
  49. List/*<FontTriplet>*/ tripletList = fromQualifier.getTriplets();
  50. for (Iterator tripletit = tripletList.iterator(); tripletit.hasNext();) {
  51. FontTriplet triplet = (FontTriplet) tripletit.next();
  52. fontInfo.addFontProperties(internalFontKey, triplet);
  53. }
  54. }
  55. }
  56. }