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.

FontWeightPropertyMaker.java 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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.Constants;
  20. import org.apache.fop.fo.FObj;
  21. import org.apache.fop.fo.PropertyList;
  22. import org.apache.fop.fo.expr.PropertyException;
  23. import org.apache.fop.fo.expr.PropertyInfo;
  24. import org.apache.fop.fo.expr.PropertyParser;
  25. /**
  26. * Font weight property maker.
  27. */
  28. public class FontWeightPropertyMaker extends EnumProperty.Maker {
  29. /**
  30. * Main constructor
  31. * @param propId the property id
  32. */
  33. public FontWeightPropertyMaker(int propId) {
  34. super(propId);
  35. }
  36. /**
  37. * {@inheritDoc}
  38. */
  39. public Property make(PropertyList pList, String value, FObj fo)
  40. throws PropertyException {
  41. if ("inherit".equals(value)) {
  42. return super.make(pList, value, fo);
  43. } else {
  44. String pValue = checkValueKeywords(value);
  45. Property newProp = checkEnumValues(pValue);
  46. int enumValue = (newProp != null) ? newProp.getEnum() : -1;
  47. if (enumValue == Constants.EN_BOLDER || enumValue == Constants.EN_LIGHTER) {
  48. /* check for relative enum values, compute in relation to parent */
  49. Property parentProp = pList.getInherited(Constants.PR_FONT_WEIGHT);
  50. if (enumValue == Constants.EN_BOLDER) {
  51. enumValue = parentProp.getEnum();
  52. switch (enumValue) {
  53. case Constants.EN_100:
  54. newProp = EnumProperty.getInstance(Constants.EN_200, "200");
  55. break;
  56. case Constants.EN_200:
  57. newProp = EnumProperty.getInstance(Constants.EN_300, "300");
  58. break;
  59. case Constants.EN_300:
  60. newProp = EnumProperty.getInstance(Constants.EN_400, "400");
  61. break;
  62. case Constants.EN_400:
  63. newProp = EnumProperty.getInstance(Constants.EN_500, "500");
  64. break;
  65. case Constants.EN_500:
  66. newProp = EnumProperty.getInstance(Constants.EN_600, "600");
  67. break;
  68. case Constants.EN_600:
  69. newProp = EnumProperty.getInstance(Constants.EN_700, "700");
  70. break;
  71. case Constants.EN_700:
  72. newProp = EnumProperty.getInstance(Constants.EN_800, "800");
  73. break;
  74. case Constants.EN_800:
  75. case Constants.EN_900:
  76. newProp = EnumProperty.getInstance(Constants.EN_900, "900");
  77. break;
  78. default:
  79. //nop
  80. }
  81. } else {
  82. enumValue = parentProp.getEnum();
  83. switch (enumValue) {
  84. case Constants.EN_100:
  85. case Constants.EN_200:
  86. newProp = EnumProperty.getInstance(Constants.EN_100, "100");
  87. break;
  88. case Constants.EN_300:
  89. newProp = EnumProperty.getInstance(Constants.EN_200, "200");
  90. break;
  91. case Constants.EN_400:
  92. newProp = EnumProperty.getInstance(Constants.EN_300, "300");
  93. break;
  94. case Constants.EN_500:
  95. newProp = EnumProperty.getInstance(Constants.EN_400, "400");
  96. break;
  97. case Constants.EN_600:
  98. newProp = EnumProperty.getInstance(Constants.EN_500, "500");
  99. break;
  100. case Constants.EN_700:
  101. newProp = EnumProperty.getInstance(Constants.EN_600, "600");
  102. break;
  103. case Constants.EN_800:
  104. newProp = EnumProperty.getInstance(Constants.EN_700, "700");
  105. break;
  106. case Constants.EN_900:
  107. newProp = EnumProperty.getInstance(Constants.EN_800, "800");
  108. break;
  109. default:
  110. //nop
  111. }
  112. }
  113. } else if (enumValue == -1) {
  114. /* neither a keyword, nor an enum
  115. * still maybe a valid expression, so send it through the parser... */
  116. newProp = PropertyParser.parse(value, new PropertyInfo(this, pList));
  117. }
  118. if (newProp != null) {
  119. newProp = convertProperty(newProp, pList, fo);
  120. }
  121. return newProp;
  122. }
  123. }
  124. }