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.

AFPFontFamilyResolver.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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.afp.svg;
  19. import java.util.HashMap;
  20. import java.util.Map;
  21. import org.apache.batik.gvt.font.GVTFontFace;
  22. import org.apache.fop.afp.AFPEventProducer;
  23. import org.apache.fop.afp.fonts.DoubleByteFont;
  24. import org.apache.fop.events.EventBroadcaster;
  25. import org.apache.fop.fonts.Font;
  26. import org.apache.fop.fonts.FontInfo;
  27. import org.apache.fop.fonts.FontTriplet;
  28. import org.apache.fop.fonts.Typeface;
  29. import org.apache.fop.svg.font.FOPFontFamilyResolverImpl;
  30. import org.apache.fop.svg.font.FOPGVTFontFamily;
  31. import org.apache.fop.svg.font.FilteringFontFamilyResolver;
  32. public class AFPFontFamilyResolver extends FilteringFontFamilyResolver {
  33. private final FontInfo fontInfo;
  34. private final AFPEventProducer eventProducer;
  35. public AFPFontFamilyResolver(FontInfo fontInfo, EventBroadcaster eventBroadCaster) {
  36. super(new FOPFontFamilyResolverImpl(fontInfo));
  37. this.fontInfo = fontInfo;
  38. this.eventProducer = AFPEventProducer.Provider.get(eventBroadCaster);
  39. }
  40. @Override
  41. public FOPGVTFontFamily resolve(String familyName) {
  42. FOPGVTFontFamily fopGVTFontFamily = super.resolve(familyName);
  43. // TODO why don't DB fonts work with GOCA?!?
  44. if (fopGVTFontFamily != null && fopGVTFontFamily.deriveFont(1, new HashMap())
  45. .getFont().getFontMetrics() instanceof DoubleByteFont) {
  46. notifyDBFontRejection(fopGVTFontFamily.getFamilyName());
  47. fopGVTFontFamily = null;
  48. }
  49. return fopGVTFontFamily;
  50. }
  51. @Override
  52. public FOPGVTFontFamily getFamilyThatCanDisplay(char c) {
  53. Map<String, Typeface> fonts = fontInfo.getFonts();
  54. for (Typeface font : fonts.values()) {
  55. // TODO why don't DB fonts work with GOCA?!?
  56. if (font.hasChar(c) && !(font instanceof DoubleByteFont)) {
  57. String fontFamily = font.getFamilyNames().iterator().next();
  58. if (font instanceof DoubleByteFont) {
  59. notifyDBFontRejection(font.getFontName());
  60. } else {
  61. return new FOPGVTFontFamily(fontInfo, fontFamily,
  62. new FontTriplet(fontFamily, Font.STYLE_NORMAL, Font.WEIGHT_NORMAL),
  63. new GVTFontFace(fontFamily));
  64. }
  65. }
  66. }
  67. return null;
  68. }
  69. private void notifyDBFontRejection(String fontFamily) {
  70. eventProducer.invalidDBFontInSVG(this, fontFamily);
  71. }
  72. }