gosu 0.14.3 → 0.14.4.pre2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: efccd137ba65f5c34a9662df8619debc8cb06325adedb946efc117cdcac983cd
4
- data.tar.gz: e02d6e0e09d07d447ec0bb49f1a7553ad69da2dfd7203550e02c41ed37a81acd
3
+ metadata.gz: ad14d18a7ade0c42aab29811719f40e6f6c8ada5f1aa2b8048b3f0306baaf138
4
+ data.tar.gz: 3937bfbc9006015e908c3ce0420ad0c3a2264d6181720bc3a924c0fbca624861
5
5
  SHA512:
6
- metadata.gz: a53b4b8dfa5b1b68dbe0be6437b023c3a1dd4a2ca3ad6e3db2726d7c00ba287433ae314484e9f5b52932ebaeb95a2969115ed3c3294c05259221a2a7de1eb9b2
7
- data.tar.gz: e57e71620ff07233b7ef50c2c43f764ab9b41177767f4c724a55b0479f1ee62fffe66e05d5e8f90d4d6ef21673a32886c6118cfa004a3297d0b1a38cd756f9ce
6
+ metadata.gz: a568075f265f527e288991b9da74b81fd1e52c308609d5aea42fdb5c4b5af1fac0f3a399d8ba7d35089f3fa070b52309997be923f94f5a991440683852837003
7
+ data.tar.gz: c075d9b23de4e3135953cedb3c27079f94e5c128697581418b8ab553e32172024961a36e75a2338a1c37c9f567923be774c0f709f8dc9babb0260cb82987b549
data/Gosu/Version.hpp CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  #define GOSU_MAJOR_VERSION 0
6
6
  #define GOSU_MINOR_VERSION 14
7
- #define GOSU_POINT_VERSION 3
7
+ #define GOSU_POINT_VERSION 4
8
8
 
9
9
  namespace Gosu
10
10
  {
data/src/Log.hpp ADDED
@@ -0,0 +1,19 @@
1
+ #pragma once
2
+
3
+ #include <cstdlib>
4
+ #include <utility>
5
+
6
+ namespace Gosu
7
+ {
8
+ template<class... Args>
9
+ void log(const char* format, Args&&... args)
10
+ {
11
+ using namespace std;
12
+
13
+ if (getenv("GOSU_DEBUG")) {
14
+ fprintf(stderr, format, std::forward<Args>(args)...);
15
+ fprintf(stderr, "\n");
16
+ }
17
+ }
18
+ }
19
+
data/src/RubyGosu.cxx CHANGED
@@ -11701,7 +11701,7 @@ SWIGEXPORT void Init_gosu(void) {
11701
11701
  rb_define_const(mGosu, "LICENSES", SWIG_From_std_string(static_cast< std::string >(Gosu::LICENSES)));
11702
11702
  rb_define_const(mGosu, "MAJOR_VERSION", SWIG_From_int(static_cast< int >(0)));
11703
11703
  rb_define_const(mGosu, "MINOR_VERSION", SWIG_From_int(static_cast< int >(14)));
11704
- rb_define_const(mGosu, "POINT_VERSION", SWIG_From_int(static_cast< int >(3)));
11704
+ rb_define_const(mGosu, "POINT_VERSION", SWIG_From_int(static_cast< int >(4)));
11705
11705
  rb_define_module_function(mGosu, "milliseconds", VALUEFUNC(_wrap_milliseconds), -1);
11706
11706
  rb_define_module_function(mGosu, "random", VALUEFUNC(_wrap_random), -1);
11707
11707
  rb_define_module_function(mGosu, "degrees_to_radians", VALUEFUNC(_wrap_degrees_to_radians), -1);
data/src/Texture.cpp CHANGED
@@ -1,5 +1,6 @@
1
1
  #include "Texture.hpp"
2
2
  #include "TexChunk.hpp"
3
+ #include "Log.hpp"
3
4
  #include <Gosu/Bitmap.hpp>
4
5
  #include <Gosu/Graphics.hpp>
5
6
  #include <Gosu/Platform.hpp>
@@ -14,6 +15,8 @@ namespace Gosu
14
15
  Gosu::Texture::Texture(unsigned width, unsigned height, bool retro)
15
16
  : allocator_(width, height), retro_(retro)
16
17
  {
18
+ log("Allocating a new texture of size %dx%d (retro=%d)", width, height, (int) retro);
19
+
17
20
  ensure_current_context();
18
21
 
19
22
  // Create texture name.
data/src/TrueTypeFont.cpp CHANGED
@@ -244,7 +244,7 @@ Gosu::TrueTypeFont& Gosu::font_by_name(const string& font_name, unsigned font_fl
244
244
  vector<const unsigned char*> ttf_stack;
245
245
  ttf_stack.push_back(ttf_fallback_data());
246
246
  ttf_stack.push_back(ttf_data_by_name(default_font_name(), 0));
247
- ttf_stack.push_back(ttf_data_by_name(default_font_name(), font_flags));
247
+ if (font_flags != 0) ttf_stack.push_back(ttf_data_by_name(default_font_name(), font_flags));
248
248
 
249
249
  if (font_name.find_first_of("./\\") != string::npos) {
250
250
  // A filename? Load it and add it to the stack.
@@ -253,7 +253,7 @@ Gosu::TrueTypeFont& Gosu::font_by_name(const string& font_name, unsigned font_fl
253
253
  else if (font_name != default_font_name()) {
254
254
  // A font name? Add it to the stack, both with font_flags and without.
255
255
  ttf_stack.push_back(ttf_data_by_name(font_name, 0));
256
- ttf_stack.push_back(ttf_data_by_name(font_name, font_flags));
256
+ if (font_flags != 0) ttf_stack.push_back(ttf_data_by_name(font_name, font_flags));
257
257
  }
258
258
 
259
259
  font_ptr = &font_with_stack(move(ttf_stack));
@@ -2,9 +2,11 @@
2
2
  #if defined(GOSU_IS_X)
3
3
 
4
4
  #include "TrueTypeFont.hpp"
5
+ #include "Log.hpp"
5
6
 
6
7
  #include <Gosu/IO.hpp>
7
8
  #include <Gosu/Text.hpp>
9
+ #include <Gosu/Utility.hpp>
8
10
 
9
11
  #include <fontconfig/fontconfig.h>
10
12
 
@@ -19,18 +21,22 @@ const unsigned char* Gosu::ttf_data_by_name(const string& font_name, unsigned fo
19
21
  auto& ttf_ptr = ttf_file_cache[make_pair(font_name, font_flags)];
20
22
  if (ttf_ptr) return ttf_ptr;
21
23
 
24
+ log("Trying to find a font named '%s', flags=%x", font_name.c_str(), font_flags);
25
+
22
26
  static FcConfig* config = FcInitLoadConfigAndFonts();
23
27
  if (config) {
24
- // Find "outline fonts" (so no bitmap fonts).
25
- // Our search pattern does not include weight or slant so that we can compromise on these.
26
- FcPattern* pattern = FcPatternBuild(nullptr, FC_OUTLINE, FcTypeBool, FcTrue, nullptr);
27
- // If a font name was given, add it to the pattern.
28
- if (!font_name.empty()) {
29
- FcPatternBuild(pattern, FC_FAMILY, FcTypeString, font_name.c_str(), nullptr);
30
- }
28
+ FcPattern* pattern;
29
+ // Our search pattern does not include weight or slant so that we can compromise on these.
30
+ pattern = FcPatternBuild(nullptr,
31
+ FC_FAMILY, FcTypeString, font_name.empty() ? "sans-serif" : font_name.c_str(),
32
+ FC_OUTLINE, FcTypeBool, FcTrue, // exclude bitmap fonts
33
+ nullptr);
34
+
31
35
  FcObjectSet* props = FcObjectSetBuild(FC_FILE, FC_WEIGHT, FC_SLANT, nullptr);
32
36
 
33
37
  if (FcFontSet* fonts = FcFontList(config, pattern, props)) {
38
+ log("Looking for the best candidate among %d matching fonts", (int) fonts->nfont);
39
+
34
40
  // Among all matching fonts, find the variant that is the best fit for our font_flags.
35
41
  string best_filename;
36
42
  int best_diff;
@@ -45,26 +51,32 @@ const unsigned char* Gosu::ttf_data_by_name(const string& font_name, unsigned fo
45
51
  // Lower is better, so find the font with the lowest diff.
46
52
  int diff = 0;
47
53
  if (font_flags & Gosu::FF_BOLD) {
48
- diff += abs(weight - 200);
54
+ diff += abs(weight - FC_WEIGHT_BOLD);
49
55
  }
50
56
  else {
51
- diff += abs(weight - 80);
57
+ diff += abs(weight - FC_WEIGHT_REGULAR);
52
58
  }
53
59
  if (font_flags & Gosu::FF_ITALIC) {
54
- diff += abs(slant - 100);
60
+ diff += abs(slant - FC_SLANT_ITALIC);
55
61
  }
56
62
  else {
57
- diff += abs(slant - 0);
63
+ diff += abs(slant - FC_SLANT_ROMAN);
64
+ }
65
+
66
+ // Penalize OTF fonts since we are not really good at handling these.
67
+ FcChar8 *file;
68
+ FcPatternGetString(fonts->fonts[i], FC_FILE, 0, &file);
69
+ if (has_extension(reinterpret_cast<char*>(file), ".otf")) {
70
+ diff += 10000;
58
71
  }
59
72
 
60
73
  if (best_filename.empty() || diff < best_diff) {
61
- FcChar8 *file;
62
- FcPatternGetString(fonts->fonts[i], FC_FILE, 0, &file);
63
74
  best_filename = reinterpret_cast<char*>(file);
64
75
  best_diff = diff;
65
76
  }
66
77
  }
67
78
  if (!best_filename.empty()) {
79
+ log("Loading best candidate '%s'", best_filename.c_str());
68
80
  ttf_ptr = ttf_data_from_file(best_filename.c_str());
69
81
  }
70
82
 
@@ -78,22 +90,57 @@ const unsigned char* Gosu::ttf_data_by_name(const string& font_name, unsigned fo
78
90
  return ttf_ptr;
79
91
  }
80
92
 
93
+ static const unsigned char* ttf_data_of_default_sans_serif_font()
94
+ {
95
+ const unsigned char* ttf_ptr = nullptr;
96
+
97
+ // At this point, we already have an open FcConfig, and can pass nullptr to these functions.
98
+ FcPattern* pattern = FcNameParse(reinterpret_cast<const FcChar8*>("sans-serif"));
99
+ FcConfigSubstitute(nullptr, pattern, FcMatchPattern);
100
+ FcDefaultSubstitute(pattern);
101
+ FcResult match_result;
102
+ pattern = FcFontMatch(nullptr, pattern, &match_result);
103
+ if (match_result == FcResultMatch) {
104
+ FcChar8* filename;
105
+ if (FcPatternGetString(pattern, FC_FILE, 0, &filename) == FcResultMatch) {
106
+ Gosu::log("Found the default sans-serif font: '%s'", filename);
107
+ ttf_ptr = Gosu::ttf_data_from_file(reinterpret_cast<char*>(filename));
108
+ }
109
+ }
110
+ FcPatternDestroy(pattern);
111
+
112
+ return ttf_ptr;
113
+ }
114
+
81
115
  const unsigned char* Gosu::ttf_fallback_data()
82
116
  {
83
- // Prefer Unifont as a fallback because it covers a lot of Unicode.
117
+ // Prefer Arial Unicode MS as a fallback because it covers a lot of Unicode in a single file.
118
+ // This is also the fallback font on Windows and macOS.
119
+ static const unsigned char* arial_unicode = ttf_data_by_name("Arial Unicode MS", 0);
120
+ if (arial_unicode) return arial_unicode;
121
+
122
+ // DejaVu has at least some Unicode coverage (though no CJK).
123
+ static const unsigned char* deja_vu = ttf_data_by_name("DejaVu", 0);
124
+ if (deja_vu) return deja_vu;
125
+
126
+ // Unifont has pretty good Unicode coverage, but looks extremely ugly.
84
127
  static const unsigned char* unifont = ttf_data_by_name("Unifont", 0);
85
128
  if (unifont) return unifont;
86
129
 
87
- // Otherwise, just use any font that font-config gives us.
88
- static const unsigned char* any_font = ttf_data_by_name("", 0);
89
- if (any_font) return any_font;
130
+ // If none of the fonts above work, try to use the default sans-serif font.
131
+ static const unsigned char* default_font = ttf_data_of_default_sans_serif_font();
132
+ if (default_font) return default_font;
90
133
 
134
+ // If nothing else works, try to load a file from this hardcoded path.
91
135
  return ttf_data_from_file("/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf");
92
136
  }
93
137
 
94
138
  string Gosu::default_font_name()
95
139
  {
140
+ // Liberation Sans was designed to have the same metrics as Arial, which is the default
141
+ // font on macOS and Windows.
96
142
  return "Liberation Sans";
97
143
  }
98
144
 
99
145
  #endif
146
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gosu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.3
4
+ version: 0.14.4.pre2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Raschke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-04 00:00:00.000000000 Z
11
+ date: 2018-10-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |2
14
14
  2D game development library.
@@ -95,6 +95,7 @@ files:
95
95
  - src/Inspection.cpp
96
96
  - src/LargeImageData.cpp
97
97
  - src/LargeImageData.hpp
98
+ - src/Log.hpp
98
99
  - src/MPEGFile.hpp
99
100
  - src/Macro.cpp
100
101
  - src/Macro.hpp
@@ -162,9 +163,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
162
163
  version: 1.9.3
163
164
  required_rubygems_version: !ruby/object:Gem::Requirement
164
165
  requirements:
165
- - - ">="
166
+ - - ">"
166
167
  - !ruby/object:Gem::Version
167
- version: '0'
168
+ version: 1.3.1
168
169
  requirements: []
169
170
  rubyforge_project:
170
171
  rubygems_version: 2.7.6