Class FontSpec
The FontSpec class is a generic font class that maintains the font family, attributes, colors, border and fill modes, font size, and angle information. This class can render text with a variety of alignment options using the AlignH and AlignV parameters in the Draw(Graphics, PaneBase, String, Single, Single, AlignH, AlignV, Single) method.
Inherited Members
Namespace: ZedGraph
Assembly: ZedGraph.dll
Syntax
[Serializable]
public class FontSpec : ICloneable, ISerializable
Constructors
| Improve this Doc View SourceFontSpec()
Construct a FontSpec object with default properties.
Declaration
public FontSpec()
FontSpec(SerializationInfo, StreamingContext)
Constructor for deserializing objects
Declaration
protected FontSpec(SerializationInfo info, StreamingContext context)
Parameters
Type | Name | Description |
---|---|---|
SerializationInfo | info | A SerializationInfo instance that defines the serialized data |
StreamingContext | context | A StreamingContext instance that contains the serialized data |
FontSpec(String, Single, Color, Boolean, Boolean, Boolean)
Construct a FontSpec object with the given properties. All other properties are defaulted according to the values specified in the FontSpec.Default default class.
Declaration
public FontSpec(string family, float size, Color color, bool isBold, bool isItalic, bool isUnderline)
Parameters
Type | Name | Description |
---|---|---|
String | family | A text string representing the font family (default is "Arial") |
Single | size | A size of the font in points. This size will be scaled based on the ratio of the Rect dimension to the BaseDimension of the GraphPane object. |
Color | color | The color with which to render the font |
Boolean | isBold | true for a bold typeface, false otherwise |
Boolean | isItalic | true for an italic typeface, false otherwise |
Boolean | isUnderline | true for an underlined font, false otherwise |
FontSpec(String, Single, Color, Boolean, Boolean, Boolean, Color, Brush, FillType)
Construct a FontSpec object with the given properties. All other properties are defaulted according to the values specified in the FontSpec.Default default class.
Declaration
public FontSpec(string family, float size, Color color, bool isBold, bool isItalic, bool isUnderline, Color fillColor, Brush fillBrush, FillType fillType)
Parameters
Type | Name | Description |
---|---|---|
String | family | A text string representing the font family (default is "Arial") |
Single | size | A size of the font in points. This size will be scaled based on the ratio of the Rect dimension to the BaseDimension of the GraphPane object. |
Color | color | The color with which to render the font |
Boolean | isBold | true for a bold typeface, false otherwise |
Boolean | isItalic | true for an italic typeface, false otherwise |
Boolean | isUnderline | true for an underlined font, false otherwise |
Color | fillColor | The Color to use for filling in the text background |
Brush | fillBrush | The Brush to use for filling in the text background |
FillType | fillType | The FillType to use for the text background |
FontSpec(FontSpec)
The Copy Constructor
Declaration
public FontSpec(FontSpec rhs)
Parameters
Type | Name | Description |
---|---|---|
FontSpec | rhs | The FontSpec object from which to copy |
Fields
| Improve this Doc View Sourceschema
Current schema value that defines the version of the serialized file
Declaration
public const int schema = 10
Field Value
Type | Description |
---|---|
Int32 |
Properties
| Improve this Doc View SourceAngle
The angle at which this FontSpec object is drawn.
Declaration
public float Angle { get; set; }
Property Value
Type | Description |
---|---|
Single | The angle of the font, measured in anti-clockwise degrees from horizontal. Negative values are permitted. |
Border
Gets or sets the Border class used to draw the border border around this text.
Declaration
public Border Border { get; set; }
Property Value
Type | Description |
---|---|
Border |
DropShadowAngle
Gets or sets the offset angle of the drop shadow for this FontSpec.
Declaration
public float DropShadowAngle { get; set; }
Property Value
Type | Description |
---|---|
Single | The angle, measured in anti-clockwise degrees from horizontal. Negative values are permitted. |
Remarks
This value only applies if IsDropShadow is true.
See Also
| Improve this Doc View SourceDropShadowColor
Gets or sets the color of the drop shadow for this FontSpec.
Declaration
public Color DropShadowColor { get; set; }
Property Value
Type | Description |
---|---|
Color |
Remarks
This value only applies if IsDropShadow is true.
See Also
| Improve this Doc View SourceDropShadowOffset
Gets or sets the offset distance of the drop shadow for this FontSpec.
Declaration
public float DropShadowOffset { get; set; }
Property Value
Type | Description |
---|---|
Single | The offset distance, measured as a fraction of the scaled font height. |
Remarks
This value only applies if IsDropShadow is true.
See Also
| Improve this Doc View SourceFamily
The font family name for this FontSpec.
Declaration
public string Family { get; set; }
Property Value
Type | Description |
---|---|
String | A text string with the font family name, e.g., "Arial" |
Fill
Gets or sets the Fill data for this FontSpec, which controls how the background behind the text is filled.
Declaration
public Fill Fill { get; set; }
Property Value
Type | Description |
---|---|
Fill |
FontColor
The color of the font characters for this FontSpec. Note that the border and background colors are set using the Color and Color properties, respectively.
Declaration
public Color FontColor { get; set; }
Property Value
Type | Description |
---|---|
Color | A system Color reference. |
IsAntiAlias
Gets or sets a value that determines if the FontSpec will be drawn using anti-aliasing logic within GDI+.
Declaration
public bool IsAntiAlias { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
Remarks
If this property is set to true, it will override the current setting of SmoothingMode by setting the value temporarily to HighQuality. If this property is set to false, the the current setting of SmoothingMode will be left as-is.
IsBold
Determines whether this FontSpec is drawn with bold typeface.
Declaration
public bool IsBold { get; set; }
Property Value
Type | Description |
---|---|
Boolean | A boolean value, true for bold, false for normal |
IsDropShadow
Gets or sets a value that determines if the FontSpec will be displayed with a drop shadow.
Declaration
public bool IsDropShadow { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
See Also
| Improve this Doc View SourceIsItalic
Determines whether this FontSpec is drawn with italic typeface.
Declaration
public bool IsItalic { get; set; }
Property Value
Type | Description |
---|---|
Boolean | A boolean value, true for italic, false for normal |
IsUnderline
Determines whether this FontSpec is drawn with underlined typeface.
Declaration
public bool IsUnderline { get; set; }
Property Value
Type | Description |
---|---|
Boolean | A boolean value, true for underline, false for normal |
Size
The size of the font for this FontSpec object.
Declaration
public float Size { get; set; }
Property Value
Type | Description |
---|---|
Single | The size of the font, measured in points (1/72 inch). |
StringAlignment
Determines the alignment with which this FontSpec object is drawn. This alignment really only affects multi-line strings.
Declaration
public StringAlignment StringAlignment { get; set; }
Property Value
Type | Description |
---|---|
StringAlignment | A StringAlignment enumeration. |
Methods
| Improve this Doc View SourceBoundingBox(Graphics, String, Single)
Get a SizeF struct representing the width and height of the bounding box for the specified text string, based on the scaled font size.
Declaration
public SizeF BoundingBox(Graphics g, string text, float scaleFactor)
Parameters
Type | Name | Description |
---|---|---|
Graphics | g | A graphic device object to be drawn into. This is normally e.Graphics from the PaintEventArgs argument to the Paint() method. |
String | text | The text string for which the width is to be calculated |
Single | scaleFactor | The scaling factor to be used for rendering objects. This is calculated and passed down by the parent GraphPane object using the CalcScaleFactor() method, and is used to proportionally adjust font sizes, etc. according to the actual size of the graph. |
Returns
Type | Description |
---|---|
SizeF | The scaled text dimensions, in pixels, in the form of a SizeF struct |
Remarks
This routine differs from MeasureString(Graphics, String, Single) in that it takes into account the rotation angle of the font, and gives the dimensions of the bounding box that encloses the text at the specified angle.
BoundingBox(Graphics, String, Single, SizeF)
Get a SizeF struct representing the width and height of the bounding box for the specified text string, based on the scaled font size.
Declaration
public SizeF BoundingBox(Graphics g, string text, float scaleFactor, SizeF layoutArea)
Parameters
Type | Name | Description |
---|---|---|
Graphics | g | A graphic device object to be drawn into. This is normally e.Graphics from the PaintEventArgs argument to the Paint() method. |
String | text | The text string for which the width is to be calculated |
Single | scaleFactor | The scaling factor to be used for rendering objects. This is calculated and passed down by the parent GraphPane object using the CalcScaleFactor() method, and is used to proportionally adjust font sizes, etc. according to the actual size of the graph. |
SizeF | layoutArea | The limiting area (SizeF) into which the text must fit. The actual rectangle may be smaller than this, but the text will be wrapped to accomodate the area. |
Returns
Type | Description |
---|---|
SizeF | The scaled text dimensions, in pixels, in the form of a SizeF struct |
Remarks
This routine differs from MeasureString(Graphics, String, Single) in that it takes into account the rotation angle of the font, and gives the dimensions of the bounding box that encloses the text at the specified angle.
BoundingBoxTenPower(Graphics, String, Single)
Get a SizeF struct representing the width and height of the bounding box for the specified text string, based on the scaled font size.
Declaration
public SizeF BoundingBoxTenPower(Graphics g, string text, float scaleFactor)
Parameters
Type | Name | Description |
---|---|---|
Graphics | g | A graphic device object to be drawn into. This is normally e.Graphics from the PaintEventArgs argument to the Paint() method. |
String | text | The text string for which the width is to be calculated |
Single | scaleFactor | The scaling factor to be used for rendering objects. This is calculated and passed down by the parent GraphPane object using the CalcScaleFactor() method, and is used to proportionally adjust font sizes, etc. according to the actual size of the graph. |
Returns
Type | Description |
---|---|
SizeF | The scaled text dimensions, in pixels, in the form of a SizeF struct |
Remarks
This special case method will show the specified string as a power of 10, superscripted and downsized according to the SuperSize and SuperShift. This routine differs from MeasureString(Graphics, String, Single) in that it takes into account the rotation angle of the font, and gives the dimensions of the bounding box that encloses the text at the specified angle.
Clone()
Typesafe, deep-copy clone method.
Declaration
public FontSpec Clone()
Returns
Type | Description |
---|---|
FontSpec | A new, independent copy of this class |
Draw(Graphics, PaneBase, String, Single, Single, AlignH, AlignV, Single)
Render the specified text
to the specifed
Graphics device. The text, border, and fill options
will be rendered as required.
Declaration
public void Draw(Graphics g, PaneBase pane, string text, float x, float y, AlignH alignH, AlignV alignV, float scaleFactor)
Parameters
Type | Name | Description |
---|---|---|
Graphics | g | A graphic device object to be drawn into. This is normally e.Graphics from the PaintEventArgs argument to the Paint() method. |
PaneBase | pane | A reference to the PaneBase object that is the parent or owner of this object. |
String | text | A string value containing the text to be displayed. This can be multiple lines, separated by newline ('\n') characters |
Single | x | The X location to display the text, in screen
coordinates, relative to the horizontal (AlignH)
alignment parameter |
Single | y | The Y location to display the text, in screen
coordinates, relative to the vertical (AlignV
alignment parameter |
AlignH | alignH | A horizontal alignment parameter specified using the AlignH enum type |
AlignV | alignV | A vertical alignment parameter specified using the AlignV enum type |
Single | scaleFactor | The scaling factor to be used for rendering objects. This is calculated and passed down by the parent GraphPane object using the CalcScaleFactor() method, and is used to proportionally adjust font sizes, etc. according to the actual size of the graph. |
Draw(Graphics, PaneBase, String, Single, Single, AlignH, AlignV, Single, SizeF)
Render the specified text
to the specifed
Graphics device. The text, border, and fill options
will be rendered as required.
Declaration
public void Draw(Graphics g, PaneBase pane, string text, float x, float y, AlignH alignH, AlignV alignV, float scaleFactor, SizeF layoutArea)
Parameters
Type | Name | Description |
---|---|---|
Graphics | g | A graphic device object to be drawn into. This is normally e.Graphics from the PaintEventArgs argument to the Paint() method. |
PaneBase | pane | A reference to the PaneBase object that is the parent or owner of this object. |
String | text | A string value containing the text to be displayed. This can be multiple lines, separated by newline ('\n') characters |
Single | x | The X location to display the text, in screen
coordinates, relative to the horizontal (AlignH)
alignment parameter |
Single | y | The Y location to display the text, in screen
coordinates, relative to the vertical (AlignV
alignment parameter |
AlignH | alignH | A horizontal alignment parameter specified using the AlignH enum type |
AlignV | alignV | A vertical alignment parameter specified using the AlignV enum type |
Single | scaleFactor | The scaling factor to be used for rendering objects. This is calculated and passed down by the parent GraphPane object using the CalcScaleFactor() method, and is used to proportionally adjust font sizes, etc. according to the actual size of the graph. |
SizeF | layoutArea | The limiting area (SizeF) into which the text must fit. The actual rectangle may be smaller than this, but the text will be wrapped to accomodate the area. |
DrawTenPower(Graphics, GraphPane, String, Single, Single, AlignH, AlignV, Single)
Render the specified text
to the specifed
Graphics device. The text, border, and fill options
will be rendered as required. This special case method will show the
specified text as a power of 10, using the SuperSize
and SuperShift.
Declaration
public void DrawTenPower(Graphics g, GraphPane pane, string text, float x, float y, AlignH alignH, AlignV alignV, float scaleFactor)
Parameters
Type | Name | Description |
---|---|---|
Graphics | g | A graphic device object to be drawn into. This is normally e.Graphics from the PaintEventArgs argument to the Paint() method. |
GraphPane | pane | A reference to the GraphPane object that is the parent or owner of this object. |
String | text | A string value containing the text to be displayed. This can be multiple lines, separated by newline ('\n') characters |
Single | x | The X location to display the text, in screen
coordinates, relative to the horizontal (AlignH)
alignment parameter |
Single | y | The Y location to display the text, in screen
coordinates, relative to the vertical (AlignV
alignment parameter |
AlignH | alignH | A horizontal alignment parameter specified using the AlignH enum type |
AlignV | alignV | A vertical alignment parameter specified using the AlignV enum type |
Single | scaleFactor | The scaling factor to be used for rendering objects. This is calculated and passed down by the parent GraphPane object using the CalcScaleFactor() method, and is used to proportionally adjust font sizes, etc. according to the actual size of the graph. |
GetBox(Graphics, String, Single, Single, AlignH, AlignV, Single, SizeF)
Returns a polygon that defines the bounding box of the text, taking into account alignment and rotation parameters.
Declaration
public PointF[] GetBox(Graphics g, string text, float x, float y, AlignH alignH, AlignV alignV, float scaleFactor, SizeF layoutArea)
Parameters
Type | Name | Description |
---|---|---|
Graphics | g | A graphic device object to be drawn into. This is normally e.Graphics from the PaintEventArgs argument to the Paint() method. |
String | text | A string value containing the text to be displayed. This can be multiple lines, separated by newline ('\n') characters |
Single | x | The X location to display the text, in screen
coordinates, relative to the horizontal (AlignH)
alignment parameter |
Single | y | The Y location to display the text, in screen
coordinates, relative to the vertical (AlignV
alignment parameter |
AlignH | alignH | A horizontal alignment parameter specified using the AlignH enum type |
AlignV | alignV | A vertical alignment parameter specified using the AlignV enum type |
Single | scaleFactor | The scaling factor to be used for rendering objects. This is calculated and passed down by the parent GraphPane object using the CalcScaleFactor() method, and is used to proportionally adjust font sizes, etc. according to the actual size of the graph. |
SizeF | layoutArea | The limiting area (SizeF) into which the text must fit. The actual rectangle may be smaller than this, but the text will be wrapped to accomodate the area. |
Returns
Type | Description |
---|---|
PointF[] | A polygon of 4 points defining the area of this text |
GetFont(Single)
Get the Font class for the current scaled font.
Declaration
public Font GetFont(float scaleFactor)
Parameters
Type | Name | Description |
---|---|---|
Single | scaleFactor | The scaling factor to be used for rendering objects. This is calculated and passed down by the parent GraphPane object using the CalcScaleFactor() method, and is used to proportionally adjust font sizes, etc. according to the actual size of the graph. |
Returns
Type | Description |
---|---|
Font | Returns a reference to a Font object with a size of ZedGraph.FontSpec._scaledSize, and font Family. |
GetHeight(Single)
Get the height of the scaled font
Declaration
public float GetHeight(float scaleFactor)
Parameters
Type | Name | Description |
---|---|---|
Single | scaleFactor | The scaling factor to be used for rendering objects. This is calculated and passed down by the parent GraphPane object using the CalcScaleFactor() method, and is used to proportionally adjust font sizes, etc. according to the actual size of the graph. |
Returns
Type | Description |
---|---|
Single | The scaled font height, in pixels |
GetObjectData(SerializationInfo, StreamingContext)
Populates a SerializationInfo instance with the data needed to serialize the target object
Declaration
[SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
Type | Name | Description |
---|---|---|
SerializationInfo | info | A SerializationInfo instance that defines the serialized data |
StreamingContext | context | A StreamingContext instance that contains the serialized data |
GetWidth(Graphics, Single)
Get the average character width of the scaled font. The average width is based on the character 'x'
Declaration
public float GetWidth(Graphics g, float scaleFactor)
Parameters
Type | Name | Description |
---|---|---|
Graphics | g | A graphic device object to be drawn into. This is normally e.Graphics from the PaintEventArgs argument to the Paint() method. |
Single | scaleFactor | The scaling factor to be used for rendering objects. This is calculated and passed down by the parent GraphPane object using the CalcScaleFactor() method, and is used to proportionally adjust font sizes, etc. according to the actual size of the graph. |
Returns
Type | Description |
---|---|
Single | The scaled font width, in pixels |
GetWidth(Graphics, String, Single)
Get the total width of the specified text string
Declaration
public float GetWidth(Graphics g, string text, float scaleFactor)
Parameters
Type | Name | Description |
---|---|---|
Graphics | g | A graphic device object to be drawn into. This is normally e.Graphics from the PaintEventArgs argument to the Paint() method. |
String | text | The text string for which the width is to be calculated |
Single | scaleFactor | The scaling factor to be used for rendering objects. This is calculated and passed down by the parent GraphPane object using the CalcScaleFactor() method, and is used to proportionally adjust font sizes, etc. according to the actual size of the graph. |
Returns
Type | Description |
---|---|
Single | The scaled text width, in pixels |
MeasureString(Graphics, String, Single)
Get a SizeF struct representing the width and height of the specified text string, based on the scaled font size
Declaration
public SizeF MeasureString(Graphics g, string text, float scaleFactor)
Parameters
Type | Name | Description |
---|---|---|
Graphics | g | A graphic device object to be drawn into. This is normally e.Graphics from the PaintEventArgs argument to the Paint() method. |
String | text | The text string for which the width is to be calculated |
Single | scaleFactor | The scaling factor to be used for rendering objects. This is calculated and passed down by the parent GraphPane object using the CalcScaleFactor() method, and is used to proportionally adjust font sizes, etc. according to the actual size of the graph. |
Returns
Type | Description |
---|---|
SizeF | The scaled text dimensions, in pixels, in the form of a SizeF struct |
MeasureString(Graphics, String, Single, SizeF)
Get a SizeF struct representing the width and height of the specified text string, based on the scaled font size, and using the specified SizeF as an outer limit.
Declaration
public SizeF MeasureString(Graphics g, string text, float scaleFactor, SizeF layoutArea)
Parameters
Type | Name | Description |
---|---|---|
Graphics | g | A graphic device object to be drawn into. This is normally e.Graphics from the PaintEventArgs argument to the Paint() method. |
String | text | The text string for which the width is to be calculated |
Single | scaleFactor | The scaling factor to be used for rendering objects. This is calculated and passed down by the parent GraphPane object using the CalcScaleFactor() method, and is used to proportionally adjust font sizes, etc. according to the actual size of the graph. |
SizeF | layoutArea | The limiting area (SizeF) into which the text must fit. The actual rectangle may be smaller than this, but the text will be wrapped to accomodate the area. |
Returns
Type | Description |
---|---|
SizeF | The scaled text dimensions, in pixels, in the form of a SizeF struct |
Remarks
This method will allow the text to wrap as necessary to fit the
PointInBox(PointF, Graphics, String, Single, Single, AlignH, AlignV, Single)
Determines if the specified screen point lies within the bounding box of the text, taking into account alignment and rotation parameters.
Declaration
public bool PointInBox(PointF pt, Graphics g, string text, float x, float y, AlignH alignH, AlignV alignV, float scaleFactor)
Parameters
Type | Name | Description |
---|---|---|
PointF | pt | The screen point, in pixel units |
Graphics | g | A graphic device object to be drawn into. This is normally e.Graphics from the PaintEventArgs argument to the Paint() method. |
String | text | A string value containing the text to be displayed. This can be multiple lines, separated by newline ('\n') characters |
Single | x | The X location to display the text, in screen
coordinates, relative to the horizontal (AlignH)
alignment parameter |
Single | y | The Y location to display the text, in screen
coordinates, relative to the vertical (AlignV
alignment parameter |
AlignH | alignH | A horizontal alignment parameter specified using the AlignH enum type |
AlignV | alignV | A vertical alignment parameter specified using the AlignV enum type |
Single | scaleFactor | The scaling factor to be used for rendering objects. This is calculated and passed down by the parent GraphPane object using the CalcScaleFactor() method, and is used to proportionally adjust font sizes, etc. according to the actual size of the graph. |
Returns
Type | Description |
---|---|
Boolean | true if the point lies within the bounding box, false otherwise |
PointInBox(PointF, Graphics, String, Single, Single, AlignH, AlignV, Single, SizeF)
Determines if the specified screen point lies within the bounding box of the text, taking into account alignment and rotation parameters.
Declaration
public bool PointInBox(PointF pt, Graphics g, string text, float x, float y, AlignH alignH, AlignV alignV, float scaleFactor, SizeF layoutArea)
Parameters
Type | Name | Description |
---|---|---|
PointF | pt | The screen point, in pixel units |
Graphics | g | A graphic device object to be drawn into. This is normally e.Graphics from the PaintEventArgs argument to the Paint() method. |
String | text | A string value containing the text to be displayed. This can be multiple lines, separated by newline ('\n') characters |
Single | x | The X location to display the text, in screen
coordinates, relative to the horizontal (AlignH)
alignment parameter |
Single | y | The Y location to display the text, in screen
coordinates, relative to the vertical (AlignV
alignment parameter |
AlignH | alignH | A horizontal alignment parameter specified using the AlignH enum type |
AlignV | alignV | A vertical alignment parameter specified using the AlignV enum type |
Single | scaleFactor | The scaling factor to be used for rendering objects. This is calculated and passed down by the parent GraphPane object using the CalcScaleFactor() method, and is used to proportionally adjust font sizes, etc. according to the actual size of the graph. |
SizeF | layoutArea | The limiting area (SizeF) into which the text must fit. The actual rectangle may be smaller than this, but the text will be wrapped to accomodate the area. |
Returns
Type | Description |
---|---|
Boolean | true if the point lies within the bounding box, false otherwise |
Explicit Interface Implementations
| Improve this Doc View SourceICloneable.Clone()
Implement the ICloneable interface in a typesafe manner by just calling the typed version of Clone()
Declaration
object ICloneable.Clone()
Returns
Type | Description |
---|---|
Object | A deep copy of this object |