git subrepo clone --force https://github.com/WerWolv/libtesla Source/sys-clk-OC/overlay/lib/tesla
subrepo: subdir: "Source/sys-clk-OC/overlay/lib/tesla" merged: "930ce85" upstream: origin: "https://github.com/WerWolv/libtesla" branch: "master" commit: "930ce85" git-subrepo: version: "0.4.3" origin: "https://github.com/Homebrew/brew" commit: "7a14ae618"
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
[subrepo]
|
[subrepo]
|
||||||
remote = https://github.com/WerWolv/libtesla
|
remote = https://github.com/WerWolv/libtesla
|
||||||
branch = master
|
branch = master
|
||||||
commit = a5ce77d14f144a24c21684128ae79ef1e808734c
|
commit = 930ce85a1718e0724c146dd8dbb78d7483711231
|
||||||
parent = d518b4937cef7042fd6697babcf40351b1e5f1e9
|
parent = 503c6ff31ea2042f0acb5b14b38b7f982c5c10a8
|
||||||
method = merge
|
method = merge
|
||||||
cmdver = 0.4.3
|
cmdver = 0.4.3
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ CFLAGS := -g -Wall -O2 -ffunction-sections \
|
|||||||
|
|
||||||
CFLAGS += $(INCLUDE) -D__SWITCH__
|
CFLAGS += $(INCLUDE) -D__SWITCH__
|
||||||
|
|
||||||
CXXFLAGS := $(CFLAGS) -fno-exceptions -std=c++17
|
CXXFLAGS := $(CFLAGS) -fno-exceptions -std=c++20
|
||||||
|
|
||||||
ASFLAGS := -g $(ARCH)
|
ASFLAGS := -g $(ARCH)
|
||||||
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
|
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
|
||||||
|
|||||||
@@ -765,6 +765,17 @@ namespace tsl {
|
|||||||
s32 currX = x;
|
s32 currX = x;
|
||||||
s32 currY = y;
|
s32 currY = y;
|
||||||
|
|
||||||
|
struct Glyph {
|
||||||
|
stbtt_fontinfo *currFont;
|
||||||
|
float currFontSize;
|
||||||
|
int bounds[4];
|
||||||
|
int xAdvance;
|
||||||
|
u8 *glyphBmp;
|
||||||
|
int width, height;
|
||||||
|
};
|
||||||
|
|
||||||
|
static std::unordered_map<u64, Glyph> s_glyphCache;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (maxWidth > 0 && maxWidth < (currX - x))
|
if (maxWidth > 0 && maxWidth < (currX - x))
|
||||||
break;
|
break;
|
||||||
@@ -777,24 +788,6 @@ namespace tsl {
|
|||||||
|
|
||||||
string += codepointWidth;
|
string += codepointWidth;
|
||||||
|
|
||||||
stbtt_fontinfo *currFont = nullptr;
|
|
||||||
|
|
||||||
if (stbtt_FindGlyphIndex(&this->m_extFont, currCharacter))
|
|
||||||
currFont = &this->m_extFont;
|
|
||||||
else if(this->m_hasLocalFont && stbtt_FindGlyphIndex(&this->m_stdFont, currCharacter)==0)
|
|
||||||
currFont = &this->m_localFont;
|
|
||||||
else
|
|
||||||
currFont = &this->m_stdFont;
|
|
||||||
|
|
||||||
float currFontSize = stbtt_ScaleForPixelHeight(currFont, fontSize);
|
|
||||||
|
|
||||||
int bounds[4] = { 0 };
|
|
||||||
stbtt_GetCodepointBitmapBoxSubpixel(currFont, currCharacter, currFontSize, currFontSize,
|
|
||||||
0, 0, &bounds[0], &bounds[1], &bounds[2], &bounds[3]);
|
|
||||||
|
|
||||||
int xAdvance = 0, yAdvance = 0;
|
|
||||||
stbtt_GetCodepointHMetrics(currFont, monospace ? 'W' : currCharacter, &xAdvance, &yAdvance);
|
|
||||||
|
|
||||||
if (currCharacter == '\n') {
|
if (currCharacter == '\n') {
|
||||||
maxX = std::max(currX, maxX);
|
maxX = std::max(currX, maxX);
|
||||||
|
|
||||||
@@ -804,10 +797,56 @@ namespace tsl {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!std::iswspace(currCharacter) && fontSize > 0 && color.a != 0x0)
|
u64 key = (static_cast<u64>(currCharacter) << 32) | static_cast<u64>(std::bit_cast<u32>(fontSize));
|
||||||
this->drawGlyph(currCharacter, currX + bounds[0], currY + bounds[1], color, currFont, currFontSize);
|
|
||||||
|
|
||||||
currX += static_cast<s32>(xAdvance * currFontSize);
|
Glyph *glyph = nullptr;
|
||||||
|
|
||||||
|
auto it = s_glyphCache.find(key);
|
||||||
|
if (it == s_glyphCache.end()) {
|
||||||
|
/* Cache glyph */
|
||||||
|
glyph = &s_glyphCache.emplace(key, Glyph()).first->second;
|
||||||
|
|
||||||
|
if (stbtt_FindGlyphIndex(&this->m_extFont, currCharacter))
|
||||||
|
glyph->currFont = &this->m_extFont;
|
||||||
|
else if(this->m_hasLocalFont && stbtt_FindGlyphIndex(&this->m_stdFont, currCharacter)==0)
|
||||||
|
glyph->currFont = &this->m_localFont;
|
||||||
|
else
|
||||||
|
glyph->currFont = &this->m_stdFont;
|
||||||
|
|
||||||
|
glyph->currFontSize = stbtt_ScaleForPixelHeight(glyph->currFont, fontSize);
|
||||||
|
|
||||||
|
stbtt_GetCodepointBitmapBoxSubpixel(glyph->currFont, currCharacter, glyph->currFontSize, glyph->currFontSize,
|
||||||
|
0, 0, &glyph->bounds[0], &glyph->bounds[1], &glyph->bounds[2], &glyph->bounds[3]);
|
||||||
|
|
||||||
|
int yAdvance = 0;
|
||||||
|
stbtt_GetCodepointHMetrics(glyph->currFont, monospace ? 'W' : currCharacter, &glyph->xAdvance, &yAdvance);
|
||||||
|
|
||||||
|
glyph->glyphBmp = stbtt_GetCodepointBitmap(glyph->currFont, glyph->currFontSize, glyph->currFontSize, currCharacter, &glyph->width, &glyph->height, nullptr, nullptr);
|
||||||
|
} else {
|
||||||
|
/* Use cached glyph */
|
||||||
|
glyph = &it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (glyph->glyphBmp != nullptr && !std::iswspace(currCharacter) && fontSize > 0 && color.a != 0x0) {
|
||||||
|
|
||||||
|
auto x = currX + glyph->bounds[0];
|
||||||
|
auto y = currY + glyph->bounds[1];
|
||||||
|
for (s32 bmpY = 0; bmpY < glyph->height; bmpY++) {
|
||||||
|
for (s32 bmpX = 0; bmpX < glyph->width; bmpX++) {
|
||||||
|
auto bmpColor = glyph->glyphBmp[glyph->width * bmpY + bmpX] >> 4;
|
||||||
|
if (bmpColor == 0xF) {
|
||||||
|
this->setPixel(x + bmpX, y + bmpY, color);
|
||||||
|
} else if (bmpColor != 0x0) {
|
||||||
|
Color tmpColor = color;
|
||||||
|
tmpColor.a = bmpColor * (float(tmpColor.a) / 0xF);
|
||||||
|
this->setPixelBlendDst(x + bmpX, y + bmpY, tmpColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
currX += static_cast<s32>(glyph->xAdvance * glyph->currFontSize);
|
||||||
|
|
||||||
} while (*string != '\0');
|
} while (*string != '\0');
|
||||||
|
|
||||||
@@ -1127,36 +1166,6 @@ namespace tsl {
|
|||||||
|
|
||||||
this->m_currentFramebuffer = nullptr;
|
this->m_currentFramebuffer = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Draws a single font glyph
|
|
||||||
*
|
|
||||||
* @param codepoint Unicode codepoint to draw
|
|
||||||
* @param x X pos
|
|
||||||
* @param y Y pos
|
|
||||||
* @param color Color
|
|
||||||
* @param font STB Font to use
|
|
||||||
* @param fontSize Font size
|
|
||||||
*/
|
|
||||||
inline void drawGlyph(s32 codepoint, s32 x, s32 y, Color color, stbtt_fontinfo *font, float fontSize) {
|
|
||||||
int width = 10, height = 10;
|
|
||||||
|
|
||||||
u8 *glyphBmp = stbtt_GetCodepointBitmap(font, fontSize, fontSize, codepoint, &width, &height, nullptr, nullptr);
|
|
||||||
|
|
||||||
if (glyphBmp == nullptr)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (s32 bmpY = 0; bmpY < height; bmpY++) {
|
|
||||||
for (s32 bmpX = 0; bmpX < width; bmpX++) {
|
|
||||||
Color tmpColor = color;
|
|
||||||
tmpColor.a = (glyphBmp[width * bmpY + bmpX] >> 4) * (float(tmpColor.a) / 0xF);
|
|
||||||
this->setPixelBlendDst(x + bmpX, y + bmpY, tmpColor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::free(glyphBmp);
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user