示例#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);
        }
示例#2
0
        /// <summary>
        /// Renders the bar code.
        /// </summary>
        protected internal override void Render(XGraphics gfx, XBrush brush, XFont font, XPoint position)
        {
            XGraphicsState state = gfx.Save();

            BarCodeRenderInfo info = new BarCodeRenderInfo(gfx, brush, font, position);

            InitRendering(info);
            info.CurrPosInString = 0;
            //info.CurrPos = info.Center - Size / 2;
            info.CurrPos = position - CodeBase.CalcDistance(AnchorType.TopLeft, Anchor, Size);

            if (TurboBit)
            {
                RenderTurboBit(info, true);
            }
            RenderStart(info);
            while (info.CurrPosInString < Text.Length)
            {
                RenderNextPair(info);
            }
            RenderStop(info);
            if (TurboBit)
            {
                RenderTurboBit(info, false);
            }
            if (TextLocation != TextLocation.None)
            {
                RenderText(info);
            }

            gfx.Restore(state);
        }
示例#3
0
 public PDFLabel(string text, XPoint point, XFont font, XBrush brush)
 {
     this.Text  = text;
     this.Point = point;
     this.Font  = font;
     this.Brush = brush;
 }
示例#4
0
        /// <summary>
        /// Draws the data labels of the pie chart.
        /// </summary>
        internal override void Draw()
        {
            ChartRendererInfo cri = (ChartRendererInfo)this.rendererParms.RendererInfo;

            if (cri.seriesRendererInfos.Length == 0)
            {
                return;
            }

            SeriesRendererInfo sri = cri.seriesRendererInfos[0];

            if (sri.dataLabelRendererInfo == null)
            {
                return;
            }

            if (sri != null)
            {
                XGraphics     gfx       = this.rendererParms.Graphics;
                XFont         font      = sri.dataLabelRendererInfo.Font;
                XBrush        fontColor = sri.dataLabelRendererInfo.FontColor;
                XStringFormat format    = XStringFormats.Center;
                format.LineAlignment = XLineAlignment.Center;
                foreach (DataLabelEntryRendererInfo dataLabel in sri.dataLabelRendererInfo.Entries)
                {
                    if (dataLabel.Text != null)
                    {
                        gfx.DrawString(dataLabel.Text, font, fontColor, dataLabel.Rect, format);
                    }
                }
            }
        }
示例#5
0
 public DrawStringListItem(string text, XFont font, XBrush brush, XRect rect)
 {
     this.Text  = text;
     this.Font  = font;
     this.Brush = brush;
     this.Rect  = rect;
 }
示例#6
0
        private void DrawBox(int x, int y, int Height, int Width, int BorderThickness, string BorderColor, string FillColor)
        {
            XPen   mPen   = null;
            XBrush xBrush = null;

            if (BorderColor != "")
            {
                mPen = new XPen(XColor(BorderColor));
            }
            if (FillColor != "")
            {
                xBrush = XBrush(FillColor);
            }
            if (BorderColor != "" && FillColor != "")
            {
                gfx.DrawRectangle(mPen, xBrush, x, y, Width, Height);
            }
            else if (BorderColor != "")
            {
                gfx.DrawRectangle(mPen, x, y, Width, Height);
            }
            if (FillColor != "")
            {
                gfx.DrawRectangle(xBrush, x, y, Width, Height);
            }
        }
示例#7
0
        public void DrawString(string s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format)
        {
            XStringFormat xFormat = StringFormatToXStringFormat(format);
            XFont         xFont   = FontToXFont(font);
            XBrush        xBrush  = BrushToXBrush(brush);

            if (format.FormatFlags == StringFormatFlags.NoWrap)
            {
                //Single line
                string line = TrimString(s, layoutRectangle.Width, xFont, format.Trimming);
                _graphics.DrawString(line, xFont, xBrush, layoutRectangle, xFormat);
            }
            else
            {
                //Multiline
                int           lineHeight = xFont.Height;
                List <string> lines      = SetText(s, layoutRectangle.Width, (int)(layoutRectangle.Height / lineHeight), xFont);

                for (int i = 0; i < lines.Count; i++)
                {
                    RectangleF rect = new RectangleF(layoutRectangle.X, layoutRectangle.Y + i * lineHeight,
                                                     layoutRectangle.Width, lineHeight);
                    _graphics.DrawString(lines[i], xFont, xBrush, rect, xFormat);
                }
            }
        }
示例#8
0
        /// <summary>
        /// Renders a single line of the character. Each character has three lines and three spaces
        /// </summary>
        /// <param name="info">
        /// </param>
        /// <param name="barWidth">
        /// Indicates the thickness of the line/bar to be rendered.
        /// </param>
        /// <param name="brush">
        /// Indicates the brush to use to render the line/bar.
        /// </param>
        private void RenderBar(BarCodeRenderInfo info, double barWidth, XBrush brush)
        {
            double height = this.Size.Height;
            double yPos   = info.CurrPos.Y;

            switch (this.TextLocation)
            {
            case TextLocation.Above:
                yPos    = info.CurrPos.Y + (height / 5);
                height *= 4.0 / 5;
                break;

            case TextLocation.Below:
                height *= 4.0 / 5;
                break;

            case TextLocation.AboveEmbedded:
            case TextLocation.BelowEmbedded:
            case TextLocation.None:
                break;
            }
            XRect rect = new XRect(info.CurrPos.X, yPos, barWidth, height);

            info.Gfx.DrawRectangle(brush, rect);
            info.CurrPos.X += barWidth;
        }
示例#9
0
        private static void createTableHeader(XGraphics gfx)
        {
            XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);
            XBrush          brush   = XBrushes.Black;
            XStringFormat   format  = new XStringFormat();

            format.LineAlignment = XLineAlignment.Center;

            XPen   xpen   = new XPen(XColors.Black, 1.5);
            XBrush xbrush = XBrushes.Bisque;

            XRect rect;
            XFont font;

            int currX = X_START;

            string headerLastName = RES_MANAGER.GetString("lastname");

            rect             = new XRect(currX, CURR_Y, COL_WIDTH[0], 16);
            font             = new XFont("Arial", 12, XFontStyle.Bold, options);
            format.Alignment = XStringAlignment.Near;
            //gfx.DrawRectangle(xpen, xbrush, rect);
            gfx.DrawString(headerLastName, font, brush, rect, format);

            currX += COL_WIDTH[0] + COL_GAP;

            string headerName = RES_MANAGER.GetString("name");

            rect = new XRect(currX, CURR_Y, COL_WIDTH[1], 16);
            //gfx.DrawRectangle(xpen, xbrush, rect);
            gfx.DrawString(headerName, font, brush, rect, format);

            currX += COL_WIDTH[1] + COL_GAP;

            string headerTitle = RES_MANAGER.GetString("title");

            rect = new XRect(currX, CURR_Y, COL_WIDTH[2], 16);
            //gfx.DrawRectangle(xpen, xbrush, rect);
            gfx.DrawString(headerTitle, font, brush, rect, format);

            currX += COL_WIDTH[2] + COL_GAP;

            string headerEduRank = RES_MANAGER.GetString("edurank");

            rect = new XRect(currX, CURR_Y, COL_WIDTH[3], 16);
            //gfx.DrawRectangle(xpen, xbrush, rect);
            gfx.DrawString(headerEduRank, font, brush, rect, format);

            currX += COL_WIDTH[3] + COL_GAP;

            string headerExtID = RES_MANAGER.GetString("extid");

            rect = new XRect(currX, CURR_Y, COL_WIDTH[4], 16);
            //gfx.DrawRectangle(xpen, xbrush, rect);
            gfx.DrawString(headerExtID, font, brush, rect, format);

            gfx.DrawLine(xpen, X_START - 20, CURR_Y + 18, X_START + 475, CURR_Y + 18);

            CURR_Y += 20;
        }
示例#10
0
    //public double GetVerticalPos(double value)
    //{
    //    if(value > _lineGap)
    //    {

    //    }
    //    if ((_verticalPos + value + _lineGap) > (gfx.PageSize.Height - _bottomMargin))
    //    {
    //        double temp = _verticalPos;
    //        NewPage();
    //        return temp;
    //    }
    //    return _verticalPos += value;
    //}

    /// <summary>
    /// This function print data with right align...
    /// </summary>
    /// <param name="yourString"></param>
    /// <param name="font"></param>
    /// <param name="brash"></param>
    /// <param name="HigheshHorizontalPos"> Last position to align</param>
    /// <param name="verticalPos"></param>
    public void DrawNumericRightAlign(string yourString, XFont font, XBrush brush, double HigheshHorizontalPos, double verticalPos)
    {
        XSize textSize  = gfx.MeasureString(yourString, font);
        long  pixLength = Convert.ToInt64(textSize.Width);

        gfx.DrawString(yourString, font, brush, HigheshHorizontalPos - pixLength, verticalPos);
    }
示例#11
0
        private void DrawTextAlignment(XGraphics gfx, int number)
        {
            base.BeginBox(gfx, number, "Text Alignment");
            XRect         xRect         = new XRect(0.0, 0.0, 250.0, 140.0);
            XFont         font          = new XFont("Verdana", 10.0);
            XBrush        purple        = XBrushes.Purple;
            XStringFormat xStringFormat = new XStringFormat();

            gfx.DrawRectangle(XPens.YellowGreen, xRect);
            gfx.DrawLine(XPens.YellowGreen, xRect.Width / 2.0, 0.0, xRect.Width / 2.0, xRect.Height);
            gfx.DrawLine(XPens.YellowGreen, 0.0, xRect.Height / 2.0, xRect.Width, xRect.Height / 2.0);
            gfx.DrawString("TopLeft", font, purple, xRect, xStringFormat);
            xStringFormat.Alignment = XStringAlignment.Center;
            gfx.DrawString("TopCenter", font, purple, xRect, xStringFormat);
            xStringFormat.Alignment = XStringAlignment.Far;
            gfx.DrawString("TopRight", font, purple, xRect, xStringFormat);
            xStringFormat.LineAlignment = XLineAlignment.Center;
            xStringFormat.Alignment     = XStringAlignment.Near;
            gfx.DrawString("CenterLeft", font, purple, xRect, xStringFormat);
            xStringFormat.Alignment = XStringAlignment.Center;
            gfx.DrawString("Center", font, purple, xRect, xStringFormat);
            xStringFormat.Alignment = XStringAlignment.Far;
            gfx.DrawString("CenterRight", font, purple, xRect, xStringFormat);
            xStringFormat.LineAlignment = XLineAlignment.Far;
            xStringFormat.Alignment     = XStringAlignment.Near;
            gfx.DrawString("BottomLeft", font, purple, xRect, xStringFormat);
            xStringFormat.Alignment = XStringAlignment.Center;
            gfx.DrawString("BottomCenter", font, purple, xRect, xStringFormat);
            xStringFormat.Alignment = XStringAlignment.Far;
            gfx.DrawString("BottomRight", font, purple, xRect, xStringFormat);
            base.EndBox(gfx);
        }
示例#12
0
        /// <summary>
        /// Defines page setup, headers, and footers.
        /// </summary>
        public static void SetPageNumber(PdfDocument document)
        {
            // Make a font and a brush to draw the page counter.
            XFont  font  = new XFont("Verdana", 8, XFontStyle.Regular);
            XBrush brush = XBrushes.Black;

            // Add the page counter.
            string pageTotalCount = document.Pages.Count.ToString();

            XStringFormat pageNumberFormat = new XStringFormat
            {
                Alignment     = XStringAlignment.Far,
                LineAlignment = XLineAlignment.Near
            };

            for (int i = 0; i < document.Pages.Count; ++i)
            {
                PdfPage page = document.Pages[i];

                // Make a layout rectangle.
                XRect layoutRectangle = new XRect(0 /*X*/, page.Height - font.Height /*Y*/, page.Width - 15 /*Width*/, font.Height /*Height*/);

                using (XGraphics gfx = XGraphics.FromPdfPage(page))
                {
                    gfx.DrawString(
                        "Page " + (i + 1).ToString() + " of " + pageTotalCount,
                        font,
                        brush,
                        layoutRectangle,
                        pageNumberFormat);
                }
            }
        }
示例#13
0
    public void PrintALine(string yourString, XFont font, XBrush brush, double columnWidth, double horizontalPos, double verticalPos)
    {
        XSize strSize  = this.gfx.MeasureString(yourString, font);
        int   intWidth = (int)strSize.Width;

        if (columnWidth >= intWidth)     //allowed pixel sets in one line
        {
            gfx.DrawString(yourString, font, brush, horizontalPos, verticalPos);
        }
        else
        {
            string 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);
                }
                else if (columnWidth < intWidth)
                {
                    myString.Remove(myString.Length - 1);
                }
            }
            gfx.DrawString(myString, font, brush, horizontalPos, verticalPos);
        }
    }
示例#14
0
 public BarCodeRenderInfo(XGraphics gfx, XBrush brush, XFont font, XPoint position)
 {
     Gfx      = gfx;
     Brush    = brush;
     Font     = font;
     Position = position;
 }
示例#15
0
        public void DrawRectangle(Pen pen, Brush brush, double X, double Y, double W, double H)
        {
            XPen   penUsed   = pen != null ? new XPen(XColor.FromName(pen.Color.Name), pen.Width) : null;
            XBrush brushUsed = (XBrush)brush;

            gfx.DrawRectangle(penUsed, brushUsed, X, Y, W, H);
        }
示例#16
0
        /// <summary>
        /// Draws the data labels of the column chart.
        /// </summary>
        internal override void Draw()
        {
            ChartRendererInfo cri = (ChartRendererInfo)_rendererParms.RendererInfo;

            foreach (SeriesRendererInfo sri in cri.seriesRendererInfos)
            {
                if (sri._dataLabelRendererInfo == null)
                {
                    continue;
                }

                XGraphics     gfx       = _rendererParms.Graphics;
                XFont         font      = sri._dataLabelRendererInfo.Font;
                XBrush        fontColor = sri._dataLabelRendererInfo.FontColor;
                XStringFormat format    = XStringFormats.Center;
                format.LineAlignment = XLineAlignment.Center;
                foreach (DataLabelEntryRendererInfo dataLabel in sri._dataLabelRendererInfo.Entries)
                {
                    if (dataLabel.Text != null)
                    {
                        gfx.DrawString(dataLabel.Text, font, fontColor, dataLabel.Rect, format);
                    }
                }
            }
        }
示例#17
0
 public BarCodeRenderInfo(XGraphics gfx, XBrush brush, XFont font, XPoint position)
 {
     Gfx = gfx;
     Brush = brush;
     Font = font;
     Position = position;
 }
示例#18
0
        private static XBrush GetBrushByPercentage(double p)
        {
            XBrush brush = XBrushes.Red;

            if (p >= 25 && p < 50)
            {
                brush = XBrushes.OrangeRed;
            }
            else
            {
                if (p >= 50 && p < 74)
                {
                    brush = XBrushes.Yellow;
                }
                else
                {
                    if (p >= 75 & p < 95)
                    {
                        brush = XBrushes.YellowGreen;
                    }
                    else
                    {
                        if (p >= 95)
                        {
                            brush = XBrushes.Green;
                        }
                    }
                }
            }

            return(brush);
        }
示例#19
0
        private static void AddAbout(XGraphics gfx, AssesmentReportTO report)
        {
            XPen separatorsPen = new XPen(XColor.FromArgb(0, 238, 238, 238), 1);

            // About font
            XFont  aboutFont      = new XFont(fontName, 7, XFontStyle.Regular);
            XBrush aboutBrushText = XBrushes.Silver;

            //Logo and Separators
            int imageX      = 200;
            int imageWidth  = 41;
            int imageHeight = 58;

            int separatorX = imageX + imageWidth + 15;
            int aboutTextX = separatorX + 20;
            int imageY     = 770;

            XImage laboruImage = XImage.FromFile(HttpContext.Current.Server.MapPath("~/Static/dist/images/logo-laboru.png"));

            gfx.DrawImage(laboruImage, imageX, imageY, imageWidth, imageHeight);
            gfx.DrawLine(separatorsPen, separatorX, imageY, separatorX, imageY + imageHeight);

            //Text
            gfx.DrawString("Elaborado por Laboru para " + report.AssesmentInfo.Company.Name, aboutFont, aboutBrushText,
                           new XRect(aboutTextX, imageY + 10, 200, 20),
                           XStringFormats.TopLeft);
            gfx.DrawString("Todos los derechos reservados", aboutFont, aboutBrushText,
                           new XRect(aboutTextX, imageY + 25, 200, 20),
                           XStringFormats.TopLeft);
            gfx.DrawString("http://laboru.co/tech", aboutFont, aboutBrushText,
                           new XRect(aboutTextX, imageY + 40, 200, 20),
                           XStringFormats.TopLeft);
        }
示例#20
0
        public override void GerarRelatorio()
        {
            using (PdfDocument doc = new PdfDocument())
            {
                PdfPage page = doc.AddPage();

                XFont titleFont        = new XFont("Arial", 18);
                XFont boldSubtitleFont = new XFont("Arial", 14, XFontStyle.Bold);
                XFont boldDefaultFont  = new XFont("Arial", 12, XFontStyle.Bold);
                XFont defaultFont      = new XFont("Arial", 12);

                XBrush         defaultBrush  = XBrushes.Black;
                XGraphics      graphics      = XGraphics.FromPdfPage(page);
                XTextFormatter textFormatter = new XTextFormatter(graphics);

                MontarHeader(page, titleFont, defaultBrush, graphics, textFormatter);
                MontarInformacoesReservas(boldSubtitleFont, boldDefaultFont, defaultFont, textFormatter, defaultBrush);
                MontarInformacoesSalas(boldSubtitleFont, boldDefaultFont, defaultFont, textFormatter, defaultBrush);
                MontarInformacoesUltimaReserva(boldSubtitleFont, boldDefaultFont, defaultFont, textFormatter, defaultBrush);
                MontarInformacoesUltimaSala(boldSubtitleFont, boldDefaultFont, defaultFont, textFormatter, defaultBrush);

                NomeArquivo = GerarNomeArquivo();

                doc.Save(RetornarCaminhoArquivo());

                VisualizarArquivo(RetornarCaminhoArquivo());
            }
        }
示例#21
0
        public void FillRectangle(double x, double y, double w, double h, ColorPreset FillColor, ColorPreset BorderColor)
        {
            // y2 = y2 -
            InitPageOffset(ref y);

            using (XGraphics gfx = XGraphics.FromPdfPage(currentPage))
            {
                XPen   pen   = new XPen(XColors.White);
                XBrush brush = XBrushes.White;
                gfx.DrawRectangle(pen, brush, x, y, w, h);
            }

            /*  Rectangle rect = new Rectangle();
             * rect.Width = x2 - x2;
             * rect.Height = y2 - y1;
             *
             #if !SILVERLIGHT
             * rect.Fill = Brushes.WhiteSmoke;
             #else
             * rect.Fill = WhiteBrush;
             #endif
             *
             * Canvas.SetTop(rect, y1);
             * Canvas.SetLeft(rect, x1);
             *
             * canvas.Children.Add(rect);
             */
        }
示例#22
0
        private void DrawPolygon(string fillColor, XPoint [] points)
        {
            //XPen pen = new XPen(XColors.DarkBlue, 2.5);

            XBrush xBrush = XBrush(fillColor);

            gfx.DrawPolygon(xBrush, points, XFillMode.Winding);
        }
        public void RealizeBrush(XBrush brush, PdfColorMode colorMode, int renderingMode, double fontEmSize, bool isForPen = false)
        {
            // Rendering mode 2 is used for bold simulation.
            // Reference: TABLE 5.3  Text rendering modes / Page 402

            XSolidBrush solidBrush = brush as XSolidBrush;

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

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

                if (brush is XBaseGradientBrush gradientBrush)
                {
                    Debug.Assert(UnrealizedCtm.IsIdentity, "Must realize ctm first.");
                    XMatrix matrix = _renderer.DefaultViewMatrix;
                    matrix.Prepend(EffectiveCtm);
                    PdfShadingPattern pattern = new PdfShadingPattern(_renderer.Owner);
                    pattern.SetupFromBrush(gradientBrush, matrix, _renderer);
                    string name = _renderer.Resources.AddPattern(pattern);
                    if (isForPen)
                    {
                        _renderer.AppendFormatString("/Pattern CS\n", name);
                        _renderer.AppendFormatString("{0} SCN\n", name);
                    }
                    else
                    {
                        _renderer.AppendFormatString("/Pattern cs\n", name);
                        _renderer.AppendFormatString("{0} scn\n", name);
                    }
                    // Invalidate fill color.
                    _realizedFillColor = XColor.Empty;
                }
            }
        }
示例#24
0
        private void createCoverPage(PdfPage p, int[] areas)
        {
            //graphics
            XGraphics xgr = XGraphics.FromPdfPage(p);
            //fonts, brushes, alignments
            const string    facename = "Microsoft Sans Serif";
            XPdfFontOptions options  = new XPdfFontOptions(PdfFontEncoding.WinAnsi, PdfFontEmbedding.Default);

            XFont[] fonts = new XFont[] { new XFont(facename, 50, XFontStyle.Regular, options),
                                          new XFont(facename, 20, XFontStyle.Regular, options),
                                          new XFont(facename, 34, XFontStyle.Bold, options),
                                          new XFont(facename, 20, XFontStyle.Bold, options),
                                          new XFont(facename, 20, XFontStyle.Regular, options),
                                          new XFont(facename, 16, XFontStyle.Regular, options),
                                          new XFont(facename, 11, XFontStyle.Regular, options) };
            XBrush        brush  = XBrushes.Black;
            XStringFormat format = new XStringFormat();

            format.Alignment = XStringAlignment.Center;
            double y = p.Height * 0.05;
            //setup text
            List <string> linesOfText = new List <string>();
            List <int>    fontID      = new List <int>();

            linesOfText.AddRange(new string[] { "92WG", "COMPILED", "US DOD", "TERMINALS", "EFF: " + effectiveDates[0] + " - " + effectiveDates[1], "VERSION: " + docVersion, "", "THIS DOCUMENT CONTAINS:", "" });
            fontID.AddRange(new int[] { 0, 1, 2, 2, 3, 3, 3, 4, 4 });
            for (int q = 0; q < areas.Length; q++)
            {
                linesOfText.Add(areaDiscLocations[areas[q]][3] + " TERMINALS");
                fontID.Add(5);
            }
            string suppNote = "SUPPLEMENT INCLUDED FOR FIELDS IN TERMINAL";

            linesOfText.AddRange(new string[] { "", "TCNs EFFECTIVE THIS PERIOD ALSO INCLUDED", suppNote });
            fontID.AddRange(new int[] { 6, 6, 6 });
            //draw text
            double lineSpace = 0.0;
            XRect  rect      = new XRect(0, 0, 0, 0);

            for (int lineNo = 0; lineNo < linesOfText.Count; lineNo++)
            {
                lineSpace = fonts[fontID[lineNo]].GetHeight(xgr);
                rect      = new XRect(0, y, p.Width, lineSpace);
                xgr.DrawString(linesOfText[lineNo], fonts[fontID[lineNo]], brush, rect, format);
                y += lineSpace;
            }
            //Bottom right text
            format.Alignment = XStringAlignment.Near;
            y = p.Height - p.Height * 0.1;
            double x = p.Width * 0.1;

            lineSpace = fonts[6].GetHeight(xgr);
            rect      = new XRect(x, y, p.Width - x, lineSpace);
            xgr.DrawString("COMPILED BY: " + authorName, fonts[6], brush, rect, format);
            y   += lineSpace;
            rect = new XRect(x, y, p.Width - x, lineSpace);
            xgr.DrawString("ON: " + DateTime.Now.ToString("ddMMMyy").ToUpper(), fonts[6], brush, rect, format);
        }
示例#25
0
        public void Fill(XGraphics graphics, XBrush brush)
        {
            XGraphicsPath path = new XGraphicsPath
            {
                FillMode = XFillMode.Winding
            };
            bool hasFigure = false;
            int  ptIndex   = 0;

            foreach (Command command in Commands)
            {
                switch (command)
                {
                case Command.MoveTo:
                    if (hasFigure)
                    {
                        path.CloseFigure();
                        hasFigure = false;
                    }
                    ptIndex++;
                    break;

                case Command.LineTo:
                    path.AddLine(Points[ptIndex - 1], Points[ptIndex]);
                    ptIndex  += 1;
                    hasFigure = true;
                    break;

                case Command.CubicCurveTo:
                    path.AddBezier(Points[ptIndex - 1], Points[ptIndex], Points[ptIndex + 1], Points[ptIndex + 2]);
                    ptIndex  += 3;
                    hasFigure = true;
                    break;

                case Command.CloseSubpath:
                    if (hasFigure)
                    {
                        path.CloseFigure();
                        hasFigure = false;
                    }
                    break;

                case Command.Rectangle:
                    path.AddRectangle(Points[ptIndex + 1].X, Points[ptIndex + 1].Y, Points[ptIndex].X, Points[ptIndex].Y);
                    ptIndex += 2;
                    path.CloseFigure();
                    hasFigure = false;
                    break;
                }
            }

            if (hasFigure)
            {
                path.CloseFigure();
            }

            graphics.DrawPath(brush, path);
        }
示例#26
0
        private static void drawHeaderTable(PdfPage newPage, XGraphics gfx, XPen pen, int startX, int startY, int columnWidth, int rowHeight)
        {
            int columnCount = AppForm.CURR_OCTT_DOC.getNumberOfDays();

            gfx.DrawRectangle(pen, startX, startY, columnWidth * columnCount, rowHeight);

            for (int k = 0; k < columnCount - 1; k++)
            {
                gfx.DrawLine(pen, startX + (k + 1) * columnWidth, startY, startX + (k + 1) * columnWidth, startY + rowHeight);
            }

            string dayName = "";
            int    modPos  = 0;

            for (int kk = 0; kk < columnCount; kk++)
            {
                while (true)
                {
                    if (AppForm.CURR_OCTT_DOC.getIsDayIncluded(modPos))
                    {
                        break;
                    }
                    modPos++;
                }


                dayName = AppForm.getDayText()[modPos];
                modPos++;

                XRect           rect    = new XRect(startX + kk * columnWidth + 4, startY + 4, columnWidth - 8, rowHeight - 8);
                XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);

                //XFont font = new XFont("Arial", 10, XFontStyle.Bold, options);
                XFont         font   = getMyFont(Settings.TTREP_FONT_DAY_NAMES, options);
                XBrush        brush  = XBrushes.Black;
                XStringFormat format = new XStringFormat();



                //gfx.DrawRectangle(XPens.Black, XBrushes.Bisque, rect);

                //gfx.DrawRectangle(XPens.Black, XBrushes.LightBlue, rect);
                char[] separator = new char[1];
                separator[0] = ',';
                string[] ss = Settings.TTREP_COLOR_HEADER.Split(separator, 3);
                int      R  = System.Convert.ToInt32(ss[0]);
                int      G  = System.Convert.ToInt32(ss[1]);
                int      B  = System.Convert.ToInt32(ss[2]);

                gfx.DrawRectangle(XPens.Black, new XSolidBrush(XColor.FromArgb(R, G, B)), rect);


                format.LineAlignment = XLineAlignment.Center;
                format.Alignment     = XStringAlignment.Center;
                gfx.DrawString(dayName, font, brush, rect, format);
            }
        }
示例#27
0
        private void MergeMultiplePDFIntoSinglePDF(string outputFilePath, string[] pdfFiles, string rootMenu)
        {
            pdfFiles = pdfFiles.OrderBy(x => int.Parse(x.Split('\\').Last().Split(' ').Last().Split('.').First())).ToArray();
            PdfDocument document = new PdfDocument();

            document.Info.Title = rootMenu;
            PdfOutline outline = null;

            for (int i = 0, n = pdfFiles.Length; i < n; i++)
            {
                try
                {
                    PdfDocument inputPDFDocument = PdfReader.Open(pdfFiles[i], PdfDocumentOpenMode.Import);
                    document.Version = inputPDFDocument.Version;
                    for (int j = 0, m = inputPDFDocument.Pages.Count; j < m; j++)
                    {
                        document.AddPage(inputPDFDocument.Pages[j]);
                        if (j == 0)
                        {
                            if (i == 0)
                            {
                                outline = document.Outlines.Add(rootMenu, document.Pages[j], true, PdfOutlineStyle.Bold, XColors.Red);
                            }
                            outline.Outlines.Add(inputPDFDocument.Info.Title, document.Pages[document.Pages.Count - 1], true);
                        }
                    }

                    // When document is add in pdf document remove file from folder
                    File.Delete(pdfFiles[i]);
                }
                catch (Exception)
                {
                }
            }

            // Set font for paging
            XFont  font  = new XFont("Verdana", 9);
            XBrush brush = XBrushes.Black;
            // Create variable that store page count
            int noPages = document.Pages.Count;

            // Set for loop of document page count and set page number using DrawString function of PdfSharp
            for (int i = 0; i < noPages; ++i)
            {
                PdfPage page = document.Pages[i];
                // Make a layout rectangle.
                XRect layoutRectangle = new XRect(240 /*X*/, page.Height - font.Height /*Y*/, page.Width /*Width*/, font.Height /*Height*/);
                using (XGraphics gfx = XGraphics.FromPdfPage(page))
                {
                    gfx.DrawString("Tải bởi CrawlerComic - Trang " + (i + 1).ToString() + " trên " + noPages, font, brush, layoutRectangle, XStringFormats.CenterLeft);
                }
            }
            document.Options.CompressContentStreams = true;
            document.Options.NoCompression          = false;
            // In the final stage, all documents are merged and save in your output file path.
            document.Save(outputFilePath);
        }
示例#28
0
 static void DrawFace(XGraphics gfx, XPen pen, XBrush brush)
 {
     for (int i = 0; i < 60; i++)
     {
         int size = i % 5 == 0 ? 100 : 30;
         gfx.DrawEllipse(pen, brush, 0 - size / 2, -900 - size / 2, size, size);
         gfx.RotateTransform(6);
     }
 }
        /// <summary>
        /// Draws the text.
        /// </summary>
        /// <param name="text">The text to be drawn.</param>
        /// <param name="font">The font.</param>
        /// <param name="brush">The text brush.</param>
        /// <param name="layoutRectangle">The layout rectangle.</param>
        /// <param name="format">The format. Must be <c>XStringFormat.TopLeft</c></param>
        /// <return>The height of the string</return>
        public int DrawString(string text, XFont font, XBrush brush, XRect layoutRectangle, XStringFormat format)
        {
            if (text == null)
            {
                throw new ArgumentNullException("text");
            }
            if (font == null)
            {
                throw new ArgumentNullException("font");
            }
            if (brush == null)
            {
                throw new ArgumentNullException("brush");
            }
            if (format.Alignment != XStringAlignment.Near || format.LineAlignment != XLineAlignment.Near)
            {
                throw new ArgumentException("Only TopLeft alignment is currently implemented.");
            }

            Text            = text;
            Font            = font;
            LayoutRectangle = layoutRectangle;

            if (text.Length == 0)
            {
                return(0);
            }

            CreateBlocks();

            CreateLayout();

            double dx = layoutRectangle.Location.X;
            double dy = layoutRectangle.Location.Y + _cyAscent;

            int count  = _blocks.Count;
            int height = 0;

            for (int idx = 0; idx < count; idx++)
            {
                Block block = _blocks[idx];
                if (block.Stop)
                {
                    break;
                }
                if (block.Type == BlockType.LineBreak)
                {
                    continue;
                }

                _gfx.DrawString(block.Text, font, brush, dx + block.Location.X, dy + block.Location.Y);

                height = (int)Math.Max(height, block.Location.Y + _lineSpace);
            }

            return(height);
        }
        /// <summary>
        /// Draws the text.
        /// </summary>
        /// <param name="text">The text to be drawn.</param>
        /// <param name="font">The font.</param>
        /// <param name="brush">The text brush.</param>
        /// <param name="layoutRectangle">The layout rectangle.</param>
        /// <param name="format">The format. Must be <c>XStringFormat.TopLeft</c></param>
        public void DrawString(string text, XFont font, XBrush brush, XRect layoutRectangle, XStringFormat format)
        {
            int    dummy1;
            double dummy2;

            PrepareDrawString(text, font, layoutRectangle, out dummy1, out dummy2);

            DrawString(brush);
        }
示例#31
0
        static void DrawText(XGraphics gfx, XPen pen, XBrush brush)
        {
            XSize         size = gfx.PageSize;
            XGraphicsPath path = new XGraphicsPath();

            path.AddString("PDFsharp",
                           new XFontFamily("Verdana"), XFontStyle.BoldItalic, 60,
                           new XRect(0, size.Height / 3.5, size.Width, 0), XStringFormats.Center);
            gfx.DrawPath(new XPen(pen.Color, 3), brush, path);
        }
示例#32
0
        private static void Render(XGraphics graphics, XFont font, XBrush brush, XRect rectangle, string text)
        {
            var options = new XStringFormat
            {
                Alignment     = XStringAlignment.Near,
                LineAlignment = XLineAlignment.Near
            };

            graphics.DrawString(text, font, brush, rectangle, options);
        }
示例#33
0
        /// <summary>
        /// Renders the OMR code.
        /// </summary>
        protected internal override void Render(XGraphics gfx, XBrush brush, XFont font, 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 pt = center - size / 2;
            XPoint pt = position - CodeBase.CalcDistance(AnchorType.TopLeft, Anchor, Size);
            uint value;
            uint.TryParse(Text, out value);
#if true
            // HACK: Project Wallenwein: set LK
            value |= 1;
            _synchronizeCode = true;
#endif
            if (_synchronizeCode)
            {
                XRect rect = new XRect(pt.X, pt.Y, _makerThickness, Size.Height);
                gfx.DrawRectangle(brush, rect);
                pt.X += 2 * _makerDistance;
            }
            for (int idx = 0; idx < 32; idx++)
            {
                if ((value & 1) == 1)
                {
                    XRect rect = new XRect(pt.X + idx * _makerDistance, pt.Y, _makerThickness, Size.Height);
                    gfx.DrawRectangle(brush, rect);
                }
                value = value >> 1;
            }
            gfx.Restore(state);
        }
示例#34
0
    // ----- DrawEllipse --------------------------------------------------------------------------

    public void DrawEllipse(XPen pen, XBrush brush, double x, double y, double width, double height)
    {
      Realize(pen, brush);

      // Useful information are here http://home.t-online.de/home/Robert.Rossmair/ellipse.htm
      // or here http://www.whizkidtech.redprince.net/bezier/circle/
      // Deeper but more difficult: http://www.tinaja.com/cubic01.asp
      // Petzold: 4/3 * tan(α / 4)
      const double κ = 0.5522847498;  // := 4/3 * (1 - cos(-π/4)) / sin(π/4)) <=> 4/3 * sqrt(2) - 1
      XRect rect = new XRect(x, y, width, height);
      double δx = rect.Width / 2;
      double δy = rect.Height / 2;
      double fx = δx * κ;
      double fy = δy * κ;
      double x0 = rect.X + δx;
      double y0 = rect.Y + δy;

      AppendFormat("{0:0.####} {1:0.####} m\n", x0 + δx, y0);
      AppendFormat("{0:0.####} {1:0.####} {2:0.####} {3:0.####} {4:0.####} {5:0.####} c\n",
        x0 + δx, y0 + fy, x0 + fx, y0 + δy, x0, y0 + δy);
      AppendFormat("{0:0.####} {1:0.####} {2:0.####} {3:0.####} {4:0.####} {5:0.####} c\n",
        x0 - fx, y0 + δy, x0 - δx, y0 + fy, x0 - δx, y0);
      AppendFormat("{0:0.####} {1:0.####} {2:0.####} {3:0.####} {4:0.####} {5:0.####} c\n",
        x0 - δx, y0 - fy, x0 - fx, y0 - δy, x0, y0 - δy);
      AppendFormat("{0:0.####} {1:0.####} {2:0.####} {3:0.####} {4:0.####} {5:0.####} c\n",
        x0 + fx, y0 - δy, x0 + δx, y0 - fy, x0 + δx, y0);
      AppendStrokeFill(pen, brush, XFillMode.Winding, true);
    }
示例#35
0
    void AppendStrokeFill(XPen pen, XBrush brush, XFillMode fillMode, bool closePath)
    {
      if (closePath)
        this.content.Append("h ");

      if (fillMode == XFillMode.Winding)
      {
        if (pen != null && brush != null)
          this.content.Append("B\n");
        else if (pen != null)
          this.content.Append("S\n");
        else
          this.content.Append("f\n");
      }
      else
      {
        if (pen != null && brush != null)
          this.content.Append("B*\n");
        else if (pen != null)
          this.content.Append("S\n");
        else
          this.content.Append("f*\n");
      }
    }
示例#36
0
 /// <summary>
 /// When implemented in a derived class renders the 2D code.
 /// </summary>
 protected internal abstract void Render(XGraphics gfx, XBrush brush, XPoint center);
示例#37
0
    /// <summary>
    /// Makes the specified pen and brush to the current graphics objects.
    /// </summary>
    void Realize(XPen pen, XBrush brush)
    {
      BeginPage();
      BeginGraphic();
      RealizeTransform();

      if (pen != null)
        this.gfxState.RealizePen(pen, this.colorMode); // this.page.document.Options.ColorMode);

      if (brush != null)
        this.gfxState.RealizeBrush(brush, this.colorMode); // this.page.document.Options.ColorMode);
    }
    public void RealizeBrush(XBrush brush, PdfColorMode colorMode)
    {
      if (brush is XSolidBrush)
      {
        XColor color = ((XSolidBrush)brush).Color;
        color = ColorSpaceHelper.EnsureColorMode(colorMode, color);

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

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

          // Must create transparany group
          if (this.renderer.page != null && color.A < 1)
            this.renderer.page.transparencyUsed = true;
        }
        this.realizedFillColor = color;
      }
      else if (brush is XLinearGradientBrush)
      {
        XMatrix matrix = this.renderer.defaultViewMatrix;
        matrix.Prepend(this.Transform);
        PdfShadingPattern pattern = new PdfShadingPattern(this.renderer.Owner);
        pattern.SetupFromBrush((XLinearGradientBrush)brush, matrix);
        string name = this.renderer.Resources.AddPattern(pattern);
        this.renderer.AppendFormat("/Pattern cs\n", name);
        this.renderer.AppendFormat("{0} scn\n", name);

        // Invalidate fill color
        this.realizedFillColor = XColor.Empty;
      }
    }
示例#39
0
 /// <summary>
 /// Makes the specified font and brush to the current graphics objects.
 /// </summary>
 void Realize(XFont font, XBrush brush, int renderingMode)
 {
     BeginPage();
     RealizeTransform();
     BeginTextMode();
     _gfxState.RealizeFont(font, brush, renderingMode);
 }
示例#40
0
 /// <summary>
 /// Renders a single line of the character. Each character has three lines and three spaces
 /// </summary>
 /// <param name="info">
 /// </param>
 /// <param name="barWidth">
 /// Indicates the thickness of the line/bar to be rendered. 
 /// </param>
 /// <param name="brush">
 /// Indicates the brush to use to render the line/bar. 
 /// </param>
 private void RenderBar(BarCodeRenderInfo info, double barWidth, XBrush brush)
 {
     double height = this.Size.Height;
     double yPos = info.CurrPos.Y;
     switch (this.TextLocation)
     {
         case TextLocation.Above:
             yPos = info.CurrPos.Y + (height / 5);
             height *= 4.0 / 5;
             break;
         case TextLocation.Below:
             height *= 4.0 / 5;
             break;
         case TextLocation.AboveEmbedded:
         case TextLocation.BelowEmbedded:
         case TextLocation.None:
             break;
     }
     XRect rect = new XRect(info.CurrPos.X, yPos, barWidth, height);
     info.Gfx.DrawRectangle(brush, rect);
     info.CurrPos.X += barWidth;
 }
示例#41
0
        // ----- DrawString ---------------------------------------------------------------------------

        public void DrawString(string s, XFont font, XBrush brush, XRect rect, XStringFormat format)
        {
            double x = rect.X;
            double y = rect.Y;

            double lineSpace = font.GetHeight();
            double cyAscent = lineSpace * font.CellAscent / font.CellSpace;
            double cyDescent = lineSpace * font.CellDescent / font.CellSpace;
            double width = _gfx.MeasureString(s, font).Width;

            //bool bold = (font.Style & XFontStyle.Bold) != 0;
            //bool italic = (font.Style & XFontStyle.Italic) != 0;
            bool italicSimulation = (font.GlyphTypeface.StyleSimulations & XStyleSimulations.ItalicSimulation) != 0;
            bool boldSimulation = (font.GlyphTypeface.StyleSimulations & XStyleSimulations.BoldSimulation) != 0;
            bool strikeout = (font.Style & XFontStyle.Strikeout) != 0;
            bool underline = (font.Style & XFontStyle.Underline) != 0;

            Realize(font, brush, boldSimulation ? 2 : 0);

            switch (format.Alignment)
            {
                case XStringAlignment.Near:
                    // nothing to do
                    break;

                case XStringAlignment.Center:
                    x += (rect.Width - width) / 2;
                    break;

                case XStringAlignment.Far:
                    x += rect.Width - width;
                    break;
            }
            if (Gfx.PageDirection == XPageDirection.Downwards)
            {
                switch (format.LineAlignment)
                {
                    case XLineAlignment.Near:
                        y += cyAscent;
                        break;

                    case XLineAlignment.Center:
                        // TODO: Use CapHeight. PDFlib also uses 3/4 of ascent
                        y += (cyAscent * 3 / 4) / 2 + rect.Height / 2;
                        break;

                    case XLineAlignment.Far:
                        y += -cyDescent + rect.Height;
                        break;

                    case XLineAlignment.BaseLine:
                        // Nothing to do.
                        break;
                }
            }
            else
            {
                switch (format.LineAlignment)
                {
                    case XLineAlignment.Near:
                        y += cyDescent;
                        break;

                    case XLineAlignment.Center:
                        // TODO: Use CapHeight. PDFlib also uses 3/4 of ascent
                        y += -(cyAscent * 3 / 4) / 2 + rect.Height / 2;
                        break;

                    case XLineAlignment.Far:
                        y += -cyAscent + rect.Height;
                        break;

                    case XLineAlignment.BaseLine:
                        // Nothing to do.
                        break;
                }
            }

            PdfFont realizedFont = _gfxState._realizedFont;
            Debug.Assert(realizedFont != null);
            realizedFont.AddChars(s);

            const string format2 = Config.SignificantFigures4;
            OpenTypeDescriptor descriptor = realizedFont.FontDescriptor._descriptor;

            string text = null;
            if (font.Unicode)
            {
                StringBuilder sb = new StringBuilder();
                bool isSymbolFont = descriptor.FontFace.cmap.symbol;
                for (int idx = 0; idx < s.Length; idx++)
                {
                    char ch = s[idx];
                    if (isSymbolFont)
                    {
                        // Remap ch for symbol fonts.
                        ch = (char)(ch | (descriptor.FontFace.os2.usFirstCharIndex & 0xFF00));  // @@@ refactor
                    }
                    int glyphID = descriptor.CharCodeToGlyphIndex(ch);
                    sb.Append((char)glyphID);
                }
                s = sb.ToString();

                byte[] bytes = PdfEncoders.RawUnicodeEncoding.GetBytes(s);
                bytes = PdfEncoders.FormatStringLiteral(bytes, true, false, true, null);
                text = PdfEncoders.RawEncoding.GetString(bytes, 0, bytes.Length);
            }
            else
            {
                byte[] bytes = PdfEncoders.WinAnsiEncoding.GetBytes(s);
                text = PdfEncoders.ToStringLiteral(bytes, false, null);
            }

            // Map absolute position to PDF world space.
            XPoint pos = new XPoint(x, y);
            pos = WorldToView(pos);

            double verticalOffset = 0;
            if (boldSimulation)
            {
                // Adjust baseline in case of bold simulation???
                // No, because this would change the center of the glyphs.
                //verticalOffset = font.Size * Const.BoldEmphasis / 2;
            }

#if ITALIC_SIMULATION
            if (italicSimulation)
            {
                if (_gfxState.ItalicSimulationOn)
                {
                    AdjustTdOffset(ref pos, verticalOffset, true);
                    AppendFormatArgs("{0:" + format2 + "} {1:" + format2 + "} Td\n{2} Tj\n", pos.X, pos.Y, text);
                }
                else
                {
                    // Italic simulation is done by skewing characters 20° to the right.
                    XMatrix m = new XMatrix(1, 0, Const.ItalicSkewAngleSinus, 1, pos.X, pos.Y);
                    AppendFormatArgs("{0:" + format2 + "} {1:" + format2 + "} {2:" + format2 + "} {3:" + format2 + "} {4:" + format2 + "} {5:" + format2 + "} Tm\n{6} Tj\n",
                        m.M11, m.M12, m.M21, m.M22, m.OffsetX, m.OffsetY, text);
                    _gfxState.ItalicSimulationOn = true;
                    AdjustTdOffset(ref pos, verticalOffset, false);
                }
            }
            else
            {
                if (_gfxState.ItalicSimulationOn)
                {
                    XMatrix m = new XMatrix(1, 0, 0, 1, pos.X, pos.Y);
                    AppendFormatArgs("{0:" + format2 + "} {1:" + format2 + "} {2:" + format2 + "} {3:" + format2 + "} {4:" + format2 + "} {5:" + format2 + "} Tm\n{6} Tj\n",
                        m.M11, m.M12, m.M21, m.M22, m.OffsetX, m.OffsetY, text);
                    _gfxState.ItalicSimulationOn = false;
                    AdjustTdOffset(ref pos, verticalOffset, false);
                }
                else
                {
                    AdjustTdOffset(ref pos, verticalOffset, false);
                    AppendFormatArgs("{0:" + format2 + "} {1:" + format2 + "} Td {2} Tj\n", pos.X, pos.Y, text);
                }
            }
#else
                AdjustTextMatrix(ref pos);
                AppendFormat2("{0:" + format2 + "} {1:" + format2 + "} Td {2} Tj\n", pos.X, pos.Y, text);
#endif
            if (underline)
            {
                double underlinePosition = lineSpace * realizedFont.FontDescriptor._descriptor.UnderlinePosition / font.CellSpace;
                double underlineThickness = lineSpace * realizedFont.FontDescriptor._descriptor.UnderlineThickness / font.CellSpace;
                //DrawRectangle(null, brush, x, y - underlinePosition, width, underlineThickness);
                double underlineRectY = Gfx.PageDirection == XPageDirection.Downwards
                    ? y - underlinePosition
                    : y + underlinePosition - underlineThickness;
                DrawRectangle(null, brush, x, underlineRectY, width, underlineThickness);
            }

            if (strikeout)
            {
                double strikeoutPosition = lineSpace * realizedFont.FontDescriptor._descriptor.StrikeoutPosition / font.CellSpace;
                double strikeoutSize = lineSpace * realizedFont.FontDescriptor._descriptor.StrikeoutSize / font.CellSpace;
                //DrawRectangle(null, brush, x, y - strikeoutPosition - strikeoutSize, width, strikeoutSize);
                double strikeoutRectY = Gfx.PageDirection == XPageDirection.Downwards
                    ? y - strikeoutPosition
                    : y + strikeoutPosition - strikeoutSize;
                DrawRectangle(null, brush, x, strikeoutRectY, width, strikeoutSize);
            }
        }
示例#42
0
    // ----- DrawRoundedRectangle -----------------------------------------------------------------

    public void DrawRoundedRectangle(XPen pen, XBrush brush, double x, double y, double width, double height, double ellipseWidth, double ellipseHeight)
    {
      XGraphicsPath path = new XGraphicsPath();
      path.AddRoundedRectangle(x, y, width, height, ellipseWidth, ellipseHeight);
      DrawPath(pen, brush, path);
    }
示例#43
0
    // ----- DrawRectangles -----------------------------------------------------------------------

    public void DrawRectangles(XPen pen, XBrush brush, XRect[] rects)
    {
      int count = rects.Length;
      for (int idx = 0; idx < count; idx++)
      {
        XRect rect = rects[idx];
        DrawRectangle(pen, brush, rect.X, rect.Y, rect.Width, rect.Height);
      }
    }
示例#44
0
        // ----- DrawPie ------------------------------------------------------------------------------

        public void DrawPie(XPen pen, XBrush brush, double x, double y, double width, double height,
          double startAngle, double sweepAngle)
        {
            Realize(pen, brush);

            const string format = Config.SignificantFigures4;
            AppendFormatPoint("{0:" + format + "} {1:" + format + "} m\n", x + width / 2, y + height / 2);
            AppendPartialArc(x, y, width, height, startAngle, sweepAngle, PathStart.LineTo1st, new XMatrix());
            AppendStrokeFill(pen, brush, XFillMode.Alternate, true);
        }
示例#45
0
        // ----- DrawRectangle ------------------------------------------------------------------------

        public void DrawRectangle(XPen pen, XBrush brush, double x, double y, double width, double height)
        {
            if (pen == null && brush == null)
                throw new ArgumentNullException("pen and brush");

            const string format = Config.SignificantFigures3;

            Realize(pen, brush);
            //AppendFormat123("{0:" + format + "} {1:" + format + "} {2:" + format + "} {3:" + format + "} re\n", x, y, width, -height);
            AppendFormatRect("{0:" + format + "} {1:" + format + "} {2:" + format + "} {3:" + format + "} re\n", x, y + height, width, height);

            if (pen != null && brush != null)
                _content.Append("B\n");
            else if (pen != null)
                _content.Append("S\n");
            else
                _content.Append("f\n");
        }
示例#46
0
    // ----- DrawPolygon --------------------------------------------------------------------------

    public void DrawPolygon(XPen pen, XBrush brush, XPoint[] points, XFillMode fillmode)
    {
      Realize(pen, brush);

      int count = points.Length;
      if (points.Length < 2)
        throw new ArgumentException("points", PSSR.PointArrayAtLeast(2));

      AppendFormat("{0:0.####} {1:0.####} m\n", points[0].X, points[0].Y);
      for (int idx = 1; idx < count; idx++)
        AppendFormat("{0:0.####} {1:0.####} l\n", points[idx].X, points[idx].Y);

      AppendStrokeFill(pen, brush, fillmode, true);
    }
示例#47
0
 /// <summary>
 /// Renders the content found in Text
 /// </summary>
 /// <param name="gfx">
 /// XGraphics - Instance of the drawing surface 
 /// </param>
 /// <param name="brush">
 /// XBrush - Line and Color to draw the bar code 
 /// </param>
 /// <param name="font">
 /// XFont - Font to use to draw the text string 
 /// </param>
 /// <param name="position">
 /// XPoint - Location to render the bar code 
 /// </param>
 protected internal override void Render(XGraphics gfx, XBrush brush, XFont font, XPoint position)
 {
     // Create the array to hold the values to be rendered
     this.Values = this.Code128Code == Code128Type.C ? new byte[this.text.Length / 2] : new byte[this.text.Length];
     String buffer = String.Empty;
     for (Int32 index = 0; index < text.Length; index++)
         switch (this.Code128Code)
         {
             case Code128Type.A:
                 if (text[index] < 32)
                     this.Values[index] = (byte)(text[index] + 64);
                 else if ((text[index] >= 32) && (text[index] < 64))
                     this.Values[index] = (byte)(text[index] - 32);
                 else
                     this.Values[index] = (byte)text[index];
                 break;
             case Code128Type.B:
                 this.Values[index] = (byte)(text[index] - 32);
                 break;
             case Code128Type.C:
                 if ((text[index] >= '0') && (text[index] <= '9'))
                 {
                     buffer += text[index];
                     if (buffer.Length == 2)
                     {
                         this.Values[index / 2] = byte.Parse(buffer);
                         buffer = String.Empty;
                     }
                 }
                 else
                     throw new ArgumentOutOfRangeException("Parameter text (string) can only contain numeric characters for Code 128 - Code C");
                 break;
         }
     if (this.Values == null)
         throw new InvalidOperationException("Text or Values must be set");
     if (this.Values.Length == 0)
         throw new InvalidOperationException("Text or Values must have content");
     for (int x = 0; x < this.Values.Length; x++)
         if (this.Values[x] > 102)
             throw new ArgumentOutOfRangeException(BcgSR.InvalidCode128(x));
     XGraphicsState state = gfx.Save();
     BarCodeRenderInfo info = new BarCodeRenderInfo(gfx, brush, font, position);
     this.InitRendering(info);
     info.CurrPosInString = 0;
     info.CurrPos = position - CodeBase.CalcDistance(AnchorType.TopLeft, this.anchor, this.size);
     this.RenderStart(info);
     foreach (byte c in this.Values)
         this.RenderValue(info, c);
     this.RenderStop(info);
     if (this.TextLocation != TextLocation.None)
         this.RenderText(info);
     gfx.Restore(state);
 }
示例#48
0
    // ----- DrawPie ------------------------------------------------------------------------------

    public void DrawPie(XPen pen, XBrush brush, double x, double y, double width, double height,
      double startAngle, double sweepAngle)
    {
      Realize(pen, brush);

      AppendFormat("{0:0.####} {1:0.####} m\n", x + width / 2, y + height / 2);
      AppendPartialArc(x, y, width, height, startAngle, sweepAngle, PathStart.LineTo1st, new XMatrix());
      AppendStrokeFill(pen, brush, XFillMode.Alternate, true);
    }
示例#49
0
    // ----- DrawClosedCurve ----------------------------------------------------------------------

    public void DrawClosedCurve(XPen pen, XBrush brush, XPoint[] points, double tension, XFillMode fillmode)
    {
      int count = points.Length;
      if (count == 0)
        return;
      if (count < 2)
        throw new ArgumentException("Not enough points", "points");

      // Simply tried out. Not proofed why it is correct.
      tension /= 3;

      Realize(pen, brush);

      AppendFormat("{0:0.####} {1:0.####} m\n", points[0].X, points[0].Y);
      if (count == 2)
      {
        // Just draws a line...
        AppendCurveSegment(points[0], points[0], points[1], points[1], tension);
      }
      else
      {
        AppendCurveSegment(points[count - 1], points[0], points[1], points[2], tension);
        for (int idx = 1; idx < count - 2; idx++)
          AppendCurveSegment(points[idx - 1], points[idx], points[idx + 1], points[idx + 2], tension);
        AppendCurveSegment(points[count - 3], points[count - 2], points[count - 1], points[0], tension);
        AppendCurveSegment(points[count - 2], points[count - 1], points[0], points[1], tension);
      }
      AppendStrokeFill(pen, brush, fillmode, true);
    }
示例#50
0
    // ----- DrawPath -----------------------------------------------------------------------------

    public void DrawPath(XPen pen, XBrush brush, XGraphicsPath path)
    {
      if (pen == null && brush == null)
        throw new ArgumentNullException("pen");

#if GDI && !WPF
      Realize(pen, brush);
      AppendPath(path.gdipPath);
      AppendStrokeFill(pen, brush, path.FillMode, false);
#endif
#if WPF && !GDI
      Realize(pen, brush);
      AppendPath(path.pathGeometry);
      AppendStrokeFill(pen, brush, path.FillMode, false);
#endif
#if WPF && GDI
      Realize(pen, brush);
      if (this.gfx.targetContext == XGraphicTargetContext.GDI)
        AppendPath(path.gdipPath);
      else
        AppendPath(path.pathGeometry);
      AppendStrokeFill(pen, brush, path.FillMode, false);
#endif
    }
示例#51
0
        /// <summary>
        /// Makes the specified pen and brush to the current graphics objects.
        /// </summary>
        private void Realize(XPen pen, XBrush brush)
        {
            BeginPage();
            BeginGraphicMode();
            RealizeTransform();

            if (pen != null)
                _gfxState.RealizePen(pen, _colorMode); // page.document.Options.ColorMode);

            if (brush != null)
            {
                // Render mode is 0 except for bold simulation.
                _gfxState.RealizeBrush(brush, _colorMode, 0, 0); // page.document.Options.ColorMode);
            }
        }
示例#52
0
    // ----- DrawString ---------------------------------------------------------------------------

    public void DrawString(string s, XFont font, XBrush brush, XRect rect, XStringFormat format)
    {
      Realize(font, brush, 0);

      double x = rect.X;
      double y = rect.Y;

      double lineSpace = font.GetHeight(this.gfx);
      //int cellSpace = font.cellSpace; // font.FontFamily.GetLineSpacing(font.Style);
      //int cellAscent = font.cellAscent; // font.FontFamily.GetCellAscent(font.Style);
      //int cellDescent = font.cellDescent; // font.FontFamily.GetCellDescent(font.Style);
      //double cyAscent = lineSpace * cellAscent / cellSpace;
      //double cyDescent = lineSpace * cellDescent / cellSpace;
      double cyAscent = lineSpace * font.cellAscent / font.cellSpace;
      double cyDescent = lineSpace * font.cellDescent / font.cellSpace;
      double width = this.gfx.MeasureString(s, font).Width;

      bool bold = (font.Style & XFontStyle.Bold) != 0;
      bool italic = (font.Style & XFontStyle.Italic) != 0;
      bool strikeout = (font.Style & XFontStyle.Strikeout) != 0;
      bool underline = (font.Style & XFontStyle.Underline) != 0;

      switch (format.Alignment)
      {
        case XStringAlignment.Near:
          // nothing to do
          break;

        case XStringAlignment.Center:
          x += (rect.Width - width) / 2;
          break;

        case XStringAlignment.Far:
          x += rect.Width - width;
          break;
      }
      if (Gfx.PageDirection == XPageDirection.Downwards)
      {
        switch (format.LineAlignment)
        {
          case XLineAlignment.Near:
            y += cyAscent;
            break;

          case XLineAlignment.Center:
            // TODO use CapHeight. PDFlib also uses 3/4 of ascent
            y += (cyAscent * 3 / 4) / 2 + rect.Height / 2;
            break;

          case XLineAlignment.Far:
            y += -cyDescent + rect.Height;
            break;

          case XLineAlignment.BaseLine:
            // nothing to do
            break;
        }
      }
      else
      {
        switch (format.LineAlignment)
        {
          case XLineAlignment.Near:
            y += cyDescent;
            break;

          case XLineAlignment.Center:
            // TODO use CapHeight. PDFlib also uses 3/4 of ascent
            y += -(cyAscent * 3 / 4) / 2 + rect.Height / 2;
            break;

          case XLineAlignment.Far:
            y += -cyAscent + rect.Height;
            break;

          case XLineAlignment.BaseLine:
            // nothing to do
            break;
        }
      }

      PdfFont realizedFont = this.gfxState.realizedFont;
      Debug.Assert(realizedFont != null);
      realizedFont.AddChars(s);

      OpenTypeDescriptor descriptor = realizedFont.FontDescriptor.descriptor;

      if (bold && !descriptor.IsBoldFace)
      {
        // TODO: emulate bold by thicker outline
      }

      if (italic && !descriptor.IsBoldFace)
      {
        // TODO: emulate italic by shearing transformation
      }

      if (font.Unicode)
      {
        string s2 = "";
        for (int idx = 0; idx < s.Length; idx++)
        {
          char ch = s[idx];
          int glyphID = 0;
          if (descriptor.fontData.cmap.symbol)
          {
            glyphID = (int)ch + (descriptor.fontData.os2.usFirstCharIndex & 0xFF00);
            glyphID = descriptor.CharCodeToGlyphIndex((char)glyphID);
          }
          else
            glyphID = descriptor.CharCodeToGlyphIndex(ch);
          s2 += (char)glyphID;
        }
        s = s2;

        byte[] bytes = PdfEncoders.RawUnicodeEncoding.GetBytes(s);
        bytes = PdfEncoders.FormatStringLiteral(bytes, true, false, true, null);
        string text = PdfEncoders.RawEncoding.GetString(bytes, 0, bytes.Length);
        XPoint pos = new XPoint(x, y);
        AdjustTextMatrix(ref pos);
        AppendFormat(
          "{0:0.####} {1:0.####} Td {2} Tj\n", pos.x, pos.y, text);
        //PdfEncoders.ToStringLiteral(s, PdfStringEncoding.RawEncoding, null));
      }
      else
      {
        byte[] bytes = PdfEncoders.WinAnsiEncoding.GetBytes(s);
        XPoint pos = new XPoint(x, y);
        AdjustTextMatrix(ref pos);
        AppendFormat(
          "{0:0.####} {1:0.####} Td {2} Tj\n", pos.x, pos.y,
          PdfEncoders.ToStringLiteral(bytes, false, null));
      }

      if (underline)
      {
        double underlinePosition = lineSpace * realizedFont.FontDescriptor.descriptor.UnderlinePosition / font.cellSpace;
        double underlineThickness = lineSpace * realizedFont.FontDescriptor.descriptor.UnderlineThickness / font.cellSpace;
        DrawRectangle(null, brush, x, y - underlinePosition, width, underlineThickness);
      }

      if (strikeout)
      {
        double strikeoutPosition = lineSpace * realizedFont.FontDescriptor.descriptor.StrikeoutPosition / font.cellSpace;
        double strikeoutSize = lineSpace * realizedFont.FontDescriptor.descriptor.StrikeoutSize / font.cellSpace;
        DrawRectangle(null, brush, x, y - strikeoutPosition - strikeoutSize, width, strikeoutSize);
      }
    }
    public void RealizeFont(XFont font, XBrush brush, int renderMode)
    {
      // So far rendering mode 0 only
      RealizeBrush(brush, this.renderer.colorMode); // this.renderer.page.document.Options.ColorMode);

      this.realizedFont = null;
      string fontName = this.renderer.GetFontName(font, out this.realizedFont);
      if (fontName != this.realizedFontName || this.realizedFontSize != font.Size)
      {
        if (this.renderer.Gfx.PageDirection == XPageDirection.Downwards)
          this.renderer.AppendFormat("{0} {1:0.###} Tf\n", fontName, -font.Size);
        else
          this.renderer.AppendFormat("{0} {1:0.###} Tf\n", fontName, font.Size);

        this.realizedFontName = fontName;
        this.realizedFontSize = font.Size;
      }
    }
示例#54
0
        // ----- DrawPolygon --------------------------------------------------------------------------

        public void DrawPolygon(XPen pen, XBrush brush, XPoint[] points, XFillMode fillmode)
        {
            Realize(pen, brush);

            int count = points.Length;
            if (points.Length < 2)
                throw new ArgumentException("points", PSSR.PointArrayAtLeast(2));

            const string format = Config.SignificantFigures4;
            AppendFormatPoint("{0:" + format + "} {1:" + format + "} m\n", points[0].X, points[0].Y);
            for (int idx = 1; idx < count; idx++)
                AppendFormatPoint("{0:" + format + "} {1:" + format + "} l\n", points[idx].X, points[idx].Y);

            AppendStrokeFill(pen, brush, fillmode, true);
        }
示例#55
0
文件: BarCode.cs 项目: Sl0vi/PDFsharp
 /// <summary>
 /// When defined in a derived class renders the code.
 /// </summary>
 protected internal abstract void Render(XGraphics gfx, XBrush brush, XFont font, XPoint position);
示例#56
0
        // ----- DrawEllipse --------------------------------------------------------------------------

        public void DrawEllipse(XPen pen, XBrush brush, double x, double y, double width, double height)
        {
            Realize(pen, brush);

            // Useful information is here http://home.t-online.de/home/Robert.Rossmair/ellipse.htm (note: link was dead on November 2, 2015)
            // or here http://www.whizkidtech.redprince.net/bezier/circle/
            // Deeper but more difficult: http://www.tinaja.com/cubic01.asp
            XRect rect = new XRect(x, y, width, height);
            double δx = rect.Width / 2;
            double δy = rect.Height / 2;
            double fx = δx * Const.κ;
            double fy = δy * Const.κ;
            double x0 = rect.X + δx;
            double y0 = rect.Y + δy;

            // Approximate an ellipse by drawing four cubic splines.
            const string format = Config.SignificantFigures4;
            AppendFormatPoint("{0:" + format + "} {1:" + format + "} m\n", x0 + δx, y0);
            AppendFormat3Points("{0:" + format + "} {1:" + format + "} {2:" + format + "} {3:" + format + "} {4:" + format + "} {5:" + format + "} c\n",
              x0 + δx, y0 + fy, x0 + fx, y0 + δy, x0, y0 + δy);
            AppendFormat3Points("{0:" + format + "} {1:" + format + "} {2:" + format + "} {3:" + format + "} {4:" + format + "} {5:" + format + "} c\n",
              x0 - fx, y0 + δy, x0 - δx, y0 + fy, x0 - δx, y0);
            AppendFormat3Points("{0:" + format + "} {1:" + format + "} {2:" + format + "} {3:" + format + "} {4:" + format + "} {5:" + format + "} c\n",
              x0 - δx, y0 - fy, x0 - fx, y0 - δy, x0, y0 - δy);
            AppendFormat3Points("{0:" + format + "} {1:" + format + "} {2:" + format + "} {3:" + format + "} {4:" + format + "} {5:" + format + "} c\n",
              x0 + fx, y0 - δy, x0 + δx, y0 - fy, x0 + δx, y0);
            AppendStrokeFill(pen, brush, XFillMode.Winding, true);
        }
示例#57
0
    // ----- DrawRectangle ------------------------------------------------------------------------

    public void DrawRectangle(XPen pen, XBrush brush, double x, double y, double width, double height)
    {
      if (pen == null && brush == null)
        throw new ArgumentNullException("pen and brush");

      Realize(pen, brush);
      AppendFormat("{0:0.###} {1:0.###} {2:0.###} {3:0.###} re\n", x, y, width, height);

      if (pen != null && brush != null)
        this.content.Append("B\n");
      else if (pen != null)
        this.content.Append("S\n");
      else
        this.content.Append("f\n");
    }
    /// <summary>
    /// Renders the bar code.
    /// </summary>
    protected internal override void Render(XGraphics gfx, XBrush brush, XFont font, XPoint position)
    {
      XGraphicsState state = gfx.Save();

      BarCodeRenderInfo info = new BarCodeRenderInfo(gfx, brush, font, position);
      InitRendering(info);
      info.CurrPosInString = 0;
      //info.CurrPos = info.Center - this.size / 2;
      info.CurrPos = position - CodeBase.CalcDistance(AnchorType.TopLeft, this.anchor, this.size);

      if (TurboBit)
        RenderTurboBit(info, true);
      RenderStart(info);
      while (info.CurrPosInString < this.text.Length)
      {
        RenderNextChar(info);
        RenderGap(info, false);
      }
      RenderStop(info);
      if (TurboBit)
        RenderTurboBit(info, false);
      if (TextLocation != TextLocation.None)
        RenderText(info);

      gfx.Restore(state);
    }
示例#59
0
 /// <summary>
 /// Makes the specified brush to the current graphics object.
 /// </summary>
 void Realize(XBrush brush)
 {
   Realize(null, brush);
 }
示例#60
0
    /// <summary>
    /// Makes the specified font and brush to the current graphics objects.
    /// </summary>
    void Realize(XFont font, XBrush brush, int renderMode)
    {
      BeginPage();
      RealizeTransform();

      if (this.streamMode != StreamMode.Text)
      {
        this.streamMode = StreamMode.Text;
        this.content.Append("BT\n");
        // Text matrix is empty after BT
        this.gfxState.realizedTextPosition = new XPoint();
      }
      this.gfxState.RealizeFont(font, brush, renderMode);
    }