MCPcopy Create free account
hub / github.com/OpenBoardView/OpenBoardView / load_font

Function load_font

src/openboardview/win32.cpp:65–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63}
64
65std::vector<char> load_font(const std::string &name) {
66 std::vector<char> data;
67 HFONT fontHandle;
68
69 auto u16name = utf8_to_utf16(name);
70
71 fontHandle = CreateFont(0, 0, 0, 0, 0, 0, 0, 0, 0, OUT_TT_ONLY_PRECIS, 0, 0, 0, u16name.c_str());
72 if (!fontHandle) {
73 std::cerr << "CreateFont failed" << std::endl;
74 return data;
75 }
76 HDC hdc = ::CreateCompatibleDC(NULL);
77 if (hdc != NULL) {
78 ::SelectObject(hdc, fontHandle);
79
80 int ncount = ::GetTextFaceW(hdc, 0, nullptr);
81 if (ncount == 0) return data;
82
83 LPWSTR fname = new wchar_t[ncount];
84 ncount = ::GetTextFaceW(hdc, ncount, fname);
85
86 if (!name.empty() &&
87 ::CompareStringEx(NULL, NORM_IGNORECASE, u16name.c_str(), name.size(), fname, ncount - 1, NULL, NULL, 0) !=
88 CSTR_EQUAL) // We didn't get the font we requested
89 return data;
90
91 const size_t size = ::GetFontData(hdc, 0, 0, NULL, 0);
92 if (size == GDI_ERROR) {
93#ifdef ENABLE_SDL2
94 SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Couldn't get \"%s\" font data: %lu", name.c_str(), GetLastError());
95#else
96 std::cout << "Couldn't get \"" << name << "\" font data: " << GetLastError() << std::endl;
97#endif
98 } else if (size > 0) {
99 char *buffer = new char[size];
100 if (::GetFontData(hdc, 0, 0, buffer, size) == size) {
101 data = std::vector<char>(buffer, buffer + size);
102 }
103 delete[] buffer;
104 }
105 ::DeleteDC(hdc);
106 }
107 DeleteObject(fontHandle);
108 return data;
109}
110
111const std::string get_user_dir(const UserDir userdir) {
112 int cdret = 0;

Callers 1

loadMethod · 0.85

Calls 1

utf8_to_utf16Function · 0.85

Tested by

no test coverage detected