77 using PaintDotNet . Drawing ;
88 using PaintDotNet . Effects ;
99 using PaintDotNet . PropertySystem ;
10- using PaintDotNet . SystemLayer ;
1110 using System . Collections . Generic ;
11+ using System . Drawing . Text ;
1212 using System . Linq ;
1313 using PaintDotNet . IndirectUI ;
1414 using PaintDotNet . Rendering ;
1919 public class SpacedTextEffectsPlugin : PropertyBasedEffect
2020 {
2121 private readonly SpacedText helper ;
22- private readonly List < string > fontFamilies ;
22+ private readonly List < FontFamily > fontFamilies ;
2323
2424 public SpacedTextEffectsPlugin ( ) : base ( "Spaced text" , null , "Text Formations" , EffectFlags . Configurable )
2525 {
2626 fontFamilies =
27- UIUtil . GetGdiFontNames ( )
28- . Where ( f => f . Item2 == UIUtil . GdiFontType . TrueType )
29- . Select ( f => f . Item1 ) . OrderBy ( f => f )
30- . ToList ( ) ;
27+ new InstalledFontCollection ( ) . Families . ToList ( ) ;
3128 helper = new SpacedText ( ) ;
3229 }
3330
@@ -40,7 +37,7 @@ protected override PropertyCollection OnCreatePropertyCollection()
4037 new DoubleProperty ( C . Properties . LetterSpacing . ToString ( ) , C . DefaultLetterSpacing , C . MinLetterSpacing , C . MaxLetterSpacing ) ,
4138 new DoubleProperty ( C . Properties . LineSpacing . ToString ( ) , C . DefaultLineSpacing , C . MinLineSpacing , C . MaxLineSpacing ) ,
4239 new Int32Property ( C . Properties . AntiAliasLevel . ToString ( ) , C . DefaultAntiAliasingLevel , C . MinAntiAliasingLevel , C . MaxAntiAliasingLevel ) ,
43- new StaticListChoiceProperty ( C . Properties . FontFamily . ToString ( ) , fontFamilies . ToArray < object > ( ) , fontFamilies . FirstIndexWhere ( f => f == "Arial" || f == "Helvetica" ) ) ,
40+ new StaticListChoiceProperty ( C . Properties . FontFamily . ToString ( ) , fontFamilies . ToArray < object > ( ) , fontFamilies . FirstIndexWhere ( f => f . Name == "Arial" || f . Name == "Helvetica" ) ) ,
4441 new StaticListChoiceProperty ( C . Properties . TextAlignment , Enum . GetNames ( typeof ( C . TextAlignmentOptions ) ) . ToArray < object > ( ) , 0 ) ,
4542 new BooleanProperty ( C . Properties . Bold . ToString ( ) , false ) ,
4643 new BooleanProperty ( C . Properties . Italic . ToString ( ) , false ) ,
@@ -53,60 +50,65 @@ protected override ControlInfo OnCreateConfigUI(PropertyCollection props)
5350 {
5451 ControlInfo configUI = CreateDefaultConfigUI ( props ) ;
5552
56- configUI . SetPropertyControlValue ( Constants . Properties . Text . ToString ( ) , ControlInfoPropertyNames . Multiline , true ) ;
57- configUI . SetPropertyControlValue ( Constants . Properties . Bold . ToString ( ) , ControlInfoPropertyNames . DisplayName , "Formatting" ) ;
58- configUI . SetPropertyControlValue ( Constants . Properties . Bold . ToString ( ) , ControlInfoPropertyNames . Description , Constants . Properties . Bold . ToString ( ) ) ;
59- configUI . SetPropertyControlValue ( Constants . Properties . Italic . ToString ( ) , ControlInfoPropertyNames . DisplayName , string . Empty ) ;
60- configUI . SetPropertyControlValue ( Constants . Properties . Italic . ToString ( ) , ControlInfoPropertyNames . Description , Constants . Properties . Italic . ToString ( ) ) ;
61- configUI . SetPropertyControlValue ( Constants . Properties . Underline . ToString ( ) , ControlInfoPropertyNames . DisplayName , string . Empty ) ;
62- configUI . SetPropertyControlValue ( Constants . Properties . Underline . ToString ( ) , ControlInfoPropertyNames . Description , Constants . Properties . Underline . ToString ( ) ) ;
63- configUI . SetPropertyControlValue ( Constants . Properties . Strikeout . ToString ( ) , ControlInfoPropertyNames . DisplayName , string . Empty ) ;
64- configUI . SetPropertyControlValue ( Constants . Properties . Strikeout . ToString ( ) , ControlInfoPropertyNames . Description , Constants . Properties . Strikeout . ToString ( ) ) ;
53+ configUI . SetPropertyControlValue ( C . Properties . Text . ToString ( ) , ControlInfoPropertyNames . Multiline , true ) ;
54+ configUI . SetPropertyControlValue ( C . Properties . Bold . ToString ( ) , ControlInfoPropertyNames . DisplayName , "Formatting" ) ;
55+ configUI . SetPropertyControlValue ( C . Properties . Bold . ToString ( ) , ControlInfoPropertyNames . Description , C . Properties . Bold . ToString ( ) ) ;
56+ configUI . SetPropertyControlValue ( C . Properties . Italic . ToString ( ) , ControlInfoPropertyNames . DisplayName , string . Empty ) ;
57+ configUI . SetPropertyControlValue ( C . Properties . Italic . ToString ( ) , ControlInfoPropertyNames . Description , C . Properties . Italic . ToString ( ) ) ;
58+ configUI . SetPropertyControlValue ( C . Properties . Underline . ToString ( ) , ControlInfoPropertyNames . DisplayName , string . Empty ) ;
59+ configUI . SetPropertyControlValue ( C . Properties . Underline . ToString ( ) , ControlInfoPropertyNames . Description , C . Properties . Underline . ToString ( ) ) ;
60+ configUI . SetPropertyControlValue ( C . Properties . Strikeout . ToString ( ) , ControlInfoPropertyNames . DisplayName , string . Empty ) ;
61+ configUI . SetPropertyControlValue ( C . Properties . Strikeout . ToString ( ) , ControlInfoPropertyNames . Description , C . Properties . Strikeout . ToString ( ) ) ;
6562
66- configUI . SetPropertyControlValue ( Constants . Properties . LetterSpacing . ToString ( ) ,
63+ configUI . SetPropertyControlValue ( C . Properties . LetterSpacing . ToString ( ) ,
6764 ControlInfoPropertyNames . SliderLargeChange , 0.25 ) ;
68- configUI . SetPropertyControlValue ( Constants . Properties . LetterSpacing . ToString ( ) ,
65+ configUI . SetPropertyControlValue ( C . Properties . LetterSpacing . ToString ( ) ,
6966 ControlInfoPropertyNames . SliderSmallChange , 0.01 ) ;
70- configUI . SetPropertyControlValue ( Constants . Properties . LetterSpacing . ToString ( ) ,
67+ configUI . SetPropertyControlValue ( C . Properties . LetterSpacing . ToString ( ) ,
7168 ControlInfoPropertyNames . UpDownIncrement , 0.01 ) ;
7269
73- configUI . SetPropertyControlValue ( Constants . Properties . LineSpacing . ToString ( ) ,
70+ configUI . SetPropertyControlValue ( C . Properties . LineSpacing . ToString ( ) ,
7471 ControlInfoPropertyNames . SliderLargeChange , 0.25 ) ;
75- configUI . SetPropertyControlValue ( Constants . Properties . LineSpacing . ToString ( ) ,
72+ configUI . SetPropertyControlValue ( C . Properties . LineSpacing . ToString ( ) ,
7673 ControlInfoPropertyNames . SliderSmallChange , 0.01 ) ;
77- configUI . SetPropertyControlValue ( Constants . Properties . LineSpacing . ToString ( ) ,
74+ configUI . SetPropertyControlValue ( C . Properties . LineSpacing . ToString ( ) ,
7875 ControlInfoPropertyNames . UpDownIncrement , 0.01 ) ;
7976
77+ PropertyControlInfo fontControl = configUI . FindControlForPropertyName ( C . Properties . FontFamily ) ;
78+ foreach ( FontFamily fontFamily in fontFamilies )
79+ {
80+ fontControl . SetValueDisplayName ( fontFamily , fontFamily . Name ) ;
81+ }
82+
8083 return configUI ;
8184 }
8285
8386 protected override void OnSetRenderInfo ( PropertyBasedEffectConfigToken newToken , RenderArgs dstArgs , RenderArgs srcArgs )
8487 {
8588 helper . Text = newToken . GetProperty < StringProperty > ( C . Properties . Text . ToString ( ) ) . Value ;
86- helper . FontFamily = newToken . GetProperty < StaticListChoiceProperty > ( C . Properties . FontFamily . ToString ( ) ) . Value . ToString ( ) ;
89+ helper . FontFamily = ( FontFamily ) newToken . GetProperty < StaticListChoiceProperty > ( C . Properties . FontFamily . ToString ( ) ) . Value ;
8790 helper . FontSize = newToken . GetProperty < Int32Property > ( C . Properties . FontSize . ToString ( ) ) . Value ;
8891 helper . LetterSpacing = newToken . GetProperty < DoubleProperty > ( C . Properties . LetterSpacing . ToString ( ) ) . Value ;
8992 helper . LineSpacing = newToken . GetProperty < DoubleProperty > ( C . Properties . LineSpacing . ToString ( ) ) . Value ;
9093 helper . AntiAliasLevel = newToken . GetProperty < Int32Property > ( C . Properties . AntiAliasLevel . ToString ( ) ) . Value ;
91- var fontFamily = new FontFamily ( helper . FontFamily ) ;
92- helper . FontStyle = fontFamily . IsStyleAvailable ( FontStyle . Regular ) ? FontStyle . Regular : fontFamily . IsStyleAvailable ( FontStyle . Bold ) ? FontStyle . Bold : FontStyle . Italic ;
94+ helper . FontStyle = helper . FontFamily . IsStyleAvailable ( FontStyle . Regular ) ? FontStyle . Regular : helper . FontFamily . IsStyleAvailable ( FontStyle . Bold ) ? FontStyle . Bold : FontStyle . Italic ;
9395 helper . TextAlign = ( C . TextAlignmentOptions ) Enum . Parse ( typeof ( C . TextAlignmentOptions ) ,
9496 newToken
9597 . GetProperty < StaticListChoiceProperty > ( C . Properties . TextAlignment . ToString ( ) )
9698 . Value . ToString ( ) ) ;
97- if ( newToken . GetProperty < BooleanProperty > ( C . Properties . Bold . ToString ( ) ) . Value && fontFamily . IsStyleAvailable ( FontStyle . Bold ) )
99+ if ( newToken . GetProperty < BooleanProperty > ( C . Properties . Bold . ToString ( ) ) . Value && helper . FontFamily . IsStyleAvailable ( FontStyle . Bold ) )
98100 {
99101 helper . FontStyle |= FontStyle . Bold ;
100102 }
101- if ( newToken . GetProperty < BooleanProperty > ( C . Properties . Italic . ToString ( ) ) . Value && fontFamily . IsStyleAvailable ( FontStyle . Italic ) )
103+ if ( newToken . GetProperty < BooleanProperty > ( C . Properties . Italic . ToString ( ) ) . Value && helper . FontFamily . IsStyleAvailable ( FontStyle . Italic ) )
102104 {
103105 helper . FontStyle |= FontStyle . Italic ;
104106 }
105- if ( newToken . GetProperty < BooleanProperty > ( C . Properties . Underline . ToString ( ) ) . Value && fontFamily . IsStyleAvailable ( FontStyle . Underline ) )
107+ if ( newToken . GetProperty < BooleanProperty > ( C . Properties . Underline . ToString ( ) ) . Value && helper . FontFamily . IsStyleAvailable ( FontStyle . Underline ) )
106108 {
107109 helper . FontStyle |= FontStyle . Underline ;
108110 }
109- if ( newToken . GetProperty < BooleanProperty > ( C . Properties . Strikeout . ToString ( ) ) . Value && fontFamily . IsStyleAvailable ( FontStyle . Strikeout ) )
111+ if ( newToken . GetProperty < BooleanProperty > ( C . Properties . Strikeout . ToString ( ) ) . Value && helper . FontFamily . IsStyleAvailable ( FontStyle . Strikeout ) )
110112 {
111113 helper . FontStyle |= FontStyle . Strikeout ;
112114 }
@@ -132,7 +134,7 @@ protected override void OnRender(Rectangle[] renderRects, int startIndex, int le
132134 renderBounds . Intersect ( renderRects [ i ] ) ;
133135
134136 //since TextOut does not support transparent text, we will use the resulting bitmap as a transparency map
135- CopyRectangle ( renderBounds , helper . BufferSurface , base . DstArgs . Surface ) ;
137+ CopyRectangle ( renderBounds , helper . BufferSurface , DstArgs . Surface ) ;
136138
137139 //clear the remainder
138140 DstArgs . Surface . Clear ( new RectInt32 (
@@ -156,7 +158,7 @@ private void CopyRectangle(Rectangle area, Surface buffer, Surface dest)
156158 for ( int x = area . Left ; x < area . Right ; x ++ )
157159 {
158160 //use the buffer as an alpha map
159- ColorBgra color = base . EnvironmentParameters . PrimaryColor ;
161+ ColorBgra color = EnvironmentParameters . PrimaryColor ;
160162 ColorBgra opacitySource = buffer [ x - helper . Bounds . Left , y - helper . Bounds . Top ] ;
161163 color . A = opacitySource . R ;
162164 dest [ x , y ] = color ;
0 commit comments