01: /*
02: * Copyright 1999-2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package com.lowagie.text.pdf.hyphenation;
18:
19: /**
20: * This class represents a hyphenated word.
21: *
22: * @author Carlos Villegas <cav@uniscope.co.jp>
23: */
24: public class Hyphenation {
25:
26: private int[] hyphenPoints;
27: private String word;
28:
29: /**
30: * number of hyphenation points in word
31: */
32: private int len;
33:
34: /**
35: * rawWord as made of alternating strings and {@link Hyphen Hyphen}
36: * instances
37: */
38: Hyphenation(String word, int[] points) {
39: this .word = word;
40: hyphenPoints = points;
41: len = points.length;
42: }
43:
44: /**
45: * @return the number of hyphenation points in the word
46: */
47: public int length() {
48: return len;
49: }
50:
51: /**
52: * @return the pre-break text, not including the hyphen character
53: */
54: public String getPreHyphenText(int index) {
55: return word.substring(0, hyphenPoints[index]);
56: }
57:
58: /**
59: * @return the post-break text
60: */
61: public String getPostHyphenText(int index) {
62: return word.substring(hyphenPoints[index]);
63: }
64:
65: /**
66: * @return the hyphenation points
67: */
68: public int[] getHyphenationPoints() {
69: return hyphenPoints;
70: }
71:
72: public String toString() {
73: StringBuffer str = new StringBuffer();
74: int start = 0;
75: for (int i = 0; i < len; i++) {
76: str.append(word.substring(start, hyphenPoints[i])).append(
77: '-');
78: start = hyphenPoints[i];
79: }
80: str.append(word.substring(start));
81: return str.toString();
82: }
83:
84: }
|