1- using System . ComponentModel ;
1+ using System ;
2+ using System . ComponentModel ;
23using System . Windows . Media ;
34using Microsoft . VisualStudio . PlatformUI ;
45using Microsoft . VisualStudio . Shell . Interop ;
@@ -22,14 +23,16 @@ public class ConfiguredFont : ObservableObject
2223 private FontFamily ? _family ;
2324 private bool _hasFamily ;
2425 private string _familyName ;
26+ private int _pointSize ;
2527 private double _size ;
2628 private byte _characterSet ;
2729
28- internal ConfiguredFont ( ref FontInfo info )
30+ internal ConfiguredFont ( ref LOGFONTW logfont , ref FontInfo fontInfo )
2931 {
30- _familyName = info . bstrFaceName ;
31- _size = info . wPointSize ;
32- _characterSet = info . iCharSet ;
32+ _familyName = fontInfo . bstrFaceName ;
33+ _pointSize = fontInfo . wPointSize ;
34+ _size = CalculateFontSize ( ref logfont ) ;
35+ _characterSet = fontInfo . iCharSet ;
3336 }
3437
3538 /// <summary>
@@ -61,7 +64,14 @@ public FontFamily? Family
6164 public string FamilyName => _familyName ;
6265
6366 /// <summary>
64- /// The font size.
67+ /// The font size, in points. This is the value specified on the <i>Fonts and Colors</i> options page.
68+ /// </summary>
69+ public int PointSize => _pointSize ;
70+
71+ /// <summary>
72+ /// The font size, for use in WPF. This is the font size that can be used in WPF controls.
73+ /// For example, the value can be used directly in the
74+ /// <see cref="System.Windows.Documents.TextElement.FontSize"/> property.
6575 /// </summary>
6676 public double Size => _size ;
6777
@@ -70,17 +80,19 @@ public FontFamily? Family
7080 /// </summary>
7181 public byte CharacterSet => _characterSet ;
7282
73- internal bool Update ( ref FontInfo info )
83+ internal bool Update ( ref LOGFONTW logfont , ref FontInfo info )
7484 {
7585 bool changed = false ;
7686 string oldFaceName = _familyName ;
87+ int oldPointSize = _pointSize ;
7788 double oldSize = _size ;
7889 byte oldCharacterSet = _characterSet ;
7990
8091 // Update all of the fields first so that
8192 // everything is set before we raise the events.
8293 _familyName = info . bstrFaceName ;
83- _size = info . wPointSize ;
94+ _pointSize = info . wPointSize ;
95+ _size = CalculateFontSize ( ref logfont ) ;
8496 _characterSet = info . iCharSet ;
8597
8698 if ( ! string . Equals ( oldFaceName , _familyName ) )
@@ -92,6 +104,12 @@ internal bool Update(ref FontInfo info)
92104 NotifyPropertyChanged ( nameof ( FamilyName ) ) ;
93105 }
94106
107+ if ( oldPointSize != _pointSize )
108+ {
109+ changed = true ;
110+ NotifyPropertyChanged ( nameof ( PointSize ) ) ;
111+ }
112+
95113 if ( oldSize != _size )
96114 {
97115 changed = true ;
@@ -106,5 +124,18 @@ internal bool Update(ref FontInfo info)
106124
107125 return changed ;
108126 }
127+
128+ private static double CalculateFontSize ( ref LOGFONTW logfont )
129+ {
130+ return Math . Abs ( logfont . lfHeight ) * 96.0 /
131+ #if VS14
132+ // `DpiAwareness` does not exist in VS 14, so default
133+ // to 96.0, which is the standard system DPI.
134+ 96.0
135+ #else
136+ Microsoft . VisualStudio . Utilities . DpiAwareness . SystemDpiY
137+ #endif
138+ ;
139+ }
109140 }
110141}
0 commit comments