1 47 48 package com.lowagie.text.pdf; 49 50 import com.lowagie.text.pdf.hyphenation.Hyphenation; 51 import com.lowagie.text.pdf.hyphenation.Hyphenator; 52 53 59 public class HyphenationAuto implements HyphenationEvent { 60 61 63 protected Hyphenator hyphenator; 64 66 protected String post; 67 68 74 public HyphenationAuto(String lang, String country, int leftMin, int rightMin) { 75 hyphenator = new Hyphenator(lang, country, leftMin, rightMin); 76 } 77 78 81 public String getHyphenSymbol() { 82 return "-"; 83 } 84 85 94 public String getHyphenatedWordPre(String word, BaseFont font, float fontSize, float remainingWidth) { 95 post = word; 96 String hyphen = getHyphenSymbol(); 97 float hyphenWidth = font.getWidthPoint(hyphen, fontSize); 98 if (hyphenWidth > remainingWidth) 99 return ""; 100 Hyphenation hyphenation = hyphenator.hyphenate(word); 101 if (hyphenation == null) { 102 return ""; 103 } 104 int len = hyphenation.length(); 105 int k; 106 for (k = 0; k < len; ++k) { 107 if (font.getWidthPoint(hyphenation.getPreHyphenText(k), fontSize) + hyphenWidth > remainingWidth) 108 break; 109 } 110 --k; 111 if (k < 0) 112 return ""; 113 post = hyphenation.getPostHyphenText(k); 114 return hyphenation.getPreHyphenText(k) + hyphen; 115 } 116 117 121 public String getHyphenatedWordPost() { 122 return post; 123 } 124 125 } 126 | Popular Tags |