KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lowagie > text > pdf > hyphenation > Hyphenation


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc 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 JavaDoc 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 JavaDoc getPreHyphenText(int index) {
55         return word.substring(0, hyphenPoints[index]);
56     }
57
58     /**
59      * @return the post-break text
60      */

61     public String JavaDoc 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 JavaDoc toString() {
73         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
74         int start = 0;
75         for (int i = 0; i < len; i++) {
76             str.append(word.substring(start, hyphenPoints[i])).append('-');
77             start = hyphenPoints[i];
78         }
79         str.append(word.substring(start));
80         return str.toString();
81     }
82
83 }
84
Popular Tags