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.

TextArea.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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.area.inline;
  19. /**
  20. * A text inline area.
  21. */
  22. public class TextArea extends AbstractTextArea {
  23. private static final long serialVersionUID = 7315900267242540809L;
  24. /**
  25. * Create a text inline area
  26. */
  27. public TextArea() {
  28. }
  29. /**
  30. * Constructor with extra parameters:
  31. * create a TextAdjustingInfo object
  32. * @param stretch the available stretch of the text
  33. * @param shrink the available shrink of the text
  34. * @param adj the current total adjustment
  35. */
  36. public TextArea(int stretch, int shrink, int adj) {
  37. super(stretch, shrink, adj);
  38. }
  39. /**
  40. * Remove the old text
  41. */
  42. public void removeText() {
  43. inlines.clear();
  44. }
  45. /**
  46. * Create and add a WordArea child to this TextArea.
  47. *
  48. * @param word the word string
  49. * @param offset the offset for the next area
  50. */
  51. public void addWord(String word, int offset) {
  52. addWord(word, offset, null);
  53. }
  54. /**
  55. * Create and add a WordArea child to this TextArea.
  56. *
  57. * @param word the word string
  58. * @param offset the offset for the next area
  59. * @param letterAdjust the letter adjustment array (may be null)
  60. */
  61. public void addWord(String word, int offset, int[] letterAdjust) {
  62. WordArea wordArea = new WordArea(word, offset, letterAdjust);
  63. addChildArea(wordArea);
  64. wordArea.setParentArea(this);
  65. }
  66. /**
  67. * Create and add a SpaceArea child to this TextArea
  68. *
  69. * @param space the space character
  70. * @param offset the offset for the next area
  71. * @param adjustable is this space adjustable?
  72. */
  73. public void addSpace(char space, int offset, boolean adjustable) {
  74. SpaceArea spaceArea = new SpaceArea(space, offset, adjustable);
  75. addChildArea(spaceArea);
  76. spaceArea.setParentArea(this);
  77. }
  78. /**
  79. * Get the whole text string.
  80. * Renderers whose space adjustment handling is not affected
  81. * by multi-byte characters can use this method to render the
  82. * whole TextArea at once; the other renderers (for example
  83. * PDFRenderer) have to implement renderWord(WordArea) and
  84. * renderSpace(SpaceArea) in order to correctly place each
  85. * text fragment.
  86. *
  87. * @return the text string
  88. */
  89. public String getText() {
  90. StringBuffer text = new StringBuffer();
  91. InlineArea child;
  92. // assemble the text
  93. for (int i = 0; i < inlines.size(); i++) {
  94. child = (InlineArea) inlines.get(i);
  95. if (child instanceof WordArea) {
  96. text.append(((WordArea) child).getWord());
  97. } else {
  98. text.append(((SpaceArea) child).getSpace());
  99. }
  100. }
  101. return text.toString();
  102. }
  103. /** {@inheritDoc} */
  104. public String toString() {
  105. return "TextArea{text=" + getText() + "}";
  106. }
  107. }