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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. *
  41. * @see PropertyMaker#get(int, PropertyList, boolean, boolean)
  42. */
  43. public Property get(int subpropId, PropertyList propertyList,
  44. boolean tryInherit, boolean tryDefault)
  45. throws PropertyException {
  46. Property p = super.get(0, propertyList, tryInherit, tryDefault);
  47. FObj fo = propertyList.getFObj();
  48. String fallbackValue = (propId == Constants.PR_PAGE_HEIGHT)
  49. ? fo.getUserAgent().getPageHeight()
  50. : fo.getUserAgent().getPageWidth();
  51. if (p.getEnum() == Constants.EN_INDEFINITE) {
  52. int otherId = (propId == Constants.PR_PAGE_HEIGHT)
  53. ? Constants.PR_PAGE_WIDTH : Constants.PR_PAGE_HEIGHT;
  54. int writingMode = propertyList.get(Constants.PR_WRITING_MODE).getEnum();
  55. int refOrientation = propertyList.get(Constants.PR_REFERENCE_ORIENTATION)
  56. .getNumeric().getValue();
  57. if (propertyList.getExplicit(otherId) != null
  58. && propertyList.getExplicit(otherId).getEnum() == Constants.EN_INDEFINITE) {
  59. //both set to "indefinite":
  60. //determine which one of the two defines the dimension
  61. //in block-progression-direction, and set the other to
  62. //"auto"
  63. if ((writingMode != Constants.EN_TB_RL
  64. && (refOrientation == 0
  65. || refOrientation == 180
  66. || refOrientation == -180))
  67. || (writingMode == Constants.EN_TB_RL
  68. && (refOrientation == 90
  69. || refOrientation == 270
  70. || refOrientation == -270))) {
  71. //set page-width to "auto" = use the fallback from FOUserAgent
  72. if (propId == Constants.PR_PAGE_WIDTH) {
  73. Property.log.warn("Both page-width and page-height set to "
  74. + "\"indefinite\". Forcing page-width to \"auto\"");
  75. return make(propertyList, fallbackValue, fo);
  76. }
  77. } else {
  78. //set page-height to "auto" = use fallback from FOUserAgent
  79. Property.log.warn("Both page-width and page-height set to "
  80. + "\"indefinite\". Forcing page-height to \"auto\"");
  81. if (propId == Constants.PR_PAGE_HEIGHT) {
  82. return make(propertyList, fallbackValue, fo);
  83. }
  84. }
  85. }
  86. } else if (p.isAuto()) {
  87. return make(propertyList, fallbackValue, fo);
  88. }
  89. return p;
  90. }
  91. }