Ejemplo n.º 1
0
			public TextChunk (ChunkStyle style, int offset, string text) : this (style, offset)
			{
				if (text == null)
					throw new ArgumentNullException ("text");
				this.text = text;
				this.Length = text.Length;
			}
Ejemplo n.º 2
0
		public ChunkStyle (ChunkStyle baseStyle)
		{
			this.Name = baseStyle.Name;
			this.Foreground = baseStyle.Foreground;
			this.Background = baseStyle.Background;
			this.Weight = baseStyle.Weight;
		}
Ejemplo n.º 3
0
		public ChunkStyle (ChunkStyle baseStyle)
		{
			this.Name = baseStyle.Name;
			this.Foreground = baseStyle.Foreground;
			this.Background = baseStyle.Background;
			this.FontWeight = baseStyle.FontWeight;
			this.FontStyle = baseStyle.FontStyle;
			this.Underline = baseStyle.Underline;
		}
Ejemplo n.º 4
0
/*		void SetStyle (string name, byte r, byte g, byte b, byte bg_r, byte bg_g, byte bg_b, ChunkProperties properties)
 *              {
 *                      SetStyle (name, new ChunkStyle (new Gdk.Color (r, g, b), new Gdk.Color (bg_r, bg_g, bg_b), properties));
 *              }*/

        public ChunkStyle GetDefaultChunkStyle()
        {
            ChunkStyle style;

            if (!styleLookupTable.TryGetValue(DefaultString, out style))
            {
                style = new ChunkStyle(GetColorFromDefinition(DefaultString));
                styleLookupTable[DefaultString] = style;
            }
            return(style);
        }
Ejemplo n.º 5
0
        public static ChunkStyle Create(XElement element, Dictionary <string, Cairo.Color> palette)
        {
            var result = new ChunkStyle();

            foreach (var node in element.DescendantNodes())
            {
                if (node.NodeType == System.Xml.XmlNodeType.Element)
                {
                    var el = (XElement)node;
                    switch (el.Name.LocalName)
                    {
                    case "name":
                        result.Name = el.Value;
                        break;

                    case "fore":
                        result.Foreground = ColorScheme.ParsePaletteColor(palette, el.Value);
                        break;

                    case "back":
                        result.Background = ColorScheme.ParsePaletteColor(palette, el.Value);
                        break;

                    case "weight":
                        FontWeight weight;
                        if (!Enum.TryParse <FontWeight> (el.Value, true, out weight))
                        {
                            throw new InvalidDataException(el.Value + " is no valid text weight values are: " + string.Join(",", Enum.GetNames(typeof(FontWeight))));
                        }
                        result.FontWeight = weight;
                        break;

                    case "style":
                        FontStyle style;
                        if (!Enum.TryParse <FontStyle> (el.Value, true, out style))
                        {
                            throw new InvalidDataException(el.Value + " is no valid text weight values are: " + string.Join(",", Enum.GetNames(typeof(FontStyle))));
                        }
                        result.FontStyle = style;
                        break;

                    default:
                        throw new InvalidDataException("Invalid element in text color:" + el.Name);
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 6
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            if (ReferenceEquals(this, obj))
            {
                return(true);
            }
            if (obj.GetType() != typeof(ChunkStyle))
            {
                return(false);
            }
            ChunkStyle other = (ChunkStyle)obj;

            return(Name == other.Name && Foreground.Equals(other.Foreground) && Background.Equals(other.Background) && FontWeight == other.FontWeight && FontStyle == other.FontStyle);
        }
Ejemplo n.º 7
0
        public static ChunkStyle Import(string name, ColorScheme.VSSettingColor vsc)
        {
            var textColor = new ChunkStyle();

            textColor.Name = name;
            if (!string.IsNullOrEmpty(vsc.Foreground) && vsc.Foreground != "0x02000000")
            {
                textColor.Foreground = ColorScheme.ImportVsColor(vsc.Foreground);
                if (textColor.TransparentForeground && name != "Selected Text" && name != "Selected Text(Inactive)")
                {
                    textColor.Foreground = new Cairo.Color(0, 0, 0);
                }
            }
            if (!string.IsNullOrEmpty(vsc.Background) && vsc.Background != "0x02000000")
            {
                textColor.Background = ColorScheme.ImportVsColor(vsc.Background);
            }
            if (vsc.BoldFont)
            {
                textColor.FontWeight = FontWeight.Bold;
            }
            return(textColor);
        }
Ejemplo n.º 8
0
        public string GetMarkup(Document doc, ITextEditorOptions options, ColorSheme style, int offset, int length, bool removeIndent, bool useColors, bool replaceTabs)
        {
            int indentLength = GetIndentLength(doc, offset, length, false);
            int curOffset    = offset;

            StringBuilder result = new StringBuilder();

            while (curOffset < offset + length && curOffset < doc.Length)
            {
                LineSegment        line       = doc.GetLineByOffset(curOffset);
                int                toOffset   = System.Math.Min(line.Offset + line.EditableLength, offset + length);
                Stack <ChunkStyle> styleStack = new Stack <ChunkStyle> ();
                for (Chunk chunk = GetChunks(doc, style, line, curOffset, toOffset - curOffset); chunk != null; chunk = chunk.Next)
                {
                    ChunkStyle chunkStyle = chunk.GetChunkStyle(style);
                    bool       setBold    = chunkStyle.Bold && (styleStack.Count == 0 || !styleStack.Peek().Bold) ||
                                            !chunkStyle.Bold && (styleStack.Count == 0 || styleStack.Peek().Bold);
                    bool setItalic = chunkStyle.Italic && (styleStack.Count == 0 || !styleStack.Peek().Italic) ||
                                     !chunkStyle.Italic && (styleStack.Count == 0 || styleStack.Peek().Italic);
                    bool setUnderline = chunkStyle.Underline && (styleStack.Count == 0 || !styleStack.Peek().Underline) ||
                                        !chunkStyle.Underline && (styleStack.Count == 0 || styleStack.Peek().Underline);
                    bool setColor = styleStack.Count == 0 || TextViewMargin.GetPixel(styleStack.Peek().Color) != TextViewMargin.GetPixel(chunkStyle.Color);
                    if (setColor || setBold || setItalic || setUnderline)
                    {
                        if (styleStack.Count > 0)
                        {
                            result.Append("</span>");
                            styleStack.Pop();
                        }
                        result.Append("<span");
                        if (useColors)
                        {
                            result.Append(" foreground=\"");
                            result.Append(ColorToPangoMarkup(chunkStyle.Color));
                            result.Append("\"");
                        }
                        if (chunkStyle.Bold)
                        {
                            result.Append(" weight=\"bold\"");
                        }
                        if (chunkStyle.Italic)
                        {
                            result.Append(" style=\"italic\"");
                        }
                        if (chunkStyle.Underline)
                        {
                            result.Append(" underline=\"single\"");
                        }
                        result.Append(">");
                        styleStack.Push(chunkStyle);
                    }

                    for (int i = 0; i < chunk.Length && chunk.Offset + i < doc.Length; i++)
                    {
                        char ch = chunk.GetCharAt(doc, chunk.Offset + i);
                        switch (ch)
                        {
                        case '&':
                            result.Append("&amp;");
                            break;

                        case '<':
                            result.Append("&lt;");
                            break;

                        case '>':
                            result.Append("&gt;");
                            break;

                        case '\t':
                            if (replaceTabs)
                            {
                                result.Append(new string (' ', options.TabSize));
                            }
                            else
                            {
                                result.Append('\t');
                            }
                            break;

                        default:
                            result.Append(ch);
                            break;
                        }
                    }
                }
                while (styleStack.Count > 0)
                {
                    result.Append("</span>");
                    styleStack.Pop();
                }

                curOffset = line.EndOffset;
                if (removeIndent)
                {
                    curOffset += indentLength;
                }
                if (result.Length > 0 && curOffset < offset + length)
                {
                    result.AppendLine();
                }
            }
            return(result.ToString());
        }
Ejemplo n.º 9
0
		public void SetChunkStyle (string name, ChunkStyle style)
		{
			SetStyle (name, style);
		}
Ejemplo n.º 10
0
 public TextChunk(ChunkStyle style, int offset)
 {
     this.Offset     = offset;
     this.ChunkStyle = style;
 }
		public override void UpdateFromGtkStyle (Gtk.Style style)
		{
			this.selectionStyle = new ChunkStyle (style.Text (StateType.Selected), style.Base (StateType.Selected));
			this.defaultStyle = new ChunkStyle (style.Text (StateType.Normal), style.Base (StateType.Normal));
			this.lineNumberStyle = new ChunkStyle (new Gdk.Color (172, 168, 153), style.Base (StateType.Normal));
			this.iconBarBg = style.Background (StateType.Normal);
			this.iconBarSeperator = style.Background (StateType.Active);
		}
Ejemplo n.º 12
0
		public Cairo.Color GetForeground (ChunkStyle chunkStyle)
		{
			if (chunkStyle.TransparentForeground)
				return PlainText.Foreground;
			return chunkStyle.Foreground;
		}
Ejemplo n.º 13
0
        public static ColorScheme Import(string fileName, Stream stream)
        {
            var result = new ColorScheme();

            result.Name        = Path.GetFileNameWithoutExtension(fileName);
            result.Description = "Imported color scheme";
            result.Originator  = "Imported from " + fileName;

            var colors = new Dictionary <string, VSSettingColor> ();

            using (var reader = XmlReader.Create(stream)) {
                while (reader.Read())
                {
                    if (reader.LocalName == "Item")
                    {
                        var color = VSSettingColor.Create(reader);
                        if (colors.ContainsKey(color.Name))
                        {
                            Console.WriteLine("Warning: {0} is defined twice in vssettings.", color.Name);
                            continue;
                        }
                        colors[color.Name] = color;
                    }
                }
            }


            HashSet <string> importedAmbientColors = new HashSet <string> ();

            // convert ambient colors
            foreach (var ambient in ambientColors.Values)
            {
                if (!string.IsNullOrEmpty(ambient.Attribute.VSSetting))
                {
                    var import = AmbientColor.Import(colors, ambient.Attribute.VSSetting);
                    if (import != null)
                    {
                        importedAmbientColors.Add(import.Name);
                        ambient.Info.SetValue(result, import, null);
                        continue;
                    }
                }
            }

            // convert text colors
            foreach (var vsc in colors.Values)
            {
                bool found = false;
                foreach (var color in textColors)
                {
                    if (color.Value.Attribute.VSSetting == null)
                    {
                        continue;
                    }
                    var split = color.Value.Attribute.VSSetting.Split('?');
                    foreach (var s in split)
                    {
                        if (s == vsc.Name)
                        {
                            /*	if (vsc.Foreground == "0x02000000" && vsc.Background == "0x02000000") {
                             *              color.Value.Info.SetValue (result, result.PlainText, null);
                             *              found = true;
                             *              continue;
                             *      }*/
                            var textColor = ChunkStyle.Import(color.Value.Attribute.Name, vsc);
                            if (textColor != null)
                            {
                                color.Value.Info.SetValue(result, textColor, null);
                                found = true;
                            }
                        }
                    }
                }
                if (!found && !importedAmbientColors.Contains(vsc.Name))
                {
                    Console.WriteLine(vsc.Name + " not imported!");
                }
            }

            result.IndentationGuide = new AmbientColor();
            result.IndentationGuide.Colors.Add(Tuple.Create("color", AlphaBlend(result.PlainText.Foreground, result.PlainText.Background, 0.3)));

            result.TooltipText = result.PlainText.Clone();
            var h = (HslColor)result.TooltipText.Background;

            h.L += 0.01;
            result.TooltipText.Background = h;

            result.TooltipPagerTop = new AmbientColor();
            result.TooltipPagerTop.Colors.Add(Tuple.Create("color", result.TooltipText.Background));

            result.TooltipPagerBottom = new AmbientColor();
            result.TooltipPagerBottom.Colors.Add(Tuple.Create("color", result.TooltipText.Background));

            result.TooltipPagerTriangle = new AmbientColor();
            result.TooltipPagerTriangle.Colors.Add(Tuple.Create("color", AlphaBlend(result.PlainText.Foreground, result.PlainText.Background, 0.8)));

            result.TooltipBorder = new AmbientColor();
            result.TooltipBorder.Colors.Add(Tuple.Create("color", AlphaBlend(result.PlainText.Foreground, result.PlainText.Background, 0.5)));

            var defaultStyle = SyntaxModeService.GetColorStyle(HslColor.Brightness(result.PlainText.Background) < 0.5 ? "Monokai" : "Default");

            foreach (var color in textColors.Values)
            {
                if (color.Info.GetValue(result, null) == null)
                {
                    color.Info.SetValue(result, color.Info.GetValue(defaultStyle, null), null);
                }
            }
            foreach (var color in ambientColors.Values)
            {
                if (color.Info.GetValue(result, null) == null)
                {
                    color.Info.SetValue(result, color.Info.GetValue(defaultStyle, null), null);
                }
            }
            if (result.PlainText.TransparentForeground)
            {
                result.PlainText.Foreground = new Cairo.Color(0, 0, 0);
            }
            return(result);
        }
Ejemplo n.º 14
0
        public static ColorScheme LoadFrom(Stream stream)
        {
            var result = new ColorScheme();
            var reader = System.Runtime.Serialization.Json.JsonReaderWriterFactory.CreateJsonReader(stream, new System.Xml.XmlDictionaryReaderQuotas());

            var root = XElement.Load(reader);

            // The fields we'd like to extract
            result.Name = root.XPathSelectElement("name").Value;

            if (result.Name != "Default")
            {
                result.CopyValues(SyntaxModeService.DefaultColorStyle);
            }

            var version = Version.Parse(root.XPathSelectElement("version").Value);

            if (version.Major != 1)
            {
                return(null);
            }
            var el = root.XPathSelectElement("description");

            if (el != null)
            {
                result.Description = el.Value;
            }
            el = root.XPathSelectElement("originator");
            if (el != null)
            {
                result.Originator = el.Value;
            }
            el = root.XPathSelectElement("baseScheme");
            if (el != null)
            {
                result.BaseScheme = el.Value;
            }

            if (result.BaseScheme != null)
            {
                var baseScheme = SyntaxModeService.GetColorStyle(result.BaseScheme);
                if (baseScheme != null)
                {
                    result.CopyValues(baseScheme);
                }
            }

            var palette = new Dictionary <string, Cairo.Color> ();

            foreach (var color in root.XPathSelectElements("palette/*"))
            {
                var name = color.XPathSelectElement("name").Value;
                if (palette.ContainsKey(name))
                {
                    throw new InvalidDataException("Duplicate palette color definition for: " + name);
                }
                palette.Add(
                    name,
                    ParseColor(color.XPathSelectElement("value").Value)
                    );
            }

            foreach (var colorElement in root.XPathSelectElements("//colors/*"))
            {
                var color = AmbientColor.Create(colorElement, palette);
                PropertyDecsription info;
                if (!ambientColors.TryGetValue(color.Name, out info))
                {
                    Console.WriteLine("Ambient color:" + color.Name + " not found.");
                    continue;
                }
                info.Info.SetValue(result, color, null);
            }

            foreach (var textColorElement in root.XPathSelectElements("//text/*"))
            {
                var color = ChunkStyle.Create(textColorElement, palette);
                PropertyDecsription info;
                if (!textColors.TryGetValue(color.Name, out info))
                {
                    Console.WriteLine("Text color:" + color.Name + " not found.");
                    continue;
                }
                info.Info.SetValue(result, color, null);
            }

            // Check scheme
            bool valid = true;

            foreach (var color in textColors.Values)
            {
                if (color.Info.GetValue(result, null) == null)
                {
                    Console.WriteLine(color.Attribute.Name + " == null");
                    valid = false;
                }
            }
            foreach (var color in ambientColors.Values)
            {
                if (color.Info.GetValue(result, null) == null)
                {
                    Console.WriteLine(color.Attribute.Name + " == null");
                    valid = false;
                }
            }
            if (!valid)
            {
                throw new InvalidDataException("Scheme " + result.Name + " is not valid.");
            }
            return(result);
        }
Ejemplo n.º 15
0
		void SetStyle (string name, ChunkStyle style)
		{
			styleLookupTable[name] = style;
		}
Ejemplo n.º 16
0
/*		void SetStyle (string name, byte r, byte g, byte b, byte bg_r, byte bg_g, byte bg_b, ChunkProperties properties)
		{
			SetStyle (name, new ChunkStyle (new Gdk.Color (r, g, b), new Gdk.Color (bg_r, bg_g, bg_b), properties));
		}*/
		
		public ChunkStyle GetDefaultChunkStyle ()
		{
			ChunkStyle style;
			if (!styleLookupTable.TryGetValue (DefaultString, out style)) {
				style = new ChunkStyle (GetColorFromDefinition (DefaultString));
				styleLookupTable[DefaultString] = style;
			}
			return style;
		}
Ejemplo n.º 17
0
 void SetStyle(string name, ChunkStyle style)
 {
     styleLookupTable[name] = style;
 }
Ejemplo n.º 18
0
 public void SetChunkStyle(string name, ChunkStyle style)
 {
     SetStyle(name, style);
 }
Ejemplo n.º 19
0
		public static ChunkStyle Create (XElement element, Dictionary<string, Cairo.Color> palette)
		{
			var result = new ChunkStyle ();

			foreach (var node in element.DescendantNodes ()) {
				if (node.NodeType == System.Xml.XmlNodeType.Element) {
					var el = (XElement)node;
					switch (el.Name.LocalName) {
					case "name":
						result.Name = el.Value;
						break;
					case "fore":
						result.Foreground = ColorScheme.ParsePaletteColor (palette, el.Value);
						break;
					case "back":
						result.Background = ColorScheme.ParsePaletteColor (palette, el.Value);
						break;
					case "weight":
						FontWeight weight;
						if (!Enum.TryParse<FontWeight> (el.Value, true, out weight)) 
							throw new InvalidDataException (el.Value + " is no valid text weight values are: " + string.Join (",", Enum.GetNames (typeof(FontWeight))) );
						result.FontWeight = weight;
						break;
					case "style":
						FontStyle style;
						if (!Enum.TryParse<FontStyle> (el.Value, true, out style)) 
							throw new InvalidDataException (el.Value + " is no valid text weight values are: " + string.Join (",", Enum.GetNames (typeof(FontStyle))) );
						result.FontStyle = style;
						break;
					default:
						throw new InvalidDataException ("Invalid element in text color:" + el.Name);
					}
				}
			}

			return result;
		}
Ejemplo n.º 20
0
		public static ChunkStyle Import (string name, ColorScheme.VSSettingColor vsc)
		{
			var textColor = new ChunkStyle ();
			textColor.Name = name;
			if (!string.IsNullOrEmpty (vsc.Foreground) && vsc.Foreground != "0x02000000") {
				textColor.Foreground = ColorScheme.ImportVsColor (vsc.Foreground);
				if (textColor.TransparentForeground && name != "Selected Text" && name != "Selected Text(Inactive)")
					textColor.Foreground = new Cairo.Color (0, 0, 0);
			}
			if (!string.IsNullOrEmpty (vsc.Background) && vsc.Background != "0x02000000")
				textColor.Background = ColorScheme.ImportVsColor (vsc.Background);
			if (vsc.BoldFont)
				textColor.FontWeight = FontWeight.Bold;
			return textColor;
		}
Ejemplo n.º 21
0
			public TextChunk (ChunkStyle style, int offset)
			{
				this.Offset = offset;
				this.ChunkStyle = style;
			}
Ejemplo n.º 22
0
		static ChunkStyle GetChunkStyle (Style style, IEnumerable<Tag> tagStack)
		{
			ChunkStyle result = new ChunkStyle ();
			if (style == null)
				style = new DefaultStyle (null);
			result.Color = style.Default.Color;
			
			foreach (Tag tag in tagStack) {
				//System.Console.WriteLine("'" + tag.Command + "'");
				switch (tag.Command) {
				case "B":
					result.ChunkProperties |= ChunkProperties.Bold;
					break;
				case "SPAN":
					string val;
					if (tag.Arguments.TryGetValue ("style", out val)) {
						ChunkStyle chunkStyle = style.GetChunkStyle (val);
						if (chunkStyle != null) {
							result.Color = chunkStyle.Color;
							result.ChunkProperties |= chunkStyle.ChunkProperties;
						} else {
							throw new Exception ("Style " + val + " not found.");
						}
					}
					if (tag.Arguments.TryGetValue ("foreground", out val))
						result.Color = style.GetColorFromString (val);
					if (tag.Arguments.TryGetValue ("background", out val))
						result.BackgroundColor = style.GetColorFromString (val);
					break;
				case "A":
					result.Link = tag.Arguments["ref"];
					break;
				case "I":
					result.ChunkProperties |= ChunkProperties.Italic;
					break;
				case "U":
					result.ChunkProperties |= ChunkProperties.Underline;
					break;
				}
			}
			return result;
		}
Ejemplo n.º 23
0
		public override ChunkStyle GetStyle (ChunkStyle baseStyle) {
			return baseStyle;
		}