示例#1
0
        // All label-vertexes are assigned the same vertical size independently of text descenders etc.
        private Dictionary <Vertex, SKSize> ComputeUniformVertexSizes(IEnumerable <Vertex> vertexes, float textHeight, float padding)
        {
            SKRect fitRect = MeasureVertexText(vertexes, textHeight);
            Dictionary <Vertex, SKSize> vertexSizes = new Dictionary <Vertex, SKSize>();

            using (var paint = new SKPaint()) {
                paint.TextSize = textHeight; paint.IsAntialias = true; paint.Color = SKColors.Black; paint.IsStroke = false;
                var bounds = new SKRect();
                foreach (Vertex v in vertexes)
                {
                    if (v is Vertex_Label)
                    {
                        float width = GraphLayout.PaintMeasureText(paint, (v as Vertex_Label).Label, ref bounds);
                        vertexSizes[v] = new SKSize(
                            width + 2 * padding, // use width, not (bounds.Right - bounds.Left)
                            (fitRect.Bottom - fitRect.Top) + 2 * padding);
                    }
                    else if (v is Vertex_Rectangle)
                    {
                        SKSize size = (v as Vertex_Rectangle).Size;
                        vertexSizes[v] = new SKSize(textHeight * size.Width, textHeight * size.Height);
                    }
                    else if (v is Vertex_Routing)
                    {
                        vertexSizes[v] = new SKSize(0, 0);
                    }
                }
            }
            return(vertexSizes);
        }
示例#2
0
        // Get the bounding rect of the text found in all the vertices (used mostly for bounding hight)
        private SKRect MeasureVertexText(IEnumerable <Vertex> vertexes, float textHeight)
        {
            SKRect fitRect = new SKRect(0, 0, 0, 0);

            using (var paint = new SKPaint()) {
                paint.TextSize = textHeight; paint.IsAntialias = true; paint.Color = SKColors.Black; paint.IsStroke = false;
                var bounds = new SKRect();
                foreach (Vertex v in vertexes)
                {
                    if (v is Vertex_Label)
                    {
                        float width = GraphLayout.PaintMeasureText(paint, (v as Vertex_Label).Label, ref bounds);
                        fitRect.Left   = Math.Min(fitRect.Left, bounds.Left);
                        fitRect.Top    = Math.Min(fitRect.Top, bounds.Top);
                        fitRect.Right  = Math.Max(fitRect.Right, bounds.Right);
                        fitRect.Bottom = Math.Max(fitRect.Bottom, bounds.Bottom);
                    }
                }
            }
            return(fitRect);
        }