-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
143 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,74 @@ | ||
#include "FontConfig.h" | ||
#include <string.h> | ||
#include <stdlib.h> | ||
|
||
namespace ons_font { | ||
const static FontConfig __DEFAULT_FONT_CONFIG = | ||
FontConfig{0, 0, {0xff, 0xff, 0xff}, false, 1, {0x0, 0x0, 0x0}, 0, 0}; | ||
const FontConfig* DEFAULT_FONT_CONFIG() { return &__DEFAULT_FONT_CONFIG; } | ||
|
||
const int readFontConfig(const char *buf, ons_font::FontConfig *cfg) { | ||
ons_font::FONT_TYPE types = ons_font::GLOBAL_FONT; | ||
int offset = 0; | ||
if (buf[offset] >= '0' && buf[offset] <= '9') { | ||
types = ons_font::FONT_TYPE(buf[offset] - '0'); | ||
} | ||
offset++; | ||
if (buf[offset] != ':') { | ||
return 0; | ||
} | ||
offset++; | ||
auto default_config = ons_font::DEFAULT_FONT_CONFIG(); | ||
memcpy(cfg, default_config, sizeof(ons_font::FontConfig)); | ||
int start = offset; | ||
int field = 0; | ||
char buff[256]; | ||
#define IS_FONT_CONFIG_END(c) (c == '\0' || c == ';' || c == ' ' || c == '\n') | ||
while (1) { | ||
if (buf[offset] == ',' || IS_FONT_CONFIG_END(buf[offset])) { | ||
int size = offset - start; | ||
if (size > 0) { | ||
memcpy(buff, buf + start, size); | ||
buff[size] = '\0'; | ||
} else { | ||
buff[0] = '\0'; | ||
} | ||
start = offset + 1; | ||
if (buff[0] != '\0') { | ||
switch (field) { | ||
case 0: | ||
cfg->size = atoi(buff); | ||
break; | ||
case 1: | ||
cfg->size_ratio = atof(buff); | ||
break; | ||
case 2: | ||
utils::readColor(buff, &cfg->color); | ||
break; | ||
case 3: | ||
cfg->render_outline = buff[0] != '0' && buff[0] != 'f'; | ||
break; | ||
case 4: | ||
cfg->outline_size = atoi(buff); | ||
break; | ||
case 5: | ||
readColor(buff, &cfg->outline_color); | ||
break; | ||
case 6: | ||
cfg->offset_x = atoi(buff); | ||
break; | ||
case 7: | ||
cfg->offset_y = atoi(buff); | ||
break; | ||
} | ||
} | ||
field++; | ||
} | ||
if (IS_FONT_CONFIG_END(buf[offset])) { | ||
break; | ||
} | ||
offset++; | ||
} | ||
return offset; | ||
} | ||
}; // namespace ons_font |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,29 @@ | ||
|
||
#ifndef __FONT_CONFIG_H__ | ||
#define __FONT_CONFIG_H__ | ||
|
||
namespace ons_font { | ||
typedef unsigned char uchar3[3]; | ||
enum FONT_TYPE { | ||
GLOBAL_FONT, | ||
SENTENCE_FONT, | ||
ANIM_FONT, | ||
MENU_FONT, | ||
DAILOG_FONT, | ||
RUBY_FONT, | ||
}; | ||
struct FontConfig { | ||
int size; | ||
float size_ratio; | ||
uchar3 color; | ||
bool render_outline; | ||
int outline_size; | ||
uchar3 outline_color; | ||
int offset_x; | ||
int offset_y; | ||
}; | ||
const FontConfig* DEFAULT_FONT_CONFIG(); | ||
} // namespace ons_font | ||
|
||
#endif | ||
|
||
#ifndef __FONT_CONFIG_H__ | ||
#define __FONT_CONFIG_H__ | ||
#include "private/utils.h" | ||
|
||
namespace ons_font { | ||
enum FONT_TYPE { | ||
GLOBAL_FONT, | ||
SENTENCE_FONT, | ||
ANIM_FONT, | ||
MENU_FONT, | ||
DAILOG_FONT, | ||
RUBY_FONT, | ||
}; | ||
struct FontConfig { | ||
int size; | ||
float size_ratio; | ||
utils::uchar4 color; | ||
bool render_outline; | ||
int outline_size; | ||
utils::uchar4 outline_color; | ||
int offset_x; | ||
int offset_y; | ||
}; | ||
const FontConfig* DEFAULT_FONT_CONFIG(); | ||
const int readFontConfig(const char *buf, ons_font::FontConfig *cfg); | ||
} // namespace ons_font | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters