0

I am trying to set the font size of a legend on ZedGraph. However, the size never appears as I set it.

I have browsed through the GraphPane.Legend.FontSpec object and found the scaledSize private variable. This appears to be the size that is actually displaying. e.g. I set the Size to 10 but the scaledSize = 16.09

Where does this value come from? I have looked through my code (I took over the project from someone else and it's a large project so it's not easy to find) and elsewhere in the ZedGraph object for some sort of scaling item, but can't find how this value could be set. Is it auto-calculated somehow?

I've searched the 'net for the answer too but to no avail.

Thomas Ayoub
  • 29,063
  • 15
  • 95
  • 142
komodosp
  • 3,316
  • 2
  • 30
  • 59

2 Answers2

0

This is the setter of Size :

set
{
    if ( value != _size )
    {
        Remake( _scaledSize / _size * value, _size, ref _scaledSize,
                    ref _font );
        _size = value;
    }
}
//...

/// <summary>
/// Recreate the font based on a new scaled size.  The font
/// will only be recreated if the scaled size has changed by
/// at least 0.1 points.
/// </summary>
/// <param name="scaleFactor">
/// The scaling factor to be used for rendering objects.  This is calculated and
/// passed down by the parent <see cref="GraphPane"/> object using the
/// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust
/// font sizes, etc. according to the actual size of the graph.
/// </param>
/// <param name="size">The unscaled size of the font, in points</param>
/// <param name="scaledSize">The scaled size of the font, in points</param>
/// <param name="font">A reference to the <see cref="Font"/> object</param>
private void Remake( float scaleFactor, float size, ref float scaledSize, ref Font font )
{
    float newSize = size * scaleFactor;

    float oldSize = ( font == null ) ? 0.0f : font.Size;

    // Regenerate the font only if the size has changed significantly
    if ( font == null ||
            Math.Abs( newSize - oldSize ) > 0.1 ||
            font.Name != this.Family ||
            font.Bold != _isBold ||
            font.Italic != _isItalic ||
            font.Underline != _isUnderline )
    {
        FontStyle style = FontStyle.Regular;
        style = ( _isBold ? FontStyle.Bold : style ) |
                    ( _isItalic ? FontStyle.Italic : style ) |
                     ( _isUnderline ? FontStyle.Underline : style );

        scaledSize = size * (float)scaleFactor;
        font = new Font( _family, scaledSize, style, GraphicsUnit.World );
    }
}

The interesting lines are:

scaledSize = size * (float)scaleFactor;
font = new Font( _family, scaledSize, style, GraphicsUnit.World );

Which means that your size is scaled using PaneBase.CalcScaleFactor. You should take a look at this last one

Thomas Ayoub
  • 29,063
  • 15
  • 95
  • 142
0

ZedGraph automatically scales all fonts based on the size of the pane.

This is controlled through the GraphPane.IsFontScaled property. Set this to false and your fonts should stay the size you have set.

discomurray
  • 14,411
  • 1
  • 21
  • 11