@@ -67,18 +67,18 @@ auto ft_library() -> FT_Library
|
||||
|
||||
struct CodepointSpan {
|
||||
uint32_t codepoint {};
|
||||
size_t start {};
|
||||
size_t end {};
|
||||
usize start {};
|
||||
usize end {};
|
||||
};
|
||||
|
||||
auto decode_utf8(std::string_view text) -> std::vector<CodepointSpan>
|
||||
{
|
||||
std::vector<CodepointSpan> spans;
|
||||
size_t i = 0;
|
||||
usize i = 0;
|
||||
while (i < text.size()) {
|
||||
u8 const byte = static_cast<u8>(text[i]);
|
||||
size_t const start = i;
|
||||
size_t length = 1;
|
||||
usize const start = i;
|
||||
usize length = 1;
|
||||
uint32_t cp = 0xFFFD;
|
||||
if (byte < 0x80) {
|
||||
cp = byte;
|
||||
@@ -239,7 +239,7 @@ auto TextRenderer::generate_glyph(FontRuntime &rt, FontData &fd,
|
||||
msdfgen::generateMSDF(
|
||||
msdf_bitmap, shape, rt.px_range, scale_vec, translate);
|
||||
|
||||
std::vector<Color> buffer(static_cast<size_t>(bmp_w) * bmp_h);
|
||||
std::vector<Color> buffer(static_cast<usize>(bmp_w) * bmp_h);
|
||||
// FIXME: Figure out shader
|
||||
// for (int y = 0; y < bmp_h; ++y) {
|
||||
// int const dst_y = bmp_h - 1 - y;
|
||||
@@ -248,7 +248,7 @@ auto TextRenderer::generate_glyph(FontRuntime &rt, FontData &fd,
|
||||
// auto const r = msdfgen::pixelFloatToByte(px[0]);
|
||||
// auto const g = msdfgen::pixelFloatToByte(px[1]);
|
||||
// auto const b = msdfgen::pixelFloatToByte(px[2]);
|
||||
// buffer[static_cast<size_t>(dst_y) * bmp_w + x]
|
||||
// buffer[static_cast<usize>(dst_y) * bmp_w + x]
|
||||
// = Color { r, g, b, 255 };
|
||||
// }
|
||||
//}
|
||||
@@ -274,10 +274,10 @@ auto TextRenderer::generate_glyph(FontRuntime &rt, FontData &fd,
|
||||
float const *px = msdf_bitmap(x, y);
|
||||
auto const r = msdfgen::pixelFloatToByte(px[0]);
|
||||
if (sum_white > sum_black && (float)bmp_w / (float)bmp_h > 0.6) {
|
||||
buffer[static_cast<size_t>(dst_y) * bmp_w + x] = Color { 255,
|
||||
buffer[static_cast<usize>(dst_y) * bmp_w + x] = Color { 255,
|
||||
255, 255, static_cast<unsigned char>(255 - r) };
|
||||
} else {
|
||||
buffer[static_cast<size_t>(dst_y) * bmp_w + x]
|
||||
buffer[static_cast<usize>(dst_y) * bmp_w + x]
|
||||
= Color { 255, 255, 255, r };
|
||||
}
|
||||
}
|
||||
@@ -338,11 +338,11 @@ auto TextRenderer::ensure_glyph(FontRuntime &rt, FontData &fd, u32 glyph_index,
|
||||
TextRenderer::TextRenderer()
|
||||
{
|
||||
static char const msdf_vs_data[] {
|
||||
#embed "base.vs"
|
||||
#embed "base.vert"
|
||||
, 0
|
||||
};
|
||||
static char const msdf_fs_data[] {
|
||||
#embed "msdf.fs"
|
||||
#embed "msdf.frag"
|
||||
, 0
|
||||
};
|
||||
m_msdf_shader = LoadShaderFromMemory(msdf_vs_data, msdf_fs_data);
|
||||
@@ -661,9 +661,9 @@ auto TextRenderer::shape_text(FontHandle const font,
|
||||
|
||||
constexpr usize kNoFont = std::numeric_limits<usize>::max();
|
||||
std::vector<usize> selections(codepoints.size(), kNoFont);
|
||||
for (size_t i = 0; i < codepoints.size(); ++i) {
|
||||
for (usize i = 0; i < codepoints.size(); ++i) {
|
||||
bool matched = false;
|
||||
for (size_t candidate = 0; candidate < font_set.font_indices.size();
|
||||
for (usize candidate = 0; candidate < font_set.font_indices.size();
|
||||
++candidate) {
|
||||
usize runtime_index = font_set.font_indices[candidate];
|
||||
if (runtime_index >= m_font_runtime.size())
|
||||
@@ -683,9 +683,9 @@ auto TextRenderer::shape_text(FontHandle const font,
|
||||
selections[i] = kNoFont;
|
||||
}
|
||||
|
||||
size_t idx = 0;
|
||||
usize idx = 0;
|
||||
while (idx < codepoints.size()) {
|
||||
size_t font_choice = selections[idx];
|
||||
usize font_choice = selections[idx];
|
||||
if (font_choice == kNoFont) {
|
||||
++idx;
|
||||
continue;
|
||||
@@ -700,9 +700,9 @@ auto TextRenderer::shape_text(FontHandle const font,
|
||||
continue;
|
||||
}
|
||||
|
||||
size_t segment_start = codepoints[idx].start;
|
||||
size_t segment_end = codepoints[idx].end;
|
||||
size_t end_idx = idx + 1;
|
||||
usize segment_start = codepoints[idx].start;
|
||||
usize segment_end = codepoints[idx].end;
|
||||
usize end_idx = idx + 1;
|
||||
while (
|
||||
end_idx < codepoints.size() && selections[end_idx] == font_choice) {
|
||||
segment_end = codepoints[end_idx].end;
|
||||
|
||||
Reference in New Issue
Block a user