forked from Mirrors/openclonk
Merge StdFont.cpp and C4Fonts.cpp
parent
4dffefe8c9
commit
7967d94a59
|
@ -255,8 +255,8 @@ set(OC_CLONK_SOURCES
|
||||||
src/graphics/C4FacetEx.cpp
|
src/graphics/C4FacetEx.cpp
|
||||||
src/graphics/C4FacetEx.h
|
src/graphics/C4FacetEx.h
|
||||||
src/graphics/C4Facet.h
|
src/graphics/C4Facet.h
|
||||||
src/graphics/C4Fonts.cpp
|
src/graphics/C4FontLoader.cpp
|
||||||
src/graphics/C4Fonts.h
|
src/graphics/C4FontLoader.h
|
||||||
src/graphics/C4GraphicsResource.cpp
|
src/graphics/C4GraphicsResource.cpp
|
||||||
src/graphics/C4GraphicsResource.h
|
src/graphics/C4GraphicsResource.h
|
||||||
src/graphics/C4Surface.cpp
|
src/graphics/C4Surface.cpp
|
||||||
|
@ -510,8 +510,6 @@ set(OC_CLONK_SOURCES
|
||||||
src/platform/PlatformAbstraction.h
|
src/platform/PlatformAbstraction.h
|
||||||
src/platform/StdFile.cpp
|
src/platform/StdFile.cpp
|
||||||
src/platform/StdFile.h
|
src/platform/StdFile.h
|
||||||
src/platform/StdFont.cpp
|
|
||||||
src/platform/StdFont.h
|
|
||||||
src/platform/StdRegistry.cpp
|
src/platform/StdRegistry.cpp
|
||||||
src/platform/StdRegistry.h
|
src/platform/StdRegistry.h
|
||||||
src/platform/StdScheduler.cpp
|
src/platform/StdScheduler.cpp
|
||||||
|
|
|
@ -228,8 +228,8 @@ src/graphics/C4Facet.cpp \
|
||||||
src/graphics/C4FacetEx.cpp \
|
src/graphics/C4FacetEx.cpp \
|
||||||
src/graphics/C4FacetEx.h \
|
src/graphics/C4FacetEx.h \
|
||||||
src/graphics/C4Facet.h \
|
src/graphics/C4Facet.h \
|
||||||
src/graphics/C4Fonts.cpp \
|
src/graphics/C4FontLoader.cpp \
|
||||||
src/graphics/C4Fonts.h \
|
src/graphics/C4FontLoader.h \
|
||||||
src/graphics/C4GraphicsResource.cpp \
|
src/graphics/C4GraphicsResource.cpp \
|
||||||
src/graphics/C4GraphicsResource.h \
|
src/graphics/C4GraphicsResource.h \
|
||||||
src/graphics/C4Surface.cpp \
|
src/graphics/C4Surface.cpp \
|
||||||
|
@ -468,8 +468,6 @@ src/platform/C4Window.h \
|
||||||
src/platform/C4windowswrapper.h \
|
src/platform/C4windowswrapper.h \
|
||||||
src/platform/PlatformAbstraction.cpp \
|
src/platform/PlatformAbstraction.cpp \
|
||||||
src/platform/PlatformAbstraction.h \
|
src/platform/PlatformAbstraction.h \
|
||||||
src/platform/StdFont.cpp \
|
|
||||||
src/platform/StdFont.h \
|
|
||||||
src/platform/StdSync.h \
|
src/platform/StdSync.h \
|
||||||
src/platform/StdVideo.cpp \
|
src/platform/StdVideo.cpp \
|
||||||
src/platform/StdVideo.h \
|
src/platform/StdVideo.h \
|
||||||
|
|
|
@ -44,7 +44,6 @@
|
||||||
#include <C4Log.h>
|
#include <C4Log.h>
|
||||||
#include <C4GamePadCon.h>
|
#include <C4GamePadCon.h>
|
||||||
#include <C4GameLobby.h>
|
#include <C4GameLobby.h>
|
||||||
#include <C4Fonts.h>
|
|
||||||
#include <C4Network2.h>
|
#include <C4Network2.h>
|
||||||
#include <C4Network2IRC.h>
|
#include <C4Network2IRC.h>
|
||||||
|
|
||||||
|
@ -723,7 +722,7 @@ bool C4Application::SetGameFont(const char *szFontFace, int32_t iFontSize)
|
||||||
// first, check if the selected font can be created at all
|
// first, check if the selected font can be created at all
|
||||||
// check regular font only - there's no reason why the other fonts couldn't be created
|
// check regular font only - there's no reason why the other fonts couldn't be created
|
||||||
CStdFont TestFont;
|
CStdFont TestFont;
|
||||||
if (!::FontLoader.InitFont(TestFont, szFontFace, C4FontLoader::C4FT_Main, iFontSize, &::GraphicsResource.Files))
|
if (!::FontLoader.InitFont(&TestFont, szFontFace, C4FontLoader::C4FT_Main, iFontSize, &::GraphicsResource.Files))
|
||||||
return false;
|
return false;
|
||||||
// OK; reinit all fonts
|
// OK; reinit all fonts
|
||||||
StdStrBuf sOldFont; sOldFont.Copy(Config.General.RXFontName);
|
StdStrBuf sOldFont; sOldFont.Copy(Config.General.RXFontName);
|
||||||
|
|
|
@ -77,7 +77,6 @@
|
||||||
#include <C4PlayerList.h>
|
#include <C4PlayerList.h>
|
||||||
#include <C4GameObjects.h>
|
#include <C4GameObjects.h>
|
||||||
#include <C4GameControl.h>
|
#include <C4GameControl.h>
|
||||||
#include <C4Fonts.h>
|
|
||||||
#include <C4Version.h>
|
#include <C4Version.h>
|
||||||
#include <C4AulExec.h>
|
#include <C4AulExec.h>
|
||||||
#include <StdFile.h>
|
#include <StdFile.h>
|
||||||
|
|
|
@ -26,12 +26,12 @@
|
||||||
#include <C4Draw.h>
|
#include <C4Draw.h>
|
||||||
|
|
||||||
#include "C4App.h"
|
#include "C4App.h"
|
||||||
|
#include <C4FontLoader.h>
|
||||||
#include <C4Window.h>
|
#include <C4Window.h>
|
||||||
#include <C4DrawD3D.h>
|
#include <C4DrawD3D.h>
|
||||||
#include <C4DrawGL.h>
|
#include <C4DrawGL.h>
|
||||||
#include <C4DrawT.h>
|
#include <C4DrawT.h>
|
||||||
#include <C4Markup.h>
|
#include <C4Markup.h>
|
||||||
#include <StdFont.h>
|
|
||||||
#include "C4Rect.h"
|
#include "C4Rect.h"
|
||||||
#include <C4Config.h>
|
#include <C4Config.h>
|
||||||
#include "StdMesh.h"
|
#include "StdMesh.h"
|
||||||
|
|
|
@ -23,14 +23,17 @@
|
||||||
|
|
||||||
// text drawing facility for C4Draw
|
// text drawing facility for C4Draw
|
||||||
|
|
||||||
#include "C4Include.h"
|
#include <C4Include.h>
|
||||||
#include <StdFont.h>
|
#include "C4FontLoader.h"
|
||||||
|
|
||||||
#include "Standard.h"
|
#include <C4Components.h>
|
||||||
#include <StdBuf.h>
|
#include <C4Config.h>
|
||||||
#include <C4Draw.h>
|
#include <C4Draw.h>
|
||||||
#include <C4Surface.h>
|
#include <C4Language.h>
|
||||||
|
#include <C4Log.h>
|
||||||
#include <C4Markup.h>
|
#include <C4Markup.h>
|
||||||
|
#include <C4Surface.h>
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
@ -45,6 +48,144 @@
|
||||||
|
|
||||||
/* Initialization */
|
/* Initialization */
|
||||||
|
|
||||||
|
bool C4FontLoader::InitFont(CStdFont * rFont, const char *szFontName, FontType eType, int32_t iSize, C4GroupSet *pGfxGroups, bool fDoShadow)
|
||||||
|
{
|
||||||
|
#ifdef USE_CONSOLE
|
||||||
|
return true;
|
||||||
|
#endif
|
||||||
|
// safety
|
||||||
|
assert(szFontName);
|
||||||
|
if (!szFontName || !*szFontName)
|
||||||
|
{
|
||||||
|
LogFatal(FormatString("%s (\"%s\")", LoadResStr("IDS_ERR_INITFONTS"), szFontName ? szFontName : "(null)").getData());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// if def has not been found, use the def as font name
|
||||||
|
// determine font def string
|
||||||
|
const char *szFontString = szFontName;
|
||||||
|
// font not assigned?
|
||||||
|
assert(*szFontString);
|
||||||
|
if (!*szFontString)
|
||||||
|
{
|
||||||
|
// invalid call or spec
|
||||||
|
LogFatal(LoadResStr("IDS_ERR_INITFONTS")); return false;
|
||||||
|
}
|
||||||
|
// get font name
|
||||||
|
char FontFaceName[C4MaxName+1], FontParam[C4MaxName+1];
|
||||||
|
SCopyUntil(szFontString, FontFaceName, ',', C4MaxName);
|
||||||
|
// is it an image file?
|
||||||
|
int32_t iDefFontSize; DWORD dwDefWeight=FW_NORMAL;
|
||||||
|
switch (eType)
|
||||||
|
{
|
||||||
|
case C4FT_Log: iDefFontSize = iSize*12/14; break;
|
||||||
|
case C4FT_MainSmall:iDefFontSize = iSize*13/14; break;
|
||||||
|
case C4FT_Main: iDefFontSize = iSize; break;
|
||||||
|
case C4FT_Caption: iDefFontSize = iSize*16/14; /*dwDefWeight = FW_MEDIUM;*/ break;
|
||||||
|
case C4FT_Title: iDefFontSize = iSize*22/14; /*dwDefWeight = FW_MEDIUM;*/ break;
|
||||||
|
default: assert(false); LogFatal(LoadResStr("IDS_ERR_INITFONTS")); return false; // invalid call
|
||||||
|
}
|
||||||
|
// regular font name: let WinGDI or Freetype draw a font with the given parameters
|
||||||
|
// font size given?
|
||||||
|
if (SCopySegment(szFontString, 1, FontParam, ',', C4MaxName))
|
||||||
|
sscanf(FontParam, "%i", &iDefFontSize);
|
||||||
|
// font weight given?
|
||||||
|
if (SCopySegment(szFontString, 2, FontParam, ',', C4MaxName))
|
||||||
|
{
|
||||||
|
int iDefWeight;
|
||||||
|
sscanf(FontParam, "%i", &iDefWeight);
|
||||||
|
dwDefWeight = iDefWeight;
|
||||||
|
}
|
||||||
|
// check if it's already loaded from that group with that parameters
|
||||||
|
if (rFont->IsSameAs(FontFaceName, iDefFontSize, dwDefWeight))
|
||||||
|
return true;
|
||||||
|
// it's not; so (re-)load it now!
|
||||||
|
if (rFont->IsInitialized())
|
||||||
|
{
|
||||||
|
// reloading
|
||||||
|
rFont->Clear();
|
||||||
|
LogF(LoadResStr("IDS_PRC_UPDATEFONT"), FontFaceName, iDefFontSize, dwDefWeight);
|
||||||
|
}
|
||||||
|
// check if one of the internally listed fonts should be used
|
||||||
|
const char * const extensions[] = { "ttf", "otf", "ttc", "fon", "fnt", "fot", NULL };
|
||||||
|
char FileName[_MAX_PATH+1];
|
||||||
|
int32_t ID;
|
||||||
|
C4Group * pGrp = pGfxGroups->FindSuitableFile(FontFaceName, extensions, FileName, &ID);
|
||||||
|
if (pGrp)
|
||||||
|
{
|
||||||
|
if (LastUsedGrpID != ID || LastUsedName != FontFaceName)
|
||||||
|
{
|
||||||
|
DestroyFont(pLastUsedFont);
|
||||||
|
pLastUsedFont = NULL;
|
||||||
|
}
|
||||||
|
if (!pLastUsedFont)
|
||||||
|
{
|
||||||
|
StdBuf Data;
|
||||||
|
if (pGrp->LoadEntry(FileName, &Data))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
pLastUsedFont = CreateFont(Data);
|
||||||
|
LastUsedGrpID = ID;
|
||||||
|
LastUsedName = FontFaceName;
|
||||||
|
}
|
||||||
|
catch (std::runtime_error & e)
|
||||||
|
{
|
||||||
|
LogFatal(e.what());
|
||||||
|
pGrp = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// no internal font match? Then create one using the given face/filename (using a system font)
|
||||||
|
if (!pGrp)
|
||||||
|
{
|
||||||
|
if (LastUsedGrpID != -1 || LastUsedName != FontFaceName)
|
||||||
|
{
|
||||||
|
DestroyFont(pLastUsedFont);
|
||||||
|
pLastUsedFont = NULL;
|
||||||
|
}
|
||||||
|
if (!pLastUsedFont)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
pLastUsedFont = CreateFont(FontFaceName);
|
||||||
|
if (!pLastUsedFont)
|
||||||
|
// no match for font face found
|
||||||
|
throw std::runtime_error(FormatString("Font face %s undefined", FontFaceName).getData());
|
||||||
|
LastUsedGrpID = -1;
|
||||||
|
LastUsedName = FontFaceName;
|
||||||
|
}
|
||||||
|
catch (std::runtime_error & e)
|
||||||
|
{
|
||||||
|
LogFatal(e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!pLastUsedFont)
|
||||||
|
{
|
||||||
|
LogFatal(LoadResStr("IDS_ERR_INITFONTS"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
rFont->Init(*pLastUsedFont, FontFaceName, iDefFontSize, dwDefWeight, fDoShadow); // throws exception on error
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (std::runtime_error & e)
|
||||||
|
{
|
||||||
|
LogFatal(e.what());
|
||||||
|
LogFatal(LoadResStr("IDS_ERR_INITFONTS"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void C4FontLoader::Clear()
|
||||||
|
{
|
||||||
|
// delete vector font cache
|
||||||
|
DestroyFont(pLastUsedFont);
|
||||||
|
pLastUsedFont = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef HAVE_FREETYPE
|
#ifdef HAVE_FREETYPE
|
||||||
class CStdVectorFont
|
class CStdVectorFont
|
||||||
{
|
{
|
||||||
|
@ -123,15 +264,15 @@ public:
|
||||||
int RefCnt;
|
int RefCnt;
|
||||||
};
|
};
|
||||||
|
|
||||||
CStdVectorFont * CStdFont::CreateFont(const char *szFaceName)
|
CStdVectorFont * C4FontLoader::CreateFont(const char *szFaceName)
|
||||||
{
|
{
|
||||||
return new CStdVectorFont(szFaceName);
|
return new CStdVectorFont(szFaceName);
|
||||||
}
|
}
|
||||||
CStdVectorFont * CStdFont::CreateFont(StdBuf & Data)
|
CStdVectorFont * C4FontLoader::CreateFont(StdBuf & Data)
|
||||||
{
|
{
|
||||||
return new CStdVectorFont(Data);
|
return new CStdVectorFont(Data);
|
||||||
}
|
}
|
||||||
void CStdFont::DestroyFont(CStdVectorFont * pFont)
|
void C4FontLoader::DestroyFont(CStdVectorFont * pFont)
|
||||||
{
|
{
|
||||||
if (!pFont) return;
|
if (!pFont) return;
|
||||||
--(pFont->RefCnt);
|
--(pFont->RefCnt);
|
||||||
|
@ -139,19 +280,21 @@ void CStdFont::DestroyFont(CStdVectorFont * pFont)
|
||||||
delete pFont;
|
delete pFont;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
CStdVectorFont * CStdFont::CreateFont(StdBuf & Data)
|
CStdVectorFont * C4FontLoader::CreateFont(StdBuf & Data)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
CStdVectorFont * CStdFont::CreateFont(const char *szFaceName)
|
CStdVectorFont * C4FontLoader::CreateFont(const char *szFaceName)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
void CStdFont::DestroyFont(CStdVectorFont * pFont)
|
void C4FontLoader::DestroyFont(CStdVectorFont * pFont)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
C4FontLoader FontLoader;
|
||||||
|
|
||||||
CStdFont::CStdFont()
|
CStdFont::CStdFont()
|
||||||
{
|
{
|
||||||
// set default values
|
// set default values
|
||||||
|
@ -375,7 +518,7 @@ void CStdFont::Init(CStdVectorFont & VectorFont, const char *font_face_name, DWO
|
||||||
void CStdFont::Clear()
|
void CStdFont::Clear()
|
||||||
{
|
{
|
||||||
#if defined HAVE_FREETYPE
|
#if defined HAVE_FREETYPE
|
||||||
DestroyFont(pVectorFont);
|
FontLoader.DestroyFont(pVectorFont);
|
||||||
pVectorFont = NULL;
|
pVectorFont = NULL;
|
||||||
#endif
|
#endif
|
||||||
// clear font sfcs
|
// clear font sfcs
|
|
@ -45,6 +45,34 @@
|
||||||
class C4Markup;
|
class C4Markup;
|
||||||
class CStdVectorFont;
|
class CStdVectorFont;
|
||||||
|
|
||||||
|
// font loader
|
||||||
|
class C4FontLoader
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// enum of different fonts used in the clonk engine
|
||||||
|
enum FontType { C4FT_Log, C4FT_MainSmall, C4FT_Main, C4FT_Caption, C4FT_Title };
|
||||||
|
|
||||||
|
C4FontLoader(): pLastUsedFont(NULL), LastUsedGrpID(0) { } // ctor
|
||||||
|
~C4FontLoader() { Clear(); } // dtor
|
||||||
|
|
||||||
|
void Clear(); // clear loaded fonts
|
||||||
|
// init a font class of the given type
|
||||||
|
// iSize is always the size of the normal font, which is adjusted for larger (title) and smaller (log) font types
|
||||||
|
bool InitFont(CStdFont * Font, const char *szFontName, FontType eType, int32_t iSize, C4GroupSet *pGfxGroups, bool fDoShadow=true);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
CStdVectorFont * pLastUsedFont; // cache
|
||||||
|
StdCopyStrBuf LastUsedName;
|
||||||
|
int32_t LastUsedGrpID;
|
||||||
|
|
||||||
|
CStdVectorFont * CreateFont(StdBuf & Data);
|
||||||
|
CStdVectorFont * CreateFont(const char *szFaceName);
|
||||||
|
void DestroyFont(CStdVectorFont * pFont);
|
||||||
|
friend class CStdFont;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern C4FontLoader FontLoader;
|
||||||
|
|
||||||
class CStdFont
|
class CStdFont
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -60,10 +88,6 @@ public:
|
||||||
virtual ~CustomImages() { }
|
virtual ~CustomImages() { }
|
||||||
};
|
};
|
||||||
|
|
||||||
static CStdVectorFont * CreateFont(StdBuf & Data);
|
|
||||||
static CStdVectorFont * CreateFont(const char *szFaceName);
|
|
||||||
static void DestroyFont(CStdVectorFont * pFont);
|
|
||||||
public:
|
|
||||||
int id; // used by the engine to keep track of where the font came from
|
int id; // used by the engine to keep track of where the font came from
|
||||||
|
|
||||||
protected:
|
protected:
|
|
@ -1,173 +0,0 @@
|
||||||
/*
|
|
||||||
* OpenClonk, http://www.openclonk.org
|
|
||||||
*
|
|
||||||
* Copyright (c) 2004-2007 Sven Eberhardt
|
|
||||||
* Copyright (c) 2005-2007, 2010 Günther Brammer
|
|
||||||
* Copyright (c) 2010 Benjamin Herr
|
|
||||||
* Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de
|
|
||||||
*
|
|
||||||
* Portions might be copyrighted by other authors who have contributed
|
|
||||||
* to OpenClonk.
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
* See isc_license.txt for full license and disclaimer.
|
|
||||||
*
|
|
||||||
* "Clonk" is a registered trademark of Matthes Bender.
|
|
||||||
* See clonk_trademark_license.txt for full license.
|
|
||||||
*/
|
|
||||||
// engine font loading
|
|
||||||
|
|
||||||
#include <C4Include.h>
|
|
||||||
#include <C4Fonts.h>
|
|
||||||
|
|
||||||
#include <C4Language.h>
|
|
||||||
#include <C4Config.h>
|
|
||||||
#include <C4Components.h>
|
|
||||||
#include <C4Log.h>
|
|
||||||
#include <C4Surface.h>
|
|
||||||
#include <StdFont.h>
|
|
||||||
|
|
||||||
#include <StdFont.h>
|
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
void C4FontLoader::Clear()
|
|
||||||
{
|
|
||||||
// delete vector font cache
|
|
||||||
CStdFont::DestroyFont(pLastUsedFont);
|
|
||||||
pLastUsedFont = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool C4FontLoader::InitFont(CStdFont &rFont, const char *szFontName, FontType eType, int32_t iSize, C4GroupSet *pGfxGroups, bool fDoShadow)
|
|
||||||
{
|
|
||||||
#ifdef USE_CONSOLE
|
|
||||||
return true;
|
|
||||||
#endif
|
|
||||||
// safety
|
|
||||||
assert(szFontName);
|
|
||||||
if (!szFontName || !*szFontName)
|
|
||||||
{
|
|
||||||
LogFatal(FormatString("%s (\"%s\")", LoadResStr("IDS_ERR_INITFONTS"), szFontName ? szFontName : "(null)").getData());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// if def has not been found, use the def as font name
|
|
||||||
// determine font def string
|
|
||||||
const char *szFontString = szFontName;
|
|
||||||
// font not assigned?
|
|
||||||
assert(*szFontString);
|
|
||||||
if (!*szFontString)
|
|
||||||
{
|
|
||||||
// invalid call or spec
|
|
||||||
LogFatal(LoadResStr("IDS_ERR_INITFONTS")); return false;
|
|
||||||
}
|
|
||||||
// get font name
|
|
||||||
char FontFaceName[C4MaxName+1], FontParam[C4MaxName+1];
|
|
||||||
SCopyUntil(szFontString, FontFaceName, ',', C4MaxName);
|
|
||||||
// is it an image file?
|
|
||||||
int32_t iDefFontSize; DWORD dwDefWeight=FW_NORMAL;
|
|
||||||
switch (eType)
|
|
||||||
{
|
|
||||||
case C4FT_Log: iDefFontSize = iSize*12/14; break;
|
|
||||||
case C4FT_MainSmall:iDefFontSize = iSize*13/14; break;
|
|
||||||
case C4FT_Main: iDefFontSize = iSize; break;
|
|
||||||
case C4FT_Caption: iDefFontSize = iSize*16/14; /*dwDefWeight = FW_MEDIUM;*/ break;
|
|
||||||
case C4FT_Title: iDefFontSize = iSize*22/14; /*dwDefWeight = FW_MEDIUM;*/ break;
|
|
||||||
default: assert(false); LogFatal(LoadResStr("IDS_ERR_INITFONTS")); return false; // invalid call
|
|
||||||
}
|
|
||||||
// regular font name: let WinGDI or Freetype draw a font with the given parameters
|
|
||||||
// font size given?
|
|
||||||
if (SCopySegment(szFontString, 1, FontParam, ',', C4MaxName))
|
|
||||||
sscanf(FontParam, "%i", &iDefFontSize);
|
|
||||||
// font weight given?
|
|
||||||
if (SCopySegment(szFontString, 2, FontParam, ',', C4MaxName))
|
|
||||||
{
|
|
||||||
int iDefWeight;
|
|
||||||
sscanf(FontParam, "%i", &iDefWeight);
|
|
||||||
dwDefWeight = iDefWeight;
|
|
||||||
}
|
|
||||||
// check if it's already loaded from that group with that parameters
|
|
||||||
if (rFont.IsSameAs(FontFaceName, iDefFontSize, dwDefWeight))
|
|
||||||
return true;
|
|
||||||
// it's not; so (re-)load it now!
|
|
||||||
if (rFont.IsInitialized())
|
|
||||||
{
|
|
||||||
// reloading
|
|
||||||
rFont.Clear();
|
|
||||||
LogF(LoadResStr("IDS_PRC_UPDATEFONT"), FontFaceName, iDefFontSize, dwDefWeight);
|
|
||||||
}
|
|
||||||
// check if one of the internally listed fonts should be used
|
|
||||||
const char * const extensions[] = { "ttf", "otf", "ttc", "fon", "fnt", "fot", NULL };
|
|
||||||
char FileName[_MAX_PATH+1];
|
|
||||||
int32_t ID;
|
|
||||||
C4Group * pGrp = pGfxGroups->FindSuitableFile(FontFaceName, extensions, FileName, &ID);
|
|
||||||
if (pGrp)
|
|
||||||
{
|
|
||||||
if (LastUsedGrpID != ID || LastUsedName != FontFaceName)
|
|
||||||
{
|
|
||||||
CStdFont::DestroyFont(pLastUsedFont);
|
|
||||||
pLastUsedFont = NULL;
|
|
||||||
}
|
|
||||||
if (!pLastUsedFont)
|
|
||||||
{
|
|
||||||
StdBuf Data;
|
|
||||||
if (pGrp->LoadEntry(FileName, &Data))
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
pLastUsedFont = CStdFont::CreateFont(Data);
|
|
||||||
LastUsedGrpID = ID;
|
|
||||||
LastUsedName = FontFaceName;
|
|
||||||
}
|
|
||||||
catch (std::runtime_error & e)
|
|
||||||
{
|
|
||||||
LogFatal(e.what());
|
|
||||||
pGrp = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// no internal font match? Then create one using the given face/filename (using a system font)
|
|
||||||
if (!pGrp)
|
|
||||||
{
|
|
||||||
if (LastUsedGrpID != -1 || LastUsedName != FontFaceName)
|
|
||||||
{
|
|
||||||
CStdFont::DestroyFont(pLastUsedFont);
|
|
||||||
pLastUsedFont = NULL;
|
|
||||||
}
|
|
||||||
if (!pLastUsedFont)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
pLastUsedFont = CStdFont::CreateFont(FontFaceName);
|
|
||||||
if (!pLastUsedFont)
|
|
||||||
// no match for font face found
|
|
||||||
throw std::runtime_error(FormatString("Font face %s undefined", FontFaceName).getData());
|
|
||||||
LastUsedGrpID = -1;
|
|
||||||
LastUsedName = FontFaceName;
|
|
||||||
}
|
|
||||||
catch (std::runtime_error & e)
|
|
||||||
{
|
|
||||||
LogFatal(e.what());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!pLastUsedFont)
|
|
||||||
{
|
|
||||||
LogFatal(LoadResStr("IDS_ERR_INITFONTS"));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
rFont.Init(*pLastUsedFont, FontFaceName, iDefFontSize, dwDefWeight, fDoShadow); // throws exception on error
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (std::runtime_error & e)
|
|
||||||
{
|
|
||||||
LogFatal(e.what());
|
|
||||||
LogFatal(LoadResStr("IDS_ERR_INITFONTS"));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
C4FontLoader FontLoader;
|
|
|
@ -1,50 +0,0 @@
|
||||||
/*
|
|
||||||
* OpenClonk, http://www.openclonk.org
|
|
||||||
*
|
|
||||||
* Copyright (c) 2004-2005 Sven Eberhardt
|
|
||||||
* Copyright (c) 2006 Günther Brammer
|
|
||||||
* Copyright (c) 2004-2009, RedWolf Design GmbH, http://www.clonk.de
|
|
||||||
*
|
|
||||||
* Portions might be copyrighted by other authors who have contributed
|
|
||||||
* to OpenClonk.
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
* See isc_license.txt for full license and disclaimer.
|
|
||||||
*
|
|
||||||
* "Clonk" is a registered trademark of Matthes Bender.
|
|
||||||
* See clonk_trademark_license.txt for full license.
|
|
||||||
*/
|
|
||||||
// engine font loading
|
|
||||||
|
|
||||||
#ifndef INC_C4Fonts
|
|
||||||
#define INC_C4Fonts
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
// font loader
|
|
||||||
class C4FontLoader
|
|
||||||
{
|
|
||||||
protected:
|
|
||||||
CStdVectorFont * pLastUsedFont; // cache
|
|
||||||
StdCopyStrBuf LastUsedName;
|
|
||||||
int32_t LastUsedGrpID;
|
|
||||||
|
|
||||||
public:
|
|
||||||
// enum of different fonts used in the clonk engine
|
|
||||||
enum FontType { C4FT_Log, C4FT_MainSmall, C4FT_Main, C4FT_Caption, C4FT_Title };
|
|
||||||
|
|
||||||
public:
|
|
||||||
C4FontLoader(): pLastUsedFont(NULL), LastUsedGrpID(0) { } // ctor
|
|
||||||
~C4FontLoader() { Clear(); } // dtor
|
|
||||||
|
|
||||||
void Clear(); // clear loaded fonts
|
|
||||||
// init a font class of the given type
|
|
||||||
// iSize is always the size of the normal font, which is adjusted for larger (title) and smaller (log) font types
|
|
||||||
bool InitFont(CStdFont &rFont, const char *szFontName, FontType eType, int32_t iSize, C4GroupSet *pGfxGroups, bool fDoShadow=true);
|
|
||||||
};
|
|
||||||
|
|
||||||
extern C4FontLoader FontLoader;
|
|
||||||
|
|
||||||
#endif // INC_C4Fonts
|
|
|
@ -26,11 +26,11 @@
|
||||||
#include <C4GraphicsResource.h>
|
#include <C4GraphicsResource.h>
|
||||||
|
|
||||||
#include <C4DefList.h>
|
#include <C4DefList.h>
|
||||||
|
#include <C4FontLoader.h>
|
||||||
#include <C4Log.h>
|
#include <C4Log.h>
|
||||||
#include <C4Game.h>
|
#include <C4Game.h>
|
||||||
#include <C4GraphicsSystem.h>
|
#include <C4GraphicsSystem.h>
|
||||||
#include <C4Def.h>
|
#include <C4Def.h>
|
||||||
#include <C4Fonts.h>
|
|
||||||
|
|
||||||
#include <C4DrawGL.h>
|
#include <C4DrawGL.h>
|
||||||
|
|
||||||
|
@ -154,15 +154,15 @@ bool C4GraphicsResource::InitFonts()
|
||||||
// this regards scenario-specific fonts or overloads in Extra.ocg
|
// this regards scenario-specific fonts or overloads in Extra.ocg
|
||||||
const char *szFont;
|
const char *szFont;
|
||||||
if (*Game.C4S.Head.Font) szFont = Game.C4S.Head.Font; else szFont = Config.General.RXFontName;
|
if (*Game.C4S.Head.Font) szFont = Game.C4S.Head.Font; else szFont = Config.General.RXFontName;
|
||||||
if (!::FontLoader.InitFont(FontRegular, szFont, C4FontLoader::C4FT_Main, Config.General.RXFontSize, &Files)) return false;
|
if (!::FontLoader.InitFont(&FontRegular, szFont, C4FontLoader::C4FT_Main, Config.General.RXFontSize, &Files)) return false;
|
||||||
Game.SetInitProgress(ProgressStart); ProgressStart += ProgressIncrement;
|
Game.SetInitProgress(ProgressStart); ProgressStart += ProgressIncrement;
|
||||||
if (!::FontLoader.InitFont(FontTiny, szFont, C4FontLoader::C4FT_Log, Config.General.RXFontSize, &Files)) return false;
|
if (!::FontLoader.InitFont(&FontTiny, szFont, C4FontLoader::C4FT_Log, Config.General.RXFontSize, &Files)) return false;
|
||||||
Game.SetInitProgress(ProgressStart); ProgressStart += ProgressIncrement;
|
Game.SetInitProgress(ProgressStart); ProgressStart += ProgressIncrement;
|
||||||
if (!::FontLoader.InitFont(FontTitle, szFont, C4FontLoader::C4FT_Title, Config.General.RXFontSize, &Files)) return false;
|
if (!::FontLoader.InitFont(&FontTitle, szFont, C4FontLoader::C4FT_Title, Config.General.RXFontSize, &Files)) return false;
|
||||||
Game.SetInitProgress(ProgressStart); ProgressStart += ProgressIncrement;
|
Game.SetInitProgress(ProgressStart); ProgressStart += ProgressIncrement;
|
||||||
if (!::FontLoader.InitFont(FontCaption, szFont, C4FontLoader::C4FT_Caption, Config.General.RXFontSize, &Files)) return false;
|
if (!::FontLoader.InitFont(&FontCaption, szFont, C4FontLoader::C4FT_Caption, Config.General.RXFontSize, &Files)) return false;
|
||||||
Game.SetInitProgress(ProgressStart); ProgressStart += ProgressIncrement;
|
Game.SetInitProgress(ProgressStart); ProgressStart += ProgressIncrement;
|
||||||
if (!::FontLoader.InitFont(FontTooltip, szFont, C4FontLoader::C4FT_Main, Config.General.RXFontSize, &Files, false)) return false;
|
if (!::FontLoader.InitFont(&FontTooltip, szFont, C4FontLoader::C4FT_Main, Config.General.RXFontSize, &Files, false)) return false;
|
||||||
Game.SetInitProgress(ProgressStart); ProgressStart += ProgressIncrement;
|
Game.SetInitProgress(ProgressStart); ProgressStart += ProgressIncrement;
|
||||||
// assign def list as custom image source
|
// assign def list as custom image source
|
||||||
FontRegular.SetCustomImages(&::Definitions);
|
FontRegular.SetCustomImages(&::Definitions);
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#ifndef INC_C4Gui
|
#ifndef INC_C4Gui
|
||||||
#define INC_C4Gui
|
#define INC_C4Gui
|
||||||
|
|
||||||
|
#include <C4FontLoader.h>
|
||||||
#include "C4Rect.h"
|
#include "C4Rect.h"
|
||||||
#include "C4Shape.h"
|
#include "C4Shape.h"
|
||||||
#include "C4FacetEx.h"
|
#include "C4FacetEx.h"
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include <C4Include.h>
|
#include <C4Include.h>
|
||||||
#include <C4Startup.h>
|
#include <C4Startup.h>
|
||||||
|
|
||||||
|
#include <C4FontLoader.h>
|
||||||
#include <C4StartupMainDlg.h>
|
#include <C4StartupMainDlg.h>
|
||||||
#include <C4StartupScenSelDlg.h>
|
#include <C4StartupScenSelDlg.h>
|
||||||
#include <C4StartupNetDlg.h>
|
#include <C4StartupNetDlg.h>
|
||||||
|
@ -34,7 +35,6 @@
|
||||||
#include <C4Log.h>
|
#include <C4Log.h>
|
||||||
#include <C4GraphicsResource.h>
|
#include <C4GraphicsResource.h>
|
||||||
#include <C4GraphicsSystem.h>
|
#include <C4GraphicsSystem.h>
|
||||||
#include <C4Fonts.h>
|
|
||||||
|
|
||||||
bool C4StartupGraphics::LoadFile(C4FacetID &rToFct, const char *szFilename)
|
bool C4StartupGraphics::LoadFile(C4FacetID &rToFct, const char *szFilename)
|
||||||
{
|
{
|
||||||
|
@ -95,16 +95,16 @@ bool C4StartupGraphics::Init()
|
||||||
bool C4StartupGraphics::InitFonts()
|
bool C4StartupGraphics::InitFonts()
|
||||||
{
|
{
|
||||||
const char *szFont = Config.General.RXFontName;
|
const char *szFont = Config.General.RXFontName;
|
||||||
if (!::FontLoader.InitFont(BookFontCapt, szFont, C4FontLoader::C4FT_Caption, Config.General.RXFontSize, &::GraphicsResource.Files, false))
|
if (!::FontLoader.InitFont(&BookFontCapt, szFont, C4FontLoader::C4FT_Caption, Config.General.RXFontSize, &::GraphicsResource.Files, false))
|
||||||
{ LogFatal("Font Error (1)"); return false; }
|
{ LogFatal("Font Error (1)"); return false; }
|
||||||
Game.SetInitProgress(97);
|
Game.SetInitProgress(97);
|
||||||
if (!::FontLoader.InitFont(BookFont, szFont, C4FontLoader::C4FT_Main, Config.General.RXFontSize, &::GraphicsResource.Files, false))
|
if (!::FontLoader.InitFont(&BookFont, szFont, C4FontLoader::C4FT_Main, Config.General.RXFontSize, &::GraphicsResource.Files, false))
|
||||||
{ LogFatal("Font Error (2)"); return false; }
|
{ LogFatal("Font Error (2)"); return false; }
|
||||||
Game.SetInitProgress(98);
|
Game.SetInitProgress(98);
|
||||||
if (!::FontLoader.InitFont(BookFontTitle, szFont, C4FontLoader::C4FT_Title, Config.General.RXFontSize, &::GraphicsResource.Files, false))
|
if (!::FontLoader.InitFont(&BookFontTitle, szFont, C4FontLoader::C4FT_Title, Config.General.RXFontSize, &::GraphicsResource.Files, false))
|
||||||
{ LogFatal("Font Error (3)"); return false; }
|
{ LogFatal("Font Error (3)"); return false; }
|
||||||
Game.SetInitProgress(99);
|
Game.SetInitProgress(99);
|
||||||
if (!::FontLoader.InitFont(BookSmallFont, szFont, C4FontLoader::C4FT_MainSmall, Config.General.RXFontSize, &::GraphicsResource.Files, false))
|
if (!::FontLoader.InitFont(&BookSmallFont, szFont, C4FontLoader::C4FT_MainSmall, Config.General.RXFontSize, &::GraphicsResource.Files, false))
|
||||||
{ LogFatal("Font Error (4)"); return false; }
|
{ LogFatal("Font Error (4)"); return false; }
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
#include "C4Include.h"
|
#include "C4Include.h"
|
||||||
#include "C4LogBuf.h"
|
#include "C4LogBuf.h"
|
||||||
|
|
||||||
|
#include <C4FontLoader.h>
|
||||||
|
|
||||||
C4LogBuffer::C4LogBuffer(int iSize, int iMaxLines, int iLBWidth, const char *szIndentChars, bool fDynamicGrow, bool fMarkup)
|
C4LogBuffer::C4LogBuffer(int iSize, int iMaxLines, int iLBWidth, const char *szIndentChars, bool fDynamicGrow, bool fMarkup)
|
||||||
: iBufSize(iSize), iFirstLinePos(0), iAfterLastLinePos(0), iLineDataPos(0),
|
: iBufSize(iSize), iFirstLinePos(0), iAfterLastLinePos(0), iLineDataPos(0),
|
||||||
iNextLineDataPos(0), iMaxLineCount(iMaxLines), iLineCount(0), iLineBreakWidth(iLBWidth), fDynamicGrow(fDynamicGrow), fMarkup(fMarkup)
|
iNextLineDataPos(0), iMaxLineCount(iMaxLines), iLineCount(0), iLineBreakWidth(iLBWidth), fDynamicGrow(fDynamicGrow), fMarkup(fMarkup)
|
||||||
|
|
|
@ -20,8 +20,6 @@
|
||||||
#ifndef INC_C4LogBuf
|
#ifndef INC_C4LogBuf
|
||||||
#define INC_C4LogBuf
|
#define INC_C4LogBuf
|
||||||
|
|
||||||
#include <StdFont.h>
|
|
||||||
|
|
||||||
// circular log buffer to holding line-wise log data
|
// circular log buffer to holding line-wise log data
|
||||||
class C4LogBuffer
|
class C4LogBuffer
|
||||||
{
|
{
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
#ifndef INC_C4DefList
|
#ifndef INC_C4DefList
|
||||||
#define INC_C4DefList
|
#define INC_C4DefList
|
||||||
|
|
||||||
#include <StdFont.h>
|
#include <C4FontLoader.h>
|
||||||
|
|
||||||
class C4DefList: public CStdFont::CustomImages
|
class C4DefList: public CStdFont::CustomImages
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue