Crafter.Graphics/interfaces/Crafter.Graphics-RenderingElement2D.cppm

449 lines
24 KiB
Text
Raw Permalink Normal View History

2026-03-09 20:10:19 +01:00
/*
Crafter®.Graphics
Copyright (C) 2026 Catcrafts®
catcrafts.net
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License version 3.0 as published by the Free Software Foundation;
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
module;
#include "../lib/stb_truetype.h"
export module Crafter.Graphics:RenderingElement2D;
2026-03-10 19:03:39 +01:00
import Crafter.Asset;
2026-03-09 20:10:19 +01:00
import std;
import :Transform2D;
2026-03-10 22:32:50 +01:00
import :RenderingElement2DBase;
2026-03-09 20:10:19 +01:00
import :Font;
import :Types;
import :Window;
export namespace Crafter {
2026-03-31 15:22:55 +02:00
template<typename T, bool Scaling, bool Owning, bool Rotating, std::uint8_t Alignment = 0, std::uint8_t Frames = 1> requires ((!Rotating || Scaling) && (!Owning || Scaling))
2026-04-01 18:43:18 +02:00
struct RenderingElement2D : RenderingElement2DBase<T, Frames>, ScalingBase<T, Scaling, Owning, Alignment>, RotatingBase<Rotating> {
2026-03-09 20:10:19 +01:00
RenderingElement2D() = default;
2026-03-31 15:22:55 +02:00
RenderingElement2D(Anchor2D anchor, OpaqueType opaque) : RenderingElement2DBase<T, Frames>(anchor, opaque) {
2026-03-09 20:10:19 +01:00
}
2026-03-31 15:22:55 +02:00
RenderingElement2D(Anchor2D anchor, OpaqueType opaque, std::uint32_t rotation) requires(Rotating) : RenderingElement2DBase<T, Frames>(anchor, opaque), RotatingBase<Rotating>(rotation) {
2026-03-09 20:10:19 +01:00
}
2026-04-01 18:43:18 +02:00
RenderingElement2D(Anchor2D anchor, OpaqueType opaque, std::uint32_t bufferWidth, std::uint32_t bufferHeight, Vector<T, 4, Alignment>* scalingBuffer) requires(Scaling && !Owning) : RenderingElement2DBase<T, Frames>(anchor, opaque), ScalingBase<T, Scaling, Owning, Alignment>(bufferWidth, bufferHeight, scalingBuffer) {
2026-03-09 20:10:19 +01:00
}
2026-04-01 18:43:18 +02:00
RenderingElement2D(Anchor2D anchor, OpaqueType opaque, std::uint32_t bufferWidth, std::uint32_t bufferHeight, Vector<T, 4, Alignment>* scalingBuffer, std::uint32_t rotation) requires(Scaling && !Owning && Rotating) : RenderingElement2DBase<T, Frames>(anchor, opaque), ScalingBase<T, Scaling, Owning, Alignment>(bufferWidth, bufferHeight, scalingBuffer), RotatingBase<Rotating>(rotation) {
2026-03-09 20:10:19 +01:00
}
2026-04-01 18:43:18 +02:00
RenderingElement2D(Anchor2D anchor, OpaqueType opaque, std::uint32_t bufferWidth, std::uint32_t bufferHeight) requires(Owning) : RenderingElement2DBase<T, Frames>(anchor, opaque), ScalingBase<T, Scaling, Owning, Alignment>(bufferWidth, bufferHeight) {
2026-03-09 20:10:19 +01:00
}
2026-04-01 18:43:18 +02:00
RenderingElement2D(Anchor2D anchor, OpaqueType opaque, std::uint32_t bufferWidth, std::uint32_t bufferHeight, std::uint32_t rotation) requires(Owning && Rotating) : RenderingElement2DBase<T, Frames>(anchor, opaque), ScalingBase<T, Scaling, Owning, Alignment>(bufferWidth, bufferHeight) , RotatingBase<Rotating>(rotation) {
2026-03-09 20:10:19 +01:00
2026-03-10 19:03:39 +01:00
}
2026-04-01 18:43:18 +02:00
RenderingElement2D(Anchor2D anchor, TextureAsset<Vector<T, 4, Alignment>>& texture) requires(!Owning && Scaling) : RenderingElement2DBase<T, Frames>(anchor, texture.opaque), ScalingBase<T, Scaling, Owning, Alignment>(texture.pixels.data(), texture.sizeX, texture.sizeY) {
2026-03-10 19:03:39 +01:00
}
2026-04-01 18:43:18 +02:00
RenderingElement2D(Anchor2D anchor, TextureAsset<Vector<T, 4, Alignment>>& texture, std::uint32_t rotation) requires(!Owning && Scaling && Rotating) : RenderingElement2DBase<T, Frames>(anchor, texture.opaque), ScalingBase<T, Scaling, Owning, Alignment>(texture.pixels.data(), texture.sizeX, texture.sizeY), RotatingBase<Rotating>(rotation) {
2026-03-10 19:03:39 +01:00
2026-03-09 20:10:19 +01:00
}
RenderingElement2D(RenderingElement2D&) = delete;
RenderingElement2D& operator=(RenderingElement2D&) = delete;
void ScaleNearestNeighbor() requires(Scaling) {
2026-03-12 21:13:53 +01:00
for (std::uint32_t y = 0; y < this->scaled.size.y; y++) {
2026-04-01 18:43:18 +02:00
std::uint32_t srcY = y * ScalingBase<T, true, Owning, Alignment>::bufferHeight / this->scaled.size.y;
2026-03-12 21:13:53 +01:00
for (std::uint32_t x = 0; x < this->scaled.size.x; x++) {
2026-04-01 18:43:18 +02:00
std::uint32_t srcX = x * ScalingBase<T, true, Owning, Alignment>::bufferWidth / this->scaled.size.x;
this->buffer[y * this->scaled.size.x + x] = ScalingBase<T, true, Owning, Alignment>::scalingBuffer[srcY * ScalingBase<T, true, Owning, Alignment>::bufferWidth + srcX];
2026-03-09 20:10:19 +01:00
}
}
}
void ScaleRotating() requires(Scaling) {
2026-03-12 21:13:53 +01:00
const float dstWidth = this->scaled.size.x;
const float dstHeight = this->scaled.size.y;
2026-03-09 20:10:19 +01:00
const float c2 = std::abs(std::cos(RotatingBase<true>::rotation));
const float s2 = std::abs(std::sin(RotatingBase<true>::rotation));
const float rotatedWidth = dstWidth * c2 + dstHeight * s2;
const float rotatedHeight = dstWidth * s2 + dstHeight * c2;
2026-03-12 21:13:53 +01:00
const float diffX = std::ceil((rotatedWidth - dstWidth) * 0.5);
const float diffY = std::ceil((rotatedHeight - dstHeight) * 0.5);
2026-03-09 20:10:19 +01:00
2026-03-12 21:13:53 +01:00
this->scaled.size.x += diffX + diffX;
this->scaled.size.y += diffY + diffY;
2026-03-09 20:10:19 +01:00
2026-03-12 21:13:53 +01:00
this->scaled.position.x -= diffX;
this->scaled.position.y -= diffY;
2026-03-09 20:10:19 +01:00
2026-03-12 21:13:53 +01:00
this->buffer.clear();
this->buffer.resize(this->scaled.size.x * this->scaled.size.y);
2026-03-09 20:10:19 +01:00
// Destination center
2026-03-12 21:13:53 +01:00
const float dstCx = (this->scaled.size.x - 1.0) * 0.5;
const float dstCy = (this->scaled.size.y - 1.0) * 0.5;
2026-03-09 20:10:19 +01:00
// Source center
2026-04-01 18:43:18 +02:00
const float srcCx = (ScalingBase<T, true, Owning, Alignment>::bufferWidth - 1.0) * 0.5;
const float srcCy = (ScalingBase<T, true, Owning, Alignment>::bufferHeight - 1.0) * 0.5;
2026-03-09 20:10:19 +01:00
const float c = std::cos(RotatingBase<true>::rotation);
const float s = std::sin(RotatingBase<true>::rotation);
// Scale factors (destination → source)
2026-04-01 18:43:18 +02:00
const float scaleX = static_cast<float>(ScalingBase<T, true, Owning, Alignment>::bufferWidth) / dstWidth;
const float scaleY = static_cast<float>(ScalingBase<T, true, Owning, Alignment>::bufferHeight) / dstHeight;
2026-03-09 20:10:19 +01:00
2026-03-12 21:13:53 +01:00
for (std::uint32_t yB = 0; yB < this->scaled.size.y; ++yB) {
for (std::uint32_t xB = 0; xB < this->scaled.size.x; ++xB) {
2026-03-09 20:10:19 +01:00
// ---- Destination pixel relative to center ----
const float dx = (static_cast<float>(xB) - dstCx) * scaleX;
const float dy = (static_cast<float>(yB) - dstCy) * scaleY;
// ---- Inverse rotation ----
const float sx = (c * dx - s * dy) + srcCx;
const float sy = (s * dx + c * dy) + srcCy;
// ---- Nearest neighbour sampling ----
const std::int32_t srcX = static_cast<std::int32_t>(std::round(sx));
const std::int32_t srcY = static_cast<std::int32_t>(std::round(sy));
2026-04-01 18:43:18 +02:00
if (srcX >= 0 && srcX < ScalingBase<T, true, Owning, Alignment>::bufferWidth && srcY >= 0 && srcY < ScalingBase<T, true, Owning, Alignment>::bufferHeight) {
this->buffer[yB * this->scaled.size.x + xB] = ScalingBase<T, true, Owning, Alignment>::scalingBuffer[srcY * ScalingBase<T, true, Owning, Alignment>::bufferWidth + srcX];
2026-03-09 20:10:19 +01:00
}
}
}
}
2026-03-12 21:13:53 +01:00
2026-04-11 18:48:00 +02:00
void UpdatePosition(RendertargetBase& window, Transform2D& parent) override {
2026-03-12 21:13:53 +01:00
ScaleData2D oldScale = this->scaled;
this->ScaleElement(parent);
2026-03-09 20:10:19 +01:00
if constexpr(Scaling && !Rotating) {
2026-03-12 21:13:53 +01:00
if(oldScale.size.x != this->scaled.size.x || oldScale.size.y != this->scaled.size.y) {
this->buffer.resize(this->scaled.size.x * this->scaled.size.y);
2026-03-09 20:10:19 +01:00
ScaleNearestNeighbor();
}
} else if constexpr(Rotating) {
2026-03-12 21:13:53 +01:00
if(oldScale.size.x != this->scaled.size.x || oldScale.size.y != this->scaled.size.y) {
this->buffer.resize(this->scaled.size.x * this->scaled.size.y);
2026-03-09 20:10:19 +01:00
ScaleRotating();
}
} else {
2026-03-12 21:13:53 +01:00
if(oldScale.size.x != this->scaled.size.x || oldScale.size.y != this->scaled.size.y) {
this->buffer.resize(this->scaled.size.x * this->scaled.size.y);
2026-03-09 20:10:19 +01:00
}
}
2026-03-12 21:13:53 +01:00
for(Transform2D* child : this->children) {
2026-03-09 20:10:19 +01:00
child->UpdatePosition(window, *this);
}
}
2026-04-11 18:48:00 +02:00
std::vector<std::string_view> ResizeText(RendertargetBase& window, Transform2D& parent, const std::string_view text, float& size, Font& font, TextOverflowMode overflowMode = TextOverflowMode::Clip, TextScaleMode scaleMode = TextScaleMode::None) {
2026-03-09 20:10:19 +01:00
float scale = stbtt_ScaleForPixelHeight(&font.font, size);
int baseline = (int)(font.ascent * scale);
std::vector<std::string_view> lines;
std::string_view remaining = text;
std::uint32_t lineHeight = (font.ascent - font.descent) * scale;
if(overflowMode == TextOverflowMode::Clip) {
while (!remaining.empty()) {
// Find next newline or end of string
auto newlinePos = remaining.find('\n');
if (newlinePos != std::string_view::npos) {
lines.emplace_back(remaining.substr(0, newlinePos));
remaining = remaining.substr(newlinePos + 1);
} else {
lines.emplace_back(remaining);
break;
}
}
std::uint32_t maxWidth = 0;
for(const std::string_view line: lines) {
std::uint32_t lineWidth = 0;
for (const char c : line) {
int advance, lsb;
stbtt_GetCodepointHMetrics(&font.font, c, &advance, &lsb);
lineWidth += (int)(advance * scale);
}
if(lineWidth > maxWidth) {
maxWidth = lineWidth;
}
}
if(scaleMode == TextScaleMode::Element) {
2026-03-12 21:13:53 +01:00
std::int32_t logicalPerPixelY = this->anchor.height / this->scaled.size.y;
std::int32_t oldHeight = this->anchor.height;
std::int32_t logicalPerPixelX = this->anchor.width / this->scaled.size.x;
std::int32_t oldwidth = this->anchor.width;
this->anchor.height = lineHeight * logicalPerPixelY;
this->anchor.width = maxWidth * logicalPerPixelX;
if(oldHeight != this->anchor.height || oldwidth != this->anchor.width) {
2026-03-12 01:07:46 +01:00
UpdatePosition(window, parent);
2026-03-09 20:10:19 +01:00
}
} else if(scaleMode == TextScaleMode::Font) {
2026-03-12 01:07:46 +01:00
float lineHeightPerFont = lineHeight / size;
float lineWidthPerFont = maxWidth / size;
2026-03-12 21:13:53 +01:00
float maxFontHeight = this->scaled.size.y / lineHeightPerFont;
float maxFontWidth = this->scaled.size.x / lineWidthPerFont;
2026-03-12 01:07:46 +01:00
size = std::min(maxFontHeight, maxFontWidth);
2026-03-09 20:10:19 +01:00
} else {
if constexpr(Scaling) {
2026-04-01 18:43:18 +02:00
lines.resize(ScalingBase<T, true, Owning, Alignment>::bufferHeight / lines.size());
2026-03-09 20:10:19 +01:00
} else {
2026-03-12 21:13:53 +01:00
lines.resize(this->scaled.size.y / lines.size());
2026-03-09 20:10:19 +01:00
}
}
} else {
while (!remaining.empty()) {
std::string_view line;
auto newlinePos = remaining.find('\n');
if (newlinePos != std::string_view::npos) {
line = remaining.substr(0, newlinePos);
remaining = remaining.substr(newlinePos + 1);
} else {
line = remaining;
remaining = "";
}
std::uint32_t lineWidth = 0;
std::size_t lastWrapPos = 0; // position of last space that can be used to wrap
std::size_t startPos = 0;
for (std::size_t i = 0; i < line.size(); ++i) {
char c = line[i];
// get width of this character
int advance, lsb;
stbtt_GetCodepointHMetrics(&font.font, c, &advance, &lsb);
lineWidth += (std::uint32_t)(advance * scale);
// remember last space for wrapping
if (c == ' ') {
lastWrapPos = i;
}
// if line exceeds width, wrap
2026-03-12 21:13:53 +01:00
if (lineWidth > this->scaled.size.x) {
2026-03-09 20:10:19 +01:00
std::size_t wrapPos;
if (lastWrapPos > startPos) {
wrapPos = lastWrapPos; // wrap at last space
} else {
wrapPos = i; // no space, hard wrap
}
// push the line up to wrapPos
lines.push_back(line.substr(startPos, wrapPos - startPos));
// skip any spaces at the beginning of next line
startPos = wrapPos;
while (startPos < line.size() && line[startPos] == ' ') {
++startPos;
}
// reset width and i
lineWidth = 0;
i = startPos - 1; // -1 because loop will increment i
}
}
// add the remaining part of the line
if (startPos < line.size()) {
lines.push_back(line.substr(startPos));
}
}
if(scaleMode == TextScaleMode::Element) {
2026-03-12 21:13:53 +01:00
float logicalPerPixelY = this->anchor.height / this->scaled.size.y;
float oldHeight = this->anchor.height;
this->anchor.height = lineHeight * logicalPerPixelY;
if(oldHeight != this->anchor.height) {
2026-03-12 01:07:46 +01:00
UpdatePosition(window, parent);
2026-03-09 20:10:19 +01:00
}
} else if(scaleMode == TextScaleMode::Font) {
2026-03-12 01:07:46 +01:00
float lineHeightPerFont = lineHeight / size;
2026-03-12 21:13:53 +01:00
size = this->scaled.size.y / lineHeightPerFont;
2026-03-09 20:10:19 +01:00
} else {
if constexpr(Scaling) {
2026-04-01 18:43:18 +02:00
lines.resize(ScalingBase<T, true, Owning, Alignment>::bufferHeight / lines.size());
2026-03-09 20:10:19 +01:00
} else {
2026-03-12 21:13:53 +01:00
lines.resize(this->scaled.size.y / lines.size());
2026-03-09 20:10:19 +01:00
}
}
}
return lines;
}
2026-04-01 18:43:18 +02:00
int utf8_decode(const char* s, int* bytes_consumed) {
unsigned char c = s[0];
if (c < 0x80) {
*bytes_consumed = 1;
return c;
} else if ((c & 0xE0) == 0xC0) {
*bytes_consumed = 2;
return ((c & 0x1F) << 6) | (s[1] & 0x3F);
} else if ((c & 0xF0) == 0xE0) {
*bytes_consumed = 3;
return ((c & 0x0F) << 12) | ((s[1] & 0x3F) << 6) | (s[2] & 0x3F);
} else if ((c & 0xF8) == 0xF0) {
*bytes_consumed = 4;
return ((c & 0x07) << 18) | ((s[1] & 0x3F) << 12) | ((s[2] & 0x3F) << 6) | (s[3] & 0x3F);
}
*bytes_consumed = 1;
return 0xFFFD; // replacement char
}
void RenderText(std::span<const std::string_view> lines, float size, Vector<T, 4> color, Font& font, TextAlignment alignment = TextAlignment::Left, std::uint32_t offsetX = 0, std::uint32_t offsetY = 0, OpaqueType opaque = OpaqueType::FullyOpaque) {
2026-03-09 20:10:19 +01:00
float scale = stbtt_ScaleForPixelHeight(&font.font, size);
int baseline = (int)(font.ascent * scale);
std::uint32_t lineHeight = (font.ascent - font.descent) * scale;
std::uint32_t currentY = baseline;
for(std::string_view line : lines) {
std::uint32_t lineWidth = 0;
for (const char c : line) {
int advance, lsb;
stbtt_GetCodepointHMetrics(&font.font, c, &advance, &lsb);
lineWidth += (int)(advance * scale);
}
2026-03-12 01:07:46 +01:00
std::uint32_t x = 0;
2026-03-09 20:10:19 +01:00
switch (alignment) {
case TextAlignment::Left:
2026-03-12 01:07:46 +01:00
x = 0;
2026-03-09 20:10:19 +01:00
break;
case TextAlignment::Center:
2026-03-12 21:13:53 +01:00
x = (this->scaled.size.x - lineWidth) / 2;
2026-03-09 20:10:19 +01:00
break;
case TextAlignment::Right:
2026-03-12 21:13:53 +01:00
x = this->scaled.size.x - lineWidth;
2026-03-09 20:10:19 +01:00
break;
}
2026-04-01 18:43:18 +02:00
const char* p = line.data();
const char* end = p + line.size();
while (p < end) {
int bytes;
int codepoint = utf8_decode(p, &bytes);
p += bytes;
2026-03-09 20:10:19 +01:00
int ax;
int lsb;
stbtt_GetCodepointHMetrics(&font.font, codepoint, &ax, &lsb);
int c_x1, c_y1, c_x2, c_y2;
stbtt_GetCodepointBitmapBox(&font.font, codepoint, scale, scale, &c_x1, &c_y1, &c_x2, &c_y2);
int w = c_x2 - c_x1;
int h = c_y2 - c_y1;
std::vector<unsigned char> bitmap(w * h);
stbtt_MakeCodepointBitmap(&font.font, bitmap.data(), w, h, w, scale, scale, codepoint);
// Only render characters that fit within the scaled bounds
2026-03-12 01:07:46 +01:00
switch(opaque) {
case OpaqueType::FullyOpaque: {
for (int j = 0; j < h; j++) {
for (int i = 0; i < w; i++) {
int bufferX = x + i + c_x1 + offsetX;
int bufferY = currentY + j + c_y1 + offsetY;
// Only draw pixels that are within our scaled buffer bounds
if constexpr(Scaling) {
2026-04-01 18:43:18 +02:00
if (bufferX >= 0 && bufferX < ScalingBase<T, true, Owning, Alignment>::bufferWidth && bufferY >= 0 && bufferY < ScalingBase<T, true, Owning, Alignment>::bufferHeight) {
ScalingBase<T, true, Owning, Alignment>::scalingBuffer[bufferY * ScalingBase<T, true, Owning, Alignment>::bufferWidth + bufferX] = {color.r, color.g, color.b, static_cast<T>(bitmap[j * w + i])};
2026-03-12 01:07:46 +01:00
}
} else {
2026-03-12 21:13:53 +01:00
if (bufferX >= 0 && bufferX < (int)this->scaled.size.x && bufferY >= 0 && bufferY < (int)this->scaled.size.y) {
2026-04-01 18:43:18 +02:00
this->buffer[bufferY * this->scaled.size.x + bufferX] = {color.r, color.g, color.b, static_cast<T>(bitmap[j * w + i])};
2026-03-12 01:07:46 +01:00
}
}
2026-03-09 20:10:19 +01:00
}
2026-03-12 01:07:46 +01:00
}
break;
}
2026-04-05 22:53:59 +02:00
case OpaqueType::SemiOpaque:
2026-03-12 01:07:46 +01:00
case OpaqueType::Transparent: {
for (int j = 0; j < h; j++) {
for (int i = 0; i < w; i++) {
int bufferX = x + i + c_x1 + offsetX;
int bufferY = currentY + j + c_y1 + offsetY;
// Only draw pixels that are within our scaled buffer bounds
if constexpr(Scaling) {
2026-04-01 18:43:18 +02:00
if (bufferX >= 0 && bufferX < ScalingBase<T, true, Owning, Alignment>::bufferWidth && bufferY >= 0 && bufferY < ScalingBase<T, true, Owning, Alignment>::bufferHeight) {
ScalingBase<T, true, Owning, Alignment>::scalingBuffer[bufferY * ScalingBase<T, true, Owning, Alignment>::bufferWidth + bufferX] = {color.r, color.g, color.b, static_cast<T>(bitmap[j * w + i])};
2026-03-12 01:07:46 +01:00
}
} else {
2026-03-12 21:13:53 +01:00
if (bufferX >= 0 && bufferX < (int)this->scaled.size.x && bufferY >= 0 && bufferY < (int)this->scaled.size.y) {
2026-04-01 18:43:18 +02:00
if constexpr(std::same_as<T, std::uint8_t>) {
std::uint8_t alpha = bitmap[j * w + i];
2026-03-12 01:07:46 +01:00
2026-04-01 18:43:18 +02:00
Vector<T, 4, Alignment> dst = this->buffer[bufferY * this->scaled.size.x + bufferX];
2026-03-12 01:07:46 +01:00
2026-04-01 18:43:18 +02:00
float srcA = (alpha / 255.0f) * (color.a / 255.0f);
float dstA = dst.a / 255.0f;
float oneMinusSrcA = 1.0f - color.a;
float outA = srcA + dstA * (1.0f - srcA);
this->buffer[bufferY * this->scaled.size.x + bufferX] = Vector<std::uint8_t, 4, Alignment>(
static_cast<std::uint8_t>((color.r * srcA + dst.r * dstA * (1.0f - srcA)) / outA),
static_cast<std::uint8_t>((color.g * srcA + dst.g * dstA * (1.0f - srcA)) / outA),
static_cast<std::uint8_t>((color.b * srcA + dst.b * dstA * (1.0f - srcA)) / outA),
static_cast<std::uint8_t>(outA * 255)
);
} else if constexpr(std::same_as<T, _Float16>) {
std::uint8_t alpha = bitmap[j * w + i];
_Float16 srcA = (_Float16(alpha)/_Float16(255.0f))*color.a;
Vector<_Float16, 4, Alignment> dst = this->buffer[bufferY * this->scaled.size.x + bufferX];
_Float16 outA = srcA + dst.a * (1.0f - srcA);
this->buffer[bufferY * this->scaled.size.x + bufferX] = Vector<_Float16, 4, Alignment>(
(color.r * srcA + dst.r * dst.a * (1.0f - srcA)),
(color.g * srcA + dst.g * dst.a * (1.0f - srcA)),
(color.b * srcA + dst.b * dst.a * (1.0f - srcA)),
outA
);
}
2026-03-12 01:07:46 +01:00
}
}
2026-03-09 20:10:19 +01:00
}
}
2026-03-12 01:07:46 +01:00
break;
2026-03-09 20:10:19 +01:00
}
}
x += (int)(ax * scale);
2026-04-01 18:43:18 +02:00
if (p + 1 < end) {
int next;
x += (int)stbtt_GetGlyphKernAdvance(&font.font, codepoint, utf8_decode(p+1, &next));
2026-03-09 20:10:19 +01:00
}
}
currentY += lineHeight;
}
}
};
}