Example #1
0
        public void SetClip(Rectangle rect, CombineMode combineMode)
        {
            RestoreInitialClip();
            CombineClippingRegion(combineMode, new Region(rect));

            _graphics.IntersectClip(rect);
        }
Example #2
0
        private static void RenderToGraphics(Render.RenderContext ctx, int rot, float translateX, float translateY, XGraphics graphics)
        {
            graphics.TranslateTransform(translateX, translateY);
            graphics.RotateTransform(rot * 90);

            using (Maps.Rendering.RenderUtil.SaveState(graphics))
            {
                if (ctx.clipPath != null)
                {
                    XMatrix m = ctx.ImageSpaceToWorldSpace;
                    graphics.MultiplyTransform(m);
                    graphics.IntersectClip(ctx.clipPath);
                    m.Invert();
                    graphics.MultiplyTransform(m);
                }

                ctx.graphics = graphics;
                Maps.Rendering.Render.RenderTile(ctx);
            }


            if (ctx.border && ctx.clipPath != null)
            {
                using (Maps.Rendering.RenderUtil.SaveState(graphics))
                {
                    // Render border in world space
                    XMatrix m = ctx.ImageSpaceToWorldSpace;
                    graphics.MultiplyTransform(m);
                    XPen pen = new XPen(ctx.styles.imageBorderColor, 0.2f);

                    // PdfSharp can't ExcludeClip so we take advantage of the fact that we know
                    // the path starts on the left edge and proceeds clockwise. We extend the
                    // path with a counterclockwise border around it, then use that to exclude
                    // the original path's region for rendering the border.
                    ctx.clipPath.Flatten();
                    RectangleF bounds = PathUtil.Bounds(ctx.clipPath);
                    bounds.Inflate(2 * (float)pen.Width, 2 * (float)pen.Width);
                    List <byte>   types  = new List <byte>(ctx.clipPath.Internals.GdiPath.PathTypes);
                    List <PointF> points = new List <PointF>(ctx.clipPath.Internals.GdiPath.PathPoints);

                    PointF key = points[0];
                    points.Add(new PointF(bounds.Left, key.Y)); types.Add(1);
                    points.Add(new PointF(bounds.Left, bounds.Bottom)); types.Add(1);
                    points.Add(new PointF(bounds.Right, bounds.Bottom)); types.Add(1);
                    points.Add(new PointF(bounds.Right, bounds.Top)); types.Add(1);
                    points.Add(new PointF(bounds.Left, bounds.Top)); types.Add(1);
                    points.Add(new PointF(bounds.Left, key.Y)); types.Add(1);
                    points.Add(new PointF(key.X, key.Y)); types.Add(1);

                    XGraphicsPath path = new XGraphicsPath(points.ToArray(), types.ToArray(), XFillMode.Winding);
                    graphics.IntersectClip(path);
                    graphics.DrawPath(pen, ctx.clipPath);
                }
            }
        }
        /// <summary>
        /// Demonstrates the use of XGraphics.Transform.
        /// </summary>
        public override void RenderPage(XGraphics gfx)
        {
            base.RenderPage(gfx);

            gfx.Save();

            gfx.IntersectClip(new XRect(20, 20, 300, 500));
            gfx.DrawRectangle(XBrushes.Yellow, 0, 0, gfx.PageSize.Width, gfx.PageSize.Height);

            gfx.IntersectClip(new XRect(100, 200, 300, 500));
            gfx.DrawRectangle(XBrushes.LightBlue, 0, 0, gfx.PageSize.Width, gfx.PageSize.Height);

            gfx.DrawLine(XPens.MediumSlateBlue, 0, 0, 150, 200);
            gfx.DrawPolygon(properties.Pen1.Pen, GetPentagram(75, new PointF(150, 200)));


            Matrix matrix = new Matrix();

            //matrix.Scale(2f, 1.5f);
            //matrix.Translate(-200, -400);
            //matrix.Rotate(45);
            //matrix.Translate(200, 400);
            //gfx.Transform = matrix;
            //gfx.TranslateTransform(50, 30);

#if true
            gfx.TranslateTransform(30, 40, XMatrixOrder.Prepend);
            gfx.ScaleTransform(2.0f, 2.0f, XMatrixOrder.Prepend);
            gfx.RotateTransform(15, XMatrixOrder.Prepend);
#else
            gfx.TranslateTransform(30, 40, XMatrixOrder.Append);
            gfx.ScaleTransform(2.0f, 2.0f, XMatrixOrder.Append);
            gfx.RotateTransform(15, XMatrixOrder.Append);
#endif
            bool id = matrix.IsIdentity;
            matrix.Scale(2.0f, 2.0f, MatrixOrder.Prepend);
            //matrix.Translate(30, -50);
            matrix.Rotate(15, MatrixOrder.Prepend);
            //Matrix mtx = gfx.Transform.ToGdipMatrix();
            //gfx.Transform = matrix;

            gfx.DrawLine(XPens.MediumSlateBlue, 0, 0, 150, 200);
            gfx.DrawPolygon(properties.Pen2.Pen, GetPentagram(75, new PointF(150, 200)));

            //gfx.ResetClip();
            gfx.Restore();

            gfx.DrawLine(XPens.Red, 0, 0, 1000, 1000);

            gfx.DrawPolygon(XPens.SandyBrown, GetPentagram(75, new PointF(150, 200)));
        }
Example #4
0
        void Box(XGraphics gfx, XRect rect, double startAngle, double sweepAngle)
        {
            double xc = rect.X + rect.Width / 2;
            double yc = rect.Y + rect.Height / 2;
            double a  = startAngle * 0.017453292519943295;
            double b  = (startAngle + sweepAngle) * 0.017453292519943295;

            XGraphicsState state = gfx.Save();

            gfx.IntersectClip(rect);
#if true
#if true_
            for (double deg = 0; deg < 360; deg += 10)
            {
                gfx.DrawLine(XPens.Yellow, xc, yc,
                             (xc + rect.Width / 2 * Math.Cos(deg * 0.017453292519943295)),
                             (yc + rect.Height / 2 * Math.Sin(deg * 0.017453292519943295)));
            }
#endif
            double f = Math.Max(rect.Width / 2, rect.Height / 2);
            for (double deg = 0; deg < 360; deg += 10)
            {
                gfx.DrawLine(XPens.Goldenrod, xc, yc,
                             (xc + f * Math.Cos(deg * 0.017453292519943295)),
                             (yc + f * Math.Sin(deg * 0.017453292519943295)));
            }

            gfx.DrawLine(XPens.PaleGreen, xc, rect.Y, xc, rect.Y + rect.Height);
            gfx.DrawLine(XPens.PaleGreen, rect.X, yc, rect.X + rect.Width, yc);
            //gfx.DrawLine(XPens.DarkGray, xc, yc, (xc + rect.Width / 2 * Math.Cos(a)), (yc + rect.Height / 2 * Math.Sin(a)));
            //gfx.DrawLine(XPens.DarkGray, xc, yc, (xc + rect.Width / 2 * Math.Cos(b)), (yc + rect.Height / 2 * Math.Sin(b)));
#endif
            gfx.Restore(state);
            gfx.DrawRectangle(properties.Pen1.Pen, rect);
        }
Example #5
0
        public override void RenderPage(XGraphics gfx)
        {
            base.RenderPage(gfx);

            // Create a new graphical path
            XGraphicsPath path = new XGraphicsPath();

            // Add the outline of the glyphs of the word 'Clip' to the path
            path.AddString("Clip!", new XFontFamily("Times New Roman"), XFontStyle.BoldItalic, 250, new XPoint(30, 100), XStringFormats.Default);

#if DEBUG_
            gfx.WriteComment("SetClip");
#endif
            // Set the path as clip path
            gfx.IntersectClip(path);
#if DEBUG_
            gfx.WriteComment("Random lines");
#endif
            // Draw some random lines to show that clipping happens
            Random rnd = new Random(42);
            for (int idx = 0; idx < 300; idx++)
            {
                gfx.DrawLine(properties.Pen2.Pen, rnd.Next(600), rnd.Next(500), rnd.Next(600), rnd.Next(500));
            }
        }
Example #6
0
        void IDrawingCanvas.DrawString(string value, FontInfo font, BrushEx brush, RectangleF rect, StringFormatEx format)
        {
            if (string.IsNullOrEmpty(value))
            {
                return;
            }

            XGraphicsContainer clipState = _graphics.BeginContainer();
            var xRect = PdfConverter.Convert(rect);
            var xFont = _fonts.GetPdfFont(font);

            _graphics.IntersectClip(xRect);
            var resultRect = _graphics.MeasureString(value, xFont, GetFormat(format));

            if ((format.WrapMode == WrapMode.NoWrap && !value.Contains('\n')) ||
                (resultRect.Width * PdfConverter.TwipsPerPoint <= rect.Width))
            {
                _graphics.DrawString(value, xFont, (BrushBase)brush, xRect, GetFormat(format));
                _graphics.EndContainer(clipState);
                return;
            }

            if (format.WrapMode == WrapMode.NoWrap && value.Contains('\n'))
            {
                var lines = value.Split('\n');
                var y     = xRect.Y;
                for (var i = 0; i < lines.Length; i++)
                {
                    var line = lines[i].Trim('\r');
                    _graphics.DrawString(line, xFont, (BrushBase)brush, new XRect(xRect.X, y, xRect.Width, resultRect.Height), GetFormat(format));
                    y += resultRect.Height;
                }
                _graphics.EndContainer(clipState);
                return;
            }

            // http://developer.th-soft.com/developer/2015/07/17/pdfsharp-improving-the-xtextformatter-class-measuring-the-height-of-the-text/
            // http://developer.th-soft.com/developer/2015/09/21/xtextformatter-revisited-xtextformatterex2-for-pdfsharp-1-50-beta-2/
            var tf = new XTextFormatter(_graphics)
            {
                Alignment = GetAlignment(format)
            };

            tf.DrawString(value, xFont, (BrushBase)brush, xRect);

            _graphics.EndContainer(clipState);
        }
Example #7
0
        /// <summary>
        ///   Draw a multi-line string as it would be drawn by GDI+.
        ///   Compensates for issues and draw-vs-PDF differences in PDFsharp.
        /// </summary>
        /// <param name="graphics">The graphics with which to draw.</param>
        /// <param name="font">The font with which to draw.</param>
        /// <param name="brush">The brush with which to draw.</param>
        /// <param name="pos">The position at which to draw.</param>
        /// <param name="size">The size to which to limit the drawn text; or Vector.Zero for no limit.</param>
        /// <param name="format">The string format to use.</param>
        /// <param name="maxObjects"></param>
        /// <param name="text">The text to draw, which may contain line breaks.</param>
        /// <remarks>
        ///   PDFsharp cannot currently render multi-line text to PDF files; it comes out as single line.
        ///   This method simulates standard Graphics.DrawString() over PDFsharp.
        ///   It always has the effect of StringFormatFlags.LineLimit (which PDFsharp does not support).
        /// </remarks>
        public Rect Draw(XGraphics graphics, Font font, Brush brush, Vector pos, Vector size, XStringFormat format)
        {
            // do a quick test to see if text is going to get drawn at the same size as last time;
            // if so, assume we don't need to recompute our layout for that reason.
            var sizeChecker = graphics.MeasureString("M q", font);

            if (sizeChecker != m_sizeChecker || pos != m_pos || m_size != size || m_requestedFormat.Alignment != format.Alignment || m_requestedFormat.LineAlignment != format.LineAlignment || m_requestedFormat.FormatFlags != format.FormatFlags)
            {
                m_invalidLayout = true;
            }
            m_sizeChecker = sizeChecker;

            if (m_invalidLayout)
            {
                // something vital has changed; rebuild our cached layout data
                RebuildCachedLayout(graphics, font, ref pos, ref size, format);
                m_invalidLayout = false;
            }

            var state    = graphics.Save();
            var textRect = new RectangleF(pos.X, pos.Y, size.X, size.Y);

            if (size != Vector.Zero)
            {
                graphics.IntersectClip(textRect);
            }

            // disable smoothing whilst rendering text;
            // visually this is no different, but is faster
            var smoothingMode = graphics.SmoothingMode;

            graphics.SmoothingMode = XSmoothingMode.HighSpeed;

            var origin = m_origin;

            foreach (string t in m_lines)
            {
                if (size.Y > 0 && size.Y < m_lineHeight)
                {
                    break; // not enough remaining vertical space for a whole line
                }
                var line = t;

                graphics.SmoothingMode = XSmoothingMode.HighQuality;


                graphics.DrawString(line, font, brush, origin.X, origin.Y, m_actualFormat);
                origin += m_delta;
                size.Y -= m_lineHeight;
            }

            graphics.SmoothingMode = smoothingMode;
            graphics.Restore(state);

            var actualTextRect = new Rect(pos.X, m_origin.Y, size.X, m_lineHeight * m_lines.Count);

            return(actualTextRect);
        }
Example #8
0
        /// <summary>
        /// Demonstrates the use of XGraphics.SetClip.
        /// </summary>
        public override void RenderPage(XGraphics gfx)
        {
            base.RenderPage(gfx);

            gfx.Save();
            gfx.TranslateTransform(50, 50);
            gfx.IntersectClip(new Rectangle(0, 0, 400, 250));
            gfx.TranslateTransform(50, 50);
            //gfx.Clear(XColor.GhostWhite);
            gfx.DrawEllipse(XPens.Green, XBrushes.Yellow, 40, 40, 500, 500);
            gfx.Restore();

            gfx.Save();
            //gfx.Transform = new XMatrix();  //XMatrix.Identity;
            gfx.TranslateTransform(200, 200);
            gfx.IntersectClip(new Rectangle(0, 0, 400, 250));
            gfx.DrawEllipse(XPens.Green, XBrushes.Yellow, 40, 40, 500, 500);
            gfx.Restore();
        }
Example #9
0
        private void DrawClipPath(XGraphics gfx, int number)
        {
            base.BeginBox(gfx, number, "Clip through Path");
            XGraphicsPath xGraphicsPath = new XGraphicsPath();

            xGraphicsPath.AddString("Clip!", new XFontFamily("Verdana"), XFontStyle.Bold, 90.0, new XRect(0.0, 0.0, 250.0, 140.0), XStringFormats.Center);
            gfx.IntersectClip(xGraphicsPath);
            XPen xPen = XPens.DarkRed.Clone();

            xPen.DashStyle = XDashStyle.Dot;
            for (double num = 0.0; num <= 90.0; num += 0.5)
            {
                gfx.DrawLine(xPen, 0.0, 0.0, 250.0 * Math.Cos(num / 90.0 * 3.1415926535897931), 250.0 * Math.Sin(num / 90.0 * 3.1415926535897931));
            }
            base.EndBox(gfx);
        }
        /// <summary>
        /// Draws the content of the line plot area.
        /// </summary>
        internal override void Draw()
        {
            ChartRendererInfo cri = (ChartRendererInfo)this.rendererParms.RendererInfo;

            XRect plotAreaRect = cri.plotAreaRendererInfo.Rect;

            if (plotAreaRect.IsEmpty)
            {
                return;
            }

            XGraphics      gfx   = this.rendererParms.Graphics;
            XGraphicsState state = gfx.Save();

            //gfx.SetClip(plotAreaRect, XCombineMode.Intersect);
            gfx.IntersectClip(plotAreaRect);

            //TODO null-Values müssen berücksichtigt werden.
            //     Verbindungspunkte können fehlen, je nachdem wie null-Values behandelt werden sollen.
            //     (NotPlotted, Interpolate etc.)

            // Draw lines and markers for each data series.
            XMatrix matrix = cri.plotAreaRendererInfo.matrix;

            double xMajorTick = cri.xAxisRendererInfo.MajorTick;

            foreach (SeriesRendererInfo sri in cri.seriesRendererInfos)
            {
                int      count  = sri.series.Elements.Count;
                XPoint[] points = new XPoint[count];
                for (int idx = 0; idx < count; idx++)
                {
                    double v = sri.series.Elements[idx].Value;
                    if (double.IsNaN(v))
                    {
                        v = 0;
                    }
                    points[idx] = new XPoint(idx + xMajorTick / 2, v);
                }
                matrix.TransformPoints(points);
                gfx.DrawLines(sri.LineFormat, points);
                DrawMarker(gfx, points, sri);
            }

            //gfx.ResetClip();
            gfx.Restore(state);
        }
Example #11
0
        /// <summary>
        /// Draws the content of the line plot area.
        /// </summary>
        internal override void Draw()
        {
            ChartRendererInfo cri = (ChartRendererInfo)_rendererParms.RendererInfo;

            XRect plotAreaRect = cri.plotAreaRendererInfo.Rect;

            if (plotAreaRect.IsEmpty)
            {
                return;
            }

            XGraphics      gfx   = _rendererParms.Graphics;
            XGraphicsState state = gfx.Save();

            //gfx.SetClip(plotAreaRect, XCombineMode.Intersect);
            gfx.IntersectClip(plotAreaRect);

            //TODO Treat null values correctly.
            //     Points can be missing. Treat null values accordingly (NotPlotted, Interpolate etc.)

            // Draw lines and markers for each data series.
            XMatrix matrix = cri.plotAreaRendererInfo._matrix;

            double xMajorTick = cri.xAxisRendererInfo.MajorTick;

            foreach (SeriesRendererInfo sri in cri.seriesRendererInfos)
            {
                int      count  = sri._series.Elements.Count;
                XPoint[] points = new XPoint[count];
                for (int idx = 0; idx < count; idx++)
                {
                    double v = sri._series.Elements[idx].Value;
                    if (double.IsNaN(v))
                    {
                        v = 0;
                    }
                    points[idx] = new XPoint(idx + xMajorTick / 2, v);
                }
                matrix.TransformPoints(points);
                gfx.DrawLines(sri.LineFormat, points);
                DrawMarker(gfx, points, sri);
            }

            //gfx.ResetClip();
            gfx.Restore(state);
        }
        /// <summary>
        /// Draws the content of the area plot area.
        /// </summary>
        internal override void Draw()
        {
            ChartRendererInfo cri          = (ChartRendererInfo)_rendererParms.RendererInfo;
            XRect             plotAreaRect = cri.plotAreaRendererInfo.Rect;

            if (plotAreaRect.IsEmpty)
            {
                return;
            }

            XGraphics      gfx   = _rendererParms.Graphics;
            XGraphicsState state = gfx.Save();

            //gfx.SetClip(plotAreaRect, XCombineMode.Intersect);
            gfx.IntersectClip(plotAreaRect);

            XMatrix matrix     = cri.plotAreaRendererInfo._matrix;
            double  xMajorTick = cri.xAxisRendererInfo.MajorTick;

            foreach (SeriesRendererInfo sri in cri.seriesRendererInfos)
            {
                int      count  = sri._series.Elements.Count;
                XPoint[] points = new XPoint[count + 2];
                points[0] = new XPoint(xMajorTick / 2, 0);
                for (int idx = 0; idx < count; idx++)
                {
                    double pointValue = sri._series.Elements[idx].Value;
                    if (double.IsNaN(pointValue))
                    {
                        pointValue = 0;
                    }
                    points[idx + 1] = new XPoint(idx + xMajorTick / 2, pointValue);
                }
                points[count + 1] = new XPoint(count - 1 + xMajorTick / 2, 0);
                matrix.TransformPoints(points);
                gfx.DrawPolygon(sri.LineFormat, sri.FillFormat, points, XFillMode.Winding);
            }

            //gfx.ResetClip();
            gfx.Restore(state);
        }
Example #13
0
        void RenderClipPath(XGraphics gfx)
        {
            gfx.TranslateTransform(15, 20);

            XGraphicsPath path = new XGraphicsPath();

            path.AddString("Clip!", new XFontFamily("Verdana"), XFontStyle.Bold, 90, new XRect(0, 0, 250, 140),
                           XStringFormats.Center);

            gfx.IntersectClip(path);

            gfx.DrawRectangle(XBrushes.LightSalmon, new XRect(0, 0, 10000, 10000));
            // Draw a beam of dotted lines
            XPen pen = XPens.DarkRed.Clone();

            pen.DashStyle = XDashStyle.Dot;
            for (double r = 0; r <= 90; r += 0.5)
            {
                gfx.DrawLine(pen, 0, 0, 1000 * Math.Cos(r / 90 * Math.PI), 1000 * Math.Sin(r / 90 * Math.PI));
            }
        }
        /// <summary>
        /// Draw the texture image in the given graphics at the given location.
        /// </summary>
        public void DrawRectangle(XGraphics g, double x, double y, double width, double height)
        {
            var prevState = g.Save();

            g.IntersectClip(new XRect(x, y, width, height));

            double rx = _translateTransformLocation.X;
            double w = _image.PixelWidth, h = _image.PixelHeight;

            while (rx < x + width)
            {
                double ry = _translateTransformLocation.Y;
                while (ry < y + height)
                {
                    g.DrawImage(_image, rx, ry, w, h);
                    ry += h;
                }
                rx += w;
            }

            g.Restore(prevState);
        }
Example #15
0
        /// <summary>
        /// Clips through path.
        /// </summary>
        void DrawClipPath(XGraphics gfx, int number)
        {
            BeginBox(gfx, number, "Clip through Path");

#if CORE
            DrawMessage(gfx, "AddString is not implemented in PDFsharp Core.");
#else
            var path = new XGraphicsPath();
            path.AddString("Clip!", new XFontFamily("Verdana"), XFontStyle.Bold, 90, new XRect(0, 0, 250, 140), XStringFormats.Center);
            gfx.IntersectClip(path);

            // Draw a beam of dotted lines.
            var pen = XPens.DarkRed.Clone();
            pen.DashStyle = XDashStyle.Dot;
            for (double r = 0; r <= 90; r += 0.5)
            {
                gfx.DrawLine(pen, 0, 0, 250 * Math.Cos(r / 90 * Math.PI), 250 * Math.Sin(r / 90 * Math.PI));
            }
#endif

            EndBox(gfx);
        }
Example #16
0
        static void DrawClipPath(XGraphics gfx, int number)
        {
            BeginBox(gfx, number, "Clip through Path");

            XGraphicsPath path = new XGraphicsPath();

            path.AddString("Clip!", new XFontFamily("Verdana"), XFontStyle.Bold, 90, new XRect(0, 0, 250, 140),
                           XStringFormats.Center);

            gfx.IntersectClip(path);

            // Draw a beam of dotted lines
            XPen pen = XPens.DarkRed.Clone();

            pen.DashStyle = XDashStyle.Dot;
            for (double r = 0; r <= 90; r += 0.5)
            {
                gfx.DrawLine(pen, 0, 0, 250 * System.Math.Cos(r / 90 * System.Math.PI), 250 * System.Math.Sin(r / 90 * System.Math.PI));
            }

            EndBox(gfx);
        }
Example #17
0
        /// <summary>
        /// Demonstrates the use of XGraphics.Transform.
        /// </summary>
        public override void RenderPage(XGraphics gfx)
        {
            XGraphicsState state1, state2;

            base.RenderPage(gfx);

            state1 = gfx.Save(); // Level 1
            gfx.TranslateTransform(20, 50);
            gfx.DrawLine(XPens.Blue, 0, 0, 10, 10);
            gfx.Restore(state1);

            state1 = gfx.Save(); // Level 2
            gfx.TranslateTransform(220, 50);
            gfx.DrawLine(XPens.Blue, 0, 0, 10, 10);
            XGraphicsPath clipPath = new XGraphicsPath();

            clipPath.AddPie(0, 10, 150, 100, -50, 100);
            gfx.IntersectClip(clipPath);
            gfx.DrawRectangle(XBrushes.LightYellow, 0, 0, 1000, 1000);

            state2 = gfx.Save(); // Level 3
            gfx.ScaleTransform(10);
            gfx.DrawLine(XPens.Red, 1, 1, 10, 10);

            //gfx.ResetClip();
            gfx.Restore(state2); // Level 2

            gfx.DrawLine(XPens.Red, 1, 1, 10, 10);

            gfx.Restore(state1);

#if true_
            gfx.SetClip(new XRect(20, 20, 300, 500));
            gfx.DrawRectangle(XBrushes.Yellow, 0, 0, gfx.PageSize.Width, gfx.PageSize.Height);

            gfx.SetClip(new XRect(100, 200, 300, 500), XCombineMode.Intersect);
            gfx.DrawRectangle(XBrushes.LightBlue, 0, 0, gfx.PageSize.Width, gfx.PageSize.Height);

            gfx.DrawLine(XPens.MediumSlateBlue, 0, 0, 150, 200);
            gfx.DrawPolygon(properties.Pen1.Pen, GetPentagram(75, new PointF(150, 200)));


            Matrix matrix = new Matrix();
            //matrix.Scale(2f, 1.5f);
            //matrix.Translate(-200, -400);
            //matrix.Rotate(45);
            //matrix.Translate(200, 400);
            //gfx.Transform = matrix;
            //gfx.TranslateTransform(50, 30);

#if true
            gfx.TranslateTransform(30, 40, XMatrixOrder.Prepend);
            gfx.ScaleTransform(2.0f, 2.0f, XMatrixOrder.Prepend);
            gfx.RotateTransform(15, XMatrixOrder.Prepend);
#else
            gfx.TranslateTransform(30, 40, XMatrixOrder.Append);
            gfx.ScaleTransform(2.0f, 2.0f, XMatrixOrder.Append);
            gfx.RotateTransform(15, XMatrixOrder.Append);
#endif
            bool id = matrix.IsIdentity;
            matrix.Scale(2.0f, 2.0f, MatrixOrder.Prepend);
            //matrix.Translate(30, -50);
            matrix.Rotate(15, MatrixOrder.Prepend);
            Matrix mtx = gfx.Transform.ToMatrix();
            //gfx.Transform = matrix;

            gfx.DrawLine(XPens.MediumSlateBlue, 0, 0, 150, 200);
            gfx.DrawPolygon(properties.Pen2.Pen, GetPentagram(75, new PointF(150, 200)));

            gfx.ResetClip();

            gfx.DrawLine(XPens.Red, 0, 0, 1000, 1000);

            gfx.DrawPolygon(XPens.SandyBrown, GetPentagram(75, new PointF(150, 200)));
#endif
        }
Example #18
0
        private static void printSeriesData(PdfPage page, int x, int y, int width, int height, List <Shot> shotList, int index, Session session)
        {
            XGraphics gfx = XGraphics.FromPdfPage(page);

            gfx.IntersectClip(new XRect(x, y, width, height));
            XPen   penBlack   = new XPen(XColor.FromKnownColor(XKnownColor.Black), 0.5);
            XBrush brushBlack = new XSolidBrush(XColor.FromKnownColor(XKnownColor.Black));

            XTextFormatter tf = new XTextFormatter(gfx);

            tf.Alignment = XParagraphAlignment.Left;
            Font fMedium     = new Font("Arial", 10, GraphicsUnit.World);
            Font fMediumBold = new Font("Arial", 10, FontStyle.Bold, GraphicsUnit.World);

            XPoint point = new XPoint(x, y);

            point.Offset(5, 5);
            String s    = "Series " + index;
            XSize  rect = gfx.MeasureString(s, fMediumBold);

            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            //new line
            point = new XPoint(x + 5, point.Y + rect.Height + 5);
            s     = "Score:";
            rect  = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            int X;

            point.Offset(rect.Width + 2, 0);
            decimal score = sumScores(session, shotList, out X);

            if (session.decimalScoring)
            {
                s = score.ToString("F1", CultureInfo.InvariantCulture) + " - " + X + "x";
            }
            else
            {
                s = score.ToString("F0", CultureInfo.InvariantCulture) + " - " + X + "x";
            }
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            //new line
            point = new XPoint(x + 5, point.Y + rect.Height + 5);
            s     = "Shots:";
            rect  = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 2, 0);
            s = "";
            foreach (Shot shot in shotList)
            {
                string t = shot.innerTen ? "*" : "";
                if (session.decimalScoring)
                {
                    s += shot.decimalScore.ToString("F1", CultureInfo.InvariantCulture) + t + "   ";
                }
                else
                {
                    s += shot.score + t + "   ";
                }
            }
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));


            //new line
            point = new XPoint(x + 5, point.Y + rect.Height + 5);
            s     = "Average score:";
            rect  = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 1, 0);
            decimal avg = score / shotList.Count;

            s    = avg.ToString("F2", CultureInfo.InvariantCulture);
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));



            decimal localRbar;
            decimal localXbar;
            decimal localYbar;

            computeMeans(out localRbar, out localXbar, out localYbar, shotList);

            //new line
            point = new XPoint(x + 5, point.Y + rect.Height + 5);
            s     = "MPI: ";
            rect  = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 1, 0);
            string W, E;

            if (localXbar < 0)
            {
                W = "\u2190";
            }
            else
            {
                W = "\u2192";
            }

            if (localYbar < 0)
            {
                E = "\u2193";
            }
            else
            {
                E = "\u2191";
            }
            s    = W + Math.Abs(localXbar).ToString("F2", CultureInfo.InvariantCulture) + "mm" + "  " + E + Math.Abs(localYbar).ToString("F2", CultureInfo.InvariantCulture) + "mm";
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 5, 0);
            s    = "MR:";
            rect = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 1, 0);
            s    = localRbar.ToString("F2", CultureInfo.InvariantCulture) + "mm";
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 5, 0);
            s    = "Group size:";
            rect = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 1, 0);
            s    = calculateMaxSpread(shotList).ToString("F2", CultureInfo.InvariantCulture) + "mm";
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            //new line
            point = new XPoint(x + 5, point.Y + rect.Height + 5);
            s     = "First shot:";
            rect  = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 1, 0);
            s    = shotList[0].timestamp.ToString("hh:mm:ss");
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 5, 0);
            s    = "Last shot:";
            rect = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 1, 0);
            s    = shotList[shotList.Count - 1].timestamp.ToString("hh:mm:ss");
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            TimeSpan shortest;
            TimeSpan longest;
            TimeSpan avgTime;

            calculateTimeStats(out shortest, out longest, out avgTime, shotList);
            //new line
            point = new XPoint(x + 5, point.Y + rect.Height + 5);
            s     = "Avg Shot time:";
            rect  = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 1, 0);
            s    = avgTime.TotalSeconds.ToString("F2", CultureInfo.InvariantCulture) + "s";
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 5, 0);
            s    = "Shortest:";
            rect = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 1, 0);
            s    = shortest.TotalSeconds.ToString("F2", CultureInfo.InvariantCulture) + "s";
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 5, 0);
            s    = "Longest:";
            rect = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 1, 0);
            s    = longest.TotalSeconds.ToString("F2", CultureInfo.InvariantCulture) + "s";
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));


            gfx.DrawRectangle(penBlack, x, y, width, height);
            gfx.Dispose();
        }
Example #19
0
        private static void printSessionData(PdfPage page, int x, int y, int width, int height, Session session)
        {
            XGraphics gfx = XGraphics.FromPdfPage(page);

            gfx.IntersectClip(new XRect(x, y, width, height));
            XPen   penBlack   = new XPen(XColor.FromKnownColor(XKnownColor.Black), 0.5);
            XBrush brushBlack = new XSolidBrush(XColor.FromKnownColor(XKnownColor.Black));


            XTextFormatter tf = new XTextFormatter(gfx);

            tf.Alignment = XParagraphAlignment.Left;
            Font fLarge      = new Font("Arial", 12, FontStyle.Bold, GraphicsUnit.World);
            Font fMedium     = new Font("Arial", 10, GraphicsUnit.World);
            Font fMediumBold = new Font("Arial", 10, FontStyle.Bold, GraphicsUnit.World);
            Font fSmall      = new Font("Arial", 8, GraphicsUnit.World);

            String s = "Match summary";

            XPoint point = new XPoint(x, y);

            point.Offset(5, 5);
            s = "Session ID:";
            XSize rect = gfx.MeasureString(s, fMediumBold);

            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 5, 0);
            s    = session.id.ToString();
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));



            //new line
            point = new XPoint(x, y);
            point.Offset(5, 5);
            point.Offset(0, rect.Height + 5);
            s    = "Event:";
            rect = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 5, 0);
            s = session.eventType.Name;
            if (session.numberOfShots > 0)
            {
                s += " " + session.numberOfShots;
            }
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));


            //new line
            point = new XPoint(x + 5, point.Y + rect.Height + 5);
            s     = "Shooter:";
            rect  = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 5, 0);
            s    = session.user;
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));


            //new line
            point = new XPoint(x + 5, point.Y + rect.Height + 5);
            s     = "Start Time: ";
            rect  = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width, 0);
            s    = session.startTime.ToString("yyyy-MM-dd hh:mm:ss");
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            //new line
            point = new XPoint(x + 5, point.Y + rect.Height + 5);
            s     = "End Time: ";
            rect  = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width, 0);
            s    = session.endTime.ToString("yyyy-MM-dd hh:mm:ss");
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 15, 0);
            s    = "Duration:";
            rect = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 1, 0);
            s    = (session.endTime - session.startTime).TotalMinutes.ToString("F2", CultureInfo.InvariantCulture) + " mins";
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            //new line
            point = new XPoint(x + 5, point.Y + rect.Height + 5);
            s     = "Avg Shot time:";
            rect  = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 1, 0);
            s    = session.averageTimePerShot.TotalSeconds.ToString("F2", CultureInfo.InvariantCulture) + "s";
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 5, 0);
            s    = "Shortest:";
            rect = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 1, 0);
            s    = session.shortestShot.TotalSeconds.ToString("F2", CultureInfo.InvariantCulture) + "s";
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 5, 0);
            s    = "Longest:";
            rect = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 1, 0);
            s    = session.longestShot.TotalSeconds.ToString("F2", CultureInfo.InvariantCulture) + "s";
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));


            //new line
            point = new XPoint(x + 5, point.Y + rect.Height + 5);
            s     = "MPI: ";
            rect  = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 1, 0);
            string W, E;

            if (session.xbar < 0)
            {
                W = "\u2190";
            }
            else
            {
                W = "\u2192";
            }

            if (session.ybar < 0)
            {
                E = "\u2193";
            }
            else
            {
                E = "\u2191";
            }
            s    = W + Math.Abs(session.xbar).ToString("F2", CultureInfo.InvariantCulture) + "mm" + "  " + E + Math.Abs(session.ybar).ToString("F2", CultureInfo.InvariantCulture) + "mm";
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 5, 0);
            s    = "MR:";
            rect = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 1, 0);
            s    = session.rbar.ToString("F2", CultureInfo.InvariantCulture) + "mm";
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 5, 0);
            s    = "Group size:";
            rect = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 1, 0);
            s    = session.groupSize.ToString("F2", CultureInfo.InvariantCulture) + "mm";
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            //new line
            point = new XPoint(x + 5, point.Y + rect.Height + 5);
            s     = "Total Score:";
            rect  = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 5, 0);
            if (session.decimalScoring)
            {
                s = session.decimalScore.ToString("F1", CultureInfo.InvariantCulture) + " - " + session.innerX + "x";
            }
            else
            {
                s = session.score.ToString() + " - " + session.innerX + "x";
            }
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 10, 0);
            s    = "Average score:";
            rect = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 1, 0);
            s    = session.averageScore.ToString("F2", CultureInfo.InvariantCulture);
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            //new line
            point = new XPoint(x + 5, point.Y + rect.Height + 5);
            s     = "Number of shots in session:";
            rect  = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 2, 0);
            s    = session.actualNumberOfShots.ToString();
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            //new line
            point = new XPoint(x + 5, point.Y + rect.Height + 5);
            s     = "Series:";
            rect  = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 2, 0);
            s = "";
            int X;

            foreach (List <Shot> shots in session.AllSeries)
            {
                if (session.decimalScoring)
                {
                    s += sumScores(session, shots, out X).ToString("F1", CultureInfo.InvariantCulture) + " ";
                }
                else
                {
                    s += sumScores(session, shots, out X).ToString("F0", CultureInfo.InvariantCulture) + " ";
                }
            }
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            //new line
            point = new XPoint(x + 5, point.Y + rect.Height + 5);
            drawBreakdownGraph(gfx, point.X, point.Y, width - 10, height - point.Y + 15, session);

            gfx.DrawRectangle(penBlack, x, y, width, height);
            gfx.Dispose();
        }
Example #20
0
        private static void paintTarget(int dimension, int xLoc, int yLoc, int blackRingCutoff, decimal[] rings, decimal zoomFactor, bool solidInner, List <Shot> shotsList, PdfPage page)
        {
            XPen   penBlack   = new XPen(XColor.FromKnownColor(XKnownColor.Black), 0.5);
            XPen   penWhite   = new XPen(XColor.FromKnownColor(XKnownColor.Linen), 0.5);
            XBrush brushBlack = new XSolidBrush(XColor.FromKnownColor(XKnownColor.Black));
            XBrush brushWhite = new XSolidBrush(XColor.FromKnownColor(XKnownColor.Linen));

            XGraphics gfx = XGraphics.FromPdfPage(page);

            gfx.IntersectClip(new XRect(xLoc, yLoc, dimension, dimension));

            gfx.SmoothingMode = XSmoothingMode.AntiAlias;

            gfx.DrawRectangle(brushWhite, xLoc, yLoc, dimension, dimension);

            int r = 1;

            for (int i = 0; i < rings.Length; i++)
            {
                XPen   p;
                XBrush b;
                XBrush bText;
                if (r < blackRingCutoff)
                {
                    p     = penBlack;
                    b     = brushWhite;
                    bText = brushBlack;
                }
                else
                {
                    p     = penWhite;
                    b     = brushBlack;
                    bText = brushWhite;
                }

                float circle  = getDimension(dimension, rings[i], zoomFactor);
                float centerX = (dimension / 2) + xLoc;
                float centerY = (dimension / 2) + yLoc;
                float x       = centerX - (circle / 2);
                float y       = centerY - (circle / 2);
                float xInvers = centerX + (circle / 2);
                float yInvers = centerY + (circle / 2);


                if (solidInner && i == rings.Length - 1) //rifle target - last ring (10) is a solid dot
                {
                    gfx.DrawEllipse(brushWhite, x, y, circle, circle);
                }
                else
                {
                    gfx.DrawEllipse(b, x, y, circle, circle);
                    gfx.DrawEllipse(p, x, y, circle, circle);
                }

                if (r < 9) //for ring 9 and after no text is displayed
                {
                    float nextCircle = getDimension(dimension, rings[i + 1], zoomFactor);
                    float diff       = circle - nextCircle;
                    float fontSize   = diff / 6f;
                    Font  f          = new Font("Arial", fontSize, GraphicsUnit.World);

                    XStringFormat format = new XStringFormat();
                    format.LineAlignment = (XLineAlignment)XStringAlignment.Center;
                    format.Alignment     = XStringAlignment.Center;

                    gfx.DrawString(r.ToString(), f, bText, centerX, y + (diff / 4), format);
                    gfx.DrawString(r.ToString(), f, bText, centerX, yInvers - (diff / 4), format);
                    gfx.DrawString(r.ToString(), f, bText, x + (diff / 4), centerY, format);
                    gfx.DrawString(r.ToString(), f, bText, xInvers - (diff / 4), centerY, format);
                }
                r++;
            }

            gfx.DrawRectangle(penBlack, xLoc, yLoc, dimension, dimension);

            foreach (Shot shot in shotsList)
            {
                drawShot(shot, gfx, xLoc, yLoc, dimension, zoomFactor);
            }

            decimal localRbar;
            decimal localXbar;
            decimal localYbar;

            computeMeans(out localRbar, out localXbar, out localYbar, shotsList);

            drawMeanGroup(gfx, dimension, zoomFactor, shotsList, localRbar, localXbar, localYbar, xLoc, yLoc);

            gfx.Dispose();
        }
Example #21
0
        /// <summary>
        /// Creates the normal appearance form X object for the annotation that represents
        /// this acro form text field.
        /// </summary>
        void RenderAppearance()
        {
            if (string.IsNullOrEmpty(Text))
            {
                Elements.Remove(PdfAnnotation.Keys.AP);
                return;
            }
#if true_
            PdfFormXObject xobj = new PdfFormXObject(Owner);
            Owner.Internals.AddObject(xobj);
            xobj.Elements["/BBox"]     = new PdfLiteral("[0 0 122.653 12.707]");
            xobj.Elements["/FormType"] = new PdfLiteral("1");
            xobj.Elements["/Matrix"]   = new PdfLiteral("[1 0 0 1 0 0]");
            PdfDictionary res = new PdfDictionary(Owner);
            xobj.Elements["/Resources"] = res;
            res.Elements["/Font"]       = new PdfLiteral("<< /Helv 28 0 R >> /ProcSet [/PDF /Text]");
            xobj.Elements["/Subtype"]   = new PdfLiteral("/Form");
            xobj.Elements["/Type"]      = new PdfLiteral("/XObject");

            string s =
                "/Tx BMC " + '\n' +
                "q" + '\n' +
                "1 1 120.653 10.707 re" + '\n' +
                "W" + '\n' +
                "n" + '\n' +
                "BT" + '\n' +
                "/Helv 7.93 Tf" + '\n' +
                "0 g" + '\n' +
                "2 3.412 Td" + '\n' +
                "(Hello ) Tj" + '\n' +
                "20.256 0 Td" + '\n' +
                "(XXX) Tj" + '\n' +
                "ET" + '\n' +
                "Q" + '\n' +
                "";//"EMC";
            int    length = s.Length;
            byte[] stream = new byte[length];
            for (int idx = 0; idx < length; idx++)
            {
                stream[idx] = (byte)s[idx];
            }
            xobj.CreateStream(stream);

            // Get existing or create new appearance dictionary
            PdfDictionary ap = Elements[PdfAnnotation.Keys.AP] as PdfDictionary;
            if (ap == null)
            {
                ap = new PdfDictionary(_document);
                Elements[PdfAnnotation.Keys.AP] = ap;
            }

            // Set XRef to normal state
            ap.Elements["/N"] = xobj.Reference;



            //// HACK
            //string m =
            //"<?xpacket begin=\"\" id=\"W5M0MpCehiHzreSzNTczkc9d\"?>" + '\n' +
            //"<x:xmpmeta xmlns:x=\"adobe:ns:meta/\" x:xmptk=\"Adobe XMP Core 4.0-c321 44.398116, Tue Aug 04 2009 14:24:39\"> " + '\n' +
            //"   <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"> " + '\n' +
            //"      <rdf:Description rdf:about=\"\" " + '\n' +
            //"            xmlns:pdf=\"http://ns.adobe.com/pdf/1.3/\"> " + '\n' +
            //"         <pdf:Producer>PDFsharp 1.40.2150-g (www.PdfSharp.com) (Original: Powered By Crystal)</pdf:Producer> " + '\n' +
            //"      </rdf:Description> " + '\n' +
            //"      <rdf:Description rdf:about=\"\" " + '\n' +
            //"            xmlns:xap=\"http://ns.adobe.com/xap/1.0/\"> " + '\n' +
            //"         <xap:ModifyDate>2011-07-11T23:15:09+02:00</xap:ModifyDate> " + '\n' +
            //"         <xap:CreateDate>2011-05-19T16:26:51+03:00</xap:CreateDate> " + '\n' +
            //"         <xap:MetadataDate>2011-07-11T23:15:09+02:00</xap:MetadataDate> " + '\n' +
            //"         <xap:CreatorTool>Crystal Reports</xap:CreatorTool> " + '\n' +
            //"      </rdf:Description> " + '\n' +
            //"      <rdf:Description rdf:about=\"\" " + '\n' +
            //"            xmlns:dc=\"http://purl.org/dc/elements/1.1/\"> " + '\n' +
            //"         <dc:format>application/pdf</dc:format> " + '\n' +
            //"      </rdf:Description> " + '\n' +
            //"      <rdf:Description rdf:about=\"\" " + '\n' +
            //"            xmlns:xapMM=\"http://ns.adobe.com/xap/1.0/mm/\"> " + '\n' +
            //"         <xapMM:DocumentID>uuid:68249d89-baed-4384-9a2d-fbf8ace75c45</xapMM:DocumentID> " + '\n' +
            //"         <xapMM:InstanceID>uuid:3d5f2f46-c140-416f-baf2-7f9c970cef1d</xapMM:InstanceID> " + '\n' +
            //"      </rdf:Description> " + '\n' +
            //"   </rdf:RDF> " + '\n' +
            //"</x:xmpmeta> " + '\n' +
            //"                                                                          " + '\n' +
            //"                                                                          " + '\n' +
            //"                                                                          " + '\n' +
            //"                                                                          " + '\n' +
            //"                                                                          " + '\n' +
            //"                                                                          " + '\n' +
            //"                                                                          " + '\n' +
            //"                                                                          " + '\n' +
            //"                                                                          " + '\n' +
            //"                                                                          " + '\n' +
            //"<?xpacket end=\"w\"?>";

            //PdfDictionary mdict = (PdfDictionary)_document.Internals.GetObject(new PdfObjectID(32));

            //length = m.Length;
            //stream = new byte[length];
            //for (int idx = 0; idx < length; idx++)
            //  stream[idx] = (byte)m[idx];

            //mdict.Stream.Value = stream;
#else
            PdfRectangle rect  = Elements.GetRectangle(PdfAnnotation.Keys.Rect);
            XForm        form  = new XForm(_document, rect.Size);
            XGraphics    gfx   = XGraphics.FromForm(form);
            XRect        xrect = (rect.ToXRect() - rect.Location);

            if (BackColor != XColor.Empty)
            {
                gfx.DrawRectangle(new XSolidBrush(BackColor), rect.ToXRect() - rect.Location);
            }
            // Draw Border
            if (!BorderColor.IsEmpty)
            {
                gfx.DrawRectangle(new XPen(BorderColor), rect.ToXRect() - rect.Location);
            }

            string text = Text;

            if (text.Length > 0)
            {
                xrect.Y      = xrect.Y + TopMargin;
                xrect.X      = xrect.X + LeftMargin;
                xrect.Width  = xrect.Width + RightMargin;
                xrect.Height = xrect.Height + BottomMargin;

                if ((Flags & PdfAcroFieldFlags.Comb) != 0 && MaxLength > 0)
                {
                    var combWidth = xrect.Width / MaxLength;
                    var format    = XStringFormats.TopLeft;
                    format.Comb      = true;
                    format.CombWidth = combWidth;
                    gfx.Save();
                    gfx.IntersectClip(xrect);
                    if (this.MultiLine)
                    {
                        XTextFormatter formatter = new XTextFormatter(gfx);
                        formatter.Text = text;

                        formatter.DrawString(Text, Font, new XSolidBrush(ForeColor), xrect, Alignment);
                    }
                    else
                    {
                        gfx.DrawString(text, Font, new XSolidBrush(ForeColor), xrect + new XPoint(0, 1.5), format);
                    }
                    gfx.Restore();
                }
                else
                {
                    XTextFormatter formatter = new XTextFormatter(gfx);
                    formatter.Text = text;

                    formatter.DrawString(text, Font, new XSolidBrush(ForeColor), rect.ToXRect() - rect.Location, Alignment);
                }
            }

            form.DrawingFinished();
            form.PdfForm.Elements.Add("/FormType", new PdfLiteral("1"));

            // Get existing or create new appearance dictionary.
            PdfDictionary ap = Elements[PdfAnnotation.Keys.AP] as PdfDictionary;
            if (ap == null)
            {
                ap = new PdfDictionary(_document);
                Elements[PdfAnnotation.Keys.AP] = ap;
            }

            // Set XRef to normal state
            ap.Elements["/N"] = PdfObject.DeepCopyClosure(Owner, form.PdfForm);

            var normalStateDict = ap.Elements.GetDictionary("/N");
            var resourceDict    = new PdfDictionary(Owner);
            resourceDict.Elements[PdfResources.Keys.ProcSet] = new PdfArray(Owner, new PdfName("/PDF"), new PdfName("/Text"));

            var defaultFormResources = Owner.AcroForm.Elements.GetDictionary(PdfAcroForm.Keys.DR);
            if (defaultFormResources != null && defaultFormResources.Elements.ContainsKey(PdfResources.Keys.Font))
            {
                var           fontResourceItem = XForm.GetFontResourceItem(Font.FamilyName, defaultFormResources);
                PdfDictionary fontDict         = new PdfDictionary(Owner);
                resourceDict.Elements[PdfResources.Keys.Font] = fontDict;
                fontDict.Elements[fontResourceItem.Key]       = fontResourceItem.Value;
            }

            normalStateDict.Elements.SetObject(PdfPage.Keys.Resources, resourceDict);

            PdfFormXObject xobj = form.PdfForm;
            if (xobj.Stream == null)
            {
                xobj.CreateStream(new byte[] { });
            }

            string s = xobj.Stream.ToString();
            // Thank you Adobe: Without putting the content in 'EMC brackets'
            // the text is not rendered by PDF Reader 9 or higher.
            s = "/Tx BMC\n" + s + "\nEMC";
            ap.Elements.GetDictionary("/N").Stream.Value = new RawEncoding().GetBytes(s);
#endif
        }
 public override void PushClip(RRect rect)
 {
     _clipStack.Push(rect);
     _g.Save();
     _g.IntersectClip(Utils.Convert(rect));
 }
 public void SetClip(RectangleF area)
 {
     g.IntersectClip(area);
 }
Example #24
0
 public void SetClip(Rectangle rect)
 {
     Graphics.IntersectClip(rect);
 }
Example #25
0
        public override void Draw(XGraphics graphics, Palette palette, DrawingContext context)
        {
            Random random = new Random(Name.GetHashCode());

            var topLeft     = InnerBounds.GetCorner(CompassPoint.NorthWest);
            var topRight    = InnerBounds.GetCorner(CompassPoint.NorthEast);
            var bottomLeft  = InnerBounds.GetCorner(CompassPoint.SouthWest);
            var bottomRight = InnerBounds.GetCorner(CompassPoint.SouthEast);

            var top    = new LineSegment(topLeft, topRight);
            var right  = new LineSegment(topRight, bottomRight);
            var bottom = new LineSegment(bottomRight, bottomLeft);
            var left   = new LineSegment(bottomLeft, topLeft);

            context.LinesDrawn.Add(top);
            context.LinesDrawn.Add(right);
            context.LinesDrawn.Add(bottom);
            context.LinesDrawn.Add(left);

            var brush = context.Selected ? palette.BorderBrush : palette.FillBrush;

            if (!Settings.DebugDisableLineRendering)
            {
                var path = palette.Path();
                Drawing.AddLine(path, top, random);
                Drawing.AddLine(path, right, random);
                Drawing.AddLine(path, bottom, random);
                Drawing.AddLine(path, left, random);
                graphics.DrawPath(brush, path);

                if (IsDark)
                {
                    var state = graphics.Save();
                    graphics.IntersectClip(path);
                    brush = context.Selected ? palette.FillBrush : palette.BorderBrush;
                    graphics.DrawPolygon(brush, new PointF[] { topRight.ToPointF(), new PointF(topRight.X - Settings.DarknessStripeSize, topRight.Y), new PointF(topRight.X, topRight.Y + Settings.DarknessStripeSize) }, XFillMode.Alternate);
                    graphics.Restore(state);
                }

                graphics.DrawPath(palette.BorderPen, path);
            }

            var font = Settings.LargeFont;

            brush = context.Selected ? palette.FillBrush : palette.LargeTextBrush;
            Rect textBounds = InnerBounds;

            textBounds.Inflate(-5, -5);

            if (textBounds.Width > 0 && textBounds.Height > 0)
            {
                m_name.Draw(graphics, font, brush, textBounds.Position, textBounds.Size, XStringFormats.Center);
            }

            var expandedBounds = InnerBounds;

            expandedBounds.Inflate(Settings.ObjectListOffsetFromRoom, Settings.ObjectListOffsetFromRoom);
            var drawnObjectList = false;

            font  = Settings.SmallFont;
            brush = palette.SmallTextBrush;

            if (!string.IsNullOrEmpty(Objects))
            {
                XStringFormat format = new XStringFormat();
                Vector        pos    = expandedBounds.GetCorner(m_objectsPosition);
                if (!Drawing.SetAlignmentFromCardinalOrOrdinalDirection(format, m_objectsPosition))
                {
                    // object list appears inside the room below its name
                    format.LineAlignment = XLineAlignment.Far;
                    format.Alignment     = XStringAlignment.Near;
                    //format.Trimming = StringTrimming.EllipsisCharacter;
                    //format.FormatFlags = StringFormatFlags.LineLimit;
                    var height = InnerBounds.Height / 2 - font.Height / 2;
                    var bounds = new Rect(InnerBounds.Left + Settings.ObjectListOffsetFromRoom, InnerBounds.Bottom - height, InnerBounds.Width - Settings.ObjectListOffsetFromRoom, height - Settings.ObjectListOffsetFromRoom);
                    brush = context.Selected ? palette.FillBrush : brush;
                    if (bounds.Width > 0 && bounds.Height > 0)
                    {
                        m_objects.Draw(graphics, font, brush, bounds.Position, bounds.Size, format);
                    }
                    drawnObjectList = true;
                }
                else if (m_objectsPosition == CompassPoint.North || m_objectsPosition == CompassPoint.South)
                {
                    pos.X += Settings.ObjectListOffsetFromRoom;
                }

                if (!drawnObjectList)
                {
                    m_objects.Draw(graphics, font, brush, pos, Vector.Zero, format);
                }
            }
        }