Skip to content

Commit 668f42d

Browse files
committed
Replaced direct winforms ref by using an intermediary
1 parent 71d01d6 commit 668f42d

File tree

6 files changed

+26
-11
lines changed

6 files changed

+26
-11
lines changed

Source/RtfDomParser.WinFormsDemo/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ static class Program
1212
[STAThread]
1313
static void Main()
1414
{
15+
Defaults.FontName = System.Windows.Forms.Control.DefaultFont.Name;
16+
1517
Application.EnableVisualStyles();
1618
Application.SetCompatibleTextRenderingDefault(false);
1719
Application.Run(new frmRTFTest());

Source/RtfDomParser/ByteBuffer.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
*/
99

1010
using System;
11-
using System.Windows.Forms;
1211

1312
namespace RtfDomParser
1413
{

Source/RtfDomParser/Defaults.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.Text;
2+
3+
namespace RtfDomParser
4+
{
5+
public static class Defaults
6+
{
7+
public static string FontName { get; set; } = "Times New Roman";
8+
9+
public static void LoadEncodings()
10+
{
11+
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
12+
}
13+
}
14+
}

Source/RtfDomParser/DocumentFormatInfo.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ public System.Drawing.Font Font
403403
}
404404
}
405405

406-
private string strFontName = System.Windows.Forms.Control.DefaultFont.Name;
406+
private string strFontName = Defaults.FontName;
407407
/// <summary>
408408
/// font name
409409
/// </summary>
@@ -801,7 +801,7 @@ public DocumentFormatInfo Clone()
801801

802802
public void ResetText()
803803
{
804-
this.FontName = System.Windows.Forms.Control.DefaultFont.Name;
804+
this.FontName = Defaults.FontName;
805805
this.FontSize = 12;
806806
this.Bold = false;
807807
this.Italic = false;
@@ -861,7 +861,7 @@ public void Reset()
861861
this.SpacingBefore = 0;
862862
this.SpacingAfter = 0;
863863
this.Align = 0;
864-
this.FontName = System.Windows.Forms.Control.DefaultFont.Name;
864+
this.FontName = Defaults.FontName;
865865
this.FontSize = 12;
866866
this.Bold = false;
867867
this.Italic = false;
@@ -1145,7 +1145,7 @@ public void Reset()
11451145
// }
11461146
// }
11471147

1148-
// private string strFontName = System.Windows.Forms.Control.DefaultFont.Name;
1148+
// private string strFontName = Defaults.FontName;
11491149
// /// <summary>
11501150
// /// font name
11511151
// /// </summary>
@@ -1522,7 +1522,7 @@ public void Reset()
15221522

15231523
// public void ResetText()
15241524
// {
1525-
// this.FontName = System.Windows.Forms.Control.DefaultFont.Name;
1525+
// this.FontName = Defaults.FontName;
15261526
// this.FontSize = 12;
15271527
// this.Bold = false;
15281528
// this.Italic = false;
@@ -1562,7 +1562,7 @@ public void Reset()
15621562
// this.Spacing = 0;
15631563
// this.LineSpacing = 0;
15641564
// this.Align = 0;
1565-
// this.FontName = System.Windows.Forms.Control.DefaultFont.Name;
1565+
// this.FontName = Defaults.FontName;
15661566
// this.FontSize = 12;
15671567
// this.Bold = false;
15681568
// this.Italic = false;

Source/RtfDomParser/RTFDocumentWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ public void WriteStartDocument()
255255
myInfo.Clear();
256256
myFontTable.Clear();
257257
myColorTable.Clear();
258-
myFontTable.Add( System.Windows.Forms.Control.DefaultFont.Name );
258+
myFontTable.Add( Defaults.FontName );
259259
}
260260
else
261261
{

Source/RtfDomParser/RTFDomDocument.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ internal System.Text.Encoding RuntimeEncoding
9898
/// <summary>
9999
/// default font name
100100
/// </summary>
101-
private static string DefaultFontName = System.Windows.Forms.Control.DefaultFont.Name;
101+
private static string DefaultFontName = Defaults.FontName;
102102

103103

104104
private RTFFontTable myFontTable = new RTFFontTable();
@@ -3440,7 +3440,7 @@ private void ReadFontTable(RTFReader reader)
34403440
}
34413441
else if (reader.Keyword == "fnil")
34423442
{
3443-
name = System.Windows.Forms.Control.DefaultFont.Name;
3443+
name = Defaults.FontName;
34443444
nilFlag = true;
34453445
}
34463446
else if (reader.Keyword == RTFConsts._fcharset)
@@ -3478,7 +3478,7 @@ private void ReadFontTable(RTFReader reader)
34783478
name = name.Trim();
34793479
if (string.IsNullOrEmpty(name))
34803480
{
3481-
name = System.Windows.Forms.Control.DefaultFont.Name;
3481+
name = Defaults.FontName;
34823482
}
34833483
//System.Console.WriteLine( "Index:" + index + " Name:" + name );
34843484
RTFFont font = new RTFFont(index, name);

0 commit comments

Comments
 (0)