diff options
Diffstat (limited to 'src/libjin/Graphics/Font')
-rw-r--r-- | src/libjin/Graphics/Font/je_decoder.h | 6 | ||||
-rw-r--r-- | src/libjin/Graphics/Font/je_font.h | 1 | ||||
-rw-r--r-- | src/libjin/Graphics/Font/je_text.cpp | 8 | ||||
-rw-r--r-- | src/libjin/Graphics/Font/je_text.h | 94 | ||||
-rw-r--r-- | src/libjin/Graphics/Font/je_texture_font.h | 77 | ||||
-rw-r--r-- | src/libjin/Graphics/Font/je_ttf.h | 156 |
6 files changed, 334 insertions, 8 deletions
diff --git a/src/libjin/Graphics/Font/je_decoder.h b/src/libjin/Graphics/Font/je_decoder.h index 162f22e..36cbda7 100644 --- a/src/libjin/Graphics/Font/je_decoder.h +++ b/src/libjin/Graphics/Font/je_decoder.h @@ -16,6 +16,7 @@ namespace JinEngine class Decoder { public: + /// /// Decode a code unit. /// @@ -32,6 +33,7 @@ namespace JinEngine /// @return Next code unit location. /// virtual const void* next(const void* data) const = 0; + }; /// @@ -40,6 +42,7 @@ namespace JinEngine class Utf8 : public Decoder { public: + /// /// Decode a code unit. /// @@ -56,6 +59,7 @@ namespace JinEngine /// @return Next code unit location. /// const void* next(const void* data) const override; + }; /// @@ -64,6 +68,7 @@ namespace JinEngine class Ascii : public Decoder { public: + /// /// Decode a code unit. /// @@ -80,6 +85,7 @@ namespace JinEngine /// @return Next code unit location. /// const void* next(const void* data) const override; + }; } // namespace Graphics diff --git a/src/libjin/Graphics/Font/je_font.h b/src/libjin/Graphics/Font/je_font.h index ec60c21..75dd4c5 100644 --- a/src/libjin/Graphics/Font/je_font.h +++ b/src/libjin/Graphics/Font/je_font.h @@ -89,6 +89,7 @@ namespace JinEngine inline unsigned getFontSize() { return mFontSize; }; protected: + unsigned mFontSize; }; diff --git a/src/libjin/Graphics/Font/je_text.cpp b/src/libjin/Graphics/Font/je_text.cpp index 70a1c36..75dfc7b 100644 --- a/src/libjin/Graphics/Font/je_text.cpp +++ b/src/libjin/Graphics/Font/je_text.cpp @@ -20,8 +20,8 @@ namespace JinEngine { switch (encode) { - case Encode::UTF8: decoder = new Utf8(); break; - case Encode::ASCII: decoder = new Ascii(); break; + case Encode::UTF8: decoder = new Utf8(); break; + case Encode::ASCII: decoder = new Ascii(); break; } } @@ -33,8 +33,8 @@ namespace JinEngine { switch (encode) { - case Encode::UTF8: decoder = new Utf8(); break; - case Encode::ASCII: decoder = new Ascii(); break; + case Encode::UTF8: decoder = new Utf8(); break; + case Encode::ASCII: decoder = new Ascii(); break; } } diff --git a/src/libjin/Graphics/Font/je_text.h b/src/libjin/Graphics/Font/je_text.h index af40993..7436875 100644 --- a/src/libjin/Graphics/Font/je_text.h +++ b/src/libjin/Graphics/Font/je_text.h @@ -31,44 +31,134 @@ namespace JinEngine class Text { public: + /// + /// + /// Text(Encode encode, const void* data); + + /// + /// + /// Text(Encode encode, const void* data, unsigned int length); + + /// + /// + /// ~Text(); + /// + /// + /// const Content& getContent() const; + + /// + /// + /// const Content& operator*() const; private: + /// + /// + /// class Iterator { public: + + /// + /// + /// Iterator(const Iterator& itor); + + /// + /// + /// Iterator(const Encode& encode, const void* data, unsigned int length); + + /// + /// + /// ~Iterator(); + /// + /// + /// Codepoint get(); + //Iterator begin(); //Iterator end(); + + /// + /// + /// void toBegin(); + + /// + /// + /// void toEnd(); + + /// + /// + /// Codepoint operator *(); - /* prefix ++ */ + + /// + /// + /// Iterator& operator ++(); - /* postfix ++ */ + + /// + /// + /// Iterator operator ++(int); + + /// + /// + /// bool operator !=(const Iterator& itor); + + /// + /// + /// bool operator ==(const Iterator& itor); private: + + /// + /// + /// void operator = (const Iterator&); + /// + /// + /// const Encode encode; + + /// + /// + /// const Decoder* decoder; + + /// + /// + /// const void* p; + + /// + /// + /// const void* const data; + + /// + /// + /// unsigned int length; + }; + /// + /// + /// Content content; }; diff --git a/src/libjin/Graphics/Font/je_texture_font.h b/src/libjin/Graphics/Font/je_texture_font.h index 9805cda..43d92c8 100644 --- a/src/libjin/Graphics/Font/je_texture_font.h +++ b/src/libjin/Graphics/Font/je_texture_font.h @@ -25,36 +25,111 @@ namespace JinEngine , public Drawable { public: + + /// + /// + /// static TextureFont* createTextureFont(const Bitmap* bitmap, const Content& codepoints, int cellw, int cellh); + + /// + /// + /// static TextureFont* createTextureFont(const Bitmap* bitmap, const Text& text, int cellw, int cellh); + + /// + /// + /// static TextureFont* createTextureFont(const Bitmap* bitmap, const Content& codepoints, Color mask, int cellh); + + /// + /// + /// static TextureFont* createTextureFont(const Bitmap* bitmap, const Text& text, Color mask, int cellh); - + + /// + /// + /// ~TextureFont(); + /// + /// + /// Page* typeset(const Text& text, int lineheight, int spacing = 0) override; + + /// + /// + /// Page* typeset(const Content& text, int lineheight, int spacing = 0) override ; + /// + /// + /// void print(const Page* page, int x, int y) override; + + /// + /// + /// void print(const Content& text, int x, int y, int linehgiht, int spacing = 0) override; + + /// + /// + /// void print(const Text& text, int x, int y, int lineheight, int spacing = 0)override; private: + + /// + /// + /// struct TextureGlyph { float x, y, w, h; }; + /// + /// + /// 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); + + /// + /// + /// int getCharHeight(int c); + + /// + /// + /// int getTextWidth(const Content& text, int spacing = 0); + + /// + /// + /// int getTextHeight(const Content& text, int lineheight); + + /// + /// + /// void getTextBox(const Content& text, int* w, int* h, int lineheight, int spacing = 0); + + /// + /// + /// const TextureGlyph* findGlyph(Codepoint codepoint) const; + + /// + /// + /// std::map<Codepoint, TextureGlyph> glyphs; }; diff --git a/src/libjin/Graphics/Font/je_ttf.h b/src/libjin/Graphics/Font/je_ttf.h index e4314fe..9acb07e 100644 --- a/src/libjin/Graphics/Font/je_ttf.h +++ b/src/libjin/Graphics/Font/je_ttf.h @@ -34,32 +34,81 @@ namespace JinEngine class TTFData { public: + + /// + /// + /// static TTFData* createTTFData(const unsigned char* data, unsigned int size); + /// + /// + /// ~TTFData(); + /// + /// + /// TTF* createTTF(unsigned ttfsize); + /// + /// + /// void pushTTFsize(unsigned ttfsize); + + /// + /// + /// void popTTFsize(); + /// + /// + /// Channel* getCodepointBitmapAlpha(unsigned int codepoint, int* width, int* height, int* xoff, int* yoff) const; + + /// + /// + /// Color* getCodepointBitmap(unsigned int codepoint, int* width, int* height, int* xoff, int* yoff) const; + /// + /// + /// void getVMetrics(int* baseline, int* descent); + + /// + /// + /// void getHMetrics(unsigned int codepoint, int* advanceWidth, int* leftSideBearing); private: + + /// + /// + /// static const unsigned int FONT_SIZE = 12; + /// + /// + /// TTFData(const unsigned char* data, unsigned int size); + /// + /// + /// stbtt_fontinfo info; + + /// + /// + /// struct { unsigned char* data; unsigned int size; } raw; + + /// + /// + /// std::vector<float> scales; }; @@ -69,18 +118,43 @@ namespace JinEngine public: //static TTF* createTTF(TTFData* ttfData, unsigned ttfSzie); + /// + /// + /// Page* typeset(const Text& text, int lineheight, int spacing = 0) override; + + /// + /// + /// Page* typeset(const Content& text, int lineheight, int spacing = 0) override; + /// + /// + /// void print(const Text& text, int x, int y, int lineheight, int spacing = 0) override; + + /// + /// + /// void print(const Content& text, int x, int y, int lineheight, int spacing = 0) override; + + /// + /// + /// void print(const Page* page, int x, int y) override; + /// + /// + /// ~TTF(); private: + friend class TTFData; + /// + /// + /// struct TTFGlyph { GLuint atlas; @@ -94,34 +168,114 @@ namespace JinEngine unsigned int width, height; }; + /// + /// + /// static const int TEXTURE_SIZE_LEVELS_COUNT = 7; + + /// + /// + /// static const int TEXTURE_SIZE_LEVEL_MAX = TEXTURE_SIZE_LEVELS_COUNT - 1; + + /// + /// + /// static const int TEXTURE_WIDTHS[TEXTURE_SIZE_LEVELS_COUNT]; + + /// + /// + /// static const int TEXTURE_HEIGHTS[TEXTURE_SIZE_LEVELS_COUNT]; + /// + /// + /// TTF(TTFData* ttf, Codepoint ttfSize); + /// + /// + /// void estimateSize(); + + /// + /// + /// GLuint createAtlas(); + + /// + /// + /// TTFGlyph& bakeGlyph(Codepoint character); + + /// + /// + /// TTFGlyph& findGlyph(Codepoint character); + /// + /// + /// int getCharWidth(int c); + + /// + /// + /// int getCharHeight(int c); + /// + /// + /// int getTextWidth(const Content& text, int spacing = 0); + + /// + /// + /// int getTextHeight(const Content& text, int lineheight); + + /// + /// + /// void getTextBox(const Content& text, int* w, int* h, int lineheight, int spacing = 0); + /// + /// + /// int textureWidth; + + /// + /// + /// int textureHeight; + + /// + /// + /// std::vector<GLuint> atlases; + + /// + /// + /// std::map<Codepoint, TTFGlyph> glyphs; + + /// + /// + /// TTFData* ttf; + + /// + /// + /// int baseline; + + /// + /// + /// int descent; - /* cursor helped render to texture */ + /// + /// + /// Math::Vector2<float> cursor; }; |