Merge remote-tracking branch 'itsRevela/main'
# Conflicts: # .github/workflows/nightly.yml # .gitignore # Minecraft.Client/ChatScreen.cpp # Minecraft.Client/ClientConnection.cpp # Minecraft.Client/Common/Audio/SoundEngine.cpp # Minecraft.Client/Common/Audio/SoundEngine.h # Minecraft.Client/Common/Media/MediaWindows64.arc # Minecraft.Client/Common/UI/IUIScene_HUD.cpp # Minecraft.Client/Common/UI/UIControl_Base.cpp # Minecraft.Client/Common/UI/UIScene_DeathMenu.cpp # Minecraft.Client/Common/UI/UIScene_JoinMenu.cpp # Minecraft.Client/Common/XUI/XUI_Chat.cpp # Minecraft.Client/Common/XUI/XUI_Death.cpp # Minecraft.Client/Font.cpp # Minecraft.Client/Gui.cpp # Minecraft.Client/PendingConnection.cpp # Minecraft.Client/PlayerConnection.cpp # Minecraft.Client/PlayerConnection.h # Minecraft.Client/PlayerList.cpp # Minecraft.Client/Windows64/Network/WinsockNetLayer.cpp # Minecraft.Client/Windows64/Network/WinsockNetLayer.h # Minecraft.Client/Windows64Media/strings.h # Minecraft.Client/cmake/sources/Common.cmake # Minecraft.Server/Console/ServerCliEngine.cpp # Minecraft.Server/Console/commands/whitelist/CliCommandWhitelist.cpp # Minecraft.Server/Windows64/ServerMain.cpp # Minecraft.World/WitherBoss.h # Minecraft.World/cmake/sources/Common.cmake # README.md
This commit is contained in:
+161
-31
@@ -8,6 +8,7 @@
|
||||
#include "../Minecraft.World/net.minecraft.h"
|
||||
#include "../Minecraft.World/StringHelpers.h"
|
||||
#include "../Minecraft.World/Random.h"
|
||||
#include "..\Minecraft.World\ArabicShaping.h"
|
||||
|
||||
Font::Font(Options *options, const wstring& name, Textures* textures, bool enforceUnicode, ResourceLocation *textureLocation, int cols, int rows, int charWidth, int charHeight, unsigned short charMap[]/* = nullptr */) : textures(textures)
|
||||
{
|
||||
@@ -16,7 +17,7 @@ Font::Font(Options *options, const wstring& name, Textures* textures, bool enfor
|
||||
charWidths = new int[charC];
|
||||
|
||||
// 4J - added initialisers
|
||||
memset(charWidths, 0, charC);
|
||||
memset(charWidths, 0, charC * sizeof(int));
|
||||
|
||||
enforceUnicodeSheet = false;
|
||||
bidirectional = false;
|
||||
@@ -26,6 +27,19 @@ Font::Font(Options *options, const wstring& name, Textures* textures, bool enfor
|
||||
m_underline = false;
|
||||
m_strikethrough = false;
|
||||
|
||||
memset(unicodeTexID, 0, sizeof(unicodeTexID));
|
||||
memset(unicodeWidth, 0, sizeof(unicodeWidth));
|
||||
lastBoundTexture = 0;
|
||||
|
||||
// Load unicode glyph sizes
|
||||
FILE *glyphFile = nullptr;
|
||||
fopen_s(&glyphFile, "Common/res/1_2_2/font/glyph_sizes.bin", "rb");
|
||||
if (glyphFile)
|
||||
{
|
||||
fread(unicodeWidth, 1, 65536, glyphFile);
|
||||
fclose(glyphFile);
|
||||
}
|
||||
|
||||
// Set up member variables
|
||||
m_cols = cols;
|
||||
m_rows = rows;
|
||||
@@ -268,7 +282,87 @@ void Font::drawLiteral(const wstring& str, int x, int y, int color)
|
||||
yPos = static_cast<float>(y);
|
||||
wstring cleanStr = sanitize(str);
|
||||
for (size_t i = 0; i < cleanStr.length(); ++i)
|
||||
renderCharacter(cleanStr.at(i));
|
||||
{
|
||||
wchar_t c = cleanStr.at(i);
|
||||
if (isUnicodeGlyphChar(c))
|
||||
{
|
||||
renderUnicodeCharacter(c);
|
||||
textures->bindTexture(m_textureLocation);
|
||||
lastBoundTexture = fontTexture;
|
||||
}
|
||||
else
|
||||
{
|
||||
renderCharacter(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Like sanitize() but skips the shapeArabicText() call - for pre-shaped strings.
|
||||
wstring Font::sanitizePreshaped(const wstring& str)
|
||||
{
|
||||
wstring sb = str;
|
||||
for (unsigned int i = 0; i < sb.length(); i++)
|
||||
{
|
||||
if (CharacterExists(sb[i]))
|
||||
sb[i] = MapCharacter(sb[i]);
|
||||
else if (unicodeWidth[sb[i]] != 0)
|
||||
{
|
||||
// Leave as-is: raw codepoint for glyph page rendering
|
||||
}
|
||||
else
|
||||
{
|
||||
sb[i] = 0;
|
||||
}
|
||||
}
|
||||
return sb;
|
||||
}
|
||||
|
||||
void Font::drawLiteralPreshaped(const wstring& str, int x, int y, int color)
|
||||
{
|
||||
if (str.empty()) return;
|
||||
if ((color & 0xFC000000) == 0) color |= 0xFF000000;
|
||||
textures->bindTexture(m_textureLocation);
|
||||
glColor4f((color >> 16 & 255) / 255.0F, (color >> 8 & 255) / 255.0F, (color & 255) / 255.0F, (color >> 24 & 255) / 255.0F);
|
||||
xPos = static_cast<float>(x);
|
||||
yPos = static_cast<float>(y);
|
||||
wstring cleanStr = sanitizePreshaped(str);
|
||||
for (size_t i = 0; i < cleanStr.length(); ++i)
|
||||
{
|
||||
wchar_t c = cleanStr.at(i);
|
||||
if (isUnicodeGlyphChar(c))
|
||||
{
|
||||
renderUnicodeCharacter(c);
|
||||
textures->bindTexture(m_textureLocation);
|
||||
lastBoundTexture = fontTexture;
|
||||
}
|
||||
else
|
||||
{
|
||||
renderCharacter(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Font::drawShadowLiteralPreshaped(const wstring& str, int x, int y, int color)
|
||||
{
|
||||
int shadowColor = (color & 0xFCFCFC) >> 2 | (color & 0xFF000000);
|
||||
drawLiteralPreshaped(str, x + 1, y + 1, shadowColor);
|
||||
drawLiteralPreshaped(str, x, y, color);
|
||||
}
|
||||
|
||||
int Font::widthPreshaped(const wstring& str)
|
||||
{
|
||||
wstring cleanStr = sanitizePreshaped(str);
|
||||
if (cleanStr.empty()) return 0;
|
||||
int len = 0;
|
||||
for (size_t i = 0; i < cleanStr.length(); ++i)
|
||||
{
|
||||
wchar_t wc = cleanStr.at(i);
|
||||
if (isUnicodeGlyphChar(wc))
|
||||
len += (int)unicodeCharWidth(wc);
|
||||
else
|
||||
len += charWidths[static_cast<unsigned>(wc)];
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
void Font::drawShadowWordWrap(const wstring &str, int x, int y, int w, int color, int h)
|
||||
@@ -358,7 +452,7 @@ void Font::draw(const wstring &str, bool dropShadow, int initialColor)
|
||||
}
|
||||
|
||||
// "noise" for crazy splash screen message
|
||||
if (noise)
|
||||
if (noise && !isUnicodeGlyphChar(c))
|
||||
{
|
||||
int newc;
|
||||
do
|
||||
@@ -368,7 +462,23 @@ void Font::draw(const wstring &str, bool dropShadow, int initialColor)
|
||||
c = newc;
|
||||
}
|
||||
|
||||
addCharacterQuad(c);
|
||||
if (isUnicodeGlyphChar(c))
|
||||
{
|
||||
t->end();
|
||||
// renderUnicodeCharacter uses its own begin/end and relies on glColor
|
||||
glColor4f((currentColor >> 16 & 255) / 255.0F, (currentColor >> 8 & 255) / 255.0F,
|
||||
(currentColor & 255) / 255.0F, (currentColor >> 24 & 255) / 255.0F);
|
||||
renderUnicodeCharacter(c);
|
||||
glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
textures->bindTexture(m_textureLocation);
|
||||
lastBoundTexture = fontTexture;
|
||||
t->begin();
|
||||
t->color(currentColor & 0x00ffffff, (currentColor >> 24) & 255);
|
||||
}
|
||||
else
|
||||
{
|
||||
addCharacterQuad(c);
|
||||
}
|
||||
}
|
||||
|
||||
t->end();
|
||||
@@ -409,11 +519,22 @@ int Font::width(const wstring& str)
|
||||
++i;
|
||||
else
|
||||
{
|
||||
len += charWidths[167];
|
||||
if (isUnicodeGlyphChar(167))
|
||||
len += (int)unicodeCharWidth(167);
|
||||
else
|
||||
len += charWidths[167];
|
||||
if (i + 1 < cleanStr.length())
|
||||
len += charWidths[static_cast<unsigned>(cleanStr[++i])];
|
||||
{
|
||||
wchar_t nextC = cleanStr[++i];
|
||||
if (isUnicodeGlyphChar(nextC))
|
||||
len += (int)unicodeCharWidth(nextC);
|
||||
else if (static_cast<unsigned>(nextC) < static_cast<unsigned>(m_cols * m_rows))
|
||||
len += charWidths[static_cast<unsigned>(nextC)];
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (isUnicodeGlyphChar(c))
|
||||
len += (int)unicodeCharWidth(c);
|
||||
else
|
||||
len += charWidths[c];
|
||||
}
|
||||
@@ -427,13 +548,19 @@ int Font::widthLiteral(const wstring& str)
|
||||
if (cleanStr == L"") return 0;
|
||||
int len = 0;
|
||||
for (size_t i = 0; i < cleanStr.length(); ++i)
|
||||
len += charWidths[static_cast<unsigned>(cleanStr.at(i))];
|
||||
{
|
||||
wchar_t wc = cleanStr.at(i);
|
||||
if (isUnicodeGlyphChar(wc))
|
||||
len += (int)unicodeCharWidth(wc);
|
||||
else
|
||||
len += charWidths[static_cast<unsigned>(wc)];
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
wstring Font::sanitize(const wstring& str)
|
||||
{
|
||||
wstring sb = str;
|
||||
wstring sb = shapeArabicText(str);
|
||||
|
||||
for (unsigned int i = 0; i < sb.length(); i++)
|
||||
{
|
||||
@@ -441,6 +568,10 @@ wstring Font::sanitize(const wstring& str)
|
||||
{
|
||||
sb[i] = MapCharacter(sb[i]);
|
||||
}
|
||||
else if (unicodeWidth[sb[i]] != 0)
|
||||
{
|
||||
// Leave as-is: raw codepoint for glyph page rendering
|
||||
}
|
||||
else
|
||||
{
|
||||
// If this character isn't supported, just show the first character (empty square box character)
|
||||
@@ -684,33 +815,22 @@ void Font::renderFakeCB(IntBuffer *ib)
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
void Font::loadUnicodePage(int page)
|
||||
{
|
||||
wchar_t fileName[25];
|
||||
//String fileName = String.format("/1_2_2/font/glyph_%02X.png", page);
|
||||
swprintf(fileName,25,L"/1_2_2/font/glyph_%02X.png",page);
|
||||
wchar_t fileName[40];
|
||||
swprintf(fileName, 40, L"/1_2_2/font/glyph_%02X.png", page);
|
||||
BufferedImage *image = new BufferedImage(fileName);
|
||||
//try
|
||||
//{
|
||||
// image = ImageIO.read(Textures.class.getResourceAsStream(fileName.toString()));
|
||||
//}
|
||||
//catch (IOException e)
|
||||
//{
|
||||
// throw new RuntimeException(e);
|
||||
//}
|
||||
|
||||
unicodeTexID[page] = textures->getTexture(image);
|
||||
lastBoundTexture = unicodeTexID[page];
|
||||
delete image;
|
||||
}
|
||||
|
||||
void Font::renderUnicodeCharacter(wchar_t c)
|
||||
{
|
||||
if (unicodeWidth[c] == 0)
|
||||
{
|
||||
// System.out.println("no-width char " + c);
|
||||
return;
|
||||
}
|
||||
|
||||
int page = c / 256;
|
||||
|
||||
@@ -722,19 +842,17 @@ void Font::renderUnicodeCharacter(wchar_t c)
|
||||
lastBoundTexture = unicodeTexID[page];
|
||||
}
|
||||
|
||||
// first column with non-trans pixels
|
||||
int firstLeft = unicodeWidth[c] >> 4;
|
||||
// last column with non-trans pixels
|
||||
int firstRight = unicodeWidth[c] & 0xF;
|
||||
|
||||
float left = firstLeft;
|
||||
float right = firstRight + 1;
|
||||
float left = (float)firstLeft;
|
||||
float right = (float)(firstRight + 1);
|
||||
|
||||
float xOff = c % 16 * 16 + left;
|
||||
float yOff = (c & 0xFF) / 16 * 16;
|
||||
float xOff = (c % 16) * 16 + left;
|
||||
float yOff = ((c & 0xFF) / 16) * 16;
|
||||
float width = right - left - .02f;
|
||||
|
||||
Tesselator *t = Tesselator::getInstance();
|
||||
Tesselator *t = Tesselator::getInstance();
|
||||
t->begin(GL_TRIANGLE_STRIP);
|
||||
t->tex(xOff / 256.0F, yOff / 256.0F);
|
||||
t->vertex(xPos, yPos, 0.0f);
|
||||
@@ -748,5 +866,17 @@ void Font::renderUnicodeCharacter(wchar_t c)
|
||||
|
||||
xPos += (right - left) / 2 + 1;
|
||||
}
|
||||
*/
|
||||
|
||||
float Font::unicodeCharWidth(wchar_t c)
|
||||
{
|
||||
if (unicodeWidth[c] == 0) return 0;
|
||||
int firstLeft = unicodeWidth[c] >> 4;
|
||||
int firstRight = unicodeWidth[c] & 0xF;
|
||||
return (firstRight + 1 - firstLeft) / 2.0f + 1;
|
||||
}
|
||||
|
||||
bool Font::isUnicodeGlyphChar(wchar_t c)
|
||||
{
|
||||
return c >= m_cols * m_rows && unicodeWidth[c] != 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user