aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-10-15 07:18:13 +0800
committerchai <chaifix@163.com>2018-10-15 07:18:13 +0800
commitddfedbff7d9ea4f344173ef2c228a51a778d7433 (patch)
tree4e8c40bee95f5ba91a2808ca9a14cea5937bea52
parentb1bbc998960fff2169dc5a992c47d08723472f9b (diff)
+从TTFData创建TTF的接口
-rw-r--r--bin/Jin.exebin524800 -> 524288 bytes
-rw-r--r--bin/jin.exebin524800 -> 524288 bytes
-rw-r--r--bin/main.lua4
-rw-r--r--src/libjin/Graphics/Font/TTF.cpp15
-rw-r--r--src/libjin/Graphics/Font/TTF.h14
-rw-r--r--src/libjin/Graphics/Font/Text.cpp19
-rw-r--r--src/libjin/Graphics/Font/Text.h4
-rw-r--r--src/libjin/Graphics/Image.h1
-rw-r--r--src/lua/modules/types.h16
9 files changed, 50 insertions, 23 deletions
diff --git a/bin/Jin.exe b/bin/Jin.exe
index e30c82c..24a6629 100644
--- a/bin/Jin.exe
+++ b/bin/Jin.exe
Binary files differ
diff --git a/bin/jin.exe b/bin/jin.exe
index e30c82c..24a6629 100644
--- a/bin/jin.exe
+++ b/bin/jin.exe
Binary files differ
diff --git a/bin/main.lua b/bin/main.lua
index 66fd4ba..bee78ca 100644
--- a/bin/main.lua
+++ b/bin/main.lua
@@ -1,4 +1,4 @@
-io.stdout:setvbuf("no")
+io.stdout:setvbuf("no")
local shader
local text
@@ -21,6 +21,6 @@ end
function jin.core.onDraw()
jin.graphics.useShader(shader)
- jin.graphics.print("this is a test", tf, 10, 10, 16)
+ jin.graphics.print("this 你好 is a test", tf, 10, 10, 16)
jin.graphics.unuseShader()
end \ No newline at end of file
diff --git a/src/libjin/Graphics/Font/TTF.cpp b/src/libjin/Graphics/Font/TTF.cpp
index 98e57dd..5c77e7f 100644
--- a/src/libjin/Graphics/Font/TTF.cpp
+++ b/src/libjin/Graphics/Font/TTF.cpp
@@ -55,6 +55,20 @@ namespace graphics
free(raw.data);
}
+ TTF* TTFData::createTTF(unsigned ttfsize)
+ {
+ TTF* ttf;
+ try
+ {
+ ttf = new TTF(this, ttfsize);
+ }
+ catch (...)
+ {
+ return nullptr;
+ }
+ return ttf;
+ }
+
/*
* (0, 0)
* +--------------+ ascent
@@ -417,6 +431,7 @@ namespace graphics
const Color* bitmap = ttf->getCodepointBitmap(character, &w, &h, &xoff, &yoff);
int adw, lsb;
{
+ /* bake glyph */
ttf->getHMetrics(character, &adw, &lsb);
ttf->popTTFsize();
if (cursor.x + adw > textureWidth )
diff --git a/src/libjin/Graphics/Font/TTF.h b/src/libjin/Graphics/Font/TTF.h
index 4f51138..7f4f873 100644
--- a/src/libjin/Graphics/Font/TTF.h
+++ b/src/libjin/Graphics/Font/TTF.h
@@ -19,11 +19,13 @@ namespace jin
{
namespace graphics
{
+
+ class TTF;
/**
* TTFData
- * |- TTF
- * |- TTF
+ * |- TTF(14px)
+ * |- TTF(15px)
* .
* .
* .
@@ -35,7 +37,9 @@ namespace graphics
~TTFData();
- void pushTTFsize(unsigned int ttfsize);
+ TTF* createTTF(unsigned ttfsize);
+
+ void pushTTFsize(unsigned ttfsize);
void popTTFsize();
Channel* getCodepointBitmapAlpha(unsigned int codepoint, int* width, int* height, int* xoff, int* yoff) const;
@@ -62,7 +66,7 @@ namespace graphics
class TTF : public Font
{
public:
- static TTF* createTTF(TTFData* ttfData, unsigned int ttfSzie);
+ 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;
@@ -74,6 +78,8 @@ namespace graphics
~TTF();
private:
+ friend class TTFData;
+
struct TTFGlyph
{
GLuint atlas;
diff --git a/src/libjin/Graphics/Font/Text.cpp b/src/libjin/Graphics/Font/Text.cpp
index 68601de..f202267 100644
--- a/src/libjin/Graphics/Font/Text.cpp
+++ b/src/libjin/Graphics/Font/Text.cpp
@@ -56,7 +56,7 @@ namespace graphics
{
return get();
}
-
+/*
Text::Iterator Text::Iterator::begin()
{
Iterator itor(encode, data, length);
@@ -70,7 +70,7 @@ namespace graphics
itor.toEnd();
return itor;
}
-
+*/
void Text::Iterator::toBegin()
{
p = (const unsigned char*)data;
@@ -117,17 +117,22 @@ namespace graphics
Text::Text(Encode encode, const void* data)
{
- Iterator it = Iterator(encode, data, strlen((const char*)data));
- for (; it != it.end(); ++it)
+ unsigned length = strlen((const char*)data);
+ Iterator end = Iterator(encode, data, length);
+ end.toEnd();
+ Iterator it = Iterator(encode, data, length);
+ for (; it != end; ++it)
{
content.push_back(*it);
}
}
- Text::Text(Encode _encode, const void* _data, unsigned int _length)
+ Text::Text(Encode encode, const void* data, unsigned length)
{
- Iterator it = Iterator(_encode, _data, _length);
- for (; it != it.end(); ++it)
+ Iterator end = Iterator(encode, data, length);
+ end.toEnd();
+ Iterator it = Iterator(encode, data, length);
+ for (; it != end; ++it)
{
content.push_back(*it);
}
diff --git a/src/libjin/Graphics/Font/Text.h b/src/libjin/Graphics/Font/Text.h
index 3faabc0..9fe152d 100644
--- a/src/libjin/Graphics/Font/Text.h
+++ b/src/libjin/Graphics/Font/Text.h
@@ -42,8 +42,8 @@ namespace graphics
~Iterator();
Codepoint get();
- Iterator begin();
- Iterator end();
+ //Iterator begin();
+ //Iterator end();
void toBegin();
void toEnd();
Codepoint operator *();
diff --git a/src/libjin/Graphics/Image.h b/src/libjin/Graphics/Image.h
index 5c426dc..29546cc 100644
--- a/src/libjin/Graphics/Image.h
+++ b/src/libjin/Graphics/Image.h
@@ -9,6 +9,7 @@ namespace graphics
{
/* just like bitmap but only from image file*/
+ /* readonly bitmap */
class Image : public Bitmap
{
public:
diff --git a/src/lua/modules/types.h b/src/lua/modules/types.h
index dcf3631..123604e 100644
--- a/src/lua/modules/types.h
+++ b/src/lua/modules/types.h
@@ -13,13 +13,13 @@
#define JIN_GRAPHICS_BITMAP "Bitmap"
// audio module
-#define JIN_AUDIO_SOURCE "Source"
-
-// thread module
-#define JIN_THREAD_THREAD "Thread"
-
-// network module
-#define JIN_NETWORK_SOCKET "Socket"
-#define JIN_NETWORK_BUFFER "Buffer"
+#define JIN_AUDIO_SOURCE "Source"
+
+// thread module
+#define JIN_THREAD_THREAD "Thread"
+
+// network module
+#define JIN_NETWORK_SOCKET "Socket"
+#define JIN_NETWORK_BUFFER "Buffer"
#endif \ No newline at end of file