Skip to content

Instantly share code, notes, and snippets.

@yumetodo
Last active March 22, 2016 13:43
Show Gist options
  • Save yumetodo/480ee94bbe530acc91ce to your computer and use it in GitHub Desktop.
Save yumetodo/480ee94bbe530acc91ce to your computer and use it in GitHub Desktop.
#include <DxLib.h>
#include <string>
#include <codecvt>
#include <vector>
#include <fstream>
int WINAPI WinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, int /*nCmdShow*/) {
//init
DxLib::SetOutApplicationLogValidFlag(FALSE);
DxLib::SetGraphMode(300, 100, 16);
DxLib::ChangeWindowMode(TRUE);
DxLib::SetBackgroundColor(255, 255, 255);
if (DxLib_Init() == -1)return -1;// エラーが起きたら直ちに終了
DxLib::SetDrawScreen(DX_SCREEN_BACK);
DxLib::ClearDrawScreen();
const auto font = DxLib::CreateFontToHandle(L"Segoe UI Symbol", 40, 1);
//print
using namespace std::literals;
const auto str = U"1⃣🇫🇷㊙𠮷🆔🐑"s;
const auto str_u16 = L"1⃣🇫🇷㊙𠮷🆔🐑"s;
DxLib::DrawStringToHandle(0, 0, str_u16.c_str(), DxLib::GetColor(0, 0, 0), font);
DxLib::ScreenFlip();
//get info
std::vector<DRAWCHARINFO> info;
info.resize(str.size());
DxLib::GetDrawStringCharInfoToHandle(&info[0], str_u16.c_str(), str_u16.size(), font);
//write BOM
std::ofstream o;
o.exceptions(std::ios::badbit | std::ios::failbit);
o.open("log.txt");
const char bom[] = { (char)0xef, (char)0xbb, (char)0xbf , '\0' };
o << bom << std::flush;
o.close();
//write info
std::wofstream out;
out.exceptions(std::ios::badbit | std::ios::failbit);
out.open("log.txt", std::ios_base::app);
out.imbue(std::locale(std::locale(""), new std::codecvt_utf8_utf16<wchar_t>()));
using std::endl;
for (auto&& i : info) {
out
<< L"char:" << i.Char << endl
<< L"byte:" << i.Bytes << endl
<< L"size: (" << i.SizeX << ", " << i.SizeY << L')' << endl
<< L"draw_size: (" << i.DrawX << ", " << i.DrawY << L')' << endl;
}
DxLib::WaitKey();
DxLib::WaitKey();
return 0;
}
char:1
byte:2
size: (22, 56)
draw_size: (0, -7)
char:⃣
byte:2
size: (0, 56)
draw_size: (22, -7)
char:🇫
byte:4
size: (17, 56)
draw_size: (22, -7)
char:🇷
byte:4
size: (19, 56)
draw_size: (39, -7)
char:㊙
byte:2
size: (41, 56)
draw_size: (58, -7)
char:𠮷
byte:4
size: (0, 56)
draw_size: (99, -7)
char:🆔
byte:4
size: (40, 56)
draw_size: (99, -7)
char:🐑
byte:4
size: (41, 56)
draw_size: (139, -7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment