24#include <proto/exec.h>
29#ifndef AMIGA_DR2D_STANDALONE
39static struct ColorRegister cm[1000];
42static ULONG findcolour(ULONG newcol)
45 ULONG colr = 0xFFFFFFFF;
48 red = svgtiny_RED(newcol);
49 grn = svgtiny_GREEN(newcol);
50 blu = svgtiny_BLUE(newcol);
52 for(i=0;i<numcols;i++)
54 if((cm[i].red == red) && (cm[i].green == grn) && (cm[i].blue == blu))
61static void addcolour(ULONG newcol)
63 ULONG colr = findcolour(newcol);
65 if(colr == 0xFFFFFFFF)
67 cm[numcols].red = svgtiny_RED(newcol);
68 cm[numcols].green = svgtiny_GREEN(newcol);
69 cm[numcols].blue = svgtiny_BLUE(newcol);
75bool ami_svg_to_dr2d(
struct IFFHandle *
iffh,
const char *
buffer,
76 uint32_t size,
const char *url)
78 struct svgtiny_diagram *diagram;
80 BOOL fons_written = FALSE;
81 struct fons_struct *fons;
82 struct stxt_struct *stxt;
83 struct attr_struct *attr;
86 diagram = svgtiny_create();
88 fprintf(stderr,
"svgtiny_create failed\n");
93 code = svgtiny_parse(diagram,
buffer, size, url, 1000, 1000);
94 if (code != svgtiny_OK) {
95 fprintf(stderr,
"svgtiny_parse failed: ");
97 case svgtiny_OUT_OF_MEMORY:
98 fprintf(stderr,
"svgtiny_OUT_OF_MEMORY");
100 case svgtiny_LIBDOM_ERROR:
101 fprintf(stderr,
"svgtiny_LIBDOM_ERROR");
103 case svgtiny_NOT_SVG:
104 fprintf(stderr,
"svgtiny_NOT_SVG");
106 case svgtiny_SVG_ERROR:
107 fprintf(stderr,
"svgtiny_SVG_ERROR: line %i: %s",
109 diagram->error_message);
112 fprintf(stderr,
"unknown svgtiny_code %i", code);
115 fprintf(stderr,
"\n");
118 if(!(PushChunk(
iffh,ID_DR2D,ID_FORM,IFFSIZE_UNKNOWN)))
120 if(!(PushChunk(
iffh,0,ID_NAME,IFFSIZE_UNKNOWN)))
122 WriteChunkBytes(
iffh,url,strlen(url));
123 WriteChunkBytes(
iffh,
"\0",1);
127 if(!(PushChunk(
iffh,0,ID_ANNO,19)))
129 WriteChunkBytes(
iffh,
"Created by NetSurf\0",19);
133 if(!(PushChunk(
iffh,0,ID_DRHD,16)))
135 struct drhd_struct drhd;
136 drhd.XLeft = (float) 0.0;
137 drhd.YTop = (float) 0.0;
138 drhd.XRight = (float) diagram->width;
139 drhd.YBot = (
float) diagram->height;
141 WriteChunkBytes(
iffh,&drhd,16);
145 if(!(PushChunk(
iffh,0,ID_DASH,IFFSIZE_UNKNOWN)))
147 struct dash_struct dash;
151 WriteChunkBytes(
iffh,&dash,
sizeof(
struct dash_struct));
155 if(!(PushChunk(
iffh,0,ID_CMAP,IFFSIZE_UNKNOWN)))
157 for (
unsigned int i = 0; i != diagram->shape_count; i++) {
158 if(diagram->shape[i].fill != svgtiny_TRANSPARENT)
160 addcolour(diagram->shape[i].fill);
163 if(diagram->shape[i].stroke != svgtiny_TRANSPARENT)
165 addcolour(diagram->shape[i].stroke);
169 WriteChunkBytes(
iffh,cm,3*numcols);
173 for (
unsigned int i = 0; i != diagram->shape_count; i++) {
174 attr = calloc(1,
sizeof(
struct attr_struct));
175 if (diagram->shape[i].fill == svgtiny_TRANSPARENT)
176 attr->FillType = FT_NONE;
179 attr->FillType = FT_COLOR;
180 attr->FillValue = findcolour(diagram->shape[i].fill);
182 if (diagram->shape[i].stroke == svgtiny_TRANSPARENT)
183 attr->DashPattern = 0;
186 attr->DashPattern = 1;
187 attr->EdgeValue = findcolour(diagram->shape[i].stroke);
190 attr->EdgeThick = (float) diagram->shape[i].stroke_width;
192 if(!(PushChunk(
iffh,0,ID_ATTR,IFFSIZE_UNKNOWN)))
194 WriteChunkBytes(
iffh,attr,14);
199 if (diagram->shape[i].path) {
203 } poly[(diagram->shape[i].path_length)*2];
214 for (
unsigned int j = 0;
215 j != diagram->shape[i].path_length; ) {
216 switch ((
int) diagram->shape[i].path[j]) {
217 case svgtiny_PATH_MOVE:
220 poly[NumPoints*2].val = INDICATOR;
221 poly[(NumPoints*2)+1].val = IND_MOVETO;
224 poly[(NumPoints*2)].PolyPoints = diagram->shape[i].path[j + 1];
225 poly[(NumPoints*2)+1].PolyPoints = diagram->shape[i].path[j + 2];
227 curx = (float) diagram->shape[i].path[j + 1];
228 cury = (
float) diagram->shape[i].path[j + 2];
232 case svgtiny_PATH_CLOSE:
236 case svgtiny_PATH_LINE:
237 poly[(NumPoints*2)].PolyPoints = (
float) diagram->shape[i].path[j + 1];
238 poly[(NumPoints*2)+1].PolyPoints = (
float) diagram->shape[i].path[j + 2];
240 curx = (float) diagram->shape[i].path[j + 1];
241 cury = (
float) diagram->shape[i].path[j + 2];
244 case svgtiny_PATH_BEZIER:
245 poly[NumPoints*2].val = INDICATOR;
246 poly[(NumPoints*2)+1].val = IND_CURVE;
248 poly[(NumPoints*2)].PolyPoints = curx;
249 poly[(NumPoints*2)+1].PolyPoints = cury;
251 poly[(NumPoints*2)].PolyPoints = (
float) diagram->shape[i].path[j + 1];
252 poly[(NumPoints*2)+1].PolyPoints = (
float) diagram->shape[i].path[j + 2];
254 poly[(NumPoints*2)].PolyPoints = (
float) diagram->shape[i].path[j + 3];
255 poly[(NumPoints*2)+1].PolyPoints = (
float) diagram->shape[i].path[j + 4];
257 poly[(NumPoints*2)].PolyPoints = (
float) diagram->shape[i].path[j + 5];
258 poly[(NumPoints*2)+1].PolyPoints = (
float) diagram->shape[i].path[j + 6];
259 curx = poly[(NumPoints*2)].PolyPoints;
260 cury = poly[(NumPoints*2)+1].PolyPoints;
269 if(!(PushChunk(
iffh,0,
type,IFFSIZE_UNKNOWN)))
271 WriteChunkBytes(
iffh,&NumPoints,
sizeof(USHORT));
272 WriteChunkBytes(
iffh,poly,NumPoints*2*4);
275 }
else if (diagram->shape[i].text) {
276 stxt = calloc(1,
sizeof(
struct stxt_struct));
277 stxt->BaseX = diagram->shape[i].text_x;
278 stxt->BaseY = diagram->shape[i].text_y;
279 stxt->NumChars = strlen(diagram->shape[i].text);
282 fons = calloc(1,
sizeof(
struct fons_struct));
283 if(!(PushChunk(
iffh, 0, ID_FONS, IFFSIZE_UNKNOWN)))
285 WriteChunkBytes(
iffh, fons,
sizeof(
struct fons_struct));
286 WriteChunkBytes(
iffh,
"Helvetica\0", 10);
293 if(!(PushChunk(
iffh, 0, ID_STXT, IFFSIZE_UNKNOWN)))
295 WriteChunkBytes(
iffh, stxt, 26);
296 WriteChunkBytes(
iffh, diagram->shape[i].text, strlen(diagram->shape[i].text));
306 svgtiny_free(diagram);
311#ifndef AMIGA_DR2D_STANDALONE
314 struct IFFHandle *
iffh;
315 const uint8_t *source_data;
320 if ((
iffh = AllocIFF())) {
321 if ((
iffh->iff_Stream = Open(filename,MODE_NEWFILE))) {
327 if ((OpenIFF(
iffh,IFFF_WRITE)))
return false;
330 if (source_data != NULL) {
331 ami_svg_to_dr2d(
iffh,
332 (
const char *)source_data,
338 if(
iffh->iff_Stream) Close((BPTR)
iffh->iff_Stream);
352const char __attribute__((used)) ver[] =
"\0$VER: svg2dr2d 1.2 (05.01.2015)\0";
354int main(
int argc,
char **argv)
358 struct IFFHandle *
iffh = NULL;
360 LONG rarray[] = {0,0};
362 STRPTR
template =
"SVG=INPUT/A,DR2D=OUTPUT/A";
370 DOSBase = OpenLibrary(
"dos.library", 37);
371 if(!DOSBase)
return RETURN_FAIL;
373 IFFParseBase = OpenLibrary(
"iffparse.library", 37);
374 if(!IFFParseBase)
return RETURN_FAIL;
377 args = ReadArgs(
template,rarray,NULL);
381 printf(
"Required argument missing\n");
385 if(fh = Open((
char *)rarray[A_SVG],MODE_OLDFILE))
389 buffer = malloc((uint32_t)size);
391 Read(fh,
buffer,(uint32_t)size);
396 printf(
"Unable to open file\n");
400 if(
iffh = AllocIFF())
402 if(
iffh->iff_Stream = Open((
char *)rarray[A_DR2D],MODE_NEWFILE))
409 if((OpenIFF(
iffh,IFFF_WRITE)))
return 20;
411 ami_svg_to_dr2d(
iffh,
buffer,size,(
char *)rarray[A_SVG]);
415 if(
iffh->iff_Stream) Close((BPTR)
iffh->iff_Stream);
420 if(DOSBase) CloseLibrary(DOSBase);
421 if(IFFParseBase) CloseLibrary(IFFParseBase);
static struct IFFHandle * iffh
static const __attribute__((used))
int main(int argc, char **argv)
Normal entry point from OS.
static osspriteop_area * buffer
The buffer characteristics.
BOOL ami_download_check_overwrite(const char *file, struct Window *win, ULONG size)
Public content interface.
struct nsurl * hlcache_handle_get_url(const struct hlcache_handle *handle)
Retrieve the URL associated with a high level cache handle.
const uint8_t * content_get_source_data(struct hlcache_handle *h, size_t *size)
Retrieve source of content.
Netsurf additional integer type formatting macros.
NetSurf URL handling (interface).
const char * nsurl_access(const nsurl *url)
Access a NetSurf URL object as a string.
int64 GetFileSize(BPTR fh)
Minimal compatibility header for AmigaOS 3.
Interface to utility string handling.