mirror of
https://github.com/CloverHackyColor/CloverBootloader.git
synced 2024-11-12 09:54:36 +01:00
some text formatting
Signed-off-by: Slice <sergey.slice@gmail.com>
This commit is contained in:
parent
7bec54ee89
commit
9c3e5436ac
@ -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;
|
||||
|
@ -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
|
||||
@ -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;
|
||||
@ -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;
|
||||
@ -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
|
||||
@ -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;
|
||||
@ -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) {
|
||||
@ -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) {
|
||||
@ -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;
|
||||
@ -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;
|
||||
@ -2957,7 +2958,7 @@ 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;
|
||||
@ -2965,10 +2966,10 @@ static void nsvg__parseText(NSVGparser* p, char** dict)
|
||||
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;
|
||||
}
|
||||
@ -2995,7 +2996,7 @@ 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;
|
||||
@ -3003,11 +3004,11 @@ static void nsvg__parseText(NSVGparser* p, char** dict)
|
||||
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
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
@ -3037,7 +3038,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_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) {
|
||||
@ -3045,7 +3046,7 @@ static void nsvg__parseText(NSVGparser* p, char** dict)
|
||||
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) {
|
||||
@ -3060,7 +3061,7 @@ 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) {
|
||||
@ -3068,7 +3069,7 @@ 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_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;
|
||||
@ -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;
|
||||
@ -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
|
||||
@ -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;
|
||||
|
@ -43,6 +43,7 @@
|
||||
#define NANOSVG_H
|
||||
|
||||
extern "C" {
|
||||
#include <Library/DebugLib.h>
|
||||
#include <Library/BaseMemoryLib.h>
|
||||
}
|
||||
#include "libeg.h"
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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;
|
||||
@ -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];
|
||||
@ -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,
|
||||
@ -302,6 +304,7 @@ typedef struct NSVGattrib
|
||||
char hasStroke;
|
||||
char visible;
|
||||
NSVGclipPathIndex clipPathCount;
|
||||
NSVGclipPathIndex clipPathStack[NSVG_MAX_CLIP_PATHS];
|
||||
NSVGgroup* group;
|
||||
// NSVGpattern* pattern;
|
||||
} NSVGattrib;
|
||||
@ -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*);
|
||||
@ -503,7 +506,7 @@ typedef struct NSVGpoint {
|
||||
float dx, dy;
|
||||
float len;
|
||||
float dmx, dmy;
|
||||
unsigned char flags;
|
||||
UINT8 flags;
|
||||
char pad[3];
|
||||
} NSVGpoint;
|
||||
|
||||
@ -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;
|
||||
@ -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;
|
||||
@ -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;
|
||||
|
@ -29,7 +29,7 @@
|
||||
// Create rasterizer (can be used to render multiple images).
|
||||
struct NSVGrasterizer* rast = nsvgCreateRasterizer();
|
||||
// Allocate memory for image
|
||||
unsigned char* img = malloc(w*h*4);
|
||||
UINT8* img = malloc(w*h*4);
|
||||
// Rasterize
|
||||
scaleX = width_to_see / design_width
|
||||
nsvgRasterize(rast, image, 0,0, scaleX, scaleY, img, w, h, w*4);
|
||||
@ -38,9 +38,10 @@
|
||||
#include "nanosvg.h"
|
||||
#include "FloatLib.h"
|
||||
#include "XImage.h"
|
||||
#include "../Platform/Utils.h"
|
||||
|
||||
#ifndef DEBUG_ALL
|
||||
#define DEBUG_SVG 0
|
||||
#define DEBUG_SVG 1
|
||||
#else
|
||||
#define DEBUG_SVG DEBUG_ALL
|
||||
#endif
|
||||
@ -125,6 +126,7 @@ NSVGrasterizer* nsvgCreateRasterizer()
|
||||
if (r == NULL) return NULL;
|
||||
r->tessTol = 0.1f; //0.25f;
|
||||
r->distTol = 0.01f;
|
||||
r->stencilList = NULL;
|
||||
return r;
|
||||
}
|
||||
|
||||
@ -147,6 +149,14 @@ void nsvgDeleteRasterizer(NSVGrasterizer* r)
|
||||
if (r->scanline) FreePool(r->scanline);
|
||||
if (r->stencil) FreePool(r->stencil);
|
||||
|
||||
NSVGstencil* s = r->stencilList;
|
||||
while ( s != NULL) {
|
||||
NSVGstencil* next = s->next;
|
||||
if (s->square) FreePool(s->square);
|
||||
FreePool(s);
|
||||
s = next;
|
||||
}
|
||||
|
||||
FreePool(r);
|
||||
}
|
||||
|
||||
@ -183,9 +193,9 @@ static void nsvg__resetPool(NSVGrasterizer* r)
|
||||
r->curpage = r->pages;
|
||||
}
|
||||
|
||||
static unsigned char* nsvg__alloc(NSVGrasterizer* r, int size)
|
||||
static UINT8* nsvg__alloc(NSVGrasterizer* r, int size)
|
||||
{
|
||||
unsigned char* buf;
|
||||
UINT8* buf;
|
||||
if (size > NSVG__MEMPAGE_SIZE) return NULL;
|
||||
if (r->curpage == NULL || r->curpage->size+size > NSVG__MEMPAGE_SIZE) {
|
||||
r->curpage = nsvg__nextPage(r, r->curpage);
|
||||
@ -217,7 +227,7 @@ static void nsvg__addPathPoint(NSVGrasterizer* r, NSVGpoint* pt, float* t, int f
|
||||
if (r->npoints > 0) {
|
||||
pt1 = &r->points[r->npoints-1];
|
||||
if (nsvg__ptEquals(pt1, &pt2, r->distTol)) {
|
||||
r->points[r->npoints-1].flags |= (unsigned char)flags;
|
||||
r->points[r->npoints-1].flags |= (UINT8)flags;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -237,7 +247,7 @@ static void nsvg__addPathPoint(NSVGrasterizer* r, NSVGpoint* pt, float* t, int f
|
||||
|
||||
pt1->x = pt2.x;
|
||||
pt1->y = pt2.y;
|
||||
pt1->flags = (unsigned char)flags;
|
||||
pt1->flags = (UINT8)flags;
|
||||
r->npoints++;
|
||||
}
|
||||
|
||||
@ -965,7 +975,7 @@ static void nsvg__freeActive(NSVGrasterizer* r, NSVGactiveEdge* z)
|
||||
r->freelist = z;
|
||||
}
|
||||
|
||||
static void nsvg__fillScanline(unsigned char* scanline, int len, int x0, int x1, int maxWeight, int* xmin, int* xmax)
|
||||
static void nsvg__fillScanline(UINT8* scanline, int len, int x0, int x1, int maxWeight, int* xmin, int* xmax)
|
||||
{
|
||||
int i = x0 >> NSVG__FIXSHIFT;
|
||||
int j = x1 >> NSVG__FIXSHIFT;
|
||||
@ -974,20 +984,20 @@ static void nsvg__fillScanline(unsigned char* scanline, int len, int x0, int x1,
|
||||
if (i < len && j >= 0) {
|
||||
if (i == j) {
|
||||
// x0,x1 are the same pixel, so compute combined coverage
|
||||
scanline[i] = (unsigned char)(scanline[i] + ((x1 - x0) * maxWeight >> NSVG__FIXSHIFT));
|
||||
scanline[i] = (UINT8)(scanline[i] + ((x1 - x0) * maxWeight >> NSVG__FIXSHIFT));
|
||||
} else {
|
||||
if (i >= 0) // add antialiasing for x0
|
||||
scanline[i] = (unsigned char)(scanline[i] + (((NSVG__FIX - (x0 & NSVG__FIXMASK)) * maxWeight) >> NSVG__FIXSHIFT));
|
||||
scanline[i] = (UINT8)(scanline[i] + (((NSVG__FIX - (x0 & NSVG__FIXMASK)) * maxWeight) >> NSVG__FIXSHIFT));
|
||||
else
|
||||
i = -1; // clip
|
||||
|
||||
if (j < len) // add antialiasing for x1
|
||||
scanline[j] = (unsigned char)(scanline[j] + (((x1 & NSVG__FIXMASK) * maxWeight) >> NSVG__FIXSHIFT));
|
||||
scanline[j] = (UINT8)(scanline[j] + (((x1 & NSVG__FIXMASK) * maxWeight) >> NSVG__FIXSHIFT));
|
||||
else
|
||||
j = len; // clip
|
||||
|
||||
for (++i; i < j; ++i) // fill pixels between x0 and x1
|
||||
scanline[i] = (unsigned char)(scanline[i] + maxWeight);
|
||||
scanline[i] = (UINT8)(scanline[i] + maxWeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -995,7 +1005,7 @@ static void nsvg__fillScanline(unsigned char* scanline, int len, int x0, int x1,
|
||||
// note: this routine clips fills that extend off the edges... ideally this
|
||||
// wouldn't happen, but it could happen if the truetype glyph bounding boxes
|
||||
// are wrong, or if the user supplies a too-small bitmap
|
||||
static void nsvg__fillActiveEdges(unsigned char* scanline, int len, NSVGactiveEdge* e, int maxWeight, int* xmin, int* xmax, char fillRule)
|
||||
static void nsvg__fillActiveEdges(UINT8* scanline, int len, NSVGactiveEdge* e, int maxWeight, int* xmin, int* xmax, char fillRule)
|
||||
{
|
||||
// non-zero winding fill
|
||||
int x0 = 0, w = 0;
|
||||
@ -1034,7 +1044,7 @@ static float nsvg__clampf(float a, float mn, float mx)
|
||||
return a < mn ? mn : (a > mx ? mx : a);
|
||||
}
|
||||
|
||||
static unsigned int nsvg__RGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
|
||||
static UINT32 nsvg__RGBA(UINT8 r, UINT8 g, UINT8 b, UINT8 a)
|
||||
{
|
||||
return (b) | (g << 8) | (r << 16) | (a << 24);
|
||||
}
|
||||
@ -1048,7 +1058,7 @@ static unsigned int nsvg__lerpRGBA(unsigned int c0, unsigned int c1, float u, fl
|
||||
int g = (((c0>>8) & 0xff)*(256-iu) + (((c1>>8) & 0xff)*iu)) >> 8;
|
||||
int r = (((c0>>16) & 0xff)*(256-iu) + (((c1>>16) & 0xff)*iu)) >> 8;
|
||||
int a = ((((c0>>24) & 0xff)*(256-iu) + (((c1>>24) & 0xff)*iu)) * ia) >> 16;
|
||||
return nsvg__RGBA((unsigned char)r, (unsigned char)g, (unsigned char)b, (unsigned char)a);
|
||||
return nsvg__RGBA((UINT8)r, (UINT8)g, (UINT8)b, (UINT8)a);
|
||||
}
|
||||
|
||||
static unsigned int nsvg__applyOpacity(unsigned int c, float u)
|
||||
@ -1058,7 +1068,7 @@ static unsigned int nsvg__applyOpacity(unsigned int c, float u)
|
||||
int g = (c>>8) & 0xff;
|
||||
int r = (c>>16) & 0xff;
|
||||
int a = (((c>>24) & 0xff)*iu) >> 8;
|
||||
return nsvg__RGBA((unsigned char)r, (unsigned char)g, (unsigned char)b, (unsigned char)a);
|
||||
return nsvg__RGBA((UINT8)r, (UINT8)g, (UINT8)b, (UINT8)a);
|
||||
}
|
||||
|
||||
static inline int nsvg__div255(int x)
|
||||
@ -1067,7 +1077,7 @@ static inline int nsvg__div255(int x)
|
||||
}
|
||||
|
||||
static void nsvg__scanlineBit(
|
||||
unsigned char* row, int count, unsigned char* cover, int x, int y,
|
||||
UINT8* row, int count, UINT8* cover, int x, int y,
|
||||
/* float tx, float ty, float scalex, float scaley, */ NSVGcachedPaint* cache)
|
||||
{
|
||||
//xxx where is security check that x/8 and (x+count)/8 is inside row[] index?
|
||||
@ -1078,11 +1088,11 @@ static void nsvg__scanlineBit(
|
||||
}
|
||||
}
|
||||
|
||||
static void nsvg__scanlineSolid(unsigned char* row, int count, unsigned char* cover, int x, int y,
|
||||
static void nsvg__scanlineSolid(UINT8* row, int count, UINT8* cover, int x, int y,
|
||||
/* float tx, float ty, float scalex, float scaley, */ NSVGcachedPaint* cache)
|
||||
{
|
||||
// static int once = 0;
|
||||
unsigned char* dst = row + x*4;
|
||||
UINT8* dst = row + x*4;
|
||||
if (cache->type == NSVG_PAINT_COLOR) {
|
||||
int cr, cg, cb, ca;
|
||||
cr = cache->colors[0] & 0xff;
|
||||
@ -1105,10 +1115,10 @@ static void nsvg__scanlineSolid(unsigned char* row, int count, unsigned char* co
|
||||
b += nsvg__div255(ia * (int)dst[2]);
|
||||
a += nsvg__div255(ia * (int)dst[3]);
|
||||
|
||||
dst[0] = (unsigned char)r;
|
||||
dst[1] = (unsigned char)g;
|
||||
dst[2] = (unsigned char)b;
|
||||
dst[3] = (unsigned char)a;
|
||||
dst[0] = (UINT8)r;
|
||||
dst[1] = (UINT8)g;
|
||||
dst[2] = (UINT8)b;
|
||||
dst[3] = (UINT8)a;
|
||||
|
||||
cover++;
|
||||
dst += 4;
|
||||
@ -1148,10 +1158,10 @@ static void nsvg__scanlineSolid(unsigned char* row, int count, unsigned char* co
|
||||
g += nsvg__div255(ia * (int)dst[1]);
|
||||
b += nsvg__div255(ia * (int)dst[2]);
|
||||
a += nsvg__div255(ia * (int)dst[3]);
|
||||
dst[0] = (unsigned char)r;
|
||||
dst[1] = (unsigned char)g;
|
||||
dst[2] = (unsigned char)b;
|
||||
dst[3] = (unsigned char)a;
|
||||
dst[0] = (UINT8)r;
|
||||
dst[1] = (UINT8)g;
|
||||
dst[2] = (UINT8)b;
|
||||
dst[3] = (UINT8)a;
|
||||
|
||||
cover++;
|
||||
dst += 4;
|
||||
@ -1198,10 +1208,10 @@ static void nsvg__scanlineSolid(unsigned char* row, int count, unsigned char* co
|
||||
b += nsvg__div255(ia * (int)dst[2]);
|
||||
a += nsvg__div255(ia * (int)dst[3]);
|
||||
|
||||
dst[0] = (unsigned char)r;
|
||||
dst[1] = (unsigned char)g;
|
||||
dst[2] = (unsigned char)b;
|
||||
dst[3] = (unsigned char)a;
|
||||
dst[0] = (UINT8)r;
|
||||
dst[1] = (UINT8)g;
|
||||
dst[2] = (UINT8)b;
|
||||
dst[3] = (UINT8)a;
|
||||
|
||||
cover++;
|
||||
dst += 4;
|
||||
@ -1254,10 +1264,10 @@ static void nsvg__scanlineSolid(unsigned char* row, int count, unsigned char* co
|
||||
b += nsvg__div255(ia * (int)dst[2]);
|
||||
a += nsvg__div255(ia * (int)dst[3]);
|
||||
|
||||
dst[0] = (unsigned char)r;
|
||||
dst[1] = (unsigned char)g;
|
||||
dst[2] = (unsigned char)b;
|
||||
dst[3] = (unsigned char)a;
|
||||
dst[0] = (UINT8)r;
|
||||
dst[1] = (UINT8)g;
|
||||
dst[2] = (UINT8)b;
|
||||
dst[3] = (UINT8)a;
|
||||
|
||||
cover++;
|
||||
dst += 4;
|
||||
@ -1307,10 +1317,10 @@ static void nsvg__scanlineSolid(unsigned char* row, int count, unsigned char* co
|
||||
b += nsvg__div255(ia * (int)dst[2]);
|
||||
a += nsvg__div255(ia * (int)dst[3]);
|
||||
|
||||
dst[0] = (unsigned char)r;
|
||||
dst[1] = (unsigned char)g;
|
||||
dst[2] = (unsigned char)b;
|
||||
dst[3] = (unsigned char)a;
|
||||
dst[0] = (UINT8)r;
|
||||
dst[1] = (UINT8)g;
|
||||
dst[2] = (UINT8)b;
|
||||
dst[3] = (UINT8)a;
|
||||
|
||||
cover++;
|
||||
dst += 4;
|
||||
@ -1321,6 +1331,16 @@ static void nsvg__scanlineSolid(unsigned char* row, int count, unsigned char* co
|
||||
}
|
||||
}
|
||||
|
||||
UINT8* FindStencil(NSVGrasterizer *r, int index)
|
||||
{
|
||||
NSVGstencil* sl = r->stencilList;
|
||||
while (sl != NULL) {
|
||||
if (sl->index == index) return sl->square;
|
||||
sl = sl->next;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void nsvg__rasterizeSortedEdges(NSVGrasterizer *r,
|
||||
/* float tx, float ty, float scalex, float scaley, */
|
||||
NSVGcachedPaint* cache, char fillRule, NSVGclip* clip)
|
||||
@ -1408,10 +1428,13 @@ static void nsvg__rasterizeSortedEdges(NSVGrasterizer *r,
|
||||
// nsvg__scanlineSolid(&r->bitmap[y * r->stride] + xmin*4, xmax-xmin+1, &r->scanline[xmin], xmin, y, tx,ty, scalex, scaley, cache);
|
||||
|
||||
for (int i = 0; i < clip->count; i++) {
|
||||
unsigned char* stencil = &r->stencil[r->stencilSize * clip->index[i] + y * r->stencilStride];
|
||||
for (int j = xmin; j <= xmax; j++) {
|
||||
if (((stencil[j / 8] >> (j % 8)) & 1) == 0) {
|
||||
r->scanline[j] = 0;
|
||||
UINT8* stencil = &r->stencil[r->stencilSize * clip->index[i] + y * r->stencilStride];
|
||||
// UINT8* stencil = FindStencil(r, clip->index[i]);
|
||||
if (stencil) {
|
||||
for (int j = xmin; j <= xmax; j++) {
|
||||
if (((stencil[j / 8] >> (j % 8)) & 1) == 0) {
|
||||
r->scanline[j] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1421,18 +1444,18 @@ static void nsvg__rasterizeSortedEdges(NSVGrasterizer *r,
|
||||
}
|
||||
}
|
||||
|
||||
static void nsvg__unpremultiplyAlpha(unsigned char* image, int w, int h, int stride)
|
||||
static void nsvg__unpremultiplyAlpha(UINT8* image, int w, int h, int stride)
|
||||
{
|
||||
|
||||
// Unpremultiply
|
||||
for (int y = 0; y < h; y++) {
|
||||
unsigned char *row = &image[y*stride];
|
||||
UINT8 *row = &image[y*stride];
|
||||
for (int x = 0; x < w; x++) {
|
||||
int r = row[0], g = row[1], b = row[2], a = row[3];
|
||||
if (a != 0) {
|
||||
row[0] = (unsigned char)(r*255/a);
|
||||
row[1] = (unsigned char)(g*255/a);
|
||||
row[2] = (unsigned char)(b*255/a);
|
||||
row[0] = (UINT8)(r*255/a);
|
||||
row[1] = (UINT8)(g*255/a);
|
||||
row[2] = (UINT8)(b*255/a);
|
||||
}
|
||||
row += 4;
|
||||
}
|
||||
@ -1440,7 +1463,7 @@ static void nsvg__unpremultiplyAlpha(unsigned char* image, int w, int h, int str
|
||||
|
||||
// Defringe
|
||||
for (int y = 0; y < h; y++) {
|
||||
unsigned char *row = &image[y*stride];
|
||||
UINT8 *row = &image[y*stride];
|
||||
for (int x = 0; x < w; x++) {
|
||||
int r = 0, g = 0, b = 0, a = row[3], n = 0;
|
||||
if (a == 0) {
|
||||
@ -1469,9 +1492,9 @@ static void nsvg__unpremultiplyAlpha(unsigned char* image, int w, int h, int str
|
||||
n++;
|
||||
}
|
||||
if (n > 0) {
|
||||
row[0] = (unsigned char)(r/n);
|
||||
row[1] = (unsigned char)(g/n);
|
||||
row[2] = (unsigned char)(b/n);
|
||||
row[0] = (UINT8)(r/n);
|
||||
row[1] = (UINT8)(g/n);
|
||||
row[2] = (UINT8)(b/n);
|
||||
}
|
||||
}
|
||||
row += 4;
|
||||
@ -1615,7 +1638,7 @@ static void nsvg__initPaint(NSVGcachedPaint* cache, NSVGpaint* paint, NSVGshape*
|
||||
|
||||
static void nsvg__rasterizeShapes(NSVGrasterizer* r,
|
||||
NSVGshape* shapes, 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,
|
||||
NSVGscanlineFunction fscanline)
|
||||
{
|
||||
NSVGshape *shape = NULL, *shapeLink = NULL;
|
||||
@ -1632,9 +1655,9 @@ static void nsvg__rasterizeShapes(NSVGrasterizer* r,
|
||||
int oldw = r->cscanline;
|
||||
r->cscanline = w;
|
||||
if (oldw == 0) {
|
||||
r->scanline = (unsigned char*)AllocatePool(w);
|
||||
r->scanline = (UINT8*)AllocatePool(w);
|
||||
} else {
|
||||
r->scanline = (unsigned char*)ReallocatePool(oldw, w, r->scanline);
|
||||
r->scanline = (UINT8*)ReallocatePool(oldw, w, r->scanline);
|
||||
}
|
||||
if (r->scanline == NULL) return;
|
||||
}
|
||||
@ -1684,6 +1707,10 @@ static void renderShape(NSVGrasterizer* r,
|
||||
NSVGcachedPaint cache;
|
||||
|
||||
SetMem(&cache, sizeof(NSVGcachedPaint), 0);
|
||||
// NSVGclip& clip = shape->clip;
|
||||
// for (int i=0; i < clip.count; i++) {
|
||||
// DBG("renderShape %s with clip %d\n", shape->id, clip.index[i]);
|
||||
// }
|
||||
|
||||
if (shape->fill.type != NSVG_PAINT_NONE) {
|
||||
nsvg__resetPool(r);
|
||||
@ -1731,10 +1758,9 @@ void nsvg__rasterizeClipPaths(
|
||||
NSVGrasterizer* r, NSVGimage* image, int w, int h,
|
||||
float tx, float ty, float scalex, float scaley)
|
||||
{
|
||||
NSVGclipPath* clipPath;
|
||||
int clipPathCount = 0;
|
||||
|
||||
clipPath = image->clipPaths;
|
||||
NSVGclipPath* clipPath = image->clipPaths;
|
||||
if (clipPath == NULL) {
|
||||
r->stencil = NULL;
|
||||
return;
|
||||
@ -1769,16 +1795,11 @@ void nsvg__rasterizeClipPaths(
|
||||
|
||||
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)
|
||||
{
|
||||
// int i;
|
||||
|
||||
// for (i = 0; i < h; i++)
|
||||
// memset(&dst[i*stride], 0, w*4); //dst prepared before
|
||||
|
||||
tx -= image->realBounds[0] * scalex;
|
||||
ty -= image->realBounds[1] * scaley;
|
||||
// DBG(" image will be shifted by [%f,%f]\n", tx, ty);
|
||||
DBG(" image will be scaled by [%f]\n", scalex);
|
||||
// DumpFloat(" image real bounds ", image->realBounds, 4);
|
||||
|
||||
nsvg__rasterizeClipPaths(r, image, w, h, tx, ty, scalex, scaley);
|
||||
|
Loading…
Reference in New Issue
Block a user