Skip to content

Commit

Permalink
some text formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Slice <sergey.slice@gmail.com>
  • Loading branch information
SergeySlice committed Jul 16, 2023
1 parent 7bec54e commit 9c3e543
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 99 deletions.
1 change: 1 addition & 0 deletions rEFIt_UEFI/libeg/VectorGraphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ EFI_STATUS XTheme::ParseSVGXIcon(INTN Id, const XString8& IconNameX, OUT XImage*
shapeNext = shape->next;
while (group) {
if (strcmp(group->id, IconNameX.c_str()) == 0) {
strncpy(IconImage->id, group->id, 63);
break;
}
group = group->next;
Expand Down
49 changes: 25 additions & 24 deletions rEFIt_UEFI/libeg/nanosvg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#include "BmLib.h"

#ifndef DEBUG_ALL
#define DEBUG_SVG 0
#define DEBUG_SVG 1
#else
#define DEBUG_SVG DEBUG_ALL
#endif
Expand Down Expand Up @@ -980,7 +980,7 @@ static void nsvg__addShape(NSVGparser* p)
NSVGattrib* attr = nsvg__getAttr(p);
float scale;
NSVGshape* shape;
int i;
// int i;

if (p->plist == NULL /*&& !p->isText*/ )
return;
Expand All @@ -990,13 +990,13 @@ static void nsvg__addShape(NSVGparser* p)

memcpy(shape->id, attr->id, sizeof shape->id);
memcpy(shape->title, attr->title, sizeof shape->title);
// DBG("shapeID=%s\n", shape->id);
// DBG("parse shapeID=%s\n", shape->id);
shape->group = attr->group;
scale = nsvg__getAverageScale(attr->xform); //ssss
shape->strokeWidth = attr->strokeWidth * scale;
shape->strokeDashOffset = attr->strokeDashOffset * scale;
shape->strokeDashCount = (char)attr->strokeDashCount;
for (i = 0; i < attr->strokeDashCount; i++)
for (int i = 0; i < attr->strokeDashCount; i++)
shape->strokeDashArray[i] = attr->strokeDashArray[i] * scale;
shape->strokeLineJoin = attr->strokeLineJoin;
shape->strokeLineCap = attr->strokeLineCap;
Expand Down Expand Up @@ -1089,7 +1089,8 @@ static void nsvg__addShape(NSVGparser* p)
if (p->clipPath != NULL) {
shape->next = p->clipPath->shapes;
p->clipPath->shapes = shape;
} else if (p->symbolFlag) {
} else
if (p->symbolFlag) {
if (p->symbols->shapes == NULL)
p->symbols->shapes = shape;
else
Expand All @@ -1112,7 +1113,7 @@ static void nsvg__addPath(NSVGparser* p, char closed)
NSVGpath* path = NULL;
float bounds[4];
float* curve;
int i;
// int i;

if (p->npts < 4)
return;
Expand All @@ -1138,7 +1139,7 @@ static void nsvg__addPath(NSVGparser* p, char closed)
memcpy(path->pts, p->pts, p->npts * 2 * sizeof(float));

// Find bounds
for (i = 0; i < path->npts-1; i += 3) {
for (int i = 0; i < path->npts-1; i += 3) {
curve = &path->pts[i*2];
nsvg__curveBounds(bounds, curve);
if (i == 0) {
Expand Down Expand Up @@ -2863,7 +2864,7 @@ static void nsvg__parseTextSpan(NSVGparser* p, char** dict)
NSVGtext* text = p->text;
float x = 0.f, y = 0.f, r = 0.f;
int i;
DBG("parse textSpan\n");
// DBG("parse textSpan\n");
//there should be text->next with own attribs
for (i = 0; dict[i]; i += 2) {
if (strcmp(dict[i], "x") == 0) {
Expand Down Expand Up @@ -2921,7 +2922,7 @@ static void nsvg__parseText(NSVGparser* p, char** dict)
NSVGattrib* attr = nsvg__getAttr(p);

int i;
DBG("text found\n");
// DBG("text found\n");
NSVGtext* text = (NSVGtext*)AllocateZeroPool(sizeof(NSVGtext));
if (!text) {
return;
Expand All @@ -2938,7 +2939,7 @@ static void nsvg__parseText(NSVGparser* p, char** dict)
nsvg__parseAttr(p, dict[i], dict[i + 1]);
}
}
DBG("text: x=%f y=%f attr:Style=%hhX, size=%f, id=%s\n", x, y, attr->fontFace->fontStyle, attr->fontFace->fontSize, attr->id);
// DBG("text: x=%f y=%f attr:Style=%hhX, size=%f, id=%s\n", x, y, attr->fontFace->fontStyle, attr->fontFace->fontSize, attr->id);
text->x = x;
text->y = y;
text->fontSize = attr->fontFace->fontSize;
Expand All @@ -2957,18 +2958,18 @@ static void nsvg__parseText(NSVGparser* p, char** dict)
if (text->fontStyle < 0x30) {
text->fontStyle = 'n';
}
DBG("required font %s required style=%c\n", text->fontFace->fontFamily, text->fontStyle);
// DBG("required font %s required style=%c\n", text->fontFace->fontFamily, text->fontStyle);
//if the font is not registered then we have to load new one
NSVGfont *fontSVG = NULL;
NSVGfontChain *fontChain = fontsDB;
NSVGfontChain *fontChainSimilar = NULL;
while (fontChain) {
fontSVG = fontChain->font;
if (fontSVG) {
DBG("probe fontFamily=%s fontStyle=%c\n", fontSVG->fontFamily, fontSVG->fontStyle);
// DBG("probe fontFamily=%s fontStyle=%c\n", fontSVG->fontFamily, fontSVG->fontStyle);
if (strcmp(fontSVG->fontFamily, text->fontFace->fontFamily) == 0) {
fontChainSimilar = fontChain;
DBG("font %s found\n", fontSVG->fontFamily);
// DBG("font %s found\n", fontSVG->fontFamily);
if (fontSVG->fontStyle == text->fontStyle) {
break;
}
Expand All @@ -2995,19 +2996,19 @@ static void nsvg__parseText(NSVGparser* p, char** dict)
if (!EFI_ERROR(Status)) {
p1 = nsvgParse((CHAR8*)FileData, 72, 1.0f); //later we will free parser p1
if (!p1) {
DBG("font %s not parsed\n", text->fontFace->fontFamily);
// DBG("font %s not parsed\n", text->fontFace->fontFamily);
} else {
fontSVG = fontsDB->font; //last added during parse file data
text->font = fontSVG;
}
FreePool(FileData); //after load
FileData = NULL;
} else {
DBG("set embedded font\n");
// DBG("set embedded font\n");
text->font = p->font; //else embedded if present which is also double fontChain
}
} else {
DBG("set found font %s\n", fontSVG->fontFamily);
// DBG("set found font %s\n", fontSVG->fontFamily);
text->font = fontSVG; //the font found in fontChain
}

Expand All @@ -3025,7 +3026,7 @@ static void nsvg__parseText(NSVGparser* p, char** dict)
textFace[1].size = (INTN)text->fontSize;
textFace[1].color = text->fontColor;
textFace[1].valid = true;
DBG("set message->font=%s color=%X size=%f as in MessageRow\n", fontSVG->fontFamily, text->fontColor, text->fontSize);
// DBG("set message->font=%s color=%X size=%f as in MessageRow\n", fontSVG->fontFamily, text->fontColor, text->fontSize);
}
break;
} else if (!ThemeX.Daylight && strcmp(group->id, "MessageRow_night") == 0) {
Expand All @@ -3037,15 +3038,15 @@ static void nsvg__parseText(NSVGparser* p, char** dict)
textFace[1].size = (INTN)text->fontSize;
textFace[1].color = text->fontColor;
textFace[1].valid = true;
DBG("set message_night->font=%s color=%X size=%f as in MessageRow\n", fontSVG->fontFamily, text->fontColor, text->fontSize);
// DBG("set message_night->font=%s color=%X size=%f as in MessageRow\n", fontSVG->fontFamily, text->fontColor, text->fontSize);
break;
} else if (strcmp(group->id, "MenuRows") == 0) {
if (!textFace[2].valid) {
textFace[2].font = fontSVG;
textFace[2].size = (INTN)text->fontSize;
textFace[2].color = text->fontColor;
textFace[2].valid = true;
DBG("set menu->font=%s color=%X size=%f as in MenuRows\n", fontSVG->fontFamily, text->fontColor, text->fontSize);
// DBG("set menu->font=%s color=%X size=%f as in MenuRows\n", fontSVG->fontFamily, text->fontColor, text->fontSize);
}
break;
} else if (!ThemeX.Daylight && strcmp(group->id, "MenuRows_night") == 0) {
Expand All @@ -3060,15 +3061,15 @@ static void nsvg__parseText(NSVGparser* p, char** dict)
textFace[0].size = (INTN)text->fontSize;
textFace[0].color = text->fontColor;
textFace[0].valid = true;
DBG("set help->font=%s color=%X size=%f as in HelpRows\n", fontSVG->fontFamily, text->fontColor, text->fontSize);
// DBG("set help->font=%s color=%X size=%f as in HelpRows\n", fontSVG->fontFamily, text->fontColor, text->fontSize);
}
break;
} else if (!ThemeX.Daylight && strstr(group->id, "HelpRows_night") != NULL) {
textFace[0].font = fontSVG;
textFace[0].size = (INTN)text->fontSize;
textFace[0].color = text->fontColor;
textFace[0].valid = true;
DBG("set help_night->font=%s color=%X size=%f as in HelpRows\n", fontSVG->fontFamily, text->fontColor, text->fontSize);
// DBG("set help_night->font=%s color=%X size=%f as in HelpRows\n", fontSVG->fontFamily, text->fontColor, text->fontSize);
break;
}
group = group->next;
Expand Down Expand Up @@ -3689,7 +3690,7 @@ static void nsvg__parseFont(NSVGparser* p, char** dict)
if (!font->horizAdvX) {
font->horizAdvX = 1000;
}
DBG("found font id=%s family=%s\n", font->id, font->fontFamily);
// DBG("found font id=%s family=%s\n", font->id, font->fontFamily);

NSVGfontChain* fontChain = (decltype(fontChain))AllocatePool(sizeof(*fontChain));
fontChain->font = font;
Expand All @@ -3703,7 +3704,7 @@ static void nsvg__parseFontFace(NSVGparser* p, char** dict)
{
int i;
if (!p) {
DBG("no parser\n");
// DBG("no parser\n");
return;
}
NSVGfont* font = p->font; //if present??? assumed good svg structure
Expand All @@ -3714,7 +3715,7 @@ static void nsvg__parseFontFace(NSVGparser* p, char** dict)
for (i = 0; dict[i]; i += 2) {
if (strcmp(dict[i], "font-family") == 0) {
AsciiStrCpyS(font->fontFamily, 64, dict[i+1]);
DBG("font-family %s\n", font->fontFamily);
// DBG("font-family %s\n", font->fontFamily);
}
else if (strcmp(dict[i], "font-weight") == 0) {
float fontWeight = 0.0f;
Expand Down
37 changes: 25 additions & 12 deletions rEFIt_UEFI/libeg/nanosvg.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#define NANOSVG_H

extern "C" {
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
}
#include "libeg.h"
Expand Down Expand Up @@ -130,13 +131,13 @@ typedef struct NSVGpath
struct NSVGpath* next; // Pointer to next path, or NULL if last element.
} NSVGpath;

typedef unsigned char NSVGclipPathIndex;
typedef unsigned short NSVGclipPathIndex;

typedef struct NSVGclip
{
NSVGclipPathIndex* index; // Array of clip path indices (of related NSVGimage).
NSVGclipPathIndex count; // Number of clip paths in this set.
char pad[7];
char pad[6];
} NSVGclip;


Expand Down Expand Up @@ -174,7 +175,7 @@ typedef struct NSVGshape
char strokeLineJoin; // Stroke join type.
char strokeLineCap; // Stroke cap type.
char fillRule; // Fill rule, see NSVGfillRule.
unsigned char flags; // Logical or of NSVG_FLAGS_* flags
UINT8 flags; // Logical or of NSVG_FLAGS_* flags
XBool isText;
XBool debug;
XBool isSymbol;
Expand All @@ -201,6 +202,7 @@ typedef struct NSVGclipPath

typedef struct NSVGimage
{
char id[kMaxIDLength]; // Unique id of this image
float width; // Width of the image.
float height; // Height of the image.
float realBounds[4];
Expand All @@ -212,8 +214,8 @@ typedef struct NSVGimage
NSVGclipPath* clipPaths;
} NSVGimage;

#define NSVG_MAX_ATTR 1024
#define NSVG_MAX_CLIP_PATHS 255 // also note NSVGclipPathIndex
#define NSVG_MAX_ATTR 2048
#define NSVG_MAX_CLIP_PATHS 1024 // also note NSVGclipPathIndex

enum NSVGgradientUnits {
NSVG_USER_SPACE = 0,
Expand Down Expand Up @@ -302,6 +304,7 @@ typedef struct NSVGattrib
char hasStroke;
char visible;
NSVGclipPathIndex clipPathCount;
NSVGclipPathIndex clipPathStack[NSVG_MAX_CLIP_PATHS];
NSVGgroup* group;
// NSVGpattern* pattern;
} NSVGattrib;
Expand Down Expand Up @@ -480,7 +483,7 @@ NSVGrasterizer* nsvgCreateRasterizer(void);
// stride - number of bytes per scaleline in the destination buffer
void nsvgRasterize(NSVGrasterizer* r,
NSVGimage* image, float tx, float ty, float scalex, float scaley,
unsigned char* dst, int w, int h, int stride);
UINT8* dst, int w, int h, int stride);

// Deletes rasterizer context.
void nsvgDeleteRasterizer(NSVGrasterizer*);
Expand All @@ -503,7 +506,7 @@ typedef struct NSVGpoint {
float dx, dy;
float len;
float dmx, dmy;
unsigned char flags;
UINT8 flags;
char pad[3];
} NSVGpoint;

Expand All @@ -515,7 +518,7 @@ typedef struct NSVGactiveEdge {
} NSVGactiveEdge;

typedef struct NSVGmemPage {
unsigned char mem[NSVG__MEMPAGE_SIZE];
UINT8 mem[NSVG__MEMPAGE_SIZE];
int size;
struct NSVGmemPage* next;
} NSVGmemPage;
Expand All @@ -533,9 +536,17 @@ typedef struct NSVGcachedPaint {
} NSVGcachedPaint;

typedef void (*NSVGscanlineFunction)(
unsigned char* dst, int count, unsigned char* cover, int x, int y,
UINT8* dst, int count, UINT8* cover, int x, int y,
/* float tx, float ty, float scalex, float scaley, */ NSVGcachedPaint* cache);

typedef struct NSVGstencil
{
UINT8* square;
int width, height, stride;
NSVGclipPathIndex index;
struct NSVGstencil* next;
} NSVGstencil;

struct NSVGrasterizer
{
float px, py;
Expand All @@ -559,16 +570,18 @@ struct NSVGrasterizer
NSVGmemPage* pages;
NSVGmemPage* curpage;

unsigned char* scanline;
UINT8* scanline;
int cscanline;
NSVGscanlineFunction fscanline;

unsigned char* stencil;
UINT8* stencil;
int stencilSize;
int stencilStride;

unsigned char* bitmap;
UINT8* bitmap;
int width, height, stride;

NSVGstencil* stencilList;
};

extern NSVGfontChain *fontsDB;
Expand Down
Loading

0 comments on commit 9c3e543

Please sign in to comment.