SDXFrameWork  0.13
SDXFrameWork
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
Font.h
1 //Copyright © 2014 SDXFramework
2 //[License]GNU Affero General Public License, version 3
3 //[Contact]http://sourceforge.jp/projects/dxframework/
4 #pragma once
5 #include <Multimedia/SDX.h>
6 #include <Multimedia/Screen.h>
7 #include <Multimedia/IFont.h>
8 #include <Multimedia/SystemFont.h>
9 #include <Multimedia/Image.h>
10 #include <Framework/ImagePack.h>
11 #include <Multimedia/Window.h>
12 #include <Multimedia/File.h>
13 
14 #include <map>
15 #include <unordered_map>
16 #include <iomanip>
17 
18 namespace SDX
19 {
25  class Font : public IFont
26  {
27  private:
28  TTF_Font* handle = nullptr;
29  bool isBlendRender;
30  int size = 0;
31  int enterHeight = 0;
32  mutable std::unordered_map<int, Image*> hash;
33 
34  int style = TTF_STYLE_NORMAL;
35 
36  static bool GetUTFSize(unsigned char 一文字目,int &文字長さ )
37  {
38  if (一文字目 < 0x20)
39  {
40  //制御文字
41  文字長さ = 1;
42  return false;
43  }
44 
45  if (一文字目 < 0x80){ 文字長さ = 1; }
46  else if (一文字目 < 0xE0){ 文字長さ = 2; }
47  else if (一文字目 < 0xF0){ 文字長さ = 3; }
48  else { 文字長さ = 4; }
49  return true;
50  }
51 
53  void DrawUTFString(const Point &座標, const std::string &文字列 , const Color &描画色) const
54  {
55  Point 位置 = 座標;
56 
57  int charSize;
58  for (auto it = 文字列.begin(); it != 文字列.end(); it += charSize)
59  {
60  if (!GetUTFSize(*it, charSize)){ continue; }
61  if (handle == nullptr && *it == ' ')
62  {
63  位置.x += size;
64  continue;
65  }
66 
67  Image* str = GetHash(文字列.substr(std::distance(文字列.begin(), it), charSize).c_str() , charSize);
68  if (str == nullptr){ continue; }
69 
70  str->SetColor(描画色);
71  str->Draw(位置);
72  位置.x += str->GetWidth();
73  }
74  }
76  void DrawUTFString(const Point &座標, double X拡大率, double Y拡大率, const std::string &文字列, const Color &描画色) const
77  {
78  Point 位置 = 座標;
79 
80  int charSize = 0;
81  for (auto it = 文字列.begin(); it != 文字列.end(); it += charSize)
82  {
83  if (!GetUTFSize(*it, charSize)){ continue; }//制御文字は無視
84 
85  Image* str = GetHash(文字列.substr(std::distance(文字列.begin(), it), charSize).c_str(),charSize);
86  if (str == nullptr)
87  {
88  位置.x += size * X拡大率;
89  continue;
90  }
91 
92  str->SetColor(描画色);
93  str->DrawExtend({ 位置.x , 位置. y , str->GetWidth()*X拡大率, str->GetHeight()*Y拡大率 });
94  位置.x += str->GetWidth() * X拡大率;
95  }
96  }
98  void DrawRotateUTFString(const Point &座標, int X補正, int Y補正, double 拡大率, double 角度, const std::string &文字列, const Color &描画色) const
99  {
100  Point 位置 = 座標;
101 
102  int charSize = 0;
103  for (auto it = 文字列.begin(); it != 文字列.end(); it += charSize)
104  {
105  if (!GetUTFSize(*it, charSize)){ continue; }
106 
107  Image* str = GetHash(文字列.substr(std::distance(文字列.begin(), it), charSize).c_str(),charSize);
108  if (str == nullptr)
109  {
110  位置.x += size * 拡大率;
111  continue;
112  }
113 
114  X補正 += int(str->GetWidth() * 拡大率 * 0.5);
115  double x = 位置.x + std::cos(角度) * X補正 + std::cos(角度 + PAI / 2) * Y補正;
116  double y = 位置.y + std::sin(角度) * X補正 + std::sin(角度 + PAI / 2) * Y補正;
117 
118  str->SetColor(描画色);
119  str->DrawRotate({ x, y }, 拡大率, 角度);
120  X補正 += int(str->GetWidth() * 拡大率 * 0.5);
121  }
122  }
123 
125  Image* GetHash(const char* 文字 , int 文字長さ) const
126  {
127  int ID = 文字[0];
128  if (文字長さ >= 2){ ID += 文字[1]*256; }
129  if (文字長さ >= 3){ ID += 文字[2]*256*256; }
130  if (文字長さ >= 4){ ID += 文字[3] * 256 * 256 * 256; }
131 
132  auto it = hash.find(ID);
133 
134  if (it == hash.end())
135  {
136  if (handle == nullptr){ return nullptr; }
137 
138  SDL_Surface* surface = nullptr;
139 
140 #ifndef OMIT_SDL2_TTF
141  if (isBlendRender)
142  {
143  surface = TTF_RenderUTF8_Blended(handle, 文字, { 255, 255, 255 });
144  }
145  else
146  {
147  surface = TTF_RenderUTF8_Solid(handle, 文字, { 255, 255, 255 });
148  }
149 #endif
150 
151  SDL_Texture* moji = SDL_CreateTextureFromSurface(Screen::GetHandle(), surface);
152  hash[ID] = new Image(moji, surface->w, surface->h);
153 
154  SDL_FreeSurface(surface);
155  return hash[ID];
156  }
157  return it->second;
158  }
159 
161  void SetHash(const char* 文字, int 文字長さ, Image *対応Image)
162  {
163  int ID = 文字[0];
164  if (文字長さ >= 2){ ID += 文字[1] * 256; }
165  if (文字長さ >= 3){ ID += 文字[2] * 256 * 256; }
166  if (文字長さ >= 4){ ID += 文字[3] * 256 * 256 * 256; }
167 
168  hash[ID] = 対応Image;
169  }
170  public:
171 
172  Font() = default;
173 
175  Font(const char *フォント名, int 大きさ, int 行間 = 0 , bool 高品質レンダリングフラグ = true )
176  {
177  Load(フォント名, 大きさ, 行間, 高品質レンダリングフラグ);
178  }
179 
183  bool Load(const char *フォント名, int 大きさ, int 行間 = 0, bool 高品質レンダリングフラグ = true )
184  {
185  if (Loading::isLoading)
186  {
187  Loading::AddLoading([=]{ Load(フォント名, 大きさ, 行間, 高品質レンダリングフラグ); });
188  return true;
189  }
190 
191  //すでに読み込んでいる場合は失敗
192  if (handle != nullptr){ return false; }
193 
194  this->size = 大きさ;
195  this->enterHeight = 行間 + 大きさ;
196  isBlendRender = 高品質レンダリングフラグ;
197 
198 #ifndef OMIT_SDL2_TTF
199  handle = TTF_OpenFont(フォント名, 大きさ);
200 #endif
201 
202  return (handle != nullptr);
203  }
204 
205 
207  bool Release() const
208  {
209  //すでに読み込んでいる場合は失敗
210  if (handle != nullptr){ return false; }
211  TTF_CloseFont(handle);
212  for (auto && it : hash)
213  {
214  it.second->Release();
215  }
216  return true;
217  }
218 
220  TTF_Font* GetHandle() const
221  {
222  return handle;
223  }
224 
226  Image MakeImage(Color 文字色, bool 反転フラグ, const VariadicStream &描画する文字列) const
227  {
228  if (handle == nullptr){ return Image(); }
229 
230  int 幅 = GetDrawStringWidth(描画する文字列);
231  int 高さ = ((int)描画する文字列.StringS.size() - 1) * enterHeight + size;
232  int Y座標 = 0;
233 
234  std::vector<SDL_Surface*> surfaces;
235  SDL_Surface* surface;
236 
237  for (auto it : 描画する文字列.StringS)
238  {
239  if (isBlendRender)
240  {
241  surface = TTF_RenderUTF8_Blended(handle, it.c_str(), 文字色);
242  }
243  else
244  {
245  surface = TTF_RenderUTF8_Solid(handle, it.c_str(), 文字色);
246  }
247 
248  幅 = std::max(幅, surface->w);
249  surfaces.push_back(surface);
250  }
251 
252  SDL_Surface* toRend = SDL_CreateRGBSurface(0, 幅, 高さ, 32, 0, 0, 0, 0);
253  SDL_Renderer* render = SDL_CreateSoftwareRenderer(toRend);
254 
255  for (auto it : surfaces)
256  {
257  SDL_Texture* texture = SDL_CreateTextureFromSurface(render, it);
258 
259  SDL_Rect temp = { 0, Y座標, it->w, it->h };
260  SDL_RenderCopy(render, texture, 0, &temp);
261 
262  Y座標 += this->enterHeight;
263 
264  SDL_FreeSurface(it);
265  SDL_DestroyTexture(texture);
266  }
267  //描画先を戻す
268  Image image(SDL_CreateTextureFromSurface(Screen::GetHandle(), toRend), 幅, 高さ);
269 
270  SDL_FreeSurface(toRend);
271  SDL_DestroyRenderer(render);
272 
273  return image;
274  }
275 
279  void SetSize(int 大きさ, int 行間 = 0)
280  {
281  this->size = 大きさ;
282  this->enterHeight = 行間 + 大きさ;
283  }
284 
289  bool MakeBMPFont(const std::string テキストファイル名)
290  {
291  if (handle == nullptr){ return false; }
292  SDL_Surface* surface;
293  SDL_Surface* buff;
294 
295  SDL_Rect pos;
296  SDL_Rect rect;
297  rect.x = 0;
298  rect.y = 0;
299  pos.x = 0;
300  pos.y = 0;
301 
302  /* OpenGLのテクスチャとして使うために
303  各ピクセルがR,G,B,A順の32bitサーフェイスを生成する */
304  Uint32 rmask, gmask, bmask, amask;
305 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
306  rmask = 0xff000000;
307  gmask = 0x00ff0000;
308  bmask = 0x0000ff00;
309  amask = 0x000000ff;
310 #else
311  rmask = 0x000000ff;
312  gmask = 0x0000ff00;
313  bmask = 0x00ff0000;
314  amask = 0xff000000;
315 #endif
316  //追加フォント
317  File file(テキストファイル名.c_str(), FileMode::Read, true);
318  auto strS = file.GetLineS();
319  int count = strS.size();
320 
321  unsigned int index = 0;
322 
323  if( (unsigned char)strS[0][0] == 0xEF && (unsigned char)strS[0][1] == 0xBB && (unsigned char)strS[0][2] == 0xBF ){index = 3;}
324 
325  while(1)
326  {
327  if( strS[0].size() <= index ){break;}
328 
329  if( (unsigned char)strS[0][index] < 0x80 ){index += 1;}
330  else if ( (unsigned char)strS[0][index] < 0xE0){ index += 2; }
331  else if ( (unsigned char)strS[0][index] < 0xF0){ index += 3; }
332  else { index += 4; }
333 
334  ++count;
335  }
336 
337  int high = TTF_FontHeight(handle);
338  surface = SDL_CreateRGBSurface(0, size * 32 , high * (12+((count+31)/32) ) , 32, rmask, gmask, bmask, amask);
339 
340  std::string str;
341 
342  //基本フォントを生成
343  for (int a = 0; a < 12; ++a)
344  {
345  //全角32文字ずつ
346  switch (a)
347  {
348  case 0: str = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`"; break;
349  case 1: str = "abcdefghijklmnopqrstuvwxyz{|}~。「」、・ヲァィゥェォャュョッーアイウエオカキクケコサシスセソ"; break;
350  case 2: str = "タチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙゚ "; break;
351  case 3: str = "ぁあぃいぅうぇえぉおかがきぎくぐけげこごさざしじすずせぜそぞただ"; break;
352  case 4: str = "ちぢっつづてでとどなにぬねのはばぱひびぴふぶぷへべぺほぼぽまみむ"; break;
353  case 5: str = "めもゃやゅゆょよらりるれろゎわゐゑをんゔゕゖ "; break;
354  case 6: str = "ァアィイゥウェエォオカガキギクグケゲコゴサザシジスズセゼソゾタダ"; break;
355  case 7: str = "チヂッツヅテデトドナニヌネノハバパヒビピフブプヘベペホボポマミム"; break;
356  case 8: str = "メモャヤュユョヨラリルレロヮワヰヱヲンヴヵヶヷヸヹヺ・ーヽヾヿ゠"; break;
357  case 9: str = "!"#$%&'()*+,-./0123456789:;<=>?@"; break;
358  case 10: str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`"; break;
359  case 11: str = "abcdefghijklmnopqrstuvwxyz{|}~⦅⦆"; break;
360  }
361 
362  if (isBlendRender)
363  {
364  buff = TTF_RenderUTF8_Blended(handle, str.c_str(), { 255, 255, 255 });
365  }
366  else
367  {
368  buff = TTF_RenderUTF8_Solid(handle, str.c_str(), { 255, 255, 255 });
369  }
370  pos.w = buff->w;
371  pos.h = buff->h;
372 
373  SDL_BlitSurface(buff, NULL, surface, &pos);
374 
375  pos.y += high;
376  SDL_FreeSurface(buff);
377  }
378 
379 
380  //一文字ずつ
381  //http://1bit.mobi/20101026101350.html 常用漢字表
382  index = 0;
383  int length = 0;
384  //BOMチェック
385  if( (unsigned char)strS[0][0] == 0xEF && (unsigned char)strS[0][1] == 0xBB && (unsigned char)strS[0][2] == 0xBF ){index = 3;}
386 
387  while(1)
388  {
389  if( strS[0].size() <= index ){break;}
390 
391  if( (unsigned char)strS[0][index] < 0x80 )
392  {
393  length = 1;
394  }
395  else if ( (unsigned char)strS[0][index] < 0xE0)
396  {
397  length = 2;
398  }
399  else if ( (unsigned char)strS[0][index] < 0xF0)
400  {
401  length = 3;
402  }
403  else
404  {
405  length = 4;
406  }
407  if (isBlendRender)
408  {
409  buff = TTF_RenderUTF8_Blended(handle, strS[0].substr(index,length).c_str() , { 255, 255, 255 });
410  }
411  else
412  {
413  buff = TTF_RenderUTF8_Solid(handle, strS[0].substr(index,length).c_str() , { 255, 255, 255 });
414  }
415 
416  index += length;
417 
418  pos.w = buff->w;
419  pos.h = buff->h;
420 
421  SDL_BlitSurface(buff, NULL, surface, &pos);
422 
423  pos.x += pos.w;
424  if (pos.x >= size * 32)
425  {
426  pos.x = 0;
427  pos.y += high;
428  }
429  SDL_FreeSurface(buff);
430  }
431 
432  std::string fileName = TTF_FontFaceFamilyName(handle);
433  fileName += TTF_FontFaceStyleName(handle);
434  fileName += std::to_string(size);
435  fileName += ".bmp";
436 
437  SDL_SaveBMP(surface, fileName.c_str());
438  SDL_FreeSurface(surface);
439 
440  return true;
441  }
442 
445  bool LoadBMPFont( const Image& BMPフォント , const std::string テキストファイル名)
446  {
447  if (Loading::isLoading)
448  {
449  Loading::AddLoading([=]{ LoadBMPFont(BMPフォント, テキストファイル名); });
450  return true;
451  }
452 
453  File file(テキストファイル名.c_str(), FileMode::Read, true);
454  auto strS = file.GetLineS();
455  int count = 0;
456 
457  unsigned int index = 0;
458 
459  if( (unsigned char)strS[0][0] == 0xEF && (unsigned char)strS[0][1] == 0xBB && (unsigned char)strS[0][2] == 0xBF ){index = 3;}
460 
461  while(1)
462  {
463  if( strS[0].size() <= index ){break;}
464 
465  if( (unsigned char)strS[0][index] < 0x80 ){index += 1;}
466  else if ( (unsigned char)strS[0][index] < 0xE0){ index += 2; }
467  else if ( (unsigned char)strS[0][index] < 0xF0){ index += 3; }
468  else { index += 4; }
469 
470  ++count;
471  }
472 
473  int h = BMPフォント.GetHeight() / ((count+31)/32 + 12);
474  int w = BMPフォント.GetWidth() / 32;
475 
476  size = w;
477  enterHeight = h;
478 
479  std::string str;
480 
481  for (int a = 0; a < 12; ++a)
482  {
483  switch (a)
484  {
485  case 0: str = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`"; break;
486  case 1: str = "abcdefghijklmnopqrstuvwxyz{|}~。「」、・ヲァィゥェォャュョッーアイウエオカキクケコサシスセソ"; break;
487  case 2: str = "タチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙゚ "; break;
488  case 3: str = "ぁあぃいぅうぇえぉおかがきぎくぐけげこごさざしじすずせぜそぞただ"; break;
489  case 4: str = "ちぢっつづてでとどなにぬねのはばぱひびぴふぶぷへべぺほぼぽまみむ"; break;
490  case 5: str = "めもゃやゅゆょよらりるれろゎわゐゑをんゔゕゖ  "; break;
491  case 6: str = "ァアィイゥウェエォオカガキギクグケゲコゴサザシジスズセゼソゾタダ"; break;
492  case 7: str = "チヂッツヅテデトドナニヌネノハバパヒビピフブプヘベペホボポマミム"; break;
493  case 8: str = "メモャヤュユョヨラリルレロヮワヰヱヲンヴヵヶヷヸヹヺ・ーヽヾヿ゠"; break;
494  case 9: str = "!"#$%&'()*+,-./0123456789:;<=>?@"; break;
495  case 10: str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`"; break;
496  case 11: str = "abcdefghijklmnopqrstuvwxyz{|}~⦅⦆"; break;
497  }
498 
499  int count = 0;
500  for (int b = 0; b < 64; ++b)
501  {
502  int ID = 0;
503  int 文字長 = 0;
504  if (a <= 2)
505  {
506  if (a == 1 && b == 61){ break; }
507  if (a == 2 && b == 34){ break; }
508  GetUTFSize(str[count], 文字長);
509  ID = str[count];
510 
511  if (文字長 > 1){ ID += str[count + 1] * 0x100; }
512  if (文字長 > 2){ ID += str[count + 2] * 0x10000; }
513  if (文字長 > 3){ ID += str[count + 3] * 0x1000000; }
514 
515  hash[ID] = new Image(BMPフォント, { b * w/2, a * h, w / 2, h });
516  count += 文字長;
517  }
518  else
519  {
520  if (b >= 32){ break; }
521  if (a == 5 && b == 24){ break; }
522 
523  ID = str[b * 3] + str[b * 3 + 1] * 256 + str[b * 3 + 2] * 256 * 256;
524  hash[ID] = new Image(BMPフォント, { b * w, a * h, w, h });
525  }
526  }
527  }
528  //空白文字を登録
529  hash[0x20] = new Image(BMPフォント, { 33 * w / 2, 2 * h, w / 2, h });
530 
531  //一文字ずつ
532  //http://1bit.mobi/20101026101350.html 常用漢字表
533  int c = 0;
534 
535  index = 0;
536  int length = 0;
537  if( (unsigned char)strS[0][0] == 0xEF && (unsigned char)strS[0][1] == 0xBB && (unsigned char)strS[0][2] == 0xBF ){index = 3;}
538 
539  while(1)
540  {
541  if( strS[0].size() <= index ){break;}
542 
543  if( (unsigned char)strS[0][index] < 0x80 )
544  {
545  length = 1;
546  }
547  else if ( (unsigned char)strS[0][index] < 0xE0)
548  {
549  length = 2;
550  }
551  else if ( (unsigned char)strS[0][index] < 0xF0)
552  {
553  length = 3;
554  }
555  else
556  {
557  length = 4;
558  }
559 
560  SetImage(strS[0].substr(index,length).c_str(), new Image(BMPフォント, { c%32*w, (c/32+12)*h, w , h }));
561 
562  index += length;
563  ++c;
564  }
565 
566 
567  return true;
568  }
569 
571  int GetSize() const
572  {
573  return this->size;
574  }
575 
577  int GetDrawStringWidth(const VariadicStream &幅を計算する文字列) const
578  {
579  int 最大幅 = 0;
580 
581  for (auto 文字列 : 幅を計算する文字列.StringS)
582  {
583  unsigned char lead;
584  int charSize = 0;
585  int 幅 = 0;
586 
587  for (auto it = 文字列.begin(); it != 文字列.end(); it += charSize)
588  {
589  lead = *it;
590  if (lead < 0x20){ charSize = 1; continue; }//制御文字は無視
591  else if (lead < 0x80){ charSize = 1; }
592  else if (lead < 0xE0){ charSize = 2; }
593  else if (lead < 0xF0){ charSize = 3; }
594  else { charSize = 4; }
595 
596  Image* buf = GetHash(文字列.substr(std::distance(文字列.begin(), it), charSize).c_str(), charSize);
597 
598  if (buf)
599  {
600  幅 += buf->GetWidth();
601  }
602  else
603  {
604  幅 += size;
605  }
606  }
607 
608  最大幅 = std::max(幅, 最大幅);
609  }
610  return 最大幅;
611  }
612 
615  bool Draw(const Point &座標, const Color &描画色, const VariadicStream &描画する文字列 , bool 反転フラグ = false) const override
616  {
617  Point 位置 = 座標;
618 
619  for (auto it : 描画する文字列.StringS)
620  {
621  DrawUTFString(位置, it, 描画色);
622  位置.y += this->enterHeight;
623  }
624 
625  return true;
626  }
627 
629  bool DrawShadow(const Point &座標, Color 表色, Color 影色, const VariadicStream &描画する文字列) const
630  {
631  Draw({ 座標.x + 1, 座標.y + 1 }, 影色, 描画する文字列);
632  return Draw(座標, 表色, 描画する文字列);
633  }
634 
637  bool DrawRotate(const Point &座標, double 拡大率, double 角度, const Color &描画色, const VariadicStream &描画する文字列, bool 反転フラグ = false) const override
638  {
639  int 行数 = 描画する文字列.StringS.size();
640 
641  int X補正 = int(-GetDrawStringWidth(描画する文字列) * 拡大率 * 0.5);
642  int Y補正 = int(-enterHeight * 拡大率 * (0.5*行数-0.5));
643 
644  for (auto it : 描画する文字列.StringS)
645  {
646  DrawRotateUTFString(座標, X補正, Y補正, 拡大率, 角度, it, 描画色);
647  Y補正 += int(enterHeight * 拡大率);
648  }
649 
650  return true;
651  }
652 
655  bool DrawExtend(const Point &座標, double X拡大率, double Y拡大率, const Color &描画色, const VariadicStream &描画する文字列, bool 反転フラグ = false) const override
656  {
657  Point 位置 = 座標;
658 
659  for (auto it : 描画する文字列.StringS)
660  {
661  DrawUTFString(位置, X拡大率, Y拡大率, it, 描画色);
662  位置.y += this->enterHeight * Y拡大率;
663  }
664 
665  return true;
666  }
667 
670  void SetImage(const std::string &文字, Image *対応画像)
671  {
672  if (Loading::isLoading)
673  {
674  Loading::AddLoading([=]{ SetImage(文字,対応画像); });
675  return;
676  }
677 
678  int charSize;
679  auto it = 文字.begin();
680 
681  if (!GetUTFSize(*it, charSize)){ return; }
682  SetHash(文字.substr(std::distance(文字.begin(), it), charSize).c_str(), charSize, 対応画像);
683  }
684 
688  void SetImageS(const std::string &文字列, ImagePack *対応画像, int 登録数)
689  {
690  if (Loading::isLoading)
691  {
692  Loading::AddLoading([=]{ SetImageS(文字列, 対応画像,登録数); });
693  return;
694  }
695 
696  int charSize;
697 
698  auto it = 文字列.begin();
699  if (!GetUTFSize(*it, charSize)){ return; }
700  std::string str = 文字列.substr(0, charSize);
701 
702  for (int a = 0; a < 登録数;++a)
703  {
704  if (!GetUTFSize(*it, charSize)){ continue; }
705  SetHash(str.c_str(),charSize,対応画像[0][a]);
706  if (str[charSize - 1] == 0xff)
707  {
708  str[charSize - 2]++;
709  str[charSize - 1] = 0;
710  }
711  else
712  {
713  str[charSize - 1]++;
714  }
715  }
716  }
717  };
718 }
bool Draw(const Point &座標, const Color &描画色, const VariadicStream &描画する文字列, bool 反転フラグ=false) const override
文字を描画.
Definition: Font.h:615
const double PAI
円周率
Definition: SDX.h:26
double y
座標
Definition: Point.h:26
Fontのインターフェース.
Definition: IFont.h:12
bool DrawExtend(const Rect &描画領域, bool 反転フラグ=false) const override
指定矩形内に描画.
Definition: Image.h:201
bool MakeBMPFont(const std::string テキストファイル名)
BMPフォントデータを生成する.
Definition: Font.h:289
void SetImageS(const std::string &文字列, ImagePack *対応画像, int 登録数)
指定した文字から連続してに対応するImageをまとめて設定.
Definition: Font.h:688
点を表す図形クラス.
Definition: Point.h:22
入出力可能なテキストかバイナリファイルを表すクラス.
Definition: File.h:29
std::vector< std::string > GetLineS()
ファイルを改行区切りで一括して読み込む.
Definition: File.h:390
TrueTypeFontとBMPFontをまとめて扱うクラス.
Definition: Font.h:25
std::vector< std::string > StringS
一行ずつの文字列.
Definition: VariadicStream.h:53
読込のみ
bool DrawRotate(const Point &座標, double 拡大率, double 角度, bool 反転フラグ=false) const override
角度、拡大率を指定して描画.
Definition: Image.h:229
bool DrawRotate(const Point &座標, double 拡大率, double 角度, const Color &描画色, const VariadicStream &描画する文字列, bool 反転フラグ=false) const override
文字を回転して描画.
Definition: Font.h:637
int GetSize() const
大きさを取得.
Definition: Font.h:571
画像データを表すクラス.
Definition: Image.h:17
色を表すクラス.
Definition: Color.h:11
bool Load(const char *フォント名, int 大きさ, int 行間=0, bool 高品質レンダリングフラグ=true)
フォントを作成する.
Definition: Font.h:183
bool LoadBMPFont(const Image &BMPフォント, const std::string テキストファイル名)
MakeBMPFontで生成したBMPフォントデータを読み込む.
Definition: Font.h:445
static void AddLoading(std::function< void(void)> &&読み込み関数)
非同期読み込み処理に追加.
Definition: Loading.h:96
int GetHeight() const
高さを取得.
Definition: Image.h:310
int GetWidth() const
幅を取得.
Definition: Image.h:304
bool Release() const
フォントハンドルをメモリから開放する.
Definition: Font.h:207
TTF_Font * GetHandle() const
フォントのハンドルを取得.
Definition: Font.h:220
static SDL_Renderer * GetHandle()
スクリーンハンドルを取得.
Definition: Screen.h:26
Image MakeImage(Color 文字色, bool 反転フラグ, const VariadicStream &描画する文字列) const
FontからImageを生成.
Definition: Font.h:226
bool DrawShadow(const Point &座標, Color 表色, Color 影色, const VariadicStream &描画する文字列) const
文字を影付きで描画.
Definition: Font.h:629
void SetSize(int 大きさ, int 行間=0)
フォントの行間を再指定する.
Definition: Font.h:279
可変数引数な文字列を処理するクラス.
Definition: VariadicStream.h:25
bool DrawExtend(const Point &座標, double X拡大率, double Y拡大率, const Color &描画色, const VariadicStream &描画する文字列, bool 反転フラグ=false) const override
拡大率を指定して文字を描画.
Definition: Font.h:655
double x
座標
Definition: Point.h:25
複数のImageをまとめるクラス.
Definition: ImagePack.h:17
void SetColor(const Color &描画色)
描画色を指定.
Definition: Image.h:316
bool Draw(const Point &座標, bool 反転フラグ=false) const override
指定座標に描画.
Definition: Image.h:181
int GetDrawStringWidth(const VariadicStream &幅を計算する文字列) const
描画時の幅を取得.
Definition: Font.h:577
Font(const char *フォント名, int 大きさ, int 行間=0, bool 高品質レンダリングフラグ=true)
コンストラクタ
Definition: Font.h:175
void SetImage(const std::string &文字, Image *対応画像)
指定した文字に対応するImageを設定.
Definition: Font.h:670