当前位置: 首页>>代码示例>>C#>>正文


C# DrawingContext.DrawGlyphRun方法代码示例

本文整理汇总了C#中System.Windows.Media.DrawingContext.DrawGlyphRun方法的典型用法代码示例。如果您正苦于以下问题:C# DrawingContext.DrawGlyphRun方法的具体用法?C# DrawingContext.DrawGlyphRun怎么用?C# DrawingContext.DrawGlyphRun使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Media.DrawingContext的用法示例。


在下文中一共展示了DrawingContext.DrawGlyphRun方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Draw

 public override void Draw(DrawingContext drawingContext, double scale, double x, double y)
 {
     // Draw character at given position.
     var typeface = this.Character.Font;
     var glyphIndex = typeface.CharacterToGlyphMap[this.Character.Character];
     var glyphRun = new GlyphRun(typeface, 0, false, this.Character.Size * scale,
         new ushort[] { glyphIndex }, new Point(x * scale, y * scale),
         new double[] { typeface.AdvanceWidths[glyphIndex] }, null, null, null, null, null, null);
     drawingContext.DrawGlyphRun(this.Foreground ?? Brushes.Black, glyphRun);
 }
开发者ID:Civa,项目名称:Zenith,代码行数:10,代码来源:CharBox.cs

示例2: OnRender

 protected override void OnRender(DrawingContext drawingContext)
 {
     if (myRun == null)
         return;
     Point offset = Point.Empty;
     float slack = Width - myRun.Width;
     if (myTextAlignment == TextAlignment.Right)
         offset.X = slack;
     else if (myTextAlignment == TextAlignment.Center)
         offset.X = slack / 2;
     drawingContext.PushTranslate(offset.X, offset.Y);
     drawingContext.DrawGlyphRun(ForeBrush, myRun);
     drawingContext.Pop();
 }
开发者ID:koush,项目名称:Xaml,代码行数:14,代码来源:Label.cs

示例3: _UpdateHighlightForeground

        private void _UpdateHighlightForeground(DrawingContext dc, ArrayList highlights)
        {
            foreach (FixedHighlight fh in highlights)
            {
                Brush fg = null;

                if (fh.HighlightType == FixedHighlightType.None)
                {
#if NEVER
                    // use this code if you want to see unrecognized highlights
                    bg = Brushes.Yellow;
#else
                    continue;
#endif
                }

                Glyphs g = fh.Glyphs;
                if (g == null)
                {
                    continue;
                }


                Rect clipRect = fh.ComputeDesignRect();

                if (clipRect == Rect.Empty)
                {
                    continue;
                }

                GeneralTransform transform = fh.Element.TransformToAncestor(_page);

                Transform t = transform.AffineTransform;
                if (t != null)
                {
                    dc.PushTransform(t);
                }
                else
                {
                    dc.PushTransform(Transform.Identity);
                }

                dc.PushClip(new RectangleGeometry(clipRect));

                if (fh.HighlightType == FixedHighlightType.TextSelection)
                {
                    fg = SelectionHighlightInfo.ForegroundBrush;
                } 
                else if (fh.HighlightType == FixedHighlightType.AnnotationHighlight)
                {
                    fg = fh.ForegroundBrush;
                }
                // can add cases for new types of highlights

                GlyphRun gr = g.ToGlyphRun();

                if (fg == null)
                {
                    fg = g.Fill;
                }

                dc.PushGuidelineY1(gr.BaselineOrigin.Y);
                dc.PushClip(g.Clip);
                dc.DrawGlyphRun(fg, gr);
                dc.Pop(); // Glyphs clip
                dc.Pop(); // Guideline
                dc.Pop(); // clip
                dc.Pop(); // transform
            }
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:70,代码来源:HighlightVisual.cs

示例4: Draw

			public override void Draw(DrawingContext drawingContext, Point origin, InvertAxes inversion) {
				foreach (var entry in entries) {
					if (entry.Item2 == null)
						continue;
					if (entry.Item3 == entry.Item1.Length) // All whitespace, no need to render
						continue;

					var textRun = entry.Item1;
					var glyphRun = entry.Item2;
					var textProps = textRun.Properties;

					var newRun = Clone(glyphRun, new Point {
						X = origin.X + glyphRun.BaselineOrigin.X,
						Y = (int)(origin.Y + glyphRun.GlyphTypeface.Baseline * textProps.FontRenderingEmSize)
					});
					if (_textFormattingMode != null)
						_textFormattingMode.SetValue(glyphRun, mode);

					var box = newRun.ComputeAlignmentBox();
					if (textProps.BackgroundBrush != null) {
						drawingContext.DrawRectangle(
							textProps.BackgroundBrush, null,
							new Rect(origin, box.Size));
					}

					drawingContext.DrawGlyphRun(textProps.ForegroundBrush, newRun);

					if (textProps.TextDecorations != null)
						foreach (var deco in textProps.TextDecorations) {
							var thickness = Math.Round(glyphRun.GlyphTypeface.UnderlineThickness * textProps.FontRenderingEmSize);
							var pos = glyphRun.GlyphTypeface.UnderlinePosition -
							          glyphRun.GlyphTypeface.Baseline +
							          glyphRun.GlyphTypeface.Height;
							pos = Math.Round(pos * textProps.FontRenderingEmSize) + thickness / 2;

							var pen = new Pen(textProps.ForegroundBrush, thickness);
							drawingContext.DrawLine(pen,
								new Point(newRun.BaselineOrigin.X, newRun.BaselineOrigin.Y + pos),
								new Point(newRun.BaselineOrigin.X + box.Width, newRun.BaselineOrigin.Y + pos));
						}
				}
			}
开发者ID:manojdjoshi,项目名称:dnSpy,代码行数:42,代码来源:GlyphRunFormatter.cs

示例5: DrawVerticalLinesText

        private void DrawVerticalLinesText(DrawingContext dc, double initialPos, double stepSize)
        {
            double previousTextPos = initialPos;
            while (initialPos < MaxX)
            {
                initialPos += stepSize;

                System.Windows.Point p0 = new System.Windows.Point(initialPos, MinY);
                p0 = CurveCoordsToScreen(ref p0);
                p0.X = Math.Truncate(p0.X);

                if (Math.Abs(p0.X - previousTextPos) > 40)
                {
                    p0.X = Math.Truncate(p0.X) + 0.5;
                    // Draw the tick
                    System.Windows.Point p1 = new System.Windows.Point(p0.X, ActualHeight);
                    p0 = new System.Windows.Point(p0.X, ActualHeight - 3);
                    dc.DrawLine(gridLinePen, p0, p1);

                    p0.X = Math.Truncate(p0.X - 3);
                    glyphs.UnicodeString = String.Format("{0:0.###}", initialPos);
                    glyphs.OriginX = p0.X;
                    glyphs.OriginY = 12;

                    dc.DrawGlyphRun(textBrush, glyphs.ToGlyphRun());
                    previousTextPos = p0.X;
                }

            }
        }
开发者ID:juancampa,项目名称:Gearset,代码行数:30,代码来源:GridRuler.cs

示例6: OnRender

        protected override void OnRender(DrawingContext dc)
        {
            Brush bgBrush = Background;
            dc.DrawRectangle(bgBrush, null, new Rect(RenderSize));

            if (Items == null)
            {
                return;
            }

            try
            {
                //long tickStart = DateTime.Now.Ticks; //パフォーマンス計測用
                double selfLeft = Canvas.GetLeft(this);

                // Items 設定時に CreateDrawTextList を行うと、番組表に複数のタブを設定していると
                // 全てのタブの GlyphRun を一度に生成しようとするので、最初の表示までに多くの時間がかかる。
                // 表示しようとするタブのみ GlyphRun を行うことで、最初の応答時間を削減することにする。
                CreateDrawTextList();
                //long tickGlyphRun = DateTime.Now.Ticks; //パフォーマンス計測用

                foreach (ProgramViewItem info in Items)
                {
                    dc.DrawRectangle(bgBrush, null, new Rect(info.LeftPos - selfLeft, info.TopPos, info.Width, 1));
                    dc.DrawRectangle(bgBrush, null, new Rect(info.LeftPos - selfLeft, info.TopPos + info.Height, info.Width, 1));
                    if (info.Height > 1)
                    {
                        dc.DrawRectangle(info.ContentColor, null, new Rect(info.LeftPos - selfLeft, info.TopPos + 0.5, info.Width - 1, info.Height - 0.5));
                        if (textDrawDict.ContainsKey(info))
                        {
                            dc.PushClip(new RectangleGeometry(new Rect(info.LeftPos - selfLeft, info.TopPos + 0.5, info.Width - 1, info.Height - 0.5)));
                            foreach (TextDrawItem txtinfo in textDrawDict[info])
                            {
                                dc.DrawGlyphRun(txtinfo.FontColor, txtinfo.Text);
                            }
                            dc.Pop();
                        }
                    }
                }

                // EpgViewPanel は複数に分けて Render するので、最後のパネルが Render し終わったら
                // 些細なメモリ節約のために cache をクリアする
                ItemFontNormal.ClearCache();
                ItemFontTitle.ClearCache();

                //パフォーマンス計測用
                //long tickDraw = DateTime.Now.Ticks;
                //Console.Write("GlyphRun = " + Math.Round((tickGlyphRun - tickStart)/10000D).ToString()
                //    + ", Draw = " + Math.Round((tickDraw - tickGlyphRun)/10000D).ToString()
                //    + ", Total = " + Math.Round((tickDraw-tickStart)/10000D).ToString() + "\n");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
            }
        }
开发者ID:xceza7,项目名称:EDCB,代码行数:56,代码来源:EpgViewPanel.cs

示例7: _drawGlyphRun

 // draws a glyphrun including any defined highlights
 private void _drawGlyphRun(DrawingContext dc, GlyphRun run, Brush brush) {
    if (_highlights == null) {
       dc.DrawGlyphRun(brush, run);
       return;
    }
    var max = run.GlyphIndices.Count;
    var pos = 0;
    var k = 0;
    while (k < _highlights.Count) {
       var h1 = _highlights[k].Start;
       var h2 = h1 + _highlights[k].Length;
       if (h1 > pos) {
          _drawGlyphRun(dc, run, brush, pos, h1 - pos);
       }
       _drawGlyphRun(dc, run, _highlights[k].Foreground, h1, h2 - h1);
       pos = h2;
       k++;
    }
    if (pos < max) {
       _drawGlyphRun(dc, run, brush, pos, max - pos);
    }
 }
开发者ID:borkaborka,项目名称:gmit,代码行数:23,代码来源:TextGlyph.cs

示例8: OnRender

        protected override void OnRender(DrawingContext dc)
        {
            dc.DrawRectangle(Background, null, new Rect(RenderSize));
            this.VisualTextRenderingMode = TextRenderingMode.ClearType;
            this.VisualTextHintingMode = TextHintingMode.Fixed;
            this.UseLayoutRounding = true;

            if (Items == null)
            {
                return;
            }
            
            try
            {
                double sizeNormal = Settings.Instance.FontSize;
                double sizeTitle = Settings.Instance.FontSizeTitle;
                Brush bgBrush = Background;
                foreach (ProgramViewItem info in Items)
                {
                    dc.DrawRectangle(bgBrush, null, new Rect(info.LeftPos, info.TopPos, info.Width, 1));
                    dc.DrawRectangle(bgBrush, null, new Rect(info.LeftPos, info.TopPos + info.Height, info.Width, 1));
                    if (info.Height > 1)
                    {
                        dc.DrawRectangle(info.ContentColor, null, new Rect(info.LeftPos + 0, info.TopPos + 0.5, info.Width - 1, info.Height - 0.5));
                        if (textDrawDict.ContainsKey(info))
                        {
                            dc.PushClip(new RectangleGeometry(new Rect(info.LeftPos + 0, info.TopPos + 0.5, info.Width - 1, info.Height - 0.5)));
                            foreach (TextDrawItem txtinfo in textDrawDict[info])
                            {
                                dc.DrawGlyphRun(txtinfo.FontColor, txtinfo.Text);
                            }
                            dc.Pop();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
            }
        }
开发者ID:lokippc,项目名称:EDCB,代码行数:41,代码来源:EpgViewPanel.cs

示例9: RenderText

        protected bool RenderText(String text, DrawingContext dc, GlyphTypeface glyphType, double fontSize, double maxWidth, double maxHeight, double x, double y, ref double useHeight)
        {
            if (maxHeight < fontSize + 2)
            {
                useHeight = 0;
                return false;
            }
            double totalHeight = 0;

            string[] lineText = text.Replace("\r", "").Split('\n');
            foreach (string line in lineText)
            {
                totalHeight += Math.Floor(2 + fontSize);
                List<ushort> glyphIndexes = new List<ushort>();
                List<double> advanceWidths = new List<double>();
                double totalWidth = 0;
                for (int n = 0; n < line.Length; n++)
                {
                    ushort glyphIndex = glyphType.CharacterToGlyphMap[line[n]];
                    double width = glyphType.AdvanceWidths[glyphIndex] * fontSize;
                    if (totalWidth + width > maxWidth)
                    {
                        if (totalHeight + fontSize > maxHeight)
                        {
                            //次の行無理
                            glyphIndex = glyphType.CharacterToGlyphMap['…'];
                            glyphIndexes[glyphIndexes.Count - 1] = glyphIndex;
                            advanceWidths[advanceWidths.Count - 1] = width;

                            Point origin = new Point(x + 2, y + totalHeight);
                            GlyphRun glyphRun = new GlyphRun(glyphType, 0, false, fontSize,
                                glyphIndexes, origin, advanceWidths, null, null, null, null,
                                null, null);

                            dc.DrawGlyphRun(Brushes.Black, glyphRun);

                            useHeight = totalHeight;
                            return false;
                        }
                        else
                        {
                            //次の行いけるので今までの分出力
                            //次の行いける
                            Point origin = new Point(x + 2, y + totalHeight);
                            GlyphRun glyphRun = new GlyphRun(glyphType, 0, false, fontSize,
                                glyphIndexes, origin, advanceWidths, null, null, null, null,
                                null, null);

                            dc.DrawGlyphRun(Brushes.Black, glyphRun);
                            totalHeight += fontSize + 2;
                            glyphIndexes = new List<ushort>();
                            advanceWidths = new List<double>();
                            totalWidth = 0;
                        }
                    }
                    glyphIndexes.Add(glyphIndex);
                    advanceWidths.Add(width);
                    totalWidth += width;
                }
                if (glyphIndexes.Count > 0)
                {
                    Point origin = new Point(x + 2, y + totalHeight);
                    GlyphRun glyphRun = new GlyphRun(glyphType, 0, false, fontSize,
                        glyphIndexes, origin, advanceWidths, null, null, null, null,
                        null, null);

                    dc.DrawGlyphRun(Brushes.Black, glyphRun);
                }
                //高さ確認
                if (totalHeight + fontSize > maxHeight)
                {
                    //これ以上は無理
                    useHeight = totalHeight;
                    return false;
                }

            }
            useHeight = Math.Floor(totalHeight);
            return true;
        }
开发者ID:epgdatacapbon,项目名称:EDCB,代码行数:80,代码来源:TunerReservePanel.cs

示例10: DrawActorLabel

        private static void DrawActorLabel(DrawingContext dc, CanvasData canvas, RadarObject radarObject, Brush brush)
        {
            var text = radarObject.CachedActorName;

            if (text == null)
                return;

            const int textSize = 12;
            const int charLimit = 20;

            if (text.Length > charLimit)
                text = text.Substring(0, charLimit);

            // FormattedText is very slow, so instead create text manually with glyphs
            var glyphRun = DrawingUtilities.CreateGlyphRun(text, textSize, radarObject.Point);
            dc.DrawGlyphRun(brush, glyphRun);
        }
开发者ID:mythsya,项目名称:db-plugins,代码行数:17,代码来源:RadarCanvas.cs

示例11: DrawPointsOfInterest

        private void DrawPointsOfInterest(DrawingContext dc, CanvasData canvas)
        {
            try
            {
                foreach (var marker in AdvDia.CurrentWorldMarkers.Where(m => m.Id >= 0 && m.Id < 200))
                {
                    dc.DrawEllipse(Brushes.Yellow, RadarResources.GridPen, marker.Position.ToCanvasPoint(), 5, 5);
                    var textPoint = marker.Position.ToCanvasPoint();
                    textPoint.Y = textPoint.Y + 32;
                    var glyphRun = DrawingUtilities.CreateGlyphRun(marker.NameHash.ToString(), 8, textPoint);
                    dc.DrawGlyphRun(Brushes.Yellow, glyphRun);

                    var toObjectivePen = new Pen(Brushes.Yellow, 0.2);
                    dc.DrawLine(toObjectivePen, canvas.Center, marker.Position.ToCanvasPoint());
                }

            }
            catch (Exception ex)
            {
                Logger.Debug("Exception in RadarUI.DrawPointsOfInterest(). {0} {1} {2}", ex.Message, ex.InnerException, ex);
            }
        }
开发者ID:mythsya,项目名称:db-plugins,代码行数:22,代码来源:RadarCanvas.cs

示例12: Draw

        internal Rect Draw(
            DrawingContext      drawingContext,
            double              x,
            double              y,
            bool                visiCodePath
            )
        {
            if (Length <= 0 || this.Ghost)
            {
                return Rect.Empty;  // nothing to draw
            }

            Brush foregroundBrush = TextRun.Properties.ForegroundBrush;

            if(visiCodePath && foregroundBrush is SolidColorBrush)
            {
                Color color = ((SolidColorBrush)foregroundBrush).Color;
                foregroundBrush = new SolidColorBrush(Color.FromArgb(
                    (byte)(color.A>>2), // * 0.25
                    color.R,
                    color.G,
                    color.B
                    ));
            }

            Rect inkBoundingBox;

            IList<double> displayGlyphAdvances;
            if (_textFormatterImp.TextFormattingMode == TextFormattingMode.Ideal)
            {
                displayGlyphAdvances = new ThousandthOfEmRealDoubles(EmSize, NominalAdvances.Length);
                for (int i = 0; i < displayGlyphAdvances.Count; i++)
                {
                    // convert ideal glyph advance width to real width for displaying.
                    displayGlyphAdvances[i] = _textFormatterImp.IdealToReal(NominalAdvances[i]);
                }
            }
            else
            {
                displayGlyphAdvances = new List<double>(NominalAdvances.Length);
                for (int i = 0; i < NominalAdvances.Length; i++)
                {
                    // convert ideal glyph advance width to real width for displaying.
                    displayGlyphAdvances.Add(_textFormatterImp.IdealToReal(NominalAdvances[i]));
                }
            }

            CharacterBufferRange charBufferRange = new CharacterBufferRange(CharBufferReference, Length);

            GlyphTypeface glyphTypeface = Typeface.TryGetGlyphTypeface();
            Invariant.Assert(glyphTypeface != null);

            GlyphRun glyphRun = glyphTypeface.ComputeUnshapedGlyphRun(
                new Point(x, y),
                charBufferRange,
                displayGlyphAdvances,
                EmSize,
                TextRun.Properties.FontHintingEmSize,
                Typeface.NullFont,
                CultureMapper.GetSpecificCulture(TextRun.Properties.CultureInfo),
                null,  // device font name
                _textFormatterImp.TextFormattingMode
              );

            if (glyphRun != null)
            {
                inkBoundingBox = glyphRun.ComputeInkBoundingBox();
            }
            else
            {
                inkBoundingBox = Rect.Empty;
            }

            if (!inkBoundingBox.IsEmpty)
            {
                // glyph run's ink bounding box is relative to its origin
                inkBoundingBox.X += glyphRun.BaselineOrigin.X;
                inkBoundingBox.Y += glyphRun.BaselineOrigin.Y;
            }

            if (drawingContext != null)
            {
                if (glyphRun != null)
                {
                    glyphRun.EmitBackground(drawingContext, TextRun.Properties.BackgroundBrush);
                    drawingContext.DrawGlyphRun(foregroundBrush, glyphRun);
                }


                // draw underline here
                if (Underline != null)
                {
                    // Determine number of characters to underline. We don't underline trailing spaces
                    // if the TrimTrailingUnderline flag is set.
                    int underlineLength = Length;
                    if (TrimTrailingUnderline)
                    {
                        while (underlineLength > 0 && IsSpace(charBufferRange[underlineLength - 1]))
                        {
                            --underlineLength;
//.........这里部分代码省略.........
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:101,代码来源:SimpleTextLine.cs

示例13: DrawText

        public static void DrawText(DrawingContext dc, string text, double x, double y, double maxWidth, bool bEnableDotDotDot, SolidColorBrush colorBrush)
        {
            ushort[] glyphIndexes = null;
            double[] advanceWidths = null;

            ushort[] tempGlyphIndexes = new ushort[text.Length];
            double[] tempAdvanceWidths = new double[text.Length];

            double totalTextWidth = 0;
            double maxHeight = 0.0f;

            bool needDoTDotDot = false;
            double desiredTextWidth = maxWidth;
            int charIndex = 0;

            // Build the text info and measure the final text width
            for (; charIndex < text.Length; charIndex++)
            {
                ushort glyphIndex = _glyphTypeface.CharacterToGlyphMap[text[charIndex]];
                tempGlyphIndexes[charIndex] = glyphIndex;

                double width = _glyphTypeface.AdvanceWidths[glyphIndex] * _cFontSize;
                tempAdvanceWidths[charIndex] = width;

                maxHeight = Math.Max(_glyphTypeface.AdvanceHeights[glyphIndex] * _cFontSize, maxHeight);

                totalTextWidth += width;

                if (totalTextWidth > desiredTextWidth)
                {
                    //we need to clip the text since it doesn't fit the allowed width
                    //do a second measurement pass
                    needDoTDotDot = true;
                    break;
                }
            }

            if (bEnableDotDotDot && needDoTDotDot)
            {
                ushort suffixGlyphIndex = _glyphTypeface.CharacterToGlyphMap['.'];
                double suffixWidth = _glyphTypeface.AdvanceWidths[suffixGlyphIndex] * _cFontSize;

                desiredTextWidth -= suffixWidth * 3;

                for (; charIndex > 0; charIndex--)
                {
                    double removedCharacterWidth = tempAdvanceWidths[charIndex];

                    totalTextWidth -= removedCharacterWidth;

                    if (totalTextWidth <= desiredTextWidth)
                    {
                        charIndex--;
                        break;
                    }
                }

                int finalNumCharacters = charIndex + 1 + 3;

                glyphIndexes = new ushort[finalNumCharacters];
                advanceWidths = new double[finalNumCharacters];

                Array.Copy(tempGlyphIndexes, glyphIndexes, charIndex + 1);
                Array.Copy(tempAdvanceWidths, advanceWidths, charIndex + 1);

                for (int i = charIndex + 1; i < finalNumCharacters; ++i)
                {
                    glyphIndexes[i] = suffixGlyphIndex;
                    advanceWidths[i] = suffixWidth;
                }
            }
            else
            {
                glyphIndexes = tempGlyphIndexes;
                advanceWidths = tempAdvanceWidths;
            }

            double roundedX = Math.Round(x);
            double roundedY = Math.Round(y + maxHeight);

            GlyphRun gr = new GlyphRun(
                _glyphTypeface,
                0,       // Bi-directional nesting level
                false,   // isSideways
                _cFontSize,      // pt size
                glyphIndexes,   // glyphIndices
                new Point(roundedX, roundedY),           // baselineOrigin
                advanceWidths,  // advanceWidths
                null,    // glyphOffsets
                null,    // characters
                null,    // deviceFontName
                null,    // clusterMap
                null,    // caretStops
                null);   // xmlLanguage

            dc.DrawGlyphRun(colorBrush, gr);
        }
开发者ID:yass007,项目名称:FASTBuildMonitor,代码行数:97,代码来源:TextUtils.cs

示例14: OnRender

        protected override void OnRender(DrawingContext drawingContext)
        {
            if (ParentMap != null)
            {
                var bounds = ParentMap.ViewportTransform.Inverse.TransformBounds(new Rect(ParentMap.RenderSize));
                var start = ParentMap.MapTransform.Transform(new Point(bounds.X, bounds.Y));
                var end = ParentMap.MapTransform.Transform(new Point(bounds.X + bounds.Width, bounds.Y + bounds.Height));
                var minSpacing = MinLineSpacing * 360d / (Math.Pow(2d, ParentMap.ZoomLevel) * TileSource.TileSize);
                var spacing = LineSpacings[LineSpacings.Length - 1];

                if (spacing >= minSpacing)
                {
                    spacing = LineSpacings.FirstOrDefault(s => s >= minSpacing);
                }

                var labelFormat = spacing < 1d ? "{0} {1}°{2:00}'" : "{0} {1}°";
                var labelStart = new Location(
                    Math.Ceiling(start.Latitude / spacing) * spacing,
                    Math.Ceiling(start.Longitude / spacing) * spacing);

                var latLabels = new List<Label>((int)((end.Latitude - labelStart.Latitude) / spacing) + 1);
                var lonLabels = new List<Label>((int)((end.Longitude - labelStart.Longitude) / spacing) + 1);

                for (var lat = labelStart.Latitude; lat <= end.Latitude; lat += spacing)
                {
                    latLabels.Add(new Label(lat, CoordinateString(lat, labelFormat, "NS")));

                    drawingContext.DrawLine(Pen,
                        ParentMap.LocationToViewportPoint(new Location(lat, start.Longitude)),
                        ParentMap.LocationToViewportPoint(new Location(lat, end.Longitude)));
                }

                for (var lon = labelStart.Longitude; lon <= end.Longitude; lon += spacing)
                {
                    lonLabels.Add(new Label(lon, CoordinateString(Location.NormalizeLongitude(lon), labelFormat, "EW")));

                    drawingContext.DrawLine(Pen,
                        ParentMap.LocationToViewportPoint(new Location(start.Latitude, lon)),
                        ParentMap.LocationToViewportPoint(new Location(end.Latitude, lon)));
                }

                if (Foreground != null && Foreground != Brushes.Transparent && latLabels.Count > 0 && lonLabels.Count > 0)
                {
                    var latLabelOrigin = new Point(StrokeThickness / 2d + 2d, -StrokeThickness / 2d - FontSize / 4d);
                    var lonLabelOrigin = new Point(StrokeThickness / 2d + 2d, StrokeThickness / 2d + FontSize);
                    var transform = Matrix.Identity;
                    transform.Rotate(ParentMap.Heading);

                    foreach (var latLabel in latLabels)
                    {
                        foreach (var lonLabel in lonLabels)
                        {
                            GlyphRun latGlyphRun;
                            GlyphRun lonGlyphRun;

                            if (!glyphRuns.TryGetValue(latLabel.Text, out latGlyphRun))
                            {
                                latGlyphRun = GlyphRunText.Create(latLabel.Text, Typeface, FontSize, latLabelOrigin);
                                glyphRuns.Add(latLabel.Text, latGlyphRun);
                            }

                            if (!glyphRuns.TryGetValue(lonLabel.Text, out lonGlyphRun))
                            {
                                lonGlyphRun = GlyphRunText.Create(lonLabel.Text, Typeface, FontSize, lonLabelOrigin);
                                glyphRuns.Add(lonLabel.Text, lonGlyphRun);
                            }

                            var position = ParentMap.LocationToViewportPoint(new Location(latLabel.Position, lonLabel.Position));

                            drawingContext.PushTransform(new MatrixTransform(
                                transform.M11, transform.M12, transform.M21, transform.M22, position.X, position.Y));

                            drawingContext.DrawGlyphRun(Foreground, latGlyphRun);
                            drawingContext.DrawGlyphRun(Foreground, lonGlyphRun);
                            drawingContext.Pop();
                        }
                    }

                    var removeKeys = glyphRuns.Keys.Where(k => !latLabels.Any(l => l.Text == k) && !lonLabels.Any(l => l.Text == k));

                    foreach (var key in removeKeys.ToList())
                    {
                        glyphRuns.Remove(key);
                    }
                }
                else
                {
                    glyphRuns.Clear();
                }
            }
        }
开发者ID:bhanu475,项目名称:XamlMapControl,代码行数:91,代码来源:MapGraticule.WPF.cs

示例15: OnRender

 protected override void OnRender(DrawingContext drawingContext)
 {
     if (CheckGlyphRun())
     {
         var location = outline.Bounds.Location;
         drawingContext.PushTransform(new TranslateTransform(-location.X, -location.Y));
         drawingContext.DrawGeometry(Background, null, outline);
         drawingContext.DrawGlyphRun(Foreground, glyphRun);
     }
 }
开发者ID:huoxudong125,项目名称:XamlMapControl,代码行数:10,代码来源:OutlinedText.cs


注:本文中的System.Windows.Media.DrawingContext.DrawGlyphRun方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。