@@ -6,22 +6,6 @@ namespace Captcha.Core.Services;
66
77public class CaptchaImageService : ICaptchaImageService
88{
9- private readonly SKTypeface _mainFontTypeface ;
10- private readonly SKTypeface _fallbackFontTypeface ;
11-
12- public CaptchaImageService ( )
13- {
14- var assembly = typeof ( CaptchaImageService ) . Assembly ;
15-
16- _mainFontTypeface = SKTypeface . FromStream (
17- assembly . GetManifestResourceStream ( Constants . DefaultCaptchaFontName )
18- ) ;
19-
20- _fallbackFontTypeface = SKTypeface . FromStream (
21- assembly . GetManifestResourceStream ( Constants . DefaultCaptchaFallbackFontName )
22- ) ;
23- }
24-
259 public SKBitmap CreateCaptchaImage ( CaptchaConfigurationData config )
2610 {
2711 var bitmap = new SKBitmap ( new SKImageInfo ( config . Width , config . Height ) ) ;
@@ -89,7 +73,7 @@ private static void DrawWarpedText(CaptchaConfigurationData config, SKFont font,
8973 graphics . DrawPath ( path , fillPaint ) ;
9074 }
9175
92- private SKFont GetFontThatFitsRectangle ( CaptchaConfigurationData config , SKRect rectangle )
76+ private static SKFont GetFontThatFitsRectangle ( CaptchaConfigurationData config , SKRect rectangle )
9377 {
9478 var typeface = GetTypefaceThatCanRenderText ( config . Text ) ;
9579
@@ -123,16 +107,16 @@ private static void FillInTheBackground(CaptchaConfigurationData config, SKRect
123107 graphics . DrawRect ( rectangle , paint ) ;
124108 }
125109
126- private SKTypeface GetTypefaceThatCanRenderText ( string text )
110+ private static SKTypeface GetTypefaceThatCanRenderText ( string text )
127111 {
128- using var mainFont = new SKFont ( _mainFontTypeface ) ;
112+ using var mainFont = new SKFont ( Constants . MainFontTypeface ) ;
129113
130114 if ( mainFont . ContainsGlyphs ( text ) )
131115 {
132- return _mainFontTypeface ;
116+ return Constants . MainFontTypeface ;
133117 }
134118
135- return _fallbackFontTypeface ;
119+ return Constants . FallbackFontTypeface ;
136120 }
137121
138122 /// <summary>
0 commit comments