Ejemplo n.º 1
0
			internal PageImage PgImage;	// When ConstantImage is true this will save the PageImage for reuse
			internal WorkClass()
			{
				PgImage=null;
			}
Ejemplo n.º 2
0
		override internal void RunPage(Pages pgs, Row row)
		{
			Report r = pgs.Report;
            bool bHidden = IsHidden(r, row);

			WorkClass wc = GetWC(r);
			string mtype=null; 
			Stream strm=null;
			System.Drawing.Image im=null;

			SetPagePositionBegin(pgs);
            if (bHidden)
            {
                PageImage pi = new PageImage(ImageFormat.Jpeg, null, 0, 0);
                this.SetPagePositionAndStyle(r, pi, row);
                SetPagePositionEnd(pgs, pi.Y + pi.H);
                return;
            }

			if (wc.PgImage != null)
			{	// have we already generated this one
				// reuse most of the work; only position will likely change
				PageImage pi = new PageImage(wc.PgImage.ImgFormat, wc.PgImage.ImageData, wc.PgImage.SamplesW, wc.PgImage.SamplesH);
				pi.Name = wc.PgImage.Name;				// this is name it will be shared under
				pi.Sizing = this._Sizing;
				this.SetPagePositionAndStyle(r, pi, row);
				pgs.CurrentPage.AddObject(pi);
                SetPagePositionEnd(pgs, pi.Y + pi.H);
				return;
			}

			try 
			{
				strm = GetImageStream(r, row, out mtype);
                if (strm == null)
                {
                    r.rl.LogError(4, string.Format("Unable to load image {0}.", this.Name.Nm));
                    return;
                }
				im = System.Drawing.Image.FromStream(strm);
				int height = im.Height;
				int width = im.Width;
				MemoryStream ostrm = new MemoryStream();
				strm.Position = 0;
				ImageFormat imf;
				switch(mtype.ToLower())
				{	
					case "image/jpeg" :
						imf = ImageFormat.Jpeg;
						CopyStream(strm, ostrm);
						break;
					case "image/png":
						imf = ImageFormat.Png;
						CopyStream(strm, ostrm);
						break;
					default: // from old code where all images convert to jpeg, i don't know why. May be need delete it and add all support formats.
						imf = ImageFormat.Jpeg;
						System.Drawing.Imaging.ImageCodecInfo[] info;
						info = ImageCodecInfo.GetImageEncoders();
						EncoderParameters encoderParameters;
						encoderParameters = new EncoderParameters(1);
						encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, ImageQualityManager.EmbeddedImageQuality);
						System.Drawing.Imaging.ImageCodecInfo codec = null;
						for (int i = 0; i < info.Length; i++)
						{
							if (info[i].FormatDescription == "JPEG")
							{
								codec = info[i];
								break;
							}
						}
						im.Save(ostrm, codec, encoderParameters);
						break;
				}

				byte[] ba = ostrm.ToArray();
				ostrm.Close();
				PageImage pi = new PageImage(imf, ba, width, height);
				pi.Sizing = this._Sizing;
				this.SetPagePositionAndStyle(r, pi, row);

				pgs.CurrentPage.AddObject(pi);
				if (_ConstantImage)
				{
					wc.PgImage = pi;
					// create unique name; PDF generation uses this to optimize the saving of the image only once
					pi.Name = "pi" + Interlocked.Increment(ref Parser.Counter).ToString();	// create unique name
				}

                SetPagePositionEnd(pgs, pi.Y + pi.H);
            }
			catch (Exception e)
			{	
				// image failed to load, continue processing
				r.rl.LogError(4, "Image load failed.  " + e.Message);
			}
			finally
			{
				if (strm != null)
					strm.Close();
				if (im != null)
					im.Dispose();
			}
			return;
		}
Ejemplo n.º 3
0
        private void SaveAsPdf(Report report, OneFileStreamGen sg)
        {
            Pages pgs = report.BuildPages();
            FileStream strm=null;
            System.Drawing.Image im=null;

            // Handle any parameters
            float x = 0;		// x position of image
            float y = 0;		// y position of image
            float h = 0;		// height of image
            float w = 0;		// width position of image
            string fname=null;
            int index = _StampInfo.LastIndexOf('?');
            bool bClip=false;	// we force clip if either height or width not specified

            if (index >= 0)
            {
                // Get all the arguments for sizing the image
                ListDictionary ld = this.GetParameters(_StampInfo.Substring(index+1));
                fname = _StampInfo.Substring(0, index);
                string ws = (string)ld["x"];
                x = Size(ws);
                ws = (string)ld["y"];
                y = Size(ws);
                ws = (string)ld["h"];
                if (ws == null)
                {
                    bClip = true;
                    ws = "12in";	// just give it a big value
                }
                h = Size(ws);
                ws = (string)ld["w"];
                if (ws == null)
                {
                    bClip = true;
                    ws = "12in";	// just give it a big value
                }
                w = Size(ws);
            }
            else
            {
                fname = _StampInfo;
                // force size
                bClip = true;
                h = Size("12in");
                w = Size("12in");
            }

            // Stamp the first page
            foreach (Page p in pgs)		// we loop then break after obtaining one
            {
                try
                {
                    strm = new FileStream(fname, System.IO.FileMode.Open, FileAccess.Read);
                    im = System.Drawing.Image.FromStream(strm);
                    int height = im.Height;
                    int width = im.Width;
                    MemoryStream ostrm = new MemoryStream();

                    /* Replaced with high quality JPEG encoder
                      * 06122007AJM */
             					ImageFormat imf = ImageFormat.Jpeg;
             					//im.Save(ostrm, imf);
                    System.Drawing.Imaging.ImageCodecInfo[] info;
                    info = ImageCodecInfo.GetImageEncoders();
                    EncoderParameters encoderParameters;
                    encoderParameters = new EncoderParameters(1);
                    encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, 100L);
                    System.Drawing.Imaging.ImageCodecInfo codec = null;
                    for (int i = 0; i < info.Length; i++)
                    {
                        if (info[i].FormatDescription == "JPEG")
                        {
                            codec = info[i];
                            break;
                        }
                    }
                    im.Save(ostrm, codec, encoderParameters);
                    // end change
                    byte[] ba = ostrm.ToArray();
                    ostrm.Close();
                    PageImage pi = new PageImage(imf, ba, width, height);
                    pi.SI = new StyleInfo();			// defaults are ok; don't want border, etc
                    // Set location, height and width
                    pi.X = x;
                    pi.Y = y;
                    pi.H = h;
                    pi.W = w;
                    pi.Sizing = bClip? ImageSizingEnum.Clip: ImageSizingEnum.FitProportional;

                    p.InsertObject(pi);
                }
                catch (Exception e)
                {
                    // image failed to load, continue processing
                    Console.WriteLine("Stamping image failed.  {0}", e.Message);
                }
                finally
                {
                    if (strm != null)
                        strm.Close();
                    if (im != null)
                        im.Dispose();
                }
                break;			// only stamp the first page
            }

            // Now create the PDF
            report.RunRenderPdf(sg, pgs);
        }
Ejemplo n.º 4
0
        private void DrawImage(PageImage pi, StringBuilder sb, Rectangle r)
        {
            string name = GetName(pi);
            _Images.Add(name, pi);              // TODO optimize this so that common images are only one URL (see PDF generation)

            StyleInfo si = pi.SI;

            string stretch;
            switch (pi.Sizing)
            {
                case ImageSizingEnum.AutoSize:
                    stretch = "None";
                    break;
                case ImageSizingEnum.Clip:
                    stretch = "None";
                    break;
                case ImageSizingEnum.FitProportional:
                    stretch = "Uniform";
                    break;
                case ImageSizingEnum.Fit:
                default:
                    stretch = "Fill";
                    break;
            }
            Rectangle r2 = new Rectangle(r.Left + PixelsX(si.PaddingLeft),
                                           r.Top + PixelsY(si.PaddingTop),
                                           r.Width - PixelsX(si.PaddingLeft - si.PaddingRight),
                                           r.Height - PixelsY(si.PaddingTop - si.PaddingBottom));

            string url;
            if (_ZipStream != null)
            {
                url = ImageHelper.SaveZipImage(_ZipImages, _ZipStream, pi);
            }
            else
            {
                url = ImageHelper.SaveImage(this.MapPathSecure(this.ImageDirectory), pi.ImageData, this.Context.Cache);

                url = this.ImageDirectory + "/" + url;
            }
            sb.AppendFormat("<Image Source=\"{0}\" Stretch=\"{1}\" " +
                            "Canvas.Left=\"{2}\" Canvas.Top=\"{3}\" Width=\"{4}\" Height=\"{5}\"/>", 
                url, stretch, r2.Left, r2.Top, r2.Width, r2.Height);
            
//            sb.Append("<Image Source=\"/dscrnshot1tn.jpg?rs:url=JustAnImage.rdl&rs:pageno=1&rs:image=n1\" Stretch=\"None\" Canvas.Left=\"260\" Canvas.Top=\"85\" Width=\"211\" Height=\"71\"/>");

        }
Ejemplo n.º 5
0
        private PageImage BuildImage(Graphics g, string token, StyleInfo oldsi, PageText model)
        {
            PageTextHtmlCmdLexer hc = new PageTextHtmlCmdLexer(token.Substring(4));
            Hashtable ht = hc.Lex();

            string src = (string)ht["src"];
            if (src == null || src.Length < 1)
                return null;

            string alt = (string)ht["alt"];

            string height = (string)ht["height"];
            string width = (string)ht["width"];
            string align = (string)ht["align"];

            Stream strm = null;
            System.Drawing.Image im = null;
            PageImage pi = null;
            try
            {
                // Obtain the image stream
                if (src.StartsWith("http:") ||
                    src.StartsWith("file:") ||
                    src.StartsWith("https:"))
                {
                    WebRequest wreq = WebRequest.Create(src);
                    WebResponse wres = wreq.GetResponse();
                    strm = wres.GetResponseStream();
                }
                else
                    strm = new FileStream(src, System.IO.FileMode.Open, FileAccess.Read);

                im = System.Drawing.Image.FromStream(strm);
                int h = im.Height;
                int w = im.Width;
                MemoryStream ostrm = new MemoryStream();
                ImageFormat imf;
                imf = ImageFormat.Jpeg;
                im.Save(ostrm, imf);
                byte[] ba = ostrm.ToArray();
                ostrm.Close();
                pi = new PageImage(imf, ba, w, h);
                pi.AllowSelect = false;
                pi.Page = this.Page;
                pi.HyperLink = model.HyperLink;
                pi.Tooltip = alt == null ? model.Tooltip : alt;
                pi.X = 0;
                pi.Y = 0;

                pi.W = RSize.PointsFromPixels(g, width != null? Convert.ToInt32(width): w);
                pi.H = RSize.PointsFromPixels(g, height != null? Convert.ToInt32(height): h);
                pi.SI = new StyleInfo();
            }
            catch
            {
                pi = null;
            }
            finally
            {
                if (strm != null)
                    strm.Close();
                if (im != null)
                    im.Dispose();
            }

            return pi;
        }
Ejemplo n.º 6
0
        private void DrawImageBackground(PageImage pi, StyleInfo si, Graphics g, RectangleF r)
        {
            Stream strm = null;
            System.Drawing.Image im = null;
            try
            {
                strm = new MemoryStream(pi.ImageData);
                im = System.Drawing.Image.FromStream(strm);

                // http://www.fyireporting.com/forum/viewtopic.php?t=892
                //A.S.> convert pt to px if needed(when printing we need px, when draw preview - pt)

                RectangleF r2;
                if (g.PageUnit == GraphicsUnit.Pixel)
                {
                    r2 = new RectangleF(r.Left + (si.PaddingLeft * g.DpiX) / 72,
                    r.Top + (si.PaddingTop * g.DpiX) / 72,
                    r.Width - ((si.PaddingLeft + si.PaddingRight) * g.DpiX) / 72,
                    r.Height - ((si.PaddingTop + si.PaddingBottom) * g.DpiX) / 72);
                }
                else
                {
                    // adjust drawing rectangle based on padding
                    r2 = new RectangleF(r.Left + si.PaddingLeft,
                    r.Top + si.PaddingTop,
                    r.Width - si.PaddingLeft - si.PaddingRight,
                    r.Height - si.PaddingTop - si.PaddingBottom);
                }

                int repeatX = 0;
                int repeatY = 0;
                switch (pi.Repeat)
                {
                    case ImageRepeat.Repeat:
                        repeatX = (int)Math.Floor(r2.Width / pi.SamplesW);
                        repeatY = (int)Math.Floor(r2.Height / pi.SamplesH);
                        break;
                    case ImageRepeat.RepeatX:
                        repeatX = (int)Math.Floor(r2.Width / pi.SamplesW);
                        repeatY = 1;
                        break;
                    case ImageRepeat.RepeatY:
                        repeatY = (int)Math.Floor(r2.Height / pi.SamplesH);
                        repeatX = 1;
                        break;
                    case ImageRepeat.NoRepeat:
                    default:
                        repeatX = repeatY = 1;
                        break;
                }

                //make sure the image is drawn at least 1 times
                repeatX = Math.Max(repeatX, 1);
                repeatY = Math.Max(repeatY, 1);

                float startX = r2.Left;
                float startY = r2.Top;

                Region saveRegion = g.Clip;
                Region clipRegion = new Region(g.Clip.GetRegionData());
                clipRegion.Intersect(r2);
                g.Clip = clipRegion;

                for (int i = 0; i < repeatX; i++)
                {
                    for (int j = 0; j < repeatY; j++)
                    {
                        float currX = startX + i * pi.SamplesW;
                        float currY = startY + j * pi.SamplesH;
                        g.DrawImage(im, new RectangleF(currX, currY, pi.SamplesW, pi.SamplesH));
                    }
                }
                g.Clip = saveRegion;
            }
            finally
            {
                if (strm != null)
                    strm.Close();
                if (im != null)
                    im.Dispose();
            }
        }
Ejemplo n.º 7
0
		override internal void RunPage(Pages pgs, Row row)
		{
			Report rpt = pgs.Report;

			if (IsHidden(pgs.Report, row))
				return;

			_ChartMatrix.RunReset(rpt);
			Rows _Data = GetFilteredData(rpt, row);
			SetMyData(rpt, _Data);

			SetPagePositionBegin(pgs);

			if (!AnyRowsPage(pgs, _Data))		// if no rows return
				return;						//   nothing left to do

			// Build the Chart bitmap, along with data regions
			Page p = pgs.CurrentPage;
			ChartBase cb=null;
			try
			{
				cb = RunChartBuild(rpt, row);					// Build the chart
				System.Drawing.Image im = cb.Image(rpt);	// Grab the image
				int height = im.Height;							// save height and width
				int width = im.Width;

				MemoryStream ostrm = new MemoryStream();
				im.Save(ostrm, IMAGEFORMAT);	// generate a jpeg   TODO: get png to work with pdf

				byte[] ba = ostrm.ToArray();
				ostrm.Close();
				PageImage pi = new PageImage(IMAGEFORMAT, ba, width, height);	// Create an image
				
				RunPageRegionBegin(pgs);

				SetPagePositionAndStyle(rpt, pi, row);
				pi.SI.BackgroundImage = null;	// chart already has the background image

				if (pgs.CurrentPage.YOffset + pi.Y + pi.H >= pgs.BottomOfPage && !pgs.CurrentPage.IsEmpty())
				{	// force page break if it doesn't fit on the page
					pgs.NextOrNew();
					pgs.CurrentPage.YOffset = OwnerReport.TopOfPage;
					if (this.YParents != null)
						pi.Y = 0;
				}

				p = pgs.CurrentPage;
				
				p.AddObject(pi);	// Put image onto the current page

				RunPageRegionEnd(pgs);

				if (!this.PageBreakAtEnd && !IsTableOrMatrixCell(rpt))
				{
					float newY = pi.Y + pi.H;
					p.YOffset += newY;	// bump the y location
				}
                SetPagePositionEnd(pgs, pi.Y + pi.H);
            }
			catch (Exception ex)
			{
				rpt.rl.LogError(8, string.Format("Exception in Chart handling.\n{0}\n{1}", ex.Message, ex.StackTrace));
			}
			finally
			{
				if (cb != null)
					cb.Dispose();
			}

            return;
		}
Ejemplo n.º 8
0
        private void ProcessPage(Graphics g, IEnumerable p)
        {
            foreach (PageItem pi in p)
            {
                if (pi is PageTextHtml)
                {   // PageTextHtml is actually a composite object (just like a page)
                    ProcessHtml(pi as PageTextHtml, g);
                    continue;
                }

                if (pi is PageLine)
                {
                    PageLine pl = pi as PageLine;
                    DrawLine(
                        pl.SI.BColorLeft, pl.SI.BStyleLeft, pl.SI.BWidthLeft,
                        g, PixelsX(pl.X), PixelsY(pl.Y), PixelsX(pl.X2), PixelsY(pl.Y2)
                        );
                    continue;
                }

                RectangleF rect = new RectangleF(PixelsX(pi.X), PixelsY(pi.Y), PixelsX(pi.W), PixelsY(pi.H));

                if (pi.SI.BackgroundImage != null)
                {   // put out any background image
                    PageImage i = pi.SI.BackgroundImage;
                    DrawImage(i, g, rect);
                }

                if (pi is PageText)
                {
                    PageText pt = pi as PageText;
                    DrawString(pt, g, rect);
                }
                else if (pi is PageImage)
                {
                    PageImage i = pi as PageImage;
                    DrawImage(i, g, rect);
                }
                else if (pi is PageRectangle)
                {
                    this.DrawBackground(g, rect, pi.SI);
                }
                else if (pi is PageEllipse)
                {
                    PageEllipse pe = pi as PageEllipse;
                    DrawEllipse(pe, g, rect);
                }
                else if (pi is PagePie)
                {
                    PagePie pp = pi as PagePie;
                    DrawPie(pp, g, rect);
                }
                else if (pi is PagePolygon)
                {
                    PagePolygon ppo = pi as PagePolygon;
                    FillPolygon(ppo, g, rect);
                }
                else if (pi is PageCurve)
                {
                    PageCurve pc = pi as PageCurve;
                    DrawCurve(pc.SI.BColorLeft, pc.SI.BStyleLeft, pc.SI.BWidthLeft,
                              g, pc.Points, pc.Offset, pc.Tension);
                }

                DrawBorder(pi, g, rect);
            }
        }
Ejemplo n.º 9
0
        private void DrawImageSized(PageImage pi, System.Drawing.Image im, System.Drawing.Graphics g, System.Drawing.RectangleF r)
        {
            float     height, width;  // some work variables
            StyleInfo si = pi.SI;

            // adjust drawing rectangle based on padding
            System.Drawing.RectangleF r2 = new System.Drawing.RectangleF(r.Left + PixelsX(si.PaddingLeft),
                                                                         r.Top + PixelsY(si.PaddingTop),
                                                                         r.Width - PixelsX(si.PaddingLeft + si.PaddingRight),
                                                                         r.Height - PixelsY(si.PaddingTop + si.PaddingBottom));

            System.Drawing.Rectangle ir;   // int work rectangle
            switch (pi.Sizing)
            {
            case ImageSizingEnum.AutoSize:
                // Note: GDI+ will stretch an image when you only provide
                //  the left/top coordinates.  This seems pretty stupid since
                //  it results in the image being out of focus even though
                //  you don't want the image resized.
                if (g.DpiX == im.HorizontalResolution &&
                    g.DpiY == im.VerticalResolution)
                {
                    ir = new System.Drawing.Rectangle(Convert.ToInt32(r2.Left), Convert.ToInt32(r2.Top),
                                                      im.Width, im.Height);
                }
                else
                {
                    ir = new System.Drawing.Rectangle(Convert.ToInt32(r2.Left), Convert.ToInt32(r2.Top),
                                                      Convert.ToInt32(r2.Width), Convert.ToInt32(r2.Height));
                }
                g.DrawImage(im, ir);

                break;

            case ImageSizingEnum.Clip:
                Region saveRegion = g.Clip;
                Region clipRegion = new Region(g.Clip.GetRegionData());
                clipRegion.Intersect(r2);
                g.Clip = clipRegion;
                if (g.DpiX == im.HorizontalResolution &&
                    g.DpiY == im.VerticalResolution)
                {
                    ir = new System.Drawing.Rectangle(Convert.ToInt32(r2.Left), Convert.ToInt32(r2.Top),
                                                      im.Width, im.Height);
                }
                else
                {
                    ir = new System.Drawing.Rectangle(Convert.ToInt32(r2.Left), Convert.ToInt32(r2.Top),
                                                      Convert.ToInt32(r2.Width), Convert.ToInt32(r2.Height));
                }
                g.DrawImage(im, ir);
                g.Clip = saveRegion;
                break;

            case ImageSizingEnum.FitProportional:
                float ratioIm = (float)im.Height / (float)im.Width;
                float ratioR  = r2.Height / r2.Width;
                height = r2.Height;
                width  = r2.Width;
                if (ratioIm > ratioR)
                {       // this means the rectangle width must be corrected
                    width = height * (1 / ratioIm);
                }
                else if (ratioIm < ratioR)
                {       // this means the ractangle height must be corrected
                    height = width * ratioIm;
                }
                r2 = new RectangleF(r2.X, r2.Y, width, height);
                g.DrawImage(im, r2);
                break;

            case ImageSizingEnum.Fit:
            default:
                g.DrawImage(im, r2);
                break;
            }
            return;
        }
Ejemplo n.º 10
0
        // render all the objects in a page in PDF
        private void ProcessPage(Pages pgs, IEnumerable items)
        {
            foreach (PageItem pi in items)
            {
                if (pi.SI.BackgroundImage != null)
                {       // put out any background image
                    PageImage bgImg = pi.SI.BackgroundImage;
                    //					elements.AddImage(images, i.Name, content.objectNum, i.SI, i.ImgFormat,
                    //						pi.X, pi.Y, pi.W, pi.H, i.ImageData,i.SamplesW, i.SamplesH, null);
                    //Duc Phan modified 10 Dec, 2007 to support on background image
                    float imW     = Measurement.PointsFromPixels(bgImg.SamplesW, pgs.G.DpiX);
                    float imH     = Measurement.PointsFromPixels(bgImg.SamplesH, pgs.G.DpiY);
                    int   repeatX = 0;
                    int   repeatY = 0;
                    float itemW   = pi.W - (pi.SI.PaddingLeft + pi.SI.PaddingRight);
                    float itemH   = pi.H - (pi.SI.PaddingTop + pi.SI.PaddingBottom);
                    switch (bgImg.Repeat)
                    {
                    case ImageRepeat.Repeat:
                        repeatX = (int)Math.Floor(itemW / imW);
                        repeatY = (int)Math.Floor(itemH / imH);
                        break;

                    case ImageRepeat.RepeatX:
                        repeatX = (int)Math.Floor(itemW / imW);
                        repeatY = 1;
                        break;

                    case ImageRepeat.RepeatY:
                        repeatY = (int)Math.Floor(itemH / imH);
                        repeatX = 1;
                        break;

                    case ImageRepeat.NoRepeat:
                    default:
                        repeatX = repeatY = 1;
                        break;
                    }

                    //make sure the image is drawn at least 1 times
                    repeatX = Math.Max(repeatX, 1);
                    repeatY = Math.Max(repeatY, 1);

                    float currX  = pi.X + pi.SI.PaddingLeft;
                    float currY  = pi.Y + pi.SI.PaddingTop;
                    float startX = currX;
                    float startY = currY;
                    for (int i = 0; i < repeatX; i++)
                    {
                        for (int j = 0; j < repeatY; j++)
                        {
                            currX = startX + i * imW;
                            currY = startY + j * imH;



                            AddImage(bgImg.Name, bgImg.SI, bgImg.ImgFormat,
                                     currX, currY, imW, imH, RectangleF.Empty, bgImg.ImageData, bgImg.SamplesW, bgImg.SamplesH, null, pi.Tooltip);
                        }
                    }
                }

                if (pi is PageTextHtml)
                {
                    PageTextHtml pth = pi as PageTextHtml;
                    pth.Build(pgs.G);
                    ProcessPage(pgs, pth);
                    continue;
                }

                if (pi is PageText)
                {
                    PageText pt = pi as PageText;
                    float[]  textwidth;
                    string[] sa = MeasureString(pt, pgs.G, out textwidth);


                    AddText(pt.X, pt.Y, pt.H, pt.W, sa, pt.SI, textwidth, pt.CanGrow, pt.HyperLink, pt.NoClip, pt.Tooltip);

                    if (pt.Bookmark != null)
                    {
                        AddBookmark(pt);
                    }
                    continue;
                }

                if (pi is PageLine)
                {
                    PageLine pl = pi as PageLine;
                    AddLine(pl.X, pl.Y, pl.X2, pl.Y2, pl.SI);
                    continue;
                }

                if (pi is PageEllipse)
                {
                    PageEllipse pe = pi as PageEllipse;
                    AddEllipse(pe.X, pe.Y, pe.H, pe.W, pe.SI, pe.HyperLink);
                    continue;
                }



                if (pi is PageImage)
                {
                    PageImage i = pi as PageImage;

                    //Duc Phan added 20 Dec, 2007 to support sized image
                    RectangleF r2 = new RectangleF(i.X + i.SI.PaddingLeft, i.Y + i.SI.PaddingTop, i.W - i.SI.PaddingLeft - i.SI.PaddingRight, i.H - i.SI.PaddingTop - i.SI.PaddingBottom);

                    RectangleF adjustedRect;   // work rectangle
                    RectangleF clipRect = RectangleF.Empty;
                    switch (i.Sizing)
                    {
                    case ImageSizingEnum.AutoSize:
                        adjustedRect = new RectangleF(r2.Left, r2.Top,
                                                      r2.Width, r2.Height);
                        break;

                    case ImageSizingEnum.Clip:
                        adjustedRect = new RectangleF(r2.Left, r2.Top,
                                                      Measurement.PointsFromPixels(i.SamplesW, pgs.G.DpiX), Measurement.PointsFromPixels(i.SamplesH, pgs.G.DpiY));
                        clipRect = new RectangleF(r2.Left, r2.Top,
                                                  r2.Width, r2.Height);
                        break;

                    case ImageSizingEnum.FitProportional:
                        float height;
                        float width;
                        float ratioIm = (float)i.SamplesH / i.SamplesW;
                        float ratioR  = r2.Height / r2.Width;
                        height = r2.Height;
                        width  = r2.Width;
                        if (ratioIm > ratioR)
                        {       // this means the rectangle width must be corrected
                            width = height * (1 / ratioIm);
                        }
                        else if (ratioIm < ratioR)
                        {       // this means the rectangle height must be corrected
                            height = width * ratioIm;
                        }
                        adjustedRect = new RectangleF(r2.X, r2.Y, width, height);
                        break;

                    case ImageSizingEnum.Fit:
                    default:
                        adjustedRect = r2;
                        break;
                    }
                    if (i.ImgFormat == System.DrawingCore.Imaging.ImageFormat.Wmf || i.ImgFormat == System.DrawingCore.Imaging.ImageFormat.Emf)
                    {
                        //We dont want to add it - its already been broken down into page items;
                    }
                    else
                    {
                        AddImage(i.Name, i.SI, i.ImgFormat,
                                 adjustedRect.X, adjustedRect.Y, adjustedRect.Width, adjustedRect.Height, clipRect, i.ImageData, i.SamplesW, i.SamplesH, i.HyperLink, i.Tooltip);
                    }
                    continue;
                }

                if (pi is PageRectangle)
                {
                    PageRectangle pr = pi as PageRectangle;
                    AddRectangle(pr.X, pr.Y, pr.H, pr.W, pi.SI, pi.HyperLink, pi.Tooltip);
                    continue;
                }
                if (pi is PagePie)
                {   // TODO
                    PagePie pp = pi as PagePie;
                    //
                    AddPie(pp.X, pp.Y, pp.H, pp.W, pi.SI, pi.HyperLink, pi.Tooltip);
                    continue;
                }
                if (pi is PagePolygon)
                {
                    PagePolygon ppo = pi as PagePolygon;
                    AddPolygon(ppo.Points, pi.SI, pi.HyperLink);
                    continue;
                }
                if (pi is PageCurve)
                {
                    PageCurve pc = pi as PageCurve;
                    AddCurve(pc.Points, pi.SI);
                    continue;
                }
            }
        }
Ejemplo n.º 11
0
        internal PageImage GetPageImage(Report rpt, Row row)
        {
            string mtype = null;
            Stream strm  = null;

            System.Drawing.Image im = null;
            PageImage            pi = null;

            WorkClass wc = GetWC(rpt);

            if (wc.PgImage != null)
            {                              // have we already generated this one
                                           // reuse most of the work; only position will likely change
                pi      = new PageImage(wc.PgImage.ImgFormat, wc.PgImage.ImageData, wc.PgImage.SamplesW, wc.PgImage.SamplesH);
                pi.Name = wc.PgImage.Name; // this is name it will be shared under
                return(pi);
            }

            try
            {
                strm = GetImageStream(rpt, row, out mtype);
                if (strm == null)
                {
                    rpt.rl.LogError(4, string.Format("Unable to load image {0}.",
                                                     this._Value == null?"": this._Value.EvaluateString(rpt, row)));
                    return(null);
                }
                im = System.Drawing.Image.FromStream(strm);
                int          height = im.Height;
                int          width  = im.Width;
                MemoryStream ostrm  = new MemoryStream();
                ImageFormat  imf;
                //				if (mtype.ToLower() == "image/jpeg")    //TODO: how do we get png to work
                //					imf = ImageFormat.Jpeg;
                //				else

                imf = ImageFormat.Jpeg;
                System.Drawing.Imaging.ImageCodecInfo[] info;
                info = ImageCodecInfo.GetImageEncoders();
                EncoderParameters encoderParameters;
                encoderParameters          = new EncoderParameters(1);
                encoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, ImageQualityManager.EmbeddedImageQuality);
                System.Drawing.Imaging.ImageCodecInfo codec = null;
                for (int i = 0; i < info.Length; i++)
                {
                    if (info[i].FormatDescription == "JPEG")
                    {
                        codec = info[i];
                        break;
                    }
                }
                im.Save(ostrm, codec, encoderParameters);

                byte[] ba = ostrm.ToArray();
                ostrm.Close();
                pi    = new PageImage(imf, ba, width, height);
                pi.SI = new StyleInfo();                        // this will just default everything
                if (_BackgroundRepeat != null)
                {
                    string r = _BackgroundRepeat.EvaluateString(rpt, row).ToLower();
                    switch (r)
                    {
                    case "repeat":
                        pi.Repeat = ImageRepeat.Repeat;
                        break;

                    case "repeatx":
                        pi.Repeat = ImageRepeat.RepeatX;
                        break;

                    case "repeaty":
                        pi.Repeat = ImageRepeat.RepeatY;
                        break;

                    case "norepeat":
                    default:
                        pi.Repeat = ImageRepeat.NoRepeat;
                        break;
                    }
                }
                else
                {
                    pi.Repeat = ImageRepeat.Repeat;
                }

                if (_ConstantImage)
                {
                    wc.PgImage = pi;
                    // create unique name; PDF generation uses this to optimize the saving of the image only once
                    pi.Name = "pi" + Interlocked.Increment(ref Parser.Counter).ToString();                      // create unique name
                }
            }
            finally
            {
                if (strm != null)
                {
                    strm.Close();
                }
                if (im != null)
                {
                    im.Dispose();
                }
            }
            return(pi);
        }
Ejemplo n.º 12
0
Archivo: Image.cs Proyecto: mnisl/OD
		override internal void RunPage(Pages pgs, Row row)
		{
			Report r = pgs.Report;
			if (IsHidden(r, row))
				return;

			WorkClass wc = GetWC(r);
			string mtype=null; 
			Stream strm=null;
			System.Drawing.Image im=null;

			SetPagePositionBegin(pgs);
			if (wc.PgImage != null)
			{	// have we already generated this one
				// reuse most of the work; only position will likely change
				PageImage pi = new PageImage(wc.PgImage.ImgFormat, wc.PgImage.ImageData, wc.PgImage.SamplesW, wc.PgImage.SamplesH);
				pi.Name = wc.PgImage.Name;				// this is name it will be shared under
				pi.Sizing = this._Sizing;
				this.SetPagePositionAndStyle(r, pi, row);
				pgs.CurrentPage.AddObject(pi);
                SetPagePositionEnd(pgs, pi.Y + pi.H);
				return;
			}

			try 
			{
				strm = GetImageStream(r, row, out mtype); 
				im = System.Drawing.Image.FromStream(strm);
				int height = im.Height;
				int width = im.Width;
				MemoryStream ostrm = new MemoryStream();
				ImageFormat imf;
				//				if (mtype.ToLower() == "image/jpeg")    //TODO: how do we get png to work
				//					imf = ImageFormat.Jpeg;
				//				else
				imf = ImageFormat.Jpeg;
				im.Save(ostrm, imf);
				byte[] ba = ostrm.ToArray();
				ostrm.Close();
				PageImage pi = new PageImage(imf, ba, width, height);
				pi.Sizing = this._Sizing;
				this.SetPagePositionAndStyle(r, pi, row);

				pgs.CurrentPage.AddObject(pi);
				if (_ConstantImage)
				{
					wc.PgImage = pi;
					// create unique name; PDF generation uses this to optimize the saving of the image only once
					pi.Name = "pi" + Interlocked.Increment(ref Parser.Counter).ToString();	// create unique name
				}

                SetPagePositionEnd(pgs, pi.Y + pi.H);
            }
			catch (Exception e)
			{	
				// image failed to load, continue processing
				r.rl.LogError(4, "Image load failed.  " + e.Message);
			}
			finally
			{
				if (strm != null)
					strm.Close();
				if (im != null)
					im.Dispose();
			}
			return;
		}
Ejemplo n.º 13
0
        override internal void RunPage(Pages pgs, Row row)
        {
            Report rpt = pgs.Report;

            if (IsHidden(pgs.Report, row))
            {
                return;
            }

            _ChartMatrix.RunReset(rpt);
            Rows _Data = GetFilteredData(rpt, row);

            SetMyData(rpt, _Data);

            SetPagePositionBegin(pgs);

            if (!AnyRowsPage(pgs, _Data))                       // if no rows return
            {
                return;                                         //   nothing left to do
            }
            // Build the Chart bitmap, along with data regions
            Page      p  = pgs.CurrentPage;
            ChartBase cb = null;

            try
            {
                cb = RunChartBuild(rpt, row);                                   // Build the chart
                System.Drawing.Image im = cb.Image(rpt);                        // Grab the image
                int height = im.Height;                                         // save height and width
                int width  = im.Width;

                MemoryStream ostrm = new MemoryStream();
                im.Save(ostrm, IMAGEFORMAT);                    // generate a jpeg   TODO: get png to work with pdf

                byte[] ba = ostrm.ToArray();
                ostrm.Close();
                PageImage pi = new PageImage(IMAGEFORMAT, ba, width, height);                   // Create an image

                RunPageRegionBegin(pgs);

                SetPagePositionAndStyle(rpt, pi, row);
                pi.SI.BackgroundImage = null;                   // chart already has the background image

                if (pgs.CurrentPage.YOffset + pi.Y + pi.H >= pgs.BottomOfPage && !pgs.CurrentPage.IsEmpty())
                {                       // force page break if it doesn't fit on the page
                    pgs.NextOrNew();
                    pgs.CurrentPage.YOffset = OwnerReport.TopOfPage;
                    if (this.YParents != null)
                    {
                        pi.Y = 0;
                    }
                }

                p = pgs.CurrentPage;

                p.AddObject(pi);                        // Put image onto the current page

                RunPageRegionEnd(pgs);

                if (!this.PageBreakAtEnd && !IsTableOrMatrixCell(rpt))
                {
                    float newY = pi.Y + pi.H;
                    p.YOffset += newY;                          // bump the y location
                }
                SetPagePositionEnd(pgs, pi.Y + pi.H);
            }
            catch (Exception ex)
            {
                rpt.rl.LogError(8, string.Format("Exception in Chart handling.\n{0}\n{1}", ex.Message, ex.StackTrace));
            }
            finally
            {
                if (cb != null)
                {
                    cb.Dispose();
                }
            }

            return;
        }
Ejemplo n.º 14
0
        private void DrawImageBackground(PageImage pi, StyleInfo si, Graphics g, RectangleF r)
        {
            Stream strm = null;
            System.Drawing.Image im = null;
            try
            {
                strm = new MemoryStream(pi.ImageData);
                im = System.Drawing.Image.FromStream(strm);

                RectangleF r2 = new RectangleF(r.Left + PixelsX(si.PaddingLeft),
                    r.Top + PixelsY(si.PaddingTop),
                    r.Width - PixelsX(si.PaddingLeft + si.PaddingRight),
                    r.Height - PixelsY(si.PaddingTop + si.PaddingBottom));

                int repeatX = 0;
                int repeatY = 0;
                switch (pi.Repeat)
                {
                    case ImageRepeat.Repeat:
                        repeatX = (int)Math.Floor(r2.Width / pi.SamplesW);
                        repeatY = (int)Math.Floor(r2.Height / pi.SamplesH);
                        break;
                    case ImageRepeat.RepeatX:
                        repeatX = (int)Math.Floor(r2.Width / pi.SamplesW);
                        repeatY = 1;
                        break;
                    case ImageRepeat.RepeatY:
                        repeatY = (int)Math.Floor(r2.Height / pi.SamplesH);
                        repeatX = 1;
                        break;
                    case ImageRepeat.NoRepeat:
                    default:
                        repeatX = repeatY = 1;
                        break;
                }

                //make sure the image is drawn at least 1 times
                repeatX = Math.Max(repeatX, 1);
                repeatY = Math.Max(repeatY, 1);

                float startX = r2.Left;
                float startY = r2.Top;

                Region saveRegion = g.Clip;
                Region clipRegion = new Region(g.Clip.GetRegionData());
                clipRegion.Intersect(r2);
                g.Clip = clipRegion;

                for (int i = 0; i < repeatX; i++)
                {
                    for (int j = 0; j < repeatY; j++)
                    {
                        float currX = startX + i * pi.SamplesW;
                        float currY = startY + j * pi.SamplesH;
                        g.DrawImage(im, new RectangleF(currX, currY, pi.SamplesW, pi.SamplesH));
                    }
                }
                g.Clip = saveRegion;
            }
            finally
            {
                if (strm != null)
                    strm.Close();
                if (im != null)
                    im.Dispose();
            }
        }
Ejemplo n.º 15
0
		public int NumeralVariant;	//(Integer) The variant of the digit format to use.

		/// <summary>
		/// Constructor using all defaults for the style.
		/// </summary>
		public StyleInfo()
		{
			BColorLeft = BColorRight = BColorTop = BColorBottom = System.Drawing.Color.Black;	// (Color) Color of the bottom border
			BStyleLeft = BStyleRight = BStyleTop = BStyleBottom = BorderStyleEnum.None;
			// _BorderWdith
			BWidthLeft = BWidthRight = BWidthTop = BWidthBottom = 1;

			BackgroundColor = System.Drawing.Color.Empty;
			BackgroundGradientType = BackgroundGradientTypeEnum.None;
			BackgroundGradientEndColor = System.Drawing.Color.Empty;
			BackgroundImage = null;

			FontStyle = FontStyleEnum.Normal;
			_FontFamily = "Arial";
			FontSize = 10;
			FontWeight = FontWeightEnum.Normal;

			TextDecoration = TextDecorationEnum.None;
			TextAlign = TextAlignEnum.Left;
			VerticalAlign = VerticalAlignEnum.Top;
			Color = System.Drawing.Color.Black;
			PaddingLeft = PaddingRight = PaddingTop = PaddingBottom = 0;
			LineHeight = 0;
			Direction = DirectionEnum.LTR;
			WritingMode = WritingModeEnum.lr_tb;
			Language = "en-US";
			UnicodeBiDirectional = UnicodeBiDirectionalEnum.Normal;
			Calendar = CalendarEnum.Gregorian;
			NumeralLanguage = Language;
			NumeralVariant=1;
		}
Ejemplo n.º 16
0
        override internal void RunPage(Pages pgs, Row row)
        {
            Report r = pgs.Report;

            if (IsHidden(r, row))
            {
                return;
            }

            WorkClass wc    = GetWC(r);
            string    mtype = null;
            Stream    strm  = null;

            System.Drawing.Image im = null;

            SetPagePositionBegin(pgs);
            if (wc.PgImage != null)
            {                                // have we already generated this one
                                             // reuse most of the work; only position will likely change
                PageImage pi = new PageImage(wc.PgImage.ImgFormat, wc.PgImage.ImageData, wc.PgImage.SamplesW, wc.PgImage.SamplesH);
                pi.Name   = wc.PgImage.Name; // this is name it will be shared under
                pi.Sizing = this._Sizing;
                this.SetPagePositionAndStyle(r, pi, row);
                pgs.CurrentPage.AddObject(pi);
                SetPagePositionEnd(pgs, pi.Y + pi.H);
                return;
            }

            try
            {
                strm = GetImageStream(r, row, out mtype);
                im   = System.Drawing.Image.FromStream(strm);
                int          height = im.Height;
                int          width  = im.Width;
                MemoryStream ostrm  = new MemoryStream();
                ImageFormat  imf;
                //				if (mtype.ToLower() == "image/jpeg")    //TODO: how do we get png to work
                //					imf = ImageFormat.Jpeg;
                //				else
                imf = ImageFormat.Jpeg;
                im.Save(ostrm, imf);
                byte[] ba = ostrm.ToArray();
                ostrm.Close();
                PageImage pi = new PageImage(imf, ba, width, height);
                pi.Sizing = this._Sizing;
                this.SetPagePositionAndStyle(r, pi, row);

                pgs.CurrentPage.AddObject(pi);
                if (_ConstantImage)
                {
                    wc.PgImage = pi;
                    // create unique name; PDF generation uses this to optimize the saving of the image only once
                    pi.Name = "pi" + Interlocked.Increment(ref Parser.Counter).ToString();                      // create unique name
                }

                SetPagePositionEnd(pgs, pi.Y + pi.H);
            }
            catch (Exception e)
            {
                // image failed to load, continue processing
                r.rl.LogError(4, "Image load failed.  " + e.Message);
            }
            finally
            {
                if (strm != null)
                {
                    strm.Close();
                }
                if (im != null)
                {
                    im.Dispose();
                }
            }
            return;
        }
Ejemplo n.º 17
0
        private void DrawImageSized(PageImage pi, Xwt.Drawing.Image im, Xwt.Drawing.Context g, Xwt.Rectangle r)
        {
            double height, width;      // some work variables
            StyleInfo si = pi.SI;

            Xwt.Rectangle r2 = new Xwt.Rectangle(r.X + PixelsX(si.PaddingLeft),
                                                      r.Y + PixelsY(si.PaddingTop),
                                                      r.Width - PixelsX(si.PaddingLeft + si.PaddingRight),
                                                      r.Height - PixelsY(si.PaddingTop + si.PaddingBottom));

            Xwt.Rectangle ir;   // int work rectangle
            switch (pi.Sizing)
            {
                case ImageSizingEnum.AutoSize:

                    float imwidth = PixelsX( (float)im.Size.Width);
                    float imheight = PixelsX( (float)im.Size.Height);
                    ir = new Xwt.Rectangle(Convert.ToInt32(r2.X), Convert.ToInt32(r2.Y),
                                                    imwidth, imheight);

                    im.Scale((int)r2.Width, (int)r2.Height);
                    g.DrawImage(im, ir);

                    break;
                case ImageSizingEnum.Clip:
                    g.Save();
                    g.Rectangle(r2);
                    g.Clip();

                    ir = new Xwt.Rectangle(Convert.ToInt32(r2.X), Convert.ToInt32(r2.Y),
                                                    im.Size.Width, im.Size.Height);

                    g.DrawImage(im, ir);
                    g.Restore();
                    break;
                case ImageSizingEnum.FitProportional:
                    double ratioIm = (float)im.Size.Height / (float)im.Size.Width;
                    double ratioR = r2.Height / r2.Width;
                    height = r2.Height;
                    width = r2.Width;
                    if (ratioIm > ratioR)
                    {
                        // this means the rectangle width must be corrected
                        width = height * (1 / ratioIm);
                    }
                    else if (ratioIm < ratioR)
                    {
                        // this means the ractangle height must be corrected
                        height = width * ratioIm;
                    }
                    r2 = new Xwt.Rectangle(r2.X, r2.Y, width, height);
                    g.DrawImage(im, r2);
                    break;
                case ImageSizingEnum.Fit:
                default:
                    g.DrawImage(im, r2);
                    break;
            }
        }
Ejemplo n.º 18
0
        internal PageImage GetPageImage(Report rpt, Row row)
        {
            string mtype = null;
            Stream strm  = null;

            System.Drawing.Image im = null;
            PageImage            pi = null;

            WorkClass wc = GetWC(rpt);

            if (wc.PgImage != null)
            {                              // have we already generated this one
                                           // reuse most of the work; only position will likely change
                pi      = new PageImage(wc.PgImage.ImgFormat, wc.PgImage.ImageData, wc.PgImage.SamplesW, wc.PgImage.SamplesH);
                pi.Name = wc.PgImage.Name; // this is name it will be shared under
                return(pi);
            }

            try
            {
                strm = GetImageStream(rpt, row, out mtype);
                im   = System.Drawing.Image.FromStream(strm);
                int          height = im.Height;
                int          width  = im.Width;
                MemoryStream ostrm  = new MemoryStream();
                ImageFormat  imf;
                //				if (mtype.ToLower() == "image/jpeg")    //TODO: how do we get png to work
                //					imf = ImageFormat.Jpeg;
                //				else
                imf = ImageFormat.Jpeg;
                im.Save(ostrm, imf);
                byte[] ba = ostrm.ToArray();
                ostrm.Close();
                pi    = new PageImage(imf, ba, width, height);
                pi.SI = new StyleInfo();                        // this will just default everything
                if (_BackgroundRepeat != null)
                {
                    string r = _BackgroundRepeat.EvaluateString(rpt, row).ToLower();
                    switch (r)
                    {
                    case "repeat":
                        pi.Repeat = ImageRepeat.Repeat;
                        break;

                    case "repeatx":
                        pi.Repeat = ImageRepeat.RepeatX;
                        break;

                    case "repeaty":
                        pi.Repeat = ImageRepeat.RepeatY;
                        break;

                    case "norepeat":
                    default:
                        pi.Repeat = ImageRepeat.NoRepeat;
                        break;
                    }
                }
                else
                {
                    pi.Repeat = ImageRepeat.Repeat;
                }

                if (_ConstantImage)
                {
                    wc.PgImage = pi;
                    // create unique name; PDF generation uses this to optimize the saving of the image only once
                    pi.Name = "pi" + Interlocked.Increment(ref Parser.Counter).ToString();                      // create unique name
                }
            }
            finally
            {
                if (strm != null)
                {
                    strm.Close();
                }
                if (im != null)
                {
                    im.Dispose();
                }
            }
            return(pi);
        }
Ejemplo n.º 19
0
        override internal void RunPage(Pages pgs, Row row)
        {
            Report rpt = pgs.Report;

            if (IsHidden(pgs.Report, row))
                return;

            SetPagePositionBegin(pgs);

            // Build the Chart bitmap, along with data regions
            Page p = pgs.CurrentPage;
            ICustomReportItem cri = null;
            Bitmap bm = null;
            try
            {
                cri = RdlEngineConfig.CreateCustomReportItem(_Type);
                SetProperties(pgs.Report, row, cri);
                
                int width = WidthCalc(rpt, pgs.G) - 
                    (Style == null? 0 :
                        (Style.EvalPaddingLeftPx(rpt, row) + Style.EvalPaddingRightPx(rpt, row)));
                int height = RSize.PixelsFromPoints(this.HeightOrOwnerHeight) -
                    (Style == null? 0 :
                        (Style.EvalPaddingTopPx(rpt, row) + Style.EvalPaddingBottomPx(rpt, row)));
                bm = new Bitmap(width, height);
                cri.DrawImage(bm);

                MemoryStream ostrm = new MemoryStream();
                bm.Save(ostrm, IMAGEFORMAT);	// generate a jpeg   TODO: get png to work with pdf

                byte[] ba = ostrm.ToArray();
                ostrm.Close();
                PageImage pi = new PageImage(IMAGEFORMAT, ba, width, height);	// Create an image
                pi.Sizing = ImageSizingEnum.Clip;
//                RunPageRegionBegin(pgs);

                SetPagePositionAndStyle(rpt, pi, row);

                if (pgs.CurrentPage.YOffset + pi.Y + pi.H >= pgs.BottomOfPage && !pgs.CurrentPage.IsEmpty())
                {	// force page break if it doesn't fit on the page
                    pgs.NextOrNew();
                    pgs.CurrentPage.YOffset = OwnerReport.TopOfPage;
                    if (this.YParents != null)
                        pi.Y = 0;
                }

                p = pgs.CurrentPage;

                p.AddObject(pi);	// Put image onto the current page

  //              RunPageRegionEnd(pgs);

                if (!this.PageBreakAtEnd && !IsTableOrMatrixCell(rpt))
                {
                    float newY = pi.Y + pi.H;
                    p.YOffset += newY;	// bump the y location
                }
                SetPagePositionEnd(pgs, pi.Y + pi.H);
            }
            catch (Exception ex)
            {
                rpt.rl.LogError(8, string.Format("Exception in CustomReportItem handling: {0}", ex.Message));
            }
            finally
            {
                if (cri != null)
                    cri.Dispose();
            }

            return;
        }
Ejemplo n.º 20
0
        override internal void RunPage(Pages pgs, Row row)
        {
            Report r       = pgs.Report;
            bool   bHidden = IsHidden(r, row);

            WorkClass wc    = GetWC(r);
            string    mtype = null;
            Stream    strm  = null;

            System.DrawingCore.Image im = null;

            SetPagePositionBegin(pgs);
            if (bHidden)
            {
                PageImage pi = new PageImage(ImageFormat.Jpeg, null, 0, 0);
                this.SetPagePositionAndStyle(r, pi, row);
                SetPagePositionEnd(pgs, pi.Y + pi.H);
                return;
            }

            if (wc.PgImage != null)
            {                                // have we already generated this one
                                             // reuse most of the work; only position will likely change
                PageImage pi = new PageImage(wc.PgImage.ImgFormat, wc.PgImage.ImageData, wc.PgImage.SamplesW, wc.PgImage.SamplesH);
                pi.Name   = wc.PgImage.Name; // this is name it will be shared under
                pi.Sizing = this._Sizing;
                this.SetPagePositionAndStyle(r, pi, row);
                pgs.CurrentPage.AddObject(pi);
                SetPagePositionEnd(pgs, pi.Y + pi.H);
                return;
            }

            try
            {
                strm = GetImageStream(r, row, out mtype);
                if (strm == null)
                {
                    r.rl.LogError(4, string.Format("Unable to load image {0}.", this.Name.Nm));
                    return;
                }
                im = System.DrawingCore.Image.FromStream(strm);
                int          height = im.Height;
                int          width  = im.Width;
                MemoryStream ostrm  = new MemoryStream();
                strm.Position = 0;
                ImageFormat imf;
                switch (mtype.ToLower())
                {
                case "image/jpeg":
                    imf = ImageFormat.Jpeg;
                    CopyStream(strm, ostrm);
                    break;

                case "image/png":
                    imf = ImageFormat.Png;
                    CopyStream(strm, ostrm);
                    break;

                default:                         // from old code where all images convert to jpeg, i don't know why. May be need delete it and add all support formats.
                    imf = ImageFormat.Jpeg;
                    System.DrawingCore.Imaging.ImageCodecInfo[] info;
                    info = ImageCodecInfo.GetImageEncoders();
                    EncoderParameters encoderParameters;
                    encoderParameters          = new EncoderParameters(1);
                    encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, ImageQualityManager.EmbeddedImageQuality);
                    System.DrawingCore.Imaging.ImageCodecInfo codec = null;
                    for (int i = 0; i < info.Length; i++)
                    {
                        if (info[i].FormatDescription == "JPEG")
                        {
                            codec = info[i];
                            break;
                        }
                    }
                    im.Save(ostrm, codec, encoderParameters);
                    break;
                }

                byte[] ba = ostrm.ToArray();
                ostrm.Close();
                PageImage pi = new PageImage(imf, ba, width, height);
                pi.Sizing = this._Sizing;
                this.SetPagePositionAndStyle(r, pi, row);

                pgs.CurrentPage.AddObject(pi);
                if (_ConstantImage)
                {
                    wc.PgImage = pi;
                    // create unique name; PDF generation uses this to optimize the saving of the image only once
                    pi.Name = "pi" + Interlocked.Increment(ref Parser.Counter).ToString();                      // create unique name
                }

                SetPagePositionEnd(pgs, pi.Y + pi.H);
            }
            catch (Exception e)
            {
                // image failed to load, continue processing
                r.rl.LogError(4, "Image load failed.  " + e.Message);
            }
            finally
            {
                if (strm != null)
                {
                    strm.Close();
                }
                if (im != null)
                {
                    im.Dispose();
                }
            }
            return;
        }
Ejemplo n.º 21
0
        /// <summary>
        /// SaveZipImage saves the bytes to a zip entry and returns the name.  The passed cache is used
        /// to remember file names so that the same image isn't repeatedly saved.
        /// </summary>
        /// <param name="zipCache"></param>
        /// <param name="_ZipStream"></param>
        /// <param name="pi"></param>
        /// <returns></returns>
        internal static string SaveZipImage(Dictionary<string, string> zipCache, ZipOutputStream _ZipStream, PageImage pi)
        { 
            string imgname;
            imgname = (pi.Name != null)?
                string.Format("{0}.{1}", pi.Name, GetExtension(pi.ImgFormat)): 
                string.Format("i_{0}.{1}", zipCache.Count + 1, GetExtension(pi.ImgFormat));

            if (zipCache.ContainsKey(imgname))
                return imgname;

            zipCache.Add(imgname, imgname);

            ZipEntry ze = new ZipEntry(imgname);
            _ZipStream.PutNextEntry(ze);
            _ZipStream.Write(pi.ImageData, 0, pi.ImageData.Length);

            return imgname; 
        }
Ejemplo n.º 22
0
 internal PageImage PgImage;                 // When ConstantImage is true this will save the PageImage for reuse
 internal WorkClass()
 {
     PgImage = null;
 }
Ejemplo n.º 23
0
        private void DrawImageBackground(PageImage pi, StyleInfo si, StringBuilder sb, Rectangle r)
        {
            //Stream strm = null;
            //System.Drawing.Image im = null;
            //try
            //{
            //    strm = new MemoryStream(pi.ImageData);
            //    im = System.Drawing.Image.FromStream(strm);

            //    Rectangle r2 = new Rectangle(r.Left + PixelsX(si.PaddingLeft),
            //        r.Top + PixelsY(si.PaddingTop),
            //        r.Width - PixelsX(si.PaddingLeft + si.PaddingRight),
            //        r.Height - PixelsY(si.PaddingTop + si.PaddingBottom));

            //    int repeatX = 0;
            //    int repeatY = 0;
            //    switch (pi.Repeat)
            //    {
            //        case ImageRepeat.Repeat:
            //            repeatX = (int)Math.Floor(r2.Width / pi.SamplesW);
            //            repeatY = (int)Math.Floor(r2.Height / pi.SamplesH);
            //            break;
            //        case ImageRepeat.RepeatX:
            //            repeatX = (int)Math.Floor(r2.Width / pi.SamplesW);
            //            repeatY = 1;
            //            break;
            //        case ImageRepeat.RepeatY:
            //            repeatY = (int)Math.Floor(r2.Height / pi.SamplesH);
            //            repeatX = 1;
            //            break;
            //        case ImageRepeat.NoRepeat:
            //        default:
            //            repeatX = repeatY = 1;
            //            break;
            //    }

            //    //make sure the image is drawn at least 1 times 
            //    repeatX = Math.Max(repeatX, 1);
            //    repeatY = Math.Max(repeatY, 1);

            //    float startX = r2.Left;
            //    float startY = r2.Top;

            //    Region saveRegion = g.Clip;
            //    Region clipRegion = new Region(g.Clip.GetRegionData());
            //    clipRegion.Intersect(r2);
            //    g.Clip = clipRegion;

            //    for (int i = 0; i < repeatX; i++)
            //    {
            //        for (int j = 0; j < repeatY; j++)
            //        {
            //            float currX = startX + i * pi.SamplesW;
            //            float currY = startY + j * pi.SamplesH;
            //            g.DrawImage(im, new Rectangle(currX, currY, pi.SamplesW, pi.SamplesH));
            //        }
            //    }
            //    g.Clip = saveRegion;
            //}
            //finally
            //{
            //    if (strm != null)
            //        strm.Close();
            //    if (im != null)
            //        im.Dispose();
            //}
        }
Ejemplo n.º 24
0
        private void DrawImage(PageImage pi, Cairo.Context g, Cairo.Rectangle r)
        {
//            Stream strm = null;
//            System.Drawing.Image im = null;
            Gdk.Pixbuf im = null;
            try
            {
//                strm = new MemoryStream (pi.ImageData);
//                im = System.Drawing.Image.FromStream (strm);
                im = new Gdk.Pixbuf(pi.ImageData);
                DrawImageSized(pi, im, g, r);
            }
            finally
            {
//                if (strm != null)
//                    strm.Close();
                if (im != null)
                    im.Dispose();
            }

        }
Ejemplo n.º 25
0
        private void DrawImage(PageImage pi, Xwt.Drawing.Context g, Xwt.Rectangle r)
        {
            System.IO.MemoryStream ms = new System.IO.MemoryStream(pi.ImageData);
            Xwt.Drawing.Image im = null;
            try
            {
                // Xwt.Drawing.Image.FromStream does not work.  It crashes with both wpf and gtk
                // As a work around save the image to a temporary file and load it into xwt using the
                // FromFile method.


                System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
                               
                string fileName = System.IO.Path.GetTempFileName();
                img.Save(fileName, System.Drawing.Imaging.ImageFormat.Png);

                //im = Xwt.Drawing.Image.FromStream(ms);
                im = Xwt.Drawing.Image.FromFile(fileName);
                DrawImageSized(pi, im, g, r);

                im.Dispose();
                System.IO.File.Delete(fileName);
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex);
            }
            finally
            {

                if (im != null)
                    im.Dispose();
            }

        }
Ejemplo n.º 26
0
        private void DrawImageSized(PageImage pi, Gdk.Pixbuf im, Cairo.Context g, Cairo.Rectangle r)
        {
            double height, width;      // some work variables 
            StyleInfo si = pi.SI;

            // adjust drawing rectangle based on padding 
//            System.Drawing.RectangleF r2 = new System.Drawing.RectangleF(r.Left + PixelsX(si.PaddingLeft),
//                r.Top + PixelsY(si.PaddingTop),
//                r.Width - PixelsX(si.PaddingLeft + si.PaddingRight),
//                r.Height - PixelsY(si.PaddingTop + si.PaddingBottom));
            Cairo.Rectangle r2 = new Cairo.Rectangle(r.X + PixelsX(si.PaddingLeft),
                                     r.Y + PixelsY(si.PaddingTop),
                                     r.Width - PixelsX(si.PaddingLeft + si.PaddingRight),
                                     r.Height - PixelsY(si.PaddingTop + si.PaddingBottom));

            Cairo.Rectangle ir;   // int work rectangle 
            switch (pi.Sizing)
            {
                case ImageSizingEnum.AutoSize:
//                    // Note: GDI+ will stretch an image when you only provide 
//                    //  the left/top coordinates.  This seems pretty stupid since 
//                    //  it results in the image being out of focus even though 
//                    //  you don't want the image resized. 
//                    if (g.DpiX == im.HorizontalResolution &&
//                        g.DpiY == im.VerticalResolution)
                    float imwidth = PixelsX(im.Width);
                    float imheight = PixelsX(im.Height);
                    ir = new Cairo.Rectangle(Convert.ToInt32(r2.X), Convert.ToInt32(r2.Y),
                        imwidth, imheight);
//                    else
//                        ir = new Cairo.Rectangle(Convert.ToInt32(r2.X), Convert.ToInt32(r2.Y),
//                                           Convert.ToInt32(r2.Width), Convert.ToInt32(r2.Height));
                    //g.DrawImage(im, ir);
                    im = im.ScaleSimple((int)r2.Width, (int)r2.Height, Gdk.InterpType.Hyper);
                    g.DrawPixbufRect(im, ir);
                    break;
                case ImageSizingEnum.Clip:
//                    Region saveRegion = g.Clip;
                    g.Save();
//                    Region clipRegion = new Region(g.Clip.GetRegionData());
//                    clipRegion.Intersect(r2);
//                    g.Clip = clipRegion;
                    g.Rectangle(r2);
                    g.Clip();
				
//                    if (dpiX == im.HorizontalResolution &&
//                        dpiY == im.VerticalResolution) 
                    ir = new Cairo.Rectangle(Convert.ToInt32(r2.X), Convert.ToInt32(r2.Y),
                        im.Width, im.Height);
//                    else
//                        ir = new Cairo.Rectangle(Convert.ToInt32(r2.X), Convert.ToInt32(r2.Y),
//                                           Convert.ToInt32(r2.Width), Convert.ToInt32(r2.Height));
//                    g.DrawImage(im, ir);
                    g.DrawPixbufRect(im, ir);					
//                    g.Clip = saveRegion;
                    g.Restore();
                    break;
                case ImageSizingEnum.FitProportional:
                    double ratioIm = (float)im.Height / (float)im.Width;
                    double ratioR = r2.Height / r2.Width;
                    height = r2.Height;
                    width = r2.Width;
                    if (ratioIm > ratioR)
                    { 
                        // this means the rectangle width must be corrected 
                        width = height * (1 / ratioIm);
                    }
                    else if (ratioIm < ratioR)
                    {  
                        // this means the ractangle height must be corrected 
                        height = width * ratioIm;
                    }
                    r2 = new Cairo.Rectangle(r2.X, r2.Y, width, height);
                    g.DrawPixbufRect(im, r2);
                    break;
                case ImageSizingEnum.Fit:
                default:
                    g.DrawPixbufRect(im, r2);
                    break;
            }
        }
		internal PageImage GetPageImage(Report rpt, Row row)
		{
			string mtype=null; 
			Stream strm=null;
			System.Drawing.Bitmap im=null;
			PageImage pi=null;

			WorkClass wc = GetWC(rpt);
			if (wc.PgImage != null)
			{	// have we already generated this one
				// reuse most of the work; only position will likely change
				pi = new PageImage(wc.PgImage.ImgFormat, wc.PgImage.ImageData, wc.PgImage.SamplesW, wc.PgImage.SamplesH);
				pi.Name = wc.PgImage.Name;				// this is name it will be shared under
				return pi;
			}

			try 
			{
				strm = GetImageStream(rpt, row, out mtype);
                if (strm == null)
                {
                    rpt.rl.LogError(4, string.Format("Unable to load image {0}.", 
                        this._Value==null?"": this._Value.EvaluateString(rpt, row)));
                    return null;
                }
                im = Bitmap.FromStream(strm);
				int height = im.Height;
				int width = im.Width;
				MemoryStream ostrm = new MemoryStream();
				ImageFormat imf;
				//				if (mtype.ToLower() == "image/jpeg")    //TODO: how do we get png to work
				//					imf = ImageFormatType.Jpeg;
				//				else

                imf = ImageFormat.Jpeg;
                System.Drawing.Imaging.ImageCodecInfo[] info;
                info = ImageCodecInfo.GetImageEncoders();
                EncoderParameters encoderParameters;
                encoderParameters = new EncoderParameters(1);
                encoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, ImageQualityManager.EmbeddedImageQuality);
                System.Drawing.Imaging.ImageCodecInfo codec = null;
                for (int i = 0; i < info.Length; i++)
                {
                    if (info[i].FormatDescription == "JPEG")
                    {
                        codec = info[i];
                        break;
                    }
                }
                im.Save(ostrm, codec, encoderParameters);

				byte[] ba = ostrm.ToArray();
				ostrm.Close();
				pi = new PageImage(imf, ba, width, height);
				pi.SI = new StyleInfo();	// this will just default everything
				if (_BackgroundRepeat != null)
				{
					string r = _BackgroundRepeat.EvaluateString(rpt, row).ToLower();
					switch (r)
					{
						case "repeat":
							pi.Repeat = ImageRepeat.Repeat;
							break;
						case "repeatx":
							pi.Repeat = ImageRepeat.RepeatX;
							break;
						case "repeaty":
							pi.Repeat = ImageRepeat.RepeatY;
							break;
						case "norepeat":
						default:
							pi.Repeat = ImageRepeat.NoRepeat;
							break;
					}
				}
				else
					pi.Repeat = ImageRepeat.Repeat;

				if (_ConstantImage)
				{
					wc.PgImage = pi;
					// create unique name; PDF generation uses this to optimize the saving of the image only once
					pi.Name = "pi" + Interlocked.Increment(ref Parser.Counter).ToString();	// create unique name
				}
			}
			finally
			{
				if (strm != null)
					strm.Close();
				if (im != null)
					im.Dispose();
			}
			return pi;
		}
Ejemplo n.º 28
0
        override internal void RunPage(Pages pgs, Row row)
        {
            Report rpt = pgs.Report;

            if (IsHidden(pgs.Report, row))
            {
                return;
            }

            SetPagePositionBegin(pgs);

            // Build the Chart bitmap, along with data regions
            Page p = pgs.CurrentPage;
            ICustomReportItem cri = null;
            Bitmap            bm  = null;

            try
            {
                cri = RdlEngineConfig.CreateCustomReportItem(_Type);
                SetProperties(pgs.Report, row, cri);

                int width = WidthCalc(rpt, pgs.G) -
                            (Style == null? 0 :
                             (Style.EvalPaddingLeftPx(rpt, row) + Style.EvalPaddingRightPx(rpt, row)));
                int height = RSize.PixelsFromPoints(this.HeightOrOwnerHeight) -
                             (Style == null? 0 :
                              (Style.EvalPaddingTopPx(rpt, row) + Style.EvalPaddingBottomPx(rpt, row)));
                bm = new Bitmap(width, height);
                cri.DrawImage(ref bm);

                MemoryStream ostrm = new MemoryStream();
                // 06122007AJM Changed to use high quality JPEG encoding
                //bm.Save(ostrm, IMAGEFORMAT);	// generate a jpeg   TODO: get png to work with pdf
                System.Drawing.Imaging.ImageCodecInfo[] info;
                info = ImageCodecInfo.GetImageEncoders();
                EncoderParameters encoderParameters;
                encoderParameters = new EncoderParameters(1);
                // 20022008 AJM GJL - Using centralised image quality
                encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, ImageQualityManager.CustomImageQuality);
                System.Drawing.Imaging.ImageCodecInfo codec = null;
                for (int i = 0; i < info.Length; i++)
                {
                    if (info[i].FormatDescription == "JPEG")
                    {
                        codec = info[i];
                        break;
                    }
                }
                bm.Save(ostrm, codec, encoderParameters);

                byte[] ba = ostrm.ToArray();
                ostrm.Close();
                PageImage pi = new PageImage(IMAGEFORMAT, ba, width, height);   // Create an image
                pi.Sizing = ImageSizingEnum.Clip;
//                RunPageRegionBegin(pgs);

                SetPagePositionAndStyle(rpt, pi, row);

                if (pgs.CurrentPage.YOffset + pi.Y + pi.H >= pgs.BottomOfPage && !pgs.CurrentPage.IsEmpty())
                {       // force page break if it doesn't fit on the page
                    pgs.NextOrNew();
                    pgs.CurrentPage.YOffset = OwnerReport.TopOfPage;
                    if (this.YParents != null)
                    {
                        pi.Y = 0;
                    }
                }

                p = pgs.CurrentPage;

                p.AddObject(pi);        // Put image onto the current page

                //              RunPageRegionEnd(pgs);
// I don't know why we need move offset after draw. If we do it, barcode if it first in list all text shifted.
// If it broken something, write to Gankov

/*                if (!this.PageBreakAtEnd && !IsTableOrMatrixCell(rpt))
 *              {
 *                  float newY = pi.Y + pi.H;
 *                  p.YOffset += newY;	// bump the y location
 *              } */
                SetPagePositionEnd(pgs, pi.Y + pi.H);
            }
            catch (Exception ex)
            {
                rpt.rl.LogError(8, string.Format("Exception in CustomReportItem handling: {0}", ex.Message));
            }
            finally
            {
                if (cri != null)
                {
                    cri.Dispose();
                }
            }

            return;
        }
Ejemplo n.º 29
0
		internal PageImage GetPageImage(Report rpt, Row row)
		{
			string mtype=null; 
			Stream strm=null;
			System.Drawing.Image im=null;
			PageImage pi=null;

			WorkClass wc = GetWC(rpt);
			if (wc.PgImage != null)
			{	// have we already generated this one
				// reuse most of the work; only position will likely change
				pi = new PageImage(wc.PgImage.ImgFormat, wc.PgImage.ImageData, wc.PgImage.SamplesW, wc.PgImage.SamplesH);
				pi.Name = wc.PgImage.Name;				// this is name it will be shared under
				return pi;
			}

			try 
			{
				strm = GetImageStream(rpt, row, out mtype); 
				im = System.Drawing.Image.FromStream(strm);
				int height = im.Height;
				int width = im.Width;
				MemoryStream ostrm = new MemoryStream();
				ImageFormat imf;
				//				if (mtype.ToLower() == "image/jpeg")    //TODO: how do we get png to work
				//					imf = ImageFormat.Jpeg;
				//				else
				imf = ImageFormat.Jpeg;
				im.Save(ostrm, imf);
				byte[] ba = ostrm.ToArray();
				ostrm.Close();
				pi = new PageImage(imf, ba, width, height);
				pi.SI = new StyleInfo();	// this will just default everything
				if (_BackgroundRepeat != null)
				{
					string r = _BackgroundRepeat.EvaluateString(rpt, row).ToLower();
					switch (r)
					{
						case "repeat":
							pi.Repeat = ImageRepeat.Repeat;
							break;
						case "repeatx":
							pi.Repeat = ImageRepeat.RepeatX;
							break;
						case "repeaty":
							pi.Repeat = ImageRepeat.RepeatY;
							break;
						case "norepeat":
						default:
							pi.Repeat = ImageRepeat.NoRepeat;
							break;
					}
				}
				else
					pi.Repeat = ImageRepeat.Repeat;

				if (_ConstantImage)
				{
					wc.PgImage = pi;
					// create unique name; PDF generation uses this to optimize the saving of the image only once
					pi.Name = "pi" + Interlocked.Increment(ref Parser.Counter).ToString();	// create unique name
				}
			}
			finally
			{
				if (strm != null)
					strm.Close();
				if (im != null)
					im.Dispose();
			}
			return pi;
		}
Ejemplo n.º 30
0
        override internal void RunPage(Pages pgs, Row row)
        {
            Report rpt = pgs.Report;

            if (IsHidden(pgs.Report, row))
            {
                return;
            }

            _ChartMatrix.RunReset(rpt);
            Rows _Data = GetFilteredData(rpt, row);

            SetMyData(rpt, _Data);

            SetPagePositionBegin(pgs);

            if (!AnyRowsPage(pgs, _Data))                       // if no rows return
            {
                return;                                         //   nothing left to do
            }
            // Build the Chart bitmap, along with data regions
            Page      p  = pgs.CurrentPage;
            ChartBase cb = null;

            try
            {
                cb = RunChartBuild(rpt, row);                           // Build the chart
                if (!_isHYNEsWonderfulVector.EvaluateBoolean(rpt, row)) //AJM GJL 14082008 'Classic' Rendering
                {
                    System.Drawing.Image im = cb.Image(rpt);            // Grab the image
                    int height = im.Height;                             // save height and width
                    int width  = im.Width;

                    MemoryStream ostrm = new MemoryStream();

                    /* The following is a new image saving logic which will allow for higher
                     * quality images using JPEG with 100% quality
                     * 06122007AJM */
                    System.Drawing.Imaging.ImageCodecInfo[] info;
                    info = ImageCodecInfo.GetImageEncoders();
                    EncoderParameters encoderParameters;
                    encoderParameters = new EncoderParameters(1);
                    // 20022008 AJM GJL - Centralised class with global encoder settings
                    encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, ImageQualityManager.ChartImageQuality);
                    System.Drawing.Imaging.ImageCodecInfo codec = null;
                    for (int i = 0; i < info.Length; i++)
                    {
                        if (info[i].FormatDescription == "JPEG")
                        {
                            codec = info[i];
                            break;
                        }
                    }
                    im.Save(ostrm, codec, encoderParameters);
                    // 06122007AJM The follow has been replaced with the code above
                    //im.Save(ostrm, info);	// generate a jpeg   TODO: get png to work with pdf

                    byte[] ba = ostrm.ToArray();
                    ostrm.Close();
                    PageImage pi = new PageImage(IMAGEFORMAT, ba, width, height);       // Create an image

                    RunPageRegionBegin(pgs);

                    SetPagePositionAndStyle(rpt, pi, row);
                    pi.SI.BackgroundImage = null;       // chart already has the background image

                    if (pgs.CurrentPage.YOffset + pi.Y + pi.H >= pgs.BottomOfPage && !pgs.CurrentPage.IsEmpty())
                    {   // force page break if it doesn't fit on the page
                        pgs.NextOrNew();
                        pgs.CurrentPage.YOffset = OwnerReport.TopOfPage;
                        if (this.YParents != null)
                        {
                            pi.Y = 0;
                        }
                    }

                    p = pgs.CurrentPage;

                    p.AddObject(pi);    // Put image onto the current page

                    RunPageRegionEnd(pgs);

                    if (!this.PageBreakAtEnd && !IsTableOrMatrixCell(rpt))
                    {
                        float newY = pi.Y + pi.H;
                        p.YOffset += newY;      // bump the y location
                    }
                    SetPagePositionEnd(pgs, pi.Y + pi.H);
                }
                else //Ultimate Rendering - Vector //AJM GJL 14082008
                {
                    System.Drawing.Imaging.Metafile im = cb.Image(rpt); // Grab the image
                    //im could still be saved to a bitmap at this point
                    //if we were to offer a choice of raster or vector, it would probably
                    //be easiest to draw the chart to the EMF and then save as bitmap if needed
                    int    height = im.Height;                                                  // save height and width
                    int    width  = im.Width;
                    byte[] ba     = cb._aStream.ToArray();
                    cb._aStream.Close();

                    PageImage pi = new PageImage(ImageFormat.Wmf, ba, width, height);
                    RunPageRegionBegin(pgs);

                    SetPagePositionAndStyle(rpt, pi, row);
                    pi.SI.BackgroundImage = null;       // chart already has the background image

                    if (pgs.CurrentPage.YOffset + pi.Y + pi.H >= pgs.BottomOfPage && !pgs.CurrentPage.IsEmpty())
                    {   // force page break if it doesn't fit on the page
                        pgs.NextOrNew();
                        pgs.CurrentPage.YOffset = OwnerReport.TopOfPage;
                        if (this.YParents != null)
                        {
                            pi.Y = 0;
                        }
                    }

                    p = pgs.CurrentPage;

                    //GJL 25072008 - Charts now draw in EMFplus format and not in bitmap. Still using the "PageImage" for the positioning
                    //paging etc, but we don't add it to the page.
                    // ******************************************************************************************************************
                    // New EMF Processing... we want to add the EMF Components to the page and not the actual EMF...
                    EMF emf = new EMF(pi.X, pi.Y, width, height);
                    emf.ProcessEMF(ba); //Process takes the bytearray of EMFplus data and breaks it down into lines,ellipses,text,rectangles
                    //etc... There are still a lot of GDI+ functions I haven't got to (and some I have no intention of getting to!).
                    foreach (PageItem emfItem in emf.PageItems)
                    {
                        p.AddObject(emfItem);
                    }
                    // ******************************************************************************************************************

                    //p.AddObject(pi);
                    RunPageRegionEnd(pgs);
                    pi.Y += p.YOffset;
                    if (!this.PageBreakAtEnd && !IsTableOrMatrixCell(rpt))
                    {
                        float newY = pi.Y + pi.H;
                        p.YOffset += newY;                // bump the y location
                    }
                    SetPagePositionEnd(pgs, pi.Y + pi.H); //our emf size seems to be bigger than the jpeg...
                }
            }
            catch (Exception ex)
            {
                rpt.rl.LogError(8, string.Format("Exception in Chart handling.\n{0}\n{1}", ex.Message, ex.StackTrace));
            }
            finally
            {
                if (cb != null)
                {
                    cb.Dispose();
                }
            }

            return;
        }
        override internal void RunPage(Pages pgs, Row row)
        {
            Report rpt = pgs.Report;

            if (IsHidden(pgs.Report, row))
                return;

            SetPagePositionBegin(pgs);

            // Build the Chart bitmap, along with data regions
            Page p = pgs.CurrentPage;
            ICustomReportItem cri = null;
            Bitmap bm = null;
            try
            {
                cri = RdlEngineConfig.CreateCustomReportItem(_Type);
                SetProperties(pgs.Report, row, cri);
                
                int width = WidthCalc(rpt, pgs.G) - 
                    (Style == null? 0 :
                        (Style.EvalPaddingLeftPx(rpt, row) + Style.EvalPaddingRightPx(rpt, row)));
                int height = RSize.PixelsFromPoints(this.HeightOrOwnerHeight) -
                    (Style == null? 0 :
                        (Style.EvalPaddingTopPx(rpt, row) + Style.EvalPaddingBottomPx(rpt, row)));
                bm = Bitmap.CreateBitmap(width, height, PixelFormat.Format16bppRgb565);// Bitmap.Config.Rgb565);
                cri.DrawImage(ref bm);

                MemoryStream ostrm = new MemoryStream();
                // 06122007AJM Changed to use high quality JPEG encoding
                //bm.Save(ostrm, IMAGEFORMAT);	// generate a jpeg   TODO: get png to work with pdf
                //System.Drawing.Imaging.ImageCodecInfo[] info;
                //info = ImageCodecInfo.GetImageEncoders();
                //EncoderParameters encoderParameters;
                //encoderParameters = new EncoderParameters(1);
                //// 20022008 AJM GJL - Using centralised image quality
                //encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, ImageQualityManager.CustomImageQuality);
                //System.Drawing.Imaging.ImageCodecInfo codec = null;
                //for (int i = 0; i < info.Length; i++)
                //{
                //    if (info[i].FormatDescription == "JPEG")
                //    {
                //        codec = info[i];
                //        break;
                //    }
                //}
                //bm.Save(ostrm, codec, encoderParameters);

                byte[] ba = ostrm.ToArray();
                ostrm.Close();
                PageImage pi = new PageImage(IMAGEFORMAT, ba, width, height);	// Create an image
                pi.Sizing = ImageSizingEnum.Clip;
//                RunPageRegionBegin(pgs);

                SetPagePositionAndStyle(rpt, pi, row);

                if (pgs.CurrentPage.YOffset + pi.Y + pi.H >= pgs.BottomOfPage && !pgs.CurrentPage.IsEmpty())
                {	// force page break if it doesn't fit on the page
                    pgs.NextOrNew();
                    pgs.CurrentPage.YOffset = OwnerReport.TopOfPage;
                    if (this.YParents != null)
                        pi.Y = 0;
                }

                p = pgs.CurrentPage;

                p.AddObject(pi);	// Put image onto the current page

  //              RunPageRegionEnd(pgs);

                if (!this.PageBreakAtEnd && !IsTableOrMatrixCell(rpt))
                {
                    float newY = pi.Y + pi.H;
                    p.YOffset += newY;	// bump the y location
                }
                SetPagePositionEnd(pgs, pi.Y + pi.H);
            }
            catch (Exception ex)
            {
                rpt.rl.LogError(8, string.Format("Exception in CustomReportItem handling: {0}", ex.Message));
            }
            finally
            {
                if (cri != null)
                    cri.Dispose();
            }

            return;
        }
        private PageImage BuildImage(Graphics g, string token, StyleInfo oldsi, PageText model)
        {
            PageTextHtmlCmdLexer hc = new PageTextHtmlCmdLexer(token.Substring(4));
            Hashtable            ht = hc.Lex();

            string src = (string)ht["src"];

            if (src == null || src.Length < 1)
            {
                return(null);
            }

            string alt = (string)ht["alt"];

            string height = (string)ht["height"];
            string width  = (string)ht["width"];
            string align  = (string)ht["align"];

            Stream strm = null;

            System.Drawing.Image im = null;
            PageImage            pi = null;

            try
            {
                // Obtain the image stream
                if (src.StartsWith("http:") ||
                    src.StartsWith("file:") ||
                    src.StartsWith("https:"))
                {
                    WebRequest  wreq = WebRequest.Create(src);
                    WebResponse wres = wreq.GetResponse();
                    strm = wres.GetResponseStream();
                }
                else
                {
                    strm = new FileStream(src, System.IO.FileMode.Open, FileAccess.Read);
                }

                im = System.Drawing.Image.FromStream(strm);
                int          h     = im.Height;
                int          w     = im.Width;
                MemoryStream ostrm = new MemoryStream();
                ImageFormat  imf;
                imf = ImageFormat.Jpeg;
                im.Save(ostrm, imf);
                byte[] ba = ostrm.ToArray();
                ostrm.Close();
                pi             = new PageImage(imf, ba, w, h);
                pi.AllowSelect = false;
                pi.Page        = this.Page;
                pi.HyperLink   = model.HyperLink;
                pi.Tooltip     = alt == null ? model.Tooltip : alt;
                pi.X           = 0;
                pi.Y           = 0;

                pi.W  = RSize.PointsFromPixels(g, width != null? Convert.ToInt32(width): w);
                pi.H  = RSize.PointsFromPixels(g, height != null? Convert.ToInt32(height): h);
                pi.SI = new StyleInfo();
            }
            catch
            {
                pi = null;
            }
            finally
            {
                if (strm != null)
                {
                    strm.Close();
                }
                if (im != null)
                {
                    im.Dispose();
                }
            }

            return(pi);
        }
Ejemplo n.º 33
0
        private void DrawImage(PageImage pi, Xwt.Drawing.Context g, Xwt.Rectangle r)
        {
            System.IO.MemoryStream ms = new System.IO.MemoryStream(pi.ImageData);
            Xwt.Drawing.Image im = null;
            try
            {
                im = Xwt.Drawing.Image.FromStream(ms);
                DrawImageSized(pi, im, g, r);
            }
            finally
            {

                if (im != null)
                    im.Dispose();
            }
        }
        private void BuildPrivate(Graphics g)
        {
            PageText model = new PageText("");

            model.AllowSelect = false;
            model.Page        = this.Page;
            model.HyperLink   = null;
            model.Tooltip     = null;
            int fontSizeModel = 3;

            if (_items != null)                         // this has already been built
            {
                return;
            }
            _items      = new List <PageItem>();
            _StyleStack = new Stack();

            // The first item is always a text box with the border and background attributes
            PageText pt = new PageText("");

            pt.AllowSelect      = true;           // This item represents HTML item for selection in RdlViewer
            pt.Page             = this.Page;
            pt.HtmlParent       = this;
            pt.X                = this.X;
            pt.Y                = this.Y;
            pt.H                = this.H;
            pt.W                = this.W;
            pt.CanGrow          = false;
            pt.SI               = this.SI.Clone() as StyleInfo;
            pt.SI.PaddingBottom = pt.SI.PaddingLeft = pt.SI.PaddingRight = pt.SI.PaddingTop = 0;
            pt.SI.TextAlign     = TextAlignEnum.Left;
            _items.Add(pt);

            // Now we create multiple items that represent what is in the box
            PageTextHtmlLexer hl     = new PageTextHtmlLexer(this.Text);
            List <string>     tokens = hl.Lex();

            float textWidth = this.W - pt.SI.PaddingLeft - pt.SI.PaddingRight;
            // Now set the default style for the rest of the members
            StyleInfo si = this.SI.Clone() as StyleInfo;

            si.BStyleBottom           = si.BStyleLeft = si.BStyleRight = si.BStyleTop = BorderStyleEnum.None;
            pt.SI.TextAlign           = TextAlignEnum.Left;
            pt.SI.VerticalAlign       = VerticalAlignEnum.Top;
            si.BackgroundColor        = Color.Empty;
            si.BackgroundGradientType = BackgroundGradientTypeEnum.None;
            si.BackgroundImage        = null;

            bool            bFirstInLine  = true;
            StringBuilder   sb            = new StringBuilder(); // this will hold the accumulating line
            float           lineXPos      = 0;
            float           xPos          = 0;
            float           yPos          = 0;
            float           maxLineHeight = 0;
            float           maxDescent    = 0;
            float           descent;                            // working value for descent
            SizeF           ms;
            bool            bWhiteSpace    = false;
            List <PageItem> lineItems      = new List <PageItem>();
            bool            bIsOrderedList = false;
            int?            OlLiCount      = null; //Maintains number of OL items; zero indicates UL item (bullet)

            foreach (string token in tokens)
            {
                if (token[0] == PageTextHtmlLexer.HTMLCMD)                              // indicates an HTML command
                {
                    // we need to create a PageText since the styleinfo is changing
                    if (sb.Length != 0)
                    {
                        pt             = new PageText(sb.ToString());
                        pt.AllowSelect = false;
                        pt.Page        = this.Page;
                        pt.HtmlParent  = this;
                        pt.HyperLink   = model.HyperLink;
                        pt.Tooltip     = model.Tooltip;
                        pt.NoClip      = true;
                        sb             = new StringBuilder();
                        pt.X           = this.X + lineXPos;
                        pt.Y           = this.Y + yPos;
                        pt.CanGrow     = false;
                        pt.SI          = CurrentStyle(si).Clone() as StyleInfo;
                        _items.Add(pt);
                        lineItems.Add(pt);
                        ms            = this.MeasureString(pt.Text, pt.SI, g, out descent);
                        maxDescent    = Math.Max(maxDescent, descent);
                        pt.W          = ms.Width;
                        pt.H          = ms.Height;
                        pt.Descent    = descent;
                        maxLineHeight = Math.Max(maxLineHeight, ms.Height);
                        lineXPos      = xPos;
                    }
                    // Now reset the styleinfo
                    StyleInfo cs     = CurrentStyle(si);
                    string    ltoken = token.Substring(1, Math.Min(token.Length - 1, 10)).ToLower();
                    if (ltoken == "<b>" || ltoken == "<strong>")
                    {
                        cs.FontWeight = FontWeightEnum.Bold;
                    }
                    else if (ltoken == "</b>" || ltoken == "</strong>")
                    {
                        cs.FontWeight = FontWeightEnum.Normal;
                    }
                    else if (ltoken == "<i>" || ltoken == "<cite>" || ltoken == "<var>" || ltoken == "<em>")
                    {
                        cs.FontStyle = FontStyleEnum.Italic;
                    }
                    else if (ltoken == "</i>" || ltoken == "</cite>" || ltoken == "</var>" || ltoken == "</em>")
                    {
                        cs.FontStyle = FontStyleEnum.Normal;
                    }
                    else if (ltoken == "<code>" || ltoken == "<samp>")
                    {
                        cs.FontFamily = "Courier New";
                    }
                    else if (ltoken == "</code>" || ltoken == "</samp>")
                    {
                        cs.FontFamily = this.SI.FontFamily;
                    }
                    else if (ltoken == "<kbd>")
                    {
                        cs.FontFamily = "Courier New";
                        cs.FontWeight = FontWeightEnum.Bold;
                    }
                    else if (ltoken == "</kdd>")
                    {
                        cs.FontFamily = this.SI.FontFamily;
                        cs.FontWeight = FontWeightEnum.Normal;
                    }
                    else if (ltoken == "<big>")
                    {                           // big makes it bigger by 20% for each time over the baseline of 3
                        fontSizeModel++;
                        float inc = 1;
                        for (int i = 3; i < fontSizeModel; i++)
                        {
                            inc += .2f;
                        }
                        float h = this.SI.FontSize * inc;
                        cs.FontSize = h;
                    }
                    else if (ltoken == "</big>")
                    {                           // undoes the effect of big
                        fontSizeModel--;
                        float inc = 1;
                        for (int i = 3; i < fontSizeModel; i++)
                        {
                            inc += .2f;
                        }
                        float h = this.SI.FontSize / inc;
                        cs.FontSize = h;
                    }
                    else if (ltoken == "<small>")
                    {                           // small makes it smaller by 20% for each time under the baseline of 3
                        fontSizeModel--;
                        float inc = 1;
                        for (int i = 3; i > fontSizeModel; i--)
                        {
                            inc += .2f;
                        }
                        float h = this.SI.FontSize / inc;
                        cs.FontSize = h;
                    }
                    else if (ltoken == "</small>")
                    {                           // undoes the effect of small
                        fontSizeModel++;
                        float inc = 1;
                        for (int i = 3; i > fontSizeModel; i--)
                        {
                            inc += .2f;
                        }
                        float h = this.SI.FontSize * inc;
                        cs.FontSize = h;
                    }
                    else if (ltoken.StartsWith("<br"))
                    {
                        yPos += maxLineHeight;
                        NormalizeLineHeight(lineItems, maxLineHeight, maxDescent);
                        xPos         = lineXPos = maxDescent = 0;
                        bFirstInLine = true;
                        bWhiteSpace  = false;
                    }
                    else if (ltoken.StartsWith("<hr"))
                    {   // Add a line
                        // Process existing line if any
                        yPos += maxLineHeight;
                        NormalizeLineHeight(lineItems, maxLineHeight, maxDescent);
                        maxLineHeight = xPos = lineXPos = maxDescent = 0;
                        bFirstInLine  = true;
                        bWhiteSpace   = false;

                        PageLine pl = new PageLine();
                        pl.AllowSelect = false;
                        pl.Page        = this.Page;
                        const int horzLineHeight = 10;
                        pl.SI            = cs.Clone() as StyleInfo;
                        pl.SI.BStyleLeft = BorderStyleEnum.Ridge;
                        pl.Y             = pl.Y2 = this.Y + yPos + horzLineHeight / 2;
                        pl.X             = this.X;
                        pl.X2            = pl.X + this.W;
                        _items.Add(pl);
                        yPos += horzLineHeight;  // skip past horizontal line
                    }
                    else if (ltoken.StartsWith("<p"))
                    {
                        yPos += maxLineHeight * 2;
                        NormalizeLineHeight(lineItems, maxLineHeight, maxDescent);
                        maxLineHeight = xPos = lineXPos = maxDescent = 0;
                        bFirstInLine  = true;
                        bWhiteSpace   = false;
                    }
                    else if (ltoken.StartsWith("<a"))
                    {
                        BuildAnchor(token.Substring(1), cs, model);
                    }
                    else if (ltoken.StartsWith("<img"))
                    {
                        PageImage pimg = BuildImage(g, token.Substring(1), cs, model);
                        if (pimg != null)   // We got an image; add to process list
                        {
                            pimg.Y = this.Y + yPos;
                            pimg.X = this.X;
                            _items.Add(pimg);
                            yPos         += pimg.H;     // Increment y position
                            maxLineHeight = xPos = lineXPos = maxDescent = 0;
                            bFirstInLine  = true;
                            bWhiteSpace   = false;
                        }
                    }
                    else if (ltoken == "</a>")
                    {
                        model.HyperLink = model.Tooltip = null;
                        PopStyle();
                    }
                    else if (ltoken.StartsWith("<span"))
                    {
                        HandleStyle(token.Substring(1), si);
                    }
                    else if (ltoken == "</span>")
                    {   // we really should match span and font but it shouldn't matter very often?
                        PopStyle();
                    }
                    else if (ltoken.StartsWith("<font"))
                    {
                        HandleFont(token.Substring(1), si);
                    }
                    else if (ltoken == "</font>")
                    {   // we really should match span and font but it shouldn't matter very often?
                        PopStyle();
                    }
                    else if (ltoken.StartsWith("<ol") || ltoken.StartsWith("<ul"))
                    {
                        yPos += maxLineHeight;
                        NormalizeLineHeight(lineItems, maxLineHeight, maxDescent);
                        maxLineHeight = xPos = lineXPos = maxDescent = 0;
                        bFirstInLine  = true;
                        bWhiteSpace   = false;

                        bIsOrderedList = ltoken.StartsWith("<ol");
                    }
                    else if (ltoken.StartsWith("<li"))
                    {
                        yPos += maxLineHeight;
                        NormalizeLineHeight(lineItems, maxLineHeight, maxDescent);
                        maxLineHeight = xPos = lineXPos = maxDescent = 0;
                        bFirstInLine  = true;
                        bWhiteSpace   = false;

                        if (OlLiCount == null)
                        {
                            OlLiCount = 0;
                        }
                        if (bIsOrderedList)
                        {
                            OlLiCount++;
                        }
                    }
                    else if (ltoken.StartsWith("</ol") || ltoken.StartsWith("</ul"))
                    {
                        bIsOrderedList = false;
                        OlLiCount      = null;
                    }
                    continue;
                }
                if (token == PageTextHtmlLexer.WHITESPACE)
                {
                    if (!bFirstInLine)
                    {
                        bWhiteSpace = true;
                    }
                    continue;
                }

                if (token != PageTextHtmlLexer.EOF)
                {
                    string ntoken;
                    if (token == PageTextHtmlLexer.NBSP.ToString())
                    {
                        ntoken = bWhiteSpace ? "  " : " ";
                    }
                    else
                    {
                        ntoken = bWhiteSpace ? " " + token : token;
                    }
                    ntoken = ntoken.Replace(PageTextHtmlLexer.NBSP, ' ');

                    bWhiteSpace = false;                                        // can only use whitespace once
                    ms          = this.MeasureString(ntoken, CurrentStyle(si), g, out descent);
                    if (xPos + ms.Width < textWidth)
                    {
                        if (bFirstInLine)
                        {
                            if (OlLiCount == 0)                        //Adds UL bullet
                            {
                                sb.Append("•   ");
                            }
                            else if (OlLiCount > 0)                        //Adds OL numeric prefix
                            {
                                sb.AppendFormat("{0})   ", OlLiCount);
                            }
                        }

                        bFirstInLine = false;
                        sb.Append(ntoken);

                        maxDescent    = Math.Max(maxDescent, descent);
                        maxLineHeight = Math.Max(maxLineHeight, ms.Height);
                        xPos         += ms.Width;
                        continue;
                    }
                }
                else if (sb.Length == 0)                        // EOF and no previous string means we're done
                {
                    continue;
                }

                pt             = new PageText(sb.ToString());
                pt.AllowSelect = false;
                pt.Page        = this.Page;
                pt.HtmlParent  = this;
                pt.NoClip      = true;
                pt.HyperLink   = model.HyperLink;
                pt.Tooltip     = model.Tooltip;
                sb             = new StringBuilder();
                sb.Append(token.Replace(PageTextHtmlLexer.NBSP, ' '));
                pt.SI      = CurrentStyle(si).Clone() as StyleInfo;
                ms         = this.MeasureString(pt.Text, pt.SI, g, out descent);
                pt.X       = this.X + lineXPos;
                pt.Y       = this.Y + yPos;
                pt.H       = ms.Height;
                pt.W       = ms.Width;
                pt.Descent = descent;
                pt.CanGrow = false;
                _items.Add(pt);
                lineItems.Add(pt);
                maxDescent    = Math.Max(maxDescent, descent);
                maxLineHeight = Math.Max(maxLineHeight, ms.Height);
                yPos         += maxLineHeight;             // Increment y position
                NormalizeLineHeight(lineItems, maxLineHeight, maxDescent);
                lineXPos = maxLineHeight = maxDescent = 0; // start line height over

                // Now set the xPos just after the current token
                ms   = this.MeasureString(token, CurrentStyle(si), g, out descent);
                xPos = ms.Width;
            }

            _TotalHeight = yPos;                        // set the calculated height of the result
            _StyleStack  = null;
            return;
        }
Ejemplo n.º 35
0
 private void DrawImage(PageImage pi, Graphics g, RectangleF r)
 {
     Stream strm = null;
     System.Drawing.Image im = null;
     try
     {
         strm = new MemoryStream(pi.ImageData);
         im = System.Drawing.Image.FromStream(strm);
         DrawImageSized(pi, im, g, r);
     }
     finally
     {
         if (strm != null)
             strm.Close();
         if (im != null)
             im.Dispose();
     }
 }
Ejemplo n.º 36
0
		private void DrawImageSized(PageImage pi, Image im, Graphics g, RectangleF r)
		{
			float height, width;		// some work variables
			StyleInfo si = pi.SI;

			// adjust drawing rectangle based on padding
			RectangleF r2 = new RectangleF(r.Left + PixelsX(si.PaddingLeft),
				r.Top + PixelsY(si.PaddingTop),
				r.Width - PixelsX(si.PaddingLeft + si.PaddingRight),
				r.Height - PixelsY(si.PaddingTop + si.PaddingBottom));
		
			Rectangle ir;	// int work rectangle
			switch (pi.Sizing)
			{
				case ImageSizingEnum.AutoSize:
					// Note: GDI+ will stretch an image when you only provide
					//  the left/top coordinates.  This seems pretty stupid since
					//  it results in the image being out of focus even though
					//  you don't want the image resized.
                    if (g.DpiX == im.HorizontalResolution &&
                        g.DpiY == im.VerticalResolution)
                    {
                        ir = new Rectangle(Convert.ToInt32(r2.Left), Convert.ToInt32(r2.Top),
                                                        im.Width, im.Height);
                    }
                    else
                        ir = new Rectangle(Convert.ToInt32(r2.Left), Convert.ToInt32(r2.Top),
                                           Convert.ToInt32(r2.Width), Convert.ToInt32(r2.Height));
                    g.DrawImage(im, ir);

					break;
				case ImageSizingEnum.Clip:
					Region saveRegion = g.Clip;
					Region clipRegion = new Region(g.Clip.GetRegionData());
					clipRegion.Intersect(r2);
					g.Clip = clipRegion;
                    if (g.DpiX == im.HorizontalResolution &&
                        g.DpiY == im.VerticalResolution)
                    {
                        ir = new Rectangle(Convert.ToInt32(r2.Left), Convert.ToInt32(r2.Top),
                                                        im.Width, im.Height);
                    }
                    else
                        ir = new Rectangle(Convert.ToInt32(r2.Left), Convert.ToInt32(r2.Top),
                                           Convert.ToInt32(r2.Width), Convert.ToInt32(r2.Height));
                    g.DrawImage(im, ir);
                    g.Clip = saveRegion;
					break;
				case ImageSizingEnum.FitProportional:
					float ratioIm = (float) im.Height / (float) im.Width;
					float ratioR = r2.Height / r2.Width;
					height = r2.Height;
					width = r2.Width;
					if (ratioIm > ratioR)
					{	// this means the rectangle width must be corrected
						width = height * (1/ratioIm);
					}
					else if (ratioIm < ratioR)
					{	// this means the ractangle height must be corrected
						height = width * ratioIm;
					}
					r2 = new RectangleF(r2.X, r2.Y, width, height);
					g.DrawImage(im, r2);
					break;
				case ImageSizingEnum.Fit:
				default:
					g.DrawImage(im, r2);
					break;
			}
			return;
		}
Ejemplo n.º 37
0
        private void DrawImageSized(PageImage pi, Image im, Graphics g, RectangleF r)
        {
            float height, width;		// some work variables
            StyleInfo si = pi.SI;

            // adjust drawing rectangle based on padding

            // http://www.fyireporting.com/forum/viewtopic.php?t=892
            //A.S.> convert pt to px if needed(when printing we need px, when draw preview - pt)

            RectangleF r2;
            if (g.PageUnit == GraphicsUnit.Pixel)
            {
                r2 = new RectangleF(r.Left + (si.PaddingLeft * g.DpiX) / 72,
                r.Top + (si.PaddingTop * g.DpiX) / 72,
                r.Width - ((si.PaddingLeft + si.PaddingRight) * g.DpiX) / 72,
                r.Height - ((si.PaddingTop + si.PaddingBottom) * g.DpiX) / 72);
            }
            else
            {
                // adjust drawing rectangle based on padding
                r2 = new RectangleF(r.Left + si.PaddingLeft,
                r.Top + si.PaddingTop,
                r.Width - si.PaddingLeft - si.PaddingRight,
                r.Height - si.PaddingTop - si.PaddingBottom);
            }

            Rectangle ir;	// int work rectangle
            ir = new Rectangle(Convert.ToInt32(r2.Left), Convert.ToInt32(r2.Top),
                               Convert.ToInt32(r2.Width), Convert.ToInt32(r2.Height));
            switch (pi.Sizing)
            {
                case ImageSizingEnum.AutoSize:
                    // Note: GDI+ will stretch an image when you only provide
                    //  the left/top coordinates.  This seems pretty stupid since
                    //  it results in the image being out of focus even though
                    //  you don't want the image resized.
                    if (g.DpiX == im.HorizontalResolution &&
                        g.DpiY == im.VerticalResolution)
                    {
                        ir = new Rectangle(Convert.ToInt32(r2.Left), Convert.ToInt32(r2.Top),
                                                        im.Width, im.Height);
                    }
                    g.DrawImage(im, ir);

                    break;
                case ImageSizingEnum.Clip:
                    Region saveRegion = g.Clip;
                    Region clipRegion = new Region(g.Clip.GetRegionData());
                    clipRegion.Intersect(r2);
                    g.Clip = clipRegion;
                    if (g.DpiX == im.HorizontalResolution &&
                        g.DpiY == im.VerticalResolution)
                    {
                        ir = new Rectangle(Convert.ToInt32(r2.Left), Convert.ToInt32(r2.Top),
                                                        im.Width, im.Height);
                    }
                    g.DrawImage(im, ir);
                    g.Clip = saveRegion;
                    break;
                case ImageSizingEnum.FitProportional:
                    float ratioIm = (float)im.Height / (float)im.Width;
                    float ratioR = r2.Height / r2.Width;
                    height = r2.Height;
                    width = r2.Width;
                    if (ratioIm > ratioR)
                    {	// this means the rectangle width must be corrected
                        width = height * (1 / ratioIm);
                    }
                    else if (ratioIm < ratioR)
                    {	// this means the ractangle height must be corrected
                        height = width * ratioIm;
                    }
                    r2 = new RectangleF(r2.X, r2.Y, width, height);
                    g.DrawImage(im, r2);
                    break;
                case ImageSizingEnum.Fit:
                default:
                    g.DrawImage(im, r2);
                    break;
            }

            if (SelectTool && pi.AllowSelect && _SelectList.Contains(pi))
            {
                g.FillRectangle(new SolidBrush(Color.FromArgb(50, _SelectItemColor)), ir);
            }

            return;
        }
Ejemplo n.º 38
0
		override internal void RunPage(Pages pgs, Row row)
		{
			Report rpt = pgs.Report;

			if (IsHidden(pgs.Report, row))
				return;

			_ChartMatrix.RunReset(rpt);
			Rows _Data = GetFilteredData(rpt, row);
			SetMyData(rpt, _Data);

			SetPagePositionBegin(pgs);

			if (!AnyRowsPage(pgs, _Data))		// if no rows return
				return;						//   nothing left to do

			// Build the Chart bitmap, along with data regions
			Page p = pgs.CurrentPage;
			ChartBase cb=null;
			try
			{
				cb = RunChartBuild(rpt, row);					// Build the chart
                if (!_isHYNEsWonderfulVector.EvaluateBoolean(rpt,row)) //AJM GJL 14082008 'Classic' Rendering 
                {
                    System.Drawing.Image im = cb.Image(rpt);	// Grab the image
                    int height = im.Height;							// save height and width
                    int width = im.Width;

                    MemoryStream ostrm = new MemoryStream();
                    /* The following is a new image saving logic which will allow for higher 
                     * quality images using JPEG with 100% quality
                     * 06122007AJM */
                    System.Drawing.Imaging.ImageCodecInfo[] info;
                    info = ImageCodecInfo.GetImageEncoders();
                    EncoderParameters encoderParameters;
                    encoderParameters = new EncoderParameters(1);
                    // 20022008 AJM GJL - Centralised class with global encoder settings
                    encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, ImageQualityManager.ChartImageQuality);
                    System.Drawing.Imaging.ImageCodecInfo codec = null;
                    for (int i = 0; i < info.Length; i++)
                    {
                        if (info[i].FormatDescription == "JPEG")
                        {
                            codec = info[i];
                            break;
                        }
                    }
                    im.Save(ostrm, codec, encoderParameters);
                    // 06122007AJM The follow has been replaced with the code above
                    //im.Save(ostrm, info);	// generate a jpeg   TODO: get png to work with pdf

                    byte[] ba = ostrm.ToArray();
                    ostrm.Close();
                    PageImage pi = new PageImage(IMAGEFORMAT, ba, width, height);	// Create an image

                    RunPageRegionBegin(pgs);

                    SetPagePositionAndStyle(rpt, pi, row);
                    pi.SI.BackgroundImage = null;	// chart already has the background image

                    if (pgs.CurrentPage.YOffset + pi.Y + pi.H >= pgs.BottomOfPage && !pgs.CurrentPage.IsEmpty())
                    {	// force page break if it doesn't fit on the page
                        pgs.NextOrNew();
                        pgs.CurrentPage.YOffset = OwnerReport.TopOfPage;
                        if (this.YParents != null)
                            pi.Y = 0;
                    }

                    p = pgs.CurrentPage;

                    p.AddObject(pi);	// Put image onto the current page

                    RunPageRegionEnd(pgs);

                    if (!this.PageBreakAtEnd && !IsTableOrMatrixCell(rpt))
                    {
                        float newY = pi.Y + pi.H;
                        p.YOffset += newY;	// bump the y location
                    }
                    SetPagePositionEnd(pgs, pi.Y + pi.H);
                }
                else //Ultimate Rendering - Vector //AJM GJL 14082008
                {
                    System.Drawing.Imaging.Metafile im = cb.Image(rpt);	// Grab the image
                    //im could still be saved to a bitmap at this point
                    //if we were to offer a choice of raster or vector, it would probably
                    //be easiest to draw the chart to the EMF and then save as bitmap if needed
                    int height = im.Height;							// save height and width
                    int width = im.Width;
                    byte[] ba = cb._aStream.ToArray();
                    cb._aStream.Close();

                    PageImage pi = new PageImage(ImageFormat.Wmf, ba, width, height);
                    RunPageRegionBegin(pgs);

                    SetPagePositionAndStyle(rpt, pi, row);
                    pi.SI.BackgroundImage = null;	// chart already has the background image

                    if (pgs.CurrentPage.YOffset + pi.Y + pi.H >= pgs.BottomOfPage && !pgs.CurrentPage.IsEmpty())
                    {	// force page break if it doesn't fit on the page
                        pgs.NextOrNew();
                        pgs.CurrentPage.YOffset = OwnerReport.TopOfPage;
                        if (this.YParents != null)
                            pi.Y = 0;
                    }

                    p = pgs.CurrentPage;

                    //GJL 25072008 - Charts now draw in EMFplus format and not in bitmap. Still using the "PageImage" for the positioning
                    //paging etc, but we don't add it to the page.
                    // ******************************************************************************************************************
                    // New EMF Processing... we want to add the EMF Components to the page and not the actual EMF...
                    EMF emf = new EMF(pi.X, pi.Y, width, height);
                    emf.ProcessEMF(ba); //Process takes the bytearray of EMFplus data and breaks it down into lines,ellipses,text,rectangles
                    //etc... There are still a lot of GDI+ functions I haven't got to (and some I have no intention of getting to!). 
                    foreach (PageItem emfItem in emf.PageItems)
                    {
                        p.AddObject(emfItem);

                    }
                    // ******************************************************************************************************************

                    //p.AddObject(pi);
                    RunPageRegionEnd(pgs);
                    pi.Y += p.YOffset;
                    if (!this.PageBreakAtEnd && !IsTableOrMatrixCell(rpt))
                    {
                        float newY = pi.Y + pi.H;
                        p.YOffset += newY;	// bump the y location
                    }
                    SetPagePositionEnd(pgs, pi.Y + pi.H); //our emf size seems to be bigger than the jpeg...
          
                }
            }
			catch (Exception ex)
			{
				rpt.rl.LogError(8, string.Format("Exception in Chart handling.\n{0}\n{1}", ex.Message, ex.StackTrace));
			}
			finally
			{
				if (cb != null)
					cb.Dispose();
			}

            return;
		}
Ejemplo n.º 39
0
		public int NumeralVariant;	//(Integer) The variant of the digit format to use.

		/// <summary>
		/// Constructor using all defaults for the style.
		/// </summary>
		public StyleInfo()
		{
			BColorLeft = BColorRight = BColorTop = BColorBottom = System.Drawing.Color.Black;	// (Color) Color of the bottom border
			BStyleLeft = BStyleRight = BStyleTop = BStyleBottom = BorderStyleEnum.None;
			// _BorderWdith
			BWidthLeft = BWidthRight = BWidthTop = BWidthBottom = 1;

			BackgroundColor = System.Drawing.Color.Empty;
            BackgroundColorText = string.Empty;
			BackgroundGradientType = BackgroundGradientTypeEnum.None;
			BackgroundGradientEndColor = System.Drawing.Color.Empty;
			BackgroundImage = null;

			FontStyle = FontStyleEnum.Normal;
			_FontFamily = "Arial";
            //WRP 291008 numFmtId should be 0 (Zero) for General format - will be interpreted as a string
            //It has default values in Excel07 as per ECMA-376 standard (SEction 3.8.30) for Office Open XML Excel07
            _Format = "General";  
			FontSize = 10;
			FontWeight = FontWeightEnum.Normal;

			PatternType = patternTypeEnum.None;
			TextDecoration = TextDecorationEnum.None;
			TextAlign = TextAlignEnum.General;
			VerticalAlign = VerticalAlignEnum.Top;
			Color = System.Drawing.Color.Black;
            ColorText = "Black";
            PaddingLeft = PaddingRight = PaddingTop = PaddingBottom = 0;
			LineHeight = 0;
			Direction = DirectionEnum.LTR;
			WritingMode = WritingModeEnum.lr_tb;
			Language = "en-US";
			UnicodeBiDirectional = UnicodeBiDirectionalEnum.Normal;
			Calendar = CalendarEnum.Gregorian;
			NumeralLanguage = Language;
			NumeralVariant=1;
		}
Ejemplo n.º 40
0
        override internal void RunPage(Pages pgs, Row row)
        {
            Report rpt = pgs.Report;

            if (IsHidden(pgs.Report, row))
            {
                return;
            }

            SetPagePositionBegin(pgs);

            // Build the Chart bitmap, along with data regions
            Page p = pgs.CurrentPage;
            ICustomReportItem cri = null;
            Bitmap            bm  = null;

            try
            {
                cri = RdlEngineConfig.CreateCustomReportItem(_Type);
                SetProperties(pgs.Report, row, cri);

                int width = WidthCalc(rpt, pgs.G) -
                            (Style == null? 0 :
                             (Style.EvalPaddingLeftPx(rpt, row) + Style.EvalPaddingRightPx(rpt, row)));
                int height = RSize.PixelsFromPoints(this.HeightOrOwnerHeight) -
                             (Style == null? 0 :
                              (Style.EvalPaddingTopPx(rpt, row) + Style.EvalPaddingBottomPx(rpt, row)));
                bm = new Bitmap(width, height);
                cri.DrawImage(bm);

                MemoryStream ostrm = new MemoryStream();
                bm.Save(ostrm, IMAGEFORMAT);    // generate a jpeg   TODO: get png to work with pdf

                byte[] ba = ostrm.ToArray();
                ostrm.Close();
                PageImage pi = new PageImage(IMAGEFORMAT, ba, width, height);   // Create an image
                pi.Sizing = ImageSizingEnum.Clip;
//                RunPageRegionBegin(pgs);

                SetPagePositionAndStyle(rpt, pi, row);

                if (pgs.CurrentPage.YOffset + pi.Y + pi.H >= pgs.BottomOfPage && !pgs.CurrentPage.IsEmpty())
                {       // force page break if it doesn't fit on the page
                    pgs.NextOrNew();
                    pgs.CurrentPage.YOffset = OwnerReport.TopOfPage;
                    if (this.YParents != null)
                    {
                        pi.Y = 0;
                    }
                }

                p = pgs.CurrentPage;

                p.AddObject(pi);        // Put image onto the current page

                //              RunPageRegionEnd(pgs);

                if (!this.PageBreakAtEnd && !IsTableOrMatrixCell(rpt))
                {
                    float newY = pi.Y + pi.H;
                    p.YOffset += newY;  // bump the y location
                }
                SetPagePositionEnd(pgs, pi.Y + pi.H);
            }
            catch (Exception ex)
            {
                rpt.rl.LogError(8, string.Format("Exception in CustomReportItem handling: {0}", ex.Message));
            }
            finally
            {
                if (cri != null)
                {
                    cri.Dispose();
                }
            }

            return;
        }