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.

FontAdder.java 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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.URL;
  20. import java.util.Iterator;
  21. import java.util.List;
  22. import org.apache.fop.fonts.autodetect.FontInfoFinder;
  23. /**
  24. * Adds a list of fonts to a given font info list
  25. */
  26. public class FontAdder {
  27. private FontEventListener listener;
  28. private FontResolver resolver;
  29. private FontManager manager;
  30. /**
  31. * Main constructor
  32. * @param manager a font manager
  33. * @param resolver a font resolver
  34. * @param listener a font event handler
  35. */
  36. public FontAdder(FontManager manager, FontResolver resolver, FontEventListener listener) {
  37. this.manager = manager;
  38. this.resolver = resolver;
  39. this.listener = listener;
  40. }
  41. /**
  42. * Iterates over font url list adding to font info list
  43. * @param fontURLList font file list
  44. * @param fontInfoList a configured font info list
  45. */
  46. public void add(List/*<URL>*/ fontURLList, List/*<EmbedFontInfo>*/ fontInfoList) {
  47. FontCache cache = manager.getFontCache();
  48. FontInfoFinder finder = new FontInfoFinder();
  49. finder.setEventListener(listener);
  50. for (Iterator iter = fontURLList.iterator(); iter.hasNext();) {
  51. URL fontUrl = (URL)iter.next();
  52. EmbedFontInfo[] embedFontInfos = finder.find(fontUrl, resolver, cache);
  53. if (embedFontInfos == null) {
  54. continue;
  55. }
  56. for (int i = 0, c = embedFontInfos.length; i < c; i++) {
  57. EmbedFontInfo fontInfo = embedFontInfos[i];
  58. if (fontInfo != null) {
  59. fontInfoList.add(fontInfo);
  60. }
  61. }
  62. }
  63. }
  64. }