diff --git a/src/extension/internal/wmf-inout.cpp b/src/extension/internal/wmf-inout.cpp index 4db33f5503e80255c2728b933c8a92d163964ad6..cea259dc4212f14832395995a601c3fb4b5b40d9 100644 --- a/src/extension/internal/wmf-inout.cpp +++ b/src/extension/internal/wmf-inout.cpp @@ -213,6 +213,28 @@ int Wmf::in_hatches(PWMF_CALLBACK_DATA d, char *test){ return(0); } +class TagEmitter +{ +public: + TagEmitter(Glib::ustring & p_defs, char * p_tmpcolor, char * p_hpathname): + defs(p_defs), tmpcolor(p_tmpcolor), hpathname(p_hpathname) + { + }; + void append(const char *prefix, const char * inner) + { + defs += " "; + defs += prefix; + defs += hpathname; + defs += inner; + defs += tmpcolor; + defs += "\" />\n"; + } + +protected: + Glib::ustring & defs; + char * tmpcolor, * hpathname; +}; + /* (Conditionally) add a hatch. If a matching hatch already exists nothing happens. If one does not exist it is added to the hatches list and also entered into . This is also used to add the path part of the hatches, which they reference with a xlink:href @@ -238,6 +260,8 @@ uint32_t Wmf::add_hatch(PWMF_CALLBACK_DATA d, uint32_t hatchType, U_COLORREF hat sprintf(tmpcolor,"%6.6X",sethexcolor(hatchColor)); break; } + auto & defs = d->defs; + TagEmitter a(defs, tmpcolor, hpathname); /* For both bkMode types set the PATH + FOREGROUND COLOR for the indicated standard hatch. This will be used late to compose, or recompose the transparent or opaque final hatch.*/ @@ -249,54 +273,33 @@ uint32_t Wmf::add_hatch(PWMF_CALLBACK_DATA d, uint32_t hatchType, U_COLORREF hat if(d->hatches.count == d->hatches.size){ enlarge_hatches(d); } d->hatches.strings[d->hatches.count++]=strdup(hpathname); - d->defs += "\n"; + defs += "\n"; switch(hatchType){ case U_HS_HORIZONTAL: - d->defs += " defs += hpathname; - d->defs += "\" d=\"M 0 0 6 0\" style=\"fill:none;stroke:#"; - d->defs += tmpcolor; - d->defs += "\" />\n"; + a.append("defs += " defs += hpathname; - d->defs += "\" d=\"M 0 0 0 6\" style=\"fill:none;stroke:#"; - d->defs += tmpcolor; - d->defs += "\" />\n"; + a.append("defs += " defs += hpathname; - d->defs += "\" x1=\"-1\" y1=\"-1\" x2=\"7\" y2=\"7\" stroke=\"#"; - d->defs += tmpcolor; - d->defs += "\"/>\n"; + a.append("defs += " defs += hpathname; - d->defs += "\" x1=\"-1\" y1=\"7\" x2=\"7\" y2=\"-1\" stroke=\"#"; - d->defs += tmpcolor; - d->defs += "\"/>\n"; + a.append("defs += " defs += hpathname; - d->defs += "\" d=\"M 0 0 6 0 M 0 0 0 6\" style=\"fill:none;stroke:#"; - d->defs += tmpcolor; - d->defs += "\" />\n"; + a.append("defs += " defs += hpathname; - d->defs += "\" x1=\"-1\" y1=\"-1\" x2=\"7\" y2=\"7\" stroke=\"#"; - d->defs += tmpcolor; - d->defs += "\"/>\n"; - d->defs += " defs += hpathname; - d->defs += "\" x1=\"-1\" y1=\"7\" x2=\"7\" y2=\"-1\" stroke=\"#"; - d->defs += tmpcolor; - d->defs += "\"/>\n"; + a.append("defs += " defs += hpathname; - d->defs += "\" d=\"M 0 0 6 0 6 6 0 6 z\" style=\"fill:#"; - d->defs += tmpcolor; - d->defs += ";stroke:none"; - d->defs += "\" />\n"; + a.append("hatches.count == d->hatches.size){ enlarge_hatches(d); } d->hatches.strings[d->hatches.count++]=strdup(hatchname); - d->defs += "\n"; - d->defs += " defs += hatchname; - d->defs += "\" xlink:href=\"#WMFhbasepattern\">\n"; - d->defs += refpath; - d->defs += " \n"; + defs += "\n"; + defs += " \n"; + defs += refpath; + defs += " \n"; idx = d->hatches.count; } } @@ -390,12 +389,12 @@ uint32_t Wmf::add_hatch(PWMF_CALLBACK_DATA d, uint32_t hatchType, U_COLORREF hat if(d->hatches.count == d->hatches.size){ enlarge_hatches(d); } d->hatches.strings[d->hatches.count++]=strdup(hbkname); - d->defs += "\n"; - d->defs += " defs += hbkname; - d->defs += "\" x=\"0\" y=\"0\" width=\"6\" height=\"6\" fill=\"#"; - d->defs += bkcolor; - d->defs += "\" />\n"; + defs += "\n"; + defs += " \n"; } // this is the pattern, its name will show up in Inkscape's pattern selector @@ -404,15 +403,15 @@ uint32_t Wmf::add_hatch(PWMF_CALLBACK_DATA d, uint32_t hatchType, U_COLORREF hat if(!idx){ // add it if not already present if(d->hatches.count == d->hatches.size){ enlarge_hatches(d); } d->hatches.strings[d->hatches.count++]=strdup(hatchname); - d->defs += "\n"; - d->defs += " defs += hatchname; - d->defs += "\" xlink:href=\"#WMFhbasepattern\">\n"; - d->defs += " defs += hbkname; - d->defs += "\" />\n"; - d->defs += refpath; - d->defs += " \n"; + defs += "\n"; + defs += " \n"; + defs += " \n"; + defs += refpath; + defs += " \n"; idx = d->hatches.count; } }