com.lowagie.text.pdf.hyphenation.Hyphenation Java Examples

The following examples show how to use com.lowagie.text.pdf.hyphenation.Hyphenation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HyphenationAuto.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/** Hyphenates a word and returns the first part of it. To get
 * the second part of the hyphenated word call <CODE>getHyphenatedWordPost()</CODE>.
 * @param word the word to hyphenate
 * @param font the font used by this word
 * @param fontSize the font size used by this word
 * @param remainingWidth the width available to fit this word in
 * @return the first part of the hyphenated word including
 * the hyphen symbol, if any
 */    
public String getHyphenatedWordPre(String word, BaseFont font, float fontSize, float remainingWidth) {
    post = word;
    String hyphen = getHyphenSymbol();
    float hyphenWidth = font.getWidthPoint(hyphen, fontSize);
    if (hyphenWidth > remainingWidth)
        return "";
    Hyphenation hyphenation = hyphenator.hyphenate(word);
    if (hyphenation == null) {
        return "";
    }
    int len = hyphenation.length();
    int k;
    for (k = 0; k < len; ++k) {
        if (font.getWidthPoint(hyphenation.getPreHyphenText(k), fontSize) + hyphenWidth > remainingWidth)
            break;
    }
    --k;
    if (k < 0)
        return "";
    post = hyphenation.getPostHyphenText(k);
    return hyphenation.getPreHyphenText(k) + hyphen;
}
 
Example #2
Source File: HyphenationAuto.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/** Hyphenates a word and returns the first part of it. To get
 * the second part of the hyphenated word call <CODE>getHyphenatedWordPost()</CODE>.
 * @param word the word to hyphenate
 * @param font the font used by this word
 * @param fontSize the font size used by this word
 * @param remainingWidth the width available to fit this word in
 * @return the first part of the hyphenated word including
 * the hyphen symbol, if any
 */    
public String getHyphenatedWordPre(String word, BaseFont font, float fontSize, float remainingWidth) {
    post = word;
    String hyphen = getHyphenSymbol();
    float hyphenWidth = font.getWidthPoint(hyphen, fontSize);
    if (hyphenWidth > remainingWidth)
        return "";
    Hyphenation hyphenation = hyphenator.hyphenate(word);
    if (hyphenation == null) {
        return "";
    }
    int len = hyphenation.length();
    int k;
    for (k = 0; k < len; ++k) {
        if (font.getWidthPoint(hyphenation.getPreHyphenText(k), fontSize) + hyphenWidth > remainingWidth)
            break;
    }
    --k;
    if (k < 0)
        return "";
    post = hyphenation.getPostHyphenText(k);
    return hyphenation.getPreHyphenText(k) + hyphen;
}
 
Example #3
Source File: HyphenationAuto.java    From MesquiteCore with GNU Lesser General Public License v3.0 6 votes vote down vote up
/** Hyphenates a word and returns the first part of it. To get
 * the second part of the hyphenated word call <CODE>getHyphenatedWordPost()</CODE>.
 * @param word the word to hyphenate
 * @param font the font used by this word
 * @param fontSize the font size used by this word
 * @param remainingWidth the width available to fit this word in
 * @return the first part of the hyphenated word including
 * the hyphen symbol, if any
 */    
public String getHyphenatedWordPre(String word, BaseFont font, float fontSize, float remainingWidth) {
    post = word;
    String hyphen = getHyphenSymbol();
    float hyphenWidth = font.getWidthPoint(hyphen, fontSize);
    if (hyphenWidth > remainingWidth)
        return "";
    Hyphenation hyphenation = hyphenator.hyphenate(word);
    if (hyphenation == null) {
        return "";
    }
    int len = hyphenation.length();
    int k;
    for (k = 0; k < len; ++k) {
        if (font.getWidthPoint(hyphenation.getPreHyphenText(k), fontSize) + hyphenWidth > remainingWidth)
            break;
    }
    --k;
    if (k < 0)
        return "";
    post = hyphenation.getPostHyphenText(k);
    return hyphenation.getPreHyphenText(k) + hyphen;
}