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.

WritingModeTraits.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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.traits;
  19. /**
  20. * This class provides a reusable implementation of the WritingModeTraitsSetter
  21. * interface.
  22. */
  23. public class WritingModeTraits implements WritingModeTraitsSetter {
  24. private Direction inlineProgressionDirection;
  25. private Direction blockProgressionDirection;
  26. private Direction columnProgressionDirection;
  27. private Direction rowProgressionDirection;
  28. private Direction shiftDirection;
  29. private WritingMode writingMode;
  30. private boolean explicit;
  31. /**
  32. * Default writing mode traits constructor.
  33. */
  34. public WritingModeTraits() {
  35. this (WritingMode.LR_TB, false);
  36. }
  37. /**
  38. * Construct writing mode traits using the specified writing mode.
  39. * @param writingMode a writing mode traits object
  40. */
  41. public WritingModeTraits(WritingMode writingMode, boolean explicit) {
  42. assignWritingModeTraits(writingMode, explicit);
  43. }
  44. /**
  45. * @return the "inline-progression-direction" trait.
  46. */
  47. public Direction getInlineProgressionDirection() {
  48. return inlineProgressionDirection;
  49. }
  50. /**
  51. * @param direction the "inline-progression-direction" trait.
  52. */
  53. public void setInlineProgressionDirection(Direction direction) {
  54. this.inlineProgressionDirection = direction;
  55. }
  56. /**
  57. * @return the "block-progression-direction" trait.
  58. */
  59. public Direction getBlockProgressionDirection() {
  60. return blockProgressionDirection;
  61. }
  62. /**
  63. * @param direction the "block-progression-direction" trait.
  64. */
  65. public void setBlockProgressionDirection(Direction direction) {
  66. this.blockProgressionDirection = direction;
  67. }
  68. /**
  69. * @return the "column-progression-direction" trait.
  70. */
  71. public Direction getColumnProgressionDirection() {
  72. return columnProgressionDirection;
  73. }
  74. /**
  75. * @param direction the "column-progression-direction" trait.
  76. */
  77. public void setColumnProgressionDirection(Direction direction) {
  78. this.columnProgressionDirection = direction;
  79. }
  80. /**
  81. * @return the "row-progression-direction" trait.
  82. */
  83. public Direction getRowProgressionDirection() {
  84. return rowProgressionDirection;
  85. }
  86. /**
  87. * @param direction the "row-progression-direction" trait.
  88. */
  89. public void setRowProgressionDirection(Direction direction) {
  90. this.rowProgressionDirection = direction;
  91. }
  92. /**
  93. * @return the "shift-direction" trait.
  94. */
  95. public Direction getShiftDirection() {
  96. return shiftDirection;
  97. }
  98. /**
  99. * @param direction the "shift-direction" trait.
  100. */
  101. public void setShiftDirection(Direction direction) {
  102. this.shiftDirection = direction;
  103. }
  104. /**
  105. * @return the "writing-mode" trait.
  106. */
  107. public WritingMode getWritingMode() {
  108. return writingMode;
  109. }
  110. /**
  111. * @return the "explicit-writing-mode" trait.
  112. */
  113. public boolean getExplicitWritingMode() {
  114. return explicit;
  115. }
  116. /**
  117. * @param writingMode the "writing-mode" trait.
  118. */
  119. public void setWritingMode(WritingMode writingMode, boolean explicit) {
  120. this.writingMode = writingMode;
  121. this.explicit = explicit;
  122. }
  123. /**
  124. * @param writingMode the "writing-mode" trait.
  125. */
  126. public void assignWritingModeTraits(WritingMode writingMode, boolean explicit) {
  127. writingMode.assignWritingModeTraits(this, explicit);
  128. }
  129. /**
  130. * Helper function to find the writing mode traits getter (if any) that applies for
  131. * a given FO node.
  132. * @param fn the node to start searching from
  133. * @return the applicable writing mode traits getter, or null if none applies
  134. */
  135. public static WritingModeTraitsGetter
  136. getWritingModeTraitsGetter(org.apache.fop.fo.FONode fn) {
  137. for (org.apache.fop.fo.FONode n = fn; n != null; n = n.getParent()) {
  138. if (n instanceof WritingModeTraitsGetter) {
  139. return (WritingModeTraitsGetter) n;
  140. }
  141. }
  142. return null;
  143. }
  144. }