Example #1
0
        override protected void DoPrint(PrintOut adriver, int aposx, int aposy,
                                        int newwidth, int newheight, MetaFile metafile, Point MaxExtent,
                                        ref bool PartialPrint)
        {
            int aalign;

            base.DoPrint(adriver, aposx, aposy, newwidth, newheight,
                         metafile, MaxExtent, ref PartialPrint);
            MetaPage       apage   = metafile.Pages[metafile.CurrentPage];
            MetaObjectText metaobj = new MetaObjectText();

            metaobj.TextP        = apage.AddString(Text);
            metaobj.TextS        = Text.Length;
            metaobj.LFontNameP   = apage.AddString(LFontName);
            metaobj.LFontNameS   = LFontName.Length;
            metaobj.WFontNameP   = apage.AddString(WFontName);
            metaobj.WFontNameS   = WFontName.Length;
            metaobj.FontSize     = FontSize;
            metaobj.BackColor    = BackColor;
            metaobj.FontRotation = FontRotation;
            metaobj.FontStyle    = (short)FontStyle;
            metaobj.FontColor    = FontColor;
            metaobj.Type1Font    = Type1Font;
            metaobj.CutText      = CutText;
            metaobj.Transparent  = Transparent;
            metaobj.WordWrap     = WordWrap;
            metaobj.Top          = aposy;
            metaobj.Left         = aposx;
            metaobj.Width        = PrintWidth;
            metaobj.Height       = PrintHeight;
            metaobj.RightToLeft  = RightToLeft;
            metaobj.PrintStep    = PrintStep;
            aalign = PrintAlignment | VPrintAlignment;
            if (SingleLine)
            {
                aalign = aalign | MetaFile.AlignmentFlags_SingleLine;
            }
            metaobj.Alignment = aalign;
            apage.Objects.Add(metaobj);
        }
Example #2
0
        public static void PrintObject(object sh, MetaPage page, MetaObject obj, int dpix,
                                       int dpiy, SortedList rows, SortedList columns,
                                       string FontName, int FontSize, int rowinit, double Precision)
        {
            const int xlHAlignCenter = -4108;
            const int xlHAlignLeft   = -4131;
            const int xlHAlignRight  = -4152;
            string    atext;
            int       arow;
            int       acolumn;
            bool      isanumber;
            FontStyle astyle;
            Color     acolor;
            bool      isadate;

            string topstring  = ((double)obj.Top / Precision).ToString("0000000000");
            string leftstring = ((double)obj.Left / Precision).ToString("0000000000");

            arow    = rows.IndexOfKey(topstring) + 1 + rowinit;
            acolumn = columns.IndexOfKey(leftstring) + 1;
            if (acolumn < 1)
            {
                acolumn = 1;
            }
            if (arow < 1)
            {
                arow = 1;
            }
            object cells = sh.GetType().InvokeMember("Cells",
                                                     System.Reflection.BindingFlags.GetProperty, null, sh, null);

            object[] param2 = new object[2];
            param2[0] = arow;
            param2[1] = acolumn;
            object[] param1 = new object[1];
            object   cell   = cells.GetType().InvokeMember("Item",
                                                           System.Reflection.BindingFlags.GetProperty, null, cells, param2);

            switch (obj.MetaType)
            {
            case MetaObjectType.Text:
                MetaObjectText objt = (MetaObjectText)obj;
                atext = page.GetText(objt);

                // If it's a number
                bool assigned = false;
                isanumber = DoubleUtil.IsNumeric(atext, System.Globalization.NumberStyles.Any);
                if (isanumber)
                {
                    param1[0] = System.Convert.ToDouble(atext);
                    cell.GetType().InvokeMember("Value",
                                                System.Reflection.BindingFlags.SetProperty,
                                                null, cell, param1);
                    assigned = true;
                }
                else
                {
                    DateTime mydate;
                    isadate = DateUtil.IsDateTime(atext, out mydate);
                    if (isadate)
                    {
                        param1[0] = mydate;
                        cell.GetType().InvokeMember("Value",
                                                    System.Reflection.BindingFlags.SetProperty,
                                                    null, cell, param1);
                        assigned = true;
                    }
                    else
                    if (atext.Length > 0)
                    {
                        if (atext[0] == '=')
                        {
                            atext = "'" + atext;
                        }
                        param1[0] = atext;
                        cell.GetType().InvokeMember("Value",
                                                    System.Reflection.BindingFlags.SetProperty,
                                                    null, cell, param1);
                        assigned = true;
                    }
                }
                if (assigned)
                {
                    object shfont = cell.GetType().InvokeMember("Font",
                                                                System.Reflection.BindingFlags.GetProperty,
                                                                null, cell, null);
                    string nfontname = page.GetWFontNameText(objt);
                    if (FontName != nfontname)
                    {
                        param1[0] = nfontname;
                        shfont.GetType().InvokeMember("Name",
                                                      System.Reflection.BindingFlags.SetProperty,
                                                      null, shfont, param1);
                    }
                    if (objt.FontSize != FontSize)
                    {
                        param1[0] = objt.FontSize;
                        shfont.GetType().InvokeMember("Size",
                                                      System.Reflection.BindingFlags.SetProperty,
                                                      null, shfont, param1);
                    }
                    acolor = GraphicUtils.ColorFromInteger(objt.FontColor);
                    if (acolor.ToArgb() != Color.Black.ToArgb())
                    {
                        param1[0] = objt.FontColor;
                        shfont.GetType().InvokeMember("Color",
                                                      System.Reflection.BindingFlags.SetProperty,
                                                      null, shfont, param1);
                    }
                    astyle = GraphicUtils.FontStyleFromInteger(objt.FontStyle);
                    if ((astyle & FontStyle.Italic) > 0)
                    {
                        param1[0] = true;
                        shfont.GetType().InvokeMember("Italic",
                                                      System.Reflection.BindingFlags.SetProperty,
                                                      null, shfont, param1);
                    }
                    if ((astyle & FontStyle.Bold) > 0)
                    {
                        param1[0] = true;
                        shfont.GetType().InvokeMember("Bold",
                                                      System.Reflection.BindingFlags.SetProperty,
                                                      null, shfont, param1);
                    }
                    if ((astyle & FontStyle.Underline) > 0)
                    {
                        param1[0] = true;
                        shfont.GetType().InvokeMember("Underline",
                                                      System.Reflection.BindingFlags.SetProperty,
                                                      null, shfont, param1);
                    }
                    if ((astyle & FontStyle.Strikeout) > 0)
                    {
                        param1[0] = true;
                        shfont.GetType().InvokeMember("Strikethrough",
                                                      System.Reflection.BindingFlags.SetProperty,
                                                      null, shfont, param1);
                    }
                    // Font rotation not possible
                    if ((objt.Alignment & MetaFile.AlignmentFlags_AlignHCenter) > 0)
                    {
                        param1[0] = xlHAlignCenter;
                        cell.GetType().InvokeMember("HorizontalAlignment",
                                                    System.Reflection.BindingFlags.SetProperty,
                                                    null, cell, param1);
                    }
                    // Multiline not supported
                    //    if (obj.AlignMent AND AlignmentFlags_SingleLine)=0 then
                    //     sh.Cells.item[arow,acolumn].Multiline:=true;
                    if ((objt.Alignment & MetaFile.AlignmentFlags_AlignLeft) > 0)
                    {
                        if (isanumber)
                        {
                            param1[0] = xlHAlignLeft;
                            cell.GetType().InvokeMember("HorizontalAlignment",
                                                        System.Reflection.BindingFlags.SetProperty,
                                                        null, cell, param1);
                        }
                    }
                    if ((objt.Alignment & MetaFile.AlignmentFlags_AlignRight) > 0)
                    {
                        if (!isanumber)
                        {
                            param1[0] = xlHAlignRight;
                            cell.GetType().InvokeMember("HorizontalAlignment",
                                                        System.Reflection.BindingFlags.SetProperty,
                                                        null, cell, param1);
                        }
                    }
                    // Word wrap not supported
                    //    if obj.WordWrap then
                    //     sh.Cells.item[arow,acolumn].WordWrap:=True;
                    //    if Not obj.CutText then
                    //     aalign:=aalign or DT_NOCLIP;
                    //    if obj.RightToLeft then
                    //     aalign:=aalign or DT_RTLREADING;
                    // In office 97, not supported
                    //    if Not obj.Transparent then
                    //     sh.Cells.Item[arow,acolumn].Color:=CLXColorToVCLColor(obj.BackColor);
                }
                break;
            }
        }
Example #3
0
        /// <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;
            }
        }
Example #4
0
        override protected void DoPrint(PrintOut adriver, int aposx, int aposy,
                                        int newwidth, int newheight, MetaFile metafile, Point MaxExtent,
                                        ref bool PartialPrint)
        {
            int    newposition;
            string avalue;

            base.DoPrint(adriver, aposx, aposy, newwidth, newheight,
                         metafile, MaxExtent, ref PartialPrint);
            LastMetaIndex = -1;

            TextObjectStruct TextObj = GetTextObject();

            if (PrintOnlyOne)
            {
                if (FOldString == TextObj.Text)
                {
                    return;
                }
            }
            FOldString = TextObj.Text;
            if (MultiPage || FForcedPartial)
            {
                MaxExtent.X = PrintWidth;
                newposition = MetaFile.CalcTextExtent(Report.Driver, MaxExtent, TextObj);
                if (newposition < TextObj.Text.Length)
                {
                    if (!FIsPartial)
                    {
                        PartialPos = 0;
                    }
                    FIsPartial   = true;
                    PartialPrint = true;
                    PartialPos   = PartialPos + newposition;
                    TextObj.Text = TextObj.Text.Substring(0, newposition);
                }
                else
                {
                    FIsPartial     = false;
                    FForcedPartial = false;
                }
            }
            MetaPage       apage = metafile.Pages[metafile.CurrentPage];
            MetaObjectText aobj  = new MetaObjectText();

            aobj.MetaType     = MetaObjectType.Text;
            aobj.Left         = aposx;
            aobj.Top          = aposy;
            aobj.Width        = PrintWidth;
            aobj.Height       = PrintHeight;
            aobj.Alignment    = TextObj.Alignment;
            aobj.PrintStep    = PrintStep;
            aobj.BackColor    = BackColor;
            aobj.Transparent  = Transparent;
            aobj.CutText      = CutText;
            aobj.FontColor    = FontColor;
            aobj.FontRotation = FontRotation;
            aobj.Type1Font    = Type1Font;
            aobj.FontSize     = FontSize;
            aobj.FontStyle    = (short)FontStyle;
            aobj.TextP        = apage.AddString(TextObj.Text);
            aobj.TextS        = TextObj.Text.Length;
            aobj.WordWrap     = WordWrap;
            aobj.LFontNameP   = apage.AddString(LFontName);
            aobj.LFontNameS   = LFontName.Length;
            aobj.WFontNameP   = apage.AddString(WFontName);
            aobj.WFontNameS   = WFontName.Length;
            apage.Objects.Add(aobj);

            LastMetaIndex = metafile.Pages[metafile.CurrentPage].Objects.Count - 1;
            // Is Total pages variable?
            if (IsPageCount)
            {
                Report.AddTotalPagesItem(metafile.CurrentPage, metafile.Pages[metafile.CurrentPage].Objects.Count - 1, DisplayFormat);
            }
            if (ExportValue.VarType != VariantType.Null)
            {
                try
                {
                    avalue = FExportValue.ToString(ExportDisplayFormat, ParamType.Unknown, true);

                    MetaObjectExport nobj = new MetaObjectExport();
                    nobj.MetaType  = MetaObjectType.Export;
                    nobj.Left      = aposx;
                    nobj.Top       = aposy;
                    nobj.Width     = PrintWidth;
                    nobj.Height    = PrintHeight;
                    nobj.TextExpP  = apage.AddString(avalue);
                    nobj.TextExpS  = avalue.Length;
                    nobj.Line      = ExportLine;
                    nobj.Position  = ExportPosition;
                    nobj.DoNewLine = ExportDoNewLine;
                    nobj.Size      = ExportSize;
                    apage.Objects.Add(nobj);
                }
                catch (Exception E)
                {
                    throw new ReportException(E.Message + "Expression-" + Name + " ExportDisplayFormat",
                                              this, "ExportDisplayFormat");
                }
            }
        }