Пример #1
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();
     }
 }
Пример #2
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();
            }
        }
Пример #3
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();
                // 140208AJM Better JPEG Encoding

                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(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);

                // im.Save(ostrm, imf, encoderParameters);

                //END 140208AJM
                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;
        }
Пример #4
0
 internal PageImage PgImage;                 // When ConstantImage is true this will save the PageImage for reuse
 internal WorkClass()
 {
     PgImage = null;
 }
Пример #5
0
        private string _FontFamily; //(string)Name of the font family Default: Arial -- allow comma separated value?

        #endregion Fields

        #region Constructors

        /// <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;
        }
Пример #6
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;
        }
Пример #7
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);
        }
        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;
        }
Пример #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;
        }
Пример #10
0
        /// <summary>
        /// Render all the objects in a page
        /// </summary>
        private void processPage(Pages pages, IEnumerable page)
        {
            //loop thru the items in the page
            foreach (PageItem pageItem in page)
            {
                if (pageItem.SI.BackgroundImage != null)
                {
                    //put out any background image
                    PageImage backgroundImage = pageItem.SI.BackgroundImage;

                    float imageWidth  = RSize.PointsFromPixels(pages.G, backgroundImage.SamplesW);
                    float imageHeight = RSize.PointsFromPixels(pages.G, backgroundImage.SamplesH);
                    int   repeatX     = 0;
                    int   repeatY     = 0;
                    float itemWidth   = pageItem.W - (pageItem.SI.PaddingLeft + pageItem.SI.PaddingRight);
                    float itemHeight  = pageItem.H - (pageItem.SI.PaddingTop + pageItem.SI.PaddingBottom);

                    switch (backgroundImage.Repeat)
                    {
                    case ImageRepeat.Repeat:
                        repeatX = (int)Math.Floor(itemWidth / imageWidth);
                        repeatY = (int)Math.Floor(itemHeight / imageHeight);
                        break;

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

                    case ImageRepeat.RepeatY:
                        repeatY = (int)Math.Floor(itemHeight / imageHeight);
                        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  = pageItem.X + pageItem.SI.PaddingLeft;
                    float currY  = pageItem.Y + pageItem.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 * imageWidth;
                            currY = startY + j * imageHeight;

                            addImage(backgroundImage.SI, currX, currY, imageWidth, imageHeight, RectangleF.Empty,
                                     backgroundImage.ImageData, null, pageItem.Tooltip);
                        }
                    }
                }
                else if (pageItem is PageTextHtml)
                {
                    PageTextHtml pageTextHtml = pageItem as PageTextHtml;
                    pageTextHtml.Build(pages.G);
                    processPage(pages, pageTextHtml);
                    continue;
                }
                else if (pageItem is PageText)
                {
                    PageText pageText = pageItem as PageText;
                    float[]  textwidth;
                    string[] measureStrings = RenderUtility.MeasureString(pageText, pages.G, out textwidth);
                    addText(pageText.X, pageText.Y, pageText.W, pageText.H, measureStrings, pageText.SI, textwidth, pageText.CanGrow, pageText.HyperLink, pageText.NoClip, pageText.Tooltip);
                    continue;
                }
                else if (pageItem is PageLine)
                {
                    PageLine pageLine = pageItem as PageLine;
                    addLine(pageLine.X, pageLine.Y, pageLine.X2, pageLine.Y2, pageLine.SI);
                    continue;
                }
                else if (pageItem is PageEllipse)
                {
                    PageEllipse pageEllipse = pageItem as PageEllipse;
                    addEllipse(pageEllipse.X, pageEllipse.Y, pageEllipse.W, pageEllipse.H, pageEllipse.SI, pageEllipse.HyperLink);
                    continue;
                }
                else if (pageItem is PageImage)
                {
                    PageImage pageImage = pageItem as PageImage;

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

                    //work rectangle
                    RectangleF adjustedRect;
                    RectangleF clipRect = RectangleF.Empty;
                    switch (pageImage.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, RSize.PointsFromPixels(pages.G, pageImage.SamplesW),
                                                      RSize.PointsFromPixels(pages.G, pageImage.SamplesH));
                        clipRect = new RectangleF(r2.Left, r2.Top, r2.Width, r2.Height);
                        break;

                    case ImageSizingEnum.FitProportional:
                        float height;
                        float width;
                        float ratioIm = (float)pageImage.SamplesH / pageImage.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 (pageImage.ImgFormat != System.Drawing.Imaging.ImageFormat.Wmf && pageImage.ImgFormat != System.Drawing.Imaging.ImageFormat.Emf)
                    {
                        addImage(pageImage.SI, adjustedRect.X, adjustedRect.Y, adjustedRect.Width, adjustedRect.Height,
                                 clipRect, pageImage.ImageData, pageImage.HyperLink, pageImage.Tooltip);
                    }
                    continue;
                }
                else if (pageItem is PageRectangle)
                {
                    PageRectangle pageRectangle = pageItem as PageRectangle;
                    addRectangle(pageRectangle.X, pageRectangle.Y, pageRectangle.W, pageRectangle.H, pageItem.SI, pageItem.HyperLink, pageItem.Tooltip);
                    continue;
                }
                else if (pageItem is PagePie)
                {
                    PagePie pagePie = pageItem as PagePie;
                    addPie(pagePie.X, pagePie.Y, pagePie.W, pagePie.H, pageItem.SI, pageItem.HyperLink, pageItem.Tooltip);
                    continue;
                }
                else if (pageItem is PagePolygon)
                {
                    PagePolygon pagePolygon = pageItem as PagePolygon;
                    addPolygon(pagePolygon.Points, pageItem.SI, pageItem.HyperLink);
                    continue;
                }
                else if (pageItem is PageCurve)
                {
                    PageCurve pageCurve = pageItem as PageCurve;
                    addCurve(pageCurve.Points, pageItem.SI);
                    continue;
                }
            }
        }
Пример #11
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);
            }
        }
Пример #12
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 = EngineConfig.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();
                // 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;
        }
Пример #13
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;
        }
Пример #14
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
            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;
        }
Пример #15
0
        private void BuildPrivate(Graphics g)
        {
            this.SI.TextAlign     = TextAlignEnum.Left;
            this.SI.VerticalAlign = VerticalAlignEnum.Top;
            this.SI.WritingMode   = WritingModeEnum.lr_tb;

            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;
            _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;
            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>();

            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);
                        maxLineHeight = 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();
                    }
                    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)
                    {
                        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;
        }
Пример #16
0
        internal override 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 = EngineConfig.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();
                // 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;
        }
Пример #17
0
        internal override 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;
        }
            internal PageImage PgImage; // When ConstantImage is true this will save the PageImage for reuse

            #endregion Fields

            #region Constructors

            internal WorkClass()
            {
                PgImage=null;
            }
Пример #19
0
        internal override 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();
                // 140208AJM Better JPEG Encoding

                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(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);

                // im.Save(ostrm, imf, encoderParameters);

                //END 140208AJM
                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;
        }