Comments (5)
Hi! These sounds like interesting additions. Yes, I'd be interested to add them.
from nanosvg.
Ok, great!
Let me then ask you some questions while I am implementing the methods (this is the main reason why I opened an issue and not directly a pull request). I am a C++ developer so some things are not that obvious to me.
First things first: is this nsvgCopyPath
function ok with you?
NSVGpath* nsvgCopyPath(NSVGpath* _p)
{
NSVGpath* res = (NSVGpath*)malloc(sizeof(NSVGpath));
res->npts = _p->npts;
res->pts = (float*)malloc(res->npts*sizeof(float));
for (int i = 0; i < res->npts; ++i)
{
res->pts[i] = _p->pts[i];
}
res->closed = _p->closed;
for (int i = 0; i < 4; ++i)
{
res->bounds[i] = _p->bounds[i];
}
res->next = _p->next;
return res;
}
With "ok with you" I mean if it's ok to have a function declaration like the one above or something different (for example, bool nsvgCopyPath(NSVGpath* _src, NSVGpath* _res)
. It's completely up to you. I rather prefer the first option because it saves the user the step of allocating memory for the path.
from nanosvg.
Copy should be int nsvgCopyPath(NSVGPath* dst, NSVGPath* src)
, the above function should be called nsvgDuplicatePath()
as it returns a dupe :)
The above function is not in line how the rest of the lib is written (i.e. should not use those underscores), and public API should be more paranoid. Something like this:
NSVGpath* nsvgDuplicatePath(NSVGpath* p)
{
NSVGpath* res = NULL;
if (p == NULL)
return NULL;
res = malloc(sizeof(NSVGpath));
if (res == NULL) goto error;
memset(res, 0, sizeof(NSVGpath));
res->pts = malloc(p->npts * sizeof(float) * 2);
if (res->pts == NULL) goto error;
memcpy(res->pts, p->pts, p->npts * sizeof(float) * 2);
res->npts = p->npts;
memcpy(res->bounds, p->bounds, sizeof(p->bounds));
res->closed = p->closed;
return res;
error:
if (res != NULL) {
free(res->puts);
free(res);
}
return NULL;
}
void nsvgAddPathToShape(NSVGpath* s, NSVGpath* p)
{
if (s != NULL && p != NULL) {
p->next = s->paths;
s->paths = p;
}
}
I think it should not add the path to the linked list automatically.
from nanosvg.
Ok great! I will then proceed with nsvgDuplicatePath
and open a pull request (just to warm us up).
Some questions to go on:
- What do you mean with "I think it should not add the path to the linked list automatically"? My idea was not to implement an
addPathToShape
, but rather anaddShapeToImage
(but the mechanism is similar so the question remains) - In order for me to implement
nsvgDuplicateShape
, I need to implement also a duplicate method forNSVGgradient
andNSVGpaint
. I was thinking to not expose them to the user. Shall I call themnsvg__duplicateGradient
then (like any other method that is not exposed)? - I have some problems with the
union
inNSVGpaint
(never seen it before). How can I copy that? - In
NSVGgradient
, the variablestops
is defined asNSVGgradientStop stops[1];
. Is it correct to assume that this array is going to be generally with a size bigger than 1?
from nanosvg.
The nsvgDuplicatePath()
function I made does not add the path to any shape's linked list. I would like the adding to be explicit, so that you can do things like duplicate a path and add it to another shape. Also, there should be a matching nsvgDeletePath()
and nsvgRemovePathFromShape()
.
I don't think you need nsvg__duplicateGradient()
just make nsvg__copyPaint()
, which should handle copying the gradient too when need be (and also deal with existing gradient in dst paint).
Everything in the union will occupy the same memory location. So you can only use one of the values. This is done based on the type. If the type is NSVG_PAINT_LINEAR_GRADIENT
or NSVG_PAINT_RADIAL_GRADIENT
then the pointer is used. Take a look at nsvg__deletePaint()
.
The one sized array in gradient is old C trick for variable sized array, take a look at how it is allocated:
https://github.com/memononen/nanosvg/blob/master/src/nanosvg.h#L824
from nanosvg.
Related Issues (20)
- outlines donβt draw properly HOT 1
- How to find the outer loop and internal loops(holes) of a path? HOT 2
- Closed paths are not positioned correctly? HOT 2
- Firefox logo renders incorrectly HOT 11
- How to retrieve the "s" command so that my bezier curves are connected? HOT 2
- Textured shapes get incorrectly set as PAINT_NONE fill
- HTML &#; entities not supported
- nanosvg doesnt render beautyline icons HOT 7
- pathFlag never used HOT 1
- Unspecified stroke width gets read as 1, causing issues when scaled HOT 7
- Bug: "else" missing HOT 3
- heap-buffer-overflow read in nsvg__parseColorRGB()
- start versioning nanosvg. HOT 5
- Multicolor SVG rendered with a black background HOT 1
- nsvg__parseSVG HOT 1
- heap-buffer-overflow in nsvgRasterize HOT 1
- the antialiasing on different background,
- OSS Fuzz integration HOT 1
- Incorrect comment
- Loading SVG at its native physical-unit scaling?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nanosvg.