~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Ide/MonoDevelop.Ide.Fonts/FontService.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
                static List<FontDescriptionCodon> fontDescriptions = new List<FontDescriptionCodon> ();
39
39
                static Dictionary<string, FontDescription> loadedFonts = new Dictionary<string, FontDescription> ();
40
40
                static Properties fontProperties;
 
41
                static FontDescription defaultMonospaceFontDescription;
41
42
                
42
 
                public static IEnumerable<FontDescriptionCodon> FontDescriptions {
 
43
                internal static IEnumerable<FontDescriptionCodon> FontDescriptions {
43
44
                        get {
44
45
                                return fontDescriptions;
45
46
                        }
63
64
                                }
64
65
                        }); 
65
66
                }
66
 
                
 
67
 
 
68
                public static FontDescription DefaultMonospaceFontDescription {
 
69
                        get {
 
70
                                if (defaultMonospaceFontDescription == null)
 
71
                                        defaultMonospaceFontDescription = LoadFont (DesktopService.DefaultMonospaceFont);
 
72
                                return defaultMonospaceFontDescription;
 
73
                        }
 
74
                }
 
75
 
67
76
                static FontDescription LoadFont (string name)
68
77
                {
69
78
                        return Pango.FontDescription.FromString (FilterFontName (name));
95
104
                        }
96
105
                        return result;
97
106
                }
98
 
                
99
 
                public static FontDescription GetFontDescription (string name)
 
107
 
 
108
                /// <summary>
 
109
                /// Gets the font description for the provided font id
 
110
                /// </summary>
 
111
                /// <returns>
 
112
                /// The font description.
 
113
                /// </returns>
 
114
                /// <param name='name'>
 
115
                /// Identifier of the font
 
116
                /// </param>
 
117
                /// <param name='createDefaultFont'>
 
118
                /// If set to <c>false</c> and no custom font has been set, the method will return null.
 
119
                /// </param>
 
120
                public static FontDescription GetFontDescription (string name, bool createDefaultFont = true)
100
121
                {
101
122
                        if (loadedFonts.ContainsKey (name))
102
123
                                return loadedFonts [name];
103
124
                        return loadedFonts [name] = LoadFont (GetUnderlyingFontName (name));
104
125
                }
105
126
                
106
 
                public static FontDescriptionCodon GetFont (string name)
 
127
                internal static FontDescriptionCodon GetFont (string name)
107
128
                {
108
129
                        foreach (var d in fontDescriptions) {
109
130
                                if (d.Name == name)
118
139
                        if (loadedFonts.ContainsKey (name)) 
119
140
                                loadedFonts.Remove (name);
120
141
                        fontProperties.Set (name, value);
121
 
                        
122
 
                        if (fontChangeCallbacks.ContainsKey (name)) 
123
 
                                fontChangeCallbacks [name].ForEach (c => c ());
 
142
                        List<Action> callbacks;
 
143
                        if (fontChangeCallbacks.TryGetValue (name, out callbacks)) {
 
144
                                callbacks.ForEach (c => c ());
 
145
                        }
124
146
                }
125
147
                
126
148
                static Dictionary<string, List<Action>> fontChangeCallbacks = new Dictionary<string, List<Action>> ();
133
155
                
134
156
                public static void RemoveCallback (Action callback)
135
157
                {
136
 
                        foreach (var list in fontChangeCallbacks.Values)
 
158
                        foreach (var list in fontChangeCallbacks.Values.ToList ())
137
159
                                list.Remove (callback);
138
160
                }
139
161
        }