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.

CollapsingBorderModelEyeCatching.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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.layoutmgr.table;
  19. import org.apache.fop.fo.Constants;
  20. import org.apache.fop.fo.flow.table.BorderSpecification;
  21. import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
  22. import org.apache.fop.fo.properties.CommonBorderPaddingBackground.BorderInfo;
  23. /**
  24. * Implements the normal "collapse" border model defined in 6.7.10 in XSL 1.0.
  25. *
  26. * TODO Column groups are not yet checked in this algorithm!
  27. */
  28. public class CollapsingBorderModelEyeCatching extends CollapsingBorderModel {
  29. /** {@inheritDoc} */
  30. public BorderSpecification determineWinner(BorderSpecification border1,
  31. BorderSpecification border2, boolean discard) {
  32. BorderInfo bi1 = border1.getBorderInfo();
  33. BorderInfo bi2 = border2.getBorderInfo();
  34. if (discard) {
  35. if (bi1.getWidth().isDiscard()) {
  36. if (bi2.getWidth().isDiscard()) {
  37. return new BorderSpecification(
  38. CommonBorderPaddingBackground.getDefaultBorderInfo(), 0/*TODO*/);
  39. } else {
  40. return border2;
  41. }
  42. } else if (bi2.getWidth().isDiscard()) {
  43. return border1;
  44. }
  45. }
  46. // Otherwise, fall back to the default resolution algorithm
  47. return determineWinner(border1, border2);
  48. }
  49. /** {@inheritDoc} */
  50. public BorderSpecification determineWinner(BorderSpecification border1,
  51. BorderSpecification border2) {
  52. BorderInfo bi1 = border1.getBorderInfo();
  53. BorderInfo bi2 = border2.getBorderInfo();
  54. // Rule 1
  55. if (bi1.getStyle() == Constants.EN_HIDDEN) {
  56. return border1;
  57. } else if (bi2.getStyle() == Constants.EN_HIDDEN) {
  58. return border2;
  59. }
  60. // Rule 2
  61. if (bi2.getStyle() == Constants.EN_NONE) {
  62. return border1;
  63. } else if (bi1.getStyle() == Constants.EN_NONE) {
  64. return border2;
  65. }
  66. // Rule 3
  67. int width1 = bi1.getRetainedWidth();
  68. int width2 = bi2.getRetainedWidth();
  69. if (width1 > width2) {
  70. return border1;
  71. } else if (width1 == width2) {
  72. int cmp = compareStyles(bi1.getStyle(), bi2.getStyle());
  73. if (cmp > 0) {
  74. return border1;
  75. } else if (cmp < 0) {
  76. return border2;
  77. }
  78. } else {
  79. return border2;
  80. }
  81. // Rule 4
  82. int cmp = compareFOs(border1.getHolder(), border2.getHolder());
  83. if (cmp > 0) {
  84. return border1;
  85. } else if (cmp < 0) {
  86. return border2;
  87. }
  88. return null;
  89. }
  90. }