Comments (2)
Use nvgCreateFont method to load extra font(.ttf) files.
You don't need to recompile this library to support CJK.
example code :
// Change multibyte to UTF8.
// reference : https://doitnow-man.tistory.com/entry/%EC%9C%88%EB%8F%84%EC%9A%B0-window-%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%B0%8D-%ED%95%9C%EA%B8%80-%EC%B2%98%EB%A6%AC-c
std::string MultiByteToUtf8(std::string multibyte_str)
{
char* pszIn = new char[multibyte_str.length() + 1];
strncpy_s(pszIn, multibyte_str.length() + 1, multibyte_str.c_str(), multibyte_str.length());
std::string resultString;
int nLenOfUni = 0, nLenOfUTF = 0;
wchar_t* uni_wchar = NULL;
char* pszOut = NULL;
// 1. ANSI(multibyte) Length
if ((nLenOfUni = MultiByteToWideChar(CP_ACP, 0, pszIn, (int)strlen(pszIn), NULL, 0)) <= 0)
return "";
uni_wchar = new wchar_t[nLenOfUni + 1];
memset(uni_wchar, 0x00, sizeof(wchar_t) * (nLenOfUni + 1));
// 2. ANSI(multibyte) ---> unicode
nLenOfUni = MultiByteToWideChar(CP_ACP, 0, pszIn, (int)strlen(pszIn), uni_wchar, nLenOfUni);
// 3. utf8 Length
if ((nLenOfUTF = WideCharToMultiByte(CP_UTF8, 0, uni_wchar, nLenOfUni, NULL, 0, NULL, NULL)) <= 0)
{
delete[] uni_wchar;
return "";
}
pszOut = new char[nLenOfUTF + 1];
memset(pszOut, 0, sizeof(char) * (nLenOfUTF + 1));
// 4. unicode ---> utf8
nLenOfUTF = WideCharToMultiByte(CP_UTF8, 0, uni_wchar, nLenOfUni, pszOut, nLenOfUTF, NULL, NULL);
pszOut[nLenOfUTF] = 0;
resultString = pszOut;
delete[] uni_wchar;
delete[] pszOut;
return resultString;
}
class ExampleApplication : public nanogui::Screen {
public:
ExampleApplication() : nanogui::Screen(Eigen::Vector2i(1024, 768), "NanoGUI Test") {
using namespace nanogui;
// 1. Load your ttf file, name it.
nvgCreateFont(mNVGContext, "NanumGothic", "../resources/nanum-gothic/NanumGothic.ttf");
nvgCreateFont(mNVGContext, "NanumGothic-bold", "../resources/nanum-gothic/NanumGothicBold.ttf");
Window *window = new Window(this, "Button demo");
window->setPosition(Vector2i(15, 15));
window->setLayout(new GroupLayout());
/* No need to store a pointer, the data structure will be automatically
freed when the parent window is deleted */
// 2. Use like this.
new Label(window, MultiByteToUtf8("한국어,中國語,日本語,English"), "NanumGothic-bold");
...
};
from nanogui.
Nice, this looks like a handy thing to have an example for in the codebase.
from nanogui.
Related Issues (20)
- How to clone only nanogui and use system-installed libraries? HOT 1
- Unhandled exception at 0x00007FFD22983B29 Microsoft C++ exception: std::runtime_error (Error when loading SCREEN with GLFW)
- about the relationship between objects HOT 1
- std::cerr confusion
- Custom Font Problem (and possibly outdated documentation)
- Can't find nanogui_resources.h HOT 1
- msvc and vcpkg static build compiles, but runtime fails without nanogui.dll
- I want to draw some points in GLCanvas
- Identifier 'gluniform1i' is not defined HOT 2
- cmake error in clion HOT 1
- colorwheel.cpp.obj: too many sections (32966) or colorwheel.cpp.obj: File too big
- Hi! I'm looking for examples of 'stretchy' gui design!?
- How to avoid using 3rdparty libraries under ext, but using system installed libraries?
- TextBox - box is not wide enough for the string value argument HOT 1
- Multiple nanogui::screen HOT 2
- On the issue of window size. HOT 1
- Failed to build on MSYS2 MINGW64 HOT 1
- Preventing blocking during shell interactions
- May I know how to make the textbox support Chinese input? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nanogui.