2V0-g: port the .fnt font pipeline over a FreeType GDI emulation

CGraphicText, CGraphicFontTexture and CGraphicDib are the 40250 bodies
verbatim; CGraphicTextInstance is verbatim except that its D3D draws become
UI render commands (one image quad per glyph, Bar for cursor/underline).

- platform/Win32Gdi.cpp: the GDI subset those files call, over vendored
  FreeType 2.13.3, following GDI's LOGFONT cell height, win metrics and gasp
  rules; system font lookup with substitute and CJK fallback faces
- Win32Crt: MultiByteToWideChar / WideCharToMultiByte (UTF-8 and 1252 by
  hand, other code pages through iconv)
- CGraphicImageTexture memory textures: glyph pages reach Godot as
  "mem:<id>@<revision>"; Metin2PythonHost.memory_texture + Canvas cache
- Util.cpp code page / font face table, SetDefaultCodePage at boot,
  DefaultFont_* block, fnt resource type, GetMaxTextureWidth/Height
- TextTag, StringCodec, Arabic, Vietnamese copied from 40250
- tests: port.text (Tahoma 12 metrics, alignment, CP949), port.app_loop
  and python_host_test.gd now check glyph quads instead of text commands

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-09-23 14:17:25 +09:00
co-authored by Claude Opus 5.5
parent 141206cb69
commit afe63bfa61
272 changed files with 137097 additions and 316 deletions
+209
View File
@@ -0,0 +1,209 @@
#include "StdAfx.h"
#include "TextTag.h"
int GetTextTag(const wchar_t * src, int maxLen, int & tagLen, std::wstring & extraInfo)
{
tagLen = 1;
if (maxLen < 2 || *src != L'|')
return TEXT_TAG_PLAIN;
const wchar_t * cur = ++src;
if (*cur == L'c') // color
{
if (maxLen < 10)
return TEXT_TAG_PLAIN;
tagLen = 10;
extraInfo.assign(++cur, 8);
return TEXT_TAG_COLOR;
}
else if (*cur == L'|') // ||는 |로 표시한다.
{
tagLen = 2;
return TEXT_TAG_TAG;
}
else if (*cur == L'r') // restore color
{
tagLen = 2;
return TEXT_TAG_RESTORE_COLOR;
}
else if (*cur == L'H') // hyperlink |Hitem:10000:0:0:0:0|h[이름]|h
{
tagLen = 2;
return TEXT_TAG_HYPERLINK_START;
}
else if (*cur == L'h') // end of hyperlink
{
tagLen = 2;
return TEXT_TAG_HYPERLINK_END;
}
return TEXT_TAG_PLAIN;
}
std::wstring GetTextTagOutputString(const wchar_t * src, int src_len)
{
int len;
std::wstring dst;
std::wstring extraInfo;
int output_len = 0;
int hyperlinkStep = 0;
for (int i = 0; i < src_len; )
{
int tag = GetTextTag(&src[i], src_len - i, len, extraInfo);
if (tag == TEXT_TAG_PLAIN || tag == TEXT_TAG_TAG)
{
if (hyperlinkStep == 0)
{
++output_len;
dst += src[i];
}
}
else if (tag == TEXT_TAG_HYPERLINK_START)
hyperlinkStep = 1;
else if (tag == TEXT_TAG_HYPERLINK_END)
hyperlinkStep = 0;
i += len;
}
return dst;
}
int GetTextTagInternalPosFromRenderPos(const wchar_t * src, int src_len, int offset)
{
int len;
std::wstring dst;
std::wstring extraInfo;
int output_len = 0;
int hyperlinkStep = 0;
bool color_tag = false;
int internal_offset = 0;
for (int i = 0; i < src_len; )
{
int tag = GetTextTag(&src[i], src_len - i, len, extraInfo);
if (tag == TEXT_TAG_COLOR)
{
color_tag = true;
internal_offset = i;
}
else if (tag == TEXT_TAG_RESTORE_COLOR)
{
color_tag = false;
}
else if (tag == TEXT_TAG_PLAIN || tag == TEXT_TAG_TAG)
{
if (hyperlinkStep == 0)
{
if (!color_tag)
internal_offset = i;
if (offset <= output_len)
return internal_offset;
++output_len;
dst += src[i];
}
}
else if (tag == TEXT_TAG_HYPERLINK_START)
hyperlinkStep = 1;
else if (tag == TEXT_TAG_HYPERLINK_END)
hyperlinkStep = 0;
i += len;
}
return internal_offset;
}
int GetTextTagOutputLen(const wchar_t * src, int src_len)
{
int len;
std::wstring extraInfo;
int output_len = 0;
int hyperlinkStep = 0;
for (int i = 0; i < src_len; )
{
int tag = GetTextTag(&src[i], src_len - i, len, extraInfo);
if (tag == TEXT_TAG_PLAIN || tag == TEXT_TAG_TAG)
{
if (hyperlinkStep == 0)
++output_len;
}
else if (tag == TEXT_TAG_HYPERLINK_START)
hyperlinkStep = 1;
else if (tag == TEXT_TAG_HYPERLINK_END)
hyperlinkStep = 0;
i += len;
}
return output_len;
}
int FindColorTagStartPosition(const wchar_t * src, int src_len)
{
if (src_len < 2)
return 0;
const wchar_t * cur = src;
// |r의 경우
if (*cur == L'r' && *(cur - 1) == L'|')
{
int len = src_len;
// ||r은 무시
if (len >= 2 && *(cur - 2) == L'|')
return 1;
cur -= 2;
len -= 2;
// |c까지 찾아서 |위치까지 리턴한다.
while (len > 1) // 최소 2자를 검사해야 된다.
{
if (*cur == L'c' && *(cur - 1) == L'|')
return (src - cur) + 1;
--cur;
--len;
}
return (src_len); // 못찾으면 전부;;
}
// ||의 경우
else if (*cur == L'|' && *(cur - 1) == L'|')
return 1;
return 0;
}
int FindColorTagEndPosition(const wchar_t * src, int src_len)
{
const wchar_t * cur = src;
if (src_len >= 4 && *cur == L'|' && *(cur + 1) == L'c')
{
int left = src_len - 2;
cur += 2;
while (left > 1)
{
if (*cur == L'|' && *(cur + 1) == L'r')
return (cur - src) + 1;
--left;
++cur;
}
}
else if (src_len >= 2 && *cur == L'|' && *(cur + 1) == L'|')
return 1;
return 0;
}
+17
View File
@@ -0,0 +1,17 @@
#pragma once // PORT: 40250 TextTag.h has no include guard; the header gate includes every header twice.
enum
{
TEXT_TAG_PLAIN,
TEXT_TAG_TAG, // ||
TEXT_TAG_COLOR, // |cffffffff
TEXT_TAG_HYPERLINK_START, // |H
TEXT_TAG_HYPERLINK_END, // |h ex) |Hitem:1234:1:1:1|h
TEXT_TAG_RESTORE_COLOR,
};
extern int GetTextTag(const wchar_t * src, int maxLen, int & tagLen, std::wstring & extraInfo);
extern std::wstring GetTextTagOutputString(const wchar_t * src, int src_len);
extern int GetTextTagOutputLen(const wchar_t * src, int len);
extern int FindColorTagEndPosition(const wchar_t * src, int src_len);
extern int FindColorTagStartPosition(const wchar_t * src, int src_len);
extern int GetTextTagInternalPosFromRenderPos(const wchar_t * src, int src_len, int offset);