Example #1
1
        /// <summary>
        /// Renders the matrix code.
        /// </summary>
        protected internal override void Render(XGraphics gfx, XBrush brush, XPoint position)
        {
            XGraphicsState state = gfx.Save();

            switch (Direction)
            {
                case CodeDirection.RightToLeft:
                    gfx.RotateAtTransform(180, position);
                    break;

                case CodeDirection.TopToBottom:
                    gfx.RotateAtTransform(90, position);
                    break;

                case CodeDirection.BottomToTop:
                    gfx.RotateAtTransform(-90, position);
                    break;
            }

            XPoint pos = position + CalcDistance(Anchor, AnchorType.TopLeft, Size);

            if (MatrixImage == null)
                MatrixImage = DataMatrixImage.GenerateMatrixImage(Text, Encoding, Rows, Columns);

            if (QuietZone > 0)
            {
                XSize sizeWithZone = new XSize(Size.Width, Size.Height);
                sizeWithZone.Width = sizeWithZone.Width / (Columns + 2 * QuietZone) * Columns;
                sizeWithZone.Height = sizeWithZone.Height / (Rows + 2 * QuietZone) * Rows;

                XPoint posWithZone = new XPoint(pos.X, pos.Y);
                posWithZone.X += Size.Width / (Columns + 2 * QuietZone) * QuietZone;
                posWithZone.Y += Size.Height / (Rows + 2 * QuietZone) * QuietZone;

                gfx.DrawRectangle(XBrushes.White, pos.X, pos.Y, Size.Width, Size.Height);
                gfx.DrawImage(MatrixImage, posWithZone.X, posWithZone.Y, sizeWithZone.Width, sizeWithZone.Height);
            }
            else
                gfx.DrawImage(MatrixImage, pos.X, pos.Y, Size.Width, Size.Height);

            gfx.Restore(state);
        }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BarCode"/> class.
 /// </summary>
 /// <param name="text"></param>
 /// <param name="size"></param>
 /// <param name="direction"></param>
 public BarCode(string text, XSize size, CodeDirection direction)
     : base(text, size, direction)
 {
     Text = text;
     Size = size;
     Direction = direction;
 }
Example #3
0
/// <summary>Constructor</summary>
/// <param name="values">byte[] - The values to be rendered</param>
/// <param name="size">XSize - The size of the bar code</param>
/// <param name="direction">CodeDirection - Indicates the direction to draw the bar code</param>
/// <param name="code128Code">Code_128_Code_Types - Indicates which of the codes to use when rendering the bar code.
/// The options are A, B, or buffer.</param>
        public Code128(byte[] values, XSize size, CodeDirection direction, Code_128_Code_Types code128Code)
            : base(null, size, direction)
        {
            if (!Enum.IsDefined(typeof(Code_128_Code_Types), code128Code))
            {
                throw new ArgumentOutOfRangeException("Parameter code128Code (Code_128_Code_Types) is invalid");
            }
            if (Patterns == null)
            {
                Load();
            }
            Code128Code = code128Code;
            Values      = values;
        }
Example #4
0
        void DrawPentaInfoBox(XGraphics gfx, XPoint point, XImage image, Parameter parameter)
        {
            double val   = parameter.Value;
            string str   = parameter.Name;
            XBrush brush = ChooseBrushColor(parameter.Percentage,
                                            parameter.RedVal,
                                            parameter.AmberVal);
            XSize ellipseSize = new XSize(10, 10);

            gfx.DrawRoundedRectangle(brush, new XRect(point.X, point.Y, 50, 50), ellipseSize);
            gfx.DrawString(str, new XFont("Arial", 12), XBrushes.White, point + new XPoint(0, 60));
            gfx.DrawString(val.ToString() + "%", new XFont("Arial", 12), XBrushes.White, point + new XPoint(10, 30));
            gfx.DrawImage(image, new XRect(point + new XPoint(50, 0), new XSize(50, 50)));
        }
Example #5
0
        private void RenderLabel(XGraphics gfx)
        {
            XSize  lSize = new XSize(XUnit.FromMillimeter(pageSettings.LabelSize.Width), XUnit.FromMillimeter(pageSettings.LabelSize.Height));
            XPoint lPt   = new XPoint(0, 0);
            //Just draw each side for all labels, dont care if they overlap...
            XRect rect = new XRect(lPt, lSize);

            gfx.DrawRoundedRectangle(XPens.Black, rect, new XSize(XUnit.FromMillimeter(pageSettings.Corner.Width), XUnit.FromMillimeter(pageSettings.Corner.Height)));

            foreach (LabelItem item in labelItems)
            {
                item.Render(gfx, lPt);
            }
        }
        private XSize DrawWeekdayHeader(XGraphics g, double tempTextHeight)
        {
            XSize  textSize = XSize.Empty;
            string str;

            for (int i = 0; i < 7; i++)
            {
                str      = GCCalendar.GetWeekdayName((i + firstDayOfWeekGeneral) % 7);
                textSize = g.MeasureString(str, fontH2);

                g.DrawString(str, fontH2, Brushes.Black, xMarginLeft + xCellWidth * i + xCellWidth / 2 - textSize.Width / 2, yUnderTitleBar + tempTextHeight + textSize.Height);
            }
            return(textSize);
        }
Example #7
0
        private double GetTextHeight(string text, XFont font, double rectWidth)
        {
            double fontHeight         = font.GetHeight();
            XSize  measure            = _gfx.MeasureString(text, font);
            double absoluteTextHeight = measure.Height;
            double absoluteTextWidth  = measure.Width;

            if (absoluteTextWidth > rectWidth)
            {
                var linesToAdd = (int)Math.Ceiling(absoluteTextWidth / rectWidth) - 1;
                return(absoluteTextHeight + linesToAdd * (fontHeight));
            }
            return(absoluteTextHeight);
        }
Example #8
0
        private void addWatermark_Click(object sender, RoutedEventArgs e)
        {
            // Take existing pdf
            PdfDocument document = PdfReader.Open(filename, PdfDocumentOpenMode.Modify);

            var pagesCount = document.Pages.Count;



            string watermark = "Kowal";

            //Set Font

            XFont font = new XFont("Times New Roman", 100, XFontStyle.Bold);

            int n = 0;

            while (n < pagesCount)
            {
                var page = document.Pages[n];
                // Get an XGraphics object for drawing beneath the existing content
                XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Prepend);

                // Get the size (in point) of the text
                XSize size = gfx.MeasureString(watermark, font);

                // Define a rotation transformation at the center of the page
                gfx.TranslateTransform(page.Width / 2, page.Height / 2);
                gfx.RotateTransform(-Math.Atan(page.Height / page.Width) * 180 / Math.PI);
                gfx.TranslateTransform(-page.Width / 2, -page.Height / 2);

                // Create a string format
                XStringFormat format = new XStringFormat();
                format.Alignment     = XStringAlignment.Near;
                format.LineAlignment = XLineAlignment.Near;

                // Create a dimmed red brush
                XBrush brush = new XSolidBrush(XColor.FromArgb(128, 255, 0, 0));


                // Draw the string
                gfx.DrawString(watermark, font, brush,
                               new XPoint((page.Width - size.Width) / 2, (page.Height - size.Height) / 2), format);
                n++;
            }


            //Save Document
            document.Save(filename);
        }
        /// <summary>
        /// Calculates the space used for the Y axis.
        /// </summary>
        internal override void Format()
        {
            AxisRendererInfo yari = ((ChartRendererInfo)_rendererParms.RendererInfo).yAxisRendererInfo;

            if (yari._axis != null)
            {
                XGraphics gfx = _rendererParms.Graphics;

                XSize size = new XSize(0, 0);

                // height of all ticklabels
                double yMin       = yari.MinimumScale;
                double yMax       = yari.MaximumScale;
                double yMajorTick = yari.MajorTick;
                double lineHeight = Double.MinValue;
                XSize  labelSize  = new XSize(0, 0);
                for (double y = yMin; y <= yMax; y += yMajorTick)
                {
                    string str = y.ToString(yari.TickLabelsFormat);
                    labelSize   = gfx.MeasureString(str, yari.TickLabelsFont);
                    size.Width += labelSize.Width;
                    size.Height = Math.Max(labelSize.Height, size.Height);
                    lineHeight  = Math.Max(lineHeight, labelSize.Width);
                }

                // add space for tickmarks
                size.Height += yari.MajorTickMarkWidth * 1.5;

                // Measure axis title
                XSize titleSize = new XSize(0, 0);
                if (yari._axisTitleRendererInfo != null)
                {
                    RendererParameters parms = new RendererParameters
                    {
                        Graphics     = gfx,
                        RendererInfo = yari
                    };
                    AxisTitleRenderer atr = new AxisTitleRenderer(parms);
                    atr.Format();
                    titleSize.Height = yari._axisTitleRendererInfo.Height;
                    titleSize.Width  = yari._axisTitleRendererInfo.Width;
                }

                yari.Height = size.Height + titleSize.Height;
                yari.Width  = Math.Max(size.Width, titleSize.Width);

                yari.InnerRect = yari.Rect;
                yari.LabelSize = labelSize;
            }
        }
Example #10
0
        /// <summary>
        /// Creates a bar code from the specified code type.
        /// </summary>
        public static BarCode FromType(CodeType type, string text, XSize size, CodeDirection direction)
        {
            switch (type)
            {
            case CodeType.Code2of5Interleaved:
                return(new Code2of5Interleaved(text, size, direction));

            case CodeType.Code3of9Standard:
                return(new Code3of9Standard(text, size, direction));

            default:
                throw new InvalidEnumArgumentException("type", (int)type, typeof(CodeType));
            }
        }
Example #11
0
        public static XRect GetAvailablePageSize(PageSize pageSize, PageOrientation orientation)
        {
            //TODO implement for accurate margin
            var size = GetPageSize(pageSize);

            if (orientation == PageOrientation.Landscape)
            {
                size = new XSize(size.Height, size.Width);
            }

            double margin = (size.Width + size.Height) * 0.04;

            return(new XRect(margin, margin, size.Width - 2 * margin, size.Height - margin));
        }
Example #12
0
        void DrawCodePage(XGraphics gfx, XPoint origin)
        {
            const double dx        = 25;
            const double dy        = 25;
            XFont        labelFont = new XFont("Verdana", 10, XFontStyle.Bold);
            //XFont font = new XFont("Bauhaus", 16);
            XFont font = this.properties.Font1.Font;
            //XFont labelFont = font;
            //font = new XFont("Symbol", 16);
            Encoding encoding = Encoding.GetEncoding(1252);
            double   asdf     = XColors.LightGray.GS;
            //XBrush lighter = new XSolidBrush(XColor.FromGrayScale(XColor.LightGray.GS * 1.1));
            XBrush lighter = new XSolidBrush(XColor.FromGrayScale(0.9));

            XFontStyle style       = font.Style;
            double     lineSpace   = font.GetHeight(gfx);
            int        cellSpace   = font.FontFamily.GetLineSpacing(style);
            int        cellAscent  = font.FontFamily.GetCellAscent(style);
            int        cellDescent = font.FontFamily.GetCellDescent(style);
            int        cellLeading = cellSpace - cellAscent - cellDescent;

            double ascent  = lineSpace * cellAscent / cellSpace;
            double descent = lineSpace * cellDescent / cellSpace;
            double leading = lineSpace * cellLeading / cellSpace;

            double x = origin.X + dx;
            double y = origin.Y;

            //for (int idx = 0; idx < 16; idx++)
            //  gfx.DrawString("x" + idx.ToString("X"), labelFont, XBrushes.DarkGray, x + idx * dx, y);
            for (int row = 0; row < 16; row++)
            {
                x  = origin.X;
                y += dy;
                //gfx.DrawString(row.ToString("X") + "x", labelFont, XBrushes.DarkGray, x, y);
                for (int clm = 0; clm < 16; clm++)
                {
                    x += dx;
                    string glyph = encoding.GetString(new byte[1] {
                        Convert.ToByte(row * 16 + clm)
                    });
                    glyph += "!";
                    XSize size = gfx.MeasureString(glyph, font);
                    gfx.DrawRectangle(XBrushes.LightGray, x, y - size.Height + descent, size.Width, size.Height);
                    gfx.DrawRectangle(lighter, x, y - size.Height + descent, size.Width, leading);
                    gfx.DrawRectangle(lighter, x, y, size.Width, descent);
                    gfx.DrawString(glyph, font, XBrushes.Black, x, y);
                }
            }
        }
Example #13
0
        private double PrintServicesListSummary(XGraphics printer, double totalCost, double summaryStartY, bool includeVat)
        {
            double summaryRowHeight = 0;
            double subTotal         = totalCost * 0.8f;
            double vatValue         = totalCost * 0.2f;

            XPen strokePen = new XPen(XColor.FromArgb(100, 100, 100));

            XFont  font           = new XFont("Times", 12, XFontStyle.Bold);
            string sDecimalFormat = "###,###.00";

            XSize size = XSize.Empty;

            if (includeVat)
            {
                // /* Print Subtotal */
                printer.DrawRectangle(strokePen, new XRect(COL2_START_X, summaryStartY, COL2_WIDTH, summaryRowHeight));

                size = printer.MeasureString("Sub Total : ", font);
                printer.DrawString("Sub Total : ", font, brush, new XPoint(COL2_START_X - size.Width, summaryStartY + summaryRowHeight * 1 / 4), XStringFormats.CenterLeft);
                printer.DrawString("$ " + subTotal.ToString(sDecimalFormat), font, brush, new XPoint(COL2_START_X + 10, summaryStartY + summaryRowHeight * 1 / 4), XStringFormats.CenterLeft);

                summaryStartY += summaryRowHeight;
                // /* End Print Subtotal */

                // /* Print VAT */
                //contents.addRect(firstRectEndX, summaryStartY, secondRectEndX, summaryRowHeight);
                //contents.stroke();

                //summaryPrinter.putTextToTheRight(summaryLabelRightX, summaryStartY + summaryRowHeight * 1 / 4, "Vat : ");
                //summaryPrinter.putTextToTheRight(docEndX - 10, summaryStartY + summaryRowHeight * 1 / 4, "$ " + vatValue.ToString(sDecimalFormat));

                summaryStartY += summaryRowHeight;
                // /* End Print VAT */
            }

            /* Print Total */
            size             = printer.MeasureString("Sub Total : ", font);
            summaryRowHeight = size.Height * 3;

            printer.DrawRectangle(strokePen, new XRect(COL2_START_X, summaryStartY - summaryRowHeight * 1 / 4, COL2_WIDTH, summaryRowHeight));

            printer.DrawString("Total : ", font, brush, new XPoint(COL2_START_X - size.Width, summaryStartY + summaryRowHeight * 1 / 4), XStringFormats.CenterLeft);
            printer.DrawString("$ " + totalCost.ToString(sDecimalFormat), font, brush, new XPoint(COL2_START_X + 10, summaryStartY + summaryRowHeight * 1 / 4), XStringFormats.CenterLeft);

            summaryStartY += summaryRowHeight;
            /* End Print Total */

            return(summaryStartY);
        }
Example #14
0
        /// <summary>
        /// Creates a bar code from the specified code type.
        /// </summary>
        public static BarCode FromType(CodeType type, string text, XSize size, CodeDirection direction)
        {
            switch (type)
            {
                case CodeType.Code2of5Interleaved:
                    return new Code2of5Interleaved(text, size, direction);

                case CodeType.Code3of9Standard:
                    return new Code3of9Standard(text, size, direction);

                default:
                    throw new InvalidEnumArgumentException("type", (int)type, typeof(CodeType));
            }
        }
        private static void PaintPdfCellText(XGraphics graphicsDc, string text, PdfCell cell)
        {
            XRect rc = new XRect(cell.Left + cell.LeftMargin, cell.Top + cell.TopMargin, cell.Width - cell.LeftMargin, cell.Height);

            XStringFormat xfmt = new XStringFormat();

            xfmt.Alignment = XStringAlignment.Near;
            XTextFormatter textFmt = new XTextFormatter(graphicsDc);

            textFmt.LayoutRectangle = rc;
            textFmt.Alignment       = XParagraphAlignment.Left;
            textFmt.Font            = cell.XFont;
            XSize textSz = graphicsDc.MeasureString(text, cell.XFont, xfmt);

            if (textSz.Width > rc.Width ||
                textSz.Height > rc.Height ||
                text.Contains("\r") ||
                text.Contains("\n"))
            {
                try
                {
                    textFmt.DrawString(text ?? string.Empty,
                                       cell.XFont,
                                       XBrushes.Black,
                                       rc,
                                       xfmt);
                }
                catch
                {
                    try
                    {
                        graphicsDc.DrawString(text ?? string.Empty,
                                              cell.XFont,
                                              XBrushes.Black,
                                              rc,
                                              xfmt);
                    }
                    catch { }
                }
            }
            else
            {
                graphicsDc.DrawString(text ?? string.Empty,
                                      cell.XFont,
                                      XBrushes.Black,
                                      rc,
                                      xfmt);
            }
        }
Example #16
0
        private double PrintTermsAndConditions(XGraphics printer, double startY, Invoice invoice)
        {
            string termsAndConditions = "Quotation Valid for 21 Days. Quotation Valid for 21 Days. Quotation Valid for 21 Days. Quotation Valid for 21 Days. Quotation Valid for 21 Days. Quotation Valid for 21 Days. Quotation Valid for 21 Days. ";

            XBrush brush = XBrushes.Black;
            XFont  termsAndConditionsHeaderFont = new XFont("Times", 10, XFontStyle.Bold);
            XFont  termsAndConditionsValueFont  = new XFont("Times", 9, XFontStyle.Regular);

            string sStr = "Terms & Conditions";

            startY += printer.MeasureString(sStr, termsAndConditionsHeaderFont).Height * 2;
            printer.DrawString(sStr, termsAndConditionsHeaderFont, brush, new XPoint(DOCUMENT_LEFT_MARGIN, startY));
            //startY += printer.MeasureString(sStr, termsAndConditionsHeaderFont).Height * 2.2;

            List <string> footerLines = new List <string>();

            List <string> breaks = (termsAndConditions.Split("\n")).ToList();

            foreach (string br in breaks)
            {
                StringBuilder sb = new StringBuilder();
                foreach (string s in br.Split(" "))
                {
                    XSize size = printer.MeasureString(sb.ToString() + s + " ", termsAndConditionsValueFont);
                    if (size.Width > DOCUMENT_PRINTABLE_WIDTH)
                    {
                        footerLines.Add(sb.ToString());
                        sb = new StringBuilder();
                        sb.Append("  ");
                    }
                    sb.Append(s).Append(" ");
                }

                if (sb.Length >= 1)
                {
                    footerLines.Add(sb.ToString());
                }
            }

            // double yPos = startY - rowHeight + rowHeight * 2 / 5;
            foreach (string line in footerLines)
            {
                startY += printer.MeasureString(line, termsAndConditionsValueFont).Height * 1.1;
                printer.DrawString(line, termsAndConditionsValueFont, brush, new XPoint(DOCUMENT_LEFT_MARGIN, startY));
            }

            return(startY);
        }
        private void ImageThenText(TableBuilder tableBuilder, BoardingCell bi)
        {
            tableBuilder
            .SetWidth(XUnit.FromPercent(100))
            .SetBorder(Stroke.None)
            .AddColumnToTable("", 13)
            .AddColumn("");
            var rowBuilder = tableBuilder.AddRow();

            rowBuilder.AddCell()
            .SetPadding(0, 4, 0, 0)
            //.SetVerticalAlignment(VerticalAlignment.Bottom)
            .AddImage(Path.Combine("images", bi.image),
                      XSize.FromWidth(11));
            TextOnly(rowBuilder.AddCell().AddParagraph(), bi);
        }
Example #18
0
        protected XRect DrawTickLabel(XGraphics gfx, string tickLabel, XPoint point, XSize size, AxisRendererInfo xari)
        {
            XRect  labelArea   = new XRect(point, size);
            double rotateAngle = xari._axis.TickLabelAngle;

            // Draw rotated text.
            gfx.RotateAtTransform(rotateAngle, labelArea.Center);
            gfx.DrawString(tickLabel, xari.TickLabelsFont, xari.TickLabelsBrush, point);
            gfx.RotateAtTransform(-rotateAngle, labelArea.Center);

            // Simulate rotation to get the rotated bounding box
            var transformation = RotateByDegrees(rotateAngle, labelArea.Center);

            labelArea.Transform(transformation);
            return(labelArea);
        }
Example #19
0
        private static XSize GetSize(PrintPageEventArgs e)
        {
            //margin.Left.Value.GetXUnitValue(XGraphicsUnit.Millimeter)
            //If SectionMargin < ActualMargin (on any side), use actual margin only.
            //If SectionMargin > ActualMargin

            //No margins, use the maximum printable area of the paper
            //var w = e.PageSettings.PrintableArea.Width;
            //var h = e.PageSettings.PrintableArea.Height;
            //var size = e.PageSettings.Landscape ? new XSize(h, w) : new XSize(w, h);

            //Margins has been defined, use the entire paper
            var size = new XSize(e.PageBounds.Width, e.PageBounds.Height);

            return(size);
        }
Example #20
0
        public void PrintChapter(int chapter, XFont font)
        {
            Tuple <XUnit, XGraphics> lineTop = new Tuple <XUnit, XGraphics>(default(XUnit), null);

            for (int i = 0; i < this._leftMargin.Length; i++)
            {
                string text = string.Format("Chapter {0}", chapter);
                XSize  size = this.Gfx.MeasureString(text, font);
                if (i == 0)
                {
                    lineTop = this.GetLinePosition(size.Height);
                }
                XPoint p = new XPoint(this._leftMargin[i], lineTop.Item1);
                lineTop.Item2.DrawString(text, font, XBrushes.Black, p);
            }
        }
        /// <summary>
        /// Returns the size of the bounding box of the specified text.
        /// </summary>
        public XSize MeasureString(string text, UnitType unitType)
        {
            if (text == null)
            {
                throw new ArgumentNullException("text");
            }

            if (!Enum.IsDefined(typeof(UnitType), unitType))
            {
                throw new InvalidEnumArgumentException();
            }

            XGraphics graphics = Realize();

            XSize size = graphics.MeasureString(text, _gdiFont /*, new XPoint(0, 0), StringFormat.GenericTypographic*/);

            switch (unitType)
            {
            case UnitType.Point:
                break;

            case UnitType.Centimeter:
                size.Width  = (float)(size.Width * 2.54 / 72);
                size.Height = (float)(size.Height * 2.54 / 72);
                break;

            case UnitType.Inch:
                size.Width  = size.Width / 72;
                size.Height = size.Height / 72;
                break;

            case UnitType.Millimeter:
                size.Width  = (float)(size.Width * 25.4 / 72);
                size.Height = (float)(size.Height * 25.4 / 72);
                break;

            case UnitType.Pica:
                size.Width  = size.Width / 12;
                size.Height = size.Height / 12;
                break;

            default:
                Debug.Assert(false, "Missing unit type");
                break;
            }
            return(size);
        }
Example #22
0
        public int PrintMultipleLine(string yourString, XFont font, XBrush brush, int columnWidth, double horizontalPos, double verticalPos, int lineQuantity, bool fixedLine)
        {
            XSize strSize = this.gfx.MeasureString(yourString, font);
            int intWidth = (int)strSize.Width;
            int MyLine = 0;

            if (columnWidth >= intWidth) //allowed pixel sets in one line
            {
                gfx.DrawString(yourString, font, brush, horizontalPos, verticalPos);
            }
            else
            {
                string myString = "";
                for (int line = 1; line <= lineQuantity; line++)
                {
                    if (yourString.Length == 0 || yourString.Length == myString.Length) break;
                    myString = "";
                    for (int i = 0; i < yourString.Length; i++)
                    {
                        strSize = gfx.MeasureString(myString, font);
                        intWidth = (int)strSize.Width;

                        if (columnWidth > intWidth)
                        {
                            myString += yourString.Substring(i, 1);
                            if (yourString.Length == myString.Length)
                            {
                                MyLine++;
                            }
                        }
                        else if (columnWidth <= intWidth)
                        {
                            myString.Remove(myString.Length - 1);
                            yourString = yourString.Substring(myString.Length);
                            MyLine++;
                            break;
                        }


                    }
                    gfx.DrawString(myString, font, brush, horizontalPos, verticalPos + (MyLine - 1) * 13);

                }

            }
            return MyLine;
        }
Example #23
0
        protected void DrawGridlines(XGraphics gfx)
        {
            XPen majorpen = XPens.DarkGray.Clone();

            majorpen.Width = 1;
            XPen minorpen = XPens.LightGray.Clone();

            minorpen.Width    = 0.1f;
            gfx.SmoothingMode = XSmoothingMode.HighSpeed;
            DrawGridlines(gfx, new XPoint(100, 100), majorpen, 100, minorpen, 10);

            string text = this.Description;
            XFont  font = new XFont("Verdana", 14, XFontStyle.Bold);
            XSize  size = gfx.MeasureString(text, font);

            gfx.DrawString(text, font, XBrushes.Black, (600 - size.Width) / 2, 30);
        }
        /// <summary>
        /// Renders the matrix code.
        /// </summary>
        protected internal override void Render(XGraphics gfx, XBrush brush, XPoint position)
        {
            XGraphicsState state = gfx.Save();

            switch (Direction)
            {
            case CodeDirection.RightToLeft:
                gfx.RotateAtTransform(180, position);
                break;

            case CodeDirection.TopToBottom:
                gfx.RotateAtTransform(90, position);
                break;

            case CodeDirection.BottomToTop:
                gfx.RotateAtTransform(-90, position);
                break;
            }

            XPoint pos = position + CalcDistance(Anchor, AnchorType.TopLeft, Size);

            if (MatrixImage == null)
            {
                MatrixImage = DataMatrixImage.GenerateMatrixImage(Text, Encoding, Rows, Columns);
            }

            if (QuietZone > 0)
            {
                XSize sizeWithZone = new XSize(Size.Width, Size.Height);
                sizeWithZone.Width  = sizeWithZone.Width / (Columns + 2 * QuietZone) * Columns;
                sizeWithZone.Height = sizeWithZone.Height / (Rows + 2 * QuietZone) * Rows;

                XPoint posWithZone = new XPoint(pos.X, pos.Y);
                posWithZone.X += Size.Width / (Columns + 2 * QuietZone) * QuietZone;
                posWithZone.Y += Size.Height / (Rows + 2 * QuietZone) * QuietZone;

                gfx.DrawRectangle(XBrushes.White, pos.X, pos.Y, Size.Width, Size.Height);
                gfx.DrawImage(MatrixImage, posWithZone.X, posWithZone.Y, sizeWithZone.Width, sizeWithZone.Height);
            }
            else
            {
                gfx.DrawImage(MatrixImage, pos.X, pos.Y, Size.Width, Size.Height);
            }

            gfx.Restore(state);
        }
Example #25
0
        private void DrawWaterMark(int wx, int wy, string wText, XFont wFont, Color wColor)
        {
            XSize sf = gfx.MeasureString(wText, wFont);

            gfx.TranslateTransform(wx / 2, wy / 2);

            //double Agle = -Math.Atan(wy / wx) * 180 / Math.PI;
            //gfx.RotateTransform((float)Agle);
            //gfx.TranslateTransform(-wx / 2, -wy / 2);

            XStringFormat wformat = new XStringFormat();

            wformat.Alignment     = XStringAlignment.Near;
            wformat.LineAlignment = XLineAlignment.Near;

            // XBrush wbrush = new XSolidBrush(Color.FromArgb(20, Color.Black));
            XBrush wbrush = new XSolidBrush(Color.FromArgb(20, wColor));

            wx = (int)(wx - sf.Width) / 2;
            wy = (int)(wy - sf.Height) / 2;

            XPoint Point_xy = new XPoint(wx, wy);
            //gfx.DrawString(wText, wFont, wbrush, Point_xy, wformat);


            // OUTLINED METHOD
            // System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
            // StringFormat wformat2 = new StringFormat();
            // wformat2.Alignment = StringAlignment.Near;
            // wformat2.LineAlignment = StringAlignment.Near;
            Point Point_xy2 = new Point(wx, wy);
            // path.AddString(wText, new FontFamily("Arial"), (int)FontStyle.Italic, 120, Point_xy2, wformat2);

            // Pen pen = new Pen(Color.FromArgb(64,Color.Black), 3);
            //gfx.Graphics.DrawPath(pen, path);


            XGraphicsPath path = new XGraphicsPath();

            path.AddString(wText, wFont.FontFamily, XFontStyle.Italic, 103, Point_xy2, wformat);
            Pen pen = new Pen(Color.FromArgb(64, wColor), 3);

            //e.Graphics.DrawPath(pen, path);
            gfx.DrawPath(pen, path);
        }
        /// <summary>
        /// Returns the size of the bounding box of the specified text.
        /// </summary>
        public XSize MeasureString(string text, UnitType unitType)
        {
            if (text == null)
            {
                throw new ArgumentNullException("text");
            }

            if (!Enum.IsDefined(typeof(UnitType), unitType))
            {
                throw new ArgumentException();
            }

            XSize size = graphics.MeasureString(text, this.xFont);

            switch (unitType)
            {
            case UnitType.Point:
                break;

            case UnitType.Centimeter:
                size.Width  = (float)(size.Width * 2.54 / 72);
                size.Height = (float)(size.Height * 2.54 / 72);
                break;

            case UnitType.Inch:
                size.Width  = size.Width / 72;
                size.Height = size.Height / 72;
                break;

            case UnitType.Millimeter:
                size.Width  = (float)(size.Width * 25.4 / 72);
                size.Height = (float)(size.Height * 25.4 / 72);
                break;

            case UnitType.Pica:
                size.Width  = size.Width / 12;
                size.Height = size.Height / 12;
                break;

            default:
                Debug.Assert(false, "Missing unit type");
                break;
            }
            return(size);
        }
Example #27
0
        private double PrintPaymentDetails(XGraphics printer, double startY, Invoice invoice)
        {
            XBrush brush = XBrushes.Black;
            XFont  paymentDetailsHeaderFont = new XFont("Times", 11, XFontStyle.Bold);
            XFont  paymentDetailsValueFont  = new XFont("Times", 9, XFontStyle.Regular);

            string sStr = "Terms & Conditions";

            startY += printer.MeasureString(sStr, paymentDetailsHeaderFont).Height * 2;
            printer.DrawString(sStr, paymentDetailsHeaderFont, brush, new XPoint(DOCUMENT_LEFT_MARGIN, startY));
            //startY += printer.MeasureString(sStr, paymentDetailsHeaderFont).Height;

            List <string> footerLines = new List <string>();

            List <string> breaks = (invoice.PaymentDetails.Split("\n")).ToList();

            foreach (string br in breaks)
            {
                StringBuilder sb = new StringBuilder();
                foreach (string s in br.Split(" "))
                {
                    XSize size = printer.MeasureString(sb.ToString() + s + " ", paymentDetailsValueFont);
                    if (size.Width > DOCUMENT_PRINTABLE_WIDTH)
                    {
                        footerLines.Add(sb.ToString());
                        sb = new StringBuilder();
                        sb.Append("  ");
                    }
                    sb.Append(s).Append(" ");
                }

                if (sb.Length >= 1)
                {
                    footerLines.Add(sb.ToString());
                }
            }

            footerLines.ForEach(line =>
            {
                startY += printer.MeasureString(line, paymentDetailsValueFont).Height * 1.1;
                printer.DrawString(line, paymentDetailsValueFont, brush, new XPoint(DOCUMENT_LEFT_MARGIN, startY));
            });

            return(startY);
        }
Example #28
0
        private void SetXYSize()
        {
            Single minX, maxX, minY, maxY;
            Single XSize, YSize;
            int    XNum, YNum;

            minX = Convert.ToSingle(TB_MinX.Text);
            maxX = Convert.ToSingle(TB_MaxX.Text);
            minY = Convert.ToSingle(TB_MinY.Text);
            maxY = Convert.ToSingle(TB_MaxY.Text);
            XNum = Convert.ToInt32(TB_XNum.Text);
            YNum = Convert.ToInt32(TB_YNum.Text);

            XSize         = (maxX - minX) / (XNum - 1);
            YSize         = (maxY - minY) / (YNum - 1);
            TB_XSize.Text = XSize.ToString();
            TB_YSize.Text = YSize.ToString();
        }
Example #29
0
 private void Pd_PrintPage(object sender, PrintPageEventArgs e)
 {
     if (bFirstPagePrinting)
     {
         bFirstPagePrinting = false;
         hc.PerformLayout(e.Graphics);
     }
     if (hc.PageListCount > 0)
     {
         if (iPage <= hc.PageListCount - 1)
         {
             if (iPage == hc.PageListCount - 1)
             {
                 hc.PerformPrint(e.Graphics, iPage);
                 e.HasMorePages = false;
             }
             else
             {
                 hc.PerformPrint(e.Graphics, iPage);
                 e.HasMorePages = true;
                 iPage++;
             }
         }
         else
         {
         }
     }
     else
     {
         XSize e_Graphics_XSize = new XSize(Convert.ToDouble(e.PageSettings.PrintableArea.Width), Convert.ToDouble(e.PageSettings.PrintableArea.Height));
         e.Graphics.IntersectClip(new RectangleF(config.MarginLeft, config.MarginTop, pageSize.Width, pageSize.Height));
         hc.ScrollOffset = new Point(0, Convert.ToInt32(scrollOffset));
         hc.PerformPaint(e.Graphics);
         scrollOffset -= pageSize.Height;
         if (scrollOffset > -hc.ActualSize.Height)
         {
             e.HasMorePages = true;
         }
         else
         {
             e.HasMorePages = false;
         }
     }
 }
        internal static void BuildFooterBar(RepeatingAreaBuilder builder, float barImageHeight)
        {
            var tableBuilder = builder.AddTable();

            tableBuilder
            .SetBorder(Stroke.None)
            .SetWidth(XUnit.FromPercent(100))
            .AddColumnPercentToTable("", 40)
            .AddColumnPercentToTable("", 42)
            .AddColumnPercentToTable("", 10)
            .AddColumnPercentToTable("", 8);
            var rowBuilder = tableBuilder.AddRow();

            rowBuilder.SetVerticalAlignment(VerticalAlignment.Bottom);
            rowBuilder.AddCell()
            .SetPadding(40, 0, 0, 0)
            .SetFont(FNT11)
            .SetHorizontalAlignment(HorizontalAlignment.Right)
            .AddParagraph()
            .SetAlignment(HorizontalAlignment.Left)
            .AddTextToParagraph("Initials ", INITALS_FONT,
                                true)
            .AddTabulation(140, TabulationType.Left,
                           TabulationLeading.BottomLine);
            rowBuilder
            .AddCell()
            .SetHorizontalAlignment(HorizontalAlignment.Right)
            .SetPadding(0, 0, 5, 0)
            .AddParagraph()
            .SetUrlStyle(
                StyleBuilder.New()
                .SetFontColor(Color.Red)
                .SetFont(URL_FONT))
            .AddUrlToParagraph("http://www.bestlandlords.com/billing");
            rowBuilder
            .AddCell()
            .AddImage(Path.Combine("images", "ra-barcode.png"),
                      XSize.FromHeight(barImageHeight));
            rowBuilder.AddCell().AddParagraph()
            .SetAlignment(HorizontalAlignment.Right)
            .AddTextToParagraph(" ", PAGE_NUMBER_FONT, true)
            .AddTextToParagraph("Page ", PAGE_NUMBER_FONT)
            .AddPageNumber().SetFont(PAGE_NUMBER_FONT);
        }
Example #31
0
        /// <summary>
        /// Calculates the space used for the X axis.
        /// </summary>
        internal override void Format()
        {
            AxisRendererInfo xari = ((ChartRendererInfo)_rendererParms.RendererInfo).xAxisRendererInfo;

            if (xari._axis != null)
            {
                AxisTitleRendererInfo atri = xari._axisTitleRendererInfo;

                // Calculate space used for axis title.
                XSize titleSize = new XSize(0, 0);
                if (atri != null && atri.AxisTitleText != null && atri.AxisTitleText.Length > 0)
                {
                    titleSize          = _rendererParms.Graphics.MeasureString(atri.AxisTitleText, atri.AxisTitleFont);
                    atri.AxisTitleSize = titleSize;
                }

                // Calculate space used for tick labels.
                XSize size = new XSize(0, 0);
                if (xari.XValues.Count > 0)
                {
                    XSeries xs = xari.XValues[0];
                    foreach (XValue xv in xs)
                    {
                        if (xv != null)
                        {
                            string tickLabel = xv._value;
                            XSize  valueSize = _rendererParms.Graphics.MeasureString(tickLabel, xari.TickLabelsFont);

                            XRect rect = new XRect(new XPoint(0, 0), valueSize);
                            rect.Transform(RotateByDegrees(xari._axis.TickLabelAngle, rect.Center));
                            valueSize = rect.Size;

                            size.Height = Math.Max(valueSize.Height, size.Height);
                            size.Width += valueSize.Width;
                        }
                    }
                }

                // Remember space for later drawing.
                xari.TickLabelsHeight = size.Height;
                xari.Height           = titleSize.Height + size.Height + xari.MajorTickMarkWidth;
                xari.Width            = Math.Max(titleSize.Width, size.Width);
            }
        }
Example #32
0
        public static void CreateBarcodeAsImage()
        {
            var document = new PdfDocument();
            var page     = document.AddPage();
            var formGfx  = PdfSharpCore.Drawing.XGraphics.FromPdfPage(page);

            XPoint point = new XPoint(20, 20);

            XSize BARCODE_SIZE = new XSize(Convert.ToDouble(120), Convert.ToDouble(60));
            var   barCode39    = BarCode.FromType(CodeType.Code3of9Standard, "1234", BARCODE_SIZE, CodeDirection.TopToBottom);

//            XSize BARCODE_SIZE = new XSize(Convert.ToDouble(120), Convert.ToDouble(60));
            //  barCode39.Size = BARCODE_SIZE;
            formGfx.DrawBarCode(barCode39, point);



            document.Save("barcodetest.pdf");
        }
Example #33
0
        public void PrintVerse(int verse, XUnit indentLeft, XFont font, string text)
        {
            string[] lines = this.GetLines(indentLeft, text, font);

            for (int i = 0; i < lines.Length; i++)
            {
                XSize size    = this.Gfx.MeasureString(lines[i], font);
                XUnit lineTop = this.GetLinePosition(size.Height);

                if (i == 0)
                {
                    XPoint np = new XPoint(this._leftMargin, lineTop);
                    this.Gfx.DrawString(string.Format("{0}.", verse), font, XBrushes.Black, np);
                }

                XPoint p = new XPoint(this._leftMargin + indentLeft, lineTop);
                this.Gfx.DrawString(lines[i], font, XBrushes.Black, p);
            }
        }
Example #34
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MatrixCode"/> class.
        /// </summary>
        public MatrixCode(string text, string encoding, int rows, int columns, XSize size)
            : base(text, size, CodeDirection.LeftToRight)
        {
            _encoding = encoding;
            if (String.IsNullOrEmpty(_encoding))
                _encoding = new String('a', Text.Length);

            if (columns < rows)
            {
                _rows = columns;
                _columns = rows;
            }
            else
            {
                _columns = columns;
                _rows = rows;
            }

            Text = text;
        }
Example #35
0
        /// <summary>
        /// Calculates the distance between an old anchor point and a new anchor point.
        /// </summary>
        /// <param name="oldType"></param>
        /// <param name="newType"></param>
        /// <param name="size"></param>
        public static XVector CalcDistance(AnchorType oldType, AnchorType newType, XSize size)
        {
            if (oldType == newType)
                return new XVector();

            XVector result;
            Delta delta = Deltas[(int)oldType, (int)newType];
            result = new XVector(size.Width / 2 * delta.X, size.Height / 2 * delta.Y);
            return result;
        }
Example #36
0
 /// <summary>
 /// Initializes a new instance of Interleaved2of5.
 /// </summary>
 public Code2of5Interleaved(string code, XSize size, CodeDirection direction)
     : base(code, size, direction)
 {}
Example #37
0
 /// <summary>
 /// Initializes a new instance of Interleaved2of5.
 /// </summary>
 public Code2of5Interleaved(string code, XSize size)
     : base(code, size, CodeDirection.LeftToRight)
 {}
Example #38
0
 /// <summary>
 /// Initializes a new instance of CodeDataMatrix.
 /// </summary>
 public CodeDataMatrix(string code, int rows, int columns, XSize size)
     : this(code, "", rows, columns, 0, size)
 {}
Example #39
0
 /// <summary>
 /// Initializes a new instance of CodeDataMatrix.
 /// </summary>
 public CodeDataMatrix(string code, DataMatrixEncoding dmEncoding, int rows, int columns, XSize size)
     : this(code, CreateEncoding(dmEncoding, code.Length), rows, columns, 0, size)
 {}
Example #40
0
 /// <summary>
 /// Initializes a new instance of CodeDataMatrix.
 /// </summary>
 public CodeDataMatrix(string code, int length, XSize size)
     : this(code, "", length, length, 0, size)
 {}
Example #41
0
 /// <summary>
 /// Initializes a new instance of CodeDataMatrix.
 /// </summary>
 public CodeDataMatrix(string code, DataMatrixEncoding dmEncoding, int length, XSize size)
     : this(code, CreateEncoding(dmEncoding, code.Length), length, length, 0, size)
 {}
Example #42
0
 /// <summary>
 /// initializes a new OmrCode with the given data.
 /// </summary>
 public CodeOmr(string text, XSize size, CodeDirection direction)
     : base(text, size, direction)
 { }
Example #43
0
 /// <summary>
 /// Initializes a new instance of CodeDataMatrix.
 /// </summary>
 public CodeDataMatrix(string code, string encoding, int rows, int columns, int quietZone, XSize size)
     : base(code, encoding, rows, columns, size)
 {
     QuietZone = quietZone;
 }
Example #44
0
 /// <summary>
 /// Creates a bar code from the specified code type.
 /// </summary>
 public static BarCode FromType(CodeType type, string text, XSize size)
 {
     return FromType(type, text, size, CodeDirection.LeftToRight);
 }
 /// <summary>
 /// Initializes a new instance of Standard3of9.
 /// </summary>
 public Code3of9Standard(string code, XSize size)
   : base(code, size, CodeDirection.LeftToRight)
 {
 }
 /// <summary>
 /// Initializes a new instance of Standard3of9.
 /// </summary>
 public Code3of9Standard(string code, XSize size, CodeDirection direction)
   : base(code, size, direction)
 {
 }
Example #47
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CodeBase"/> class.
 /// </summary>
 public CodeBase(string text, XSize size, CodeDirection direction)
 {
     _text = text;
     _size = size;
     _direction = direction;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ThickThinBarCode"/> class.
 /// </summary>
 public ThickThinBarCode(string code, XSize size, CodeDirection direction)
     : base(code, size, direction)
 { }