17#ifndef ENGINE_GRAPHICS_GFONT_H_
18#define ENGINE_GRAPHICS_GFONT_H_
28#include "freetype2/ft2build.h"
31#include "freetype2/freetype/freetype.h"
32#include <android/asset_manager.h>
34#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
35#include "freetype2/freetype/freetype.h"
37#if defined(WIN32) || defined(LINUX) || TARGET_OS_OSX
44#include <unordered_map>
72 bool load(
const std::string& fullPath,
int size,
bool isAntialiased =
true,
int dpi = 96);
92 bool loadFont(
const std::string& fontPath,
int size,
bool isAntialiased =
true,
int dpi = 96);
101 void drawText(
const std::string& text,
float x,
float y);
202 bool isloaded =
false;
203 std::string fullpath;
204 bool isantialiased =
false;
206 float fontsize = 0.0f;
207 int characternumlimit = 0;
209 bool iskerning =
false;
211 FT_Library ftlib =
nullptr;
212 FT_Face fontface =
nullptr;
214 float lineheight = 0.0f;
215 float letterspacing = 1.0f;
216 float spacesize = 1.0f;
219 void loadChar(
int charCode);
221 struct CharProperties {
222 float height = 0.0f, width = 0.0f;
223 float topmargin = 0.0f, leftmargin = 0.0f;
224 float advance = 0.0f;
225 float texturewidth = 0.0f, textureheight = 0.0f;
226 float dxleft = 0.0f, dxright = 0.0f, dytop = 0.0f, dybottom = 0.0f;
229 std::unordered_map<int, CharProperties> charproperties;
230 std::unordered_map<int, gTexture*> chartextures;
232 float getKerning(
int c,
int prevC)
const;
233 void resizeVectors(
int num);
234 bool insertData(
const unsigned char* srcData,
int srcWidth,
int srcHeight,
int componentNum,
235 unsigned char* dstData,
int dstWidth,
int dstHeight,
int dstComponentNum,
236 size_t dstFirstX,
size_t dstFirstY)
const;
237 std::wstring s2ws(
const std::string& s)
const;
238 float roundIfRequired(
float val);
Definition gEventHook.h:14
void getVisualBoundsX(const std::string &text, float &xmin, float &xmax)
void onEvent(gEvent &event) override
bool loadFont(const std::string &fontPath, int size, bool isAntialiased=true, int dpi=96)
float getLineHeight() const
bool isAntialised() const
float getStringWidth(const std::string &text)
std::vector< std::string > wrapSentenceByWidth(const std::string &text, float maxWidth, TextAlign align=TextAlign::LEFT)
bool load(const std::string &fullPath, int size, bool isAntialiased=true, int dpi=96)
TextAlign
Definition gFont.h:49
void drawTextVerticallyFlipped(const std::string &text, float x, float y)
Draws the given text vertically flipped at the specified position.
float getStringHeight(const std::string &text)
const std::string & getPath() const
void drawText(const std::string &text, float x, float y)
void drawTextHorizontallyFlipped(const std::string &text, float x, float y)
Draws the given text horizontally flipped at the specified location.