xerpi

Untitled

Aug 28th, 2016
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 3.70 KB | None | 0 0
  1. --- /home/xerpi/Desktop/VITA/vita2dlib/libvita2d/source/vita2d_pgf.c    2016-08-19 12:02:39.059333224 +0200
  2. +++ vita2d_pgf.c    2016-08-28 11:49:45.000000000 +0200
  3. @@ -12,12 +12,17 @@
  4.  #include "utils.h"
  5.  #include "shared.h"
  6.  
  7. -#define ATLAS_DEFAULT_W 512
  8. -#define ATLAS_DEFAULT_H 512
  9. +#define ATLAS_DEFAULT_W 1024
  10. +#define ATLAS_DEFAULT_H 1024
  11. +
  12. +#define IS_LATIN_CHAR(c) (((unsigned short)(c) <= 0x00FF) || (0x0400 <= (unsigned short)(c) && (unsigned short)(c) <= 0x04FF))
  13. +#define IS_NOT_HANGUL_CHAR(c) ((unsigned short)(c) < 0x3131) || ((unsigned short)(c) > 0x327F && (unsigned short)(c) < 0xAC00) || ((unsigned short)(c) > 0xD7A3 && (unsigned short)(c) != 0xFFE6)
  14.  
  15.  typedef struct vita2d_pgf {
  16.     SceFontLibHandle lib_handle;
  17. -   SceFontHandle font_handle;
  18. +   SceFontHandle font_latin_handle;
  19. +   SceFontHandle font_japanese_handle;
  20. +   SceFontHandle font_korean_handle;
  21.     texture_atlas *atlas;
  22.     float vsize;
  23.  } vita2d_pgf;
  24. @@ -43,7 +48,7 @@
  25.  
  26.     SceFontNewLibParams params = {
  27.         font,
  28. -       1,
  29. +       3,
  30.         NULL,
  31.         pgf_alloc_func,
  32.         pgf_free_func,
  33. @@ -61,14 +66,32 @@
  34.         return NULL;
  35.     }
  36.  
  37. -   font->font_handle = sceFontOpen(font->lib_handle, 0, 0, &error);
  38. +   // Latin
  39. +   font->font_latin_handle = sceFontOpen(font->lib_handle, 1, 0, &error);
  40.     if (error != 0) {
  41.         sceFontDoneLib(font->lib_handle);
  42.         free(font);
  43.         return NULL;
  44.     }
  45.  
  46. -   sceFontGetFontInfo(font->font_handle, &fontinfo);
  47. +   // Japanese
  48. +   font->font_japanese_handle = sceFontOpen(font->lib_handle, 0, 0, &error);
  49. +   if (error != 0) {
  50. +       sceFontClose(font->font_latin_handle);
  51. +       sceFontDoneLib(font->lib_handle);
  52. +       free(font);
  53. +       return NULL;
  54. +   }
  55. +
  56. +   // Korean
  57. +   font->font_korean_handle = sceFontOpen(font->lib_handle, 17, 0, &error);
  58. +   if (error != 0) {
  59. +       sceFontDoneLib(font->lib_handle);
  60. +       free(font);
  61. +       return NULL;
  62. +   }
  63. +
  64. +   sceFontGetFontInfo(font->font_latin_handle, &fontinfo);
  65.     font->vsize = (fontinfo.fontStyle.fontV / fontinfo.fontStyle.fontVRes)
  66.         * SCREEN_DPI;
  67.  
  68. @@ -81,7 +104,9 @@
  69.  void vita2d_free_pgf(vita2d_pgf *font)
  70.  {
  71.     if (font) {
  72. -       sceFontClose(font->font_handle);
  73. +       sceFontClose(font->font_korean_handle);
  74. +       sceFontClose(font->font_japanese_handle);
  75. +       sceFontClose(font->font_latin_handle);
  76.         sceFontDoneLib(font->lib_handle);
  77.         texture_atlas_free(font->atlas);
  78.         free(font);
  79. @@ -90,12 +115,21 @@
  80.  
  81.  static int atlas_add_glyph(vita2d_pgf *font, unsigned int character)
  82.  {
  83. +   SceFontHandle font_handle;
  84.     SceFontCharInfo char_info;
  85.     bp2d_position position;
  86.     void *texture_data;
  87.     vita2d_texture *tex = font->atlas->texture;
  88.  
  89. -   if (sceFontGetCharInfo(font->font_handle, character, &char_info) < 0)
  90. +   if (IS_LATIN_CHAR(character)) {
  91. +       font_handle = font->font_latin_handle;
  92. +   } else if (IS_NOT_HANGUL_CHAR(character)) {
  93. +       font_handle = font->font_japanese_handle;
  94. +   } else {
  95. +       font_handle = font->font_korean_handle;
  96. +   }
  97. +
  98. +   if (sceFontGetCharInfo(font_handle, character, &char_info) < 0)
  99.         return 0;
  100.  
  101.     bp2d_size size = {
  102. @@ -127,13 +161,14 @@
  103.     glyph_image.pad = 0;
  104.     glyph_image.bufferPtr = (unsigned int)texture_data;
  105.  
  106. -   return sceFontGetCharGlyphImage(font->font_handle, character, &glyph_image) == 0;
  107. +   return sceFontGetCharGlyphImage(font_handle, character, &glyph_image) == 0;
  108.  }
  109.  
  110.  int generic_pgf_draw_text(vita2d_pgf *font, int draw, int *height,
  111.               int x, int y, unsigned int color, float scale,
  112.               const char *text)
  113.  {
  114. +   int i;
  115.     unsigned int character;
  116.     bp2d_rectangle rect;
  117.     texture_atlas_entry_data data;
  118. @@ -143,8 +178,8 @@
  119.     int pen_x = x;
  120.     int pen_y = y;
  121.  
  122. -   while (*text) {
  123. -       character = utf8_character(&text);
  124. +   for (i = 0; text[i];) {
  125. +       i += utf8_to_ucs2(&text[i], &character);
  126.  
  127.         if (character == '\n') {
  128.             if (pen_x > max_x)
Add Comment
Please, Sign In to add comment