예제 #1
0
    public void RealizeBrush(XBrush brush)
    {
      if (brush is XSolidBrush)
      {
        XColor color = ((XSolidBrush)brush).Color;
        if (this.realizedFillColor.Argb != color.Argb)
        {
          if (this.realizedFillColor.Rgb != color.Rgb)
          {
            this.renderer.AppendFormat("{0} {1} {2} rg\n",
              PdfEncoders.ToString(color.R / 255.0), PdfEncoders.ToString(color.G / 255.0), PdfEncoders.ToString(color.B / 255.0));
          }
          if (this.renderer.Owner.Version >= 14 && this.realizedFillColor.A != color.A)
          {
            PdfExtGState extGState = this.renderer.Owner.ExtGStateTable.GetExtGStateNonStroke(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.realizedFillColor = color;
        }
      }
      else if (brush is XLinearGradientBrush)
      {
        XMatrix matrix = this.renderer.defaultViewMatrix;
        matrix.Multiply(this.Transform);
        PdfShadingPattern pattern = new PdfShadingPattern(this.renderer.Owner);
        pattern.SetupFromBrush((XLinearGradientBrush)brush, matrix);
        string name = this.renderer.Resources.AddPattern(pattern);
        this.renderer.AppendFormat("/Pattern cs\n", name);
        this.renderer.AppendFormat("{0} scn\n", name);

        // Invalidate fill color
        this.realizedFillColor = XColor.Empty;
      }
    }
예제 #2
0
    public void RealizeBrush(XBrush brush, PdfColorMode colorMode)
    {
      if (brush is XSolidBrush)
      {
        XColor color = ((XSolidBrush)brush).Color;
        color = ColorSpaceHelper.EnsureColorMode(colorMode, color);

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

        if (this.renderer.Owner.Version >= 14 && this.realizedFillColor.A != color.A)
        {
          PdfExtGState extGState = this.renderer.Owner.ExtGStateTable.GetExtGStateNonStroke(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.realizedFillColor = color;
      }
      else if (brush is XLinearGradientBrush)
      {
        XMatrix matrix = this.renderer.defaultViewMatrix;
        matrix.Prepend(this.Transform);
        PdfShadingPattern pattern = new PdfShadingPattern(this.renderer.Owner);
        pattern.SetupFromBrush((XLinearGradientBrush)brush, matrix);
        string name = this.renderer.Resources.AddPattern(pattern);
        this.renderer.AppendFormat("/Pattern cs\n", name);
        this.renderer.AppendFormat("{0} scn\n", name);

        // Invalidate fill color
        this.realizedFillColor = XColor.Empty;
      }
    }
예제 #3
0
        public void RealizeBrush(XBrush brush, PdfColorMode colorMode, int renderingMode, double fontEmSize)
        {
            // Rendering mode 2 is used for bold simulation.
            // Reference: TABLE 5.3  Text rendering modes / Page 402

            XSolidBrush solidBrush = brush as XSolidBrush;
            if (solidBrush != null)
            {
                XColor color = solidBrush.Color;
                bool overPrint = solidBrush.Overprint;

                if (renderingMode == 0)
                {
                    RealizeFillColor(color, overPrint, colorMode);
                }
                else if (renderingMode == 2)
                {
                    // Come here in case of bold simulation.
                    RealizeFillColor(color, false, colorMode);
                    //color = XColors.Green;
                    RealizePen(new XPen(color, fontEmSize * Const.BoldEmphasis), colorMode);
                }
                else
                    throw new InvalidOperationException("Only rendering modes 0 and 2 are currently supported.");
            }
            else
            {
                if (renderingMode != 0)
                    throw new InvalidOperationException("Rendering modes other than 0 can only be used with solid color brushes.");

                XLinearGradientBrush gradientBrush = brush as XLinearGradientBrush;
                if (gradientBrush != null)
                {
                    Debug.Assert(UnrealizedCtm.IsIdentity, "Must realize ctm first.");
                    XMatrix matrix = _renderer.DefaultViewMatrix;
                    matrix.Prepend(EffectiveCtm);
                    PdfShadingPattern pattern = new PdfShadingPattern(_renderer.Owner);
                    pattern.SetupFromBrush(gradientBrush, matrix, _renderer);
                    string name = _renderer.Resources.AddPattern(pattern);
                    _renderer.AppendFormatString("/Pattern cs\n", name);
                    _renderer.AppendFormatString("{0} scn\n", name);

                    // Invalidate fill color.
                    _realizedFillColor = XColor.Empty;
                }
            }
        }