Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

CorrespondingPropertyMaker.java 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. * Maker class for handling corresponding properties.
  24. */
  25. public class CorrespondingPropertyMaker {
  26. /** base property maker */
  27. protected PropertyMaker baseMaker;
  28. /** corresponding property for lr-tb writing mode */
  29. protected int lrtb;
  30. /** corresponding property for rl-tb writing mode */
  31. protected int rltb;
  32. /** corresponding property for tb-rl writing mode */
  33. protected int tbrl;
  34. /** corresponding property for tb-lr writing mode */
  35. protected int tblr;
  36. /** user parent property list */
  37. protected boolean useParent;
  38. private boolean relative;
  39. /**
  40. * Construct a corresponding property maker.
  41. * @param baseMaker the base property maker
  42. */
  43. public CorrespondingPropertyMaker(PropertyMaker baseMaker) {
  44. this.baseMaker = baseMaker;
  45. baseMaker.setCorresponding(this);
  46. }
  47. /**
  48. * Set corresponding property values.
  49. * @param lrtb a corresponding value
  50. * @param rltb a corresponding value
  51. * @param tbrl a corresponding value
  52. * @param tblr a corresponding value
  53. */
  54. /**
  55. * Set corresponding property identifiers.
  56. * @param lrtb the property that corresponds with lr-tb writing mode
  57. * @param rltb the property that corresponds with rl-tb writing mode
  58. * @param tbrl the property that corresponds with tb-lr writing mode
  59. * @param tblr the property that corresponds with tb-lr writing mode
  60. */
  61. public void setCorresponding(int lrtb, int rltb, int tbrl, int tblr) {
  62. this.lrtb = lrtb;
  63. this.rltb = rltb;
  64. this.tbrl = tbrl;
  65. this.tblr = tblr;
  66. }
  67. /**
  68. * Controls whether the PropertyMaker accesses the parent property list or the current
  69. * property list for determining the writing mode.
  70. * @param useParent true if the parent property list should be used.
  71. */
  72. public void setUseParent(boolean useParent) {
  73. this.useParent = useParent;
  74. }
  75. /**
  76. * Set relative flag.
  77. * @param relative true if properties operate on a relative direction
  78. */
  79. public void setRelative(boolean relative) {
  80. this.relative = relative;
  81. }
  82. /**
  83. * For properties that operate on a relative direction (before, after,
  84. * start, end) instead of an absolute direction (top, bottom, left,
  85. * right), this method determines whether a corresponding property
  86. * is specified on the corresponding absolute direction. For example,
  87. * the border-start-color property in a lr-tb writing-mode specifies
  88. * the same thing that the border-left-color property specifies. In this
  89. * example, if the Maker for the border-start-color property is testing,
  90. * and if the border-left-color is specified in the properties,
  91. * this method should return true.
  92. * @param propertyList collection of properties to be tested
  93. * @return true iff 1) the property operates on a relative direction,
  94. * AND 2) the property has a corresponding property on an absolute
  95. * direction, AND 3) the corresponding property on that absolute
  96. * direction has been specified in the input properties
  97. */
  98. public boolean isCorrespondingForced(PropertyList propertyList) {
  99. if (!relative) {
  100. return false;
  101. }
  102. PropertyList pList = getWMPropertyList(propertyList);
  103. if (pList != null) {
  104. int correspondingId = pList.selectFromWritingMode(lrtb, rltb, tbrl, tblr);
  105. if (pList.getExplicit(correspondingId) != null) {
  106. return true;
  107. }
  108. }
  109. return false;
  110. }
  111. /**
  112. * Return a Property object representing the value of this property,
  113. * based on other property values for this FO.
  114. * A special case is properties which inherit the specified value,
  115. * rather than the computed value.
  116. * @param propertyList The PropertyList for the FO.
  117. * @return Property A computed Property value or null if no rules
  118. * are specified (in foproperties.xml) to compute the value.
  119. * @throws PropertyException if a property exception occurs
  120. */
  121. public Property compute(PropertyList propertyList) throws PropertyException {
  122. PropertyList pList = getWMPropertyList(propertyList);
  123. if (pList == null) {
  124. return null;
  125. }
  126. int correspondingId = pList.selectFromWritingMode(lrtb, rltb, tbrl, tblr);
  127. Property p = propertyList.getExplicitOrShorthand(correspondingId);
  128. if (p != null) {
  129. FObj parentFO = propertyList.getParentFObj();
  130. p = baseMaker.convertProperty(p, propertyList, parentFO);
  131. }
  132. return p;
  133. }
  134. /**
  135. * Return the property list to use for fetching writing mode depending property
  136. * ids.
  137. * @param pList a property list
  138. * @return the property list to use
  139. */
  140. protected PropertyList getWMPropertyList(PropertyList pList) {
  141. if (useParent) {
  142. return pList.getParentPropertyList();
  143. } else {
  144. return pList;
  145. }
  146. }
  147. }