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.

BorderManager.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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.render.txt.border;
  19. import org.apache.fop.fo.Constants;
  20. import org.apache.fop.render.txt.TXTState;
  21. /**
  22. * This keeps all information about borders for current processed page.
  23. */
  24. public class BorderManager {
  25. /** Matrix for storing information about one border element. */
  26. private AbstractBorderElement[][] borderInfo;
  27. /** Width of current processed border. */
  28. private int width;
  29. /** Height of current processed border. */
  30. private int height;
  31. /** x-coordinate of upper left point of current processed border. */
  32. private int startX;
  33. /** y-coordinate of upper left point of current processed border. */
  34. private int startY;
  35. /** Stores TXTState for transforming border elements. */
  36. private TXTState state;
  37. /**
  38. * Constructs BorderManger, using <code>pageWidth</code> and
  39. * <code>pageHeight</code> for creating <code>borderInfo</code>.
  40. *
  41. * @param pageWidth page width
  42. * @param pageHeight page height
  43. * @param state TXTState
  44. */
  45. public BorderManager(int pageWidth, int pageHeight, TXTState state) {
  46. this.state = state;
  47. borderInfo = new AbstractBorderElement[pageHeight][pageWidth];
  48. }
  49. /**
  50. * Adds border element to <code>borderInfo</code>.
  51. *
  52. * @param x x-coordinate
  53. * @param y y-coordinate
  54. * @param style border-style
  55. * @param type border element type, binary representation of wich gives
  56. * information about availability or absence of corresponding side.
  57. */
  58. public void addBorderElement(int x, int y, int style, int type) {
  59. AbstractBorderElement be = null;
  60. if (style == Constants.EN_SOLID || style == Constants.EN_DOUBLE) {
  61. be = new SolidAndDoubleBorderElement(style, type);
  62. } else if (style == Constants.EN_DOTTED) {
  63. be = new DottedBorderElement();
  64. } else if (style == Constants.EN_DASHED) {
  65. be = new DashedBorderElement(type);
  66. } else {
  67. return;
  68. }
  69. be.transformElement(state);
  70. if (borderInfo[y][x] != null) {
  71. borderInfo[y][x] = borderInfo[y][x].merge(be);
  72. } else {
  73. borderInfo[y][x] = be;
  74. }
  75. }
  76. /**
  77. * @param x x-coordinate
  78. * @param y y-coordinate
  79. * @return if border element at point (x,y) is available, returns instance
  80. * of Character, created on char, given by corresponding border element,
  81. * otherwise returns null.
  82. */
  83. public Character getCharacter(int x, int y) {
  84. Character c = null;
  85. if (borderInfo[y][x] != null) {
  86. c = borderInfo[y][x].convert2Char();
  87. }
  88. return c;
  89. }
  90. /**
  91. * @return width of current processed border.
  92. */
  93. public int getWidth() {
  94. return width;
  95. }
  96. /**
  97. * Sets width of current processed border.
  98. * @param width width of border
  99. */
  100. public void setWidth(int width) {
  101. this.width = width;
  102. }
  103. /**
  104. * @return height of current processed border.
  105. */
  106. public int getHeight() {
  107. return height;
  108. }
  109. /**
  110. * Sets height of current processed border.
  111. * @param height height of border
  112. */
  113. public void setHeight(int height) {
  114. this.height = height;
  115. }
  116. /**
  117. * @return x-coordinate of upper left point of current processed border.
  118. */
  119. public int getStartX() {
  120. return startX;
  121. }
  122. /**
  123. * Sets x-coordinate of upper left point of current processed border.
  124. * @param startX x-coordinate of upper left border's point.
  125. */
  126. public void setStartX(int startX) {
  127. this.startX = startX;
  128. }
  129. /**
  130. * @return y-coordinate of upper left point of current processed border.
  131. */
  132. public int getStartY() {
  133. return startY;
  134. }
  135. /**
  136. * Sets y-coordinate of upper left point of current processed border.
  137. * @param startY y-coordinate of upper left border's point.
  138. */
  139. public void setStartY(int startY) {
  140. this.startY = startY;
  141. }
  142. }