From bf58af620a39804503faf941f3c6935d1ea778dd Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Sun, 12 May 2019 14:25:00 +0300 Subject: Extract the TagEmitter.append method. This is Refactoring / code cleanup. See: * https://refactoring.com/catalog/extractMethod.html * https://en.wikipedia.org/wiki/Code_refactoring * https://www.refactoring.com/ * https://www.joelonsoftware.com/2002/01/23/rub-a-dub-dub/ Some small optimisations may have slipped in as well. --- src/extension/internal/wmf-inout.cpp | 80 ++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 41 deletions(-) (limited to 'src') diff --git a/src/extension/internal/wmf-inout.cpp b/src/extension/internal/wmf-inout.cpp index 048804f8c..2763d7c2c 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 & defs, char * tmpcolor, char * hpathname): + defs(defs), tmpcolor(tmpcolor), hpathname(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 @@ -239,6 +261,7 @@ uint32_t Wmf::add_hatch(PWMF_CALLBACK_DATA d, uint32_t hatchType, U_COLORREF hat 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.*/ @@ -253,51 +276,30 @@ uint32_t Wmf::add_hatch(PWMF_CALLBACK_DATA d, uint32_t hatchType, U_COLORREF hat defs += "\n"; switch(hatchType){ case U_HS_HORIZONTAL: - defs += " \n"; + a.append("\n"; + a.append("\n"; + a.append("\n"; + a.append("\n"; + a.append("\n"; - defs += " \n"; + a.append("\n"; + a.append("