tiny svg steps
This commit is contained in:
parent
691e0427d1
commit
3f98db058e
33
draw_fpga.c
33
draw_fpga.c
|
@ -17,19 +17,17 @@
|
|||
#include <libxml/xpath.h>
|
||||
#include <libxml/xpathInternals.h>
|
||||
|
||||
static const char* empty_svg =
|
||||
{
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
|
||||
static const xmlChar* empty_svg = (const xmlChar*)
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
||||
"<svg\n"
|
||||
" xmlns=\"http://www.w3.org/2000/svg\"\n"
|
||||
" version=\"2.0\"\n"
|
||||
" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
|
||||
" viewBox=\"0 0 1000 1000\" width=\"1000\" height=\"1000\"\n"
|
||||
" id=\"fpga\">\n"
|
||||
" viewBox=\"0 0 1000 1000\" width=\"1000\" height=\"1000\">\n"
|
||||
" <rect width=\"100%\" height=\"100%\" style=\"fill:black;\"/>\n"
|
||||
" <g id=\"root\" transform=\"translate(0,1000) scale(1,-1)\">\n"
|
||||
" </g>\n"
|
||||
"</svg>\n"
|
||||
};
|
||||
"</svg>\n";
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
@ -37,20 +35,10 @@ int main(int argc, char** argv)
|
|||
xmlXPathContextPtr xpathCtx = 0;
|
||||
xmlXPathObjectPtr xpathObj = 0;
|
||||
|
||||
// create or overwrite fpga.svg
|
||||
{
|
||||
FILE* f = fopen("fpga.svg", "w+");
|
||||
if (!f) {
|
||||
fprintf(stderr, "Cannot create fpga.svg\n");
|
||||
goto fail;
|
||||
}
|
||||
fprintf(f, empty_svg);
|
||||
fclose(f);
|
||||
}
|
||||
xmlInitParser();
|
||||
doc = xmlParseFile("fpga.svg");
|
||||
doc = xmlParseDoc(empty_svg);
|
||||
if (!doc) {
|
||||
fprintf(stderr, "Unable to parse fpga.svg.\n");
|
||||
fprintf(stderr, "Internal error %i.\n", __LINE__);
|
||||
goto fail_xml;
|
||||
}
|
||||
xpathCtx = xmlXPathNewContext(doc);
|
||||
|
@ -79,13 +67,15 @@ int main(int argc, char** argv)
|
|||
|
||||
for (i = 0; i < 10; i++) {
|
||||
new_node = xmlNewChild(xpathObj->nodesetval->nodeTab[0], 0 /* xmlNsPtr */, BAD_CAST "use", 0 /* content */);
|
||||
xmlSetProp(new_node, BAD_CAST "xlink:href", BAD_CAST "lib.svg#square");
|
||||
xmlSetProp(new_node, BAD_CAST "xlink:href", BAD_CAST "lib.svg#IOB");
|
||||
xmlSetProp(new_node, BAD_CAST "x", xmlXPathCastNumberToString(50+i*50));
|
||||
xmlSetProp(new_node, BAD_CAST "y", BAD_CAST "50");
|
||||
xmlSetProp(new_node, BAD_CAST "width", BAD_CAST "50");
|
||||
xmlSetProp(new_node, BAD_CAST "height", BAD_CAST "50");
|
||||
}
|
||||
}
|
||||
|
||||
xmlSaveFile("fpga.svg", doc);
|
||||
xmlDocDump(stdout, doc);
|
||||
|
||||
xmlXPathFreeObject(xpathObj);
|
||||
xmlXPathFreeContext(xpathCtx);
|
||||
|
@ -98,6 +88,5 @@ fail_xml:
|
|||
if (xpathCtx) xmlXPathFreeContext(xpathCtx);
|
||||
if (doc) xmlFreeDoc(doc);
|
||||
xmlCleanupParser();
|
||||
fail:
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
|
10
lib.svg
10
lib.svg
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg">
|
||||
<g id="square">
|
||||
<rect x="0" y="0" width="20" height="20"
|
||||
style="fill: black; stroke-width: 2;"/>
|
||||
</g>
|
||||
<svg id="IOB" width="1000" height="1000" viewBox="0 0 1000 1000">
|
||||
<rect x="100" y="100" width="800" height="800" style="fill:white;"/>
|
||||
<text x="200" y="200">hi</text>
|
||||
</svg>
|
||||
</svg>
|
||||
|
|
Before Width: | Height: | Size: 223 B After Width: | Height: | Size: 273 B |
Loading…
Reference in New Issue
Block a user