SDXFrameWork  0.13
SDXFrameWork
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
Public Member Functions | List of all members
SDX::Font Class Reference

TrueTypeFontとBMPFontをまとめて扱うクラス. More...

#include <Font.h>

Inherits SDX::IFont.

Public Member Functions

 Font (const char *フォント名, int 大きさ, int 行間=0, bool 高品質レンダリングフラグ=true)
 コンストラクタ
 
bool Load (const char *フォント名, int 大きさ, int 行間=0, bool 高品質レンダリングフラグ=true)
 フォントを作成する. More...
 
bool Release () const
 フォントハンドルをメモリから開放する. More...
 
TTF_Font * GetHandle () const
 フォントのハンドルを取得. More...
 
Image MakeImage (Color 文字色, bool 反転フラグ, const VariadicStream &描画する文字列) const
 FontからImageを生成. More...
 
void SetSize (int 大きさ, int 行間=0)
 フォントの行間を再指定する. More...
 
bool MakeBMPFont (const std::string テキストファイル名)
 BMPフォントデータを生成する. More...
 
bool LoadBMPFont (const Image &BMPフォント, const std::string テキストファイル名)
 MakeBMPFontで生成したBMPフォントデータを読み込む. More...
 
int GetSize () const
 大きさを取得. More...
 
int GetDrawStringWidth (const VariadicStream &幅を計算する文字列) const
 描画時の幅を取得. More...
 
bool Draw (const Point &座標, const Color &描画色, const VariadicStream &描画する文字列, bool 反転フラグ=false) const override
 文字を描画. More...
 
bool DrawShadow (const Point &座標, Color 表色, Color 影色, const VariadicStream &描画する文字列) const
 文字を影付きで描画. More...
 
bool DrawRotate (const Point &座標, double 拡大率, double 角度, const Color &描画色, const VariadicStream &描画する文字列, bool 反転フラグ=false) const override
 文字を回転して描画. More...
 
bool DrawExtend (const Point &座標, double X拡大率, double Y拡大率, const Color &描画色, const VariadicStream &描画する文字列, bool 反転フラグ=false) const override
 拡大率を指定して文字を描画. More...
 
void SetImage (const std::string &文字, Image *対応画像)
 指定した文字に対応するImageを設定. More...
 
void SetImageS (const std::string &文字列, ImagePack *対応画像, int 登録数)
 指定した文字から連続してに対応するImageをまとめて設定. More...
 

Detailed Description

TrueTypeFontとBMPFontをまとめて扱うクラス.

毎回レンダリングせず、ハッシュマップにImageを格納する 一度も表示していない文字が必要になった場合生成し以後使いまわす

Todo:
高さが違う文字が混ざった場合の仕様が未定、現状上揃え
//Copyright © 2014 SDXFramework
//[License]GNU Affero General Public License, version 3
//[Contact]http://sourceforge.jp/projects/dxframework/
//フォントを作成して文字列を描画する
bool SampleFont()
{
using namespace SDX;
System::Initialise("sample", 640, 480);
//フォントの初期化
Font fontA(SystemFont::Gothic, 9, 4,false);
Font fontB(SystemFont::Mincho, 20, 4, true);
//BMPフォントを生成したり読み込む
//事前にBMPフォントを作っておくと、Android等で読み込みが早い
fontA.MakeBMPFont("data/jyouyoukannji.txt");
Image bmpFont("data/bmpfont.png");
fontA.LoadBMPFont(bmpFont, "data/jyouyoukannji.txt");
//追加BMPフォントの登録
ImagePack bmpNumber("data/number.png",10,10,1);
ImagePack bmpFont2("data/font.png", 30, 10, 3);
fontA.SetImageS("0", &bmpNumber,10);
fontA.SetImageS("a", &bmpFont2, 26);
fontA.SetImageS("A", &bmpFont2, 26);
fontA.SetImage("×", bmpFont2[26]);
fontA.SetImage("□", bmpFont2[27]);
fontA.SetImage("○", bmpFont2[28]);
fontA.SetImage("☆", bmpFont2[29]);
double angle = 0;
while (System::Update())
{
angle += 0.02;
fontA.Draw({ 10 , 10 }, Color::White, "Hello○\nこん☆にちは\n今日は1234");
fontB.Draw({ 10 , 200 }, Color::Blue, "Hello○\nこん☆にちは\n今日は1234");
fontA.DrawRotate({ 300, 100 }, 1, angle, Color::White, false, "文字の回転□\nてすと1234×");
fontB.DrawRotate({ 300, 200 }, 1, angle, Color::White, false, "文字の回転□\nてすと1234×");
if (Input::key.Return.on){ break;}//Enterで終了
}
return true;
}

Member Function Documentation

bool SDX::Font::Load ( const char *  フォント名,
int  大きさ,
int  行間 = 0,
bool  高品質レンダリングフラグ = true 
)
inline

フォントを作成する.

行間は0の場合、改行後の文字が上下くっつく。
BMPフォント専用にしたい場合、SetSizeを使うと良い

bool SDX::Font::Release ( ) const
inline

フォントハンドルをメモリから開放する.

TTF_Font* SDX::Font::GetHandle ( ) const
inline

フォントのハンドルを取得.

Image SDX::Font::MakeImage ( Color  文字色,
bool  反転フラグ,
const VariadicStream 描画する文字列 
) const
inline

FontからImageを生成.

void SDX::Font::SetSize ( int  大きさ,
int  行間 = 0 
)
inline

フォントの行間を再指定する.

Loadしたフォントの大きさが変化するわけでは無い
BMPフォント専用にしたい場合、Loadでは無くこっちが良い

bool SDX::Font::MakeBMPFont ( const std::string  テキストファイル名)
inline

BMPフォントデータを生成する.

テキストファイルには出力したい文字を一行で入力します
pngに変換したい場合、生成したBMPの黒の箇所を透明にして下さい
等幅フォントのみ対応

bool SDX::Font::LoadBMPFont ( const Image BMPフォント,
const std::string  テキストファイル名 
)
inline

MakeBMPFontで生成したBMPフォントデータを読み込む.

テキストファイルはMakeBMPFontに使った物と同じ物を使用して下さい

int SDX::Font::GetSize ( ) const
inline

大きさを取得.

int SDX::Font::GetDrawStringWidth ( const VariadicStream 幅を計算する文字列) const
inline

描画時の幅を取得.

bool SDX::Font::Draw ( const Point 座標,
const Color 描画色,
const VariadicStream 描画する文字列,
bool  反転フラグ = false 
) const
inlineoverridevirtual

文字を描画.

Todo:
反転描画無効

Implements SDX::IFont.

bool SDX::Font::DrawShadow ( const Point 座標,
Color  表色,
Color  影色,
const VariadicStream 描画する文字列 
) const
inline

文字を影付きで描画.

bool SDX::Font::DrawRotate ( const Point 座標,
double  拡大率,
double  角度,
const Color 描画色,
const VariadicStream 描画する文字列,
bool  反転フラグ = false 
) const
inlineoverridevirtual

文字を回転して描画.

Todo:
反転描画無効

Implements SDX::IFont.

bool SDX::Font::DrawExtend ( const Point 座標,
double  X拡大率,
double  Y拡大率,
const Color 描画色,
const VariadicStream 描画する文字列,
bool  反転フラグ = false 
) const
inlineoverridevirtual

拡大率を指定して文字を描画.

Todo:
反転描画無効

Implements SDX::IFont.

void SDX::Font::SetImage ( const std::string &  文字,
Image 対応画像 
)
inline

指定した文字に対応するImageを設定.

文字列が2文字以上なら2文字目以降は無視

void SDX::Font::SetImageS ( const std::string &  文字列,
ImagePack 対応画像,
int  登録数 
)
inline

指定した文字から連続してに対応するImageをまとめて設定.

例えば文字列="0"で登録数=10なら0~9までを登録 アルファベットや数字用