From 668be1e3563834e6e5e8cc3d5f27c9f16cd694c2 Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Wed, 22 May 2019 15:55:29 +0300 Subject: Extract a common expression into a variable/const. This is Refactoring / code cleanup. See: * https://en.wikipedia.org/wiki/Code_refactoring Some small optimisations may have slipped in as well. ---- I hereby disclaim any implicit or explicit ownership of my changes in this changeset, and put them under a multiple licence consisting of your choice of one of more of: - The CC0 / Public Domain - https://creativecommons.org/choose/zero/ . - The MIT / Expat license - https://en.wikipedia.org/wiki/MIT_License - The default licence of your project - The https://en.wikipedia.org/wiki/GNU_Lesser_General_Public_License - version 2.1 or higher - The https://en.wikipedia.org/wiki/GNU_General_Public_License - version 2 or higher - Any licence in the 2018-Aug-27 popular licenses list of https://opensource.org/licenses - The https://en.wikipedia.org/wiki/Apache_License version 2.0 or later - The https://en.wikipedia.org/wiki/Artistic_License version 2.0 or later - The https://en.wikipedia.org/wiki/ISC_license - The https://opensource.org/licenses/BSD-2-Clause Crediting me will be nice, but not mandatory, and you can change the licence of the project without needing my permission. --- src/extension/internal/emf-inout.cpp | 208 ++++++++++++++++++----------------- 1 file changed, 105 insertions(+), 103 deletions(-) (limited to 'src') diff --git a/src/extension/internal/emf-inout.cpp b/src/extension/internal/emf-inout.cpp index d1b9d47ac..d1d0f5c5a 100644 --- a/src/extension/internal/emf-inout.cpp +++ b/src/extension/internal/emf-inout.cpp @@ -269,58 +269,59 @@ uint32_t Emf::add_hatch(PEMF_CALLBACK_DATA d, uint32_t hatchType, U_COLORREF hat std::string refpath; // used to reference later the path pieces which are about to be created sprintf(hpathname,"EMFhpath%d_%s",hatchType,tmpcolor); idx = in_hatches(d,hpathname); + auto & defs = d->defs; if(!idx){ // add path/color if not already present 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"; + defs += " \n"; break; case U_HS_VERTICAL: - d->defs += " defs += hpathname; - d->defs += "\" d=\"M 0 0 0 6\" style=\"fill:none;stroke:#"; - d->defs += tmpcolor; - d->defs += "\" />\n"; + defs += " \n"; break; case U_HS_FDIAGONAL: - d->defs += " defs += hpathname; - d->defs += "\" x1=\"-1\" y1=\"-1\" x2=\"7\" y2=\"7\" stroke=\"#"; - d->defs += tmpcolor; - d->defs += "\"/>\n"; + defs += " \n"; break; case U_HS_BDIAGONAL: - d->defs += " defs += hpathname; - d->defs += "\" x1=\"-1\" y1=\"7\" x2=\"7\" y2=\"-1\" stroke=\"#"; - d->defs += tmpcolor; - d->defs += "\"/>\n"; + defs += " \n"; break; case U_HS_CROSS: - d->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"; + defs += " \n"; break; case U_HS_DIAGCROSS: - d->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"; + defs += " \n"; + defs += " \n"; break; case U_HS_SOLIDCLR: case U_HS_DITHEREDCLR: @@ -329,12 +330,12 @@ uint32_t Emf::add_hatch(PEMF_CALLBACK_DATA d, uint32_t hatchType, U_COLORREF hat case U_HS_SOLIDBKCLR: case U_HS_DITHEREDBKCLR: default: - d->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"; + defs += " \n"; break; } } @@ -396,12 +397,12 @@ uint32_t Emf::add_hatch(PEMF_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=\"#EMFhbasepattern\">\n"; - d->defs += refpath; - d->defs += " \n"; + defs += "\n"; + defs += " \n"; + defs += refpath; + defs += " \n"; idx = d->hatches.count; } } @@ -414,12 +415,12 @@ uint32_t Emf::add_hatch(PEMF_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 @@ -428,15 +429,15 @@ uint32_t Emf::add_hatch(PEMF_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=\"#EMFhbasepattern\">\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; } } @@ -536,6 +537,7 @@ uint32_t Emf::add_image(PEMF_CALLBACK_DATA d, void *pEmr, uint32_t cbBits, uint } idx = in_images(d, (char *) base64String); + auto & defs = d->defs; if(!idx){ // add it if not already present - we looked at the actual data for comparison if(d->images.count == d->images.size){ enlarge_images(d); } idx = d->images.count; @@ -544,35 +546,35 @@ uint32_t Emf::add_image(PEMF_CALLBACK_DATA d, void *pEmr, uint32_t cbBits, uint sprintf(imagename,"EMFimage%d",idx++); sprintf(xywh," x=\"0\" y=\"0\" width=\"%d\" height=\"%d\" ",width,height); // reuse this buffer - d->defs += "\n"; - d->defs += " defs += imagename; - d->defs += "\"\n "; - d->defs += xywh; - d->defs += "\n"; - if(dibparams == U_BI_JPEG){ d->defs += " xlink:href=\"data:image/jpeg;base64,"; } - else { d->defs += " xlink:href=\"data:image/png;base64,"; } - d->defs += base64String; - d->defs += "\"\n"; - d->defs += " preserveAspectRatio=\"none\"\n"; - d->defs += " />\n"; - - - d->defs += "\n"; - d->defs += " defs += imagename; - d->defs += "_ref\"\n "; - d->defs += xywh; - d->defs += "\n patternUnits=\"userSpaceOnUse\""; - d->defs += " >\n"; - d->defs += " defs += imagename; - d->defs += "_ign\" "; - d->defs += " xlink:href=\"#"; - d->defs += imagename; - d->defs += "\" />\n"; - d->defs += " "; - d->defs += " \n"; + defs += "\n"; + defs += " \n"; + defs += " "; + defs += " \n"; } g_free(base64String);//wait until this point to free because it might be a duplicate image @@ -596,17 +598,17 @@ uint32_t Emf::add_image(PEMF_CALLBACK_DATA d, void *pEmr, uint32_t cbBits, uint d->images.strings[d->images.count++]=strdup(base64String); sprintf(imrotname,"EMFimage%d",idx++); - d->defs += "\n"; - d->defs += " defs += " id=\""; - d->defs += imrotname; - d->defs += "_ref\"\n"; - d->defs += " xlink:href=\"#"; - d->defs += imagename; - d->defs += "_ref\"\n"; - d->defs += " patternTransform="; - d->defs += current_matrix(d, 0.0, 0.0, 0); //j use offset 0,0 - d->defs += " />\n"; + defs += "\n"; + defs += "