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.

PageDimensionMaker.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. /**
  24. * Custom Maker for page-height / page-width
  25. *
  26. */
  27. public class PageDimensionMaker extends LengthProperty.Maker {
  28. /**
  29. * Constructor
  30. *
  31. * @param propId the property Id
  32. */
  33. public PageDimensionMaker(int propId) {
  34. super(propId);
  35. }
  36. /**
  37. * Check the value of the page-width / page-height property.
  38. * Return the default or user-defined fallback in case the value
  39. * was specified as "auto"
  40. * @param subpropId The subproperty id of the property being retrieved.
  41. * Is 0 when retrieving a base property.
  42. * @param propertyList The PropertyList object being built for this FO.
  43. * @param tryInherit true if inherited properties should be examined.
  44. * @param tryDefault true if the default value should be returned.
  45. * @return the property
  46. * @throws PropertyException if a property exception occurs
  47. * @see PropertyMaker#get(int, PropertyList, boolean, boolean)
  48. */
  49. public Property get(int subpropId, PropertyList propertyList,
  50. boolean tryInherit, boolean tryDefault)
  51. throws PropertyException {
  52. Property p = super.get(0, propertyList, tryInherit, tryDefault);
  53. FObj fo = propertyList.getFObj();
  54. String fallbackValue = (propId == Constants.PR_PAGE_HEIGHT)
  55. ? fo.getUserAgent().getPageHeight()
  56. : fo.getUserAgent().getPageWidth();
  57. if (p.getEnum() == Constants.EN_INDEFINITE) {
  58. int otherId = (propId == Constants.PR_PAGE_HEIGHT)
  59. ? Constants.PR_PAGE_WIDTH : Constants.PR_PAGE_HEIGHT;
  60. int writingMode = propertyList.get(Constants.PR_WRITING_MODE).getEnum();
  61. int refOrientation = propertyList.get(Constants.PR_REFERENCE_ORIENTATION)
  62. .getNumeric().getValue();
  63. if (propertyList.getExplicit(otherId) != null
  64. && propertyList.getExplicit(otherId).getEnum() == Constants.EN_INDEFINITE) {
  65. //both set to "indefinite":
  66. //determine which one of the two defines the dimension
  67. //in block-progression-direction, and set the other to
  68. //"auto"
  69. if ((writingMode != Constants.EN_TB_RL
  70. && (refOrientation == 0
  71. || refOrientation == 180
  72. || refOrientation == -180))
  73. || (writingMode == Constants.EN_TB_RL
  74. && (refOrientation == 90
  75. || refOrientation == 270
  76. || refOrientation == -270))) {
  77. //set page-width to "auto" = use the fallback from FOUserAgent
  78. if (propId == Constants.PR_PAGE_WIDTH) {
  79. Property.log.warn("Both page-width and page-height set to "
  80. + "\"indefinite\". Forcing page-width to \"auto\"");
  81. return make(propertyList, fallbackValue, fo);
  82. }
  83. } else {
  84. //set page-height to "auto" = use fallback from FOUserAgent
  85. Property.log.warn("Both page-width and page-height set to "
  86. + "\"indefinite\". Forcing page-height to \"auto\"");
  87. if (propId == Constants.PR_PAGE_HEIGHT) {
  88. return make(propertyList, fallbackValue, fo);
  89. }
  90. }
  91. }
  92. } else if (p.isAuto()) {
  93. return make(propertyList, fallbackValue, fo);
  94. }
  95. return p;
  96. }
  97. }