405 lines
11 KiB
C++
405 lines
11 KiB
C++
/*************************************************************************/
|
|
/* File : CKFontManager.h */
|
|
/* */
|
|
/* Author : Aymeric Bard */
|
|
/* Last Modification : 18/08/98 */
|
|
/* */
|
|
/* Virtools Nemo SDK */
|
|
/* Copyright (c) 1998, All Rights Reserved. */
|
|
/*************************************************************************/
|
|
#ifndef CKFontManager_H
|
|
//{secret}
|
|
#define CKFontManager_H "$Id:$"
|
|
|
|
#include "CKDefines.h"
|
|
#include "CKBaseManager.h"
|
|
#include "CKTextureFont.h"
|
|
#include "CompiledData.h"
|
|
|
|
#include "DrawingPrimitives.h"
|
|
|
|
|
|
|
|
|
|
#if defined(PSX2) || defined(PSP)
|
|
#define FONTMANAGER_NOSYSFONT
|
|
#endif
|
|
|
|
#ifdef _XBOX
|
|
#include "Xtl.h"
|
|
#define FONTMANAGER_NOSYSFONT
|
|
#endif
|
|
|
|
#ifdef WIN32
|
|
#include "windows.h"
|
|
#else
|
|
#ifdef macintosh
|
|
#define USEQUICKDRAWTEXT
|
|
#pragma message("Font Manager -- Quickdraw version");
|
|
|
|
#include "UStr.h"
|
|
#endif
|
|
#endif
|
|
|
|
|
|
#ifdef USEQUICKDRAWTEXT
|
|
#ifdef macintosh
|
|
#ifndef __GNUC__
|
|
#include "QuickTimeComponents.h"
|
|
#include "QTML.h"
|
|
#include "QuickDraw.h"
|
|
#include "Fonts.h"
|
|
#include "QuickDrawtext.h"
|
|
#endif
|
|
#endif
|
|
#endif
|
|
|
|
#define CKPGUID_FONTRESOLUTION CKGUID(0x7157091d,0x4fc82932)
|
|
#define CKPGUID_FONTNAME CKGUID(0x7167091a,0x7f482632)
|
|
|
|
#define CKPGUID_ALIGNMENT CKGUID(0x2e1e2209,0x47da44b5)
|
|
#define CKPGUID_FONTPROPERTIES CKGUID(0x63223dd5,0x6b5f68fc)
|
|
#define CKPGUID_TEXTPROPERTIES CKGUID(0x4157001d,0x4cc82922)
|
|
|
|
#define FONT_MANAGER_GUID CKGUID(0x64fb5810,0x73262d3b)
|
|
#define CKPGUID_FONT CKGUID(0x64fb5811,0x33862d3b)
|
|
#define CKPGUID_FONTWEIGHT CKGUID(0x4376013f,0xb3462c0)
|
|
|
|
// Struct containg line information for a multi line text
|
|
struct LineData {
|
|
char* string;
|
|
int len;
|
|
int nbspace;
|
|
float stringwidth;
|
|
};
|
|
|
|
|
|
#if defined(WIN32) && !defined(USEQUICKDRAWTEXT) && !defined(FONTMANAGER_NOSYSFONT)
|
|
typedef HFONT FONTHANDLE;
|
|
typedef TEXTMETRIC FONT_METRIC;
|
|
typedef OUTLINETEXTMETRIC FONT_OUTLINEMETRIC;
|
|
typedef ABC FONT_ABC;
|
|
#else
|
|
struct FONT_ABC {
|
|
int abcA; // Left Side Bearing
|
|
DWORD abcB; // Glyph Width
|
|
int abcC; // Advance Width
|
|
};
|
|
|
|
struct FONT_OUTLINEMETRIC {
|
|
|
|
};
|
|
|
|
struct FONT_METRIC {
|
|
LONG tmHeight;
|
|
LONG tmAscent;
|
|
LONG tmDescent;
|
|
LONG tmWeight;
|
|
LONG tmAveCharWidth;
|
|
LONG tmMaxCharWidth;
|
|
};
|
|
|
|
typedef void* FONTHANDLE;
|
|
|
|
#endif
|
|
|
|
|
|
typedef XHashTable<FONTHANDLE, XString> FontsTable;
|
|
typedef XHashTable<FONTHANDLE, XString>::Iterator FontIterator;
|
|
|
|
|
|
|
|
|
|
#define RECTANGLE_INTERIOR 1
|
|
#define RECTANGLE_BORDER 2
|
|
|
|
struct RectangleData {
|
|
RectangleData() {}
|
|
RectangleData(CKBOOL in,const CKDWORD col,CKMaterial* mat,const VxRect& s,const VxRect& u,CKBOOL border, const CKDWORD bcol, float bsize):m_InColor(col),m_Material(mat),m_Screen(s),m_InUVs(u),m_BorderColor(bcol) {m_BorderSize = border?(in?bsize:-bsize):0.0f;}
|
|
CKDWORD m_InColor;
|
|
CKMaterial* m_Material;
|
|
CKDWORD m_BorderColor;
|
|
float m_BorderSize;
|
|
|
|
VxRect m_Screen;
|
|
|
|
VxRect m_InUVs;
|
|
};
|
|
|
|
#define WHITE (0x00FFFFFF)
|
|
|
|
struct TextData {
|
|
CK_ID m_Entity;
|
|
int m_FontIndex;
|
|
CKSTRING m_String;
|
|
Vx2DVector m_Scale;
|
|
Vx2DVector m_Leading;
|
|
CKDWORD m_StartColor;
|
|
CKDWORD m_EndColor;
|
|
int m_Align;
|
|
VxRect m_Textzone;
|
|
CKMaterial* m_Mat;
|
|
int m_Textflags;
|
|
|
|
VxRect m_Margins ;
|
|
Vx2DVector m_Offset ;
|
|
Vx2DVector m_ParagraphIndentation;
|
|
float m_CaretSize;
|
|
CKMaterial* m_CaretMaterial;
|
|
VxRect m_ClippingRect;
|
|
|
|
TextData():m_Entity(0), m_FontIndex(0), m_String(NULL), m_Scale(1.0f, 1.0f),m_Leading(0.0f,0.0f), m_EndColor(WHITE), m_StartColor(WHITE), m_Align(0), m_Mat(NULL), m_Textflags(0),m_CaretMaterial(NULL)
|
|
{
|
|
}
|
|
|
|
TextData(CK_ID entity, int fontindex, CKSTRING string, Vx2DVector scale, CKDWORD startColor, CKDWORD endColor, int align, VxRect textzone, CKMaterial* mat, int textflags):m_Entity(entity), m_FontIndex(fontindex), m_Scale(scale),m_StartColor(startColor), m_EndColor(endColor), m_Align(align),m_Textzone(textzone),m_Mat(mat), m_Textflags(textflags) ,m_CaretMaterial(NULL) {
|
|
m_String = CKStrdup(string);
|
|
}
|
|
|
|
~TextData() {
|
|
CKStrdelete(m_String);
|
|
}
|
|
|
|
TextData(const TextData& td) {
|
|
memcpy(this, &td, sizeof(struct TextData));
|
|
m_String = CKStrdup(td.m_String);
|
|
}
|
|
|
|
TextData& operator=(const TextData& td) {
|
|
if (this != &td) {
|
|
CKStrdelete(m_String);
|
|
memcpy(this, &td, sizeof(struct TextData));
|
|
m_String = CKStrdup(td.m_String);
|
|
}
|
|
return *this;
|
|
}
|
|
};
|
|
|
|
int Compare2DTextData(const void* elem1, const void* elem2);
|
|
int Compare3DTextData(const void* elem1, const void* elem2);
|
|
|
|
typedef XArray<CKTextureFont*> TextureFontArray;
|
|
typedef XArray<LineData> LineDataArray;
|
|
typedef XArray<RectangleData> RectangleDataArray;
|
|
typedef XArray<TextData*> TextDataArray;
|
|
|
|
typedef XSHashTable<TextData*, CK_ID> TextDataTable;
|
|
typedef TextDataTable::Iterator TextDataTableIterator;
|
|
typedef XSHashTable<CompiledTextData*,CK_ID> CompiledTextTable;
|
|
typedef CompiledTextTable::Iterator CompiledTextTableIterator;
|
|
|
|
|
|
|
|
class CKFontManager :public CKBaseManager{
|
|
////////////////////////////////////////////////////////
|
|
// Public Part ////
|
|
////////////////////////////////////////////////////////
|
|
public :
|
|
///
|
|
// Virtuals Override
|
|
|
|
// Initialization
|
|
virtual CKERROR OnCKInit();
|
|
virtual CKERROR OnCKEnd();
|
|
|
|
virtual CKERROR SequenceToBeDeleted(CK_ID *objids,int count);
|
|
|
|
// Pause Resume
|
|
virtual CKERROR OnCKReset();
|
|
|
|
virtual CKERROR PostClearAll();
|
|
virtual CKERROR PreProcess();
|
|
virtual CKERROR PostLoad();
|
|
|
|
virtual CKERROR LoadData(CKStateChunk *chunk,CKFile* LoadedFile);
|
|
virtual CKStateChunk* SaveData(CKFile *SavedFile);
|
|
|
|
virtual CKERROR OnPostRender(CKRenderContext* dev);
|
|
virtual CKERROR OnPostSpriteRender(CKRenderContext* dev);
|
|
virtual CKERROR OnPostBackToFront(CKRenderContext* dev);
|
|
|
|
virtual CKDWORD GetValidFunctionsMask() { return CKMANAGER_FUNC_OnSequenceToBeDeleted |
|
|
CKMANAGER_FUNC_PostClearAll|
|
|
CKMANAGER_FUNC_OnCKInit|
|
|
CKMANAGER_FUNC_PostLoad|
|
|
CKMANAGER_FUNC_OnCKEnd|
|
|
CKMANAGER_FUNC_OnCKReset|
|
|
CKMANAGER_FUNC_PreProcess|
|
|
CKMANAGER_FUNC_OnPostRender|
|
|
CKMANAGER_FUNC_OnPostSpriteRender|
|
|
CKMANAGER_FUNC_OnPostBackToFront;}
|
|
|
|
// Virtual methods
|
|
|
|
// Font Access
|
|
virtual CKTexture* GetFontTexture(unsigned int fontindex);
|
|
//
|
|
virtual CKSTRING GetFontName(unsigned int fontindex);
|
|
//
|
|
virtual int GetFontIndex(CKSTRING name);
|
|
//
|
|
virtual CKTextureFont* GetFont(unsigned int fontindex);
|
|
//
|
|
virtual int CreateTextureFont(CKSTRING FontName,CKTexture* fonttexture,VxRect& tzone,Vx2DVector& charnumber,CKBOOL fixed=TRUE,int firstcharacter = 0,float iSpaceSize = 0.3f);
|
|
// Create a logical font from a system font name
|
|
virtual CKBOOL CreateFont(CKSTRING fontName, int systemFontIndex, int weigth, CKBOOL italic, CKBOOL underline, int resolution,int iForcedSize);
|
|
// Create a texture from a logical font
|
|
virtual CKTexture* CreateTextureFromFont(int systemFontIndex , int resolution, CKBOOL extended, CKBOOL bold, CKBOOL italic, CKBOOL underline, CKBOOL renderControls, CKBOOL dynamic, int iFontSize = 0);
|
|
|
|
// Character Conversion PC->Current Platform
|
|
static inline char PCToPlatformCharacter(const char pcASCIICode)
|
|
{
|
|
#if defined(macintosh)
|
|
return UStr::PCToMacASCII(pcASCIICode);
|
|
#else
|
|
// On PC, just keep the code as it is
|
|
return pcASCIICode;
|
|
#endif
|
|
}
|
|
|
|
// Character Conversion Current Platform->PC
|
|
static inline char PlatformToPCCharacter(const char platformCode)
|
|
{
|
|
#if defined(macintosh)
|
|
return UStr::MacToPCASCII(platformCode);
|
|
#else
|
|
// On PC, just keep the code as it is
|
|
return platformCode;
|
|
#endif
|
|
}
|
|
|
|
//
|
|
virtual void DrawText(CKRenderContext* iRC, int iFontIndex, const char* iText, const Vx2DVector& iPosition, const Vx2DVector& iScale, CKDWORD iStartColor, CKDWORD iEndColor);
|
|
// font deletion
|
|
virtual void DeleteFont(int iFontIndex);
|
|
|
|
// Methods
|
|
|
|
// entity under mouse
|
|
CK2dEntity* GetEntityUnderMouse() {return m_EntityUnderMouse;}
|
|
|
|
// Text Lines
|
|
void ClearLines();
|
|
void AddLine(LineData& data);
|
|
int GetLineCount();
|
|
LineData* GetLine(int i);
|
|
|
|
// Font Creation
|
|
int RegisterFont(CKTextureFont* font);
|
|
void RebuildFontEnumeration(void);
|
|
|
|
|
|
// Compiled Text Data Access
|
|
CompiledTextData* AddCompiledText(CK_ID id);
|
|
void RemoveCompiledText(CK_ID id);
|
|
CompiledTextData* GetCompiledText(CK_ID id);
|
|
|
|
|
|
// Rectangles Drawing
|
|
void DrawRectangle(const RectangleData& rd);
|
|
void DrawText(CK_ID entity, int fontindex, CKSTRING string, Vx2DVector scale, CKDWORD startColor, CKDWORD endColor, int align, VxRect textzone, CKMaterial* mat, int textflags);
|
|
|
|
// Generate font enumeration
|
|
CKBOOL RegenerateFontEnumeration();
|
|
// Delete a logical font
|
|
void DeleteFontHandle(CKSTRING fontName);
|
|
// Get the list of all system font names
|
|
CKBOOL GetFontNames(CKDataArray* array);
|
|
// Select a logical font by name
|
|
CKBOOL SelectFont(CKSTRING fontName);
|
|
// test if current font is a true type font
|
|
CKBOOL IsTrueTypeFont(void);
|
|
// Get a logical font metric
|
|
CKBOOL GetFontMetrics(FONT_METRIC& metric);
|
|
CKBOOL GetOutlineFontMetric(FONT_OUTLINEMETRIC& metric);
|
|
// Get a font character widths
|
|
CKBOOL GetCharABCWidths(CKBYTE startChar, CKBYTE endChar, FONT_ABC* ABCwidths);
|
|
CKBOOL GetCharWidths(CKBYTE startChar, CKBYTE endChar, int* widths);
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
//// Private Part ////
|
|
////////////////////////////////////////////////////////
|
|
//{secret}
|
|
CKFontManager(CKContext* ctx);
|
|
//{secret}
|
|
~CKFontManager();
|
|
|
|
static const char* Name;
|
|
CKBOOL m_VersionUpdate;
|
|
|
|
private:
|
|
void ClearFontData(void);
|
|
void ClearTextData(void);
|
|
void OnTextureToBeDeleted();
|
|
void RegisterAttributes();
|
|
// Post render Callback
|
|
void DrawRectanglesCallback(CKRenderContext* dev);
|
|
static void DrawTextCallback2D(CKRenderContext* dev, void* arg);
|
|
static void DrawTextCallback3D(CKRenderContext* dev, void* arg);
|
|
//////////////////////////////
|
|
// Members
|
|
/////////////////////////////
|
|
|
|
///
|
|
// CONTROLS DATA
|
|
|
|
// the 2D Entity currently under the mouse cursor
|
|
CK2dEntity* m_EntityUnderMouse;
|
|
|
|
|
|
///
|
|
// FONT DATA
|
|
|
|
// The Font Array
|
|
TextureFontArray m_FontArray;
|
|
CKTextureFont* m_DebugFont;
|
|
|
|
// The LineData Array
|
|
LineDataArray m_Lines;
|
|
// Remapping Array
|
|
XArray<int> m_Remap;
|
|
|
|
// The Rectangle Data Array
|
|
RectangleDataArray m_Rectangles;
|
|
|
|
// Text data
|
|
TextDataArray m_2DTexts;
|
|
TextDataArray m_3DTexts;
|
|
|
|
// Compiled Text (sorted by entity ID)
|
|
CompiledTextTable m_CompiledText;
|
|
TextDataTable m_Texts;
|
|
|
|
TextDataTable m_TextsRespectZorder;
|
|
|
|
// The texture attribute
|
|
int m_FontAttribute;
|
|
|
|
CKBOOL m_TextureLoaded;
|
|
|
|
|
|
// Win32 Specific (System TT fonts information)
|
|
#ifndef FONTMANAGER_NOSYSFONT
|
|
#ifdef USEQUICKDRAWTEXT
|
|
GWorldPtr m_GDC;
|
|
FONTHANDLE m_CurrentFont;
|
|
#else
|
|
// Memory device context for font rendering
|
|
HDC m_DC;
|
|
HFONT m_BackupFont;
|
|
#endif
|
|
// Associative table 'font name' -> 'font handle'
|
|
FontsTable m_fonts;
|
|
|
|
#endif
|
|
|
|
|
|
public:
|
|
int GetFontCount() {return m_FontArray.Size(); }
|
|
|
|
};
|
|
|
|
#endif
|
|
|