From a7e05ff1c85a44ce4c72633b7640be3864ae4ac5 Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Thu, 16 Aug 2007 16:02:52 +0000 Subject: [PATCH] Semi-workaround for wrong text_extents on non-Windows. Better but still not perfect calculation. Originally committed to SVN as r1495. --- aegisub/auto4_base.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/aegisub/auto4_base.cpp b/aegisub/auto4_base.cpp index e8243b550..7c51e2001 100644 --- a/aegisub/auto4_base.cpp +++ b/aegisub/auto4_base.cpp @@ -146,24 +146,26 @@ namespace Automation4 { for (unsigned int i = 0; i < text.length(); i++) { int a, b, c, d; thedc.GetTextExtent(text[i], &a, &b, &c, &d); - width += a + spacing; - height = b > height ? b : height; - descent = c > descent ? c : descent; - extlead= d > extlead ? d : extlead; + double scaling = fontsize / (double)(b>0?b:1); // semi-workaround for missing OS/2 table data for scaling + width += (a + spacing)*scaling; + height = b > height ? b*scaling : height; + descent = c > descent ? c*scaling : descent; + extlead = d > extlead ? d*scaling : extlead; } } else { // If the inter-character spacing should be zero, kerning info can (and must) be used, so calculate everything in one go long lwidth, lheight, ldescent, lextlead; thedc.GetTextExtent(text, &lwidth, &lheight, &ldescent, &lextlead); - width = lwidth; height = lheight; descent = ldescent; extlead = lextlead; + double scaling = fontsize / (double)(lheight>0?lheight:1); // semi-workaround for missing OS/2 table data for scaling + width = lwidth*scaling; height = lheight*scaling; descent = ldescent*scaling; extlead = lextlead*scaling; } #endif // Compensate for scaling width = style->scalex / 100 * width / 64; - height = style->scaley / 100 * height /64; - descent = style->scaley / 100 * descent /64; - extlead = style->scaley / 100 * extlead /64; + height = style->scaley / 100 * height / 64; + descent = style->scaley / 100 * descent / 64; + extlead = style->scaley / 100 * extlead / 64; return true; }