diff options
author | Michael Hutchinson <m.j.hutchinson@gmail.com> | 2014-04-05 01:46:25 +0400 |
---|---|---|
committer | Michael Hutchinson <m.j.hutchinson@gmail.com> | 2014-04-05 01:46:25 +0400 |
commit | 8d5b65fe0f95e82fa3c787997b00114c17a2ad18 (patch) | |
tree | eab947db0b55d9a74b1790997037e5bdcf4d27a7 /main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Fonts | |
parent | c558b82fe676a9daf59630e2d49150c2d69e9ea8 (diff) |
Clean up font service changes
Diffstat (limited to 'main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Fonts')
-rw-r--r-- | main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Fonts/FontService.cs | 86 |
1 files changed, 38 insertions, 48 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Fonts/FontService.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Fonts/FontService.cs index 9a8ba4a657..019f4d81a9 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Fonts/FontService.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Fonts/FontService.cs @@ -39,56 +39,25 @@ namespace MonoDevelop.Ide.Fonts static Dictionary<string, FontDescription> loadedFonts = new Dictionary<string, FontDescription> (); static Properties fontProperties; - static string defaultMonospaceFontName, defaultMonospaceSmallFontName, defaultSansFontName, defaultSansSmallFontName; - static FontDescription defaultMonospaceFont, defaultMonospaceSmallFont, defaultSansFont, defaultSansSmallFont; + static string defaultMonospaceFontName, defaultSansFontName; + static FontDescription defaultMonospaceFont, defaultSansFont; static void LoadDefaults () { if (defaultMonospaceFont != null) { defaultMonospaceFont.Dispose (); - defaultMonospaceSmallFont.Dispose (); defaultSansFont.Dispose (); - defaultSansSmallFont.Dispose (); } - defaultMonospaceFontName = DesktopService.DefaultFontMonospace; + #pragma warning disable 618 + defaultMonospaceFontName = DesktopService.DefaultMonospaceFont; defaultMonospaceFont = FontDescription.FromString (defaultMonospaceFontName); + #pragma warning restore 618 - defaultMonospaceSmallFontName = DesktopService.DefaultFontMonospaceSmall; - if (defaultMonospaceSmallFontName != null) { - defaultMonospaceSmallFont = FontDescription.FromString (defaultMonospaceSmallFontName); - } else { - defaultMonospaceSmallFont = FontDescScaledCopy (defaultMonospaceFont, 0.8d); - defaultMonospaceSmallFontName = defaultMonospaceSmallFont.ToString (); - } - - defaultSansFontName = DesktopService.DefaultFontSans; - if (defaultSansFontName != null) { - defaultSansFont = FontDescription.FromString (defaultSansFontName); - } else { - var label = new Gtk.Label (""); - defaultSansFont = label.Style.FontDescription.Copy (); - label.Destroy (); - defaultSansFontName = defaultSansFont.ToString (); - } - - defaultSansSmallFontName = DesktopService.DefaultFontSansSmall; - if (defaultSansSmallFontName != null) { - defaultSansSmallFont = FontDescription.FromString (defaultSansSmallFontName); - } else { - defaultSansSmallFont = FontDescScaledCopy (defaultSansFont, 0.8d); - defaultSansSmallFontName = defaultSansSmallFont.ToString (); - } - } - - static FontDescription FontDescScaledCopy (FontDescription font, double factor) - { - font = font.Copy (); - var size = font.Size; - if (size == 0) - size = 12; - font.Size = (int) (Scale.PangoScale * (int) (factor * size / Scale.PangoScale)); - return font; + var label = new Gtk.Label (""); + defaultSansFont = label.Style.FontDescription.Copy (); + label.Destroy (); + defaultSansFontName = defaultSansFont.ToString (); } internal static IEnumerable<FontDescriptionCodon> FontDescriptions { @@ -119,9 +88,7 @@ namespace MonoDevelop.Ide.Fonts } public static FontDescription MonospaceFont { get { return defaultMonospaceFont; } } - public static FontDescription MonospaceSmallFont { get { return defaultMonospaceSmallFont; } } public static FontDescription SansFont { get { return defaultSansFont; } } - public static FontDescription SansSmallFont { get { return defaultSansSmallFont; } } [Obsolete ("Use MonospaceFont")] public static FontDescription DefaultMonospaceFontDescription { @@ -135,7 +102,7 @@ namespace MonoDevelop.Ide.Fonts static FontDescription LoadFont (string name) { var fontName = FilterFontName (name); - return Pango.FontDescription.FromString (fontName); + return FontDescription.FromString (fontName); } public static string FilterFontName (string name) @@ -143,16 +110,11 @@ namespace MonoDevelop.Ide.Fonts switch (name) { case "_DEFAULT_MONOSPACE": return defaultMonospaceFontName; - case "_DEFAULT_MONOSPACE_SMALL": - return defaultMonospaceSmallFontName; case "_DEFAULT_SANS": return defaultSansFontName; - case "_DEFAULT_SANS_SMALL": - return defaultSansSmallFontName; default: return name; } - return name; } public static string GetUnderlyingFontName (string name) @@ -228,4 +190,32 @@ namespace MonoDevelop.Ide.Fonts list.Remove (callback); } } + + public static class FontExtensions + { + public static FontDescription CopyModified (this FontDescription font, double? scale = null, Pango.Weight? weight = null) + { + font = font.Copy (); + + if (scale.HasValue) + Scale (font, scale.Value); + + if (weight.HasValue) + font.Weight = weight.Value; + + return font; + } + + static void Scale (FontDescription font, double scale) + { + if (font.SizeIsAbsolute) { + font.AbsoluteSize = scale * font.Size; + } else { + var size = font.Size; + if (size == 0) + size = 10; + font.Size = (int)(Pango.Scale.PangoScale * (int)(scale * size / Pango.Scale.PangoScale)); + } + } + } }
\ No newline at end of file |