Files
itgmania212121/stepmania/src/Font.h
T

160 lines
3.8 KiB
C++
Raw Normal View History

#ifndef FONT_H
#define FONT_H
/*
-----------------------------------------------------------------------------
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.
Chris Danford
-----------------------------------------------------------------------------
*/
#include "RageTexture.h"
#include "RageUtil.h"
2003-01-03 22:53:22 +00:00
#include "IniFile.h"
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;
2003-01-03 22:53:22 +00:00
/* Texture coordinate rect. */
RectF rect;
};
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;
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
{
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;
map<longchar,int> m_iCharToGlyphNo;
2003-01-04 05:20:40 +00:00
FontPage();
~FontPage();
void Load( FontPageSettings cfg );
2003-01-06 23:49:43 +00:00
/* Page-global properties. */
2003-01-08 02:32:30 +00:00
int height;
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
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);
/* Steal all of a font's pages. */
void MergeFont(Font &f);
void Load(const CString &sFontOrTextureFilePath, CString sChars);
void Unload();
void Reload();
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-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
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;
/* 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);
};
#endif