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.

PropertyInfo.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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.expr;
  19. import java.util.Stack;
  20. import org.apache.fop.apps.FOUserAgent;
  21. import org.apache.fop.datatypes.Length;
  22. import org.apache.fop.datatypes.PercentBase;
  23. import org.apache.fop.fo.Constants;
  24. import org.apache.fop.fo.FObj;
  25. import org.apache.fop.fo.PropertyList;
  26. import org.apache.fop.fo.properties.PropertyMaker;
  27. /**
  28. * This class holds context information needed during property expression
  29. * evaluation.
  30. * It holds the Maker object for the property, the PropertyList being
  31. * built, and the FObj parent of the FObj for which the property is being set.
  32. */
  33. public class PropertyInfo {
  34. private PropertyMaker maker;
  35. private PropertyList plist;
  36. private FObj fo;
  37. private Stack stkFunction; // Stack of functions being evaluated
  38. /**
  39. * Constructor
  40. * @param maker Property.Maker object
  41. * @param plist PropertyList object
  42. */
  43. public PropertyInfo(PropertyMaker maker, PropertyList plist) {
  44. this.maker = maker;
  45. this.plist = plist;
  46. this.fo = plist.getParentFObj();
  47. }
  48. /**
  49. * Return the PercentBase object used to calculate the absolute value from
  50. * a percent specification.
  51. * Propagates to the Maker.
  52. * @return The PercentBase object or null if percentLengthOK()=false.
  53. * @throws PropertyException if a property exception occurs
  54. */
  55. public PercentBase getPercentBase() throws PropertyException {
  56. PercentBase pcbase = getFunctionPercentBase();
  57. return (pcbase != null) ? pcbase : maker.getPercentBase(plist);
  58. }
  59. /**
  60. * @return the current font-size value as base units (milli-points).
  61. * @throws PropertyException if a property exception occurs
  62. */
  63. public Length currentFontSize() throws PropertyException {
  64. return plist.get(Constants.PR_FONT_SIZE).getLength();
  65. }
  66. /**
  67. * accessor for FObj
  68. * @return FObj
  69. */
  70. public FObj getFO() {
  71. return fo;
  72. }
  73. /**
  74. * accessor for PropertyList
  75. * @return PropertyList object
  76. */
  77. public PropertyList getPropertyList() {
  78. return plist;
  79. }
  80. /**
  81. * accessor for PropertyMaker
  82. * @return PropertyMaker object
  83. */
  84. public PropertyMaker getPropertyMaker() {
  85. return maker;
  86. }
  87. /**
  88. * push a function onto the function stack
  89. * @param func function to push onto stack
  90. */
  91. public void pushFunction(Function func) {
  92. if (stkFunction == null) {
  93. stkFunction = new Stack();
  94. }
  95. stkFunction.push(func);
  96. }
  97. /**
  98. * pop a function off of the function stack
  99. */
  100. public void popFunction() {
  101. if (stkFunction != null) {
  102. stkFunction.pop();
  103. }
  104. }
  105. /**
  106. * Convenience shortcut to get a reference to the FOUserAgent
  107. *
  108. * @return the FOUserAgent
  109. */
  110. protected FOUserAgent getUserAgent() {
  111. return (plist.getFObj() != null)
  112. ? plist.getFObj().getUserAgent()
  113. : null;
  114. }
  115. private PercentBase getFunctionPercentBase() {
  116. if (stkFunction != null) {
  117. Function f = (Function)stkFunction.peek();
  118. if (f != null) {
  119. return f.getPercentBase();
  120. }
  121. }
  122. return null;
  123. }
  124. }