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


C# IRenderContext.DrawText方法代码示例

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


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

示例1: Render

        /// <summary>
        ///     Renders the series on the specified render context.
        /// </summary>
        /// <param name="rc">The rendering context.</param>
        /// <param name="model">The model.</param>
        public override void Render(IRenderContext rc, PlotModel model)
        {
            if (this.XAxis == null)
            {
                return;
            }

            this.symbolPosition = model.PlotArea.Bottom;
            this.symbolSize = rc.MeasureText(this.Symbol, this.FontFamily, this.FontSize);
            foreach (var v in this.Values)
            {
                if (double.IsNaN(v) || v < this.XAxis.ActualMinimum || v > this.XAxis.ActualMaximum)
                {
                    continue;
                }

                double x = this.XAxis.Transform(v);
                rc.DrawText(
                    new ScreenPoint(x, this.symbolPosition),
                    this.Symbol,
                    this.Color,
                    this.FontFamily,
                    this.FontSize,
                    FontWeights.Normal,
                    0,
                    HorizontalAlignment.Center,
                    VerticalAlignment.Bottom);
            }
        }
开发者ID:aleksanderkobylak,项目名称:oxyplot,代码行数:34,代码来源:FlagSeries.cs

示例2: RenderLegend

 /// <summary>
 ///     Renders the legend symbol on the specified render context.
 /// </summary>
 /// <param name="rc">The rendering context.</param>
 /// <param name="legendBox">The legend rectangle.</param>
 public override void RenderLegend(IRenderContext rc, OxyRect legendBox)
 {
     rc.DrawText(
         legendBox.Center,
         this.Symbol,
         this.Color,
         this.FontFamily,
         this.FontSize,
         FontWeights.Normal,
         0,
         HorizontalAlignment.Center,
         VerticalAlignment.Middle);
 }
开发者ID:aleksanderkobylak,项目名称:oxyplot,代码行数:18,代码来源:FlagSeries.cs

示例3: RenderLegendOnLine

        /// <summary>
        /// Renders a legend on the line.
        /// </summary>
        /// <param name="rc">The render context.</param>
        protected void RenderLegendOnLine(IRenderContext rc)
        {
            // Find the position
            DataPoint point;
            var ha = HorizontalAlignment.Left;
            double dx;
            switch (this.LineLegendPosition)
            {
                case LineLegendPosition.Start:

                    // start position
                    point = this.ActualPoints[0];
                    ha = HorizontalAlignment.Right;
                    dx = -4;
                    break;
                default:

                    // end position
                    point = this.ActualPoints[this.ActualPoints.Count - 1];
                    dx = 4;
                    break;
            }

            var pt = this.Transform(point) + new ScreenVector(dx, 0);

            // Render the legend
            rc.DrawText(
                pt,
                this.Title,
                this.ActualTextColor,
                this.ActualFont,
                this.ActualFontSize,
                this.ActualFontWeight,
                0,
                ha,
                VerticalAlignment.Middle);
        }
开发者ID:Keyabob,项目名称:MMG,代码行数:41,代码来源:LineSeries.cs

示例4: Render

        /// <summary>
        /// Renders the annotation on the specified context.
        /// </summary>
        /// <param name="rc">The render context.</param>
        public override void Render(IRenderContext rc)
        {
            base.Render(rc);

            var lon0 = this.XAxis.ActualMinimum;
            var lon1 = this.XAxis.ActualMaximum;
            var lat0 = this.YAxis.ActualMinimum;
            var lat1 = this.YAxis.ActualMaximum;

            // the desired number of tiles horizontally
            double tilesx = this.PlotModel.Width / this.TileSize;

            // calculate the desired zoom level
            var n = tilesx / (((lon1 + 180) / 360) - ((lon0 + 180) / 360));
            var zoom = (int)Math.Round(Math.Log(n) / Math.Log(2));
            if (zoom < this.MinZoomLevel)
            {
                zoom = this.MinZoomLevel;
            }

            if (zoom > this.MaxZoomLevel)
            {
                zoom = this.MaxZoomLevel;
            }

            // find tile coordinates for the corners
            double x0, y0;
            LatLonToTile(lat0, lon0, zoom, out x0, out y0);
            double x1, y1;
            LatLonToTile(lat1, lon1, zoom, out x1, out y1);

            double xmax = Math.Max(x0, x1);
            double xmin = Math.Min(x0, x1);
            double ymax = Math.Max(y0, y1);
            double ymin = Math.Min(y0, y1);

            var clippingRectangle = this.GetClippingRect();

            // Add the tiles
            for (var x = (int)xmin; x < xmax; x++)
            {
                for (var y = (int)ymin; y < ymax; y++)
                {
                    string uri = this.GetTileUri(x, y, zoom);
                    var img = this.GetImage(uri, rc.RendersToScreen);

                    if (img == null)
                    {
                        continue;
                    }

                    // transform from tile coordinates to lat/lon
                    double latitude0, latitude1, longitude0, longitude1;
                    TileToLatLon(x, y, zoom, out latitude0, out longitude0);
                    TileToLatLon(x + 1, y + 1, zoom, out latitude1, out longitude1);

                    // transform from lat/lon to screen coordinates
                    var s00 = this.Transform(longitude0, latitude0);
                    var s11 = this.Transform(longitude1, latitude1);

                    var r = OxyRect.Create(s00.X, s00.Y, s11.X, s11.Y);

                    // draw the image
                    rc.DrawClippedImage(clippingRectangle, img, r.Left, r.Top, r.Width, r.Height, this.Opacity, true);
                }
            }

            // draw the copyright notice
            var p = new ScreenPoint(clippingRectangle.Right - 5, clippingRectangle.Bottom - 5);
            var textSize = rc.MeasureText(this.CopyrightNotice, this.ActualFont, this.ActualFontSize, this.ActualFontWeight);
            rc.DrawRectangle(new OxyRect(p.X - textSize.Width - 2, p.Y - textSize.Height - 2, textSize.Width + 4, textSize.Height + 4), OxyColor.FromAColor(200, OxyColors.White), OxyColors.Undefined);

            rc.DrawText(
                p,
                this.CopyrightNotice,
                OxyColors.Black,
                this.ActualFont,
                this.ActualFontSize,
                this.ActualFontWeight,
                0,
                HorizontalAlignment.Right,
                VerticalAlignment.Bottom);
        }
开发者ID:huoxudong125,项目名称:oxyplot,代码行数:87,代码来源:TileMapAnnotation.cs

示例5: InternalDrawMathText

        /// <summary>
        /// Draws text with sub- and superscript items.
        /// </summary>
        /// <param name="rc">The render context.</param>
        /// <param name="x">The x.</param>
        /// <param name="y">The y.</param>
        /// <param name="dx">The x offset (in rotated coordinates).</param>
        /// <param name="dy">The y offset (in rotated coordinates).</param>
        /// <param name="s">The s.</param>
        /// <param name="textColor">The text color.</param>
        /// <param name="fontFamily">The font family.</param>
        /// <param name="fontSize">The font size.</param>
        /// <param name="fontWeight">The font weight.</param>
        /// <param name="measureOnly">Only measure if set to <c>true</c>.</param>
        /// <param name="angle">The angle of the text (degrees).</param>
        /// <returns>The size of the text.</returns>
        private static OxySize InternalDrawMathText(
            IRenderContext rc,
            double x,
            double y,
            double dx,
            double dy,
            string s,
            OxyColor textColor,
            string fontFamily,
            double fontSize,
            double fontWeight,
            bool measureOnly,
            double angle)
        {
            var i = 0;
            var angleRadian = (angle * Math.PI) / 180.0;
            var cosAngle = Math.Round(Math.Cos(angleRadian), 5);
            var sinAngle = Math.Round(Math.Sin(angleRadian), 5);

            var currentX = x;
            var maximumX = x;
            var minimumX = x;
            var currentY = y;
            var maximumY = y;
            var minimumY = y;

            // http://en.wikipedia.org/wiki/Subscript_and_superscript
            var superScriptYDisplacement = fontSize * SuperAlignment;

            var subscriptYDisplacement = fontSize * SubAlignment;

            var superscriptFontSize = fontSize * SuperSize;
            var subscriptFontSize = fontSize * SubSize;

            Func<double, double, string, double, OxySize> drawText = (xb, yb, text, fSize) =>
                {
                    if (!measureOnly)
                    {
                        var xr = x + ((xb - x + dx) * cosAngle) - ((yb - y + dy) * sinAngle);
                        var yr = y + ((xb - x + dx) * sinAngle) + ((yb - y + dy) * cosAngle);
                        rc.DrawText(new ScreenPoint(xr, yr), text, textColor, fontFamily, fSize, fontWeight, angle);
                    }

                    var flatSize = rc.MeasureText(text, fontFamily, fSize, fontWeight);
                    return new OxySize(flatSize.Width, flatSize.Height);
                };

            while (i < s.Length)
            {
                // Superscript
                if (i + 1 < s.Length && s[i] == '^' && s[i + 1] == '{')
                {
                    var i1 = s.IndexOf('}', i);
                    if (i1 != -1)
                    {
                        var supString = s.Substring(i + 2, i1 - i - 2);
                        i = i1 + 1;
                        var sx = currentX;
                        var sy = currentY + superScriptYDisplacement;
                        var size = drawText(sx, sy, supString, superscriptFontSize);
                        maximumX = Math.Max(sx + size.Width, maximumX);
                        maximumY = Math.Max(sy + size.Height, maximumY);
                        minimumX = Math.Min(sx, minimumX);
                        minimumY = Math.Min(sy, minimumY);

                        continue;
                    }
                }

                // Subscript
                if (i + 1 < s.Length && s[i] == '_' && s[i + 1] == '{')
                {
                    var i1 = s.IndexOf('}', i);
                    if (i1 != -1)
                    {
                        var subString = s.Substring(i + 2, i1 - i - 2);
                        i = i1 + 1;
                        var sx = currentX;
                        var sy = currentY + subscriptYDisplacement;
                        var size = drawText(sx, sy, subString, subscriptFontSize);
                        maximumX = Math.Max(sx + size.Width, maximumX);
                        maximumY = Math.Max(sy + size.Height, maximumY);
                        minimumX = Math.Min(sx, minimumX);
                        minimumY = Math.Min(sy, minimumY);
//.........这里部分代码省略.........
开发者ID:huoxudong125,项目名称:oxyplot,代码行数:101,代码来源:MathRenderingExtensions.cs

示例6: RenderFromXml


//.........这里部分代码省略.........
                XmlElement renderElement = renderNode as XmlElement;

                if (renderElement == null)
                    continue;

                if (renderElement.Name == "line")
                {
                    Point start = Point.Parse(renderElement.Attributes["start"].InnerText);
                    Point end = Point.Parse(renderElement.Attributes["end"].InnerText);
                    double thickness = double.Parse(renderElement.Attributes["thickness"].InnerText);
                    renderContext.DrawLine(start, end, thickness);
                }
                else if (renderElement.Name == "rect")
                {
                    Point start = Point.Parse(renderElement.Attributes["start"].InnerText);
                    Size size = Size.Parse(renderElement.Attributes["size"].InnerText);
                    double thickness = double.Parse(renderElement.Attributes["thickness"].InnerText);
                    bool fill = bool.Parse(renderElement.Attributes["fill"].InnerText);
                    renderContext.DrawRectangle(start, size, thickness, fill);
                }
                else if (renderElement.Name == "ellipse")
                {
                    Point centre = Point.Parse(renderElement.Attributes["centre"].InnerText);
                    double radiusx = double.Parse(renderElement.Attributes["rx"].InnerText);
                    double radiusy = double.Parse(renderElement.Attributes["ry"].InnerText);
                    double thickness = double.Parse(renderElement.Attributes["thickness"].InnerText);
                    bool fill = bool.Parse(renderElement.Attributes["fill"].InnerText);
                    renderContext.DrawEllipse(centre, radiusx, radiusy, thickness, fill);
                }
                else if (renderElement.Name == "path")
                {
                    Point start = Point.Parse(renderElement.Attributes["start"].InnerText);
                    double thickness = double.Parse(renderElement.Attributes["thickness"].InnerText);
                    bool fill = bool.Parse(renderElement.Attributes["fill"].InnerText);
                    string data = renderElement.InnerText;
                    List<IPathCommand> pathCommands = new List<IPathCommand>();
                    using (MemoryStream dataStream = new MemoryStream(Convert.FromBase64String(data)))
                    {
                        BinaryReader reader = new BinaryReader(dataStream);

                        int numCommands = reader.ReadInt32();

                        for (int l = 0; l < numCommands; l++)
                        {
                            CommandType pType = (CommandType)reader.ReadInt32();
                            IPathCommand theCommand = null;
                            switch (pType)
                            {
                                case CommandType.MoveTo:
                                    theCommand = new MoveTo();
                                    break;
                                case CommandType.LineTo:
                                    theCommand = new LineTo();
                                    break;
                                case CommandType.CurveTo:
                                    theCommand = new CurveTo();
                                    break;
                                case CommandType.EllipticalArcTo:
                                    theCommand = new EllipticalArcTo();
                                    break;
                                case CommandType.QuadraticBeizerCurveTo:
                                    theCommand = new QuadraticBeizerCurveTo();
                                    break;
                                case CommandType.SmoothCurveTo:
                                    theCommand = new SmoothCurveTo();
                                    break;
                                case CommandType.SmoothQuadraticBeizerCurveTo:
                                    theCommand = new SmoothQuadraticBeizerCurveTo();
                                    break;
                                default:
                                    theCommand = new ClosePath();
                                    break;
                            }
                            theCommand.Read(reader);
                            pathCommands.Add(theCommand);
                        }
                    }
                    renderContext.DrawPath(start, pathCommands, thickness, fill);
                }
                else if (renderElement.Name == "text")
                {
                    Point anchor = Point.Parse(renderElement.Attributes["anchor"].InnerText);
                    TextAlignment alignment = (TextAlignment)Enum.Parse(typeof(TextAlignment), renderElement.Attributes["alignment"].InnerText);
                    List<TextRun> runs = new List<TextRun>();
                    foreach (XmlNode runNode in renderElement.ChildNodes)
                    {
                        if (runNode.Name != "run")
                            continue;

                        double size = double.Parse(runNode.Attributes["size"].InnerText);
                        TextRunFormattingType formattingType = (TextRunFormattingType)Enum.Parse(typeof(TextRunFormattingType), runNode.Attributes["formatting"].InnerText);
                        string text = runNode.InnerText;
                        runs.Add(new TextRun(text, new TextRunFormatting(formattingType, size)));
                    }
                    renderContext.DrawText(anchor, alignment, runs);
                }
            }

            return true;
        }
开发者ID:csuffyy,项目名称:circuitdiagram,代码行数:101,代码来源:XmlRenderer.cs

示例7: InternalDrawMathText

        /// <summary>
        /// The internal draw math text.
        /// </summary>
        /// <param name="rc">
        /// The render context.
        /// </param>
        /// <param name="x">
        /// The x.
        /// </param>
        /// <param name="y">
        /// The y.
        /// </param>
        /// <param name="s">
        /// The s.
        /// </param>
        /// <param name="textColor">
        /// The text color.
        /// </param>
        /// <param name="fontFamily">
        /// The font family.
        /// </param>
        /// <param name="fontSize">
        /// The font size.
        /// </param>
        /// <param name="fontWeight">
        /// The font weight.
        /// </param>
        /// <param name="measureOnly">
        /// The measure only.
        /// </param>
        /// <returns>
        /// The size of the text.
        /// </returns>
        private static OxySize InternalDrawMathText(
            IRenderContext rc,
            double x,
            double y,
            string s,
            OxyColor textColor,
            string fontFamily,
            double fontSize,
            double fontWeight,
            bool measureOnly)
        {
            int i = 0;

            double currentX = x;
            double maximumX = x;
            double maxHeight = 0;

            // http://en.wikipedia.org/wiki/Subscript_and_superscript
            double superscriptY = y + fontSize * SuperAlignment;
            double superscriptFontSize = fontSize * SuperSize;
            double subscriptY = y + fontSize * SubAlignment;
            double subscriptFontSize = fontSize * SubSize;

            Func<double, double, string, double, OxySize> drawText = (xb, yb, text, fSize) =>
                {
                    if (!measureOnly)
                    {
                        rc.DrawText(new ScreenPoint(xb, yb), text, textColor, fontFamily, fSize, fontWeight);
                    }

                    return rc.MeasureText(text, fontFamily, fSize, fontWeight);
                };

            while (i < s.Length)
            {
                // Superscript
                if (i + 1 < s.Length && s[i] == '^' && s[i + 1] == '{')
                {
                    int i1 = s.IndexOf('}', i);
                    if (i1 != -1)
                    {
                        string supString = s.Substring(i + 2, i1 - i - 2);
                        i = i1 + 1;
                        OxySize size = drawText(currentX, superscriptY, supString, superscriptFontSize);
                        if (currentX + size.Width > maximumX)
                        {
                            maximumX = currentX + size.Width;
                        }

                        continue;
                    }
                }

                // Subscript
                if (i + 1 < s.Length && s[i] == '_' && s[i + 1] == '{')
                {
                    int i1 = s.IndexOf('}', i);
                    if (i1 != -1)
                    {
                        string subString = s.Substring(i + 2, i1 - i - 2);
                        i = i1 + 1;
                        OxySize size = drawText(currentX, subscriptY, subString, subscriptFontSize);
                        if (currentX + size.Width > maximumX)
                        {
                            maximumX = currentX + size.Width;
                        }

//.........这里部分代码省略.........
开发者ID:jwolfm98,项目名称:HardwareMonitor,代码行数:101,代码来源:MathRenderingExtensions.cs

示例8: Render

 /// <summary>
 /// Renders the icon on the specified render context.
 /// </summary>
 /// <param name="rc">The render context.</param>
 /// <param name="size">The size.</param>
 public override void Render(IRenderContext rc, double size)
 {
     var m = size * 0.05;
     var rect = new OxyRect(m, m, size - m * 2, size - m * 2);
     rc.DrawEllipse(rect, OxyColors.Black, OxyColors.Black, 0);
     rc.DrawText(new ScreenPoint(size * 0.52, size * 0.32), "XY", OxyColors.White, "Arial", size * 0.25, FontWeights.Bold, 0, HorizontalAlignment.Center, VerticalAlignment.Middle);
     rc.DrawText(new ScreenPoint(size * 0.52, size * 0.64), "PLOT", OxyColors.White, "Arial", size * 0.25, FontWeights.Bold, 0, HorizontalAlignment.Center, VerticalAlignment.Middle);
 }
开发者ID:kleopatra999,项目名称:icon-generator,代码行数:13,代码来源:Program.cs

示例9: Render


//.........这里部分代码省略.........
                        angle = endAngle;
                        stop = true;
                    }

                    double a = angle * Math.PI / 180;
                    var op = new ScreenPoint(mp.X + (outerRadius * Math.Cos(a)), mp.Y + (outerRadius * Math.Sin(a)));
                    outerPoints.Add(op);
                    var ip = new ScreenPoint(mp.X + (innerRadius * Math.Cos(a)), mp.Y + (innerRadius * Math.Sin(a)));
                    if (innerRadius + explodedRadius > 0)
                    {
                        innerPoints.Add(ip);
                    }

                    if (stop)
                    {
                        break;
                    }

                    angle += this.AngleIncrement;
                }

                innerPoints.Reverse();
                if (innerPoints.Count == 0)
                {
                    innerPoints.Add(mp);
                }

                innerPoints.Add(outerPoints[0]);

                var points = outerPoints;
                points.AddRange(innerPoints);

                rc.DrawPolygon(points, slice.ActualFillColor, this.Stroke, this.StrokeThickness, null, OxyPenLineJoin.Bevel);

                // Render label outside the slice
                if (this.OutsideLabelFormat != null)
                {
                    string label = string.Format(
                        this.OutsideLabelFormat, slice.Value, slice.Label, slice.Value / total * 100);
                    int sign = Math.Sign(Math.Cos(midAngleRadians));

                    // tick points
                    var tp0 = new ScreenPoint(
                        mp.X + ((outerRadius + this.TickDistance) * Math.Cos(midAngleRadians)),
                        mp.Y + ((outerRadius + this.TickDistance) * Math.Sin(midAngleRadians)));
                    var tp1 = new ScreenPoint(
                        tp0.X + (this.TickRadialLength * Math.Cos(midAngleRadians)),
                        tp0.Y + (this.TickRadialLength * Math.Sin(midAngleRadians)));
                    var tp2 = new ScreenPoint(tp1.X + (this.TickHorizontalLength * sign), tp1.Y);

                    // draw the tick line with the same color as the text
                    rc.DrawLine(new[] { tp0, tp1, tp2 }, this.ActualTextColor, 1, null, OxyPenLineJoin.Bevel);

                    // label
                    var labelPosition = new ScreenPoint(tp2.X + (this.TickLabelDistance * sign), tp2.Y);
                    rc.DrawText(
                        labelPosition,
                        label,
                        this.ActualTextColor,
                        this.ActualFont,
                        this.ActualFontSize,
                        this.ActualFontWeight,
                        0,
                        sign > 0 ? HorizontalAlignment.Left : HorizontalAlignment.Right,
                        VerticalAlignment.Middle);
                }

                // Render a label inside the slice
                if (this.InsideLabelFormat != null && !this.InsideLabelColor.IsUndefined())
                {
                    string label = string.Format(
                        this.InsideLabelFormat, slice.Value, slice.Label, slice.Value / total * 100);
                    double r = (innerRadius * (1 - this.InsideLabelPosition)) + (outerRadius * this.InsideLabelPosition);
                    var labelPosition = new ScreenPoint(
                        mp.X + (r * Math.Cos(midAngleRadians)), mp.Y + (r * Math.Sin(midAngleRadians)));
                    double textAngle = 0;
                    if (this.AreInsideLabelsAngled)
                    {
                        textAngle = midAngle;
                        if (Math.Cos(midAngleRadians) < 0)
                        {
                            textAngle += 180;
                        }
                    }

                    var actualInsideLabelColor = this.InsideLabelColor.IsAutomatic() ? this.ActualTextColor : this.InsideLabelColor;

                    rc.DrawText(
                        labelPosition,
                        label,
                        actualInsideLabelColor,
                        this.ActualFont,
                        this.ActualFontSize,
                        this.ActualFontWeight,
                        textAngle,
                        HorizontalAlignment.Center,
                        VerticalAlignment.Middle);
                }
            }
        }
开发者ID:Cheesebaron,项目名称:oxyplot,代码行数:101,代码来源:PieSeries.cs

示例10: RenderLabel

 /// <summary>
 /// Renders the contour label.
 /// </summary>
 /// <param name="rc">The render context.</param>
 /// <param name="cl">The contour label.</param>
 private void RenderLabel(IRenderContext rc, ContourLabel cl)
 {
     if (this.ActualFontSize > 0)
     {
         rc.DrawText(
             cl.Position,
             cl.Text,
             this.ActualTextColor,
             this.ActualFont,
             this.ActualFontSize,
             this.ActualFontWeight,
             cl.Angle,
             HorizontalAlignment.Center,
             VerticalAlignment.Middle);
     }
 }
开发者ID:Celderon,项目名称:oxyplot,代码行数:21,代码来源:ContourSeries.cs

示例11: RenderErrorMessage

 /// <summary>
 /// Renders the specified error message.
 /// </summary>
 /// <param name="rc">The rendering context.</param>
 /// <param name="title">The title.</param>
 /// <param name="errorMessage">The error message.</param>
 /// <param name="fontSize">The font size. The default value is 12.</param>
 private void RenderErrorMessage(IRenderContext rc, string title, string errorMessage, double fontSize = 12)
 {
     var p0 = new ScreenPoint(10, 10);
     rc.DrawText(p0, title, this.TextColor, fontWeight: FontWeights.Bold, fontSize: fontSize);
     rc.DrawMultilineText(p0 + new ScreenVector(0, fontSize * 1.5), errorMessage, this.TextColor, fontSize: fontSize, dy: fontSize * 1.25);
 }
开发者ID:Keyabob,项目名称:MMG,代码行数:13,代码来源:PlotModel.Rendering.cs

示例12: Render


//.........这里部分代码省略.........
               dashArray,
               this.LineJoin,
               this.aliased,
               null,
               clippedPoints.AddRange);

            ScreenPoint position;
            double angle;
            double margin = this.TextMargin;

            if (this.TextHorizontalAlignment == HorizontalAlignment.Center)
            {
                margin = 0;
            }
            else
            {
                margin *= this.TextLinePosition < 0.5 ? 1 : -1;
            }

            if (GetPointAtRelativeDistance(clippedPoints, this.TextLinePosition, margin, out position, out angle))
            {
                if (angle < -90)
                {
                    angle += 180;
                }

                if (angle > 90)
                {
                    angle -= 180;
                }

                switch (this.TextOrientation)
                {
                    case AnnotationTextOrientation.Horizontal:
                        angle = 0;
                        break;
                    case AnnotationTextOrientation.Vertical:
                        angle = -90;
                        break;
                }

                // Apply 'padding' to the position
                var angleInRadians = angle / 180 * Math.PI;
                var f = 1;

                if (this.TextHorizontalAlignment == HorizontalAlignment.Right)
                {
                    f = -1;
                }

                if (this.TextHorizontalAlignment == HorizontalAlignment.Center)
                {
                    f = 0;
                }

                position += new ScreenVector(f * this.TextPadding * Math.Cos(angleInRadians), f * this.TextPadding * Math.Sin(angleInRadians));

                if (!string.IsNullOrEmpty(this.Text))
                {
                    var textPosition = this.GetActualTextPosition(() => position);
                    
                    if (this.TextPosition.IsDefined())
                    {
                        angle = this.TextRotation;
                    }

                    if (this.ClipText)
                    {
                        var cs = new CohenSutherlandClipping(clippingRectangle);
                        if (cs.IsInside(position))
                        {
                            rc.DrawClippedText(
                                clippingRectangle,
                                textPosition,
                                this.Text,
                                this.ActualTextColor,
                                this.ActualFont,
                                this.ActualFontSize,
                                this.ActualFontWeight,
                                angle,
                                this.TextHorizontalAlignment,
                                this.TextVerticalAlignment);
                        }
                    }
                    else
                    {
                        rc.DrawText(
                           textPosition,
                           this.Text,
                           this.ActualTextColor,
                           this.ActualFont,
                           this.ActualFontSize,
                           this.ActualFontWeight,
                           angle,
                           this.TextHorizontalAlignment,
                           this.TextVerticalAlignment);
                    }
                }
            }
        }
开发者ID:benjaminrupp,项目名称:oxyplot,代码行数:101,代码来源:PathAnnotation.cs

示例13: InternalDrawMathText

        /// <summary>
        /// The internal draw math text.
        /// </summary>
        /// <param name="rc">The render context.</param>
        /// <param name="x">The x.</param>
        /// <param name="y">The y.</param>
        /// <param name="s">The s.</param>
        /// <param name="textColor">The text color.</param>
        /// <param name="fontFamily">The font family.</param>
        /// <param name="fontSize">The font size.</param>
        /// <param name="fontWeight">The font weight.</param>
        /// <param name="measureOnly">The measure only.</param>
        /// <param name="angle">The angle of the text (degrees).</param>
        /// <returns>The size of the text.</returns>
        private static OxySize InternalDrawMathText(
            IRenderContext rc,
            double x,
            double y,
            string s,
            OxyColor textColor,
            string fontFamily,
            double fontSize,
            double fontWeight,
            bool measureOnly,
            double angle)
        {
            int i = 0;
            double angleRadian = (angle * Math.PI) / 180.0;
            double cosAngle = Math.Round(Math.Cos(angleRadian), 5);
            double sinAngle = Math.Round(Math.Sin(angleRadian), 5);

            double currentX = x, maximumX = x, minimumX = x;
            double currentY = y, maximumY = y, minimumY = y;

            // http://en.wikipedia.org/wiki/Subscript_and_superscript
            double superScriptXDisplacement = sinAngle * fontSize * SuperAlignment;
            double superScriptYDisplacement = cosAngle * fontSize * SuperAlignment;

            double subscriptXDisplacement = sinAngle * fontSize * SubAlignment;
            double subscriptYDisplacement = cosAngle * fontSize * SubAlignment;

            double superscriptFontSize = fontSize * SuperSize;
            double subscriptFontSize = fontSize * SubSize;

            Func<double, double, string, double, OxySize> drawText = (xb, yb, text, fSize) =>
                {
                    if (!measureOnly)
                    {
                        rc.DrawText(new ScreenPoint(xb, yb), text, textColor, fontFamily, fSize, fontWeight, angle);
                    }

                    var flatSize = rc.MeasureText(text, fontFamily, fSize, fontWeight);
                    double width = Math.Abs((flatSize.Width * cosAngle) + (flatSize.Height * sinAngle));
                    double height = Math.Abs((flatSize.Width * sinAngle) + (flatSize.Height * cosAngle));
                    return new OxySize(width, height);
                };

            while (i < s.Length)
            {
                // Superscript
                if (i + 1 < s.Length && s[i] == '^' && s[i + 1] == '{')
                {
                    int i1 = s.IndexOf('}', i);
                    if (i1 != -1)
                    {
                        string supString = s.Substring(i + 2, i1 - i - 2);
                        i = i1 + 1;
                        double sx = currentX + superScriptXDisplacement;
                        double sy = currentY + superScriptYDisplacement;
                        var size = drawText(sx, sy, supString, superscriptFontSize);
                        if (currentX + size.Width > maximumX)
                        {
                            maximumX = currentX + size.Width;
                        }

                        if (currentX + size.Width < minimumX)
                        {
                            minimumX = currentX + size.Width;
                        }

                        if (currentY + size.Height > maximumY)
                        {
                            maximumY = currentY + size.Height;
                        }

                        if (currentY + size.Height < minimumY)
                        {
                            minimumY = currentY + size.Height;
                        }

                        continue;
                    }
                }

                // Subscript
                if (i + 1 < s.Length && s[i] == '_' && s[i + 1] == '{')
                {
                    int i1 = s.IndexOf('}', i);
                    if (i1 != -1)
                    {
//.........这里部分代码省略.........
开发者ID:Celderon,项目名称:oxyplot,代码行数:101,代码来源:MathRenderingExtensions.cs


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