Beispiel #1
0
        public void PushFragment(Fragment frg)
        {
            if (frg.Attr == Fragment.Attributes.AnchorName)
            anchors[frg.Text] = wordOffset;

            wordOffset += frg.WordCount;
        }
Beispiel #2
0
        void EmitFragment(string text)
        {
            var frg = new Fragment();

            frg.Attr = 0;

            if (depEm > 0)
            frg.Attr |= Fragment.Attributes.Italic;
            if (depStrong > 0)
            frg.Attr |= Fragment.Attributes.Bold;
            if (depCode > 0)
            frg.Attr |= Fragment.Attributes.Code;
            if (depHeading > 0)
            frg.Attr |= Fragment.Attributes.Heading;

            frg.Text = text;

            if (stkHref.Count > 0)
            frg.Linkref = stkHref.Peek();

            consumer.PushFragment(frg);
        }
Beispiel #3
0
        public void PushFragment(Fragment frg)
        {
            if ((frg.Text != null) &&
            ((frg.Attr & Fragment.Attributes.Formatter) == 0))
            {
            searchText = null;

            if ((text.Length > 0) &&
            !Char.IsWhiteSpace(text[text.Length - 1]))
            text.Append(' ');

            foreach (char c in frg.Text)
            {
            bool wsTerm = (text.Length <= 0) ||
            Char.IsWhiteSpace(text[text.Length - 1]);

            if (Char.IsWhiteSpace(c))
            {
            if (!wsTerm)
                text.Append(c);
            }
            else
            {
            if (wsTerm)
                wordOffsets.Add(text.Length);

            text.Append(c);
            }
            }
            }
        }
Beispiel #4
0
 public void PushFragment(Fragment frg)
 {
     fragments.Add(frg);
 }
Beispiel #5
0
        public void PushFragment(Fragment frg)
        {
            if (frg.Attr == Fragment.Attributes.NewLine)
            curLine++;

            if ((frg.Text != null) &&
            ((frg.Attr & Fragment.Attributes.Formatter) == 0))
            {
            while (lines.Count <= curLine)
            lines.Add(new Line() {
            Word = curWord,
            Fragment = fragments.Count
            });

            fragments.Add(frg);
            curWord += frg.WordCount;
            }
        }
Beispiel #6
0
        void SendChunks(Fragment frg)
        {
            int i = 0;

            while (i < frg.Text.Length)
            {
            bool hardBreak = false;

            // Skip leading whitespace if at start of line
            if ((paraPos == 0) && Char.IsWhiteSpace(frg.Text[i]))
            {
            while (Char.IsWhiteSpace(frg.Text[i]))
            i++;
            continue;
            }

            // Figure out how long the remainder is
            int len = frg.Text.Length - i;

            if (paraPos + len > paraWidth)
            {
            // First, look for a whitespace break
            len = paraWidth - paraPos;
            while ((len > 0) && !Char.IsWhiteSpace(frg.Text[i + len]))
            len--;

            // If there is a whitespace break that *could* fit
            // within paraWidth, do a line break and try again.
            if (len <= 0)
            {
            int t = 0;

            while ((t < paraWidth) && (i + t < frg.Text.Length) &&
                !Char.IsWhiteSpace(frg.Text[i + t]))
                t++;

            if (t < paraWidth)
            {
                consumer.PushFragment(new Fragment() {
                Attr = Fragment.Attributes.NewLine
                });

                paraPos = 0;
                continue;
            }

            // If that didn't work, just do a hard break.
            len = paraWidth - paraPos;
            hardBreak = true;
            }
            }

            // Send this part of the fragment
            Fragment part;

            part.Attr = frg.Attr |
            (hardBreak ? Fragment.Attributes.DoNotCount : 0);
            part.Linkref = frg.Linkref;
            part.Text = frg.Text.Substring(i, len);
            consumer.PushFragment(part);

            paraPos += len;
            i += len;

            if (hardBreak)
            {
            consumer.PushFragment(new Fragment() {
            Attr = Fragment.Attributes.NewLine
            });
            paraPos = 0;
            }
            }
        }
Beispiel #7
0
        public void PushFragment(Fragment frg)
        {
            if (frg.Linkref != null)
            frg.Linkref = EPath.RelPath(basePath, frg.Linkref);

            next.PushFragment(frg);
        }
Beispiel #8
0
        public void PushFragment(Fragment frg)
        {
            if (((frg.Attr & Fragment.Attributes.Formatter) != 0) ||
            (paraWidth <= 0))
            {
            if (frg.Attr == Fragment.Attributes.NewLine)
            paraPos = 0;

            consumer.PushFragment(frg);
            } else if ((frg.Text != null) && (frg.Text.Length > 0)) {
            SendChunks(frg);
            }
        }
Beispiel #9
0
        public void PushFragment(Fragment frg)
        {
            if ((frg.Attr & Fragment.Attributes.Formatter) != 0)
            {
            FlushFragment();
            consumer.PushFragment(frg);
            }
            else
            {
            if ((frg.Linkref != lastLinkref) || (frg.Attr != lastAttr))
            FlushFragment();

            lastAttr = frg.Attr;
            lastLinkref = frg.Linkref;

            if (isPreformatted)
            PreText(frg.Text);
            else
            NormalText(frg.Text);
            }
        }
Beispiel #10
0
        public void PushFragment(Fragment frg)
        {
            if (frg.Attr == Fragment.Attributes.AnchorName)
            frg.Text = basePath + frg.Text;

            next.PushFragment(frg);
        }
Beispiel #11
0
        void SendIndent()
        {
            if (paraIndent > 0)
            {
            Fragment id = new Fragment();

            if (paraPrefix != null)
            {
            id.Text = paraPrefix + ' ';
            paraPrefix = null;

            if (id.Text.Length < paraIndent)
            id.Text = new string(' ',
                paraIndent - id.Text.Length) + id.Text;
            }
            else
            id.Text = new string(' ', paraIndent);

            id.Attr = Fragment.Attributes.DoNotCount;
            consumer.PushFragment(id);
            }
        }
Beispiel #12
0
        public void PushFragment(Fragment frg)
        {
            if ((frg.Attr & Fragment.Attributes.Formatter) != 0)
            {
            if (frg.Attr == Fragment.Attributes.NewLine)
            lineEmpty = true;

            consumer.PushFragment(frg);
            } else {
            if (lineEmpty)
            SendIndent();

            consumer.PushFragment(frg);
            lineEmpty = false;
            }

            blockEmpty = false;
        }