Refinement of solution - use better scaling for noscaling vector fonts

This commit is contained in:
Matthias Koefferlein 2026-08-14 23:55:35 +02:00
parent f7ade65449
commit fb26cf6433
6 changed files with 75700 additions and 83388 deletions

View File

@ -72,7 +72,7 @@ main (int argc, char *argv [])
for (int s = 0; s < font_sizes; ++s) {
char b[1024];
sprintf (b, " FixedFont (ff%d_height, ff%d_line_height, ff%d_width, ff%d_first_char, sizeof (ff%d_data) / sizeof (uint32_t) / (ff%d_height * ff%d_stride), ff%d_data, ff%d_stride),\n", os, os, os, os, os, os, os, os, os);
sprintf (b, " FixedFont (ff%d_height, ff%d_cap_height, ff%d_ascent, ff%d_descent, ff%d_line_height, ff%d_width, ff%d_first_char, sizeof (ff%d_data) / sizeof (uint32_t) / (ff%d_height * ff%d_stride), ff%d_data, ff%d_stride),\n", os, os, os, os, os, os, os, os, os, os, os, os);
table += b;
QFont f (QString::fromLatin1 (font_name), r * sz[s]);
@ -83,8 +83,13 @@ main (int argc, char *argv [])
int w = fm.averageCharWidth ();
printf ("\n// Font: %s\n", f.toString ().toLatin1 ().constData ());
printf ("const unsigned int ff%d_height = %d;\nconst unsigned int ff%d_line_height = %d;\nconst unsigned int ff%d_width = %d;\nconst unsigned int ff%d_stride = %d;\n",
os, fm.height (), os, fm.lineSpacing (), os, w, os, (w + 31) / 32);
printf ("const unsigned int ff%d_height = %d;\n", os, fm.height ());
printf ("const unsigned int ff%d_cap_height = %d;\n", os, fm.capHeight ());
printf ("const unsigned int ff%d_ascent = %d;\n", os, fm.ascent ());
printf ("const unsigned int ff%d_descent = %d;\n", os, fm.descent ());
printf ("const unsigned int ff%d_line_height = %d;\n", os, fm.lineSpacing ());
printf ("const unsigned int ff%d_width = %d;\n", os, w);
printf ("const unsigned int ff%d_stride = %d;\n", os, (w + 31) / 32);
printf ("const unsigned char ff%d_first_char = ' ';\n\nuint32_t ff%d_data [] = {\n", os, os);

File diff suppressed because it is too large Load Diff

View File

@ -403,7 +403,7 @@ BitmapRenderer::draw (const db::Shape &shape, const db::CplxTrans &trans,
// for the special case of zero effective height, borrow the height
// from the default font in an unscaling fashion.
const lay::FixedFont &ff = lay::FixedFont::get_font (m_font_resolution);
h = ff.height ();
h = ff.cap_height ();
}
db::HAlign halign = shape.text_halign ();
@ -1111,6 +1111,13 @@ BitmapRenderer::draw (const db::Text &txt, const db::CplxTrans &trans,
}
}
if (h == 0.0) {
// for the special case of zero effective height, borrow the height
// from the default font in an unscaling fashion.
const lay::FixedFont &ff = lay::FixedFont::get_font (m_font_resolution);
h = ff.cap_height ();
}
double fy = 0.0;
if (txt.valign () == db::VAlignBottom || txt.valign () == db::NoVAlign) {
fy = 1.0;
@ -1186,6 +1193,13 @@ BitmapRenderer::draw (const db::DText &txt, const db::DCplxTrans &trans,
}
}
if (h == 0.0) {
// for the special case of zero effective height, borrow the height
// from the default font in an unscaling fashion.
const lay::FixedFont &ff = lay::FixedFont::get_font (m_font_resolution);
h = ff.cap_height ();
}
double fy = 0.0;
if (txt.valign () == db::VAlignBottom || txt.valign () == db::NoVAlign) {
fy = 1.0;

View File

@ -31,8 +31,9 @@ namespace lay
int FixedFont::ms_default_font_size = 0;
FixedFont::FixedFont (unsigned int h, unsigned int lh, unsigned int w, unsigned char c0, unsigned char nc, uint32_t *d, unsigned int stride)
: m_height (h), m_line_height (lh), m_width (w), m_first_char (c0), m_n_chars (nc), mp_data (d), m_stride (stride)
FixedFont::FixedFont (unsigned int h, unsigned int ch, unsigned int asc, unsigned int desc, unsigned int lh, unsigned int w, unsigned char c0, unsigned char nc, uint32_t *d, unsigned int stride)
: m_height (h), m_cap_height (ch), m_ascent (asc), m_descent (desc),
m_line_height (lh), m_width (w), m_first_char (c0), m_n_chars (nc), mp_data (d), m_stride (stride)
{
// .. nothing yet ..
}

View File

@ -20,7 +20,7 @@ public:
/**
* @brief ctor
*/
FixedFont (unsigned int h, unsigned int lh, unsigned int w, unsigned char c0, unsigned char nc, uint32_t *d, unsigned int stride);
FixedFont (unsigned int h, unsigned int ch, unsigned int asc, unsigned int desc, unsigned int lh, unsigned int w, unsigned char c0, unsigned char nc, uint32_t *d, unsigned int stride);
/**
* @brief Factory
@ -62,6 +62,30 @@ public:
return m_height;
}
/**
* @brief Capital letter height
*/
unsigned int cap_height () const
{
return m_cap_height;
}
/**
* @brief Ascent value (above baseline)
*/
unsigned int ascent () const
{
return m_ascent;
}
/**
* @brief Descent value (below baseline)
*/
unsigned int descent () const
{
return m_descent;
}
/**
* @brief Character line height
*/
@ -111,7 +135,7 @@ public:
}
private:
unsigned int m_height, m_line_height, m_width;
unsigned int m_height, m_cap_height, m_ascent, m_descent, m_line_height, m_width;
unsigned char m_first_char;
unsigned char m_n_chars;
uint32_t *mp_data;

View File

@ -85,7 +85,7 @@ TextInfo::bbox (const db::DText &text, const db::DCplxTrans &vp_trans) const
// for the special case of zero effective height, borrow the height
// from the default font in an unscaling fashion.
const lay::FixedFont &ff = lay::FixedFont::get_font (m_resolution);
h = ff.height () / vp_trans.mag ();
h = ff.cap_height () / vp_trans.mag ();
}
db::DPoint dp1 (fx * offset, fy * offset + (fy - 1) * 0.5 * h);