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.6KB

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