Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

AggregatingFontFamilyResolver.java 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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.Arrays;
  21. import java.util.List;
  22. import org.apache.batik.bridge.FontFace;
  23. import org.apache.batik.gvt.font.FontFamilyResolver;
  24. import org.apache.batik.gvt.font.GVTFontFamily;
  25. public class AggregatingFontFamilyResolver implements FontFamilyResolver {
  26. private final List<FontFamilyResolver> resolvers;
  27. public AggregatingFontFamilyResolver(FontFamilyResolver... resolvers) {
  28. this.resolvers = Arrays.<FontFamilyResolver>asList(resolvers);
  29. }
  30. public GVTFontFamily resolve(String familyName) {
  31. for (FontFamilyResolver resolver : resolvers) {
  32. GVTFontFamily family = resolver.resolve(familyName);
  33. if (family != null) {
  34. return family;
  35. }
  36. }
  37. return null;
  38. }
  39. public GVTFontFamily resolve(String familyName, FontFace fontFace) {
  40. for (FontFamilyResolver resolver : resolvers) {
  41. GVTFontFamily family = resolver.resolve(familyName, fontFace);
  42. if (family != null) {
  43. return family;
  44. }
  45. }
  46. return null;
  47. }
  48. public GVTFontFamily loadFont(InputStream in, FontFace fontFace) throws Exception {
  49. for (FontFamilyResolver resolver : resolvers) {
  50. try {
  51. return resolver.loadFont(in, fontFace);
  52. } catch (Exception e) {
  53. // Try the next one
  54. }
  55. }
  56. return null;
  57. }
  58. public GVTFontFamily getDefault() {
  59. return resolve("any");
  60. }
  61. public GVTFontFamily getFamilyThatCanDisplay(char c) {
  62. for (FontFamilyResolver resolver : resolvers) {
  63. GVTFontFamily family = resolver.getFamilyThatCanDisplay(c);
  64. if (family != null) {
  65. return family;
  66. }
  67. }
  68. return null;
  69. }
  70. }