KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > hyphenation > Hyphenation


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
18 /* $Id: Hyphenation.java 426576 2006-07-28 15:44:37Z jeremias $ */
19  
20 package org.apache.fop.hyphenation;
21
22 /**
23  * This class represents a hyphenated word.
24  *
25  * @author Carlos Villegas <cav@uniscope.co.jp>
26  */

27 public class Hyphenation {
28     
29     private int[] hyphenPoints;
30     private String JavaDoc word;
31
32     /**
33      * number of hyphenation points in word
34      */

35     private int len;
36
37     /**
38      * rawWord as made of alternating strings and {@link Hyphen Hyphen}
39      * instances
40      */

41     Hyphenation(String JavaDoc word, int[] points) {
42         this.word = word;
43         hyphenPoints = points;
44         len = points.length;
45     }
46
47     /**
48      * @return the number of hyphenation points in the word
49      */

50     public int length() {
51         return len;
52     }
53
54     /**
55      * @return the pre-break text, not including the hyphen character
56      */

57     public String JavaDoc getPreHyphenText(int index) {
58         return word.substring(0, hyphenPoints[index]);
59     }
60
61     /**
62      * @return the post-break text
63      */

64     public String JavaDoc getPostHyphenText(int index) {
65         return word.substring(hyphenPoints[index]);
66     }
67
68     /**
69      * @return the hyphenation points
70      */

71     public int[] getHyphenationPoints() {
72         return hyphenPoints;
73     }
74
75     public String JavaDoc toString() {
76         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
77         int start = 0;
78         for (int i = 0; i < len; i++) {
79             str.append(word.substring(start, hyphenPoints[i]) + "-");
80             start = hyphenPoints[i];
81         }
82         str.append(word.substring(start));
83         return str.toString();
84     }
85
86 }
87
Popular Tags