您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

FOPFontFamilyResolverImpl.java 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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.svg.font;
  19. import java.io.InputStream;
  20. import java.util.Map;
  21. import org.apache.batik.bridge.FontFace;
  22. import org.apache.batik.gvt.font.GVTFontFace;
  23. import org.apache.batik.gvt.font.GVTFontFamily;
  24. import org.apache.fop.fonts.Font;
  25. import org.apache.fop.fonts.FontInfo;
  26. import org.apache.fop.fonts.FontTriplet;
  27. import org.apache.fop.fonts.Typeface;
  28. public class FOPFontFamilyResolverImpl implements FOPFontFamilyResolver {
  29. private final FontInfo fontInfo;
  30. public FOPFontFamilyResolverImpl(FontInfo fontInfo) {
  31. this.fontInfo = fontInfo;
  32. }
  33. public FOPGVTFontFamily resolve(String familyName) {
  34. return resolve(familyName, new GVTFontFace(familyName));
  35. }
  36. public FOPGVTFontFamily resolve(String familyName, FontFace fontFace) {
  37. return resolve(familyName, (GVTFontFace) FontFace.createFontFace(familyName, fontFace));
  38. }
  39. private FOPGVTFontFamily resolve(String familyName, GVTFontFace fontFace) {
  40. FOPGVTFontFamily gvtFontFamily = null;
  41. FontTriplet triplet = fontInfo.fontLookup(familyName, Font.STYLE_NORMAL, Font.WEIGHT_NORMAL);
  42. if (fontInfo.hasFont(familyName, Font.STYLE_NORMAL, Font.WEIGHT_NORMAL)) {
  43. gvtFontFamily = new FOPGVTFontFamily(fontInfo, familyName, triplet, fontFace);
  44. }
  45. return gvtFontFamily;
  46. }
  47. public GVTFontFamily loadFont(InputStream in, FontFace fontFace) throws Exception {
  48. throw new UnsupportedOperationException("Not implemented");
  49. }
  50. public FOPGVTFontFamily getDefault() {
  51. return resolve("any");
  52. }
  53. public FOPGVTFontFamily getFamilyThatCanDisplay(char c) {
  54. Map<String, Typeface> fonts = fontInfo.getFonts();
  55. for (Typeface font : fonts.values()) {
  56. if (font.hasChar(c)) {
  57. String fontFamily = font.getFamilyNames().iterator().next();
  58. return new FOPGVTFontFamily(fontInfo, fontFamily,
  59. new FontTriplet(fontFamily, Font.STYLE_NORMAL, Font.WEIGHT_NORMAL),
  60. new GVTFontFace(fontFamily));
  61. }
  62. }
  63. return null;
  64. }
  65. }