dont double fonts in chain

Signed-off-by: Sergey Isakov <isakov-sl@bk.ru>
This commit is contained in:
Sergey Isakov 2020-03-13 15:13:08 +03:00
parent 07f5c88a8f
commit 81286c08b1
5 changed files with 49 additions and 14 deletions

View File

@ -296,6 +296,7 @@ rem # setup build
echo #define FIRMWARE_REVISION L"%SVNREVISION%">>%F_VER_H% echo #define FIRMWARE_REVISION L"%SVNREVISION%">>%F_VER_H%
echo #define REVISION_STR "Clover revision: %SVNREVISION%">>%F_VER_H% echo #define REVISION_STR "Clover revision: %SVNREVISION%">>%F_VER_H%
echo #define BUILDINFOS_STR %clover_build_info%>>%F_VER_H% echo #define BUILDINFOS_STR %clover_build_info%>>%F_VER_H%
copy %F_VER_H% rEFIt_UEFI\%F_VER_H%
:callbuild :callbuild
rem # launch build rem # launch build

View File

@ -421,6 +421,23 @@ EFI_STATUS ParseSVGTheme(CONST CHAR8* buffer, TagPtr * dict, UINT32 bufSize)
GlobalConfig.MainEntriesSize = (INTN)(128.f * Scale); GlobalConfig.MainEntriesSize = (INTN)(128.f * Scale);
} }
DBG("parsing theme finish\n"); DBG("parsing theme finish\n");
#if 1 //dump fonts
{
NSVGfont *fontSVG = NULL;
NSVGfontChain *fontChain = fontsDB;
while (fontChain) {
fontSVG = fontChain->font;
if (fontSVG) {
DBG("probe fontFamily=%a fontStyle=%c\n", fontSVG->fontFamily, fontSVG->fontStyle);
}
else {
DBG("nextChain is empty\n");
}
fontChain = fontChain->next;
}
}
#endif
return EFI_SUCCESS; return EFI_SUCCESS;
} }

View File

@ -547,12 +547,14 @@ void nsvg__deleteFont(NSVGfont* font)
return; return;
} }
if (font->missingGlyph) { if (font->missingGlyph) {
// DBG("missing glyph=%a\n", font->missingGlyph->name);
nsvg__deletePaths(font->missingGlyph->path); nsvg__deletePaths(font->missingGlyph->path);
FreePool(font->missingGlyph); FreePool(font->missingGlyph);
font->missingGlyph = NULL; font->missingGlyph = NULL;
} }
glyphs = font->glyphs; glyphs = font->glyphs;
while (glyphs) { while (glyphs) {
// DBG(" glyph=%a\n", glyphs->name);
next = glyphs->next; next = glyphs->next;
nsvg__deletePaths(glyphs->path); nsvg__deletePaths(glyphs->path);
FreePool(glyphs); FreePool(glyphs);
@ -2838,19 +2840,26 @@ static void nsvg__parseText(NSVGparser* p, const char** dict)
//if the font is not registered then we have to load new one //if the font is not registered then we have to load new one
NSVGfont *fontSVG = NULL; NSVGfont *fontSVG = NULL;
NSVGfontChain *fontChain = fontsDB; NSVGfontChain *fontChain = fontsDB;
NSVGfontChain *fontChainSimilar = NULL;
while (fontChain) { while (fontChain) {
fontSVG = fontChain->font; fontSVG = fontChain->font;
if (fontSVG) { if (fontSVG) {
DBG("probe fontFamily=%a fontStyle=%c\n", fontSVG->fontFamily, fontSVG->fontStyle); DBG("probe fontFamily=%a fontStyle=%c\n", fontSVG->fontFamily, fontSVG->fontStyle);
if ((strcmp(fontSVG->fontFamily, text->fontFace->fontFamily) == 0) && if (strcmp(fontSVG->fontFamily, text->fontFace->fontFamily) == 0) {
(fontSVG->fontStyle == text->fontStyle)) { fontChainSimilar = fontChain;
DBG("font %a found\n", fontSVG->fontFamily); DBG("font %a found\n", fontSVG->fontFamily);
break; if (fontSVG->fontStyle == text->fontStyle) {
break;
}
} }
} }
fontChain = fontChain->next; fontChain = fontChain->next;
} }
if (!fontChain && fontChainSimilar) { //font with this style is not found but we have same font with other style
DBG("found similar font with style=%c\n", fontChainSimilar->font->fontStyle);
fontChain = fontChainSimilar;
fontSVG = fontChain->font;
}
if (!fontChain) { // font not found in the chain if (!fontChain) { // font not found in the chain
//then load it //then load it
UINT8 *FileData = NULL; UINT8 *FileData = NULL;
@ -2865,24 +2874,27 @@ static void nsvg__parseText(NSVGparser* p, const char** dict)
if (!p1) { if (!p1) {
DBG("font %a not parsed\n", text->fontFace->fontFamily); DBG("font %a not parsed\n", text->fontFace->fontFamily);
} else { } else {
fontSVG = (__typeof__(fontSVG))AllocateCopyPool(sizeof(NSVGfont), p1->font); /* fontSVG = (__typeof__(fontSVG))AllocateCopyPool(sizeof(NSVGfont), p1->font);
DBG("font family %a parsed\n", fontSVG->fontFamily); DBG("font family %a parsed\n", fontSVG->fontFamily);
fontChain = (__typeof__(fontChain))AllocatePool(sizeof(*fontChain)); fontChain = (__typeof__(fontChain))AllocatePool(sizeof(*fontChain));
fontChain->font = fontSVG; fontChain->font = fontSVG;
fontChain->next = fontsDB; fontChain->next = fontsDB;
fontsDB = fontChain; fontsDB = fontChain;
*/
fontSVG = fontsDB->font; //last added during parse file data
text->font = fontSVG; //this is the same pointer as in fontChain but we will never free text->font. We will free fontChain text->font = fontSVG; //this is the same pointer as in fontChain but we will never free text->font. We will free fontChain
} }
FreePool(FileData); //after load FreePool(FileData); //after load
FileData = NULL; FileData = NULL;
} else { } else {
DBG("set embedded font\n");
text->font = p->font; //else embedded if present which is also double fontChain text->font = p->font; //else embedded if present which is also double fontChain
} }
} else { } else {
DBG("set found font %a\n", fontSVG->id); DBG("set found font %a\n", fontSVG->fontFamily);
text->font = fontSVG; //the font found in fontChain text->font = fontSVG; //the font found in fontChain
} }
//instead of embedded //instead of embedded
if (fontSVG && fontSVG->glyphs) { if (fontSVG && fontSVG->glyphs) {
NSVGgroup* group = attr->group; NSVGgroup* group = attr->group;
@ -3557,7 +3569,7 @@ static void nsvg__parseFont(NSVGparser* p, const char** dict)
if (!font->horizAdvX) { if (!font->horizAdvX) {
font->horizAdvX = 1000; font->horizAdvX = 1000;
} }
DBG("found font id=%a\n", font->id); DBG("found font id=%a family=%a\n", font->id, font->fontFamily);
NSVGfontChain* fontChain = (__typeof__(fontChain))AllocatePool(sizeof(*fontChain)); NSVGfontChain* fontChain = (__typeof__(fontChain))AllocatePool(sizeof(*fontChain));
fontChain->font = font; fontChain->font = font;
@ -4303,7 +4315,12 @@ NSVGparser* nsvgParse(char* input, /* const char* units,*/ float dpi, float opac
} }
p->dpi = dpi; p->dpi = dpi;
p->opacity = opacity; p->opacity = opacity;
// DBG("fontDb=%x\n", (UINTN)fontsDB);
nsvg__parseXML(input, nsvg__startElement, nsvg__endElement, nsvg__content, p); nsvg__parseXML(input, nsvg__startElement, nsvg__endElement, nsvg__content, p);
// DBG("fontDb after parse=%x\n", (UINTN)fontsDB);
// if (fontsDB && fontsDB->font) {
// DBG("added font=%a\n", fontsDB->font->fontFamily); //yes, fonts added here
// }
//assign gradients //assign gradients
clipPath = p->image->clipPaths; clipPath = p->image->clipPaths;
while (clipPath != NULL) { while (clipPath != NULL) {

View File

@ -108,7 +108,7 @@ typedef struct NSVGgradientStop {
float offset; float offset;
} NSVGgradientStop; } NSVGgradientStop;
typedef struct NSVGgradient { typedef struct NSVGgradient { //undefined sizeof
float xform[6]; float xform[6];
// float position[6]; // float position[6];
float fx, fy; float fx, fy;

View File

@ -630,7 +630,6 @@ static VOID StartLoader(IN LOADER_ENTRY *Entry)
// OSIcons // OSIcons
NSVGfontChain *fontChain = fontsDB; NSVGfontChain *fontChain = fontsDB;
while (fontChain) { while (fontChain) {
DBG("free fontChain \n");
font = fontChain->font; font = fontChain->font;
NSVGfontChain *nextChain = fontChain->next; NSVGfontChain *nextChain = fontChain->next;
if (font) { if (font) {
@ -638,8 +637,9 @@ static VOID StartLoader(IN LOADER_ENTRY *Entry)
fontChain->font = NULL; fontChain->font = NULL;
} }
FreePool(fontChain); FreePool(fontChain);
fontChain = nextChain->next; fontChain = nextChain;
} }
fontsDB = NULL;
// nsvg__deleteParser(mainParser); //temporary disabled // nsvg__deleteParser(mainParser); //temporary disabled
//destruct_globals_objects(NULL); //we can't destruct our globals here. We need, for example, Volumes. //destruct_globals_objects(NULL); //we can't destruct our globals here. We need, for example, Volumes.