⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 markerrenderer.cs

📁 用C#實現能產生PDF格式文件的源碼
💻 CS
字号:
#region PDFsharp Charting - A .NET charting library based on PDFsharp
//
// Authors:
//   Niklas Schneider (mailto:Niklas.Schneider@pdfsharp.com)
//
// Copyright (c) 2005-2007 empira Software GmbH, Cologne (Germany)
//
// http://www.pdfsharp.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.
#endregion

using System;
using PdfSharp.Drawing;

namespace PdfSharp.Charting.Renderers
{
	/// <summary>
  /// Represents a renderer for markers in line charts and legends.
  /// </summary>
	internal class MarkerRenderer
	{
    /// <summary>
    /// Draws the marker given through rendererInfo at the specified position. Position specifies
    /// the center of the marker.
    /// </summary>
    internal static void Draw(XGraphics graphics, XPoint pos, MarkerRendererInfo rendererInfo)
    {
      if (rendererInfo.MarkerStyle == MarkerStyle.None)
        return;

      double size  = rendererInfo.MarkerSize;
      double size2 = size / 2;
      double x0, y0, x1, y1;
      double g;

      XPen foreground = new XPen(rendererInfo.MarkerForegroundColor, 0.5);
      XBrush background = new XSolidBrush(rendererInfo.MarkerBackgroundColor);

      XGraphicsPath gp = new XGraphicsPath();
      switch (rendererInfo.MarkerStyle)
      {
        case MarkerStyle.Square:
          x0 = pos.X - size2;
          y0 = pos.Y - size2;
          x1 = pos.X + size2;
          y1 = pos.Y + size2;
          gp.AddLine(x0, y0, x1, y0);
          gp.AddLine(x1, y0, x1, y1);
          gp.AddLine(x1, y1, x0, y1);
          gp.AddLine(x0, y1, x0, y0);
          break;

        case MarkerStyle.Diamond:
          gp.AddLine(x1 = pos.X + size2, pos.Y, pos.X, y0 = pos.Y - size2);
          gp.AddLine(pos.X, y0, x0 = pos.X - size2, pos.Y);
          gp.AddLine(x0, pos.Y, pos.X, y1 = pos.Y + size2);
          gp.AddLine(pos.X, y1, x1, pos.Y);
          break;

        case MarkerStyle.Triangle:
          y0 = pos.Y + size / 2;
          y1 = pos.Y - size / 2;
          g = Math.Sqrt(size * size * 4 / 3) / 2;
          gp.AddLine(pos.X, y1, pos.X + g, y0);
          gp.AddLine(pos.X + g, y0, pos.X - g, y0);
          gp.AddLine(pos.X - g, y0, pos.X, y1);
          break;

        case MarkerStyle.Plus:
          g = size2 / 4;
          gp.AddLine(pos.X - size2, pos.Y + g,     pos.X - g,     pos.Y + g);
          gp.AddLine(pos.X - g,     pos.Y + g,     pos.X - g,     pos.Y + size2);
          gp.AddLine(pos.X - g,     pos.Y + size2, pos.X + g,     pos.Y + size2);
          gp.AddLine(pos.X + g,     pos.Y + size2, pos.X + g,     pos.Y + g);
          gp.AddLine(pos.X + g,     pos.Y + g,     pos.X + size2, pos.Y + g);
          gp.AddLine(pos.X + size2, pos.Y + g,     pos.X + size2, pos.Y - g);
          gp.AddLine(pos.X + size2, pos.Y - g,     pos.X + g,     pos.Y - g);
          gp.AddLine(pos.X + g,     pos.Y - g,     pos.X + g,     pos.Y - size2);
          gp.AddLine(pos.X + g,     pos.Y - size2, pos.X - g,     pos.Y - size2);
          gp.AddLine(pos.X - g,     pos.Y - size2, pos.X - g,     pos.Y - g);
          gp.AddLine(pos.X - g,     pos.Y - g,     pos.X - size2, pos.Y - g);
          gp.AddLine(pos.X - size2, pos.Y - g,     pos.X - size2, pos.Y + g);
          break;

        case MarkerStyle.Circle:
        case MarkerStyle.Dot:
          x0 = pos.X - size2;
          y0 = pos.Y - size2;
          gp.AddEllipse(x0, y0, size, size);
          break;

        case MarkerStyle.Dash:
          x0 = pos.X - size2;
          y0 = pos.Y - size2 / 3;
          x1 = pos.X + size2;
          y1 = pos.Y + size2 / 3;
          gp.AddLine(x0, y0, x1, y0);
          gp.AddLine(x1, y0, x1, y1);
          gp.AddLine(x1, y1, x0, y1);
          gp.AddLine(x0, y1, x0, y0);
          break;

        case MarkerStyle.X:
          g = size / 4;
          gp.AddLine(pos.X - size2 + g, pos.Y - size2,     pos.X,             pos.Y - g);
          gp.AddLine(pos.X,             pos.Y - g,         pos.X + size2 - g, pos.Y - size2);
          gp.AddLine(pos.X + size2 - g, pos.Y - size2,     pos.X + size2,     pos.Y - size2 + g);
          gp.AddLine(pos.X + size2,     pos.Y - size2 + g, pos.X + g,         pos.Y);
          gp.AddLine(pos.X + g,         pos.Y,             pos.X + size2,     pos.Y + size2 - g);
          gp.AddLine(pos.X + size2,     pos.Y + size2 - g, pos.X + size2 - g, pos.Y + size2);
          gp.AddLine(pos.X + size2 - g, pos.Y + size2,     pos.X,             pos.Y + g);
          gp.AddLine(pos.X,             pos.Y + g,         pos.X - size2 + g, pos.Y + size2);
          gp.AddLine(pos.X - size2 + g, pos.Y + size2,     pos.X - size2,     pos.Y + size2 - g);
          gp.AddLine(pos.X - size2,     pos.Y + size2 - g, pos.X - g,         pos.Y);
          gp.AddLine(pos.X - g,         pos.Y,             pos.X - size2,     pos.Y - size2 + g);
          break;

        case MarkerStyle.Star:
        {
          XPoint[] points = new XPoint[10];

          double radStep = 2 * Math.PI / 5;
          double outerCircle = size / 2;
          double innerCircle = size / 5;
          // outer circle
          double rad = -(Math.PI / 2); // 90

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -