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>
73 bool load(
const std::string& fullPath,
int size,
bool isAntialiased =
true,
int dpi = 96);
93 bool loadFont(
const std::string& fontPath,
int size,
bool isAntialiased =
true,
int dpi = 96);
102 void drawText(
const std::string& text,
float x,
float y);
226 bool isloaded =
false;
227 std::string fullpath;
228 bool isantialiased =
false;
230 float fontsize = 0.0f;
231 int characternumlimit = 0;
233 bool iskerning =
false;
235 FT_Library ftlib =
nullptr;
236 FT_Face fontface =
nullptr;
238 float lineheight = 0.0f;
239 float ascender = 0.0f;
240 float descender = 0.0f;
241 float letterspacing = 1.0f;
242 float spacesize = 1.0f;
245 void loadChar(
int charCode);
247 struct CharProperties {
248 float height = 0.0f, width = 0.0f;
249 float topmargin = 0.0f, leftmargin = 0.0f;
250 float advance = 0.0f;
251 float texturewidth = 0.0f, textureheight = 0.0f;
252 float dxleft = 0.0f, dxright = 0.0f, dytop = 0.0f, dybottom = 0.0f;
253 float atlasu0 = 0.0f, atlasv0 = 0.0f, atlasu1 = 0.0f, atlasv1 = 0.0f;
255 bool atlasattempted =
false;
256 bool inatlas =
false;
265 std::vector<unsigned char> pixels;
268 std::unordered_map<int, CharProperties> charproperties;
269 std::unordered_map<int, gTexture*> chartextures;
270 std::vector<AtlasPage> atlaspages;
271 static constexpr int atlaswidth = 1024;
272 static constexpr int atlasheight = 1024;
273 int atlasmaxpages = 2;
274 bool atlasbuilding =
false;
275 std::vector<std::vector<float>> batchvertices;
278 float getKerning(
int c,
int prevC)
const;
279 void resizeVectors(
int num);
280 bool insertData(
const unsigned char* srcData,
int srcWidth,
int srcHeight,
int componentNum,
281 unsigned char* dstData,
int dstWidth,
int dstHeight,
int dstComponentNum,
282 size_t dstFirstX,
size_t dstFirstY)
const;
283 std::wstring s2ws(
const std::string& s)
const;
284 float roundIfRequired(
float val);
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)
float getAscender() const
int getAtlasPageLimit() const
std::vector< std::string > wrapSentenceByWidth(const std::string &text, float maxWidth, TextAlign align=TextAlign::LEFT)
TextRenderMode getTextRenderMode() const
void setAtlasPageLimit(int maxPageCount)
bool load(const std::string &fullPath, int size, bool isAntialiased=true, int dpi=96)
TextAlign
Definition gFont.h:49
@ JUSTIFY
Definition gFont.h:49
@ RIGHT
Definition gFont.h:49
@ LEFT
Definition gFont.h:49
@ CENTER
Definition gFont.h:49
void drawTextVerticallyFlipped(const std::string &text, float x, float y)
Draws the given text vertically flipped at the specified position.
int getAtlasPageCount() const
TextRenderMode
Definition gFont.h:50
@ ATLAS
Definition gFont.h:50
@ GLYPH
Definition gFont.h:50
float getStringHeight(const std::string &text)
const std::string & getPath() const
float getDescender() const
void setTextRenderMode(TextRenderMode renderMode)
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.