public object VisitColor(XshdColor color)
            {
                HighlightingColor c = null;

                if (def._themedHighlights == null)
                {
                    if (color.Name != null)
                    {
                        c = def.colorDict[color.Name];
                    }
                    else if (color.Foreground == null && color.Background == null && color.Underline == null && color.FontStyle == null && color.FontWeight == null)
                    {
                        return(null);
                    }
                    else
                    {
                        c = new HighlightingColor();
                    }

                    c.Name       = color.Name;
                    c.Foreground = color.Foreground;
                    c.Background = color.Background;
                    c.Underline  = color.Underline;
                    c.FontStyle  = color.FontStyle;
                    c.FontWeight = color.FontWeight;
                }

                return(c);
            }
Ejemplo n.º 2
0
        private static XshdColor ParseThemeColorReference(string colorKey)
        {
            var color = new XshdColor
            {
                Foreground = ParseColorName(colorKey)
            };

            return(color);
        }
Ejemplo n.º 3
0
        static XshdColor ParseNamedColor(XmlReader reader)
        {
            XshdColor color = ParseColorAttributes(reader);

            // check removed: invisible named colors may be useful now that apps can read highlighting data
            //if (color.Foreground == null && color.FontWeight == null && color.FontStyle == null)
            //	throw Error(reader, "A named color must have at least one element.");
            color.Name = reader.GetAttribute("name");
            CheckElementName(reader, color.Name);
            color.ExampleText = reader.GetAttribute("exampleText");
            return(color);
        }
Ejemplo n.º 4
0
        private static XshdColor ParseColorAttributes(XmlReader reader)
        {
            var color = new XshdColor();

            SetPosition(color, reader);

            color.Foreground = ParseColorName(reader.GetAttribute("name"));
            color.Background = ParseColor(reader.GetAttribute("background"));
            color.FontWeight = ParseFontWeight(reader.GetAttribute("fontWeight"));
            color.FontStyle  = ParseFontStyle(reader.GetAttribute("fontStyle"));
            color.Underline  = reader.GetBoolAttribute("underline");
            return(color);
        }
Ejemplo n.º 5
0
        public NamedColorHighlightingItem(IHighlightingItem defaultText, XshdColor color)
        {
            if (defaultText == null)
            {
                throw new ArgumentNullException("defaultText");
            }
            if (color == null)
            {
                throw new ArgumentNullException("color");
            }

            this.defaultText = defaultText;
            this.color       = color;
        }
Ejemplo n.º 6
0
        static XshdColor ParseColorAttributes(XmlReader reader)
        {
            XshdColor color = new XshdColor();

            SetPosition(color, reader);
            IXmlLineInfo position = reader as IXmlLineInfo;

            color.Foreground = ParseColor(position, reader.GetAttribute("foreground"));
            color.Background = ParseColor(position, reader.GetAttribute("background"));
            color.FontWeight = ParseFontWeight(reader.GetAttribute("fontWeight"));
            color.FontStyle  = ParseFontStyle(reader.GetAttribute("fontStyle"));
            color.Underline  = reader.GetBoolAttribute("underline");
            return(color);
        }
            public object VisitColor(XshdColor color)
            {
                if (color.Name != null)
                {
                    if (color.Name.Length == 0)
                    {
                        throw Error(color, "Name must not be the empty string");
                    }

                    if (def.colorDict.ContainsKey(color.Name))
                    {
                        throw Error(color, "Duplicate color name '" + color.Name + "'.");
                    }

                    def.colorDict.Add(color.Name, new HighlightingColor());
                }
                return(null);
            }
        /// <summary>
        /// 保持しているInfoに従い、Xshdファイルを生成します
        /// </summary>
        /// <returns>true:成功, false:失敗</returns>
        private bool CreateXshdFile()
        {
            Logger.Info(CLASS_NAME, "CreateXshdFile", "start");

            XshdSyntaxDefinition def = new XshdSyntaxDefinition();

            def.Name = "TXT";
            def.Extensions.Add(".txt"); // .txtファイルのみ対象としているので、将来拡張するならここをいじる必要がある

            // keywordは勝手に正規表現で前後に改行コードが含まれてしまうため、見出し文字列等以外には適さない
            // ★設定で回避できる? 要調査、現状は動くことを優先して下記設定とする
            // そのため、日本語文章を対象としていることから、類語・検索語はXshdRuleSetに登録する
            XshdRuleSet xshdRuleSet = new XshdRuleSet();

            int i = 0;

            foreach (TextHighlightInfo info in _infos)
            {
                if (IsInfoCorrect(info) == false)
                {
                    Logger.Error(CLASS_NAME, "CreateXshdFile", $"info is null or incorrect! index:[{i}]");
                    continue;
                }

                XshdColor color = new XshdColor
                {
                    // Name = "keywordColor", // 別に名前は何でもいい
                    Foreground = info.ForeGround,
                    Background = info.BackGrouond,
                    // 検索結果表示を太字にする
                    //todo:設定で持たせるべきかもしれない
                    FontWeight = System.Windows.FontWeights.Bold,
                    //FontStyle = System.Windows.FontStyles.Italic これは斜体になる
                };

                string colorName = "keyword";

                // 文字毎に異なる背景色を設定したいため、ここでColorおよびColorRefのNameを紐付ける必要がある
                // 大量にあることを想定し、StringBuilderで結合する
                StringBuilder sb = new StringBuilder(colorName);
                sb.Append(i.ToString());

                color.Name = sb.ToString();
                XshdReference <XshdColor> colorRef = new XshdReference <XshdColor>(null, color.Name);

                string target = info.TargetWord;
                if (string.IsNullOrEmpty(target))
                {
                    Logger.Error(CLASS_NAME, "CreateXshdFile", $"target is null! target:[{target}]");
                    continue;
                }

                XshdRule rule = new XshdRule
                {
                    ColorReference = colorRef,
                    Regex          = target // 正規表現で持たせる必要があるが、文字単位なのでそのまま渡して問題ない
                };

                xshdRuleSet.Elements.Add(rule);

                // 追加したいモノは追加した
                def.Elements.Add(color);
                System.Threading.Interlocked.Increment(ref i);
            }

            def.Elements.Add(xshdRuleSet);

            return(WriteXshdFile(def));
        }
 public object VisitColor(XshdColor color)
 {
     foundColors.Add(color);
     return(null);
 }