예제 #1
0
        private SizeF DrawString(Graphics graphics, string text, System.Drawing.Point position, ReportDefintion reportDefinition, int fontType = 0, bool drawString = true)
        {
            Font       font;
            SolidBrush brush = new SolidBrush(Color.Black);

            graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
            switch (fontType)
            {
            case 1:
                font = Fontstyles.getHadlineFont();
                break;

            default:
                font = Fontstyles.getDefaultFont();
                break;
            }
            SizeF size = graphics.MeasureString(text, font);

            if (drawString)
            {
                StringFormat format = new StringFormat();
                format.Trimming = StringTrimming.None;
                RectangleF rect = new RectangleF(position, size);
                graphics.DrawString(text, font, brush, rect);
            }


            return(size);
        }
예제 #2
0
        private SizeF CalcAndDrawInfoImage(Bitmap infoImage, string[] layers, EmsgGisReportParameter reportparams, bool drawImage, ReportDefintion reportDefinition)
        {
            InfoImageHeightAndCurrentPosition currentPosAndSize       = new InfoImageHeightAndCurrentPosition(reportDefinition.dpi);
            ServerConfigurationProvider       serverConfigurationProv = new ServerConfigurationProvider();

            using (Graphics graphics = Graphics.FromImage(infoImage))
            {
                graphics.SmoothingMode = SmoothingMode.HighQuality;
                #region setFilterparams

                currentPosAndSize.IncreaseSizeAndPositionY(DrawString(graphics, localizationService.GetLocalizedLegendLabel("Filterparameter"), currentPosAndSize.GetCurrentPosition(), reportDefinition, 1, drawImage));
                currentPosAndSize.IncreaseHeightAndPositionY(SpaceAndOffsets.getSpaceYBetweenHeadline(reportDefinition.dpi));

                float valueOffset = 0;
                if (reportparams != null)
                {
                    foreach (FilterListPo filterItem in reportparams.Filterparams)
                    {
                        valueOffset = Math.Max(valueOffset, graphics.MeasureString(filterItem.Name, Fontstyles.getDefaultFont()).Width);
                    }

                    foreach (FilterListPo filterItem in reportparams.Filterparams)
                    {
                        Point filterNamePos  = new Point(currentPosAndSize.GetCurrentPosition().X, currentPosAndSize.GetCurrentPosition().Y);
                        Point filterValuePos = new Point(currentPosAndSize.GetCurrentPosition().X + Convert.ToInt32(valueOffset), currentPosAndSize.GetCurrentPosition().Y);

                        SizeF filterparamSize = DrawString(graphics, filterItem.Name + ":", filterNamePos, reportDefinition, drawString: drawImage);
                        SizeF filterValueSize = DrawString(graphics, " " + filterItem.Value, filterValuePos, reportDefinition, drawString: drawImage);

                        SizeF lineSize = new SizeF(filterparamSize.Width + filterValueSize.Width,
                                                   filterparamSize.Height < filterValueSize.Height ? filterValueSize.Height : filterparamSize.Height);

                        currentPosAndSize.IncreaseSizeAndPositionY(lineSize);
                        currentPosAndSize.IncreaseHeightAndPositionY(SpaceAndOffsets.getSpaceYBetweenLayers(reportDefinition.dpi));
                    }
                }

                #endregion

                Point lineStart = new Point(0, currentPosAndSize.GetCurrentPosition().Y + SpaceAndOffsets.getSpaceYBetweenLegendAndFilter(reportDefinition.dpi) / 2);
                Point lineEnd   = new Point(infoImage.Width - 2, currentPosAndSize.GetCurrentPosition().Y + SpaceAndOffsets.getSpaceYBetweenLegendAndFilter(reportDefinition.dpi) / 2);
                graphics.DrawLine(new Pen(Color.Black, (int)Math.Ceiling(0.01 * reportDefinition.dpi)), lineStart, lineEnd);

                currentPosAndSize.IncreaseHeightAndPositionY(SpaceAndOffsets.getSpaceYBetweenLegendAndFilter(reportDefinition.dpi));

                #region set legend

                if (!layers.IsEmpty())
                {
                    currentPosAndSize.IncreaseSizeAndPositionY(DrawString(graphics, localizationService.GetLocalizedLegendLabel("Legende"), currentPosAndSize.GetCurrentPosition(), reportDefinition, 1, drawImage));
                    currentPosAndSize.IncreaseHeightAndPositionY(SpaceAndOffsets.getSpaceYBetweenHeadline(reportDefinition.dpi));


                    foreach (var layer in layers)
                    {
                        string layername = layer;
                        Tuple <string, string> info;
                        if (this.layerInfo.TryGetValue(layername, out info))
                        {
                            layername = info.Item2;
                        }
                        currentPosAndSize.IncreaseSizeAndPositionY(DrawString(graphics, layername, currentPosAndSize.GetCurrentPosition(), reportDefinition, 2, drawImage));
                        Bitmap bm = new Bitmap(this.GetLegendStream(layer, dpi: reportDefinition.dpi, reportParameter: reportparams));
                        bm.SetResolution(reportDefinition.dpi, reportDefinition.dpi);
                        if (drawImage)
                        {
                            graphics.DrawImage(bm, currentPosAndSize.GetCurrentPosition().X, currentPosAndSize.GetCurrentPosition().Y);
                        }
                        currentPosAndSize.IncreaseSizeAndPositionY(new SizeF(bm.Width, bm.Height));
                        currentPosAndSize.IncreaseHeightAndPositionY(SpaceAndOffsets.getSpaceYBetweenLayers(reportDefinition.dpi));
                    }

                    lineStart = new Point(0, currentPosAndSize.GetCurrentPosition().Y + SpaceAndOffsets.getSpaceYBetweenLegendAndFilter(reportDefinition.dpi) / 2);
                    lineEnd   = new Point(infoImage.Width - 2, currentPosAndSize.GetCurrentPosition().Y + SpaceAndOffsets.getSpaceYBetweenLegendAndFilter(reportDefinition.dpi) / 2);
                    graphics.DrawLine(new Pen(Color.Black, (int)Math.Ceiling(0.01 * reportDefinition.dpi)), lineStart, lineEnd);

                    currentPosAndSize.IncreaseHeightAndPositionY(SpaceAndOffsets.getSpaceYBetweenLegendAndFilter(reportDefinition.dpi));
                    currentPosAndSize.IncreaseSizeAndPositionY(DrawString(graphics, localizationService.GetLocalizedLegendLabel("MapReportRedBox"), currentPosAndSize.GetCurrentPosition(), reportDefinition, drawString: drawImage));
                    //margin: resolutions not in multiple of 300 dpi may cause rounding errors resulting in 1 pixel of the MapReportRedBox text to be cut of, therefore safity margin
                    currentPosAndSize.IncreaseHeightAndPositionY(SpaceAndOffsets.getSpaceYMargin(reportDefinition.dpi));
                }
                #endregion
            }

            return(currentPosAndSize.GetInfoImageSize());
        }