42 #define NANOSVG_ALL_COLOR_KEYWORDS
43 #define NANOSVG_IMPLEMENTATION
63 if (svg_data ==
nullptr) {
64 std::cout <<
" Could not open SVG.\n ";
71 std::cout <<
"Unable to create new object.\n";
88 char prv_id[70] = {
"*"};
91 char *layer_id = (shape->id_parent[0] ==
'\0') ?
BLI_sprintfN(
"Layer_%03d", prefix) :
93 if (!
STREQ(prv_id, layer_id)) {
96 layer_id = (shape->id_parent[0] ==
'\0') ?
BLI_sprintfN(
"Layer_%03d", prefix) :
98 strcpy(prv_id, layer_id);
104 if (gpl ==
nullptr) {
114 bool is_stroke = (bool)shape->stroke.type;
115 bool is_fill = (
bool)shape->fill.type;
116 if ((!is_stroke) && (!is_fill)) {
121 const char *
const mat_names[] = {
"Stroke",
"Fill",
"Both"};
123 if ((is_stroke) && (!is_fill)) {
126 else if ((!is_stroke) && (is_fill)) {
129 else if ((is_stroke) && (is_fill)) {
135 for (
NSVGpath *path = shape->paths; path; path = path->
next) {
136 create_stroke(
gpd_, gpf, shape, path, mat_index, matrix);
160 void GpencilImporterSVG::create_stroke(
bGPdata *gpd,
165 const float matrix[4][4])
167 const bool is_stroke = (bool)shape->
stroke.
type;
168 const bool is_fill = (
bool)shape->
fill.
type;
171 const float step = 1.0f / (
float)(edges - 1);
178 if (path->
closed ==
'1') {
187 convert_color(fill.
color, gps->vert_color_fill);
188 gps->fill_opacity_fac = gps->vert_color_fill[3];
189 gps->vert_color_fill[3] = 1.0f;
193 for (
int i = 0; i < path->
npts - 1; i += 3) {
194 float *p = &path->
pts[i * 2];
196 for (
int v = 0;
v < edges;
v++) {
233 unsigned char rgb_u[4];
235 rgb_u[0] = ((pack) >> 0) & 0xFF;
236 rgb_u[1] = ((pack) >> 8) & 0xFF;
237 rgb_u[2] = ((pack) >> 16) & 0xFF;
238 rgb_u[3] = ((pack) >> 24) & 0xFF;
240 r_col[0] = (
float)rgb_u[0] / 255.0f;
241 r_col[1] = (
float)rgb_u[1] / 255.0f;
242 r_col[2] = (
float)rgb_u[2] / 255.0f;
243 r_col[3] = (
float)rgb_u[3] / 255.0f;
246 void GpencilImporterSVG::convert_color(
const int32_t color,
float r_linear_rgba[4])
252 r_linear_rgba[3] = rgba[3];
typedef float(TangentPoint)[2]
struct bGPDstroke * BKE_gpencil_stroke_new(int mat_idx, int totpoints, short thickness)
struct bGPDframe * BKE_gpencil_layer_frame_get(struct bGPDlayer *gpl, int cframe, eGP_GetFrame_Mode addnew)
struct bGPDlayer * BKE_gpencil_layer_addnew(struct bGPdata *gpd, const char *name, bool setactive)
void BKE_gpencil_stroke_merge_distance(struct bGPdata *gpd, struct bGPDframe *gpf, struct bGPDstroke *gps, const float threshold, const bool use_unselected)
void BKE_gpencil_centroid_3d(struct bGPdata *gpd, float r_centroid[3])
void BKE_gpencil_stroke_geometry_update(struct bGPdata *gpd, struct bGPDstroke *gps)
#define LISTBASE_FOREACH(type, var, list)
void * BLI_findstring(const struct ListBase *listbase, const char *id, const int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
MINLINE void srgb_to_linearrgb_v3_v3(float linear[3], const float srgb[3])
void unit_m4(float m[4][4])
void rescale_m4(float mat[4][4], const float scale[3])
void mul_m4_v3(const float M[4][4], float r[3])
void rotate_m4(float mat[4][4], const char axis, const float angle)
MINLINE void sub_v3_v3(float r[3], const float a[3])
MINLINE void mul_v3_fl(float r[3], float f)
void interp_v2_v2v2v2v2_cubic(float p[2], const float v1[2], const float v2[2], const float v3[2], const float v4[2], const float u)
size_t size_t char * BLI_sprintfN(const char *__restrict format,...) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_PRINTF_FORMAT(1
ATTR_WARN_UNUSED_RESULT const BMVert * v
void filename_set(const char *filename)
GpencilImporterSVG(const char *filename, const struct GpencilIOParams *iparams)
struct Object * create_object()
int32_t create_material(const char *name, const bool stroke, const bool fill)
void(* MEM_freeN)(void *vmemh)
static void unpack_nano_color(const unsigned int pack, float r_col[4])
NSVGimage * nsvgParseFromFile(const char *filename, const char *units, float dpi)
void nsvgDelete(NSVGimage *image)