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.

BreakUtil.java 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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.util;
  19. import org.apache.fop.fo.Constants;
  20. /**
  21. * A utility class for manipulating break classes (the break-before and break-after properties).
  22. */
  23. public final class BreakUtil {
  24. private BreakUtil() { }
  25. // TODO replace that with a proper 1.5 enumeration ASAP
  26. private static int getBreakClassPriority(int breakClass) {
  27. switch (breakClass) {
  28. case Constants.EN_AUTO: return 0;
  29. case Constants.EN_COLUMN: return 1;
  30. case Constants.EN_PAGE: return 2;
  31. case Constants.EN_EVEN_PAGE: return 3;
  32. case Constants.EN_ODD_PAGE: return 3;
  33. default: throw new IllegalArgumentException(
  34. "Illegal value for breakClass: " + breakClass);
  35. }
  36. }
  37. /**
  38. * Compares the given break classes and return the one that wins. even-page and
  39. * odd-page win over page, which wins over column, which wins over auto. If even-page
  40. * and odd-page are compared to each other, which one will be returned is undefined.
  41. *
  42. * @param break1 a break class, one of {@link Constants#EN_AUTO},
  43. * {@link Constants#EN_COLUMN}, {@link Constants#EN_PAGE},
  44. * {@link Constants#EN_EVEN_PAGE}, {@link Constants#EN_ODD_PAGE}
  45. * @param break2 another break class
  46. * @return the break class that wins the comparison
  47. */
  48. public static int compareBreakClasses(int break1, int break2) {
  49. // TODO implement some warning mechanism if even-page and odd-page are being compared
  50. int p1 = getBreakClassPriority(break1);
  51. int p2 = getBreakClassPriority(break2);
  52. if (p1 < p2) {
  53. return break2;
  54. } else {
  55. return break1;
  56. }
  57. }
  58. }