Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- /home/xerpi/Desktop/VITA/vita2dlib/libvita2d/source/vita2d_pgf.c 2016-08-19 12:02:39.059333224 +0200
- +++ vita2d_pgf.c 2016-08-28 11:49:45.000000000 +0200
- @@ -12,12 +12,17 @@
- #include "utils.h"
- #include "shared.h"
- -#define ATLAS_DEFAULT_W 512
- -#define ATLAS_DEFAULT_H 512
- +#define ATLAS_DEFAULT_W 1024
- +#define ATLAS_DEFAULT_H 1024
- +
- +#define IS_LATIN_CHAR(c) (((unsigned short)(c) <= 0x00FF) || (0x0400 <= (unsigned short)(c) && (unsigned short)(c) <= 0x04FF))
- +#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)
- typedef struct vita2d_pgf {
- SceFontLibHandle lib_handle;
- - SceFontHandle font_handle;
- + SceFontHandle font_latin_handle;
- + SceFontHandle font_japanese_handle;
- + SceFontHandle font_korean_handle;
- texture_atlas *atlas;
- float vsize;
- } vita2d_pgf;
- @@ -43,7 +48,7 @@
- SceFontNewLibParams params = {
- font,
- - 1,
- + 3,
- NULL,
- pgf_alloc_func,
- pgf_free_func,
- @@ -61,14 +66,32 @@
- return NULL;
- }
- - font->font_handle = sceFontOpen(font->lib_handle, 0, 0, &error);
- + // Latin
- + font->font_latin_handle = sceFontOpen(font->lib_handle, 1, 0, &error);
- if (error != 0) {
- sceFontDoneLib(font->lib_handle);
- free(font);
- return NULL;
- }
- - sceFontGetFontInfo(font->font_handle, &fontinfo);
- + // Japanese
- + font->font_japanese_handle = sceFontOpen(font->lib_handle, 0, 0, &error);
- + if (error != 0) {
- + sceFontClose(font->font_latin_handle);
- + sceFontDoneLib(font->lib_handle);
- + free(font);
- + return NULL;
- + }
- +
- + // Korean
- + font->font_korean_handle = sceFontOpen(font->lib_handle, 17, 0, &error);
- + if (error != 0) {
- + sceFontDoneLib(font->lib_handle);
- + free(font);
- + return NULL;
- + }
- +
- + sceFontGetFontInfo(font->font_latin_handle, &fontinfo);
- font->vsize = (fontinfo.fontStyle.fontV / fontinfo.fontStyle.fontVRes)
- * SCREEN_DPI;
- @@ -81,7 +104,9 @@
- void vita2d_free_pgf(vita2d_pgf *font)
- {
- if (font) {
- - sceFontClose(font->font_handle);
- + sceFontClose(font->font_korean_handle);
- + sceFontClose(font->font_japanese_handle);
- + sceFontClose(font->font_latin_handle);
- sceFontDoneLib(font->lib_handle);
- texture_atlas_free(font->atlas);
- free(font);
- @@ -90,12 +115,21 @@
- static int atlas_add_glyph(vita2d_pgf *font, unsigned int character)
- {
- + SceFontHandle font_handle;
- SceFontCharInfo char_info;
- bp2d_position position;
- void *texture_data;
- vita2d_texture *tex = font->atlas->texture;
- - if (sceFontGetCharInfo(font->font_handle, character, &char_info) < 0)
- + if (IS_LATIN_CHAR(character)) {
- + font_handle = font->font_latin_handle;
- + } else if (IS_NOT_HANGUL_CHAR(character)) {
- + font_handle = font->font_japanese_handle;
- + } else {
- + font_handle = font->font_korean_handle;
- + }
- +
- + if (sceFontGetCharInfo(font_handle, character, &char_info) < 0)
- return 0;
- bp2d_size size = {
- @@ -127,13 +161,14 @@
- glyph_image.pad = 0;
- glyph_image.bufferPtr = (unsigned int)texture_data;
- - return sceFontGetCharGlyphImage(font->font_handle, character, &glyph_image) == 0;
- + return sceFontGetCharGlyphImage(font_handle, character, &glyph_image) == 0;
- }
- int generic_pgf_draw_text(vita2d_pgf *font, int draw, int *height,
- int x, int y, unsigned int color, float scale,
- const char *text)
- {
- + int i;
- unsigned int character;
- bp2d_rectangle rect;
- texture_atlas_entry_data data;
- @@ -143,8 +178,8 @@
- int pen_x = x;
- int pen_y = y;
- - while (*text) {
- - character = utf8_character(&text);
- + for (i = 0; text[i];) {
- + i += utf8_to_ucs2(&text[i], &character);
- if (character == '\n') {
- if (pen_x > max_x)
Add Comment
Please, Sign In to add comment