Skip to content

Commit

Permalink
Use fontconfig instead of ttf-liberation.
Browse files Browse the repository at this point in the history
I'm not an expert in C++ or fontconfig, but at least this doesn't crash
if you don't have the ttf-liberation font. I don't know if RenderThread
is the best place for the font path, but it seems good.
  • Loading branch information
QuLogic committed Jun 12, 2010
1 parent 217763d commit 5eff3c6
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ INCLUDE(FindCURL REQUIRED)
INCLUDE(FindPkgConfig REQUIRED)
INCLUDE(FindZLIB REQUIRED)

pkg_check_modules(EXTRA_LIBS REQUIRED gl libpcrecpp libavcodec libavutil ftgl x11 libpulse)
pkg_check_modules(EXTRA_LIBS REQUIRED gl libpcrecpp libavcodec libavutil ftgl x11 libpulse fontconfig)

INCLUDE_DIRECTORIES(${SDL_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${LLVM_INCLUDE_DIR})
Expand Down
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Version 0.?.?
-------------
Use fontconfig to select fonts

Version 0.4.1
-------------

Expand Down
4 changes: 2 additions & 2 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ Currently only 64bit and 32bit platforms with SSE2 extension are supported. Supp
be ready soon.

INSTALLATION:
To compile this software you need to install development packages for llvm-2.7, sdl, opengl, curl, libavcodec, ftgl, libglew
Install also cmake and nasm and ttf-liberation font
To compile this software you need to install development packages for llvm-2.7, sdl, opengl, curl, libavcodec, ftgl, libglew, fontconfig
Install also cmake and nasm
To build the software please follow those steps.

1) cd lightspark
Expand Down
1 change: 0 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Official TODO Queue:
-) Understand the semantics of nextname on methods and the like
-) handle private methods, which should be getted on the same level
-) stick to current level change or use flag to getVariable.../setVariable
-) use fontconfig to avoid dependance on ttf-liberation
-) Add Named Objects to frames and not to clips
-) Support mozilla Out of process plugin mode - Waiting for multithreaded GTK support from mozilla
-) Conditional scaling of FontGlyph based on version
Expand Down
36 changes: 32 additions & 4 deletions swf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ extern "C" {
}
#ifndef WIN32
#include <GL/glx.h>
#include <fontconfig/fontconfig.h>
#endif

#ifdef COMPILE_PLUGIN
Expand Down Expand Up @@ -835,6 +836,33 @@ RenderThread::RenderThread(SystemState* s,ENGINE e,void* params):m_sys(s),termin
m_sys=s;
sem_init(&render,0,0);
sem_init(&inputDone,0,0);

#ifdef WIN32
fontPath = "TimesNewRoman.ttf"
#else
FcPattern *pat, *match;
FcResult result = FcResultMatch;
char *font = NULL;

pat = FcPatternCreate();
FcPatternAddString(pat, FC_FAMILY, (const FcChar8 *)"Serif");
FcConfigSubstitute(NULL, pat, FcMatchPattern);
FcDefaultSubstitute(pat);
match = FcFontMatch(NULL, pat, &result);
FcPatternDestroy(pat);

if (result != FcResultMatch)
{
LOG(LOG_ERROR,"Unable to find suitable Serif font");
throw RunTimeException("Unable to find Serif font");
}

FcPatternGetString(match, FC_FILE, 0, (FcChar8 **) &font);
fontPath = font;
FcPatternDestroy(match);
LOG(LOG_NO_INFO, "Font File is " << fontPath);
#endif

if(e==SDL)
pthread_create(&t,NULL,(thread_worker)sdl_worker,this);
#ifdef COMPILE_PLUGIN
Expand Down Expand Up @@ -967,7 +995,7 @@ void* RenderThread::gtkplug_worker(RenderThread* th)
th->commonGLInit(window_width, window_height);
ThreadProfile* profile=sys->allocateProfiler(RGB(200,0,0));
profile->setTag("Render");
FTTextureFont font("/usr/share/fonts/truetype/ttf-liberation/LiberationSerif-Regular.ttf");
FTTextureFont font(rt->fontPath.c_str());
if(font.Error())
throw RunTimeException("Unable to load font");

Expand Down Expand Up @@ -1174,10 +1202,10 @@ void* RenderThread::npapi_worker(RenderThread* th)

ThreadProfile* profile=sys->allocateProfiler(RGB(200,0,0));
profile->setTag("Render");
FTTextureFont font("/usr/share/fonts/truetype/ttf-liberation/LiberationSerif-Regular.ttf");
FTTextureFont font(rt->fontPath.c_str());
if(font.Error())
{
LOG(LOG_ERROR,"Unable to load ttf-liberation font");
LOG(LOG_ERROR,"Unable to load serif font");
throw RunTimeException("Unable to load font");
}

Expand Down Expand Up @@ -1564,7 +1592,7 @@ void* RenderThread::sdl_worker(RenderThread* th)

ThreadProfile* profile=sys->allocateProfiler(RGB(200,0,0));
profile->setTag("Render");
FTTextureFont font("/usr/share/fonts/truetype/ttf-liberation/LiberationSerif-Regular.ttf");
FTTextureFont font(rt->fontPath.c_str());
if(font.Error())
throw RunTimeException("Unable to load font");

Expand Down
2 changes: 2 additions & 0 deletions swf.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <list>
#include <map>
#include <semaphore.h>
#include <string>
#include <FTGL/ftgl.h>
#include "swftypes.h"
#include "frame.h"
Expand Down Expand Up @@ -308,6 +309,7 @@ class RenderThread: public ITickJob
sem_t render;
sem_t inputDone;
bool inputNeeded;
std::string fontPath;

#ifndef WIN32
Display* mDisplay;
Expand Down

0 comments on commit 5eff3c6

Please sign in to comment.