A color used for highlighting
Exemplo n.º 1
0
        public HighlightColor GetColorFor(string name)
        {
            switch (name)
            {
                case "String":
                    return new HighlightColor(Color.FromArgb(163, 21, 21), false, false);

                case "RuleName":
                    return new HighlightColor(Color.FromArgb(43, 145, 175), false, false);

                case "Keyword":
                    return new HighlightColor(Color.Blue, false, false);

                case "Comment":
                    return new HighlightColor(Color.DarkGreen, false, false);
            }

            HighlightColor color;
            if (name == null || !this.environmentColors.TryGetValue(name, out color))
            {
                color = new HighlightColor(SystemColors.WindowText, false, false);
            }

            return color;
        }
		/// <summary>
		/// Creates a new instance of <see cref="PrevMarker"/>
		/// </summary>
		public PrevMarker(XmlElement mark)
		{
			color = new HighlightColor(mark);
			what  = mark.InnerText;
			if (mark.Attributes["markmarker"] != null) {
				markMarker = Boolean.Parse(mark.Attributes["markmarker"].InnerText);
			}
		}
        public DefaultHighlightingStrategy(string name)
        {
            Name = name;
            Folding = "";
            Properties = new Dictionary<string, string>();
            Rules = new List<HighlightRuleSet>();

            DigitColor = new HighlightColor(SystemColors.WindowText, false, false);
            DefaultTextColor = new HighlightColor(SystemColors.WindowText, false, false);
        }
		protected void ImportSettingsFrom(DefaultHighlightingStrategy source)
		{
			if (source == null)
				throw new ArgumentNullException("source");
			properties = source.properties;
			extensions = source.extensions;
			digitColor = source.digitColor;
			defaultRuleSet = source.defaultRuleSet;
			name = source.name;
			rules = source.rules;
			environmentColors = source.environmentColors;
			defaultTextColor = source.defaultTextColor;
		}
 protected void ImportSettingsFrom(DefaultHighlightingStrategy source)
 {
     if (source == null)
         throw new ArgumentNullException("source");
     Properties = source.Properties;
     Extensions = source.Extensions;
     DigitColor = source.DigitColor;
     defaultRuleSet = source.defaultRuleSet;
     Name = source.Name;
     Folding = source.Folding;
     Rules = source.Rules;
     DefaultTextColor = source.DefaultTextColor;
 }
Exemplo n.º 6
0
 // TAB
 public TextWord(IDocument document, LineSegment line, int offset, int length, HighlightColor color, bool hasDefaultColor)
 {
     if (document == null || line == null || color == null)
         throw new Exception();
     /*Debug.Assert(document != null);
     Debug.Assert(line != null);
     Debug.Assert(color != null);
     */
     this.document = document;
     this.line  = line;
     this.offset = offset;
     this.length = length;
     this.color = color;
     this.hasDefaultColor = hasDefaultColor;
 }
Exemplo n.º 7
0
        /// <summary>
        /// Creates a new instance of <see cref="HighlightColor"/>
        /// </summary>
        public HighlightColor(XmlElement el, HighlightColor defaultColor)
        {
            Debug.Assert(el != null, "ICSharpCode.TextEditor.Document.SyntaxColor(XmlElement el) : el == null");
            if (el.Attributes["bold"] != null) {
                bold = Boolean.Parse(el.Attributes["bold"].InnerText);
            } else {
                bold = defaultColor.Bold;
            }

            if (el.Attributes["italic"] != null) {
                italic = Boolean.Parse(el.Attributes["italic"].InnerText);
            } else {
                italic = defaultColor.Italic;
            }

            if (el.Attributes["color"] != null) {
                string c = el.Attributes["color"].InnerText;
                if (c[0] == '#') {
                    color = ParseColor(c);
                } else if (c.StartsWith("SystemColors.")) {
                    color = ParseColorString(c.Substring("SystemColors.".Length));
                } else {
                    color = (Color)(Color.GetType()).InvokeMember(c, BindingFlags.GetProperty, null, Color, new object[0]);
                }
                hasForeground = true;
            } else {
                color = defaultColor.color;
            }

            if (el.Attributes["bgcolor"] != null) {
                string c = el.Attributes["bgcolor"].InnerText;
                if (c[0] == '#') {
                    backgroundcolor = ParseColor(c);
                } else if (c.StartsWith("SystemColors.")) {
                    backgroundcolor = ParseColorString(c.Substring("SystemColors.".Length));
                } else {
                    backgroundcolor = (Color)(Color.GetType()).InvokeMember(c, BindingFlags.GetProperty, null, Color, new object[0]);
                }
                hasBackground = true;
            } else {
                backgroundcolor = defaultColor.BackgroundColor;
            }
        }
Exemplo n.º 8
0
		public DefaultHighlightingStrategy(string name) 
		{
			this.name = name;
			
			digitColor      = new HighlightBackground("WindowText", "Window", false, false);
			
			// set small 'default color environment'
			environmentColors["DefaultBackground"]= new HighlightBackground("WindowText", "Window", false, false);
			environmentColors["Selection"]        = new HighlightColor("HighlightText", "Highlight", false, false);
			environmentColors["VRuler"]           = new HighlightColor("ControlLight", "Window", false, false);
			environmentColors["InvalidLines"]     = new HighlightColor(Color.Red, false, false);
			environmentColors["CaretMarker"]      = new HighlightColor(Color.Yellow, false, false);
			environmentColors["LineNumbers"]      = new HighlightBackground("ControlDark", "Window", false, false);
			
			environmentColors["FoldLine"]         = new HighlightColor(Color.FromArgb(0x80, 0x80, 0x80), Color.Black, false, false);
			environmentColors["FoldMarker"]       = new HighlightColor(Color.FromArgb(0x80, 0x80, 0x80), Color.White, false, false);
			environmentColors["SelectedFoldLine"] = new HighlightColor(Color.Black, false, false);
			environmentColors["EOLMarkers"]       = new HighlightColor("ControlLight", "Window", false, false);
			environmentColors["SpaceMarkers"]     = new HighlightColor("ControlLight", "Window", false, false);
			environmentColors["TabMarkers"]       = new HighlightColor("ControlLight", "Window", false, false);
			
		}
Exemplo n.º 9
0
        public Span(XmlElement span)
        {
            color   = new HighlightColor(span);

            if (span.HasAttribute("rule")) {
                rule = span.GetAttribute("rule");
            }

            if (span.HasAttribute("escapecharacter")) {
                escapeCharacter = span.GetAttribute("escapecharacter")[0];
            }

            name = span.GetAttribute("name");
            if (span.HasAttribute("stopateol")) {
                stopEOL = Boolean.Parse(span.GetAttribute("stopateol"));
            }

            begin   = span["Begin"].InnerText.ToCharArray();
            beginColor = new HighlightColor(span["Begin"], color);

            if (span["Begin"].HasAttribute("singleword")) {
                this.isBeginSingleWord = Boolean.Parse(span["Begin"].GetAttribute("singleword"));
            }
            if (span["Begin"].HasAttribute("startofline")) {
                this.isBeginStartOfLine = Boolean.Parse(span["Begin"].GetAttribute("startofline"));
            }

            if (span["End"] != null) {
                end  = span["End"].InnerText.ToCharArray();
                endColor = new HighlightColor(span["End"], color);
                if (span["End"].HasAttribute("singleword")) {
                    this.isEndSingleWord = Boolean.Parse(span["End"].GetAttribute("singleword"));
                }

            }
        }
Exemplo n.º 10
0
        private void InitHighlighting()
        {
            string dir = Path.Combine(Application.StartupPath, @"Highlighting\");
            if (Directory.Exists(dir))
            {
                var fsmProvider = new FileSyntaxModeProvider(dir);
                HighlightingManager.Manager.AddSyntaxModeFileProvider(fsmProvider);
                textEditorControl1.SetHighlighting("Scrape");
            }

            _executionHighlight = new HighlightColor(Color.Black, Color.Yellow, false, false);
            var highlightingStrategy = textEditorControl1.Document.HighlightingStrategy as DefaultHighlightingStrategy;
            _defaultHighlight = highlightingStrategy.GetColorFor("Selection");
        }
        /// <summary>
        /// pushes the curWord string on the word list, with the
        /// correct color.
        /// </summary>
        void PushCurWord(IDocument document, ref HighlightColor markNext, List <TextWord> words)
        {
            // Svante Lidman : Need to look through the next prev logic.
            if (currentLength > 0)
            {
                if (words.Count > 0 && activeRuleSet != null)
                {
                    TextWord prevWord = null;
                    int      pInd     = words.Count - 1;
                    while (pInd >= 0)
                    {
                        if (!((TextWord)words[pInd]).IsWhiteSpace)
                        {
                            prevWord = (TextWord)words[pInd];
                            if (prevWord.HasDefaultColor)
                            {
                                PrevMarker marker = (PrevMarker)activeRuleSet.PrevMarkers[document, currentLine, currentOffset, currentLength];
                                if (marker != null)
                                {
                                    prevWord.SyntaxColor = marker.Color;
//									document.Caret.ValidateCaretPos();
//									document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, document.GetLineNumberForOffset(document.Caret.Offset)));
                                }
                            }
                            break;
                        }
                        pInd--;
                    }
                }

                if (inSpan)
                {
                    HighlightColor c = null;
                    bool           hasDefaultColor = true;
                    if (activeSpan.Rule == null)
                    {
                        c = activeSpan.Color;
                    }
                    else
                    {
                        c = GetColor(activeRuleSet, document, currentLine, currentOffset, currentLength);
                        hasDefaultColor = false;
                    }

                    if (c == null)
                    {
                        c = activeSpan.Color;
                        if (c.Color == Color.Transparent)
                        {
                            c = this.DefaultTextColor;
                        }
                        hasDefaultColor = true;
                    }
                    words.Add(new TextWord(document, currentLine, currentOffset, currentLength, markNext != null ? markNext : c, hasDefaultColor));
                }
                else
                {
                    HighlightColor c = markNext != null ? markNext : GetColor(activeRuleSet, document, currentLine, currentOffset, currentLength);
                    if (c == null)
                    {
                        words.Add(new TextWord(document, currentLine, currentOffset, currentLength, this.DefaultTextColor, true));
                    }
                    else
                    {
                        words.Add(new TextWord(document, currentLine, currentOffset, currentLength, c, false));
                    }
                }

                if (activeRuleSet != null)
                {
                    NextMarker nextMarker = (NextMarker)activeRuleSet.NextMarkers[document, currentLine, currentOffset, currentLength];
                    if (nextMarker != null)
                    {
                        if (nextMarker.MarkMarker && words.Count > 0)
                        {
                            TextWord prevword = ((TextWord)words[words.Count - 1]);
                            prevword.SyntaxColor = nextMarker.Color;
                        }
                        markNext = nextMarker.Color;
                    }
                    else
                    {
                        markNext = null;
                    }
                }
                currentOffset += currentLength;
                currentLength  = 0;
            }
        }
Exemplo n.º 12
0
		// TAB
		public TextWord(IDocument document, LineSegment line, int offset, int length, HighlightColor color, bool hasDefaultColor)
		{
			Debug.Assert(document != null);
			Debug.Assert(line != null);
			Debug.Assert(color != null);
			
			this.document = document;
			this.line  = line;
			this.offset = offset;
			this.length = length;
			this.color = color;
			this.hasDefaultColor = hasDefaultColor;
		}
Exemplo n.º 13
0
        // TAB
        public TextWord(IDocument document, LineSegment line, int offset, int length, HighlightColor color, bool hasDefaultColor)
        {
            Debug.Assert(document != null);
            Debug.Assert(line != null);
            Debug.Assert(color != null);

            this.document = document;
            this.line = line;
            Offset = offset;
            Length = length;
            this.color = color;
            HasDefaultColor = hasDefaultColor;
        }
Exemplo n.º 14
0
        /// <summary>
        /// Creates a new instance of <see cref="HighlightColor"/>
        /// </summary>
        public HighlightColor(XmlElement el, HighlightColor defaultColor)
        {
            Debug.Assert(el != null, "ICSharpCode.TextEditor.Document.SyntaxColor(XmlElement el) : el == null");
            if (el.Attributes["bold"] != null)
            {
                bold = Boolean.Parse(el.Attributes["bold"].InnerText);
            }
            else
            {
                bold = defaultColor.Bold;
            }

            if (el.Attributes["italic"] != null)
            {
                italic = Boolean.Parse(el.Attributes["italic"].InnerText);
            }
            else
            {
                italic = defaultColor.Italic;
            }

            if (el.Attributes["color"] != null)
            {
                string c = el.Attributes["color"].InnerText;
                if (c[0] == '#')
                {
                    color = ParseColor(c);
                }
                else if (c.StartsWith("SystemColors."))
                {
                    systemColor     = true;
                    systemColorName = c.Substring("SystemColors.".Length);
                }
                else
                {
                    color = (Color)(Color.GetType()).InvokeMember(c, BindingFlags.GetProperty, null, Color, new object[0]);
                }
                hasForgeground = true;
            }
            else
            {
                color = defaultColor.color;
            }

            if (el.Attributes["bgcolor"] != null)
            {
                string c = el.Attributes["bgcolor"].InnerText;
                if (c[0] == '#')
                {
                    backgroundcolor = ParseColor(c);
                }
                else if (c.StartsWith("SystemColors."))
                {
                    systemBgColor     = true;
                    systemBgColorName = c.Substring("SystemColors.".Length);
                }
                else
                {
                    backgroundcolor = (Color)(Color.GetType()).InvokeMember(c, BindingFlags.GetProperty, null, Color, new object[0]);
                }
                hasBackground = true;
            }
            else
            {
                backgroundcolor = defaultColor.BackgroundColor;
            }
        }
Exemplo n.º 15
0
        public HighlightRuleSet(XmlElement el)
        {
            XmlNodeList nodes;

            if (el.Attributes["name"] != null)
            {
                Name = el.Attributes["name"].InnerText;
            }

            if (el.HasAttribute("escapecharacter"))
            {
                EscapeCharacter = el.GetAttribute("escapecharacter")[0];
            }

            if (el.Attributes["reference"] != null)
            {
                Reference = el.Attributes["reference"].InnerText;
            }

            if (el.Attributes["ignorecase"] != null)
            {
                IgnoreCase = Boolean.Parse(el.Attributes["ignorecase"].InnerText);
            }

            for (int i = 0; i < Delimiters.Length; ++i)
            {
                Delimiters[i] = false;
            }

            if (el["Delimiters"] != null)
            {
                string delimiterString = el["Delimiters"].InnerText;
                foreach (char ch in delimiterString)
                {
                    Delimiters[(int)ch] = true;
                }
            }

//			Spans       = new LookupTable(!IgnoreCase);

            KeyWords    = new LookupTable(!IgnoreCase);
            PrevMarkers = new LookupTable(!IgnoreCase);
            NextMarkers = new LookupTable(!IgnoreCase);

            nodes = el.GetElementsByTagName("KeyWords");
            foreach (XmlElement el2 in nodes)
            {
                HighlightColor color = new HighlightColor(el2);

                XmlNodeList keys = el2.GetElementsByTagName("Key");
                foreach (XmlElement node in keys)
                {
                    KeyWords[node.Attributes["word"].InnerText] = color;
                }
            }

            nodes = el.GetElementsByTagName("Span");
            foreach (XmlElement el2 in nodes)
            {
                Spans.Add(new Span(el2));

                /*
                 * Span span = new Span(el2);
                 * Spans[span.Begin] = span;*/
            }

            nodes = el.GetElementsByTagName("MarkPrevious");
            foreach (XmlElement el2 in nodes)
            {
                AdjacentMarker prev = new AdjacentMarker(el2);
                PrevMarkers[prev.What] = prev;
            }

            nodes = el.GetElementsByTagName("MarkFollowing");
            foreach (XmlElement el2 in nodes)
            {
                AdjacentMarker next = new AdjacentMarker(el2);
                NextMarkers[next.What] = next;
            }
        }
		public HighlightRuleSet(XmlElement el)
		{
			XmlNodeList nodes;
			
			if (el.Attributes["name"] != null) {
				Name = el.Attributes["name"].InnerText;
			}
			
			if (el.HasAttribute("escapecharacter")) {
				escapeCharacter = el.GetAttribute("escapecharacter")[0];
			}
			
			if (el.Attributes["reference"] != null) {
				reference = el.Attributes["reference"].InnerText;
			}
			
			if (el.Attributes["ignorecase"] != null) {
				ignoreCase  = Boolean.Parse(el.Attributes["ignorecase"].InnerText);
			}
			
			for (int i  = 0; i < Delimiters.Length; ++i) {
				delimiters[i] = false;
			}
			
			if (el["Delimiters"] != null) {
				string delimiterString = el["Delimiters"].InnerText;
				foreach (char ch in delimiterString) {
					delimiters[(int)ch] = true;
				}
			}
			
//			Spans       = new LookupTable(!IgnoreCase);

			keyWords    = new LookupTable(!IgnoreCase);
			prevMarkers = new LookupTable(!IgnoreCase);
			nextMarkers = new LookupTable(!IgnoreCase);
			
			nodes = el.GetElementsByTagName("KeyWords");
			foreach (XmlElement el2 in nodes) {
				HighlightColor color = new HighlightColor(el2);
				
				XmlNodeList keys = el2.GetElementsByTagName("Key");
				foreach (XmlElement node in keys) {
					keyWords[node.Attributes["word"].InnerText] = color;
				}
			}
			
			nodes = el.GetElementsByTagName("Span");
			foreach (XmlElement el2 in nodes) {
				Spans.Add(new Span(el2));
				/*
				Span span = new Span(el2);
				Spans[span.Begin] = span;*/
			}
			
			nodes = el.GetElementsByTagName("MarkPrevious");
			foreach (XmlElement el2 in nodes) {
				PrevMarker prev = new PrevMarker(el2);
				prevMarkers[prev.What] = prev;
			}
			
			nodes = el.GetElementsByTagName("MarkFollowing");
			foreach (XmlElement el2 in nodes) {
				NextMarker next = new NextMarker(el2);
				nextMarkers[next.What] = next;
			}
		}
Exemplo n.º 17
0
			public SpaceTextWord(HighlightColor  color)
			{
				length = 1;
				base.color  = color;
			}
 private void PushCurWord(IDocument document, ref HighlightColor markNext, List <TextWord> words)
 {
     if (this.currentLength > 0)
     {
         if (words.Count > 0 && this.activeRuleSet != null)
         {
             TextWord item  = null;
             int      count = words.Count - 1;
             while (count >= 0)
             {
                 if (words[count].IsWhiteSpace)
                 {
                     count--;
                 }
                 else
                 {
                     item = words[count];
                     if (!item.HasDefaultColor)
                     {
                         break;
                     }
                     PrevMarker prevMarker = (PrevMarker)this.activeRuleSet.PrevMarkers[document, this.currentLine, this.currentOffset, this.currentLength];
                     if (prevMarker == null)
                     {
                         break;
                     }
                     item.SyntaxColor = prevMarker.Color;
                     break;
                 }
             }
         }
         if (!this.inSpan)
         {
             HighlightColor highlightColor = (markNext != null ? markNext : this.GetColor(this.activeRuleSet, document, this.currentLine, this.currentOffset, this.currentLength));
             if (highlightColor != null)
             {
                 words.Add(new TextWord(document, this.currentLine, this.currentOffset, this.currentLength, highlightColor, false));
             }
             else
             {
                 words.Add(new TextWord(document, this.currentLine, this.currentOffset, this.currentLength, this.DefaultTextColor, true));
             }
         }
         else
         {
             HighlightColor color = null;
             bool           flag  = true;
             if (this.activeSpan.Rule != null)
             {
                 color = this.GetColor(this.activeRuleSet, document, this.currentLine, this.currentOffset, this.currentLength);
                 flag  = false;
             }
             else
             {
                 color = this.activeSpan.Color;
             }
             if (color == null)
             {
                 color = this.activeSpan.Color;
                 if (color.Color == Color.Transparent)
                 {
                     color = this.DefaultTextColor;
                 }
                 flag = true;
             }
             words.Add(new TextWord(document, this.currentLine, this.currentOffset, this.currentLength, (markNext != null ? markNext : color), flag));
         }
         if (this.activeRuleSet != null)
         {
             NextMarker nextMarker = (NextMarker)this.activeRuleSet.NextMarkers[document, this.currentLine, this.currentOffset, this.currentLength];
             if (nextMarker == null)
             {
                 markNext = null;
             }
             else
             {
                 if (nextMarker.MarkMarker && words.Count > 0)
                 {
                     TextWord textWord = words[words.Count - 1];
                     textWord.SyntaxColor = nextMarker.Color;
                 }
                 markNext = nextMarker.Color;
             }
         }
         this.currentOffset += this.currentLength;
         this.currentLength  = 0;
     }
 }
        private List <TextWord> ParseLine(IDocument document)
        {
            List <TextWord> textWords      = new List <TextWord>();
            HighlightColor  highlightColor = null;

            this.currentOffset = 0;
            this.currentLength = 0;
            this.UpdateSpanStateVariables();
            int length = this.currentLine.Length;
            int offset = this.currentLine.Offset;

            for (int i = 0; i < length; i++)
            {
                char charAt = document.GetCharAt(offset + i);
                char chr    = charAt;
                switch (chr)
                {
                case '\t':
                {
                    this.PushCurWord(document, ref highlightColor, textWords);
                    if (this.activeSpan == null || !this.activeSpan.Color.HasBackground)
                    {
                        textWords.Add(TextWord.Tab);
                    }
                    else
                    {
                        textWords.Add(new TextWord.TabTextWord(this.activeSpan.Color));
                    }
                    this.currentOffset++;
                    break;
                }

                case '\n':
                case '\r':
                {
                    this.PushCurWord(document, ref highlightColor, textWords);
                    this.currentOffset++;
                    break;
                }

                case '\v':
                case '\f':
                {
                    char escapeCharacter = '\0';
                    if (this.activeSpan != null && this.activeSpan.EscapeCharacter != 0)
                    {
                        escapeCharacter = this.activeSpan.EscapeCharacter;
                    }
                    else if (this.activeRuleSet != null)
                    {
                        escapeCharacter = this.activeRuleSet.EscapeCharacter;
                    }
                    if (escapeCharacter != 0 && escapeCharacter == charAt)
                    {
                        if (this.activeSpan == null || this.activeSpan.End == null || (int)this.activeSpan.End.Length != 1 || escapeCharacter != this.activeSpan.End[0])
                        {
                            this.currentLength++;
                            if (i + 1 < length)
                            {
                                this.currentLength++;
                            }
                            this.PushCurWord(document, ref highlightColor, textWords);
                            i++;
                            break;
                        }
                        else if (i + 1 < length && document.GetCharAt(offset + i + 1) == escapeCharacter)
                        {
                            this.currentLength += 2;
                            this.PushCurWord(document, ref highlightColor, textWords);
                            i++;
                            break;
                        }
                    }
                    if (!this.inSpan && (char.IsDigit(charAt) || charAt == '.' && i + 1 < length && char.IsDigit(document.GetCharAt(offset + i + 1))) && this.currentLength == 0)
                    {
                        bool flag  = false;
                        bool flag1 = false;
                        if (charAt != '0' || i + 1 >= length || char.ToUpper(document.GetCharAt(offset + i + 1)) != 'X')
                        {
                            this.currentLength++;
                            while (i + 1 < length && char.IsDigit(document.GetCharAt(offset + i + 1)))
                            {
                                i++;
                                this.currentLength++;
                            }
                        }
                        else
                        {
                            this.currentLength++;
                            i++;
                            this.currentLength++;
                            flag = true;
                            while (i + 1 < length)
                            {
                                if ("0123456789ABCDEF".IndexOf(char.ToUpper(document.GetCharAt(offset + i + 1))) != -1)
                                {
                                    i++;
                                    this.currentLength++;
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                        if (!flag && i + 1 < length && document.GetCharAt(offset + i + 1) == '.')
                        {
                            flag1 = true;
                            i++;
                            this.currentLength++;
                            while (i + 1 < length && char.IsDigit(document.GetCharAt(offset + i + 1)))
                            {
                                i++;
                                this.currentLength++;
                            }
                        }
                        if (i + 1 < length && char.ToUpper(document.GetCharAt(offset + i + 1)) == 'E')
                        {
                            flag1 = true;
                            i++;
                            this.currentLength++;
                            if (i + 1 < length && (document.GetCharAt(offset + i + 1) == '+' || document.GetCharAt(this.currentLine.Offset + i + 1) == '-'))
                            {
                                i++;
                                this.currentLength++;
                            }
                            while (i + 1 < this.currentLine.Length && char.IsDigit(document.GetCharAt(offset + i + 1)))
                            {
                                i++;
                                this.currentLength++;
                            }
                        }
                        if (i + 1 < this.currentLine.Length)
                        {
                            char upper = char.ToUpper(document.GetCharAt(offset + i + 1));
                            if (upper == 'F' || upper == 'M' || upper == 'D')
                            {
                                flag1 = true;
                                i++;
                                this.currentLength++;
                            }
                        }
                        if (!flag1)
                        {
                            bool flag2 = false;
                            if (i + 1 < length && char.ToUpper(document.GetCharAt(offset + i + 1)) == 'U')
                            {
                                i++;
                                this.currentLength++;
                                flag2 = true;
                            }
                            if (i + 1 < length && char.ToUpper(document.GetCharAt(offset + i + 1)) == 'L')
                            {
                                i++;
                                this.currentLength++;
                                if (!flag2 && i + 1 < length && char.ToUpper(document.GetCharAt(offset + i + 1)) == 'U')
                                {
                                    i++;
                                    this.currentLength++;
                                }
                            }
                        }
                        textWords.Add(new TextWord(document, this.currentLine, this.currentOffset, this.currentLength, this.DigitColor, false));
                        this.currentOffset += this.currentLength;
                        this.currentLength  = 0;
                        break;
                    }
                    else if (!this.inSpan || this.activeSpan.End == null || (int)this.activeSpan.End.Length <= 0 || !DefaultHighlightingStrategy.MatchExpr(this.currentLine, this.activeSpan.End, i, document, this.activeSpan.IgnoreCase))
                    {
                        if (this.activeRuleSet != null)
                        {
                            foreach (Span span in this.activeRuleSet.Spans)
                            {
                                if (span.IsBeginSingleWord && this.currentLength != 0)
                                {
                                    continue;
                                }
                                if (span.IsBeginStartOfLine.HasValue)
                                {
                                    if (span.IsBeginStartOfLine.Value != (this.currentLength != 0 ? false : textWords.TrueForAll((TextWord textWord) => textWord.Type != TextWordType.Word)))
                                    {
                                        continue;
                                    }
                                }
                                if (!DefaultHighlightingStrategy.MatchExpr(this.currentLine, span.Begin, i, document, this.activeRuleSet.IgnoreCase))
                                {
                                    continue;
                                }
                                this.PushCurWord(document, ref highlightColor, textWords);
                                string regString = DefaultHighlightingStrategy.GetRegString(this.currentLine, span.Begin, i, document);
                                if (!this.OverrideSpan(regString, document, textWords, span, ref i))
                                {
                                    this.currentLength += regString.Length;
                                    textWords.Add(new TextWord(document, this.currentLine, this.currentOffset, this.currentLength, span.BeginColor, false));
                                    this.currentOffset += this.currentLength;
                                    this.currentLength  = 0;
                                    i = i + (regString.Length - 1);
                                    if (this.currentSpanStack == null)
                                    {
                                        this.currentSpanStack = new SpanStack();
                                    }
                                    this.currentSpanStack.Push(span);
                                    span.IgnoreCase = this.activeRuleSet.IgnoreCase;
                                    this.UpdateSpanStateVariables();
                                }
                                goto label0;
                            }
                        }
                        if (this.activeRuleSet != null && charAt < 'Ā' && this.activeRuleSet.Delimiters[charAt])
                        {
                            this.PushCurWord(document, ref highlightColor, textWords);
                            if (this.currentOffset + this.currentLength + 1 < this.currentLine.Length)
                            {
                                this.currentLength++;
                                this.PushCurWord(document, ref highlightColor, textWords);
                                break;
                            }
                        }
                        this.currentLength++;
                        break;
                    }
                    else
                    {
                        this.PushCurWord(document, ref highlightColor, textWords);
                        string str = DefaultHighlightingStrategy.GetRegString(this.currentLine, this.activeSpan.End, i, document);
                        this.currentLength += str.Length;
                        textWords.Add(new TextWord(document, this.currentLine, this.currentOffset, this.currentLength, this.activeSpan.EndColor, false));
                        this.currentOffset += this.currentLength;
                        this.currentLength  = 0;
                        i = i + (str.Length - 1);
                        this.currentSpanStack.Pop();
                        this.UpdateSpanStateVariables();
                        break;
                    }
                }

                default:
                {
                    if (chr == ' ')
                    {
                        this.PushCurWord(document, ref highlightColor, textWords);
                        if (this.activeSpan == null || !this.activeSpan.Color.HasBackground)
                        {
                            textWords.Add(TextWord.Space);
                        }
                        else
                        {
                            textWords.Add(new TextWord.SpaceTextWord(this.activeSpan.Color));
                        }
                        this.currentOffset++;
                        break;
                    }
                    else
                    {
                        goto case '\f';
                    }
                }
                }
                label0 :;
            }
            this.PushCurWord(document, ref highlightColor, textWords);
            this.OnParsedLine(document, this.currentLine, textWords);
            return(textWords);
        }
        // TAB
        public TextWord(IDocument document, LineSegment line, int offset, int length, HighlightColor color, bool hasDefaultColor)
        {
            if (document == null || line == null || color == null)
            {
                throw new Exception();
            }

            /*Debug.Assert(document != null);
             * Debug.Assert(line != null);
             * Debug.Assert(color != null);
             */
            this.document        = document;
            this.line            = line;
            this.offset          = offset;
            this.length          = length;
            this.color           = color;
            this.hasDefaultColor = hasDefaultColor;
        }
 public TabTextWord(HighlightColor color)
 {
     length           = 1;
     base.SyntaxColor = color;
 }
        List <TextWord> ParseLine(IDocument document)
        {
            List <TextWord> words    = new List <TextWord>();
            HighlightColor  markNext = null;

            currentOffset = 0;
            currentLength = 0;
            UpdateSpanStateVariables();

            int currentLineLength = currentLine.Length;
            int currentLineOffset = currentLine.Offset;

            for (int i = 0; i < currentLineLength; ++i)
            {
                char ch = document.GetCharAt(currentLineOffset + i);
                switch (ch)
                {
                case '\n':
                case '\r':
                    PushCurWord(document, ref markNext, words);
                    ++currentOffset;
                    break;

                case ' ':
                    PushCurWord(document, ref markNext, words);
                    if (activeSpan != null && activeSpan.Color.HasBackground)
                    {
                        words.Add(new TextWord.SpaceTextWord(activeSpan.Color));
                    }
                    else
                    {
                        words.Add(TextWord.Space);
                    }
                    ++currentOffset;
                    break;

                case '\t':
                    PushCurWord(document, ref markNext, words);
                    if (activeSpan != null && activeSpan.Color.HasBackground)
                    {
                        words.Add(new TextWord.TabTextWord(activeSpan.Color));
                    }
                    else
                    {
                        words.Add(TextWord.Tab);
                    }
                    ++currentOffset;
                    break;

                default:
                {
                    // handle escape characters
                    char escapeCharacter = '\0';
                    if (activeSpan != null && activeSpan.EscapeCharacter != '\0')
                    {
                        escapeCharacter = activeSpan.EscapeCharacter;
                    }
                    else if (activeRuleSet != null)
                    {
                        escapeCharacter = activeRuleSet.EscapeCharacter;
                    }
                    if (escapeCharacter != '\0' && escapeCharacter == ch)
                    {
                        // we found the escape character
                        if (activeSpan != null && activeSpan.End != null && activeSpan.End.Length == 1 &&
                            escapeCharacter == activeSpan.End[0])
                        {
                            // the escape character is a end-doubling escape character
                            // it may count as escape only when the next character is the escape, too
                            if (i + 1 < currentLineLength)
                            {
                                if (document.GetCharAt(currentLineOffset + i + 1) == escapeCharacter)
                                {
                                    currentLength += 2;
                                    PushCurWord(document, ref markNext, words);
                                    ++i;
                                    continue;
                                }
                            }
                        }
                        else
                        {
                            // this is a normal \-style escape
                            ++currentLength;
                            if (i + 1 < currentLineLength)
                            {
                                ++currentLength;
                            }
                            PushCurWord(document, ref markNext, words);
                            ++i;
                            continue;
                        }
                    }

                    // highlight digits
                    if (!inSpan && (Char.IsDigit(ch) || (ch == '.' && i + 1 < currentLineLength && Char.IsDigit(document.GetCharAt(currentLineOffset + i + 1)))) && currentLength == 0)
                    {
                        bool ishex           = false;
                        bool isfloatingpoint = false;

                        if (ch == '0' && i + 1 < currentLineLength && Char.ToUpper(document.GetCharAt(currentLineOffset + i + 1)) == 'X')                                           // hex digits
                        {
                            const string hex = "0123456789ABCDEF";
                            ++currentLength;
                            ++i;                                             // skip 'x'
                            ++currentLength;
                            ishex = true;
                            while (i + 1 < currentLineLength && hex.IndexOf(Char.ToUpper(document.GetCharAt(currentLineOffset + i + 1))) != -1)
                            {
                                ++i;
                                ++currentLength;
                            }
                        }
                        else
                        {
                            ++currentLength;
                            while (i + 1 < currentLineLength && Char.IsDigit(document.GetCharAt(currentLineOffset + i + 1)))
                            {
                                ++i;
                                ++currentLength;
                            }
                        }
                        if (!ishex && i + 1 < currentLineLength && document.GetCharAt(currentLineOffset + i + 1) == '.')
                        {
                            isfloatingpoint = true;
                            ++i;
                            ++currentLength;
                            while (i + 1 < currentLineLength && Char.IsDigit(document.GetCharAt(currentLineOffset + i + 1)))
                            {
                                ++i;
                                ++currentLength;
                            }
                        }

                        if (i + 1 < currentLineLength && Char.ToUpper(document.GetCharAt(currentLineOffset + i + 1)) == 'E')
                        {
                            isfloatingpoint = true;
                            ++i;
                            ++currentLength;
                            if (i + 1 < currentLineLength && (document.GetCharAt(currentLineOffset + i + 1) == '+' || document.GetCharAt(currentLine.Offset + i + 1) == '-'))
                            {
                                ++i;
                                ++currentLength;
                            }
                            while (i + 1 < currentLine.Length && Char.IsDigit(document.GetCharAt(currentLineOffset + i + 1)))
                            {
                                ++i;
                                ++currentLength;
                            }
                        }

                        if (i + 1 < currentLine.Length)
                        {
                            char nextch = Char.ToUpper(document.GetCharAt(currentLineOffset + i + 1));
                            if (nextch == 'F' || nextch == 'M' || nextch == 'D')
                            {
                                isfloatingpoint = true;
                                ++i;
                                ++currentLength;
                            }
                        }

                        if (!isfloatingpoint)
                        {
                            bool isunsigned = false;
                            if (i + 1 < currentLineLength && Char.ToUpper(document.GetCharAt(currentLineOffset + i + 1)) == 'U')
                            {
                                ++i;
                                ++currentLength;
                                isunsigned = true;
                            }
                            if (i + 1 < currentLineLength && Char.ToUpper(document.GetCharAt(currentLineOffset + i + 1)) == 'L')
                            {
                                ++i;
                                ++currentLength;
                                if (!isunsigned && i + 1 < currentLineLength && Char.ToUpper(document.GetCharAt(currentLineOffset + i + 1)) == 'U')
                                {
                                    ++i;
                                    ++currentLength;
                                }
                            }
                        }

                        words.Add(new TextWord(document, currentLine, currentOffset, currentLength, DigitColor, false));
                        currentOffset += currentLength;
                        currentLength  = 0;
                        continue;
                    }

                    // Check for SPAN ENDs
                    if (inSpan)
                    {
                        if (activeSpan.End != null && activeSpan.End.Length > 0)
                        {
                            if (MatchExpr(currentLine, activeSpan.End, i, document, activeSpan.IgnoreCase))
                            {
                                PushCurWord(document, ref markNext, words);
                                string regex = GetRegString(currentLine, activeSpan.End, i, document);
                                currentLength += regex.Length;
                                words.Add(new TextWord(document, currentLine, currentOffset, currentLength, activeSpan.EndColor, false));
                                currentOffset += currentLength;
                                currentLength  = 0;
                                i             += regex.Length - 1;
                                currentSpanStack.Pop();
                                UpdateSpanStateVariables();
                                continue;
                            }
                        }
                    }

                    // check for SPAN BEGIN
                    if (activeRuleSet != null)
                    {
                        foreach (Span span in activeRuleSet.Spans)
                        {
                            if ((!span.IsBeginSingleWord || currentLength == 0) &&
                                (!span.IsBeginStartOfLine.HasValue || span.IsBeginStartOfLine.Value == (currentLength == 0 && words.TrueForAll(delegate(TextWord textWord) { return(textWord.Type != TextWordType.Word); }))) &&
                                MatchExpr(currentLine, span.Begin, i, document, activeRuleSet.IgnoreCase))
                            {
                                PushCurWord(document, ref markNext, words);
                                string regex = GetRegString(currentLine, span.Begin, i, document);

                                if (!OverrideSpan(regex, document, words, span, ref i))
                                {
                                    currentLength += regex.Length;
                                    words.Add(new TextWord(document, currentLine, currentOffset, currentLength, span.BeginColor, false));
                                    currentOffset += currentLength;
                                    currentLength  = 0;

                                    i += regex.Length - 1;
                                    if (currentSpanStack == null)
                                    {
                                        currentSpanStack = new SpanStack();
                                    }
                                    currentSpanStack.Push(span);
                                    span.IgnoreCase = activeRuleSet.IgnoreCase;

                                    UpdateSpanStateVariables();
                                }

                                goto skip;
                            }
                        }
                    }

                    // check if the char is a delimiter
                    if (activeRuleSet != null && (int)ch < 256 && activeRuleSet.Delimiters[(int)ch])
                    {
                        PushCurWord(document, ref markNext, words);
                        if (currentOffset + currentLength + 1 < currentLine.Length)
                        {
                            ++currentLength;
                            PushCurWord(document, ref markNext, words);
                            goto skip;
                        }
                    }

                    ++currentLength;
                    skip : continue;
                }
                }
            }

            PushCurWord(document, ref markNext, words);

            OnParsedLine(document, currentLine, words);

            return(words);
        }
Exemplo n.º 23
0
        List <TextWord> ParseLine(IDocument document)
        {
            List <TextWord> words    = new List <TextWord>();
            HighlightColor  markNext = null;

            currentOffset = 0;
            currentLength = 0;
            UpdateSpanStateVariables();

            for (int i = 0; i < currentLine.Length; ++i)
            {
                char ch = document.GetCharAt(currentLine.Offset + i);
                switch (ch)
                {
                case '\n':
                case '\r':
                    PushCurWord(document, ref markNext, words);
                    ++currentOffset;
                    break;

                case ' ':
                    PushCurWord(document, ref markNext, words);
                    if (activeSpan != null && activeSpan.Color.HasBackground)
                    {
                        words.Add(new TextWord.SpaceTextWord(activeSpan.Color));
                    }
                    else
                    {
                        words.Add(TextWord.Space);
                    }
                    ++currentOffset;
                    break;

                case '\t':
                    PushCurWord(document, ref markNext, words);
                    if (activeSpan != null && activeSpan.Color.HasBackground)
                    {
                        words.Add(new TextWord.TabTextWord(activeSpan.Color));
                    }
                    else
                    {
                        words.Add(TextWord.Tab);
                    }
                    ++currentOffset;
                    break;

                case '\\':                         // handle escape chars
                    if ((activeRuleSet != null && activeRuleSet.NoEscapeSequences) ||
                        (activeSpan != null && activeSpan.NoEscapeSequences))
                    {
                        goto default;
                    }
                    ++currentLength;
                    if (i + 1 < currentLine.Length)
                    {
                        ++currentLength;
                    }
                    PushCurWord(document, ref markNext, words);
                    ++i;
                    continue;

                default: {
                    // highlight digits
                    if (!inSpan && (Char.IsDigit(ch) || (ch == '.' && i + 1 < currentLine.Length && Char.IsDigit(document.GetCharAt(currentLine.Offset + i + 1)))) && currentLength == 0)
                    {
                        bool ishex           = false;
                        bool isfloatingpoint = false;

                        if (ch == '0' && i + 1 < currentLine.Length && Char.ToUpper(document.GetCharAt(currentLine.Offset + i + 1)) == 'X')                                   // hex digits
                        {
                            const string hex = "0123456789ABCDEF";
                            ++currentLength;
                            ++i;                                     // skip 'x'
                            ++currentLength;
                            ishex = true;
                            while (i + 1 < currentLine.Length && hex.IndexOf(Char.ToUpper(document.GetCharAt(currentLine.Offset + i + 1))) != -1)
                            {
                                ++i;
                                ++currentLength;
                            }
                        }
                        else
                        {
                            ++currentLength;
                            while (i + 1 < currentLine.Length && Char.IsDigit(document.GetCharAt(currentLine.Offset + i + 1)))
                            {
                                ++i;
                                ++currentLength;
                            }
                        }
                        if (!ishex && i + 1 < currentLine.Length && document.GetCharAt(currentLine.Offset + i + 1) == '.')
                        {
                            isfloatingpoint = true;
                            ++i;
                            ++currentLength;
                            while (i + 1 < currentLine.Length && Char.IsDigit(document.GetCharAt(currentLine.Offset + i + 1)))
                            {
                                ++i;
                                ++currentLength;
                            }
                        }

                        if (i + 1 < currentLine.Length && Char.ToUpper(document.GetCharAt(currentLine.Offset + i + 1)) == 'E')
                        {
                            isfloatingpoint = true;
                            ++i;
                            ++currentLength;
                            if (i + 1 < currentLine.Length && (document.GetCharAt(currentLine.Offset + i + 1) == '+' || document.GetCharAt(currentLine.Offset + i + 1) == '-'))
                            {
                                ++i;
                                ++currentLength;
                            }
                            while (i + 1 < currentLine.Length && Char.IsDigit(document.GetCharAt(currentLine.Offset + i + 1)))
                            {
                                ++i;
                                ++currentLength;
                            }
                        }

                        if (i + 1 < currentLine.Length)
                        {
                            char nextch = Char.ToUpper(document.GetCharAt(currentLine.Offset + i + 1));
                            if (nextch == 'F' || nextch == 'M' || nextch == 'D')
                            {
                                isfloatingpoint = true;
                                ++i;
                                ++currentLength;
                            }
                        }

                        if (!isfloatingpoint)
                        {
                            bool isunsigned = false;
                            if (i + 1 < currentLine.Length && Char.ToUpper(document.GetCharAt(currentLine.Offset + i + 1)) == 'U')
                            {
                                ++i;
                                ++currentLength;
                                isunsigned = true;
                            }
                            if (i + 1 < currentLine.Length && Char.ToUpper(document.GetCharAt(currentLine.Offset + i + 1)) == 'L')
                            {
                                ++i;
                                ++currentLength;
                                if (!isunsigned && i + 1 < currentLine.Length && Char.ToUpper(document.GetCharAt(currentLine.Offset + i + 1)) == 'U')
                                {
                                    ++i;
                                    ++currentLength;
                                }
                            }
                        }

                        words.Add(new TextWord(document, currentLine, currentOffset, currentLength, DigitColor, false));
                        currentOffset += currentLength;
                        currentLength  = 0;
                        continue;
                    }

                    // Check for SPAN ENDs
                    if (inSpan)
                    {
                        if (activeSpan.End != null && !activeSpan.End.Equals(""))
                        {
                            if (currentLine.MatchExpr(activeSpan.End, i, document))
                            {
                                PushCurWord(document, ref markNext, words);
                                string regex = currentLine.GetRegString(activeSpan.End, i, document);
                                currentLength += regex.Length;
                                words.Add(new TextWord(document, currentLine, currentOffset, currentLength, activeSpan.EndColor, false));
                                currentOffset += currentLength;
                                currentLength  = 0;
                                i             += regex.Length - 1;
                                currentSpanStack.Pop();
                                UpdateSpanStateVariables();
                                continue;
                            }
                        }
                    }

                    // check for SPAN BEGIN
                    if (activeRuleSet != null)
                    {
                        foreach (Span span in activeRuleSet.Spans)
                        {
                            if (currentLine.MatchExpr(span.Begin, i, document))
                            {
                                PushCurWord(document, ref markNext, words);
                                string regex = currentLine.GetRegString(span.Begin, i, document);
                                currentLength += regex.Length;
                                words.Add(new TextWord(document, currentLine, currentOffset, currentLength, span.BeginColor, false));
                                currentOffset += currentLength;
                                currentLength  = 0;

                                i += regex.Length - 1;
                                if (currentSpanStack == null)
                                {
                                    currentSpanStack = new Stack <Span>();
                                }
                                currentSpanStack.Push(span);

                                UpdateSpanStateVariables();

                                goto skip;
                            }
                        }
                    }

                    // check if the char is a delimiter
                    if (activeRuleSet != null && (int)ch < 256 && activeRuleSet.Delimiters[(int)ch])
                    {
                        PushCurWord(document, ref markNext, words);
                        if (currentOffset + currentLength + 1 < currentLine.Length)
                        {
                            ++currentLength;
                            PushCurWord(document, ref markNext, words);
                            goto skip;
                        }
                    }

                    ++currentLength;
                    skip : continue;
                }
                }
            }

            PushCurWord(document, ref markNext, words);

            return(words);
        }
Exemplo n.º 24
0
//		internal void SetDefaultColor(HighlightBackground color)
//		{
//			return (HighlightColor)environmentColors[name];
//			defaultColor = color;
//		}

        internal void SetColorFor(string name, HighlightColor color)
        {
            environmentColors[name] = color;
        }
		public void SetColorFor(string name, HighlightColor color)
		{
			if (name == "Default")
				defaultTextColor = new HighlightColor(color.Color, color.Bold, color.Italic);
			environmentColors[name] = color;
		}
 public TabTextWord(HighlightColor color)
 {
     Length      = 1;
     SyntaxColor = color;
 }
Exemplo n.º 27
0
//		internal void SetDefaultColor(HighlightBackground color)
//		{
//			return (HighlightColor)environmentColors[name];
//			defaultColor = color;
//		}		
		
		internal void SetColorFor(string name, HighlightColor color)
		{
			environmentColors[name] = color;
		}
        public DefaultTextEditorProperties()
        {
            //DefaultFont = new Font("Consolas", 10);
            FontContainer = new FontContainer(DefaultFont);
            Font = DefaultFont;

            TabIndent = 4;
            IndentationSize = 4;
            IndentStyle = IndentStyle.Smart;
            DocumentSelectionMode = DocumentSelectionMode.Normal;
            Encoding = System.Text.Encoding.UTF8;
            BracketMatchingStyle  = BracketMatchingStyle.After;

            ShowMatchingBracket = true;
            ShowLineNumbers = true;
            EnableFolding = true;
            ShowVerticalRuler = true;
            TextRenderingHint = TextRenderingHint.SystemDefault;
            MouseWheelScrollDown = true;
            MouseWheelTextZoom = true;

            VerticalRulerRow = 80;
            LineViewerStyle = LineViewerStyle.None;
            LineTerminator = "\r\n";
            AutoInsertCurlyBracket = true;

            DefaultColor = new HighlightBackground("WindowText", "Window", false, false);
            SelectionColor = new HighlightColor("HighlightText", "Highlight", false, false);
            VRulerColor = new HighlightColor("ControlLight", "Window", false, false);
            InvalidLinesColor = new HighlightColor(Color.Red, false, false);
            CaretMarkerColor = new HighlightColor(Color.Yellow, false, false);
            CaretLineColor = new HighlightBackground("ControlLight", "Window", false, false);
            LineNumbersColor = new HighlightBackground("ControlDark", "Window", false, false);
            FoldLineColor = new HighlightColor("ControlDark", false, false);
            FoldMarkerColor = new HighlightColor("WindowText", "Window", false, false);
            SelectedFoldLineColor = new HighlightColor("WindowText", false, false);
            EOLMarkersColor = new HighlightColor("ControlLight", "Window", false, false);
            SpaceMarkersColor = new HighlightColor("ControlLight", "Window", false, false);
            TabMarkersColor = new HighlightColor("ControlLight", "Window", false, false);
        }
Exemplo n.º 29
0
		/// <summary>
		/// pushes the curWord string on the word list, with the
		/// correct color.
		/// </summary>
		void PushCurWord(IDocument document, ref HighlightColor markNext, List<TextWord> words)
		{
			// Svante Lidman : Need to look through the next prev logic.
			if (currentLength > 0) {
				if (words.Count > 0 && activeRuleSet != null) {
					TextWord prevWord = null;
					int pInd = words.Count - 1;
					while (pInd >= 0) {
						if (!((TextWord)words[pInd]).IsWhiteSpace) {
							prevWord = (TextWord)words[pInd];
							if (prevWord.HasDefaultColor) {
								PrevMarker marker = (PrevMarker)activeRuleSet.PrevMarkers[document, currentLine, currentOffset, currentLength];
								if (marker != null) {
									prevWord.SyntaxColor = marker.Color;
//									document.Caret.ValidateCaretPos();
//									document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, document.GetLineNumberForOffset(document.Caret.Offset)));
								}
							}
							break;
						}
						pInd--;
					}
				}
				
				if (inSpan) {
					HighlightColor c = null;
					bool hasDefaultColor = true;
					if (activeSpan.Rule == null) {
						c = activeSpan.Color;
					} else {
						c = GetColor(activeRuleSet, document, currentLine, currentOffset, currentLength);
						hasDefaultColor = false;
					}
					
					if (c == null) {
						c = activeSpan.Color;
						if (c.Color == Color.Transparent) {
							c = GetColorFor("DefaultBackground");
						}
						hasDefaultColor = true;
					}
					words.Add(new TextWord(document, currentLine, currentOffset, currentLength, markNext != null ? markNext : c, hasDefaultColor));
				} else {
					HighlightColor c = markNext != null ? markNext : GetColor(activeRuleSet, document, currentLine, currentOffset, currentLength);
					if (c == null) {
						words.Add(new TextWord(document, currentLine, currentOffset, currentLength, GetColorFor("DefaultBackground"), true));
					} else {
						words.Add(new TextWord(document, currentLine, currentOffset, currentLength, c, false));
					}
				}
				
				if (activeRuleSet != null) {
					NextMarker nextMarker = (NextMarker)activeRuleSet.NextMarkers[document, currentLine, currentOffset, currentLength];
					if (nextMarker != null) {
						if (nextMarker.MarkMarker && words.Count > 0) {
							TextWord prevword = ((TextWord)words[words.Count - 1]);
							prevword.SyntaxColor = nextMarker.Color;
						}
						markNext = nextMarker.Color;
					} else {
						markNext = null;
					}
				}
				currentOffset += currentLength;
				currentLength = 0;					
			}
		}		
Exemplo n.º 30
0
Arquivo: Span.cs Projeto: viticm/pap2
		public Span(XmlElement span)
		{
			color   = new HighlightColor(span);
			
			if (span.Attributes["rule"] != null) {
				rule = span.Attributes["rule"].InnerText;
			}
			
			if (span.Attributes["noescapesequences"] != null) {
				noEscapeSequences = Boolean.Parse(span.Attributes["noescapesequences"].InnerText);
			}
			
			name    = span.Attributes["name"].InnerText;
			stopEOL = Boolean.Parse(span.Attributes["stopateol"].InnerText);
			begin   = span["Begin"].InnerText.ToCharArray();
			beginColor = new HighlightColor(span["Begin"], color);
			
			if (span["End"] != null) {
				end  = span["End"].InnerText.ToCharArray();
				endColor = new HighlightColor(span["End"], color);
			}
		}
Exemplo n.º 31
0
		public string GenerateHtml(IDocument document)
		{
			string myMainStyle = MainStyle;
			currentDefaultTextColor = document.HighlightingStrategy.GetColorFor("Default");
			myMainStyle += " color: " + ColorToString(currentDefaultTextColor.Color) + ";"
				+ " background-color: " + ColorToString(currentDefaultTextColor.BackgroundColor) + ";";
			
			string LineNumberStyle;
			HighlightColor lineNumbersColor = document.HighlightingStrategy.GetColorFor("LineNumbers");
			if (lineNumbersColor != null) {
				LineNumberStyle = "color: " + ColorToString(lineNumbersColor.Color) + ";"
					+ " background-color: " + ColorToString(lineNumbersColor.BackgroundColor) + ";";
			} else {
				LineNumberStyle = "color: #606060;";
			}
			
			StringBuilder b = new StringBuilder();
			if (CreateStylesheet) {
				b.AppendLine("<style type=\"text/css\">");
				if (ShowLineNumbers || AlternateLineBackground) {
					CacheClass(myMainStyle, b);
					CacheClass(LineStyle, b);
				} else {
					CacheClass(myMainStyle + LineStyle, b);
				}
				if (AlternateLineBackground) CacheClass(AlternateLineStyle, b);
				if (ShowLineNumbers) CacheClass(LineNumberStyle, b);
				foreach (LineSegment ls in document.LineSegmentCollection) {
					foreach (TextWord word in ls.Words) {
						CacheClass(GetStyle(word), b);
					}
				}
				b.AppendLine("</style>");
			}
			if (ShowLineNumbers || AlternateLineBackground) {
				b.Append("<div");
				WriteStyle(myMainStyle, b);
				b.AppendLine(">");
				
				int longestNumberLength = 1 + (int)Math.Log10(document.TotalNumberOfLines);
				
				int lineNumber = 1;
				foreach (LineSegment lineSegment in document.LineSegmentCollection) {
					b.Append("<pre");
					if (AlternateLineBackground && (lineNumber % 2) == 0) {
						WriteStyle(AlternateLineStyle, b);
					} else {
						WriteStyle(LineStyle, b);
					}
					b.Append(">");
					
					if (ShowLineNumbers) {
						b.Append("<span");
						WriteStyle(LineNumberStyle, b);
						b.Append('>');
						b.Append(lineNumber.ToString().PadLeft(longestNumberLength));
						b.Append(":  ");
						b.Append("</span>");
					}
					
					
					if (lineSegment.Words.Count == 0) {
						b.Append("&nbsp;");
					} else {
						PrintWords(lineSegment, b);
					}
					b.AppendLine("</pre>");
					
					lineNumber++;
				}
				b.AppendLine("</div>");
			} else {
				b.Append("<pre");
				WriteStyle(myMainStyle + LineStyle, b);
				b.AppendLine(">");
				foreach (LineSegment lineSegment in document.LineSegmentCollection) {
					PrintWords(lineSegment, b);
					b.AppendLine();
				}
				b.AppendLine("</pre>");
			}
			return b.ToString();
		}
Exemplo n.º 32
0
		public Span(XmlElement span)
		{
			color   = new HighlightColor(span);
			
			if (span.HasAttribute("rule")) {
				rule = span.GetAttribute("rule");
			}
			
			if (span.HasAttribute("escapecharacter")) {
				escapeCharacter = span.GetAttribute("escapecharacter")[0];
			}
			
			name = span.GetAttribute("name");
			if (span.HasAttribute("stopateol")) {
				stopEOL = Boolean.Parse(span.GetAttribute("stopateol"));
			}
			
			begin   = span["Begin"].InnerText.ToCharArray();
            //add by johnny
            //beginColor = new HighlightColor(span["Begin"], color);
            if (begin.Length == 1 && begin[0] == '<')
                beginColor = new HighlightColor(span["Begin"], new HighlightColor(System.Drawing.Color.Blue, false, false));
            else if (begin.Length == 2 && begin[0] == '<' && begin[1] == '/')
                beginColor = new HighlightColor(span["Begin"], new HighlightColor(System.Drawing.Color.Blue, false, false));
            else if (begin.Length == 2 && begin[0] == '<' && begin[1] == '?')
                beginColor = new HighlightColor(span["Begin"], new HighlightColor(System.Drawing.Color.Blue, false, false));
            else
                beginColor = new HighlightColor(span["Begin"], color);
            //end			
			
			if (span["Begin"].HasAttribute("singleword")) {
				this.isBeginSingleWord = Boolean.Parse(span["Begin"].GetAttribute("singleword"));
			}
			if (span["Begin"].HasAttribute("startofline")) {
				this.isBeginStartOfLine = Boolean.Parse(span["Begin"].GetAttribute("startofline"));
			}
			
			if (span["End"] != null) {
				end  = span["End"].InnerText.ToCharArray();
                //add by johnny
                //endColor = new HighlightColor(span["End"], color);
                if (end.Length == 1 && end[0] == '>')
                    endColor = new HighlightColor(span["End"], new HighlightColor(System.Drawing.Color.Blue, false, false));
                else if (end.Length == 2 && end[0] == '?' && end[1] == '>')
                    endColor = new HighlightColor(span["End"], new HighlightColor(System.Drawing.Color.Blue, false, false));
                else
                    endColor = new HighlightColor(span["End"], color);
                //end
				if (span["End"].HasAttribute("singleword")) {
					this.isEndSingleWord = Boolean.Parse(span["End"].GetAttribute("singleword"));
				}

			}
		}
			public TabTextWord(HighlightColor color)
			{
				length = 1;
				base.SyntaxColor = color;
			}
Exemplo n.º 34
0
        public HighlightColor(XmlElement el, HighlightColor defaultColor)
        {
            if (el.Attributes["bold"] != null)
            {
                Bold = bool.Parse(el.Attributes["bold"].InnerText);
            }
            else
            {
                Bold = defaultColor.Bold;
            }

            if (el.Attributes["italic"] != null)
            {
                Italic = bool.Parse(el.Attributes["italic"].InnerText);
            }
            else
            {
                Italic = defaultColor.Italic;
            }

            if (el.Attributes["color"] != null)
            {
                string c = el.Attributes["color"].InnerText;
                if (c[0] == '#')
                {
                    Color = ParseColor(c);
                }
                else if (c.StartsWith("SystemColors."))
                {
                    Color = ParseColorString(c.Substring("SystemColors.".Length));
                }
                else
                {
                    //?                   ColorX = (Color)(Color.GetType()).InvokeMember(c, BindingFlags.GetProperty, null, Color, new object[0]);
                    Color = defaultColor.Color;
                }
                //HasForeground = true;
            }
            else
            {
                Color = defaultColor.Color;
            }

            if (el.Attributes["bgcolor"] != null)
            {
                string c = el.Attributes["bgcolor"].InnerText;
                if (c[0] == '#')
                {
                    BackgroundColor = ParseColor(c);
                }
                else if (c.StartsWith("SystemColors."))
                {
                    BackgroundColor = ParseColorString(c.Substring("SystemColors.".Length));
                }
                else
                {
//?                    BackgroundColorX = (Color)(Color.GetType()).InvokeMember(c, BindingFlags.GetProperty, null, Color, new object[0]);
                    BackgroundColor = defaultColor.BackgroundColor;
                }
                //        HasBackground = true;
            }
            else
            {
                BackgroundColor = defaultColor.BackgroundColor;
            }
        }