From 92191b3f93f19d662bdebba251f0a2f47f2c0717 Mon Sep 17 00:00:00 2001 From: spartanj Date: Tue, 19 Oct 2010 18:33:02 -0300 Subject: [PATCH] Fixed a bug in stb_image ( reported the bug and how to fix it ). Changed some things in HaikuTTF. --- src/base/stlcontainers.hpp | 8 - src/graphics/cfontmanager.cpp | 3 + src/graphics/cshapegroupmanager.cpp | 8 +- src/helper/SOIL/stb_image.c | 327 +++++++++++++------------- src/helper/haikuttf/hkbase.hpp | 32 +-- src/helper/haikuttf/hkfont.cpp | 40 ++-- src/helper/haikuttf/hkfontmanager.cpp | 30 +-- src/system/cresourceloader.cpp | 3 + src/test/ee.cpp | 33 ++- 9 files changed, 246 insertions(+), 238 deletions(-) diff --git a/src/base/stlcontainers.hpp b/src/base/stlcontainers.hpp index 55137b5b4..dce768e5c 100644 --- a/src/base/stlcontainers.hpp +++ b/src/base/stlcontainers.hpp @@ -56,14 +56,6 @@ namespace EE { typedef typename std::multimap type; #endif }; - - typedef eeVector::type eeVectorUint8; - typedef eeVector::type eeVectorUint16; - typedef eeVector::type eeVectorUint32; - typedef eeVector::type eeVectorInt8; - typedef eeVector::type eeVectorInt16; - typedef eeVector::type eeVectorInt32; - typedef eeVector::type eeVectorFloat; } #endif diff --git a/src/graphics/cfontmanager.cpp b/src/graphics/cfontmanager.cpp index 10c086ead..f4f0f9acb 100644 --- a/src/graphics/cfontmanager.cpp +++ b/src/graphics/cfontmanager.cpp @@ -9,6 +9,9 @@ cFontManager::~cFontManager() { } cFont * cFontManager::Add( cFont * Font ) { + eeASSERT( NULL != Font ); + eePRINT( "Added font: %s\n", Font->Name().c_str() ); + return tResourceManager::Add( Font ); } diff --git a/src/graphics/cshapegroupmanager.cpp b/src/graphics/cshapegroupmanager.cpp index 07280e3f3..f12c97059 100644 --- a/src/graphics/cshapegroupmanager.cpp +++ b/src/graphics/cshapegroupmanager.cpp @@ -14,21 +14,21 @@ cShapeGroupManager::~cShapeGroupManager() { cShape * cShapeGroupManager::GetShapeByName( const std::string& Name ) { cShape * tShape = GetShapeById( MakeHash( Name ) ); - + eePRINTC( NULL == tShape, "cShapeGroupManager::GetShapeByName shape '%s' not found\n", Name.c_str() ); - + return tShape; } cShape * cShapeGroupManager::GetShapeById( const Uint32& Id ) { std::list::iterator it; - + cShapeGroup * tSG = NULL; cShape * tShape = NULL; for ( it = mResources.begin(); it != mResources.end(); it++ ) { tSG = (*it); - + tShape = tSG->GetById( Id ); if ( NULL != tShape ) diff --git a/src/helper/SOIL/stb_image.c b/src/helper/SOIL/stb_image.c index e56c0522a..910a808ea 100644 --- a/src/helper/SOIL/stb_image.c +++ b/src/helper/SOIL/stb_image.c @@ -20,7 +20,7 @@ - decoded from memory or through stdio FILE (define STBI_NO_STDIO to remove code) - supports installable dequantizing-IDCT, YCbCr-to-RGB conversion (define STBI_SIMD) - Latest revisions: + Latest revisions: 1.30 (2010-08-18) added stbi_info support for BMP,PSD,HDR,PIC by Martin Golini 1.29 (2010-08-16) various warning fixes from Aurelien Pocheville 1.28 (2010-08-01) fix bug in GIF palette transparency (SpartanJ) @@ -64,7 +64,7 @@ Jetro Lauha (stbi_info) Jonathan Blow James "moose2000" Brown (iPhone PNG) Laurent Gomila Aruelien Pocheville - Martin Golini + Martin Golini If your name should be here but isn't, let Sean know. @@ -161,14 +161,14 @@ extern int stbi_png_info_from_file (FILE *f, int *x, int extern int stbi_bmp_test_memory (stbi_uc const *buffer, int len); extern stbi_uc *stbi_bmp_load (char const *filename, int *x, int *y, int *comp, int req_comp); -extern stbi_uc *stbi_bmp_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp); -extern int stbi_bmp_info_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp); +extern stbi_uc *stbi_bmp_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp); +extern int stbi_bmp_info_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp); #ifndef STBI_NO_STDIO extern int stbi_bmp_test_file (FILE *f); -extern stbi_uc *stbi_bmp_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp); - -extern int stbi_bmp_info (char const *filename, int *x, int *y, int *comp); +extern stbi_uc *stbi_bmp_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp); + +extern int stbi_bmp_info (char const *filename, int *x, int *y, int *comp); extern int stbi_bmp_info_from_file (FILE *f, int *x, int *y, int *comp); #endif @@ -186,14 +186,14 @@ extern stbi_uc *stbi_tga_load_from_file (FILE *f, int *x, int extern int stbi_psd_test_memory (stbi_uc const *buffer, int len); extern stbi_uc *stbi_psd_load (char const *filename, int *x, int *y, int *comp, int req_comp); -extern stbi_uc *stbi_psd_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp); -extern int stbi_psd_info_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp); +extern stbi_uc *stbi_psd_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp); +extern int stbi_psd_info_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp); #ifndef STBI_NO_STDIO extern int stbi_psd_test_file (FILE *f); -extern stbi_uc *stbi_psd_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp); - -extern int stbi_psd_info (char const *filename, int *x, int *y, int *comp); +extern stbi_uc *stbi_psd_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp); + +extern int stbi_psd_info (char const *filename, int *x, int *y, int *comp); extern int stbi_psd_info_from_file (FILE *f, int *x, int *y, int *comp); #endif @@ -201,14 +201,14 @@ extern int stbi_psd_info_from_file (FILE *f, int *x, int extern int stbi_hdr_test_memory (stbi_uc const *buffer, int len); extern float * stbi_hdr_load (char const *filename, int *x, int *y, int *comp, int req_comp); -extern float * stbi_hdr_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp); -extern int stbi_hdr_info_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp); +extern float * stbi_hdr_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp); +extern int stbi_hdr_info_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp); #ifndef STBI_NO_STDIO extern int stbi_hdr_test_file (FILE *f); -extern float * stbi_hdr_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp); - -extern int stbi_hdr_info (char const *filename, int *x, int *y, int *comp); +extern float * stbi_hdr_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp); + +extern int stbi_hdr_info (char const *filename, int *x, int *y, int *comp); extern int stbi_hdr_info_from_file (FILE *f, int *x, int *y, int *comp); #endif @@ -216,14 +216,14 @@ extern int stbi_hdr_info_from_file (FILE *f, int *x, int extern int stbi_pic_test_memory (stbi_uc const *buffer, int len); extern stbi_uc *stbi_pic_load (char const *filename, int *x, int *y, int *comp, int req_comp); -extern stbi_uc *stbi_pic_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp); -extern int stbi_pic_info_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp); +extern stbi_uc *stbi_pic_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp); +extern int stbi_pic_info_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp); #ifndef STBI_NO_STDIO extern int stbi_pic_test_file (FILE *f); -extern stbi_uc *stbi_pic_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp); - -extern int stbi_pic_info (char const *filename, int *x, int *y, int *comp); +extern stbi_uc *stbi_pic_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp); + +extern int stbi_pic_info (char const *filename, int *x, int *y, int *comp); extern int stbi_pic_info_from_file (FILE *f, int *x, int *y, int *comp); #endif @@ -240,9 +240,9 @@ extern stbi_uc *stbi_gif_load_from_file (FILE *f, int *x, int extern int stbi_gif_info (char const *filename, int *x, int *y, int *comp); extern int stbi_gif_info_from_file (FILE *f, int *x, int *y, int *comp); #endif - -#ifndef STBI_NO_DDS -#include "stbi_DDS.h" + +#ifndef STBI_NO_DDS +#include "stbi_DDS.h" #endif // this is not threadsafe @@ -2546,6 +2546,9 @@ static int parse_png_file(png *z, int scan, int req_comp) uint32 ioff=0, idata_limit=0, i, pal_len=0; int first=1,k,interlace=0, iphone=0; stbi *s = &z->s; + z->expanded = NULL; + z->idata = NULL; + z->out = NULL; if (!check_png_header(s)) return 0; @@ -2691,9 +2694,6 @@ static int parse_png_file(png *z, int scan, int req_comp) static unsigned char *do_png(png *p, int *x, int *y, int *n, int req_comp) { unsigned char *result=NULL; - p->expanded = NULL; - p->idata = NULL; - p->out = NULL; if (req_comp < 0 || req_comp > 4) return epuc("bad req_comp", "Internal error"); if (parse_png_file(p, SCAN_load, req_comp)) { result = p->out; @@ -2796,6 +2796,7 @@ int stbi_png_info_from_file(FILE *f, int *x, int *y, int *comp) int stbi_png_info_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp) { png p; + memset( &p, 0, sizeof(png) ); start_mem(&p.s, buffer, len); return stbi_png_info_raw(&p, x, y, comp); } @@ -3094,7 +3095,7 @@ stbi_uc *stbi_bmp_load_from_memory (stbi_uc const *buffer, int len, int *x, int stbi s; start_mem(&s, buffer, len); return bmp_load(&s, x,y,comp,req_comp); -} +} // Targa Truevision - TGA // by Jonathan Dummer @@ -3108,8 +3109,8 @@ static int tga_info(stbi *s, int *x, int *y, int *comp) if( sz > 1 ) return 0; // only RGB or indexed allowed sz = get8u(s); // image type // only RGB or grey allowed, +/- RLE - if ((sz != 1) && (sz != 2) && (sz != 3) && (sz != 9) && (sz != 10) && (sz != 11)) return 0; - skip(s,9); + if ((sz != 1) && (sz != 2) && (sz != 3) && (sz != 9) && (sz != 10) && (sz != 11)) return 0; + skip(s,9); tga_w = get16le(s); if( tga_w < 1 ) return 0; // test width @@ -4532,11 +4533,11 @@ int stbi_info_from_file(FILE *f, int *x, int *y, int *comp) if (stbi_png_info_from_file(f, x, y, comp)) return 1; if (stbi_gif_info_from_file(f, x, y, comp)) - return 1; + return 1; if (stbi_bmp_info_from_file(f, x, y, comp)) - return 1; + return 1; if (stbi_psd_info_from_file(f, x, y, comp)) - return 1; + return 1; if (stbi_pic_info_from_file(f, x, y, comp)) return 1; #ifndef STBI_NO_DDS @@ -4561,19 +4562,19 @@ int stbi_info_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *c if (stbi_png_info_from_memory(buffer, len, x, y, comp)) return 1; if (stbi_gif_info_from_memory(buffer, len, x, y, comp)) - return 1; - if(stbi_bmp_info_from_memory(buffer, len, x, y, comp)) return 1; - if(stbi_psd_info_from_memory(buffer, len, x, y, comp)) - return 1; - if(stbi_pic_info_from_memory(buffer, len, x, y, comp)) + if(stbi_bmp_info_from_memory(buffer, len, x, y, comp)) + return 1; + if(stbi_psd_info_from_memory(buffer, len, x, y, comp)) + return 1; + if(stbi_pic_info_from_memory(buffer, len, x, y, comp)) return 1; #ifndef STBI_NO_DDS if (stbi_dds_info_from_memory(buffer, len, x, y, comp, NULL)) return 1; #endif #ifndef STBI_NO_HDR - if(stbi_hdr_info_from_memory(buffer, len, x, y, comp)) + if(stbi_hdr_info_from_memory(buffer, len, x, y, comp)) return 1; #endif // test tga last because it's a crappy test! @@ -4585,11 +4586,11 @@ int stbi_info_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *c // add in my DDS loading support #ifndef STBI_NO_DDS #include "stbi_DDS_c.h" -#endif - +#endif + static int bmp_info(stbi *s, int *x, int *y, int *comp) { int hsz; - if (get8(s) != 'B' || get8(s) != 'M') return 0; + if (get8(s) != 'B' || get8(s) != 'M') return 0; skip(s,12); hsz = get32le(s); if (hsz != 12 && hsz != 40 && hsz != 56 && hsz != 108) return 0; @@ -4601,40 +4602,40 @@ static int bmp_info(stbi *s, int *x, int *y, int *comp) { *y = get32le(s); } if (get16le(s) != 1) return 0; - *comp = get16le(s) / 8; - return 1; + *comp = get16le(s) / 8; + return 1; } - -int stbi_bmp_info_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp) -{ - stbi s; - start_mem(&s,buffer, len); - return bmp_info( &s, x, y, comp ); -} - -#ifndef STBI_NO_STDIO -int stbi_bmp_info(char const *filename, int *x, int *y, int *comp) -{ - int res; - FILE *f = fopen(filename, "rb"); - if (!f) return 0; - res = stbi_bmp_info_from_file( f, x, y, comp ); - fclose(f); - return res; -} - -int stbi_bmp_info_from_file(FILE *f, int *x, int *y, int *comp) -{ + +int stbi_bmp_info_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp) +{ + stbi s; + start_mem(&s,buffer, len); + return bmp_info( &s, x, y, comp ); +} + +#ifndef STBI_NO_STDIO +int stbi_bmp_info(char const *filename, int *x, int *y, int *comp) +{ + int res; + FILE *f = fopen(filename, "rb"); + if (!f) return 0; + res = stbi_bmp_info_from_file( f, x, y, comp ); + fclose(f); + return res; +} + +int stbi_bmp_info_from_file(FILE *f, int *x, int *y, int *comp) +{ stbi s; int res; long n = ftell(f); start_file(&s, f); res = bmp_info(&s, x, y, comp); fseek(f, n, SEEK_SET); - return res; -} -#endif - + return res; +} +#endif + static int psd_info(stbi *s, int *x, int *y, int *comp) { int channelCount; @@ -4646,57 +4647,57 @@ static int psd_info(stbi *s, int *x, int *y, int *comp) *y = get32(s); *x = get32(s); if (get16(s) != 8) return 0; - if (get16(s) != 3) return 0; - *comp = 4; + if (get16(s) != 3) return 0; + *comp = 4; return 1; -} - -int stbi_psd_info_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp) -{ - stbi s; - start_mem(&s,buffer, len); - return psd_info( &s, x, y, comp ); -} - -#ifndef STBI_NO_STDIO -int stbi_psd_info(char const *filename, int *x, int *y, int *comp) -{ - int res; - FILE *f = fopen(filename, "rb"); - if (!f) return 0; - res = stbi_psd_info_from_file( f, x, y, comp ); - fclose(f); - return res; -} - -int stbi_psd_info_from_file(FILE *f, int *x, int *y, int *comp) -{ +} + +int stbi_psd_info_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp) +{ + stbi s; + start_mem(&s,buffer, len); + return psd_info( &s, x, y, comp ); +} + +#ifndef STBI_NO_STDIO +int stbi_psd_info(char const *filename, int *x, int *y, int *comp) +{ + int res; + FILE *f = fopen(filename, "rb"); + if (!f) return 0; + res = stbi_psd_info_from_file( f, x, y, comp ); + fclose(f); + return res; +} + +int stbi_psd_info_from_file(FILE *f, int *x, int *y, int *comp) +{ stbi s; int res; long n = ftell(f); start_file(&s, f); res = psd_info(&s, x, y, comp); fseek(f, n, SEEK_SET); - return res; -} -#endif - + return res; +} +#endif + static int pic_info(stbi *s, int *x, int *y, int *comp) -{ - int act_comp=0,num_packets=0,chained; - pic_packet_t packets[10]; - - skip(s, 92); +{ + int act_comp=0,num_packets=0,chained; + pic_packet_t packets[10]; + + skip(s, 92); *x = get16(s); *y = get16(s); if (at_eof(s)) return 0; if ( (*x) != 0 && (1 << 28) / (*x) < (*y)) return 0; - + skip(s, 8); do { - pic_packet_t *packet; + pic_packet_t *packet; if (num_packets==sizeof(packets)/sizeof(packets[0])) return 0; @@ -4706,48 +4707,48 @@ static int pic_info(stbi *s, int *x, int *y, int *comp) packet->size = get8u(s); packet->type = get8u(s); packet->channel = get8u(s); - act_comp |= packet->channel; + act_comp |= packet->channel; if (at_eof(s)) return 0; if (packet->size != 8) return 0; } while (chained); *comp = (act_comp & 0x10 ? 4 : 3); - + return 1; -} - -int stbi_pic_info_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp) -{ - stbi s; - start_mem(&s,buffer, len); - return pic_info( &s, x, y, comp ); -} - -#ifndef STBI_NO_STDIO -int stbi_pic_info(char const *filename, int *x, int *y, int *comp) -{ - int res; - FILE *f = fopen(filename, "rb"); - if (!f) return 0; - res = stbi_pic_info_from_file( f, x, y, comp ); - fclose(f); - return res; -} - -int stbi_pic_info_from_file(FILE *f, int *x, int *y, int *comp) -{ +} + +int stbi_pic_info_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp) +{ + stbi s; + start_mem(&s,buffer, len); + return pic_info( &s, x, y, comp ); +} + +#ifndef STBI_NO_STDIO +int stbi_pic_info(char const *filename, int *x, int *y, int *comp) +{ + int res; + FILE *f = fopen(filename, "rb"); + if (!f) return 0; + res = stbi_pic_info_from_file( f, x, y, comp ); + fclose(f); + return res; +} + +int stbi_pic_info_from_file(FILE *f, int *x, int *y, int *comp) +{ stbi s; int res; long n = ftell(f); start_file(&s, f); res = pic_info(&s, x, y, comp); fseek(f, n, SEEK_SET); - return res; -} -#endif - -#ifndef STBI_NO_HDR + return res; +} +#endif + +#ifndef STBI_NO_HDR static int hdr_info(stbi *s, int *x, int *y, int *comp) { char buffer[HDR_BUFLEN]; @@ -4760,7 +4761,7 @@ static int hdr_info(stbi *s, int *x, int *y, int *comp) token = hdr_gettoken(s,buffer); if (token[0] == 0) break; if (strcmp(token, "FORMAT=32-bit_rle_rgbe") == 0) valid = 1; - } + } if (!valid) return 0; token = hdr_gettoken(s,buffer); @@ -4771,45 +4772,45 @@ static int hdr_info(stbi *s, int *x, int *y, int *comp) if (strncmp(token, "+X ", 3)) return 0; token += 3; *x = strtol(token, NULL, 10); - *comp = 3; + *comp = 3; return 1; -} - -int stbi_hdr_info_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp) -{ - stbi s; - start_mem(&s,buffer, len); - return hdr_info( &s, x, y, comp ); -} - -#ifndef STBI_NO_STDIO -int stbi_hdr_info(char const *filename, int *x, int *y, int *comp) -{ - int res; - FILE *f = fopen(filename, "rb"); - if (!f) return 0; - res = stbi_hdr_info_from_file( f, x, y, comp ); - fclose(f); - return res; -} - -int stbi_hdr_info_from_file(FILE *f, int *x, int *y, int *comp) -{ +} + +int stbi_hdr_info_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp) +{ + stbi s; + start_mem(&s,buffer, len); + return hdr_info( &s, x, y, comp ); +} + +#ifndef STBI_NO_STDIO +int stbi_hdr_info(char const *filename, int *x, int *y, int *comp) +{ + int res; + FILE *f = fopen(filename, "rb"); + if (!f) return 0; + res = stbi_hdr_info_from_file( f, x, y, comp ); + fclose(f); + return res; +} + +int stbi_hdr_info_from_file(FILE *f, int *x, int *y, int *comp) +{ stbi s; int res; long n = ftell(f); start_file(&s, f); res = hdr_info(&s, x, y, comp); fseek(f, n, SEEK_SET); - return res; -} -#endif -#endif + return res; +} +#endif +#endif #endif // STBI_HEADER_FILE_ONLY /* - revision history: + revision history: 1.30 (2010-08-18) added stbi_info support for BMP,PSD,HDR,PIC by Martin Golini 1.29 (2010-08-16) various warning fixes from Aurelien Pocheville 1.28 (2010-08-01) fix bug in GIF palette transparency (SpartanJ) diff --git a/src/helper/haikuttf/hkbase.hpp b/src/helper/haikuttf/hkbase.hpp index 746d7031d..96ae858b3 100644 --- a/src/helper/haikuttf/hkbase.hpp +++ b/src/helper/haikuttf/hkbase.hpp @@ -58,28 +58,28 @@ typedef SOPHIST_uint32 u32; #define CACHED_BITMAP 0x01 #define CACHED_PIXMAP 0x02 -/* Handle a style only if the font does not already handle it */ -#define TTF_HANDLE_STYLE_BOLD(font) ( ( (font)->Style() & TTF_STYLE_BOLD ) && !( (font)->FaceStyle() & TTF_STYLE_BOLD ) ) -#define TTF_HANDLE_STYLE_ITALIC(font) ( ( (font)->Style() & TTF_STYLE_ITALIC ) && !( (font)->FaceStyle() & TTF_STYLE_ITALIC ) ) -#define TTF_HANDLE_STYLE_UNDERLINE(font) ( (font)->Style() & TTF_STYLE_UNDERLINE ) -#define TTF_HANDLE_STYLE_STRIKETHROUGH(font) ( (font)->Style() & TTF_STYLE_STRIKETHROUGH ) +#define HK_TTF_STYLE_NORMAL (0x00) +#define HK_TTF_STYLE_BOLD (0x01) +#define HK_TTF_STYLE_ITALIC (0x02) +#define HK_TTF_STYLE_UNDERLINE (0x04) +#define HK_TTF_STYLE_STRIKETHROUGH (0x08) -/* Font styles that does not impact glyph drawing */ -#define TTF_STYLE_NO_GLYPH_CHANGE (TTF_STYLE_UNDERLINE | TTF_STYLE_STRIKETHROUGH) +#define HK_TTF_HINTING_NORMAL (0) +#define HK_TTF_HINTING_LIGHT (1) +#define HK_TTF_HINTING_MONO (2) +#define HK_TTF_HINTING_NONE (3) + +#define HK_TTF_HANDLE_STYLE_BOLD(font) ( ( (font)->Style() & HK_TTF_STYLE_BOLD ) && !( (font)->FaceStyle() & HK_TTF_STYLE_BOLD ) ) +#define HK_TTF_HANDLE_STYLE_ITALIC(font) ( ( (font)->Style() & HK_TTF_STYLE_ITALIC ) && !( (font)->FaceStyle() & HK_TTF_STYLE_ITALIC ) ) +#define HK_TTF_HANDLE_STYLE_UNDERLINE(font) ( (font)->Style() & HK_TTF_STYLE_UNDERLINE ) +#define HK_TTF_HANDLE_STYLE_STRIKETHROUGH(font) ( (font)->Style() & HK_TTF_STYLE_STRIKETHROUGH ) + +#define HK_TTF_STYLE_NO_GLYPH_CHANGE ( HK_TTF_STYLE_UNDERLINE | HK_TTF_STYLE_STRIKETHROUGH ) #define hkARRAY_SIZE(__array) ( sizeof(__array) / sizeof(__array[0]) ) #define hkSAFE_DELETE(p) { if(p) { delete (p); (p)=NULL; } } #define hkSAFE_FREE(p) { if(p) { free (p); (p)=NULL; } } #define hkSAFE_DELETE_ARRAY(p) { if(p) { delete[](p); (p)=NULL; } } -#define TTF_STYLE_NORMAL 0x00 -#define TTF_STYLE_BOLD 0x01 -#define TTF_STYLE_ITALIC 0x02 -#define TTF_STYLE_UNDERLINE 0x04 -#define TTF_STYLE_STRIKETHROUGH 0x08 -#define TTF_HINTING_NORMAL 0 -#define TTF_HINTING_LIGHT 1 -#define TTF_HINTING_MONO 2 -#define TTF_HINTING_NONE 3 #endif diff --git a/src/helper/haikuttf/hkfont.cpp b/src/helper/haikuttf/hkfont.cpp index e6437afff..30f7cc053 100644 --- a/src/helper/haikuttf/hkfont.cpp +++ b/src/helper/haikuttf/hkfont.cpp @@ -39,11 +39,11 @@ void hkFont::Outline( int outline ) { } void hkFont::Hinting( int hinting ) { - if (hinting == TTF_HINTING_LIGHT) + if ( hinting == HK_TTF_HINTING_LIGHT ) mHinting = FT_LOAD_TARGET_LIGHT; - else if (hinting == TTF_HINTING_MONO) + else if ( hinting == HK_TTF_HINTING_MONO ) mHinting= FT_LOAD_TARGET_MONO; - else if (hinting == TTF_HINTING_NONE) + else if ( hinting == HK_TTF_HINTING_NONE ) mHinting = FT_LOAD_NO_HINTING; else mHinting = 0; @@ -55,7 +55,7 @@ void hkFont::Style( int style ) { int prev_style = mFaceStyle; mStyle = style | mFaceStyle; - if ( ( mStyle | TTF_STYLE_NO_GLYPH_CHANGE ) != ( prev_style | TTF_STYLE_NO_GLYPH_CHANGE ) ) + if ( ( mStyle | HK_TTF_STYLE_NO_GLYPH_CHANGE ) != ( prev_style | HK_TTF_STYLE_NO_GLYPH_CHANGE ) ) CacheFlush(); } @@ -106,15 +106,15 @@ FT_Error hkFont::GlyphLoad( u16 ch, hkGlyph * cached, int want ) { return FT_Err_Invalid_Handle; face = mFace; - + mFm->MutexLock(); - + if ( !cached->Index() ) cached->Index( FT_Get_Char_Index( face, ch ) ); - - + + error = FT_Load_Glyph( face, cached->Index(), FT_LOAD_DEFAULT | mHinting ); - + if( error ) return error; @@ -139,10 +139,10 @@ FT_Error hkFont::GlyphLoad( u16 ch, hkGlyph * cached, int want ) { cached->Advance( FT_CEIL( metrics->horiAdvance ) ); } - if( TTF_HANDLE_STYLE_BOLD(this) ) + if( HK_TTF_HANDLE_STYLE_BOLD(this) ) cached->MaxX( cached->MaxX() + mGlyphOverhang ); - if( TTF_HANDLE_STYLE_ITALIC(this) ) + if( HK_TTF_HANDLE_STYLE_ITALIC(this) ) cached->MaxX( cached->MaxX() + (int)ceil( mGlyphItalics ) ); cached->Stored( cached->Stored() | CACHED_METRICS ); @@ -155,7 +155,7 @@ FT_Error hkFont::GlyphLoad( u16 ch, hkGlyph * cached, int want ) { FT_Bitmap* dst; FT_Glyph bitmap_glyph = NULL; - if( TTF_HANDLE_STYLE_ITALIC(this) ) { + if( HK_TTF_HANDLE_STYLE_ITALIC(this) ) { FT_Matrix shear; shear.xx = 1 << 16; @@ -200,13 +200,13 @@ FT_Error hkFont::GlyphLoad( u16 ch, hkGlyph * cached, int want ) { memcpy( dst, src, sizeof( *dst ) ); - if( TTF_HANDLE_STYLE_BOLD(this) ) { + if( HK_TTF_HANDLE_STYLE_BOLD(this) ) { int bump = mGlyphOverhang; dst->pitch += bump; dst->width += bump; } - if( TTF_HANDLE_STYLE_ITALIC(this) ) { + if( HK_TTF_HANDLE_STYLE_ITALIC(this) ) { int bump = (int)ceil( mGlyphItalics ); dst->pitch += bump; dst->width += bump; @@ -228,7 +228,7 @@ FT_Error hkFont::GlyphLoad( u16 ch, hkGlyph * cached, int want ) { } } - if ( TTF_HANDLE_STYLE_BOLD(this) ) { + if ( HK_TTF_HANDLE_STYLE_BOLD(this) ) { int row; int col; int offset; @@ -258,7 +258,7 @@ FT_Error hkFont::GlyphLoad( u16 ch, hkGlyph * cached, int want ) { FT_Done_Glyph( bitmap_glyph ); } } - + mFm->MutexUnlock(); cached->Cached( ch ); @@ -302,12 +302,12 @@ unsigned char * hkFont::GlyphRender( u16 ch, u32 fg ) { pixels += bitmap->pitch; } - if( TTF_HANDLE_STYLE_UNDERLINE(this) ) { + if( HK_TTF_HANDLE_STYLE_UNDERLINE(this) ) { row = UnderlineTopRow(); DrawLine( textbuf, row, fg, bitmap ); } - if( TTF_HANDLE_STYLE_STRIKETHROUGH(this) ) { + if( HK_TTF_HANDLE_STYLE_STRIKETHROUGH(this) ) { row = StrikeThroughTopRow(); DrawLine( textbuf, row, fg, bitmap ); } @@ -329,7 +329,7 @@ int hkFont::GlyphMetrics( u16 ch, int* minx, int* maxx, int* miny, int* maxy, in if ( NULL !=maxx ) { *maxx = mCurrent->MaxX(); - if( TTF_HANDLE_STYLE_BOLD(this) ) + if( HK_TTF_HANDLE_STYLE_BOLD(this) ) *maxx += mGlyphOverhang; } @@ -342,7 +342,7 @@ int hkFont::GlyphMetrics( u16 ch, int* minx, int* maxx, int* miny, int* maxy, in if ( advance ) { *advance = mCurrent->Advance(); - if( TTF_HANDLE_STYLE_BOLD(this) ) + if( HK_TTF_HANDLE_STYLE_BOLD(this) ) *advance += mGlyphOverhang; } diff --git a/src/helper/haikuttf/hkfontmanager.cpp b/src/helper/haikuttf/hkfontmanager.cpp index 26f868dc4..9fb08b062 100644 --- a/src/helper/haikuttf/hkfontmanager.cpp +++ b/src/helper/haikuttf/hkfontmanager.cpp @@ -61,17 +61,17 @@ hkFont * hkFontManager::OpenFromMemory( const u8* data, unsigned long size, int return NULL; FT_Face face = NULL; - + MutexLock(); - + if ( FT_New_Memory_Face( mLibrary, reinterpret_cast(data), static_cast(size), index, &face ) != 0 ) return NULL; if ( FT_Select_Charmap( face, FT_ENCODING_UNICODE ) != 0 ) return NULL; - + MutexUnlock(); - + hkFont * Font = new hkFont( this, glyphCacheSize ); Font->Face( face ); @@ -84,9 +84,9 @@ hkFont * hkFontManager::OpenFromFile( const char* filename, int ptsize, long ind return NULL; FT_Face face; - + MutexLock(); - + if ( FT_New_Face( mLibrary, filename, index, &face ) != 0 ) return NULL; @@ -95,7 +95,7 @@ hkFont * hkFontManager::OpenFromFile( const char* filename, int ptsize, long ind return NULL; MutexUnlock(); - + hkFont * Font = new hkFont( this, glyphCacheSize ); Font->Face( face ); @@ -112,17 +112,17 @@ hkFont * hkFontManager::FontPrepare( hkFont * font, int ptsize ) { if ( FT_IS_SCALABLE( face ) ) { MutexLock(); - + error = FT_Set_Char_Size( font->Face(), 0, ptsize * 64, 0, 0 ); - + if( error ) { CloseFont( font ); - + MutexUnlock(); - + return NULL; } - + MutexUnlock(); scale = face->size->metrics.y_scale; @@ -150,13 +150,13 @@ hkFont * hkFontManager::FontPrepare( hkFont * font, int ptsize ) { if ( font->UnderlineHeight() < 1 ) font->UnderlineHeight( 1 ); - font->FaceStyle( TTF_STYLE_NORMAL ); + font->FaceStyle( HK_TTF_STYLE_NORMAL ); if ( face->style_flags & FT_STYLE_FLAG_BOLD ) - font->FaceStyle( font->FaceStyle() | TTF_STYLE_BOLD ); + font->FaceStyle( font->FaceStyle() | HK_TTF_STYLE_BOLD ); if ( face->style_flags & FT_STYLE_FLAG_ITALIC ) - font->FaceStyle( font->FaceStyle() | TTF_STYLE_ITALIC ); + font->FaceStyle( font->FaceStyle() | HK_TTF_STYLE_ITALIC ); font->Style( font->FaceStyle() ); font->Outline( 0 ); diff --git a/src/system/cresourceloader.cpp b/src/system/cresourceloader.cpp index c935fdc83..a3acf510f 100644 --- a/src/system/cresourceloader.cpp +++ b/src/system/cresourceloader.cpp @@ -17,12 +17,15 @@ cResourceLoader::~cResourceLoader() { void cResourceLoader::SetThreads() { if ( THREADS_AUTO == mThreads ) { + mThreads = GetNumCPUs(); + /** eeInt NumCpus = GetNumCPUs() - 1; if ( NumCpus > 1 ) mThreads = NumCpus; else mThreads = 1; + */ } } diff --git a/src/test/ee.cpp b/src/test/ee.cpp index 3ac3f0546..85a38ea34 100644 --- a/src/test/ee.cpp +++ b/src/test/ee.cpp @@ -211,7 +211,7 @@ void cEETest::CreateAquaTextureAtlas() { std::string Path( MyPath + "data/aqua" ); if ( !FileExists( Path + ".etg" ) ) { - cTexturePacker tp( 512, 512, true, 0 ); + cTexturePacker tp( 512, 512, true, 2 ); tp.AddTexturesPath( Path ); tp.PackTextures(); tp.Save( Path + ".png", EE_SAVE_TYPE_PNG ); @@ -337,11 +337,11 @@ void cEETest::Init() { } void cEETest::LoadFonts() { - mFontLoader.Add( eeNew( cTTFFontLoader, ( "arialb", &PAK, "arial.ttf", 12, EE_TTF_STYLE_NORMAL, false, 256, eeColor(255,255,255), 1, eeColor(0,0,0), true ) ) ); - mFontLoader.Add( eeNew( cTTFFontLoader, ( "arial", &PAK, "arial.ttf", 12, EE_TTF_STYLE_NORMAL, false, 256, eeColor(255,255,255) ) ) ); mFontLoader.Add( eeNew( cTextureFontLoader, ( "conchars", eeNew( cTextureLoader, ( &PAK, "conchars.png", false, eeRGB(0,0,0) ) ), (eeUint)32 ) ) ); mFontLoader.Add( eeNew( cTextureFontLoader, ( "ProggySquareSZ", eeNew( cTextureLoader, ( &PAK, "ProggySquareSZ.png" ) ), &PAK, "ProggySquareSZ.dat" ) ) ); - + mFontLoader.Add( eeNew( cTTFFontLoader, ( "arial", &PAK, "arial.ttf", 12, EE_TTF_STYLE_NORMAL, false, 256, eeColor(255,255,255) ) ) ); + mFontLoader.Add( eeNew( cTTFFontLoader, ( "arialb", &PAK, "arial.ttf", 12, EE_TTF_STYLE_NORMAL, false, 256, eeColor(255,255,255), 1, eeColor(0,0,0), true ) ) ); + mFontLoader.Load( cb::Make1( this, &cEETest::OnFontLoaded ) ); } @@ -538,11 +538,10 @@ void cEETest::CreateUI() { mBuda = L"El mono ve el pez en el agua y sufre. Piensa que su mundo es el único que existe, el mejor, el real. Sufre porque es bueno y tiene compasión, lo ve y piensa: \"Pobre se está ahogando no puede respirar\". Y lo saca, lo saca y se queda tranquilo, por fin lo salvé. Pero el pez se retuerce de dolor y muere. Por eso te mostré el sueño, es imposible meter el mar en tu cabeza, que es un balde."; TTFB->ShrinkText( mBuda, 400 ); - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_textinput_normal.png" ), "aqua_textinput_normal" ) ) ); cUIThemeManager::instance()->Add( cUITheme::LoadFromPath( MyPath + "data/aqua/", "aqua", "aqua" ) ); -/* - CreateAquaTextureAtlas(); + CreateAquaTextureAtlas(); +/* cTextureGroupLoader tgl( MyPath + "data/aqua.etg" ); TF->GetByName( "data/aqua.png" )->TextureFilter( TEX_FILTER_NEAREST ); cUIThemeManager::instance()->Add( cUITheme::LoadFromShapeGroup( cShapeGroupManager::instance()->GetByName( "aqua" ), "aqua", "aqua" ) ); @@ -568,7 +567,7 @@ void cEETest::ButtonClick( const cUIEvent * Event ) { if ( MouseEvent->Flags() & EE_BUTTONS_LRM ) { cUIGfx::CreateParams GfxParams; GfxParams.Parent( cUIManager::instance()->MainControl() ); - GfxParams.Shape = cShapeGroupManager::instance()->GetShapeByName( "aqua_textinput_normal" ); + GfxParams.Shape = cShapeGroupManager::instance()->GetShapeByName( "aqua_button_ok" ); cUIGfx * Gfx = eeNew( cUIGfx, ( GfxParams ) ); Gfx->Visible( true ); Gfx->Enabled( false ); @@ -1006,7 +1005,7 @@ void cEETest::Render() { mEEText.GetTextHeight(), ColRR1, ColRR2, ColRR3, ColRR4 ); - + mEEText.Draw( 0.f, (eeFloat)EE->GetHeight() - mEEText.GetTextHeight(), FONT_DRAW_CENTER, 1.f, Ang ); mInfoText.Draw( 6.f, 6.f ); mBudaTC.Draw( 5.f, 60.f ); @@ -1022,7 +1021,7 @@ void cEETest::Render() { FF2->SetText( L"FPS: " + toWStr( EE->FPS() ) ); FF2->Draw( EE->GetWidth() - FF2->GetTextWidth() - 15, 0 ); - + FF2->SetText( InBuf.Buffer() ); FF2->Draw( 6, 180, FONT_DRAW_SHADOW ); @@ -1035,7 +1034,7 @@ void cEETest::Render() { mVBO->Bind(); mVBO->Draw(); mVBO->Unbind(); - + mFBOText.Draw( 128.f - (eeFloat)(Int32)( mFBOText.GetTextWidth() * 0.5f ), 25.f - (eeFloat)(Int32)( mFBOText.GetTextHeight() * 0.5f ), FONT_DRAW_CENTER ); mFB->Unbind(); @@ -1327,6 +1326,7 @@ void cEETest::Particles() { PS[i].Draw(); } +#include "../helper/SOIL/stb_image.h" int main (int argc, char * argv []) { cEETest * Test = eeNew( cEETest, () ); @@ -1335,6 +1335,15 @@ int main (int argc, char * argv []) { eeDelete( Test ); EE::MemoryManager::LogResults(); - + /* + int x, y, comp; + + int res = stbi_info( "/home/programming/Projects/EE/data/aqua/aqua_button_ok.png", &x, &y, &comp ); + + unsigned char * data = stbi_load( "/home/programming/Projects/EE/data/aqua/aqua_button_ok.png", &x, &y, &comp, 0 ); + + if ( data ) + free( data ); + */ return 0; }