#ifndef __FONTUTIL__ #define __FONTUTIL__ #include "fontutil.h" // Remove codepoint duplicates if requested // WARNING: This process could be a bit slow if there text to process is very long int *CodepointRemoveDuplicates(int *codepoints, int codepointCount, int *codepointsResultCount) { int codepointsNoDupsCount = codepointCount; int *codepointsNoDups = (int *)calloc(codepointCount, sizeof(int)); memcpy(codepointsNoDups, codepoints, codepointCount*sizeof(int)); // Remove duplicates for (int i = 0; i < codepointsNoDupsCount; i++) { for (int j = i + 1; j < codepointsNoDupsCount; j++) { if (codepointsNoDups[i] == codepointsNoDups[j]) { for (int k = j; k < codepointsNoDupsCount; k++) codepointsNoDups[k] = codepointsNoDups[k + 1]; codepointsNoDupsCount--; j--; } } } // NOTE: The size of codepointsNoDups is the same as original array but // only required positions are filled (codepointsNoDupsCount) *codepointsResultCount = codepointsNoDupsCount; return codepointsNoDups; } // 한글 폰트를 그리는데 필요한 글자만 전체 문자열에서 가지고 온 후에, 필요한 글자만 폰트로 로딩한다. Font GetFont(std::vector _texts) { std::string totalText; // for (int i = 0; i < text.size();i++) for (unsigned int i = 0; i < _texts.size();i++) { totalText += _texts[i].c_str(); } // Get codepoints from text int codepointCount = 0; int *codepoints = LoadCodepoints(totalText.c_str(), &codepointCount); // Removed duplicate codepoints to generate smaller font atlas int codepointsNoDupsCount = 0; int *codepointsNoDups = CodepointRemoveDuplicates(codepoints, codepointCount, &codepointsNoDupsCount); UnloadCodepoints(codepoints); Font _font = LoadFontEx("Assets/Cafe24Ohsquare.ttf", 36, codepointsNoDups, codepointsNoDupsCount) ; // Set bilinear scale filter for better font scaling SetTextureFilter(_font.texture, TEXTURE_FILTER_BILINEAR); // Free codepoints, atlas has already been generated free(codepointsNoDups); return _font; } // 폰트 파일을 지정할 수 있는 함수 Font GetFont(std::vector _texts, char* _fontFile) { std::string totalText; // for (int i = 0; i < text.size();i++) for (unsigned int i = 0; i < _texts.size();i++) { totalText += _texts[i].c_str(); } // Get codepoints from text int codepointCount = 0; int *codepoints = LoadCodepoints(totalText.c_str(), &codepointCount); // Removed duplicate codepoints to generate smaller font atlas int codepointsNoDupsCount = 0; int *codepointsNoDups = CodepointRemoveDuplicates(codepoints, codepointCount, &codepointsNoDupsCount); UnloadCodepoints(codepoints); Font _font = LoadFontEx(_fontFile, 36, codepointsNoDups, codepointsNoDupsCount) ; // Set bilinear scale filter for better font scaling SetTextureFilter(_font.texture, TEXTURE_FILTER_BILINEAR); // Free codepoints, atlas has already been generated free(codepointsNoDups); return _font; } #endif