Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

FontFamilyProperty.java 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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.fo.properties;
  19. import org.apache.fop.fo.FObj;
  20. import org.apache.fop.fo.PropertyList;
  21. import org.apache.fop.fo.expr.PropertyException;
  22. /**
  23. * Property class for the font-family property.
  24. */
  25. public final class FontFamilyProperty extends ListProperty {
  26. /** cache holding all canonical FontFamilyProperty instances */
  27. private static final PropertyCache<FontFamilyProperty> CACHE
  28. = new PropertyCache<FontFamilyProperty>();
  29. /**
  30. * Inner class for creating instances of ListProperty
  31. */
  32. public static class Maker extends PropertyMaker {
  33. /**
  34. * @param propId ID of the property for which Maker should be created
  35. */
  36. public Maker(int propId) {
  37. super(propId);
  38. }
  39. /**
  40. * {@inheritDoc}
  41. */
  42. public Property make(PropertyList propertyList, String value, FObj fo)
  43. throws PropertyException {
  44. if ("inherit".equals(value)) {
  45. return super.make(propertyList, value, fo);
  46. } else {
  47. FontFamilyProperty prop = new FontFamilyProperty();
  48. String tmpVal;
  49. int startIndex = 0;
  50. int commaIndex = value.indexOf(',');
  51. int quoteIndex;
  52. int aposIndex;
  53. char qChar;
  54. boolean parsed = false;
  55. while (!parsed) {
  56. if (commaIndex == -1) {
  57. tmpVal = value.substring(startIndex).trim();
  58. parsed = true;
  59. } else {
  60. tmpVal = value.substring(startIndex, commaIndex).trim();
  61. startIndex = commaIndex + 1;
  62. commaIndex = value.indexOf(',', startIndex);
  63. }
  64. aposIndex = tmpVal.indexOf('\'');
  65. quoteIndex = tmpVal.indexOf('\"');
  66. if (aposIndex != -1 || quoteIndex != -1) {
  67. qChar = (aposIndex == -1) ? '\"' : '\'';
  68. if (tmpVal.lastIndexOf(qChar) != tmpVal.length() - 1) {
  69. log.warn("Skipping malformed value for font-family: "
  70. + tmpVal + " in \"" + value + "\".");
  71. tmpVal = "";
  72. } else {
  73. tmpVal = tmpVal.substring(1, tmpVal.length() - 1);
  74. }
  75. }
  76. if (!"".equals(tmpVal)) {
  77. int dblSpaceIndex = tmpVal.indexOf(" ");
  78. while (dblSpaceIndex != -1) {
  79. tmpVal = tmpVal.substring(0, dblSpaceIndex)
  80. + tmpVal.substring(dblSpaceIndex + 1);
  81. dblSpaceIndex = tmpVal.indexOf(" ");
  82. }
  83. prop.addProperty(StringProperty.getInstance(tmpVal));
  84. }
  85. }
  86. return CACHE.fetch(prop);
  87. }
  88. }
  89. /**
  90. * {@inheritDoc}
  91. */
  92. public Property convertProperty(Property p,
  93. PropertyList propertyList, FObj fo) {
  94. if (p instanceof FontFamilyProperty) {
  95. return p;
  96. } else {
  97. return new FontFamilyProperty(p);
  98. }
  99. }
  100. }
  101. /**
  102. * @param prop the first Property to be added to the list
  103. */
  104. private FontFamilyProperty(Property prop) {
  105. super();
  106. addProperty(prop);
  107. }
  108. /**
  109. * Default constructor.
  110. *
  111. */
  112. private FontFamilyProperty() {
  113. super();
  114. }
  115. /**
  116. * Add a new property to the list
  117. * @param prop Property to be added to the list
  118. */
  119. public void addProperty(Property prop) {
  120. if (prop.getList() != null) {
  121. list.addAll(prop.getList());
  122. } else {
  123. super.addProperty(prop);
  124. }
  125. }
  126. /** {@inheritDoc} */
  127. public String getString() {
  128. if (list.size() > 0) {
  129. Property first = (Property)list.get(0);
  130. return first.getString();
  131. } else {
  132. return super.getString();
  133. }
  134. }
  135. }