示例#1
0
        public static XDashStyle DashStyle(IExportGraphics column)
        {
            XDashStyle style = XDashStyle.Solid;

            switch (column.DashStyle)
            {
            case System.Drawing.Drawing2D.DashStyle.Solid:
                style = XDashStyle.Solid;
                break;

            case System.Drawing.Drawing2D.DashStyle.Dash:
                style = XDashStyle.Dash;
                break;

            case System.Drawing.Drawing2D.DashStyle.Dot:
                style = XDashStyle.Dot;
                break;

            case System.Drawing.Drawing2D.DashStyle.DashDot:
                style = XDashStyle.DashDot;
                break;

            case System.Drawing.Drawing2D.DashStyle.DashDotDot:
                style = XDashStyle.DashDotDot;
                break;

            case System.Drawing.Drawing2D.DashStyle.Custom:

                break;

            default:
                throw new Exception("Invalid value for DashStyle");
            }
            return(style);
        }
示例#2
0
        //public float scaleX;
        //public float scaleY;

        public PenInfo(Color color, float width)
        {
            this.color       = color;
            this.width       = width;
            this.dashStyle   = XDashStyle.Solid;
            this.dashPattern = null;
            //this.scaleX = 0;
            //this.scaleY = 0;
        }
示例#3
0
        /// <summary>
        /// Creates a XPen based on the specified line format. If not specified color, width and dash style
        /// will be taken from the defaultColor, defaultWidth and defaultDashStyle parameters.
        /// </summary>
        internal static XPen ToXPen(LineFormat lineFormat, XColor defaultColor, double defaultWidth, XDashStyle defaultDashStyle)
        {
            XPen pen = null;

            if (lineFormat == null)
            {
                pen = new XPen(defaultColor, defaultWidth)
                {
                    DashStyle = defaultDashStyle
                };
            }
            else
            {
                XColor color = defaultColor;
                if (!lineFormat.Color.IsEmpty)
                {
                    color = lineFormat.Color;
                }

                double width = lineFormat.Width.Point;
                if (!lineFormat.Visible)
                {
                    width = 0;
                }
                if (lineFormat.Visible && width == 0)
                {
                    width = defaultWidth;
                }

                pen = new XPen(color, width)
                {
                    DashStyle  = lineFormat._dashStyle,
                    DashOffset = 10 * width
                };
            }
            return(pen);
        }
示例#4
0
        public void RealizePen(XPen pen, PdfColorMode colorMode)
        {
            const string frmt2     = Config.SignificantFigures2;
            const string format    = Config.SignificantFigures3;
            XColor       color     = pen.Color;
            bool         overPrint = pen.Overprint;

            color = ColorSpaceHelper.EnsureColorMode(colorMode, color);

            if (_realizedLineWith != pen._width)
            {
                _renderer.AppendFormatArgs("{0:" + format + "} w\n", pen._width);
                _realizedLineWith = pen._width;
            }

            if (_realizedLineCap != (int)pen._lineCap)
            {
                _renderer.AppendFormatArgs("{0} J\n", (int)pen._lineCap);
                _realizedLineCap = (int)pen._lineCap;
            }

            if (_realizedLineJoin != (int)pen._lineJoin)
            {
                _renderer.AppendFormatArgs("{0} j\n", (int)pen._lineJoin);
                _realizedLineJoin = (int)pen._lineJoin;
            }

            if (_realizedLineCap == (int)XLineJoin.Miter)
            {
                if (_realizedMiterLimit != (int)pen._miterLimit && (int)pen._miterLimit != 0)
                {
                    _renderer.AppendFormatInt("{0} M\n", (int)pen._miterLimit);
                    _realizedMiterLimit = (int)pen._miterLimit;
                }
            }

            if (_realizedDashStyle != pen._dashStyle || pen._dashStyle == XDashStyle.Custom)
            {
                double dot  = pen.Width;
                double dash = 3 * dot;

                // Line width 0 is not recommended but valid.
                XDashStyle dashStyle = pen.DashStyle;
                if (dot == 0)
                {
                    dashStyle = XDashStyle.Solid;
                }

                switch (dashStyle)
                {
                case XDashStyle.Solid:
                    _renderer.Append("[]0 d\n");
                    break;

                case XDashStyle.Dash:
                    _renderer.AppendFormatArgs("[{0:" + frmt2 + "} {1:" + frmt2 + "}]0 d\n", dash, dot);
                    break;

                case XDashStyle.Dot:
                    _renderer.AppendFormatArgs("[{0:" + frmt2 + "}]0 d\n", dot);
                    break;

                case XDashStyle.DashDot:
                    _renderer.AppendFormatArgs("[{0:" + frmt2 + "} {1:" + frmt2 + "} {1:" + frmt2 + "} {1:" + frmt2 + "}]0 d\n", dash, dot);
                    break;

                case XDashStyle.DashDotDot:
                    _renderer.AppendFormatArgs("[{0:" + frmt2 + "} {1:" + frmt2 + "} {1:" + frmt2 + "} {1:" + frmt2 + "} {1:" + frmt2 + "} {1:" + frmt2 + "}]0 d\n", dash, dot);
                    break;

                case XDashStyle.Custom:
                {
                    StringBuilder pdf = new StringBuilder("[", 256);
                    int           len = pen._dashPattern == null ? 0 : pen._dashPattern.Length;
                    for (int idx = 0; idx < len; idx++)
                    {
                        if (idx > 0)
                        {
                            pdf.Append(' ');
                        }
                        pdf.Append(PdfEncoders.ToString(pen._dashPattern[idx] * pen._width));
                    }
                    // Make an even number of values look like in GDI+
                    if (len > 0 && len % 2 == 1)
                    {
                        pdf.Append(' ');
                        pdf.Append(PdfEncoders.ToString(0.2 * pen._width));
                    }
                    pdf.AppendFormat(CultureInfo.InvariantCulture, "]{0:" + format + "} d\n", pen._dashOffset * pen._width);
                    string pattern = pdf.ToString();

                    // BUG: [email protected] reported a realizing problem
                    // HACK: I remove the if clause
                    //if (_realizedDashPattern != pattern)
                    {
                        _realizedDashPattern = pattern;
                        _renderer.Append(pattern);
                    }
                }
                break;
                }
                _realizedDashStyle = dashStyle;
            }

            if (colorMode != PdfColorMode.Cmyk)
            {
                if (_realizedStrokeColor.Rgb != color.Rgb)
                {
                    _renderer.Append(PdfEncoders.ToString(color, PdfColorMode.Rgb));
                    _renderer.Append(" RG\n");
                }
            }
            else
            {
                if (!ColorSpaceHelper.IsEqualCmyk(_realizedStrokeColor, color))
                {
                    _renderer.Append(PdfEncoders.ToString(color, PdfColorMode.Cmyk));
                    _renderer.Append(" K\n");
                }
            }

            if (_renderer.Owner.Version >= 14 && (_realizedStrokeColor.A != color.A || _realizedStrokeOverPrint != overPrint))
            {
                PdfExtGState extGState = _renderer.Owner.ExtGStateTable.GetExtGStateStroke(color.A, overPrint);
                string       gs        = _renderer.Resources.AddExtGState(extGState);
                _renderer.AppendFormatString("{0} gs\n", gs);

                // Must create transparency group.
                if (_renderer._page != null && color.A < 1)
                {
                    _renderer._page.TransparencyUsed = true;
                }
            }
            _realizedStrokeColor     = color;
            _realizedStrokeOverPrint = overPrint;
        }
    public void RealizePen(XPen pen, PdfColorMode colorMode)
    {
      XColor color = pen.Color;
      color = ColorSpaceHelper.EnsureColorMode(colorMode, color);

      if (this.realizedLineWith != pen.width)
      {
        this.renderer.AppendFormat("{0:0.###} w\n", pen.width);
        this.realizedLineWith = pen.width;
      }

      if (this.realizedLineCap != (int)pen.lineCap)
      {
        this.renderer.AppendFormat("{0} J\n", (int)pen.lineCap);
        this.realizedLineCap = (int)pen.lineCap;
      }

      if (this.realizedLineJoin != (int)pen.lineJoin)
      {
        this.renderer.AppendFormat("{0} j\n", (int)pen.lineJoin);
        this.realizedLineJoin = (int)pen.lineJoin;
      }

      if (this.realizedLineCap == (int)XLineJoin.Miter)
      {
        if (this.realizedMiterLimit != (int)pen.miterLimit && (int)pen.miterLimit != 0)
        {
          this.renderer.AppendFormat("{0} M\n", (int)pen.miterLimit);
          this.realizedMiterLimit = (int)pen.miterLimit;
        }
      }

      if (this.realizedDashStyle != pen.dashStyle || pen.dashStyle == XDashStyle.Custom)
      {
        double dot = pen.Width;
        double dash = 3 * dot;

        // Line width 0 is not recommended but valid
        XDashStyle dashStyle = pen.DashStyle;
        if (dot == 0)
          dashStyle = XDashStyle.Solid;

        switch (dashStyle)
        {
          case XDashStyle.Solid:
            this.renderer.Append("[]0 d\n");
            break;

          case XDashStyle.Dash:
            this.renderer.AppendFormat("[{0:0.##} {1:0.##}]0 d\n", dash, dot);
            break;

          case XDashStyle.Dot:
            this.renderer.AppendFormat("[{0:0.##}]0 d\n", dot);
            break;

          case XDashStyle.DashDot:
            this.renderer.AppendFormat("[{0:0.##} {1:0.##} {1:0.##} {1:0.##}]0 d\n", dash, dot);
            break;

          case XDashStyle.DashDotDot:
            this.renderer.AppendFormat("[{0:0.##} {1:0.##} {1:0.##} {1:0.##} {1:0.##} {1:0.##}]0 d\n", dash, dot);
            break;

          case XDashStyle.Custom:
            {
              StringBuilder pdf = new StringBuilder("[", 256);
              int len = pen.dashPattern == null ? 0 : pen.dashPattern.Length;
              for (int idx = 0; idx < len; idx++)
              {
                if (idx > 0)
                  pdf.Append(' ');
                pdf.Append(PdfEncoders.ToString(pen.dashPattern[idx] * pen.width));
              }
              // Make an even number of values look like in GDI+
              if (len > 0 && len % 2 == 1)
              {
                pdf.Append(' ');
                pdf.Append(PdfEncoders.ToString(0.2 * pen.width));
              }
              pdf.AppendFormat(CultureInfo.InvariantCulture, "]{0:0.###} d\n", pen.dashOffset * pen.width);
              string pattern = pdf.ToString();

              // BUG: [email protected] reported a realizing problem
              // HACK: I romove the if clause
              //if (this.realizedDashPattern != pattern)
              {
                this.realizedDashPattern = pattern;
                this.renderer.Append(pattern);
              }
            }
            break;
        }
        this.realizedDashStyle = dashStyle;
      }

      if (colorMode != PdfColorMode.Cmyk)
      {
        if (this.realizedStrokeColor.Rgb != color.Rgb)
        {
          this.renderer.Append(PdfEncoders.ToString(color, PdfColorMode.Rgb));
          this.renderer.Append(" RG\n");
        }
      }
      else
      {
        if (!ColorSpaceHelper.IsEqualCmyk(this.realizedStrokeColor, color))
        {
          this.renderer.Append(PdfEncoders.ToString(color, PdfColorMode.Cmyk));
          this.renderer.Append(" K\n");
        }
      }

      if (this.renderer.Owner.Version >= 14 && this.realizedStrokeColor.A != color.A)
      {
        PdfExtGState extGState = this.renderer.Owner.ExtGStateTable.GetExtGStateStroke(color.A);
        string gs = this.renderer.Resources.AddExtGState(extGState);
        this.renderer.AppendFormat("{0} gs\n", gs);

        // Must create transparany group
        if (this.renderer.page != null && color.A < 1)
          this.renderer.page.transparencyUsed = true;
      }
      this.realizedStrokeColor = color;
    }
示例#6
0
 //public float scaleX;
 //public float scaleY;
 public PenInfo(Color color, float width)
 {
     this.color = color;
     this.width = width;
     this.dashStyle = XDashStyle.Solid;
     this.dashPattern = null;
     //this.scaleX = 0;
     //this.scaleY = 0;
 }
示例#7
0
    /// <summary>
    /// Creates a XPen based on the specified line format. If not specified color, width and dash style
    /// will be taken from the defaultColor, defaultWidth and defaultDashStyle parameters.
    /// </summary>
    internal static XPen ToXPen(LineFormat lineFormat, XColor defaultColor, double defaultWidth, XDashStyle defaultDashStyle)
    {
      XPen pen = null;
      if (lineFormat == null)
      {
        pen = new XPen(defaultColor, defaultWidth);
        pen.DashStyle = defaultDashStyle;
      }
      else
      {
        XColor color = defaultColor;
        if (!lineFormat.Color.IsEmpty)
          color = lineFormat.Color;

        double width = lineFormat.Width.Point;
        if (!lineFormat.Visible)
          width = 0;
        if (lineFormat.Visible && width == 0)
          width = defaultWidth;

        pen = new XPen(color, width);
        pen.DashStyle = lineFormat.dashStyle;
        pen.DashOffset = 10 * width;
      }
      return pen;
    }
示例#8
0
        public void RealizePen(XPen pen, PdfColorMode colorMode)
        {
            const string frmt2 = Config.SignificantFigures2;
            const string format = Config.SignificantFigures3;
            XColor color = pen.Color;
            bool overPrint = pen.Overprint;
            color = ColorSpaceHelper.EnsureColorMode(colorMode, color);

            if (_realizedLineWith != pen._width)
            {
                _renderer.AppendFormatArgs("{0:" + format + "} w\n", pen._width);
                _realizedLineWith = pen._width;
            }

            if (_realizedLineCap != (int)pen._lineCap)
            {
                _renderer.AppendFormatArgs("{0} J\n", (int)pen._lineCap);
                _realizedLineCap = (int)pen._lineCap;
            }

            if (_realizedLineJoin != (int)pen._lineJoin)
            {
                _renderer.AppendFormatArgs("{0} j\n", (int)pen._lineJoin);
                _realizedLineJoin = (int)pen._lineJoin;
            }

            if (_realizedLineCap == (int)XLineJoin.Miter)
            {
                if (_realizedMiterLimit != (int)pen._miterLimit && (int)pen._miterLimit != 0)
                {
                    _renderer.AppendFormatInt("{0} M\n", (int)pen._miterLimit);
                    _realizedMiterLimit = (int)pen._miterLimit;
                }
            }

            if (_realizedDashStyle != pen._dashStyle || pen._dashStyle == XDashStyle.Custom)
            {
                double dot = pen.Width;
                double dash = 3 * dot;

                // Line width 0 is not recommended but valid.
                XDashStyle dashStyle = pen.DashStyle;
                if (dot == 0)
                    dashStyle = XDashStyle.Solid;

                switch (dashStyle)
                {
                    case XDashStyle.Solid:
                        _renderer.Append("[]0 d\n");
                        break;

                    case XDashStyle.Dash:
                        _renderer.AppendFormatArgs("[{0:" + frmt2 + "} {1:" + frmt2 + "}]0 d\n", dash, dot);
                        break;

                    case XDashStyle.Dot:
                        _renderer.AppendFormatArgs("[{0:" + frmt2 + "}]0 d\n", dot);
                        break;

                    case XDashStyle.DashDot:
                        _renderer.AppendFormatArgs("[{0:" + frmt2 + "} {1:" + frmt2 + "} {1:" + frmt2 + "} {1:" + frmt2 + "}]0 d\n", dash, dot);
                        break;

                    case XDashStyle.DashDotDot:
                        _renderer.AppendFormatArgs("[{0:" + frmt2 + "} {1:" + frmt2 + "} {1:" + frmt2 + "} {1:" + frmt2 + "} {1:" + frmt2 + "} {1:" + frmt2 + "}]0 d\n", dash, dot);
                        break;

                    case XDashStyle.Custom:
                        {
                            StringBuilder pdf = new StringBuilder("[", 256);
                            int len = pen._dashPattern == null ? 0 : pen._dashPattern.Length;
                            for (int idx = 0; idx < len; idx++)
                            {
                                if (idx > 0)
                                    pdf.Append(' ');
                                pdf.Append(PdfEncoders.ToString(pen._dashPattern[idx] * pen._width));
                            }
                            // Make an even number of values look like in GDI+
                            if (len > 0 && len % 2 == 1)
                            {
                                pdf.Append(' ');
                                pdf.Append(PdfEncoders.ToString(0.2 * pen._width));
                            }
                            pdf.AppendFormat(CultureInfo.InvariantCulture, "]{0:" + format + "} d\n", pen._dashOffset * pen._width);
                            string pattern = pdf.ToString();

                            // BUG: [email protected] reported a realizing problem
                            // HACK: I remove the if clause
                            //if (_realizedDashPattern != pattern)
                            {
                                _realizedDashPattern = pattern;
                                _renderer.Append(pattern);
                            }
                        }
                        break;
                }
                _realizedDashStyle = dashStyle;
            }

            if (colorMode != PdfColorMode.Cmyk)
            {
                if (_realizedStrokeColor.Rgb != color.Rgb)
                {
                    _renderer.Append(PdfEncoders.ToString(color, PdfColorMode.Rgb));
                    _renderer.Append(" RG\n");
                }
            }
            else
            {
                if (!ColorSpaceHelper.IsEqualCmyk(_realizedStrokeColor, color))
                {
                    _renderer.Append(PdfEncoders.ToString(color, PdfColorMode.Cmyk));
                    _renderer.Append(" K\n");
                }
            }

            if (_renderer.Owner.Version >= 14 && (_realizedStrokeColor.A != color.A || _realizedStrokeOverPrint != overPrint))
            {
                PdfExtGState extGState = _renderer.Owner.ExtGStateTable.GetExtGStateStroke(color.A, overPrint);
                string gs = _renderer.Resources.AddExtGState(extGState);
                _renderer.AppendFormatString("{0} gs\n", gs);

                // Must create transparency group.
                if (_renderer._page != null && color.A < 1)
                    _renderer._page.TransparencyUsed = true;
            }
            _realizedStrokeColor = color;
            _realizedStrokeOverPrint = overPrint;
        }
示例#9
0
        public void RealizePen(XPen pen, PdfColorMode colorMode)
        {
            XColor color = pen.Color;

            color = ColorSpaceHelper.EnsureColorMode(colorMode, color);

            if (realizedLineWith != pen.width)
            {
                renderer.AppendFormat("{0:0.###} w\n", pen.width);
                realizedLineWith = pen.width;
            }

            if (realizedLineCap != (int)pen.lineCap)
            {
                renderer.AppendFormat("{0} J\n", (int)pen.lineCap);
                realizedLineCap = (int)pen.lineCap;
            }

            if (realizedLineJoin != (int)pen.lineJoin)
            {
                renderer.AppendFormat("{0} j\n", (int)pen.lineJoin);
                realizedLineJoin = (int)pen.lineJoin;
            }

            if (realizedLineCap == (int)XLineJoin.Miter)
            {
                if (realizedMiterLimit != (int)pen.miterLimit && (int)pen.miterLimit != 0)
                {
                    renderer.AppendFormat("{0} M\n", (int)pen.miterLimit);
                    realizedMiterLimit = (int)pen.miterLimit;
                }
            }

            if (realizedDashStyle != pen.dashStyle || pen.dashStyle == XDashStyle.Custom)
            {
                double dot  = pen.Width;
                double dash = 3 * dot;

                // Line width 0 is not recommended but valid
                XDashStyle dashStyle = pen.DashStyle;
                if (dot == 0)
                {
                    dashStyle = XDashStyle.Solid;
                }

                switch (dashStyle)
                {
                case XDashStyle.Solid:
                    renderer.Append("[]0 d\n");
                    break;

                case XDashStyle.Dash:
                    renderer.AppendFormat("[{0:0.##} {1:0.##}]0 d\n", dash, dot);
                    break;

                case XDashStyle.Dot:
                    renderer.AppendFormat("[{0:0.##}]0 d\n", dot);
                    break;

                case XDashStyle.DashDot:
                    renderer.AppendFormat("[{0:0.##} {1:0.##} {1:0.##} {1:0.##}]0 d\n", dash, dot);
                    break;

                case XDashStyle.DashDotDot:
                    renderer.AppendFormat("[{0:0.##} {1:0.##} {1:0.##} {1:0.##} {1:0.##} {1:0.##}]0 d\n", dash, dot);
                    break;

                case XDashStyle.Custom:
                {
                    StringBuilder pdf = new StringBuilder("[", 256);
                    int           len = pen.dashPattern == null ? 0 : pen.dashPattern.Length;
                    for (int idx = 0; idx < len; idx++)
                    {
                        if (idx > 0)
                        {
                            pdf.Append(' ');
                        }
                        pdf.Append(PdfEncoders.ToString(pen.dashPattern[idx] * pen.width));
                    }
                    // Make an even number of values look like in GDI+
                    if (len > 0 && len % 2 == 1)
                    {
                        pdf.Append(' ');
                        pdf.Append(PdfEncoders.ToString(0.2 * pen.width));
                    }
                    pdf.AppendFormat(CultureInfo.InvariantCulture, "]{0:0.###} d\n", pen.dashOffset * pen.width);
                    string pattern = pdf.ToString();

                    // BUG: [email protected] reported a realizing problem
                    // HACK: I romove the if clause
                    //if (this.realizedDashPattern != pattern)
                    {
                        realizedDashPattern = pattern;
                        renderer.Append(pattern);
                    }
                }
                break;
                }
                realizedDashStyle = dashStyle;
            }

            if (colorMode != PdfColorMode.Cmyk)
            {
                if (realizedStrokeColor.Rgb != color.Rgb)
                {
                    renderer.Append(PdfEncoders.ToString(color, PdfColorMode.Rgb));
                    renderer.Append(" RG\n");
                }
            }
            else
            {
                if (!ColorSpaceHelper.IsEqualCmyk(realizedStrokeColor, color))
                {
                    renderer.Append(PdfEncoders.ToString(color, PdfColorMode.Cmyk));
                    renderer.Append(" K\n");
                }
            }

            if (renderer.Owner.Version >= 14 && realizedStrokeColor.A != color.A)
            {
                PdfExtGState extGState = renderer.Owner.ExtGStateTable.GetExtGStateStroke(color.A);
                string       gs        = renderer.Resources.AddExtGState(extGState);
                renderer.AppendFormat("{0} gs\n", gs);

                // Must create transparany group
                if (renderer.page != null && color.A < 1)
                {
                    renderer.page.transparencyUsed = true;
                }
            }
            realizedStrokeColor = color;
        }