コード例 #1
0
        int Paracount; // For suppressing space prior to first paragraph

        int Html(String s, int i, String endtag)
        {
            int n     = s.Length;
            int plain = i; // Start of plain (not within a tag) text.

            while (i < n - 2)
            {
                char c = s[i];
                i += 1;
                if (c == '&' && i < n - 2) // & char literals
                {
                    Txt(s, plain, i - 1);
                    if (s[i] == 'l' && s[i + 1] == 't' && s[i + 2] == ';')
                    {
                        Txt("<"); i += 3;
                    }
                    else if (i < n - 3 && s[i] == 'a' && s[i + 1] == 'm' && s[i + 2] == 'p' && s[i + 3] == ';')
                    {
                        Txt("&"); i += 4;
                    }
                    else
                    {
                        Txt("&");
                    }
                    plain = i;
                }
                else if (c == '<') // HTML tag
                {
                    char t = s[i]; // First char of the tag
                    if (t == '/' || (t >= 'a' && t <= 'z') || (t >= 'A' && t <= 'Z'))
                    {
                        Txt(s, plain, i - 1);
                        i += 1;
                        int tagstart = i - 1, tagend = -1;
                        while (i < n) // Loop to find end of the tag
                        {
                            c = s[i];
                            if (c == ' ')
                            {
                                tagend = i;
                            }
                            i += 1;
                            if (c == '>')
                            {
                                break;
                            }
                        }
                        if (tagend < 0)
                        {
                            tagend = i - 1;
                        }
                        if (t == '/')
                        {
                            tagstart = tagstart + 1;
                        }

                        String tag = tagend > tagstart?s.Substring(tagstart, tagend - tagstart) : "";

                        if (t == '/')
                        {
                            return(tag == endtag ? i : tagstart - 2);
                        }

                        if (tag == "br" || tag == "br/")
                        {
                            NewLine();
                        }
                        else
                        {
                            int Save = 0; PdfFont SaveF = null;
                            if (tag == "p")
                            {
                                Paracount += 1; if (Paracount > 1)
                                {
                                    NewLine(); NewLine();
                                }
                            }
                            else if (tag == "b")
                            {
                                SaveF = Font; PdfFont nf = (SaveF == Fonts[2]) ? Fonts[3] : Fonts[1]; SetFont(nf, FontSize);
                            }
                            else if (tag == "i")
                            {
                                SaveF = Font; PdfFont nf = (SaveF == Fonts[1]) ? Fonts[3] : Fonts[2]; SetFont(nf, FontSize);
                            }
                            else if (tag == "sup")
                            {
                                Save = Super; SetSuper(FontSize / 2);
                            }
                            else if (tag == "sub")
                            {
                                Save = Super; SetSuper(-FontSize / 2);
                            }
                            i = Html(s, i, tag);
                            if (tag == "b" || tag == "i")
                            {
                                SetFont(SaveF, FontSize);
                            }
                            else if (tag == "sup" || tag == "sub")
                            {
                                SetSuper(Save);
                            }
                        }
                        plain = i;
                    }
                }
            }
            i = n;
            Txt(s, plain, i);
            return(i);
        }
コード例 #2
0
ファイル: PdfWriter.cs プロジェクト: georgebarwood/pdf
        // End fields.

        public void InitFont(PdfFont f)
        {
            f.GetObj(this);
        }                                                 // Only needs to be called if a page font is set directly.
コード例 #3
0
ファイル: PdfPage.cs プロジェクト: georgebarwood/pdf
 public void ClearState()
 {
     FlushStrBuffer();
     X     = 0; Y = 0; CurFont = null; LastFont = null;
     Super = 0; Color = null; Other = null;
 }
コード例 #4
0
ファイル: PdfWriter.cs プロジェクト: georgebarwood/pdf
        }                                          // Force a new page.

        // Functions to adjust text style.
        public void SetFont(PdfFont f, int fontSize)
        {
            Word.Font(f, fontSize); _Font = f; _FontSize = fontSize;
        }