Example usage for com.lowagie.text Utilities isSurrogatePair

List of usage examples for com.lowagie.text Utilities isSurrogatePair

Introduction

In this page you can find the example usage for com.lowagie.text Utilities isSurrogatePair.

Prototype

public static boolean isSurrogatePair(char[] text, int idx) 

Source Link

Document

Checks if two subsequent characters in a character array are are the higher and the lower character in a surrogate pair (and therefore eligible for conversion to a UTF 32 character).

Usage

From source file:com.krawler.accounting.fontsetting.FontFamilySelector.java

License:Open Source License

public Phrase process(String text, FontContext context, Color color, Float size, Integer style) {
    int fsize = families.size();
    if (fsize == 0)
        throw new IndexOutOfBoundsException("No font is defined.");
    if (text == null)
        text = "";
    char cc[] = text.toCharArray();
    int len = cc.length;
    StringBuffer sb = new StringBuffer();
    Font font = null;//from  w w w  .j a v  a2s. co  m
    int lastidx = -1;
    Phrase ret = new Phrase();
    for (int k = 0; k < len; ++k) {
        char c = cc[k];
        if (c == '\n' || c == '\r') {
            sb.append(c);
            continue;
        }

        if (Utilities.isSurrogatePair(cc, k)) {
            int u = Utilities.convertToUtf32(cc, k);
            for (int f = 0; f < fsize; ++f) {
                font = (Font) families.get(f).getPrimaryFont();
                if (font.getBaseFont().charExists(u)) {
                    if (lastidx != f) {
                        if (sb.length() > 0 && lastidx != -1) {
                            FontFamily fm = families.get(lastidx);
                            Font fnt = fm.getFont(context);
                            applyPropertiesToFont(fnt, color, size, style);
                            Chunk ck = new Chunk(sb.toString(), fnt);
                            ret.add(ck);
                            sb.setLength(0);
                        }
                        lastidx = f;
                    }
                    sb.append(c);
                    sb.append(cc[++k]);
                    break;
                }
            }
        } else {
            for (int f = 0; f < fsize; ++f) {
                font = (Font) families.get(f).getPrimaryFont();
                if (font.getBaseFont().charExists(c)) {
                    if (lastidx != f) {
                        if (sb.length() > 0 && lastidx != -1) {
                            FontFamily fm = families.get(lastidx);
                            Font fnt = fm.getFont(context);
                            applyPropertiesToFont(fnt, color, size, style);
                            Chunk ck = new Chunk(sb.toString(), fnt);
                            ret.add(ck);
                            sb.setLength(0);
                        }
                        lastidx = f;
                    }
                    sb.append(c);
                    break;
                }
            }
        }
    }
    if (sb.length() > 0) {
        FontFamily fm = families.get(lastidx == -1 ? 0 : lastidx);
        Font fnt = fm.getFont(context);
        applyPropertiesToFont(fnt, color, size, style);
        Chunk ck = new Chunk(sb.toString(), fnt);
        ret.add(ck);
    }
    return ret;
}

From source file:com.krawler.common.fontsettings.FontFamilySelector.java

License:Open Source License

public Phrase process(String text, FontContext context, Color color, Float size, Integer style) {
    int fsize = families.size();
    if (fsize == 0)
        throw new IndexOutOfBoundsException("No font is defined.");
    if (text == null)
        text = "";
    char cc[] = text.toCharArray();
    int len = cc.length;
    StringBuffer sb = new StringBuffer();
    Font font = null;//from ww w.j  ava2  s .co  m
    int lastidx = -1;
    Phrase ret = new Phrase();
    for (int k = 0; k < len; ++k) {
        char c = cc[k];
        if (c == '\n' || c == '\r') {
            sb.append(c);
            continue;
        }
        if (Utilities.isSurrogatePair(cc, k)) {
            int u = Utilities.convertToUtf32(cc, k);
            for (int f = 0; f < fsize; ++f) {
                font = (Font) families.get(f).getPrimaryFont();
                if (font.getBaseFont().charExists(u)) {
                    if (lastidx != f) {
                        if (sb.length() > 0 && lastidx != -1) {
                            FontFamily fm = families.get(lastidx);
                            Font fnt = fm.getFont(context);
                            applyPropertiesToFont(fnt, color, size, style);
                            Chunk ck = new Chunk(sb.toString(), fnt);
                            ret.add(ck);
                            sb.setLength(0);
                        }
                        lastidx = f;
                    }
                    sb.append(c);
                    sb.append(cc[++k]);
                    break;
                }
            }
        } else {
            for (int f = 0; f < fsize; ++f) {
                font = (Font) families.get(f).getPrimaryFont();
                if (font.getBaseFont().charExists(c)) {
                    if (lastidx != f) {
                        if (sb.length() > 0 && lastidx != -1) {
                            FontFamily fm = families.get(lastidx);
                            Font fnt = fm.getFont(context);
                            applyPropertiesToFont(fnt, color, size, style);
                            Chunk ck = new Chunk(sb.toString(), fnt);
                            ret.add(ck);
                            sb.setLength(0);
                        }
                        lastidx = f;
                    }
                    sb.append(c);
                    break;
                }
            }
        }
    }
    if (sb.length() > 0) {
        FontFamily fm = families.get(lastidx == -1 ? 0 : lastidx);
        Font fnt = fm.getFont(context);
        applyPropertiesToFont(fnt, color, size, style);
        Chunk ck = new Chunk(sb.toString(), fnt);
        ret.add(ck);
    }
    return ret;
}

From source file:com.krawler.common.fontsettings.FontFamilySelector.java

License:Open Source License

public Chunk processChunk(String text, FontContext context, Color color, Float size, Integer style) {
    Chunk ck = null;//from   www  .j a va2 s  . c  o m
    int fsize = families.size();
    if (fsize == 0)
        throw new IndexOutOfBoundsException("No font is defined.");
    if (text == null)
        text = "";
    char cc[] = text.toCharArray();
    int len = cc.length;
    StringBuffer sb = new StringBuffer();
    Font font = null;
    int lastidx = -1;
    for (int k = 0; k < len; ++k) {
        char c = cc[k];
        if (c == '\n' || c == '\r') {
            sb.append(c);
            continue;
        }
        if (Utilities.isSurrogatePair(cc, k)) {
            int u = Utilities.convertToUtf32(cc, k);
            for (int f = 0; f < fsize; ++f) {
                font = (Font) families.get(f).getPrimaryFont();
                if (font.getBaseFont().charExists(u)) {
                    if (lastidx != f) {
                        if (sb.length() > 0 && lastidx != -1) {
                            FontFamily fm = families.get(lastidx);
                            Font fnt = fm.getFont(context);
                            applyPropertiesToFont(fnt, color, size, style);
                        }
                        lastidx = f;
                    }
                    sb.append(c);
                    sb.append(cc[++k]);
                    break;
                }
            }
        } else {
            for (int f = 0; f < fsize; ++f) {
                font = (Font) families.get(f).getPrimaryFont();
                if (font.getBaseFont().charExists(c)) {
                    if (lastidx != f) {
                        if (sb.length() > 0 && lastidx != -1) {
                            FontFamily fm = families.get(lastidx);
                            Font fnt = fm.getFont(context);
                            applyPropertiesToFont(fnt, color, size, style);
                        }
                        lastidx = f;
                    }
                    sb.append(c);
                    break;
                }
            }
        }
    }
    if (sb.length() > 0) {
        FontFamily fm = families.get(lastidx == -1 ? 0 : lastidx);
        Font fnt = fm.getFont(context);
        applyPropertiesToFont(fnt, color, size, style);
        ck = new Chunk(sb.toString(), fnt);
    }
    return ck;
}