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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. import org.apache.fop.render.PrintRenderer;
  21. /**
  22. * Sets up a set of custom (embedded) fonts
  23. */
  24. public class CustomFontCollection implements FontCollection {
  25. private PrintRenderer renderer = null;
  26. /**
  27. * A print renderer to configure
  28. * @param renderer a print renderer
  29. */
  30. public CustomFontCollection(PrintRenderer renderer) {
  31. this.renderer = renderer;
  32. }
  33. /**
  34. * {@inheritDoc}
  35. */
  36. public int setup(int num, FontInfo fontInfo) {
  37. List/*<EmbedFontInfo>*/ embedFontInfoList = renderer.getFontList();
  38. if (embedFontInfoList == null) {
  39. return num; //No fonts to process
  40. }
  41. FontResolver resolver = renderer.getFontResolver();
  42. if (resolver == null) {
  43. //Ensure that we have minimal font resolution capabilities
  44. resolver = FontManager.createMinimalFontResolver();
  45. }
  46. String internalName = null;
  47. //FontReader reader = null;
  48. for (int i = 0; i < embedFontInfoList.size(); i++) {
  49. EmbedFontInfo 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, resolver);
  60. fontInfo.addMetrics(internalName, font);
  61. List triplets = embedFontInfo.getFontTriplets();
  62. for (int tripletIndex = 0; tripletIndex < triplets.size(); tripletIndex++) {
  63. FontTriplet triplet = (FontTriplet) triplets.get(tripletIndex);
  64. fontInfo.addFontProperties(internalName, triplet);
  65. }
  66. }
  67. return num;
  68. }
  69. }