Skip to content

Commit

Permalink
Font: a little extra null safety for hhea and os2 font data, just to …
Browse files Browse the repository at this point in the history
…be safe

Followup to 62ab8eb
  • Loading branch information
joshtynjala committed Dec 13, 2024
1 parent 0db3c7c commit 9c4fa35
Showing 1 changed file with 47 additions and 27 deletions.
74 changes: 47 additions & 27 deletions project/src/text/Font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,13 +578,21 @@ namespace lime {
TT_OS2* os2 = (TT_OS2*)FT_Get_Sfnt_Table(((FT_Face)face), ft_sfnt_os2);
TT_HoriHeader* hhea = (TT_HoriHeader*)FT_Get_Sfnt_Table(((FT_Face)face), ft_sfnt_hhea);

int calculatedAscender = hhea->Ascender;
int calculatedDescender = hhea->Descender;
int calculatedHeight = calculatedAscender - calculatedDescender + hhea->Line_Gap;
int calculatedAscender = 0;
int calculatedDescender = 0;
int calculatedHeight = 0;

if (hhea) {

calculatedAscender = hhea->Ascender;
calculatedDescender = hhea->Descender;
calculatedHeight = calculatedAscender - calculatedDescender + hhea->Line_Gap;

}

if (!( calculatedAscender || calculatedDescender ))
{
if (os2->version != 0xFFFFU)
if (os2 && os2->version != 0xFFFFU)
{
if (os2->sTypoAscender || os2->sTypoDescender)
{
Expand All @@ -597,7 +605,7 @@ namespace lime {
else
{

calculatedAscender = (FT_Short)os2->usWinAscent;
calculatedAscender = (FT_Short)os2->usWinAscent;
calculatedDescender = -(FT_Short)os2->usWinDescent;
calculatedHeight = calculatedAscender - calculatedDescender;

Expand Down Expand Up @@ -835,28 +843,31 @@ namespace lime {
TT_OS2* os2 = (TT_OS2*)FT_Get_Sfnt_Table(((FT_Face)face), ft_sfnt_os2);
TT_HoriHeader* hhea = (TT_HoriHeader*)FT_Get_Sfnt_Table(((FT_Face)face), ft_sfnt_hhea);

int calculatedAscender = hhea->Ascender;
int calculatedDescender = hhea->Descender;
int calculatedHeight = calculatedAscender - calculatedDescender + hhea->Line_Gap;
int calculatedAscender = 0;
int calculatedDescender = 0;

if (hhea) {

calculatedAscender = hhea->Ascender;
calculatedDescender = hhea->Descender;
}

if (!( calculatedAscender || calculatedDescender ))
{
if (os2->version != 0xFFFFU)
if (os2 && os2->version != 0xFFFFU)
{
if (os2->sTypoAscender || os2->sTypoDescender)
{

calculatedAscender = os2->sTypoAscender;
calculatedDescender = os2->sTypoDescender;
calculatedHeight = calculatedAscender - calculatedDescender + os2->sTypoLineGap;

}
else
{

calculatedAscender = (FT_Short)os2->usWinAscent;
calculatedAscender = (FT_Short)os2->usWinAscent;
calculatedDescender = -(FT_Short)os2->usWinDescent;
calculatedHeight = calculatedAscender - calculatedDescender;

}
}
Expand All @@ -866,7 +877,6 @@ namespace lime {

calculatedAscender = ((FT_Face)face)->ascender;
calculatedDescender = ((FT_Face)face)->descender;
calculatedHeight = ((FT_Face)face)->height;

}

Expand Down Expand Up @@ -913,28 +923,32 @@ namespace lime {
TT_OS2* os2 = (TT_OS2*)FT_Get_Sfnt_Table(((FT_Face)face), ft_sfnt_os2);
TT_HoriHeader* hhea = (TT_HoriHeader*)FT_Get_Sfnt_Table(((FT_Face)face), ft_sfnt_hhea);

int calculatedAscender = hhea->Ascender;
int calculatedDescender = hhea->Descender;
int calculatedHeight = calculatedAscender - calculatedDescender + hhea->Line_Gap;
int calculatedAscender = 0;
int calculatedDescender = 0;

if (hhea) {

calculatedAscender = hhea->Ascender;
calculatedDescender = hhea->Descender;

}

if (!( calculatedAscender || calculatedDescender ))
{
if (os2->version != 0xFFFFU)
if (os2 && os2->version != 0xFFFFU)
{
if (os2->sTypoAscender || os2->sTypoDescender)
{

calculatedAscender = os2->sTypoAscender;
calculatedDescender = os2->sTypoDescender;
calculatedHeight = calculatedAscender - calculatedDescender + os2->sTypoLineGap;

}
else
{

calculatedAscender = (FT_Short)os2->usWinAscent;
calculatedAscender = (FT_Short)os2->usWinAscent;
calculatedDescender = -(FT_Short)os2->usWinDescent;
calculatedHeight = calculatedAscender - calculatedDescender;

}
}
Expand All @@ -944,7 +958,6 @@ namespace lime {

calculatedAscender = ((FT_Face)face)->ascender;
calculatedDescender = ((FT_Face)face)->descender;
calculatedHeight = ((FT_Face)face)->height;

}

Expand Down Expand Up @@ -1170,21 +1183,28 @@ namespace lime {
TT_OS2* os2 = (TT_OS2*)FT_Get_Sfnt_Table(((FT_Face)face), ft_sfnt_os2);
TT_HoriHeader* hhea = (TT_HoriHeader*)FT_Get_Sfnt_Table(((FT_Face)face), ft_sfnt_hhea);

int calculatedAscender = hhea->Ascender;
int calculatedDescender = hhea->Descender;
int calculatedHeight = calculatedAscender - calculatedDescender + hhea->Line_Gap;
int calculatedAscender = 0;
int calculatedDescender = 0;
int calculatedHeight = 0;

if (hhea) {

calculatedAscender = hhea->Ascender;
calculatedDescender = hhea->Descender;
calculatedHeight = calculatedAscender - calculatedDescender + hhea->Line_Gap;

}

if (!( calculatedAscender || calculatedDescender ))
{
if (os2->version != 0xFFFFU)
if (os2 && os2->version != 0xFFFFU)
{
if (os2->sTypoAscender || os2->sTypoDescender)
{

calculatedAscender = os2->sTypoAscender;
calculatedDescender = os2->sTypoDescender;
calculatedHeight = calculatedAscender - calculatedDescender +
os2->sTypoLineGap;
calculatedHeight = calculatedAscender - calculatedDescender + os2->sTypoLineGap;

}
else
Expand Down

0 comments on commit 9c4fa35

Please sign in to comment.