1414using System . Collections . Generic ;
1515using System . Diagnostics ;
1616using System . Drawing ;
17+ using System . Drawing . Text ;
1718using System . IO ;
1819using System . Windows . Forms ;
1920using HtmlRenderer . Demo . Common ;
2021using HtmlRenderer . PdfSharp ;
22+ using HtmlRenderer . WinForms ;
2123using PdfSharp ;
2224
2325namespace HtmlRenderer . Demo . WinForms
@@ -31,6 +33,11 @@ public partial class DemoForm : Form
3133 /// </summary>
3234 private readonly List < string > _perfTestSamples = new List < string > ( ) ;
3335
36+ /// <summary>
37+ /// the private font used for the demo
38+ /// </summary>
39+ private readonly PrivateFontCollection _privateFont = new PrivateFontCollection ( ) ;
40+
3441 #endregion
3542
3643
@@ -51,14 +58,33 @@ public DemoForm()
5158 {
5259 _perfTestSamples . Add ( sample . Html ) ;
5360 }
61+
62+ LoadCustomFonts ( ) ;
63+ }
64+
65+ /// <summary>
66+ /// Load custom fonts to be used by renderer HTMLs
67+ /// </summary>
68+ private void LoadCustomFonts ( )
69+ {
70+ // load custom font font into private fonts collection
71+ var file = Path . GetTempFileName ( ) ;
72+ File . WriteAllBytes ( file , Resources . CustomFont ) ;
73+ _privateFont . AddFontFile ( file ) ;
74+
75+ // add the fonts to renderer
76+ foreach ( var fontFamily in _privateFont . Families )
77+ {
78+ HtmlRender . AddFontFamily ( fontFamily ) ;
79+ }
5480 }
5581
5682 /// <summary>
5783 /// Get icon for the demo.
5884 /// </summary>
5985 internal static Icon GetIcon ( )
6086 {
61- var stream = typeof ( DemoForm ) . Assembly . GetManifestResourceStream ( "HtmlRenderer.Demo.WinForms.html.ico" ) ;
87+ var stream = typeof ( DemoForm ) . Assembly . GetManifestResourceStream ( "HtmlRenderer.Demo.WinForms.Resources. html.ico" ) ;
6288 return stream != null ? new Icon ( stream ) : null ;
6389 }
6490
@@ -70,6 +96,9 @@ private void OnOpenSampleForm_Click(object sender, EventArgs e)
7096 }
7197 }
7298
99+ /// <summary>
100+ /// Toggle if to show split view of HtmlPanel and WinForms WebBrowser control.
101+ /// </summary>
73102 private void OnShowIEView_ButtonClick ( object sender , EventArgs e )
74103 {
75104 _showIEViewTSSB . Checked = ! _showIEViewTSSB . Checked ;
@@ -96,12 +125,23 @@ private void OnUseGeneratedHtml_Click(object sender, EventArgs e)
96125 _mainControl . UpdateWebBrowserHtml ( ) ;
97126 }
98127
128+ /// <summary>
129+ /// Open generate image form for the current html.
130+ /// </summary>
131+ private void OnGenerateImage_Click ( object sender , EventArgs e )
132+ {
133+ using ( var f = new GenerateImageForm ( _mainControl . GetHtml ( ) ) )
134+ {
135+ f . ShowDialog ( ) ;
136+ }
137+ }
138+
99139 /// <summary>
100140 /// Create PDF using PdfSharp project, save to file and open that file.
101141 /// </summary>
102142 private void OnGeneratePdf_Click ( object sender , EventArgs e )
103143 {
104- var doc = PdfGenerator . GeneratePdf ( _mainControl . GetHtml ( ) , PageSize . A4 ) ;
144+ var doc = PdfGenerator . GeneratePdf ( _mainControl . GetHtml ( ) , PageSize . A4 , 25 , null , HtmlRenderingHelper . OnStylesheetLoad , HtmlRenderingHelper . OnImageLoad ) ;
105145 var tmpFile = Path . GetTempFileName ( ) ;
106146 tmpFile = Path . GetFileNameWithoutExtension ( tmpFile ) + ".pdf" ;
107147 doc . Save ( tmpFile ) ;
@@ -114,7 +154,7 @@ private void OnGeneratePdf_Click(object sender, EventArgs e)
114154 private void OnRunPerformance_Click ( object sender , EventArgs e )
115155 {
116156 _mainControl . UpdateLock = true ;
117- _runPerformanceTSB . Enabled = false ;
157+ _toolStrip . Enabled = false ;
118158 Application . DoEvents ( ) ;
119159
120160 GC . Collect ( ) ;
@@ -160,7 +200,7 @@ private void OnRunPerformance_Click(object sender, EventArgs e)
160200 MessageBox . Show ( msg , "Test run results" ) ;
161201
162202 _mainControl . UpdateLock = false ;
163- _runPerformanceTSB . Enabled = true ;
203+ _toolStrip . Enabled = true ;
164204 }
165205 }
166206}
0 commit comments