Exemple #1
0
        override protected void DoPrint(PrintOut adriver, int aposx, int aposy,
                                        int newwidth, int newheight, MetaFile metafile, Point MaxExtent,
                                        ref bool PartialPrint)
        {
            base.DoPrint(adriver, aposx, aposy, newwidth, newheight,
                         metafile, MaxExtent, ref PartialPrint);
            MetaObjectDraw metaobj = new MetaObjectDraw();

            metaobj.MetaType   = MetaObjectType.Draw;
            metaobj.Top        = aposy; metaobj.Left = aposx;
            metaobj.Width      = PrintWidth; metaobj.Height = PrintHeight;
            metaobj.DrawStyle  = Shape;
            metaobj.BrushStyle = (int)BrushStyle;
            metaobj.PenStyle   = (int)PenStyle;
            metaobj.PenWidth   = PenWidth;
            metaobj.PenColor   = PenColor;
            if (BrushColorExpression.Length > 0)
            {
                try
                {
                    metaobj.BrushColor = Report.Evaluator.EvaluateText(BrushColorExpression);
                }
                catch
                {
                    metaobj.BrushColor = BrushColor;
                }
            }
            else
            {
                metaobj.BrushColor = BrushColor;
            }
            metafile.Pages[metafile.CurrentPage].Objects.Add(metaobj);
        }
Exemple #2
0
        /// <summary>
        /// Encode the content using the encoding scheme given
        /// </summary>
        /// <param name="content"></param>
        /// <param name="encoding"></param>
        /// <returns></returns>
        public virtual void EncodeInMetafile(MetaFile metafile, int posx, int posy, int modul, String content, Encoding encoding)
        {
            bool[][] matrix = calQrcode(encoding.GetBytes(content));

            /*int PrintWidth = matrix.Length * qrCodeScale*modul + 1;
             * int PrintHeight = matrix.Length * qrCodeScale*modul + 1;
             * MetaObjectDraw metaobj = new MetaObjectDraw();
             * metaobj.MetaType = MetaObjectType.Draw;
             * metaobj.Top = posy;
             * metaobj.Left = posx;
             * metaobj.Width = PrintWidth;
             * metaobj.Height = PrintHeight;
             * metaobj.DrawStyle = ShapeType.Rectangle;
             * metaobj.BrushStyle = (int)BrushType.Solid;
             * metaobj.PenStyle = (int)PenType.Clear;
             * metaobj.PenWidth = 0;
             * metaobj.PenColor = GraphicUtils.IntegerFromColor(qrCodeBackgroundColor);
             * metaobj.BrushColor = GraphicUtils.IntegerFromColor(qrCodeBackgroundColor);
             * metafile.Pages[metafile.CurrentPage].Objects.Add(metaobj);*/


            int bwidth = qrCodeScale * modul;

            for (int i = 0; i < matrix.Length; i++)
            {
                for (int j = 0; j < matrix.Length; j++)
                {
                    if (matrix[j][i])
                    {
                        MetaObjectDraw metaobj = new MetaObjectDraw();
                        metaobj.MetaType   = MetaObjectType.Draw;
                        metaobj.Top        = posy + i * bwidth;
                        metaobj.Left       = posx + j * bwidth;
                        metaobj.Width      = bwidth;
                        metaobj.Height     = bwidth;
                        metaobj.DrawStyle  = ShapeType.Rectangle;
                        metaobj.BrushStyle = (int)BrushType.Solid;
                        metaobj.PenStyle   = (int)PenType.Solid;
                        metaobj.PenWidth   = 0;
                        metaobj.PenColor   = GraphicUtils.IntegerFromColor(qrCodeForegroundColor);
                        metaobj.BrushColor = GraphicUtils.IntegerFromColor(qrCodeForegroundColor);
                        metafile.Pages[metafile.CurrentPage].Objects.Add(metaobj);
                    }
                }
            }
        }
Exemple #3
0
        public void DoLines(string data, int Left, int Top, MetaFile metafile)
        {
            int      i;
            LineType lt;
            int      xadd, awidth, aheight;
            // Edges of a line (rectangle)
            Point a, b, c, d, origin;
            //	  double alpha;
            int PenWidth;
            int PenColor;
            int BrushColor;

            if (BarType == BarcodeType.CodePDF417)
            {
                //Draw2DBarcode(FLeft,FTop,meta);
                return;
            }
            xadd   = 0;
            origin = new Point(Left, Top);
            //alpha=Rotation/10*pi/180.0;
            PenWidth = 0;
            for (i = 0; i < data.Length; i++)
            {
                switch (data[i])
                {
                case '0':
                    awidth = modules[0];
                    lt     = LineType.White;
                    break;

                case '1':
                    awidth = modules[1];
                    lt     = LineType.White;
                    break;

                case '2':
                    awidth = modules[2];
                    lt     = LineType.White;
                    break;

                case '3':
                    awidth = modules[3];
                    lt     = LineType.White;
                    break;

                case '5':
                    awidth = modules[0];
                    lt     = LineType.Black;
                    break;

                case '6':
                    awidth = modules[1];
                    lt     = LineType.Black;
                    break;

                case '7':
                    awidth = modules[2];
                    lt     = LineType.Black;
                    break;

                case '8':
                    awidth = modules[3];
                    lt     = LineType.Black;
                    break;

                case 'A':
                    awidth = modules[0];
                    lt     = LineType.Half;
                    break;

                case 'B':
                    awidth = modules[1];
                    lt     = LineType.Half;
                    break;

                case 'C':
                    awidth = modules[2];
                    lt     = LineType.Half;
                    break;

                case 'D':
                    awidth = modules[3];
                    lt     = LineType.Half;
                    break;

                default:
                    throw new NamedException(Translator.TranslateStr(582) + ":" + data, data);
                }
                if ((lt == LineType.Black) || (lt == LineType.Half))
                {
                    PenColor = BColor;
                }
                else
                {
                    PenColor = 0xFFFFFF;
                }
                if (lt != LineType.White)
                {
                    BrushColor = PenColor;
                    if (lt == LineType.Half)
                    {
                        aheight = PrintHeight * 2 / 5;
                    }
                    else
                    {
                        aheight = PrintHeight;
                    }
                    a = new Point(xadd, 0);
                    b = new Point(xadd, aheight);
                    c = new Point(xadd + awidth, aheight);
                    d = new Point(xadd + awidth, 0);
                    // a,b,c,d builds the rectangle we want to draw
                    a = Translate2D(a, origin);
                    b = Translate2D(b, origin);
                    c = Translate2D(c, origin);
                    d = Translate2D(d, origin);
                    MetaObjectDraw metaobj = new MetaObjectDraw();
                    metaobj.MetaType   = MetaObjectType.Draw;
                    metaobj.Top        = a.Y; metaobj.Left = a.X;
                    metaobj.Width      = c.X - a.X; metaobj.Height = c.Y - a.Y;
                    metaobj.DrawStyle  = ShapeType.Rectangle;
                    metaobj.BrushStyle = (int)BrushType.Solid;
                    metaobj.PenStyle   = (int)PenType.Solid;
                    metaobj.PenWidth   = PenWidth;
                    metaobj.PenColor   = PenColor;
                    metaobj.BrushColor = BrushColor;
                    metafile.Pages[metafile.CurrentPage].Objects.Add(metaobj);
                }

                xadd = xadd + awidth;
            }
        }
        /// <summary>
        /// Draw an object to the PDF file
        /// </summary>
        /// <param name="page">MetaPage conatining the object</param>
        /// <param name="obj">Object to be drawn</param>
        public void DrawObject(MetaPage page, MetaObject obj)
        {
            if (CalculateOnly)
            {
                return;
            }
            int          X, Y, W, H, S;
            int          Width, Height, posx, posy;
            Rectangle    rec;
            int          aalign;
            MemoryStream stream;
            string       astring;

            posx = obj.Left;
            posy = obj.Top;
            switch (obj.MetaType)
            {
            case MetaObjectType.Text:
                MetaObjectText objt = (MetaObjectText)obj;
                FPDFFile.Canvas.Font.WFontName = page.GetWFontNameText(objt);
                FPDFFile.Canvas.Font.FontName  = FPDFFile.Canvas.Font.WFontName.Replace(" ", "");
                FPDFFile.Canvas.Font.LFontName = page.GetLFontNameText(objt);
                FPDFFile.Canvas.Font.Style     = objt.FontStyle;
                // Transparent ?
                FPDFFile.Canvas.Font.Name        = (PDFFontType)objt.Type1Font;
                FPDFFile.Canvas.Font.Size        = objt.FontSize;
                FPDFFile.Canvas.Font.Color       = objt.FontColor;
                FPDFFile.Canvas.Font.Bold        = (objt.FontStyle & 1) > 0;
                FPDFFile.Canvas.Font.Italic      = (objt.FontStyle & 2) > 0;
                FPDFFile.Canvas.Font.Underline   = (objt.FontStyle & 4) > 0;
                FPDFFile.Canvas.Font.StrikeOut   = (objt.FontStyle & 8) > 0;
                FPDFFile.Canvas.Font.BackColor   = objt.BackColor;
                FPDFFile.Canvas.Font.Transparent = objt.Transparent;
                FPDFFile.Canvas.UpdateFonts();
                aalign  = objt.Alignment;
                rec     = new Rectangle(posx, posy, posx + objt.Width, posy + objt.Height);
                astring = page.GetText(objt);
                FPDFFile.Canvas.TextRect(rec, astring, aalign, objt.CutText,
                                         objt.WordWrap, objt.FontRotation, objt.RightToLeft);
                break;

            case MetaObjectType.Draw:
                MetaObjectDraw objd = (MetaObjectDraw)obj;
                Width  = objd.Width;
                Height = objd.Height;
                FPDFFile.Canvas.BrushStyle = objd.BrushStyle;
                FPDFFile.Canvas.PenStyle   = objd.PenStyle;
                FPDFFile.Canvas.PenColor   = objd.PenColor;
                FPDFFile.Canvas.BrushColor = objd.BrushColor;
                FPDFFile.Canvas.PenWidth   = objd.PenWidth;
                X = (int)FPDFFile.Canvas.PenWidth / 2;
                Y = X;
                W = Width - FPDFFile.Canvas.PenWidth + 1;
                H = Height - FPDFFile.Canvas.PenWidth + 1;
                if (FPDFFile.Canvas.PenWidth == 0)
                {
                    W--;
                    H--;
                }
                if (W < H)
                {
                    S = W;
                }
                else
                {
                    S = H;
                }
                ShapeType shape = (ShapeType)objd.DrawStyle;
                if ((shape == ShapeType.Square) || (shape == ShapeType.RoundSquare) ||
                    (shape == ShapeType.Circle))
                {
                    X = X + (int)((W - S) / 2);
                    Y = Y + (int)((H - S) / 2);
                    W = S;
                    H = S;
                }
                switch (shape)
                {
                case ShapeType.Rectangle:
                case ShapeType.Square:
                    FPDFFile.Canvas.Rectangle(X + posx, Y + posy, X + posx + W, Y + posy + H);
                    break;

                case ShapeType.RoundRect:
                case ShapeType.RoundSquare:
                    FPDFFile.Canvas.RoundedRectangle(X + posx, Y + posy, X + posx + W, Y + posy + H, Rectangle_Radius);
                    break;

                case ShapeType.Ellipse:
                case ShapeType.Circle:
                    FPDFFile.Canvas.Ellipse(X + posx, Y + posy, X + posx + W, Y + posy + H);
                    break;

                case ShapeType.HorzLine:
                    FPDFFile.Canvas.Line(X + posx, Y + posy, X + posx + W, Y + posy);
//							if (objd.PenStyle >= 3 && objd.PenStyle <= 4)
//							{
//								FPDFFile.Canvas.PenStyle = 6;
//								FPDFFile.Canvas.Line(X + posx, Y + posy, X + posx, Y + posx + H);
//							}
                    break;

                case ShapeType.VertLine:
                    FPDFFile.Canvas.Line(X + posx, Y + posy, X + posx, Y + posy + H);
                    break;

                case ShapeType.Oblique1:
                    FPDFFile.Canvas.Line(X + posx, Y + posy, X + posx + W, Y + posy + H);
                    break;

                case ShapeType.Oblique2:
                    FPDFFile.Canvas.Line(X + posx, Y + posy + H, X + posx + W, Y + posy);
                    break;
                }
                break;

            case MetaObjectType.Image:
                MetaObjectImage obji = (MetaObjectImage)obj;
                // In pdf draw also preview only images
                //if (!obji.PreviewOnly)
                {
                    Width  = obji.Width;
                    Height = obji.Height;
                    rec    = new Rectangle(posx, posy, Width, Height);
                    stream = page.GetStream(obji);
                    ImageDrawStyleType dstyle = (ImageDrawStyleType)obji.DrawImageStyle;
                    long intimageindex        = -1;
                    if (obji.SharedImage)
                    {
                        intimageindex = obji.StreamPos;
                    }
                    bool adaptsize = false;
                    if (dstyle == ImageDrawStyleType.Full)
                    {
                        adaptsize = true;
                        dstyle    = ImageDrawStyleType.Crop;
                    }
                    switch (dstyle)
                    {
                    case ImageDrawStyleType.Full:
                        FPDFFile.Canvas.DrawImage(rec, stream, obji.DPIRes, false, false, intimageindex);
                        break;

                    case ImageDrawStyleType.Stretch:
                        FPDFFile.Canvas.DrawImage(rec, stream, 0, false, false, intimageindex);
                        break;

                    case ImageDrawStyleType.Crop:
                        int bitmapwidth  = 0;
                        int bitmapheight = 0;
                        using (Image nimage = Image.FromStream(stream))
                        {
                            bitmapwidth  = nimage.Width;
                            bitmapheight = nimage.Height;
                        }
                        if (adaptsize)
                        {
                            double nwidth  = bitmapwidth * Twips.TWIPS_PER_INCH / obji.DPIRes;
                            double nheight = bitmapheight * Twips.TWIPS_PER_INCH / obji.DPIRes;
                            if (nwidth > rec.Width)
                            {
                                rec = new Rectangle(rec.Left, rec.Top, Convert.ToInt32(nwidth), Height);
                            }
                            if (nheight > rec.Height)
                            {
                                rec = new Rectangle(rec.Left, rec.Top, rec.Width, Convert.ToInt32(nheight));
                            }
                        }

                        double propx = (double)rec.Width / bitmapwidth;
                        double propy = (double)rec.Height / bitmapheight;
                        H = 0;
                        W = 0;
                        if (propy > propx)
                        {
                            H   = Convert.ToInt32(Math.Round(rec.Height * propx / propy));
                            rec = new Rectangle(rec.Left, Convert.ToInt32(rec.Top + (rec.Height - H) / 2), rec.Width, H);
                        }
                        else
                        {
                            W   = Convert.ToInt32(rec.Width * propy / propx);
                            rec = new Rectangle(rec.Left + (rec.Width - W) / 2, rec.Top, W, rec.Height);
                        }
                        FPDFFile.Canvas.DrawImage(rec, stream, 0, false, false, intimageindex);
                        break;

                    case ImageDrawStyleType.Tile:
                    case ImageDrawStyleType.Tiledpi:
                        FPDFFile.Canvas.DrawImage(rec, stream, PDFFile.CONS_PDFRES, true, true, intimageindex);
                        break;
                    }
                }
                break;
            }
        }