iTextSharp.text.pdf.FontSelector.Process C# (CSharp) Метод

Process() публичный Метод

public Process ( String text ) : Phrase
text String
Результат iTextSharp.text.Phrase
        public Phrase Process(String text) {
            int fsize = fonts.Count;
            if (fsize == 0)
                throw new ArgumentException("No font is defined.");
            char[] cc = text.ToCharArray();
            int len = cc.Length;
            StringBuilder sb = new StringBuilder();
            Font font = null;
            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)fonts[f];
                        if (font.BaseFont.CharExists(u)) {
                            if (lastidx != f) {
                                if (sb.Length > 0 && lastidx != -1) {
                                    Chunk ck = new Chunk(sb.ToString(), (Font)fonts[lastidx]);
                                    ret.Add(ck);
                                    sb.Length = 0;
                                }
                                lastidx = f;
                            }
                            sb.Append(c);
                            sb.Append(cc[++k]);
                            break;
                        }
                    }
                }
                else {
                    for (int f = 0; f < fsize; ++f) {
                        font = (Font)fonts[f];
                        if (font.BaseFont.CharExists(c)) {
                            if (lastidx != f) {
                                if (sb.Length > 0 && lastidx != -1) {
                                    Chunk ck = new Chunk(sb.ToString(), (Font)fonts[lastidx]);
                                    ret.Add(ck);
                                    sb.Length = 0;
                                }
                                lastidx = f;
                            }
                            sb.Append(c);
                            break;
                        }
                    }
                }
            }
            if (sb.Length > 0) {
                Chunk ck = new Chunk(sb.ToString(), (Font)fonts[lastidx == -1 ? 0 : lastidx]);
                ret.Add(ck);
            }
            return ret;
        }
    }

Usage Example

Пример #1
0
        private Phrase ComposePhrase(String text, BaseFont ufont, BaseColor color, float fontSize)
        {
            Phrase phrase = null;

            if (extensionFont == null && (substitutionFonts == null || substitutionFonts.Count == 0))
            {
                phrase = new Phrase(new Chunk(text, new Font(ufont, fontSize, 0, color)));
            }
            else
            {
                FontSelector fs = new FontSelector();
                fs.AddFont(new Font(ufont, fontSize, 0, color));
                if (extensionFont != null)
                {
                    fs.AddFont(new Font(extensionFont, fontSize, 0, color));
                }
                if (substitutionFonts != null)
                {
                    foreach (BaseFont bf in substitutionFonts)
                    {
                        fs.AddFont(new Font(bf, fontSize, 0, color));
                    }
                }
                phrase = fs.Process(text);
            }
            return(phrase);
        }
All Usage Examples Of iTextSharp.text.pdf.FontSelector::Process
FontSelector