Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/09/14 15:14:38 (11 years ago)
Author:
bburlacu
Message:

#1265: Added MaximumFontSize property to RectangularPrimitiveBase.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Primitives/RectangularPrimitiveBase.cs

    r10518 r10831  
    4343    public string Text { get; set; }
    4444    public Font Font { get; set; }
     45    public float MaximumFontSize { get; set; }
    4546
    4647    protected RectangularPrimitiveBase(IChart chart, PointD lowerLeft, PointD upperRight)
     
    4849      selectionRectangles = new Group(chart);
    4950      SetPosition(lowerLeft, upperRight);
     51
     52      MaximumFontSize = 12;
    5053    }
    5154    protected RectangularPrimitiveBase(IChart chart, double x1, double y1, double x2, double y2)
     
    137140    }
    138141
    139     protected virtual void DrawText(Graphics graphics) {  // draw the text in the center of the bounding rectangle4
     142    protected virtual void DrawText(Graphics graphics) {
     143      // draw the text in the center of the bounding rectangle
    140144      var p = Chart.TransformWorldToPixel(new PointD(LowerLeft.X, LowerLeft.Y));
    141145      var s = Chart.TransformWorldToPixel(Size);
     146
    142147      var stringSize = graphics.MeasureString(Text, Font);
    143       var fontSize = Font.Size * s.Width / stringSize.Width;
    144       if (fontSize > 12) fontSize = 12; // limit maximum font size so that nodes look nicer
     148      float fontSize = (int)(Math.Round(Font.Size * s.Width / stringSize.Width));
     149      if (fontSize > MaximumFontSize) { fontSize = MaximumFontSize; }
    145150      Font = new Font(Font.FontFamily, fontSize, GraphicsUnit.Pixel);
    146151      stringSize = graphics.MeasureString(Text, Font);
Note: See TracChangeset for help on using the changeset viewer.