示例#1
0
        /// <summary>
        /// Process one font
        /// </summary>
        /// <param name="item"></param>
        private void _ProcessRtfBlockFontOne(Parsing.ParsedItem item)
        {   // for example: \f0\fswiss\fcharset238{\*\fname Arial;}Arial CE;
            //              \f2\fmodern\fprq1\fcharset0 Envy Code R;
            if (!item.HasItems)
            {
                return;
            }
            RtfFont rtfFont = new RtfFont();

            for (int index = 0; index < item.ItemCount; index++)
            {
                Parsing.ParsedItem          subItem  = item.Items[index];
                Parsing.IParsedItemExtended eSubItem = subItem as Parsing.IParsedItemExtended;
                if (subItem.HasItems)
                {
                    if (index == 0)
                    {                                 // Font number in table:
                        rtfFont.Key = item.TextInner; // f2
                    }
                    else
                    {
                        string rtfValue;
                        string rtfEntity = GetRtfEntityFirst(subItem, out rtfValue);     // "fswiss", "fcharset"+"238",
                        switch (rtfEntity)
                        {
                        case "fswiss":
                        case "fmodern":
                        case "fnil":
                            rtfFont.Family = rtfEntity;
                            break;

                        case "fprq":
                            break;

                        case "fcharset":
                            rtfFont.CharSet = rtfValue;
                            this._ProcessRtfBlockFontName(item, ref index, rtfFont);
                            break;

                        default:
                            this._ProcessAddRtfError("FontItem", rtfEntity);
                            break;
                        }
                    }
                }
            }

            if (rtfFont.IsValid)
            {
                if (this._Fonts.ContainsKey(rtfFont.Key))
                {
                    this._Fonts[rtfFont.Key] = rtfFont;
                }
                else
                {
                    this._Fonts.Add(rtfFont.Key, rtfFont);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Analyzuje parsovaný RTF text
        /// </summary>
        /// <param name="rootItem"></param>
        private void _ProcessRtfDocument(Parsing.ParsedItem rootItem)
        {
            if (rootItem == null || rootItem.ItemCount <= 0)
            {
                return;
            }

            foreach (Parsing.ParsedItem item in rootItem.Items)
            {
                switch (item.ItemType)
                {
                case Data.Parsing.ItemType.None:
                case Data.Parsing.ItemType.Blank:
                    break;

                case Data.Parsing.ItemType.Text:
                    this._ProcessRtfText(item);
                    break;

                case Data.Parsing.ItemType.Delimiter:
                    break;

                case Data.Parsing.ItemType.Array:
                    if (item.HasItems)
                    {
                        switch (item.SegmentName)
                        {
                        case Parsing.DefaultSettings.RTF_ENTITY:
                            this._ProcessRtfEntity(item);
                            break;

                        case Parsing.DefaultSettings.RTF_BLOCK:
                            this._ProcessRtfBlock(item);
                            break;

                        case Parsing.DefaultSettings.RTF_CHAR2:
                            this._ProcessRtfChar2(item);
                            break;

                        case Parsing.DefaultSettings.RTF_CHARUNICODE:
                            this._ProcessRtfCharUnicode(item);
                            break;

                        default:
                            this._ProcessAddRtfError("Segment", item.SegmentName);
                            break;
                        }
                    }
                    break;

                default:
                    this._ProcessAddRtfError("ItemType", item.ItemType.ToString());
                    break;
                }
            }
        }
示例#3
0
        /// <summary>
        /// Načte a analyzuje dodaný RTF text
        /// </summary>
        private void _LoadRtfText()
        {
            if (String.IsNullOrEmpty(this._RtfText))
            {
                return;
            }

            Parsing.ParsedItem rootItem = Parsing.Parser.ParseString(this._RtfText, Parsing.DefaultSettings.Rtf);
            this._ProcessRtfDocument(rootItem);
        }
示例#4
0
        /// <summary>
        /// Vrátí RTF text obsahující syntakticky zpracovaný vstupující holý text
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        private string RtfTextGetSyntaxColor(string text)
        {
            Parsing.Setting setting = this.ParserSetting;

            System.Diagnostics.Stopwatch sw      = System.Diagnostics.Stopwatch.StartNew();
            Parsing.ParsedItem           segment = Parsing.Parser.ParseString(text, setting);
            this.LastParsingTime = (decimal)sw.ElapsedTicks / (decimal)System.Diagnostics.Stopwatch.Frequency;
            this.EditorSegment   = segment;                // Tady se vyvolá event EditorSegmentsChangedBefore i EditorSegmentsChangedAfter. Pokud je na this editor napojen GuiTreeView, pak nyní dojde k jeho přenačtení...
            return(((Parsing.IParsedItemExtended)segment).RtfText);
        }
示例#5
0
 /// <summary>
 /// Find and return parsed segment for RTF document.
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 private Parsing.ParsedItem _GetMainRtfSegment(Parsing.ParsedItem item)
 {
     Parsing.ParsedItem rtfItem = null;
     if (item.SegmentName == Parsing.DefaultSettings.RTF_NONE && item.HasItems)
     {
         rtfItem = item;
     }
     else if (item.HasItems && item.Items[0].SegmentName == Parsing.DefaultSettings.RTF_NONE && item.Items[0].HasItems)
     {
         rtfItem = item.Items[0];
     }
     return(rtfItem);
 }
示例#6
0
 private static Parsing.ParsedItem GetFirstParserValue(Parsing.ParsedItem item)
 {
     // Search for First-First-First-... value:
     Parsing.ParsedItem scanItem = item;
     while (true)
     {
         if (!scanItem.HasItems)
         {
             break;
         }
         scanItem = scanItem.Items[0];
     }
     return(scanItem);
 }
示例#7
0
 /// <summary>
 /// Process font name
 /// </summary>
 /// <param name="item"></param>
 /// <param name="index"></param>
 /// <param name="rtfFont"></param>
 private void _ProcessRtfBlockFontName(Parsing.ParsedItem item, ref int index, RtfFont rtfFont)
 {
     index++;
     while (index < item.ItemCount)
     {
         Parsing.ParsedItem subItem = item.Items[index];
         index++;
         if (subItem.ItemType == Data.Parsing.ItemType.Text)
         {
             rtfFont.Name = subItem.Text.TrimEnd(';', ' ');
             break;
         }
     }
 }
示例#8
0
        private void _AfterSelectNode(TreeNode treeNode)
        {
            Parsing.ParsedItem item = treeNode.Tag as Parsing.ParsedItem;
            if (item == null)
            {
                return;
            }
            Parsing.IParsedItemExtended eItem = item as Parsing.IParsedItemExtended;

            int begin = eItem.BeginPointer;
            int end   = eItem.EndPointer;

            this._ParserEditor.SelectRange(begin, end - begin, true);
        }
示例#9
0
        private void _ProcessRtfBlockFColor(Parsing.ParsedItem item)
        {   // For example:   {\colortbl ;\red255\green0\blue0;\red0\green128\blue0;\red0\green0\blue255;}
            int colorIndex = 0;
            int index      = 2;
            int count      = item.ItemCount;

            while (index < count)
            {
                if ((index + 2) >= count)
                {
                    break;
                }
                this._ProcessRtfBlockFColorOne(item, ref index, ref colorIndex);
            }
        }
示例#10
0
        private bool _ProcessRtfBlockFColorValue(Parsing.ParsedItem item, ref int index, string name, out int value)
        {
            value = 0;
            string rtfEntity, rtfValue;

            rtfEntity = GetRtfEntity(item.Items[index++], out rtfValue);     // "", "red"+"255",
            if (rtfEntity != name)
            {
                return(false);
            }
            if (!Int32.TryParse(rtfValue, out value))
            {
                return(false);
            }
            return(value >= 0 && value <= 255);
        }
示例#11
0
 /// <summary>
 /// Process FontTable (=all fonts) from segment (parameter)
 /// </summary>
 /// <param name="item"></param>
 private void _ProcessRtfBlockFontTable(Parsing.ParsedItem item)
 {   // for example:  \fonttbl{\f0\fswiss\fcharset238{\*\fname Arial;}Arial CE;}{\f1\fmodern\fprq1\fcharset238 Envy Code R;}...{\f6\fnil\fcharset2 Symbol;}
     //               \fonttbl{\f0\fswiss\fcharset238{\*\fname Arial;}Arial CE;}{\f1\fmodern\fprq1\fcharset238 Envy Code R;}{\f2\fmodern\fprq1\fcharset0 Envy Code R;}{\f3\fnil\fprq2\fcharset238 Gentium Basic;}{\f4\fnil\fprq2\fcharset0 Gentium Basic;}{\f5\fnil\fcharset0 ;}{\f6\fnil\fcharset2 Symbol;}
     if (item.ItemCount < 1)
     {
         return;
     }
     for (int i = 1 /* Skip index [0], contains value with keyword "fonttbl" ! */; i < item.ItemCount; i++)
     {
         Parsing.ParsedItem subItem = item.Items[i];
         if (subItem.HasItems)
         {
             this._ProcessRtfBlockFontOne(subItem);
         }
     }
 }
示例#12
0
        private static string GetRtfEntity(Parsing.ParsedItem item, out string rtfValue)
        {
            rtfValue = "";
            if (item == null)
            {
                return("");
            }
            string rtfEntity  = item.Text;
            int    firstValue = rtfEntity.IndexOfAny(ValuesArrayNumSpace);

            if (firstValue > 0)
            {
                rtfValue  = rtfEntity.Substring(firstValue);
                rtfEntity = rtfEntity.Substring(0, firstValue);
            }
            return(rtfEntity);
        }
示例#13
0
        /// <summary>
        /// Zaháčkuje/Odháčkuje this handler _EditorSegmentsChangedAfter do eventu editor.EditorSegmentsChangedAfter.
        /// Převezme segmenty které jsou aktuálně platné v editoru (nebo své segmenty nuluje).
        /// </summary>
        /// <param name="editor"></param>
        /// <param name="link"></param>
        private void _LinkEditor(SyntaxEditorPanel editor, bool link)
        {
            if (editor == null)
            {
                return;
            }

            if (link)
            {
                editor.EditorSegmentsChangedAfter += _EditorSegmentsChangedAfter;
                this.EditorSegment = editor.EditorSegment;
            }
            else
            {
                editor.EditorSegmentsChangedAfter -= _EditorSegmentsChangedAfter;
                this.EditorSegment = null;
            }
        }
示例#14
0
        private void _ProcessRtfEntity(Parsing.ParsedItem item)
        {
            if (!item.HasItems)
            {
                return;
            }
            foreach (Parsing.ParsedItem subItem in item.Items)
            {
                string rtfValue;
                string rtfEntity = GetRtfEntity(subItem, out rtfValue);
                switch (rtfEntity)
                {
                case "viewkind":


                    break;
                }
            }
        }
示例#15
0
        private void _ProcessRtfBlockFColorOne(Parsing.ParsedItem item, ref int index, ref int colorIndex)
        {
            int r, g, b;

            if (!this._ProcessRtfBlockFColorValue(item, ref index, "red", out r))
            {
                return;
            }
            if (!this._ProcessRtfBlockFColorValue(item, ref index, "green", out g))
            {
                return;
            }
            if (!this._ProcessRtfBlockFColorValue(item, ref index, "blue", out b))
            {
                return;
            }

            RtfColor rtfColor = new RtfColor();

            rtfColor.Key   = (++colorIndex).ToString();
            rtfColor.Color = Color.FromArgb(255, r, g, b);
            this._Colors.Add(rtfColor.Key, rtfColor);
        }
示例#16
0
        private void _ProcessRtfBlock(Parsing.ParsedItem item)
        {
            if (!item.HasItems)
            {
                return;
            }
            string rtfEntity = GetRtfEntityFirst(item);

            switch (rtfEntity)
            {
            case "fonttbl":
                this._ProcessRtfBlockFontTable(item);
                break;

            case "colortbl":
                this._ProcessRtfBlockFColor(item);
                break;

            default:
                this._ProcessAddRtfError("Block", rtfEntity);
                break;
            }
        }
示例#17
0
        /// <summary>
        /// Úkolem této metody je:
        ///  - vepsat data z daného prvku <see cref="Parsing.ParsedItem"/> do doadného nodu stromu <see cref="TreeNode"/>;
        ///  - pokud daný prvek obsahuje vnořené prvky, pak je projít; pro každý prvek vytvořit nový sub-node a zařadit jej do do daného node;
        ///  - a rekurzivně zavolat tuto metodu pro vnořený prvek a sub-node.
        /// projít všechny vnořené prvky daného parsovaného prvku (item), a tyto prvky přímo vložit kolekce daného nodu.
        /// Pokud některý prvek obsahuje sub-prvky, pak rekurzivně zavolat tuto metodu, předat jí prvek, a odpovídající kolekci subnodů.
        /// </summary>
        /// <param name="item">Zdroj dat = parsovaný prvek</param>
        /// <param name="node">Cíl dat = prvek TreeNode</param>
        /// <param name="addBlank">Vkládat i Blank prvky</param>
        /// <param name="addComment">Vkládat i komentáře a další nerelevantní prvky</param>
        private static void _TreeFillOne(Parsing.ParsedItem item, TreeNode node, bool addBlank, bool addComment)
        {
            if (item == null)
            {
                return;
            }

            Parsing.IParsedItemExtended eItem = item as Parsing.IParsedItemExtended;

            node.Text        = item.Text;
            node.ToolTipText = item.ItemType.ToString() + "; " + eItem.Setting.SegmentName;
            node.Tag         = item;

            if (!item.HasItems)
            {
                return;
            }

            foreach (Parsing.ParsedItem subItem in item.Items)
            {
                Parsing.IParsedItemExtended eSubItem = subItem as Parsing.IParsedItemExtended;

                if (eSubItem.IsComment && !addComment)
                {
                    continue;
                }
                if (!eSubItem.IsRelevant && !addBlank)
                {
                    continue;
                }

                TreeNode subNode = new TreeNode();
                node.Nodes.Add(subNode);

                _TreeFillOne(subItem, subNode, addBlank, addComment);
            }
        }
示例#18
0
 private void _EditorSegmentsChangedAfter(object sender, EventArgs e)
 {
     this.EditorSegment = (this._ParserEditor == null ? null : this._ParserEditor.EditorSegment);
 }
示例#19
0
        /// <summary>
        /// Split value (for example: "charset238") to name ("charset") and numeric value ("238").
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        private static string GetRtfEntity(Parsing.ParsedItem item)
        {
            string rtfValue;

            return(GetRtfEntity(item, out rtfValue));
        }
示例#20
0
 private static string GetRtfEntityFirst(Parsing.ParsedItem item, out string rtfValue)
 {
     Parsing.ParsedItem foundValue = GetFirstParserValue(item);
     return(GetRtfEntity(foundValue, out rtfValue));
 }
示例#21
0
 /// <summary>
 /// Zpracuje textový obsah prvku
 /// </summary>
 /// <param name="item"></param>
 private void _ProcessRtfText(Parsing.ParsedItem item)
 {
 }
示例#22
0
 private void _ProcessRtfCharUnicode(Parsing.ParsedItem parserSegment)
 {
 }