Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

bad unicode

  • Loading branch information...
commit f0254931044c00b78558c4cea11e509462b224dd 1 parent f21ae0f
Dmytro Lytovchenko authored
View
3  include/hgefont.h
@@ -27,7 +27,8 @@
/*
-** HGE Font interface (to use with Legacy font and BMFont font)
+** HGE Font interface (to use with BMFont font)
+** Supports Unicode
*/
#if HGE_UNICODE
class hgeFont
View
30 src/core/graphics.cpp
@@ -211,10 +211,10 @@ bool HGE_CALL HGE_Impl::Gfx_BeginScene(HTARGET targ)
m_d3d_device->BeginScene();
#if HGE_DIRECTX_VER == 8
- pVB->Lock( 0, 0, (uint8_t**)&VertArray, D3DLOCK_DISCARD );
+ m_vertex_buf->Lock( 0, 0, (uint8_t**)&m_vert_array, D3DLOCK_DISCARD );
#endif
#if HGE_DIRECTX_VER == 9
- pVB->Lock( 0, 0, (VOID**)&VertArray, D3DLOCK_DISCARD );
+ m_vertex_buf->Lock( 0, 0, (VOID**)&m_vert_array, D3DLOCK_DISCARD );
#endif
return true;
}
@@ -705,10 +705,10 @@ void HGE_Impl::_render_batch(bool bEndScene)
if (bEndScene)
m_vert_array = 0;
#if HGE_DIRECTX_VER == 8
- else pVB->Lock( 0, 0, (uint8_t**)&VertArray, D3DLOCK_DISCARD );
+ else m_vertex_buf->Lock( 0, 0, (uint8_t**)&m_vert_array, D3DLOCK_DISCARD );
#endif
#if HGE_DIRECTX_VER == 9
- else pVB->Lock( 0, 0, (VOID**)&VertArray, D3DLOCK_DISCARD );
+ else m_vertex_buf->Lock( 0, 0, (VOID**)&m_vert_array, D3DLOCK_DISCARD );
#endif
}
}
@@ -909,8 +909,8 @@ bool HGE_Impl::_GfxInit()
m_screen_color_depth = 32;
// Create D3D Device
- if(_format_id(d3dpp->BackBufferFormat) < 4) nScreenBPP=16;
- else nScreenBPP=32;
+ if(_format_id(m_d3d_pp->BackBufferFormat) < 4) m_screen_color_depth=16;
+ else m_screen_color_depth=32;
// Create D3D Device
// #if HGE_DIRECTX_VER == 8
@@ -924,21 +924,21 @@ bool HGE_Impl::_GfxInit()
// #endif
// #if HGE_DIRECTX_VER == 9
hgeGAPICaps caps;
- pD3D->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps);
+ m_d3d->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps);
uint32_t vp;
if((caps.VertexShaderVersion < D3DVS_VERSION(1,1)) || !(caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT))
{
- System_Log("Software Vertex-processing device selected");
+ System_Log( TXT("Software Vertex-processing device selected") );
vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
}
else
{
- System_Log("Hardware Vertex-processing device selected");
+ System_Log( TXT("Hardware Vertex-processing device selected") );
vp = D3DCREATE_HARDWARE_VERTEXPROCESSING;
}
- if( FAILED( pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, vp, d3dpp, &pD3DDevice ) ) )
+ if( FAILED( m_d3d->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_hwnd, vp, m_d3d_pp, &m_d3d_device ) ) )
{
- _PostError("Can't create D3D device");
+ _PostError( TXT("Can't create D3D device") );
return false;
}
// #endif
@@ -1214,17 +1214,17 @@ bool HGE_Impl::_init_lost()
// Create Vertex buffer
#if HGE_DIRECTX_VER == 8
- if( FAILED (pD3DDevice->CreateVertexBuffer(VERTEX_BUFFER_SIZE*sizeof(hgeVertex),
+ if( FAILED (m_d3d_device->CreateVertexBuffer(VERTEX_BUFFER_SIZE*sizeof(hgeVertex),
D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY,
D3DFVF_HGEVERTEX,
- D3DPOOL_DEFAULT, &pVB )))
+ D3DPOOL_DEFAULT, & m_vertex_buf )))
#endif
#if HGE_DIRECTX_VER == 9
- if( FAILED (pD3DDevice->CreateVertexBuffer(VERTEX_BUFFER_SIZE*sizeof(hgeVertex),
+ if( FAILED (m_d3d_device->CreateVertexBuffer(VERTEX_BUFFER_SIZE*sizeof(hgeVertex),
D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY,
D3DFVF_HGEVERTEX,
D3DPOOL_DEFAULT,
- &pVB,
+ & m_vertex_buf,
NULL)))
#endif
{
View
2  src/helpers/CMakeLists.txt
@@ -6,7 +6,7 @@ set( HGEHELPERS_SRC
hgeanim.cpp
hgecolor.cpp
hgedistort.cpp
- hgefont.cpp
+ hgeasciifont.cpp hgeunicodefont.cpp
hgegui.cpp
hgeguictrls.cpp
hgeparticle.cpp
View
28 src/helpers/hgefont.cpp → src/helpers/hgeasciifont.cpp
@@ -5,6 +5,8 @@
**
** hgeFont helper class implementation
*/
+#if ! HGE_UNICODE
+
#include <hgefont.h>
#include <stdlib.h>
#include <stdio.h>
@@ -19,11 +21,8 @@ hgeConstString FNTCHARTAG = TXT("Char");
HGE *hgeFont::m_hge = 0;
-#if ! HGE_UNICODE
- hgeChar hgeFont::m_buffer[1024];
-#endif // ! HGE_UNICODE
+hgeChar hgeFont::m_buffer[1024];
-#if ! HGE_UNICODE
hgeFont::hgeFont(hgeConstString szFont, bool bMipmap)
{
void * data;
@@ -150,10 +149,8 @@ hgeFont::hgeFont(hgeConstString szFont, bool bMipmap)
//delete[] desc;
//_ASSERTE(false); // todo copy here BMFONT loader code
}
-#endif
-#if ! HGE_UNICODE
hgeFont::~hgeFont()
{
for (int i = 0; i < 256; i++)
@@ -163,10 +160,8 @@ hgeFont::~hgeFont()
hge->Texture_Free(m_texture);
hge->Release();
}
-#endif
-#if ! HGE_UNICODE
void hgeFont::Render(float x, float y, int align, hgeConstString _str)
{
const hgeChar * str = _str;
@@ -206,10 +201,8 @@ void hgeFont::Render(float x, float y, int align, hgeConstString _str)
str++;
}
}
-#endif
-#if ! HGE_UNICODE
void hgeFont::printf(float x, float y, int align, hgeConstString format, ...)
{
va_list pArg = (va_list) &format + sizeof(format);
@@ -220,10 +213,8 @@ void hgeFont::printf(float x, float y, int align, hgeConstString format, ...)
Render(x, y, align, m_buffer);
}
-#endif
-#if ! HGE_UNICODE
void hgeFont::printfb(float x, float y, float w, float h, int align, hgeConstString format, ...)
{
hgeChar chr, *pbuf, *prevword, *linestart;
@@ -315,10 +306,8 @@ void hgeFont::printfb(float x, float y, float w, float h, int align, hgeConstStr
Render(tx, ty, align, m_buffer);
}
-#endif
-#if ! HGE_UNICODE
float hgeFont::GetStringWidth(hgeConstString _str, bool bMultiline) const
{
int i;
@@ -352,10 +341,8 @@ float hgeFont::GetStringWidth(hgeConstString _str, bool bMultiline) const
return w * m_scale * m_proportion;
}
-#endif
-#if ! HGE_UNICODE
void hgeFont::SetColor(uint32_t col)
{
m_color = col;
@@ -364,10 +351,8 @@ void hgeFont::SetColor(uint32_t col)
if (m_letters[i])
m_letters[i]->SetColor(col);
}
-#endif
-#if ! HGE_UNICODE
void hgeFont::SetZ(float z)
{
m_depth = z;
@@ -376,10 +361,8 @@ void hgeFont::SetZ(float z)
if (m_letters[i])
m_letters[i]->SetZ(z);
}
-#endif
-#if ! HGE_UNICODE
void hgeFont::SetBlendMode(int blend)
{
m_blending = blend;
@@ -388,10 +371,8 @@ void hgeFont::SetBlendMode(int blend)
if (m_letters[i])
m_letters[i]->SetBlendMode(blend);
}
-#endif
-#if ! HGE_UNICODE
hgeString hgeFont::_get_line(hgeString file, hgeString line)
{
int i = 0;
@@ -411,4 +392,5 @@ hgeString hgeFont::_get_line(hgeString file, hgeString line)
return file + i;
}
-#endif
+
+#endif // HGE_UNICODE
View
136 src/helpers/hgeunicodefont.cpp
@@ -0,0 +1,136 @@
+//
+#if HGE_UNICODE
+
+#include <hge.h>
+#include <hgefont.h>
+
+
+hgeFont::hgeFont(hgeConstString filename, bool bMipmap)
+{
+}
+
+
+void hgeFont::_load_font( hgeConstString filename )
+{
+ TStrVector lines;
+ ba::split (lines, fontdef, ba::is_any_of("\n"));
+ TResourcePath font_filename;
+ TResourcePath fonts_dir = TResourcePath::Create ("data/fonts");
+
+ foreach (const Str & ln, lines)
+ {
+ TStrVector words;
+
+ ba::split (words, ln, ba::is_any_of(" "));
+ if (words.empty()) continue;
+
+ //--------------------------------------
+ // Загрузка параметров из блока info
+ //--------------------------------------
+ if (words[0] == "info")
+ {
+ TKeyValuePair size = TKeyValuePair::FromStringArray (words, "size");
+ _Size = FromStr <int> (size.Value);
+ continue;
+ }
+
+ //--------------------------------------
+ // Загрузка параметров из блока common
+ //--------------------------------------
+ if (words[0] == "common")
+ {
+ TKeyValuePair w = TKeyValuePair::FromStringArray (words, "scaleW");
+ int _w = FromStr <int> (w.Value);
+ TKeyValuePair h = TKeyValuePair::FromStringArray (words, "scaleH");
+ int _h = FromStr <int> (h.Value);
+ InvTexW = 1.0f / _w;
+ InvTexH = 1.0f / _h;
+ continue;
+ }
+
+ //--------------------------------------
+ // Загрузка текстурной страницы
+ //--------------------------------------
+ if (words[0] == "page")
+ {
+ TKeyValuePair id = TKeyValuePair::FromStringArray (words, "id");
+ TKeyValuePair file = TKeyValuePair::FromStringArray (words, "file");
+
+ // Отрежем в конце файла ".png"
+ if (! ba::ends_with (file.Value, ".png"))
+ {
+ throw XFontLoadingError ("Font texture must be in PNG format");
+ }
+ file.Value = file.Value.substr (0, file.Value.length()-4);
+
+ if (id.Valid() && file.Valid())
+ {
+ //CTextureInfo tex_info(EE::TResourcePath::Create("fonts"));
+ //tex_info.Filename = file.Value;
+ TResourcePath page_path = fonts_dir / file.Value;
+
+ int load_texture_result = Textures.LoadTextureAsPage (page_path);
+ _ASSERTE (load_texture_result >= 0);
+
+ //Textures.push_back (tex);
+ }
+
+ continue;
+ }
+
+ //--------------------------------------
+ // Загрузка знака шрифта
+ //--------------------------------------
+ if (words[0] == "char")
+ {
+ TKeyValuePair id = TKeyValuePair::FromStringArray (words, "id");
+ TKeyValuePair x = TKeyValuePair::FromStringArray (words, "x");
+ TKeyValuePair y = TKeyValuePair::FromStringArray (words, "y");
+ TKeyValuePair width = TKeyValuePair::FromStringArray (words, "width");
+ TKeyValuePair height = TKeyValuePair::FromStringArray (words, "height");
+ TKeyValuePair xoffset = TKeyValuePair::FromStringArray (words, "xoffset");
+ TKeyValuePair yoffset = TKeyValuePair::FromStringArray (words, "yoffset");
+ TKeyValuePair xadvance = TKeyValuePair::FromStringArray (words, "xadvance");
+ TKeyValuePair page = TKeyValuePair::FromStringArray (words, "page");
+
+ if (id.Valid() && x.Valid() && y.Valid())
+ {
+ TGlyph glyph;
+ int char_id = FromStr <int> (id.Value);
+ glyph.TextureX = FromStr <int> (x.Value);
+ glyph.TextureY = FromStr <int> (y.Value);
+ glyph.Width = FromStr <int> (width.Value);
+ glyph.Height = FromStr <int> (height.Value);
+ glyph.XOffset = FromStr <int> (xoffset.Value);
+ glyph.YOffset = FromStr <int> (yoffset.Value);
+ glyph.XAdvance = FromStr <int> (xadvance.Value);
+ glyph.TexturePage = FromStr <int> (page.Value);
+
+ Glyphs [char_id] = glyph;
+ }
+
+ continue;
+ }
+
+ //--------------------------------------
+ // Загрузка кернинга пары символов
+ //--------------------------------------
+ if (words[0] == "kerning")
+ {
+ TKeyValuePair first = TKeyValuePair::FromStringArray (words, "first");
+ TKeyValuePair second = TKeyValuePair::FromStringArray (words, "second");
+ TKeyValuePair amount = TKeyValuePair::FromStringArray (words, "amount");
+
+ if (first.Valid() && second.Valid() && amount.Valid())
+ {
+ _AddKerningPair (FromStr <int> (first.Value),
+ FromStr <int> (second.Value),
+ FromStr <int> (amount.Value));
+ }
+
+ continue;
+ }
+ }
+}
+
+#endif // HGE_UNICODE
Please sign in to comment.
Something went wrong with that request. Please try again.