mirror of
https://codeberg.org/comaps/comaps
synced 2026-01-05 12:13:54 +00:00
Format all C++ and Java code via clang-format
Signed-off-by: Konstantin Pastbin <konstantin.pastbin@gmail.com>
This commit is contained in:
@@ -32,7 +32,7 @@ class GlyphRenderer
|
||||
int m_fontPixelSize;
|
||||
char const * m_lang;
|
||||
|
||||
static constexpr FT_Int kSdfSpread {dp::kSdfBorder};
|
||||
static constexpr FT_Int kSdfSpread{dp::kSdfBorder};
|
||||
|
||||
public:
|
||||
GlyphRenderer()
|
||||
@@ -51,10 +51,7 @@ public:
|
||||
m_mng = std::make_unique<dp::GlyphManager>(args);
|
||||
}
|
||||
|
||||
~GlyphRenderer()
|
||||
{
|
||||
FT_Done_FreeType(m_freetypeLibrary);
|
||||
}
|
||||
~GlyphRenderer() { FT_Done_FreeType(m_freetypeLibrary); }
|
||||
|
||||
void SetString(std::string const & s, int fontPixelSize, char const * lang)
|
||||
{
|
||||
@@ -71,7 +68,7 @@ public:
|
||||
|
||||
static float PixelColorFromDistance(float distance)
|
||||
{
|
||||
//float const normalizedDistance = (distance - 128.f) / 128.f;
|
||||
// float const normalizedDistance = (distance - 128.f) / 128.f;
|
||||
float const normalizedDistance = distance / 255.f;
|
||||
static constexpr float kFontScale = 1.f;
|
||||
static constexpr float kSmoothing = 0.25f / (kSdfSpread * kFontScale);
|
||||
@@ -131,7 +128,7 @@ public:
|
||||
currentPen.rx() += glyph.m_xOffset;
|
||||
currentPen.ry() -= glyph.m_yOffset + h;
|
||||
painter.drawImage(currentPen, CreateImage(w, h, img.m_data->data()),
|
||||
QRect(dp::kSdfBorder, dp::kSdfBorder, w - 2 * dp::kSdfBorder, h - 2 * dp::kSdfBorder));
|
||||
QRect(dp::kSdfBorder, dp::kSdfBorder, w - 2 * dp::kSdfBorder, h - 2 * dp::kSdfBorder));
|
||||
}
|
||||
pen += QPoint(glyph.m_xAdvance, glyph.m_yAdvance /* 0 for horizontal texts */);
|
||||
|
||||
@@ -150,7 +147,8 @@ public:
|
||||
for (auto const & segment : runs.m_segments)
|
||||
{
|
||||
hb_buffer_t * buf = hb_buffer_create();
|
||||
hb_buffer_add_utf16(buf, reinterpret_cast<const uint16_t *>(runs.m_text.data()), runs.m_text.size(), segment.m_start, segment.m_length);
|
||||
hb_buffer_add_utf16(buf, reinterpret_cast<uint16_t const *>(runs.m_text.data()), runs.m_text.size(),
|
||||
segment.m_start, segment.m_length);
|
||||
hb_buffer_set_direction(buf, segment.m_direction);
|
||||
hb_buffer_set_script(buf, segment.m_script);
|
||||
hb_buffer_set_language(buf, hbLanguage);
|
||||
@@ -164,12 +162,13 @@ public:
|
||||
auto reader = GetPlatform().GetReader("fonts/" + fontFileName);
|
||||
auto fontFile = reader->GetName();
|
||||
FT_Face face;
|
||||
if (FT_New_Face(m_freetypeLibrary, fontFile.c_str(), 0, &face)) {
|
||||
if (FT_New_Face(m_freetypeLibrary, fontFile.c_str(), 0, &face))
|
||||
{
|
||||
std::cerr << "Can't load font " << fontFile << '\n';
|
||||
return;
|
||||
}
|
||||
// Set character size
|
||||
FT_Set_Pixel_Sizes(face, 0 , m_fontPixelSize );
|
||||
FT_Set_Pixel_Sizes(face, 0, m_fontPixelSize);
|
||||
// This also works.
|
||||
// if (FT_Set_Char_Size(face, 0, m_fontPixelSize << 6, 0, 0)) {
|
||||
// std::cerr << "Can't set character size\n";
|
||||
@@ -177,24 +176,24 @@ public:
|
||||
// }
|
||||
|
||||
// Set no transform (identity)
|
||||
//FT_Set_Transform(face, nullptr, nullptr);
|
||||
// FT_Set_Transform(face, nullptr, nullptr);
|
||||
|
||||
// Load font into HarfBuzz
|
||||
hb_font_t *font = hb_ft_font_create(face, nullptr);
|
||||
hb_font_t * font = hb_ft_font_create(face, nullptr);
|
||||
|
||||
// Shape!
|
||||
hb_shape(font, buf, nullptr, 0);
|
||||
|
||||
// Get the glyph and position information.
|
||||
unsigned int glyph_count;
|
||||
hb_glyph_info_t *glyph_info = hb_buffer_get_glyph_infos(buf, &glyph_count);
|
||||
hb_glyph_position_t *glyph_pos = hb_buffer_get_glyph_positions(buf, &glyph_count);
|
||||
hb_glyph_info_t * glyph_info = hb_buffer_get_glyph_infos(buf, &glyph_count);
|
||||
hb_glyph_position_t * glyph_pos = hb_buffer_get_glyph_positions(buf, &glyph_count);
|
||||
|
||||
for (unsigned int i = 0; i < glyph_count; i++)
|
||||
{
|
||||
hb_codepoint_t const glyphid = glyph_info[i].codepoint;
|
||||
|
||||
FT_Int32 const flags = FT_LOAD_RENDER;
|
||||
FT_Int32 const flags = FT_LOAD_RENDER;
|
||||
FT_Load_Glyph(face, glyphid, flags);
|
||||
FT_Render_Glyph(face->glyph, FT_RENDER_MODE_SDF);
|
||||
|
||||
@@ -217,12 +216,12 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
auto const bearing_x = slot->metrics.horiBearingX;//slot->bitmap_left;
|
||||
auto const bearing_y = slot->metrics.horiBearingY;//slot->bitmap_top;
|
||||
auto const bearing_x = slot->metrics.horiBearingX; // slot->bitmap_left;
|
||||
auto const bearing_y = slot->metrics.horiBearingY; // slot->bitmap_top;
|
||||
|
||||
auto const & glyphPos = glyph_pos[i];
|
||||
hb_position_t const x_offset = (glyphPos.x_offset + bearing_x) >> 6;
|
||||
hb_position_t const y_offset = (glyphPos.y_offset + bearing_y) >> 6;
|
||||
hb_position_t const x_offset = (glyphPos.x_offset + bearing_x) >> 6;
|
||||
hb_position_t const y_offset = (glyphPos.y_offset + bearing_y) >> 6;
|
||||
hb_position_t const x_advance = glyphPos.x_advance >> 6;
|
||||
hb_position_t const y_advance = glyphPos.y_advance >> 6;
|
||||
|
||||
@@ -232,7 +231,8 @@ public:
|
||||
QPoint currentPen = pen;
|
||||
currentPen.rx() += x_offset;
|
||||
currentPen.ry() -= y_offset;
|
||||
painter.drawImage(currentPen, CreateImage(width, height, buffer), QRect(kSdfSpread, kSdfSpread, width - 2*kSdfSpread, height - 2*kSdfSpread));
|
||||
painter.drawImage(currentPen, CreateImage(width, height, buffer),
|
||||
QRect(kSdfSpread, kSdfSpread, width - 2 * kSdfSpread, height - 2 * kSdfSpread));
|
||||
}
|
||||
pen += QPoint(x_advance, y_advance);
|
||||
}
|
||||
@@ -250,14 +250,13 @@ public:
|
||||
pen.rx() = kLineStartX;
|
||||
pen.ry() += kLineMarginY;
|
||||
|
||||
//QFont font("Noto Naskh Arabic");
|
||||
// QFont font("Noto Naskh Arabic");
|
||||
QFont font("Roboto");
|
||||
font.setPixelSize(m_fontPixelSize);
|
||||
//font.setWeight(QFont::Weight::Normal);
|
||||
// font.setWeight(QFont::Weight::Normal);
|
||||
painter.setFont(font);
|
||||
painter.drawText(pen, QString::fromUtf8(m_utf8.c_str(), m_utf8.size()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -286,16 +285,33 @@ UNIT_TEST(GlyphLoadingTest)
|
||||
renderer.SetString("𫝚 𫝛 𫝜", fontSize, "zh");
|
||||
RunTestLoop("CJK Surrogates", std::bind(&GlyphRenderer::RenderGlyphs, &renderer, _1));
|
||||
|
||||
renderer.SetString("الحلّة گلها"" كسول الزنجبيل القط""56""عين علي (الحربية)""123"" اَلْعَرَبِيَّةُ", fontSize, "ar");
|
||||
renderer.SetString(
|
||||
"الحلّة گلها"
|
||||
" كسول الزنجبيل القط"
|
||||
"56"
|
||||
"عين علي (الحربية)"
|
||||
"123"
|
||||
" اَلْعَرَبِيَّةُ",
|
||||
fontSize, "ar");
|
||||
RunTestLoop("Arabic1", std::bind(&GlyphRenderer::RenderGlyphs, &renderer, _1));
|
||||
|
||||
renderer.SetString("12345""گُلها""12345""گُلها""12345", fontSize, "ar");
|
||||
renderer.SetString(
|
||||
"12345"
|
||||
"گُلها"
|
||||
"12345"
|
||||
"گُلها"
|
||||
"12345",
|
||||
fontSize, "ar");
|
||||
RunTestLoop("Arabic2", std::bind(&GlyphRenderer::RenderGlyphs, &renderer, _1));
|
||||
|
||||
renderer.SetString("മനക്കലപ്പടി", fontSize, "ml");
|
||||
RunTestLoop("Malay", std::bind(&GlyphRenderer::RenderGlyphs, &renderer, _1));
|
||||
|
||||
renderer.SetString("Test 12 345 ""گُلها""678 9000 Test", fontSize, "ar");
|
||||
renderer.SetString(
|
||||
"Test 12 345 "
|
||||
"گُلها"
|
||||
"678 9000 Test",
|
||||
fontSize, "ar");
|
||||
RunTestLoop("Arabic Mixed", std::bind(&GlyphRenderer::RenderGlyphs, &renderer, _1));
|
||||
|
||||
renderer.SetString("NFKC Razdoĺny NFKD Razdoĺny", fontSize, "be");
|
||||
|
||||
Reference in New Issue
Block a user