Skip to content

Commit

Permalink
Merge pull request #9 from doTulio/ExtraCharactersSupport
Browse files Browse the repository at this point in the history
Add a font supporting more characters
  • Loading branch information
JayFoxRox authored Apr 23, 2017
2 parents 8f91dcb + 7e5ffe9 commit 2a228ad
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 4 deletions.
Binary file removed data/font/andale_mono_regular_48.png
Binary file not shown.
Binary file removed data/font/andale_mono_regular_48.zfi
Binary file not shown.
Binary file removed data/font/arial_black_regular_65.png
Binary file not shown.
Binary file removed data/font/arial_black_regular_65.zfi
Binary file not shown.
Binary file added data/font/liberation_sans_bold_65.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/font/liberation_sans_bold_65.zfi
Binary file not shown.
5 changes: 3 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ int main(int argc, char* argv[]) {

std::shared_ptr<Texture> texture = std::make_shared<Texture>("data/font/main");

std::shared_ptr<Text> text = std::make_shared<Text>("data/font/arial_black_regular_65");
std::shared_ptr<Text> text = std::make_shared<Text>("data/font/liberation_sans_bold_65");

std::string meshPath = "data/mesh/cube";
std::shared_ptr<Mesh> mesh = std::make_shared<Mesh>();
Expand Down Expand Up @@ -466,7 +466,8 @@ int main(int argc, char* argv[]) {

// Test text
glColor3f(0.1f, 0.2f, 0.5f);
text->draw(std::string("boats: ") + std::to_string(boats.size()) + std::string("\nsparks: ") + std::to_string(sparks.size()) + std::string("\nus/F: ") + std::to_string(uspf.count()));
char symbolMicro = '\xB5';
text->draw(std::string("boats: ") + std::to_string(boats.size()) + std::string("\nsparks: ") + std::to_string(sparks.size()) + "\n" + symbolMicro + "/F: " + std::to_string(uspf.count()));

glPopMatrix();
#endif
Expand Down
10 changes: 8 additions & 2 deletions text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Text {
};

struct __attribute__((packed)) Symbol {
int32_t id;
uint32_t id;
int32_t page;
uint8_t width;
uint8_t height;
Expand Down Expand Up @@ -91,7 +91,13 @@ class Text {
}

auto isMatchingSymbol = [&](const Symbol& symbol) -> bool {
return symbol.id == static_cast<uint32_t>(c);
/*
casting first to unsigned char is necessary, because if we
cast to uint32_t directly, the machine sign extends, meaning
that the match would fail because of the sign.
*/
unsigned char chUnsigned = static_cast<unsigned char>(c);
return symbol.id == static_cast<uint32_t>(chUnsigned);
};
const auto& it = std::find_if(symbols.begin(), symbols.end(), isMatchingSymbol);
assert(it != symbols.end());
Expand Down

0 comments on commit 2a228ad

Please sign in to comment.