aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/Graphics
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-10-15 12:49:54 +0800
committerchai <chaifix@163.com>2018-10-15 12:49:54 +0800
commit68b60be0d1da84aa670d29b87b26ab3e3db51b69 (patch)
tree661b2b1aff66ce3068c2bd6e4abe66734e3d1706 /src/libjin/Graphics
parent437ea76fc9b61240b2f8d1b0b800f3f7a73af766 (diff)
*增加默认字体
Diffstat (limited to 'src/libjin/Graphics')
-rw-r--r--src/libjin/Graphics/Font/Font.h10
-rw-r--r--src/libjin/Graphics/Font/TTF.cpp45
-rw-r--r--src/libjin/Graphics/Font/TTF.h1
-rw-r--r--src/libjin/Graphics/Font/TextureFont.cpp2
4 files changed, 21 insertions, 37 deletions
diff --git a/src/libjin/Graphics/Font/Font.h b/src/libjin/Graphics/Font/Font.h
index 424c324..fcc559c 100644
--- a/src/libjin/Graphics/Font/Font.h
+++ b/src/libjin/Graphics/Font/Font.h
@@ -13,7 +13,10 @@ namespace graphics
class Font
{
public:
- Font() {}
+ Font(unsigned fontsize)
+ : fontSize(fontsize)
+ {
+ }
virtual ~Font() {};
virtual Page* typeset(const Text& text, int lineheight, int spacing = 0) = 0;
@@ -23,6 +26,11 @@ namespace graphics
virtual void print(const Content& text, int x, int y, int lineheight, int spacing = 0) = 0;
virtual void print(const Text& text, int x, int y, int lineheight, int spacing = 0) = 0;
+ inline unsigned getFontSize() { return fontSize; };
+
+ protected:
+ unsigned fontSize;
+
};
} // graphics
diff --git a/src/libjin/Graphics/Font/TTF.cpp b/src/libjin/Graphics/Font/TTF.cpp
index 5c77e7f..ff4dcc7 100644
--- a/src/libjin/Graphics/Font/TTF.cpp
+++ b/src/libjin/Graphics/Font/TTF.cpp
@@ -55,12 +55,12 @@ namespace graphics
free(raw.data);
}
- TTF* TTFData::createTTF(unsigned ttfsize)
+ TTF* TTFData::createTTF(unsigned fontSize)
{
TTF* ttf;
try
{
- ttf = new TTF(this, ttfsize);
+ ttf = new TTF(this, fontSize);
}
catch (...)
{
@@ -150,31 +150,6 @@ namespace graphics
const int TTF::TEXTURE_WIDTHS[] = { 128, 256, 256, 512, 512, 1024, 1024 };
const int TTF::TEXTURE_HEIGHTS[] = { 128, 128, 256, 256, 512, 512, 1024 };
- /* utf8 byte string to unicode codepoint */
- static const char* utf8toCodepoint(const char *p, Codepoint *res) {
- unsigned x, mask, shift;
- switch (*p & 0xf0) {
- case 0xf0: mask = 0x07; shift = 18; break;
- case 0xe0: mask = 0x0f; shift = 12; break;
- case 0xc0:
- case 0xd0: mask = 0x1f; shift = 6; break;
- default:
- *res = *p;
- return p + 1;
- }
- x = (*p & mask) << shift;
- do {
- if (*(++p) == '\0') {
- *res = x;
- return p;
- }
- shift -= 6;
- x |= (*p & 0x3f) << shift;
- } while (shift);
- *res = x;
- return p + 1;
- }
-
/* little endian unicode */
static const char* unicodeLittleEndian(const char* p, unsigned* res)
{
@@ -195,11 +170,11 @@ namespace graphics
}
TTF::TTF(TTFData* f, unsigned int fontSize)
- : cursor(0, 0)
+ : Font(fontSize)
+ , cursor(0, 0)
, ttf(f)
- , ttfsize(fontSize)
{
- ttf->pushTTFsize(ttfsize);
+ ttf->pushTTFsize(fontSize);
ttf->getVMetrics(&baseline, &descent);
estimateSize();
ttf->popTTFsize();
@@ -341,7 +316,7 @@ namespace graphics
int TTF::getCharWidth(int c)
{
int adw, lsb;
- ttf->pushTTFsize(ttfsize);
+ ttf->pushTTFsize(fontSize);
ttf->getHMetrics(c, &adw, &lsb);
ttf->popTTFsize();
return adw;
@@ -354,7 +329,7 @@ namespace graphics
int TTF::getTextWidth(const Content& t, int spacing)
{
- ttf->pushTTFsize(ttfsize);
+ ttf->pushTTFsize(fontSize);
int res = 0;
int tmp = 0;
for (Codepoint c : t)
@@ -376,7 +351,7 @@ namespace graphics
int TTF::getTextHeight(const Content& t, int lineheight)
{
- ttf->pushTTFsize(ttfsize);
+ ttf->pushTTFsize(fontSize);
int res = 0;
bool newline = true;
for (Codepoint c : t)
@@ -396,7 +371,7 @@ namespace graphics
void TTF::getTextBox(const Content& text, int* w, int* h, int lineheight, int spacing)
{
- ttf->pushTTFsize(ttfsize);
+ ttf->pushTTFsize(fontSize);
*w = 0;
*h = 0;
int tmp = 0;
@@ -426,7 +401,7 @@ namespace graphics
TTF::TTFGlyph& TTF::bakeGlyph(unsigned int character)
{
int w, h, xoff, yoff;
- ttf->pushTTFsize(ttfsize);
+ ttf->pushTTFsize(fontSize);
GLuint atlas = atlases.back();
const Color* bitmap = ttf->getCodepointBitmap(character, &w, &h, &xoff, &yoff);
int adw, lsb;
diff --git a/src/libjin/Graphics/Font/TTF.h b/src/libjin/Graphics/Font/TTF.h
index 7f4f873..4e9a7ae 100644
--- a/src/libjin/Graphics/Font/TTF.h
+++ b/src/libjin/Graphics/Font/TTF.h
@@ -117,7 +117,6 @@ namespace graphics
std::vector<GLuint> atlases;
std::map<Codepoint, TTFGlyph> glyphs;
TTFData* ttf;
- const unsigned int ttfsize;
int baseline;
int descent;
diff --git a/src/libjin/Graphics/Font/TextureFont.cpp b/src/libjin/Graphics/Font/TextureFont.cpp
index 4dde236..7ee1962 100644
--- a/src/libjin/Graphics/Font/TextureFont.cpp
+++ b/src/libjin/Graphics/Font/TextureFont.cpp
@@ -231,6 +231,7 @@ namespace graphics
TextureFont::TextureFont(const Bitmap* bitmap, const Content& codepoints, int cellw, int cellh)
: Drawable(bitmap)
+ , Font(cellh)
{
TextureGlyph glyph;
Vector2<int> count(bitmap->getWidth() / cellw, bitmap->getHeight() / cellh);
@@ -251,6 +252,7 @@ namespace graphics
TextureFont::TextureFont(const Bitmap* bitmap, const Content& codepoints, Color mask, int cellh)
: Drawable(bitmap)
+ , Font(cellh)
{
TextureGlyph glyph;
glyph.h = cellh;