Beispiel #1
0
wstring
GetWString(const string& str)
{
    // NOTE(Wuxiang): http://en.cppreference.com/w/cpp/locale/codecvt_utf8_utf16
    using CodeOutput = wchar_t;
    using CodeConvert = codecvt_utf8_utf16<CodeOutput>;
    static wstring_convert<CodeConvert> sConverter;
    return sConverter.from_bytes(str);
}
u16string rgx::string_to_ucs2(const std::string& str) {
    static wstring_convert<codecvt_utf8<char16_t, 0x10ffff, std::little_endian>, char16_t> myconv_little_endian;
    static wstring_convert<codecvt_utf8<char16_t>, char16_t> myconv_big_endian;
    if (isLittleEndien()) {
        return myconv_little_endian.from_bytes(str);
    } else {
        return myconv_big_endian.from_bytes(str);
    }
}
string rgx::ucs2_to_string(const std::u16string& str) {
    static wstring_convert<codecvt_utf8<char16_t>, char16_t> myconv;
    return myconv.to_bytes(str);
}
Beispiel #4
0
u16string FSU8ToU16(const string& a_sString)
{
	static wstring_convert<codecvt_utf8_utf16<char16_t>, char16_t> c_cvt_u8_u16;
	return c_cvt_u8_u16.from_bytes(a_sString);
}
Beispiel #5
0
wstring FSAToW(const string& a_sString)
{
	static wstring_convert<codecvt<wchar_t, char, mbstate_t>> c_cvt_a(new codecvt<wchar_t, char, mbstate_t>(""));
	return c_cvt_a.from_bytes(a_sString);
}
Beispiel #6
0
wstring FSU8ToW(const string& a_sString)
{
	static wstring_convert<codecvt_utf8<wchar_t>> c_cvt_u8;
	return c_cvt_u8.from_bytes(a_sString);
}
Beispiel #7
0
string FSU16ToU8(const u16string& a_sString)
{
	static wstring_convert<codecvt_utf8_utf16<char16_t>, char16_t> c_cvt_u8_u16;
	return c_cvt_u8_u16.to_bytes(a_sString);
}
Beispiel #8
0
string FSWToU8(const wstring& a_sString)
{
	static wstring_convert<codecvt_utf8<wchar_t>> c_cvt_u8;
	return c_cvt_u8.to_bytes(a_sString);
}
Beispiel #9
0
int executeCmd(HWND hWnd, HDC hdc, Socket socket, wstring tag, wstring content, Attribute attrs)
{
	enum htmlTag { hr = 0, br = 1, ul = 2, ol = 3, input = 4, table = 5, img = 6, form = 7};
	int cmd;
	HFONT font, oldfont;
	Parser parser;
	int nextLine = 0;
	if (tag.empty())
		return 0;
	
	cmd = getCmdFromHtmlTag(tag);

	switch (cmd)
	{
		case hr:
		{
			Graphics graphics(hdc);
			Pen pen(Color(0, 0, 0));

			// 사진 높이 넘기기
			if (yCur > 40) { y = yCur; yCur = INITY; }
			y += NEWLINE;
			graphics.DrawLine(&pen, 0, y, 8000, y);
			y += NEWLINE;
		}
		case br:
		{
			// 사진 높이 넘기기
			if (yCur > 40) { y = yCur; yCur = INITY; }
			y += NEWLINE;
			return 0;
		}
		case ul:
		{
			//int foundS = 0;
			//int foundE = 0;
			//x += XMOVER;
			//while (1)
			//{
			//	wstring subcontent = L"";
			//	if ((foundS = content.find(L"<li>")) < 0) break;
			//	if ((foundE = content.find(L"</li>")) < 0) break;
			//	subcontent = content.substr(foundS + 4, foundE - (foundS + 4));
			//	wstring combined = L"@. ";
			//	combined.append(subcontent);
			//	TextOutW(hdc, x, y, combined.c_str(), combined.length());
			//	content.erase(0, foundE + 5);
			//	y += YMOVER;
			//}
			//x -= XMOVER;
			return 0;
		}
		case ol:
		{
			//int foundS = 0;
			//int foundE = 0;
			//int i = 1;
			//x += XMOVER;
			//while (1)
			//{
			//	wstring subcontent = L"";
			//	if ((foundS = content.find(L"<li>")) < 0) break;
			//	if ((foundE = content.find(L"</li>")) < 0) break;
			//	subcontent = content.substr(foundS + 4, foundE - (foundS + 4));
			//	wstring combined = std::to_wstring(i);
			//	combined.append(L". ");
			//	combined.append(subcontent);
			//	TextOutW(hdc, x, y, combined.c_str(), combined.length());
			//	content.erase(0, foundE + 5);
			//	y += YMOVER;
			//	i++;
			//}
			//x -= XMOVER;
			return 0;
		}
		case input:
		{
			//			if (htmlTag == L"input")
			//			{
			//				foundS = socket.v_htmlBuf[page].find(L"<");
			//				foundE = socket.v_htmlBuf[page].find(L">");
			//
			//				// < 와 > 를 포함한 substring
			//				htmlContent = socket.v_htmlBuf[page].substr(foundS, foundE - foundS + 1);
			//				inputInfo.value = parser.getInputValue(htmlContent);
			//				inputInfo.type = parser.getInputType(htmlContent);
			//				inputInfo.name = parser.getInputName(htmlContent);
			//				if (inputInfo.type == L"text")
			//					v_inputInfo.push_back(inputInfo);
			//				socket.v_htmlBuf[page].erase(foundS, foundE - foundS + 1);
			//				htmlContent = L"";
			//			}

			//x += XMOVER * 2;
			//if (oneInputInfo.value == L"submit")
			//{
			//	v_inputEdit.push_back(CreateWindow("BUTTON", "Submit", WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER | ES_LEFT, x, y, 100, 30, hWnd, (HMENU)(input_id), g_hinst, NULL));
			//	submitId = input_id;
			//}
			//else
			//	v_inputEdit.push_back(CreateWindow("EDIT", converter.to_bytes(oneInputInfo.value).c_str(), WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER | ES_LEFT, x, y, 200, 30, hWnd, (HMENU)(input_id), g_hinst, NULL));
			//disableWMPaint = true;
			//input_id++;
			//x -= XMOVER * 2;
			return 0;
		}
		case table:
		{
			//int S = 0;
			//int E = 0;
			//int foundS = 0;
			//int foundE = 0;
			//int offset = 10;
			//Graphics graphics(hdc);
			//Pen pen(Color(0, 0, 0));
			//int sub_x = x;
			//int sub_y = y+30;

			//while (1)
			//{
			//	if ((foundS = content.find(L"<tr>")) < 0) break;
			//	if ((foundE = content.find(L"</tr>")) < 0) break;
			//	S = foundS; E = foundE;
			//	wstring subcontent = content.substr(foundS + 4, foundE - (foundS + 4));
			//	
			//	while (1)
			//	{
			//		wstring subsubcontent = L"";
			//		if ((foundS = subcontent.find(L"<th>")) >= 0)
			//		{
			//			foundE = subcontent.find(L"</th>");
			//			subsubcontent = subcontent.substr(foundS + 4, foundE - (foundS + 4));					
			//		}
			//		else if ((foundS = subcontent.find(L"<td>")) >= 0)
			//		{
			//			foundE = subcontent.find(L"</td>");
			//			subsubcontent = subcontent.substr(foundS + 4, foundE - (foundS + 4));
			//		}
			//		else
			//		{
			//			break;
			//		}	

			//		//offset = strlen(subsubcontent.c_str()) * 10;
			//		offset = 80;
			//		//1글자 크기당  x값을 10으로 주자
			//		Rectangle(hdc, sub_x - 5, sub_y - 20, sub_x + offset, sub_y + 20);
			//		
			//		TextOutW(hdc, sub_x, sub_y, subsubcontent.c_str(), subsubcontent.length());
			//		subcontent.erase(foundS, foundE - foundS + 5);

			//		sub_x += offset;
			//	}

			//	//세로로 이동
			//	content.erase(S, E - S + 5);
			//	sub_y = sub_y + 40;
			//	sub_x = x;
			//}
			return 0;
		}
		case img:
		{
			//사진을 서버에게 요청한다.
			if (attrs.img.height == L"")
				attrs.img.height = L"300";
			if (attrs.img.width == L"")
				attrs.img.width = L"300";

			//이미지 요청
			wchar_t newUrl[BUFSIZE];
			int found = 0;
			if ((found = attrs.img.src.find(L"http://")) < 0)
			{
				//파일
				socket.ipAddrs.append(":"); socket.ipAddrs.append(socket.port); socket.ipAddrs.append("/");
				wcscpy(newUrl, L"http://");
				wstring wst(socket.ipAddrs.begin(), socket.ipAddrs.end());
				wcscat(newUrl, wst.c_str());
				wcscat(newUrl, attrs.img.src.c_str());
			}
			else
			{
				//URL로 파일 전송하는 경우
				wcscpy(newUrl, attrs.img.src.c_str());
			}

			int iResult = socket.ClientToServer(newUrl, hWnd, "GET", "", true);
			errorEventHandler(hWnd, iResult);
			if (iResult == -1)
				return 0;

			//받은 이미지 보여주기			
			Imager imager;
			string img = converter.to_bytes(attrs.img.src);

			if ((found = img.find("http://")) >= 0)
			{
				while ((found = img.find("/")) >= 0) img = img.erase(0, found + 1);
			}

			string imgPath = imager.GetExeFileName(img);
			wstring wimgPath = wstring(imgPath.begin(), imgPath.end());
			int width = atoi(converter.to_bytes(attrs.img.width).c_str());
			int height = atoi(converter.to_bytes(attrs.img.height).c_str());
			imager.setImage(hWnd, hdc, wimgPath.c_str(), x, y, width, height);
			x += width;

			//사진 같은 경우는 사진 길이를 기억해서 넘겨줘야한다.
			yCur = y + height;

			return 0;
		}
		case form:
		{
			//if (htmlTag == L"form")
			//{
			//	action = "";  method = "";
			//	foundS = socket.v_htmlBuf[page].find(L"<");
			//	foundE = socket.v_htmlBuf[page].find(L">");
			//
			//	// < 와 > 를 포함한 substring
			//	htmlContent = socket.v_htmlBuf[page].substr(foundS, foundE - foundS + 1);
			//	action = parser.getFormAction(htmlContent);
			//	method = parser.getFormMethod(htmlContent);
			//
			//	socket.v_htmlBuf[page].erase(foundS, foundE - foundS + 1);
			//	foundE = socket.v_htmlBuf[page].find(L"</form>");
			//	socket.v_htmlBuf[page].erase(foundE, 7);
			//	htmlTag = L""; htmlContent = L"";
			//
			//}
			return 0;
		}
		default:
		{
			// 사진 높이 넘기기
			if (yCur > 40) { y = yCur; yCur = INITY; }

			HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE);
			COORD max_size = GetLargestConsoleWindowSize(screen);
			int isBold = 300;

			// 폰트 칼라
			wstring style = attrs.font.style;
			int foundS = style.find(L"color:");
			if (foundS >= 0)
			{
				style = style.erase(foundS, strlen("color:"));
				if (style == L"blue") SetTextColor(hdc, RGB(0, 0, 255));
				else if (style == L"red") SetTextColor(hdc, RGB(255, 0, 0));
				else if (style == L"yellow") SetTextColor(hdc, RGB(255, 255, 0));
				else if (style == L"green") SetTextColor(hdc, RGB(0, 255, 0));
			}

			if (attrs.font.isBold)			isBold = FW_BOLD;
			if (attrs.identity.isCenter)	x = (max_size.X - sizeof(content)) / 2;
			if (attrs.identity.isP || attrs.identity.isCenter || attrs.identity.isAddress || attrs.identity.isPre) { y += NEWLINE; x = INITX; }

			if (attrs.identity.isPre)
			{
				int i;
				vector<string> contents = split(converter.to_bytes(content), '\n');
				for (i = 0; i < contents.size(); i++)
				{
					contents[i].erase(remove(contents[i].begin(), contents[i].end(), '\t'), contents[i].end());
					if (contents[i].empty())
						continue;
					font = CreateFont(attrs.font.size, 0, 0, 0, isBold, attrs.font.isCursive, attrs.font.underscore, 0, 0, 0, 0, 0, 0, L"Times New Roman");
					nextLine = attrs.font.size;
					oldfont = (HFONT)SelectObject(hdc, font);
					TextOutW(hdc, x, y, content.c_str(), content.length());
					SelectObject(hdc, oldfont);
					DeleteObject(font);

					//좌표 계산
					if (parser.isEnglishLetter(content))
						x += content.length() * 7;
					else
						x += content.length() * 18;

					if (contents.size() > 1) y += nextLine;
				}
			}
			else
			{
				if (content.empty())
					return 0;
				font = CreateFont(attrs.font.size, 0, 0, 0, isBold, attrs.font.isCursive, attrs.font.underscore, 0, 0, 0, 0, 0, 0, L"Times New Roman");
				nextLine = attrs.font.size;
				oldfont = (HFONT)SelectObject(hdc, font);			
				TextOutW(hdc, x, y, content.c_str(), content.length());
				SelectObject(hdc, oldfont);
				DeleteObject(font);

				//좌표 계산
				if (parser.isEnglishLetter(content) == true)
					x += content.length() * 7; //영어
				else
					x += content.length() * 18; //한글
			}

			if (attrs.identity.isP || attrs.identity.isCenter || attrs.identity.isAddress || attrs.identity.isPre) { y += nextLine; x = INITX; }
			if (attrs.font.size == 40 || attrs.font.size == 35 || attrs.font.size == 30 || attrs.font.size == 25 || attrs.font.size == 21 || attrs.font.size == 15) { y += nextLine; x = INITX; }
			if (x > 1000) x = INITX;

			SetTextColor(hdc, RGB(0, 0, 0));
			//DeleteObject(font);
			return 0;
		}
	}
}