2002-11-16 08:07:38 +00:00
|
|
|
#ifndef FONT_H
|
|
|
|
|
#define FONT_H
|
2002-03-30 20:00:13 +00:00
|
|
|
/*
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
File: Font
|
|
|
|
|
|
|
|
|
|
Desc: A holder for information that is used by BitmapText objects.
|
|
|
|
|
|
2002-05-19 01:59:48 +00:00
|
|
|
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
|
2002-03-30 20:00:13 +00:00
|
|
|
Chris Danford
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "RageTexture.h"
|
2003-01-05 08:11:05 +00:00
|
|
|
#include "RageUtil.h"
|
2003-01-03 22:53:22 +00:00
|
|
|
#include "IniFile.h"
|
2002-03-30 20:00:13 +00:00
|
|
|
|
2003-01-06 23:49:43 +00:00
|
|
|
class FontPage;
|
|
|
|
|
|
2003-01-03 22:53:22 +00:00
|
|
|
struct glyph {
|
2003-01-06 23:49:43 +00:00
|
|
|
FontPage *fp;
|
2003-01-04 05:20:40 +00:00
|
|
|
RageTexture *Texture;
|
2003-01-19 00:48:23 +00:00
|
|
|
RageTexture *GetTexture() const { return const_cast<RageTexture *>(Texture); }
|
2003-01-04 05:20:40 +00:00
|
|
|
|
2003-01-04 01:47:01 +00:00
|
|
|
/* Number of pixels to advance horizontally after drawing this character. */
|
2003-01-08 02:32:30 +00:00
|
|
|
int hadvance;
|
2003-01-04 01:47:01 +00:00
|
|
|
|
|
|
|
|
/* Size of the actual rendered character. */
|
|
|
|
|
float width, height;
|
|
|
|
|
|
|
|
|
|
/* Number of pixels to offset this character when rendering. */
|
2003-01-08 02:32:30 +00:00
|
|
|
float hshift; // , vshift;
|
2002-03-30 20:00:13 +00:00
|
|
|
|
2003-01-03 22:53:22 +00:00
|
|
|
/* Texture coordinate rect. */
|
|
|
|
|
RectF rect;
|
|
|
|
|
};
|
2002-03-30 20:00:13 +00:00
|
|
|
|
2003-01-10 00:31:46 +00:00
|
|
|
struct FontPageSettings
|
|
|
|
|
{
|
|
|
|
|
CString TexturePath;
|
|
|
|
|
|
2003-01-05 03:32:41 +00:00
|
|
|
int DrawExtraPixelsLeft,
|
|
|
|
|
DrawExtraPixelsRight,
|
|
|
|
|
AddToAllWidths,
|
2003-01-06 23:49:43 +00:00
|
|
|
LineSpacing,
|
2003-01-08 02:32:30 +00:00
|
|
|
Top,
|
2003-01-16 20:21:07 +00:00
|
|
|
Baseline,
|
|
|
|
|
DefaultWidth;
|
2003-01-05 03:32:41 +00:00
|
|
|
float ScaleAllWidthsBy;
|
|
|
|
|
|
2003-01-05 08:11:05 +00:00
|
|
|
map<longchar,int> CharToGlyphNo;
|
2003-01-05 03:32:41 +00:00
|
|
|
/* If a value is missing, the width of the texture frame is used. */
|
|
|
|
|
map<int,int> GlyphWidths;
|
|
|
|
|
|
|
|
|
|
FontPageSettings():
|
|
|
|
|
DrawExtraPixelsLeft(0), DrawExtraPixelsRight(0),
|
|
|
|
|
AddToAllWidths(0),
|
|
|
|
|
LineSpacing(-1),
|
2003-01-08 02:32:30 +00:00
|
|
|
Top(-1),
|
2003-01-16 20:21:07 +00:00
|
|
|
Baseline(-1),
|
2003-02-14 06:36:02 +00:00
|
|
|
DefaultWidth(-1),
|
|
|
|
|
ScaleAllWidthsBy(1)
|
2003-01-05 03:32:41 +00:00
|
|
|
{ }
|
2003-01-16 20:21:07 +00:00
|
|
|
|
|
|
|
|
/* Map a range from a character map to glyphs. If cnt is -1, map the
|
|
|
|
|
* whole map. Returns "" or an error message. */
|
|
|
|
|
CString MapRange(CString Mapping, int map_offset, int glyph_offset, int cnt);
|
2003-01-05 03:32:41 +00:00
|
|
|
};
|
|
|
|
|
|
2003-01-04 05:20:40 +00:00
|
|
|
class FontPage
|
2002-03-30 20:00:13 +00:00
|
|
|
{
|
|
|
|
|
public:
|
2003-01-04 05:20:40 +00:00
|
|
|
RageTexture* m_pTexture;
|
|
|
|
|
|
|
|
|
|
CString m_sTexturePath;
|
|
|
|
|
|
|
|
|
|
/* All glyphs in this list will point to m_pTexture. */
|
|
|
|
|
vector<glyph> glyphs;
|
|
|
|
|
|
2003-01-05 08:11:05 +00:00
|
|
|
map<longchar,int> m_iCharToGlyphNo;
|
2003-01-04 05:20:40 +00:00
|
|
|
|
|
|
|
|
FontPage();
|
|
|
|
|
~FontPage();
|
2002-03-30 20:00:13 +00:00
|
|
|
|
2003-01-18 03:14:10 +00:00
|
|
|
void Load( FontPageSettings cfg );
|
2003-01-03 20:59:50 +00:00
|
|
|
|
2003-01-06 23:49:43 +00:00
|
|
|
/* Page-global properties. */
|
2003-01-08 02:32:30 +00:00
|
|
|
int height;
|
2003-01-10 03:48:21 +00:00
|
|
|
int LineSpacing;
|
|
|
|
|
float vshift;
|
2003-01-08 02:32:30 +00:00
|
|
|
int GetCenter() const { return height/2; }
|
2003-01-06 23:49:43 +00:00
|
|
|
|
2003-01-03 20:59:50 +00:00
|
|
|
private:
|
|
|
|
|
void SetExtraPixels(int DrawExtraPixelsLeft, int DrawExtraPixelsRight);
|
2003-01-08 02:32:30 +00:00
|
|
|
void SetTextureCoords(const vector<int> &widths);
|
2003-01-04 05:20:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Font
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
int m_iRefCount;
|
|
|
|
|
CString path;
|
|
|
|
|
|
|
|
|
|
Font();
|
2003-01-04 08:12:19 +00:00
|
|
|
~Font();
|
2003-01-04 05:20:40 +00:00
|
|
|
|
2003-01-28 00:45:01 +00:00
|
|
|
const glyph &GetGlyph( wchar_t c ) const;
|
2003-01-04 05:20:40 +00:00
|
|
|
|
2003-01-28 00:45:01 +00:00
|
|
|
int GetLineWidthInSourcePixels( const wstring &szLine ) const;
|
|
|
|
|
int GetLineHeightInSourcePixels( const wstring &szLine ) const;
|
2003-01-04 05:20:40 +00:00
|
|
|
|
2003-02-12 19:33:30 +00:00
|
|
|
bool FontCompleteForString( const wstring &str ) const;
|
|
|
|
|
|
2003-01-04 05:20:40 +00:00
|
|
|
/* Add a FontPage to this font. */
|
|
|
|
|
void AddPage(FontPage *fp);
|
|
|
|
|
|
2003-01-05 07:55:31 +00:00
|
|
|
/* Steal all of a font's pages. */
|
2003-01-10 02:02:51 +00:00
|
|
|
void MergeFont(Font &f);
|
2003-01-05 07:55:31 +00:00
|
|
|
|
2003-01-10 02:02:51 +00:00
|
|
|
void Load(const CString &sFontOrTextureFilePath, CString sChars);
|
2003-01-10 00:31:46 +00:00
|
|
|
void Unload();
|
2003-01-10 02:02:51 +00:00
|
|
|
void Reload();
|
2003-01-10 00:31:46 +00:00
|
|
|
|
2003-01-04 05:20:40 +00:00
|
|
|
/* Load font-wide settings. */
|
2003-01-05 03:32:41 +00:00
|
|
|
void CapsOnly();
|
2003-01-04 05:20:40 +00:00
|
|
|
|
2003-01-08 02:32:30 +00:00
|
|
|
int GetHeight() const { return def->height; }
|
|
|
|
|
int GetCenter() const { return def->GetCenter(); }
|
|
|
|
|
int GetLineSpacing() const { return def->LineSpacing; }
|
2003-01-06 23:49:43 +00:00
|
|
|
|
|
|
|
|
void SetDefaultGlyph(FontPage *fp);
|
|
|
|
|
|
2003-01-28 00:45:01 +00:00
|
|
|
static const wchar_t DEFAULT_GLYPH;
|
2003-01-05 07:55:31 +00:00
|
|
|
|
2003-01-16 23:22:21 +00:00
|
|
|
static CString GetFontName(CString FileName);
|
2003-01-23 04:25:04 +00:00
|
|
|
/* Remove filenames in 'v' that aren't in the same font as "FileName". */
|
|
|
|
|
static void WeedFontNames(vector<CString> &v, const CString &FileName);
|
2003-01-06 23:49:43 +00:00
|
|
|
|
2003-01-10 02:02:51 +00:00
|
|
|
private:
|
|
|
|
|
/* List of pages and fonts that we use (and are responsible for freeing). */
|
|
|
|
|
vector<FontPage *> pages;
|
|
|
|
|
|
|
|
|
|
/* This is the primary fontpage of this font; font-wide height, center,
|
|
|
|
|
* etc. is pulled from it. (This is one of pages[].) */
|
2003-01-06 23:49:43 +00:00
|
|
|
FontPage *def;
|
2003-01-10 02:02:51 +00:00
|
|
|
|
|
|
|
|
/* Map from characters to glyphs. (Each glyph* is part of one of pages[].) */
|
|
|
|
|
map<longchar,glyph*> m_iCharToGlyph;
|
|
|
|
|
|
|
|
|
|
/* We keep this around only for reloading. */
|
|
|
|
|
CString Chars;
|
|
|
|
|
|
|
|
|
|
void LoadFontPageSettings(FontPageSettings &cfg, IniFile &ini, const CString &TexturePath, const CString &PageName, CString sChars);
|
|
|
|
|
static void GetFontPaths(const CString &sFontOrTextureFilePath,
|
|
|
|
|
CStringArray &TexturePaths, CString &IniPath);
|
|
|
|
|
CString GetPageNameFromFileName(const CString &fn);
|
2002-03-30 20:00:13 +00:00
|
|
|
};
|
2002-11-16 08:07:38 +00:00
|
|
|
|
|
|
|
|
#endif
|