/// <summary>Hyphenates a word.</summary> /// <param name="lang">the language</param> /// <param name="country">the optional country code (may be null or "none")</param> /// <param name="hyphPathNames">the map with user-configured hyphenation pattern file names</param> /// <param name="word">the word to hyphenate</param> /// <param name="leftMin">the minimum number of characters before the hyphenation point</param> /// <param name="rightMin">the minimum number of characters after the hyphenation point</param> /// <returns>the hyphenation result</returns> public static iText.Layout.Hyphenation.Hyphenation Hyphenate(String lang, String country, IDictionary <String , String> hyphPathNames, String word, int leftMin, int rightMin) { HyphenationTree hTree = GetHyphenationTree(lang, country, hyphPathNames); if (hTree == null) { log.Warn("Soft hyphen unicode symbols will be used as hints for hyphenation"); char softHyphen = '\u00ad'; IList <int> softHyphens = new List <int>(); int lastSoftHyphenIndex = -1; int curSoftHyphenIndex; while ((curSoftHyphenIndex = word.IndexOf(softHyphen, lastSoftHyphenIndex + 1)) > 0) { softHyphens.Add(curSoftHyphenIndex); lastSoftHyphenIndex = curSoftHyphenIndex; } int leftInd = 0; int rightInd = softHyphens.Count - 1; while (leftInd < softHyphens.Count && word.JSubstring(0, softHyphens[leftInd]).Replace(softHyphen.ToString (), "").Length < leftMin) { leftInd++; } while (rightInd >= 0 && word.Substring(softHyphens[rightInd] + 1).Replace(softHyphen.ToString(), "").Length < rightMin) { rightInd--; } if (leftInd <= rightInd) { int[] hyphenationPoints = new int[rightInd - leftInd + 1]; for (int i = leftInd; i <= rightInd; i++) { hyphenationPoints[i - leftInd] = softHyphens[i]; } return(new iText.Layout.Hyphenation.Hyphenation(word, hyphenationPoints)); } else { return(null); } } return(hTree.Hyphenate(word, leftMin, rightMin)); }
/// <summary>Hyphenates a word.</summary> /// <param name="lang">the language</param> /// <param name="country">the optional country code (may be null or "none")</param> /// <param name="hyphPathNames">the map with user-configured hyphenation pattern file names</param> /// <param name="word">the word to hyphenate</param> /// <param name="leftMin">the minimum number of characters before the hyphenation point</param> /// <param name="rightMin">the minimum number of characters after the hyphenation point</param> /// <returns>the hyphenation result</returns> public static iText.Layout.Hyphenation.Hyphenation Hyphenate(String lang, String country, IDictionary <String , String> hyphPathNames, String word, int leftMin, int rightMin) { // If a word contains soft hyphens, then hyphenation based on soft hyphens has higher priority if (WordContainsSoftHyphens(word)) { return(HyphenateBasedOnSoftHyphens(word, leftMin, rightMin)); } else { HyphenationTree hTree = null; if (lang != null) { hTree = GetHyphenationTree(lang, country, hyphPathNames); } return(hTree != null?hTree.Hyphenate(word, leftMin, rightMin) : null); } }