Fix artihmetic exception when using non-scalable fonts
For non-scalable fonts, the units_per_EM in FreeType is documented to be undefined and will default to 0, which means that any division by it will cause an exception. The emSquareSize() function already checks if the font is scalable and returns y_ppem if not, so lets use it instead in all locations where we're not already sure the font is scalable. [ChangeLog][Text][Freetype] Fixed a divide-by-zero exception when accessing bitmap fonts. Change-Id: I8839d4c83047fb3f6bb4d69af0258e94a258a4d9 Task-number: QTBUG-45963 Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>bb10
parent
ba7f76dea0
commit
a67a905190
|
|
@ -1255,7 +1255,7 @@ QFixed QFontEngineFT::xHeight() const
|
|||
TT_OS2 *os2 = (TT_OS2 *)FT_Get_Sfnt_Table(freetype->face, ft_sfnt_os2);
|
||||
if (os2 && os2->sxHeight) {
|
||||
lockFace();
|
||||
QFixed answer = QFixed(os2->sxHeight*freetype->face->size->metrics.y_ppem)/freetype->face->units_per_EM;
|
||||
QFixed answer = QFixed(os2->sxHeight * freetype->face->size->metrics.y_ppem) / emSquareSize();
|
||||
unlockFace();
|
||||
return answer;
|
||||
}
|
||||
|
|
@ -1267,7 +1267,7 @@ QFixed QFontEngineFT::averageCharWidth() const
|
|||
TT_OS2 *os2 = (TT_OS2 *)FT_Get_Sfnt_Table(freetype->face, ft_sfnt_os2);
|
||||
if (os2 && os2->xAvgCharWidth) {
|
||||
lockFace();
|
||||
QFixed answer = QFixed(os2->xAvgCharWidth*freetype->face->size->metrics.x_ppem)/freetype->face->units_per_EM;
|
||||
QFixed answer = QFixed(os2->xAvgCharWidth * freetype->face->size->metrics.x_ppem) / emSquareSize();
|
||||
unlockFace();
|
||||
return answer;
|
||||
}
|
||||
|
|
@ -1295,7 +1295,7 @@ void QFontEngineFT::doKerning(QGlyphLayout *g, QFontEngine::ShaperFlags flags) c
|
|||
kerning_pairs_loaded = true;
|
||||
lockFace();
|
||||
if (freetype->face->size->metrics.x_ppem != 0) {
|
||||
QFixed scalingFactor(freetype->face->units_per_EM/freetype->face->size->metrics.x_ppem);
|
||||
QFixed scalingFactor = emSquareSize() / QFixed(freetype->face->size->metrics.x_ppem);
|
||||
unlockFace();
|
||||
const_cast<QFontEngineFT *>(this)->loadKerningPairs(scalingFactor);
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in New Issue