List of usage examples for com.lowagie.text Utilities convertToUtf32
public static int convertToUtf32(String text, int idx)
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 . ja va2 s . c o 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;/*www. j a v a 2 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;/* w w w .ja va 2 s . com*/ 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; }