Skip to content

Commit f1304b6

Browse files
committed
Fixing Null issue in TextMeasurement
1 parent c54035d commit f1304b6

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

MigraDocCore.DocumentObjectModel/MigraDoc/MigraDoc.DocumentObjectModel/TextMeasurement.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public XSize MeasureString(string text, UnitType unitType)
6363
if (!Enum.IsDefined(typeof(UnitType), unitType))
6464
throw new ArgumentException();
6565

66-
XSize size = graphics.MeasureString(text, this.xFont);
66+
XSize size = graphics.MeasureString(text, this.XFont);
6767
switch (unitType)
6868
{
6969
case UnitType.Point:
@@ -121,6 +121,32 @@ public Font Font
121121
}
122122
}
123123
}
124+
125+
/// <summary>
126+
/// Gets the xfont used for measurement.
127+
/// </summary>
128+
private Font XFont
129+
{
130+
get {
131+
if (this.xFont == null)
132+
{
133+
var style = XFontStyle.Regular;
134+
if (this.Font.Bold)
135+
{
136+
style |= XFontStyle.Bold;
137+
}
138+
if (this.Font.Italic)
139+
{
140+
style |= XFontStyle.Italic;
141+
}
142+
143+
this.xFont = new XFont(this.Font.Name, this.Font.Size, style);
144+
}
145+
146+
return this.xFont;
147+
}
148+
}
149+
124150
Font font;
125151
XFont xFont;
126152
XGraphics graphics;

0 commit comments

Comments
 (0)