diff options
Diffstat (limited to 'src/libjin/graphics/fonts')
-rw-r--r-- | src/libjin/graphics/fonts/je_texture_font.cpp | 148 | ||||
-rw-r--r-- | src/libjin/graphics/fonts/je_texture_font.h | 19 | ||||
-rw-r--r-- | src/libjin/graphics/fonts/je_ttf.cpp | 14 | ||||
-rw-r--r-- | src/libjin/graphics/fonts/je_ttf.h | 8 |
4 files changed, 72 insertions, 117 deletions
diff --git a/src/libjin/graphics/fonts/je_texture_font.cpp b/src/libjin/graphics/fonts/je_texture_font.cpp index 8facc34..9014509 100644 --- a/src/libjin/graphics/fonts/je_texture_font.cpp +++ b/src/libjin/graphics/fonts/je_texture_font.cpp @@ -17,28 +17,83 @@ namespace JinEngine namespace Fonts { - TextureFont * TextureFont::createTextureFont(const Bitmap* bitmap, const Content& codepoints, int cellw, int cellh) + TextureFont::TextureFont(const Bitmap* bitmap, const Content& codepoints, int cellw, int cellh) + : Graphic(bitmap) + , Font(cellh) { - TextureFont* tf = new TextureFont(bitmap, codepoints, cellw, cellh); - return tf; + TextureGlyph glyph; + Vector2<int> count(bitmap->getWidth() / cellw, bitmap->getHeight() / cellh); + glyph.w = cellw; + glyph.h = cellh; + for (int y = 0; y < count.row; ++y) + { + glyph.y = y * cellh; + for (int x = 0; x < count.colum; ++x) + { + glyph.x = x * cellw; + if (x + y * count.colum >= codepoints.size()) + return; + glyphs.insert(std::pair<Codepoint, TextureGlyph>(codepoints[x + y * count.colum], glyph)); + } + } } - TextureFont * TextureFont::createTextureFont(const Bitmap* bitmap, const Text& codepoints, int cellw, int cellh) + TextureFont::TextureFont(const Bitmap* bitmap, const Content& codepoints, Color mask, int cellh) + : Graphic(bitmap) + , Font(cellh) { - TextureFont* tf = new TextureFont(bitmap, *codepoints, cellw, cellh); - return tf; + TextureGlyph glyph; + glyph.h = cellh; + int w = bitmap->getWidth(); + int h = bitmap->getHeight(); + int i = 0; + for (int y = 0; y < h; y += cellh) + { + glyph.y = y; + bool newc = false; + for (int x = 0; x <= w; ++x) + { + if (x == w && newc) + { + glyph.w = x - glyph.x; + if (i >= codepoints.size()) + return; + glyphs.insert(std::pair<Codepoint, TextureGlyph>(codepoints[i], glyph)); + ++i; + newc = false; + break; + } + Color c = bitmap->getPixels()[x + y * w]; + if (!newc && c != mask) + { + glyph.x = x; + newc = true; + } + else if (newc && c == mask) + { + glyph.w = x - glyph.x; + if (i >= codepoints.size()) + return; + glyphs.insert(std::pair<Codepoint, TextureGlyph>(codepoints[i], glyph)); + if (codepoints[i] == 't') + { + int a = 10; + } + ++i; + newc = false; + } + } + } } - TextureFont* TextureFont::createTextureFont(const Bitmap* bitmap, const Content& codepoints, Color mask, int cellh) + TextureFont::TextureFont(const Bitmap* bitmap, const Text& text, Color mask, int cellh) + : TextureFont(bitmap, *text, mask, cellh) { - TextureFont* tf = new TextureFont(bitmap, codepoints, mask, cellh); - return tf; } - TextureFont* TextureFont::createTextureFont(const Bitmap* bitmap, const Text& codepoints, Color mask, int cellh) + TextureFont::TextureFont(const Bitmap* bitmap, const Text& text, int cellw, int cellh) + : TextureFont(bitmap, *text, cellw, cellh) { - TextureFont* tf = new TextureFont(bitmap, *codepoints, mask, cellh); - return tf; } TextureFont::~TextureFont() @@ -248,75 +303,6 @@ namespace JinEngine delete page; } - TextureFont::TextureFont(const Bitmap* bitmap, const Content& codepoints, int cellw, int cellh) - : Graphic(bitmap) - , Font(cellh) - { - TextureGlyph glyph; - Vector2<int> count(bitmap->getWidth() / cellw, bitmap->getHeight() / cellh); - glyph.w = cellw; - glyph.h = cellh; - for (int y = 0; y < count.row; ++y) - { - glyph.y = y * cellh; - for (int x = 0; x < count.colum; ++x) - { - glyph.x = x * cellw; - if (x + y * count.colum >= codepoints.size()) - return; - glyphs.insert(std::pair<Codepoint, TextureGlyph>(codepoints[x + y * count.colum], glyph)); - } - } - } - - TextureFont::TextureFont(const Bitmap* bitmap, const Content& codepoints, Color mask, int cellh) - : Graphic(bitmap) - , Font(cellh) - { - TextureGlyph glyph; - glyph.h = cellh; - int w = bitmap->getWidth(); - int h = bitmap->getHeight(); - int i = 0; - for (int y = 0; y < h; y += cellh) - { - glyph.y = y; - bool newc = false; - for (int x = 0; x <= w; ++x) - { - if (x == w && newc) - { - glyph.w = x - glyph.x; - if (i >= codepoints.size()) - return; - glyphs.insert(std::pair<Codepoint, TextureGlyph>(codepoints[i], glyph)); - ++i; - newc = false; - break; - } - Color c = bitmap->getPixels()[x + y * w]; - if (!newc && c != mask) - { - glyph.x = x; - newc = true; - } - else if (newc && c == mask) - { - glyph.w = x - glyph.x; - if (i >= codepoints.size()) - return; - glyphs.insert(std::pair<Codepoint, TextureGlyph>(codepoints[i], glyph)); - if (codepoints[i] == 't') - { - int a = 10; - } - ++i; - newc = false; - } - } - } - } - } } }
\ No newline at end of file diff --git a/src/libjin/graphics/fonts/je_texture_font.h b/src/libjin/graphics/fonts/je_texture_font.h index df8f956..a753cac 100644 --- a/src/libjin/graphics/fonts/je_texture_font.h +++ b/src/libjin/graphics/fonts/je_texture_font.h @@ -26,26 +26,25 @@ namespace JinEngine class TextureFont : public Font, public Graphic { public: - /// /// /// - static TextureFont* createTextureFont(const Bitmap* bitmap, const Content& codepoints, int cellw, int cellh); + TextureFont(const Bitmap* bitmap, const Content& codepoints, int cellw, int cellh); /// /// /// - static TextureFont* createTextureFont(const Bitmap* bitmap, const Text& text, int cellw, int cellh); + TextureFont(const Bitmap* bitmap, const Content& codepoints, Color mask, int cellh); /// /// /// - static TextureFont* createTextureFont(const Bitmap* bitmap, const Content& codepoints, Color mask, int cellh); + TextureFont(const Bitmap* bitmap, const Text& text, Color mask, int cellh); /// /// /// - static TextureFont* createTextureFont(const Bitmap* bitmap, const Text& text, Color mask, int cellh); + TextureFont(const Bitmap* bitmap, const Text& text, int cellw, int cellh); /// /// @@ -90,16 +89,6 @@ namespace JinEngine /// /// /// - TextureFont(const Bitmap* bitmap, const Content& codepoints, int cellw, int cellh); - - /// - /// - /// - TextureFont(const Bitmap* bitmap, const Content& codepoints, Color mask, int cellh); - - /// - /// - /// int getCharWidth(int c); /// diff --git a/src/libjin/graphics/fonts/je_ttf.cpp b/src/libjin/graphics/fonts/je_ttf.cpp index 3f664fa..fec8cd4 100644 --- a/src/libjin/graphics/fonts/je_ttf.cpp +++ b/src/libjin/graphics/fonts/je_ttf.cpp @@ -28,20 +28,6 @@ namespace JinEngine // TTFData ////////////////////////////////////////////////////////////////////////////////////////////////////// - TTFData* TTFData::createTTFData(const unsigned char* data, unsigned int size) - { - TTFData* ttf = nullptr; - try - { - ttf = new TTFData(data, size); - return ttf; - } - catch (...) - { - return nullptr; - } - } - TTFData::TTFData(const unsigned char* d, unsigned int s) { raw.size = s; diff --git a/src/libjin/graphics/fonts/je_ttf.h b/src/libjin/graphics/fonts/je_ttf.h index c2766b4..c5e2af5 100644 --- a/src/libjin/graphics/fonts/je_ttf.h +++ b/src/libjin/graphics/fonts/je_ttf.h @@ -37,11 +37,10 @@ namespace JinEngine class TTFData : public Object { public: - /// /// /// - static TTFData* createTTFData(const unsigned char* data, unsigned int size); + TTFData(const unsigned char* data, unsigned int size); /// /// @@ -93,11 +92,6 @@ namespace JinEngine /// /// /// - TTFData(const unsigned char* data, unsigned int size); - - /// - /// - /// stbtt_fontinfo info; /// |