Esempio n. 1
0
        private IHighlighter CreateHighlighterFromNode(XmlNode highlighterNode)
        {
            var ret = new CommonHighlighter();

            if (highlighterNode.HasChildNodes)
            {
                Int32 idx = 0;
                foreach (XmlNode child in highlighterNode.SelectNodes("style"))
                {
                    var style = new HighlightStyle();
                    if (child.HasChildNodes)
                    {
                        foreach (XmlNode grandchild in child.ChildNodes)
                        {
                            if (grandchild.NodeType == XmlNodeType.Comment)
                            {
                                continue;
                            }
                            switch (grandchild.Name)
                            {
                            case "foreground":
                                style.Foreground = CommonUtilities.ColorFromHexString(grandchild.InnerText);
                                break;

                            case "background":
                                style.Background = CommonUtilities.ColorFromHexString(grandchild.InnerText);
                                break;

                            case "fontstyle":
                                if (_fontStyleMap.ContainsKey(grandchild.InnerText))
                                {
                                    style.FontStyle = _fontStyleMap[grandchild.InnerText];
                                }
                                break;

                            case "fontweight":
                                if (_fontWeightMap.ContainsKey(grandchild.InnerText))
                                {
                                    style.FontWeight = _fontWeightMap[grandchild.InnerText];
                                }
                                break;

                            case "fontstretch":
                                if (_fontStretchMap.ContainsKey(grandchild.InnerText))
                                {
                                    style.FontStretch = _fontStretchMap[grandchild.InnerText];
                                }
                                break;

                            default:
                                break;
                            }
                        }
                    }
                    ret.StyleMap.Add(idx, style);
                    ++idx;
                }
            }
            return(ret);
        }
Esempio n. 2
0
        public void Render(DrawingContext drawingContext, RenderContext renderContext)
        {
            Int32         lineCount       = _editor.Document.LineCount;
            Int32         lineNumberCount = GetLineNumberCount(lineCount);
            Typeface      typeface        = TypefaceGenerator.GetInstance().GenerateTypeface(_editor.GlyphOption.FontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal);
            GlyphTypeface glyphTypeface   = TypefaceGenerator.GetInstance().GenerateGlyphTypeface(_editor.GlyphOption.FontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal);
            UInt16        indice          = glyphTypeface.CharacterToGlyphMap['0'];
            Double        characterWidth  = glyphTypeface.AdvanceWidths[indice] * _editor.GlyphOption.FontSize;
            Double        characterHeight = glyphTypeface.AdvanceHeights[indice] * _editor.GlyphOption.FontSize;
            Double        maxNumberWidth  = Math.Max(lineNumberCount * characterWidth, 3 * characterWidth);
            Point         renderOffset    = new Point(renderContext.Offset.X - _editor.HorizontalOffset, _editor._lineRenderer.RenderOffset.Y + _editor.Padding.Top);
            var           brush           = new SolidColorBrush(CommonUtilities.ColorFromHexString("#FF7D7D7D"));

            foreach (VisualLine visualLine in _editor._lineRenderer.VisibleLines)
            {
                var   formattedText      = new FormattedText(visualLine.Line.LineNumber.ToString(), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeface, _editor.GlyphOption.FontSize, brush);
                Point actualRenderOffset = renderOffset;
                actualRenderOffset.X += maxNumberWidth - formattedText.Width;
                actualRenderOffset.Y += (_editor.GlyphOption.LineHeight - characterHeight);
                drawingContext.DrawText(formattedText, actualRenderOffset);
                renderOffset.Y += _editor.GlyphOption.LineHeight;
            }
            drawingContext.DrawLine(new Pen(brush, 2.0), new Point(_editor._lineRenderer.RenderOffset.X + maxNumberWidth + 5.0, _editor._lineRenderer.RenderOffset.Y), new Point(_editor._lineRenderer.RenderOffset.X + maxNumberWidth + 5.0, 2000.0));

            RenderWidth = maxNumberWidth + 10.0;

            renderContext.PushTranslation(RenderWidth, 0.0);
        }