• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

TextMate is a graphical text editor for OS X 10.7+


Commit MetaInfo

Revision18eecca2ab8de6b12ae1c797527abbbb9163dcc1 (tree)
Zeit2012-08-18 23:28:47
AutorJoachim Mårtensson <joachimmartensson@gmai...>
CommiterAllan Odgaard

Log Message

Represent font size using a CGFloat

This applies to scoped font size settings and should be faster than the previous std::string based approach.

Ändern Zusammenfassung

Diff

--- a/Frameworks/theme/src/theme.cc
+++ b/Frameworks/theme/src/theme.cc
@@ -2,6 +2,7 @@
22 #include <cf/cf.h>
33
44 static theme_t::color_info_t read_color (std::string const& str_color);
5+static CGFloat read_font_size (std::string const& str_font_size);
56
67 static void get_key_path (plist::dictionary_t const& plist, std::string const& setting, theme_t::color_info_t& color)
78 {
@@ -10,6 +11,13 @@ static void get_key_path (plist::dictionary_t const& plist, std::string const& s
1011 color = read_color(temp_str);
1112 }
1213
14+static void get_key_path(plist::dictionary_t const& plist, std::string const& setting, CGFloat &font_size)
15+{
16+ std::string temp_str = NULL_STR;
17+ plist::get_key_path(plist, setting, temp_str);
18+ font_size = read_font_size(temp_str);
19+}
20+
1321 theme_t::decomposed_style_t theme_t::parse_styles (plist::dictionary_t const& plist)
1422 {
1523 decomposed_style_t res;
@@ -19,7 +27,7 @@ theme_t::decomposed_style_t theme_t::parse_styles (plist::dictionary_t const& pl
1927 res.scope_selector = scopeSelector;
2028
2129 plist::get_key_path(plist, "settings.fontName", res.font_name);
22- plist::get_key_path(plist, "settings.fontSize", res.font_size);
30+ get_key_path(plist, "settings.fontSize", res.absolute_font_size);
2331 get_key_path(plist, "settings.foreground", res.foreground);
2432 get_key_path(plist, "settings.background", res.background);
2533 get_key_path(plist, "settings.caret", res.caret);
@@ -61,8 +69,12 @@ std::vector<theme_t::decomposed_style_t> theme_t::global_styles (scope::context_
6169
6270 static struct { std::string name; std::string decomposed_style_t::*field; } const stringKeys[] =
6371 {
64- { "fontName", &decomposed_style_t::font_name },
65- { "fontSize", &decomposed_style_t::font_size },
72+ { "fontName", &decomposed_style_t::font_name },
73+ };
74+
75+ static struct { std::string name; CGFloat decomposed_style_t::*field; } const doubleKeys[] =
76+ {
77+ { "fontSize", &decomposed_style_t::absolute_font_size },
6678 };
6779
6880 static struct { std::string name; bool_t decomposed_style_t::*field; } const booleanKeys[] =
@@ -97,6 +109,17 @@ std::vector<theme_t::decomposed_style_t> theme_t::global_styles (scope::context_
97109 }
98110 }
99111
112+ for(size_t i = 0; i < sizeofA(doubleKeys); ++i)
113+ {
114+ bundles::item_ptr item;
115+ plist::any_t const& value = bundles::value_for_setting(doubleKeys[i].name, scope, &item);
116+ if(item)
117+ {
118+ res.push_back(decomposed_style_t(item->scope_selector()));
119+ res.back().*(doubleKeys[i].field) = read_font_size(plist::get<std::string>(value));
120+ }
121+ }
122+
100123 for(size_t i = 0; i < sizeofA(booleanKeys); ++i)
101124 {
102125 bundles::item_ptr item;
@@ -237,6 +260,13 @@ static void alpha_blend (theme_t::color_info_t& lhs, theme_t::color_info_t const
237260 }
238261 }
239262
263+static void calculate_font_size (CGFloat& absolute_font_size, CGFloat font_size)
264+{
265+ if(font_size > 0)
266+ absolute_font_size = font_size;
267+ else absolute_font_size = absolute_font_size * fabs(font_size);
268+}
269+
240270 static double my_strtod (char const* str, char const** last) // problem with strtod() is that it uses LC_NUMERIC for point separator.
241271 {
242272 double res = atof(str);
@@ -249,13 +279,13 @@ static double my_strtod (char const* str, char const** last) // problem with str
249279 return res;
250280 }
251281
252-theme_t::decomposed_style_t& theme_t::decomposed_style_t::operator+= (theme_t::decomposed_style_t const& rhs)
282+static CGFloat read_font_size (std::string const& str_font_size)
253283 {
254- font_name = rhs.font_name == NULL_STR ? font_name : rhs.font_name;
255-
256- if(rhs.font_size != NULL_STR)
284+ // Treat positive values as absolute font
285+ // and negative as relative, that way we don't have to use a bool as a flag :)
286+ if(str_font_size != NULL_STR)
257287 {
258- char const* first = rhs.font_size.c_str();
288+ char const* first = str_font_size.c_str();
259289 char const* last;
260290 double size = my_strtod(first, &last);
261291 if(first != last)
@@ -264,19 +294,27 @@ theme_t::decomposed_style_t& theme_t::decomposed_style_t::operator+= (theme_t::d
264294 ++last;
265295
266296 if(strcmp(last, "pt") == 0 || *last == '\0')
267- absolute_font_size = size;
297+ return size;
268298 else if(strcmp(last, "em") == 0)
269- absolute_font_size = absolute_font_size * size;
299+ return -size;
270300 else if(strcmp(last, "%") == 0)
271- absolute_font_size = absolute_font_size * size / 100;
301+ return -size / 100;
272302 else
273- fprintf(stderr, "*** unsupported font size unit: %s (%s)\n", last, rhs.font_size.c_str());
303+ fprintf(stderr, "*** unsupported font size unit: %s (%s)\n", last, str_font_size.c_str());
274304 }
275305 else
276306 {
277- fprintf(stderr, "*** unsupported font size format: %s\n", rhs.font_size.c_str());
307+ fprintf(stderr, "*** unsupported font size format: %s\n", str_font_size.c_str());
278308 }
279309 }
310+ return -1;
311+}
312+
313+theme_t::decomposed_style_t& theme_t::decomposed_style_t::operator+= (theme_t::decomposed_style_t const& rhs)
314+{
315+ font_name = rhs.font_name == NULL_STR ? font_name : rhs.font_name;
316+
317+ calculate_font_size(absolute_font_size, rhs.absolute_font_size);
280318
281319 alpha_blend(foreground, rhs.foreground);
282320 alpha_blend(background, rhs.background);
--- a/Frameworks/theme/src/theme.h
+++ b/Frameworks/theme/src/theme.h
@@ -55,13 +55,12 @@ private:
5555
5656 struct decomposed_style_t
5757 {
58- decomposed_style_t (scope::selector_t const& scopeSelector = scope::selector_t(), std::string const& fontName = NULL_STR, CGFloat fontSize = 0) : scope_selector(scopeSelector), font_name(fontName), font_size(NULL_STR), bold(bool_unset), italic(bool_unset), underlined(bool_unset), misspelled(bool_unset), absolute_font_size(fontSize) { }
58+ decomposed_style_t (scope::selector_t const& scopeSelector = scope::selector_t(), std::string const& fontName = NULL_STR, CGFloat fontSize = 0) : scope_selector(scopeSelector), font_name(fontName), bold(bool_unset), italic(bool_unset), underlined(bool_unset), misspelled(bool_unset), absolute_font_size(fontSize) { }
5959 decomposed_style_t& operator+= (decomposed_style_t const& rhs);
6060
6161 scope::selector_t scope_selector;
6262
6363 std::string font_name;
64- std::string font_size;
6564 color_info_t foreground;
6665 color_info_t background;
6766 color_info_t caret;