Files
itgmania212121/stepmania/src/Font.h
T

183 lines
5.0 KiB
C++
Raw Normal View History

2004-05-31 22:42:12 +00:00
/* Font - stores a font, used by BitmapText. */
#ifndef FONT_H
#define FONT_H
2003-11-07 20:55:52 +00:00
#include "RageTextureID.h"
#include "RageUtil.h"
2003-11-07 20:55:52 +00:00
#include "RageTypes.h"
2003-01-06 23:49:43 +00:00
class FontPage;
2003-11-07 20:55:52 +00:00
class RageTexture;
2003-12-22 23:53:41 +00:00
class IniFile;
2003-01-06 23:49:43 +00:00
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,
2003-07-06 05:32:45 +00:00
DefaultWidth,
AdvanceExtraPixels;
2003-01-05 03:32:41 +00:00
float ScaleAllWidthsBy;
2003-10-08 02:54:40 +00:00
CString TextureHints;
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),
2003-07-06 05:32:45 +00:00
AdvanceExtraPixels(1),
2003-10-08 02:54:40 +00:00
ScaleAllWidthsBy(1),
TextureHints("default")
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-07-06 05:32:45 +00:00
void SetTextureCoords(const vector<int> &widths, int AdvanceExtraPixels);
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
2004-05-31 22:42:12 +00:00
/*
* (c) 2001-2004 Glenn Maynard, Chris Danford
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/