Comments (3)
This problem should be mentioned in the README, so that it's clear when someone starts using SDL_TTF.
from sdl_ttf.
What are threads allowed to do?
https://discourse.libsdl.org/t/what-are-threads-allowed-to-do/11785
Someone also offered some code as a patch there.
from sdl_ttf.
Here is the patch in the thread, however this has the overhead of the entire FreeType library in each individual font.
diff -Naurd old/SDL_ttf.c new/SDL_ttf.c
--- old/SDL_ttf.c 2005-01-24 16:11:26.000000000 -0500
+++ new/SDL_ttf.c 2005-01-24 16:28:21.000000000 -0500
@@ -90,6 +90,7 @@
struct _TTF_Font {
/* Freetype2 maintains all sorts of useful info itself */
FT_Face face;
+ FT_Library library;
/* We'll cache these ourselves */
int height;
@@ -122,10 +123,7 @@
int font_size_family;
};
-/* The FreeType font engine/library */
-static FT_Library library;
-static int TTF_initialized = 0;
-static int TTF_byteswapped = 0;
+static int TTF_byteswapped;
/* UNICODE string utilities */
static __inline__ int UNICODE_strlen(const Uint16 *text)
@@ -205,21 +203,10 @@
#endif /* USE_FREETYPE_ERRORS */
}
+/* this exists only to maintain the ABI */
int TTF_Init( void )
{
- int status = 0;On Mon, 2005-01-24 at 12:40 -0500, Albert Cahalan wrote:
> On Mon, 2005-01-24 at 09:03 -0600, Bob Pendleton wrote:
-
- if ( ! TTF_initialized ) {
- FT_Error error = FT_Init_FreeType( &library );
- if ( error ) {
- TTF_SetFTError("Couldn't init FreeType engine", error);
- status = -1;
- }
- }
- if ( status == 0 ) {
- ++TTF_initialized;
- }
- return status;
+ return 0;
}
static unsigned long RWread(
@@ -245,11 +232,6 @@
FT_Stream stream;
int position;
- if ( ! TTF_initialized ) {
- TTF_SetError( "Library not initialized" );
- return NULL;
- }
-
/* Check to make sure we can seek in this stream */
position = SDL_RWtell(src);
if ( position < 0 ) {
@@ -267,6 +249,13 @@
font->src = src;
font->freesrc = freesrc;
+ FT_Error error = FT_Init_FreeType( &font->library );
+ if ( error ) {
+ TTF_SetFTError("Couldn't init FreeType engine", error);
+ free( font );
+ return NULL;
+ }
+
stream = (FT_Stream)malloc(sizeof(*stream));
if ( stream == NULL ) {
TTF_SetError( "Out of memory" );
@@ -275,7 +264,7 @@
}
memset(stream, 0, sizeof(*stream));
- stream->memory = library->memory;
+ stream->memory = font->library->memory;
stream->read = RWread;
stream->descriptor.pointer = src;
stream->pos = (unsigned long)position;
@@ -286,7 +275,7 @@
font->args.flags = FT_OPEN_STREAM;
font->args.stream = stream;
- error = FT_Open_Face( library, &font->args, index, &font->face );
+ error = FT_Open_Face( font->library, &font->args, index, &font->face );
if( error ) {
TTF_SetFTError( "Couldn't load font file", error );
TTF_CloseFont( font );
@@ -668,6 +657,7 @@
if ( font->freesrc ) {
SDL_RWclose( font->src );
}
+ FT_Done_FreeType( font->library );
free( font );
}
@@ -849,10 +839,6 @@
FT_UInt prev_index = 0;
/* Initialize everything to 0 */
- if ( ! TTF_initialized ) {
- TTF_SetError( "Library not initialized" );
- return -1;
- }
status = 0;
minx = maxx = 0;
miny = maxy = 0;
@@ -1735,14 +1721,10 @@
void TTF_Quit( void )
{
- if ( TTF_initialized ) {
- if ( --TTF_initialized == 0 ) {
- FT_Done_FreeType( library );
- }
- }
+ return;
}
int TTF_WasInit( void )
{
- return TTF_initialized;
+ return 1; // this is a don't-care value to satisfy the ABI
}
from sdl_ttf.
Related Issues (20)
- Bitmap font spacing incorrect when using Harfbuzz HOT 3
- TTF_RenderUTF8_Solid Runtime error HOT 4
- [Feature request] More text-shaping functionality. HOT 7
- Couldn't load font file HOT 14
- `TTF_RenderUTF8_Blended_Wrapped` fails when given 2+ newlines.
- Simsum.ttc font file rendering Chinese italics does not work
- TTF_RenderUTF8_Solid Runtime error HOT 1
- In a chinese font. It shows INFO: Couldn't render text: Text has zero width HOT 1
- Help building SDL_ttf using CMake? HOT 6
- SDL2 TTF_OpenFontRW handling of RWops does not match documentation
- undefined reference to error? HOT 4
- Harfbuzz fails to compile on Android HOT 3
- Harbuzz compilation fails because of Wcast-function-type-strict HOT 5
- Lock emoji issue HOT 10
- Looking for old versions HOT 1
- Unaligned access UB in BLIT_GLYPH routines HOT 22
- FreeType version update? HOT 10
- Release 2.22.0 lib causes an error on linking HOT 1
- Cannot render full color emoji font HOT 2
- Fallback fonts on SDL2 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sdl_ttf.