TODO: 字体布局
This commit is contained in:
parent
5abdc2fc1d
commit
4074f5d6e1
BIN
HarmonyOS_Sans_SC_Regular.ttf
Normal file
BIN
HarmonyOS_Sans_SC_Regular.ttf
Normal file
Binary file not shown.
@ -112,7 +112,9 @@ void dx_window::begin_frame() {
|
||||
// context.draw_line( { 600, 600 }, { mouse_x, mouse_y }, { 1, 0, 1, 1 }, thickness);
|
||||
|
||||
// if (test_texture) context.draw_texture({ 0.f, 0.f }, test_texture->size().cast<float>(), test_texture);
|
||||
context.draw_string({0, 0}, U"你好,世界!全是水群大师\n测试换行\n测试Unicode: 😀\nТест по русскому языку\nテスト日本語", 32, {0, 0, 0, 1});
|
||||
// context.draw_string({0, 0}, U"你好,世界!全是水群大师\n测试换行\n测试Unicode: 😀\nТест по русскому языку\nテスト日本語", 32, {0, 0, 0, 1});
|
||||
context.draw_string({0, 100}, U"Тест по русскому языку", 32, {0, 0, 0, 1});
|
||||
context.draw_rectangle({ 0, 100 }, { 2048, 1 }, { 1, 0, 1, 1 });
|
||||
|
||||
context.flush();
|
||||
|
||||
|
@ -46,6 +46,7 @@ void renderer_context::draw_string(const Eigen::Vector2f& in_pos, const std::u32
|
||||
|
||||
float cursor_x = in_pos.x();
|
||||
float cursor_y = in_pos.y();
|
||||
Eigen::Vector2f cursor(cursor_x, cursor_y);
|
||||
const auto& measure = text->measure_text(in_str, in_height);
|
||||
|
||||
for (const auto& mch: measure) {
|
||||
@ -53,8 +54,12 @@ void renderer_context::draw_string(const Eigen::Vector2f& in_pos, const std::u32
|
||||
if (!info)
|
||||
continue;
|
||||
// 使用整形坐标, 避免出现模糊
|
||||
const Eigen::Vector2f pos { cursor_x + mch.x_offset, cursor_y + mch.y_offset };
|
||||
const Eigen::Vector2f size { info->get_width() * mch.size_scale, info->get_height() * mch.size_scale };
|
||||
Eigen::Vector2f pos{ info->left, info->right };
|
||||
pos += cursor;
|
||||
Eigen::Vector2f size{ info->get_width(), info->get_height() };
|
||||
|
||||
// const Eigen::Vector2f pos { cursor_x + mch.x_offset, cursor_y + mch.y_offset };
|
||||
// const Eigen::Vector2f size { info->get_width() * mch.size_scale, info->get_height() * mch.size_scale };
|
||||
|
||||
aorii_vertex_param param{};
|
||||
param.param_a1 = info->tex_u;
|
||||
@ -64,6 +69,7 @@ void renderer_context::draw_string(const Eigen::Vector2f& in_pos, const std::u32
|
||||
param.param_b2 = info->v_size;
|
||||
|
||||
make_rect(pos, size, in_color, 0, param);
|
||||
cursor.x() += size.x();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -304,6 +304,7 @@ ch_atlas_item const* aorii_text::cache_ch_to_atlas(char32_t ch) {
|
||||
stbtt_GetGlyphHMetrics(font, glyph_index, &advance_width, &left_side_bearing);
|
||||
int ch_x0, ch_y0, ch_x1, ch_y1;
|
||||
stbtt_GetGlyphBox(font, glyph_index, &ch_x0, &ch_y0, &ch_x1, &ch_y1);
|
||||
spdlog::info("left: {}, right: {}, top: {}, bottom: {}", ch_x0, ch_x1, ch_y0, ch_y1);
|
||||
|
||||
// 将x_offset和y_offset转换到字体空间
|
||||
x_offset = x_offset / scale;
|
||||
|
@ -42,7 +42,7 @@ SamplerState sampler_state : register(s0);
|
||||
float4 pixel_main(PSInput input) : SV_Target {
|
||||
float2 uv = input.altas_uv + input.char_size * input.uv;
|
||||
float distance = atlas_texture.Sample(sampler_state, float3(uv, input.altas_index)).r;
|
||||
// return float4(distance, distance, distance, 1.0);
|
||||
return float4(distance, distance, distance, 1.0);
|
||||
float range = 0.2;
|
||||
float alpha = smoothstep(0.4, 0.5, distance);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user