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.

CustomFontCollection.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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.util.List;
  20. /**
  21. * Sets up a set of custom (embedded) fonts
  22. */
  23. public class CustomFontCollection implements FontCollection {
  24. private FontResolver fontResolver;
  25. private final List<EmbedFontInfo> embedFontInfoList;
  26. /**
  27. * Main constructor.
  28. * @param fontResolver a font resolver
  29. * @param customFonts the list of custom fonts
  30. * @param useComplexScriptFeatures true if complex script features enabled
  31. */
  32. public CustomFontCollection(FontResolver fontResolver,
  33. List<EmbedFontInfo> customFonts, boolean useComplexScriptFeatures) {
  34. this.fontResolver = fontResolver;
  35. if (this.fontResolver == null) {
  36. //Ensure that we have minimal font resolution capabilities
  37. this.fontResolver = FontManager.createMinimalFontResolver(useComplexScriptFeatures);
  38. }
  39. this.embedFontInfoList = customFonts;
  40. }
  41. /** {@inheritDoc} */
  42. public int setup(int num, FontInfo fontInfo) {
  43. if (embedFontInfoList == null) {
  44. return num; //No fonts to process
  45. }
  46. String internalName = null;
  47. //FontReader reader = null;
  48. for (int i = 0; i < embedFontInfoList.size(); i++) {
  49. EmbedFontInfo embedFontInfo = embedFontInfoList.get(i);
  50. //String metricsFile = configFontInfo.getMetricsFile();
  51. internalName = "F" + num;
  52. num++;
  53. /*
  54. reader = new FontReader(metricsFile);
  55. reader.useKerning(configFontInfo.getKerning());
  56. reader.setFontEmbedPath(configFontInfo.getEmbedFile());
  57. fontInfo.addMetrics(internalName, reader.getFont());
  58. */
  59. LazyFont font = new LazyFont(embedFontInfo, this.fontResolver);
  60. fontInfo.addMetrics(internalName, font);
  61. List<FontTriplet> triplets = embedFontInfo.getFontTriplets();
  62. for (int tripletIndex = 0; tripletIndex < triplets.size(); tripletIndex++) {
  63. FontTriplet triplet = triplets.get(tripletIndex);
  64. fontInfo.addFontProperties(internalName, triplet);
  65. }
  66. }
  67. return num;
  68. }
  69. }