001/* 002 * Copyright 1999-2004 The Apache Software Foundation. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package com.itextpdf.text.pdf.hyphenation; 018 019/** 020 * This class represents a hyphenated word. 021 * 022 * @author Carlos Villegas <cav@uniscope.co.jp> 023 */ 024public class Hyphenation { 025 026 private int[] hyphenPoints; 027 private String word; 028 029 /** 030 * number of hyphenation points in word 031 */ 032 private int len; 033 034 /** 035 * rawWord as made of alternating strings and {@link Hyphen Hyphen} 036 * instances 037 */ 038 Hyphenation(String word, int[] points) { 039 this.word = word; 040 hyphenPoints = points; 041 len = points.length; 042 } 043 044 /** 045 * @return the number of hyphenation points in the word 046 */ 047 public int length() { 048 return len; 049 } 050 051 /** 052 * @return the pre-break text, not including the hyphen character 053 */ 054 public String getPreHyphenText(int index) { 055 return word.substring(0, hyphenPoints[index]); 056 } 057 058 /** 059 * @return the post-break text 060 */ 061 public String getPostHyphenText(int index) { 062 return word.substring(hyphenPoints[index]); 063 } 064 065 /** 066 * @return the hyphenation points 067 */ 068 public int[] getHyphenationPoints() { 069 return hyphenPoints; 070 } 071 072 public String toString() { 073 StringBuffer str = new StringBuffer(); 074 int start = 0; 075 for (int i = 0; i < len; i++) { 076 str.append(word.substring(start, hyphenPoints[i])).append('-'); 077 start = hyphenPoints[i]; 078 } 079 str.append(word.substring(start)); 080 return str.toString(); 081 } 082 083}