001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /* $Id: TextArea.java 453920 2006-10-07 14:29:54Z spepping $ */
019:
020: package org.apache.fop.area.inline;
021:
022: /**
023: * A text inline area.
024: */
025: public class TextArea extends AbstractTextArea {
026:
027: /**
028: * Create a text inline area
029: */
030: public TextArea() {
031: }
032:
033: /**
034: * Constructor with extra parameters:
035: * create a TextAdjustingInfo object
036: * @param stretch the available stretch of the text
037: * @param shrink the available shrink of the text
038: * @param adj the current total adjustment
039: */
040: public TextArea(int stretch, int shrink, int adj) {
041: super (stretch, shrink, adj);
042: }
043:
044: /**
045: * Remove the old text
046: */
047: public void removeText() {
048: inlines.clear();
049: }
050:
051: /**
052: * Create and add a WordArea child to this TextArea.
053: *
054: * @param word the word string
055: * @param offset the offset for the next area
056: */
057: public void addWord(String word, int offset) {
058: addWord(word, offset, null);
059: }
060:
061: /**
062: * Create and add a WordArea child to this TextArea.
063: *
064: * @param word the word string
065: * @param offset the offset for the next area
066: */
067: public void addWord(String word, int offset, int[] letterAdjust) {
068: WordArea wordArea = new WordArea(word, offset, letterAdjust);
069: addChildArea(wordArea);
070: wordArea.setParentArea(this );
071: }
072:
073: /**
074: * Create and add a SpaceArea child to this TextArea
075: *
076: * @param space the space character
077: * @param offset the offset for the next area
078: * @param adjustable is this space adjustable?
079: */
080: public void addSpace(char space, int offset, boolean adjustable) {
081: SpaceArea spaceArea = new SpaceArea(space, offset, adjustable);
082: addChildArea(spaceArea);
083: spaceArea.setParentArea(this );
084: }
085:
086: /**
087: * Get the whole text string.
088: * Renderers whose space adjustment handling is not affected
089: * by multi-byte characters can use this method to render the
090: * whole TextArea at once; the other renderers (for example
091: * PDFRenderer) have to implement renderWord(WordArea) and
092: * renderSpace(SpaceArea) in order to correctly place each
093: * text fragment.
094: *
095: * @return the text string
096: */
097: public String getText() {
098: StringBuffer text = new StringBuffer();
099: InlineArea child;
100: // assemble the text
101: for (int i = 0; i < inlines.size(); i++) {
102: child = (InlineArea) inlines.get(i);
103: if (child instanceof WordArea) {
104: text.append(((WordArea) child).getWord());
105: } else {
106: text.append(((SpaceArea) child).getSpace());
107: }
108: }
109: return text.toString();
110: }
111:
112: }
|