Esempio n. 1
0
        protected override void DrawCore(GeoCanvas canvas, Collection <SimpleCandidate> labelsInAllLayers)
        {
            if (String.IsNullOrEmpty(projectPath))
            {
                return;
            }
            base.DrawCore(canvas, labelsInAllLayers);

            double         oneToOneScale      = PrinterHelper.GetPointsPerGeographyUnit(canvas.MapUnit);
            RectangleShape currentBoundingBox = GetBoundingBox();

            string drawingText = projectPath;

            if (printerWrapMode == PrinterWrapMode.WrapText)
            {
                float drawingSize = (float)(Font.Size * oneToOneScale / canvas.CurrentScale);
                drawingFont = new GeoFont(Font.FontName, drawingSize, Font.Style);

                drawingText = WrapText(canvas, currentBoundingBox, drawingFont, projectPath);
            }
            else
            {
                // 1st time draw the layer, change the fontsize to match up the boundingBox
                if (lastBoundingBox == null)
                {
                    float drawingSize = font.Size;
                    if (currentBoundingBox.GetWellKnownText() != new RectangleShape().GetWellKnownText())
                    {
                        drawingSize = GetFontSizeByBoundingBox(canvas, Font, drawingText, currentBoundingBox);
                    }
                    drawingFont = new GeoFont(font.FontName, drawingSize, font.Style);

                    drawingSize = (float)(drawingSize / oneToOneScale * canvas.CurrentScale);
                    Font        = new GeoFont(font.FontName, drawingSize, font.Style);
                }
                else
                {
                    // change the boundingBox, change the fontsize to match up the boundingBox
                    if ((Math.Round(lastBoundingBox.Width, 8) != Math.Round(currentBoundingBox.Width, 8)) ||
                        (Math.Round(lastBoundingBox.Height, 8) != Math.Round(currentBoundingBox.Height, 8)))     // Change font size when resize
                    {
                        float drawingSize = GetFontSizeByBoundingBox(canvas, drawingFont, drawingText, currentBoundingBox);
                        drawingFont = new GeoFont(font.FontName, drawingSize, font.Style);

                        drawingSize = (float)(drawingSize / oneToOneScale * canvas.CurrentScale);
                        Font        = new GeoFont(font.FontName, drawingSize, font.Style);
                    }
                    else
                    {
                        float drawingSize = (float)(Font.Size * oneToOneScale / canvas.CurrentScale);
                        drawingFont = new GeoFont(font.FontName, drawingSize, font.Style);
                    }
                }

                lastBoundingBox = currentBoundingBox;
            }

            canvas.DrawTextWithWorldCoordinate(drawingText, drawingFont, TextBrush, currentBoundingBox.GetCenterPoint().X, currentBoundingBox.GetCenterPoint().Y, DrawingLevel.LabelLevel);
        }