diff options
Diffstat (limited to 'hwpfilter/source')
33 files changed, 2343 insertions, 3129 deletions
diff --git a/hwpfilter/source/attributes.cxx b/hwpfilter/source/attributes.cxx index 602165ba0c32..3b24d45b0351 100644 --- a/hwpfilter/source/attributes.cxx +++ b/hwpfilter/source/attributes.cxx @@ -19,6 +19,7 @@ #include <assert.h> +#include <utility> #include <vector> #include "attributes.hxx" @@ -26,8 +27,8 @@ namespace { struct TagAttribute { - TagAttribute( const OUString &rName, const OUString &rType , const OUString &rValue ) - : sName(rName), sType(rType), sValue(rValue) + TagAttribute( OUString aName, OUString aType, OUString aValue ) + : sName(std::move(aName)), sType(std::move(aType)), sValue(std::move(aValue)) { } diff --git a/hwpfilter/source/drawing.h b/hwpfilter/source/drawing.h index c7526a4c591e..e549896a5eed 100644 --- a/hwpfilter/source/drawing.h +++ b/hwpfilter/source/drawing.h @@ -315,7 +315,7 @@ static bool LoadCommonHeader(HWPDrawingObject * hdo, unsigned short * link_info) return hmem->skipBlock(size - common_size ) != 0; } -static std::unique_ptr<HWPDrawingObject> LoadDrawingObject(void) +static std::unique_ptr<HWPDrawingObject> LoadDrawingObject(HWPFile& hwpf) { HWPDrawingObject *prev = nullptr; std::unique_ptr<HWPDrawingObject> hdo, head; @@ -354,7 +354,7 @@ static std::unique_ptr<HWPDrawingObject> LoadDrawingObject(void) } if (link_info & HDOFILE_HAS_CHILD) { - hdo->child = LoadDrawingObject(); + hdo->child = LoadDrawingObject(hwpf); if (hdo->child == nullptr) { goto error; @@ -383,6 +383,17 @@ error: { hdo->type = HWPDO_RECT; } + if (hdo->property.pPara) + { + HWPPara* pPara = hdo->property.pPara; + while (pPara) + { + HWPPara* pNextPara = pPara->Next(); + hwpf.move_to_failed(std::unique_ptr<HWPPara>(pPara)); + pPara = pNextPara; + } + hdo->property.pPara = nullptr; + } HWPDOFunc(hdo.get(), OBJFUNC_FREE, nullptr, 0); hdo.reset(); @@ -396,7 +407,7 @@ error: } -static bool LoadDrawingObjectBlock(Picture * pic) +static bool LoadDrawingObjectBlock(Picture * pic, HWPFile& hwpf) { int size; if (!hmem->read4b(size)) @@ -422,7 +433,7 @@ static bool LoadDrawingObjectBlock(Picture * pic) !hmem->skipBlock(size - HDOFILE_HEADER_SIZE)) return false; - pic->picinfo.picdraw.hdo = LoadDrawingObject().release(); + pic->picinfo.picdraw.hdo = LoadDrawingObject(hwpf).release(); if (pic->picinfo.picdraw.hdo == nullptr) return false; return true; @@ -480,7 +491,6 @@ int cmd, void * /*argp*/, int /*argv*/) return HWPDODefaultFunc(cmd); } -#define WTMM(x) ((double)(x) / 1800. * 25.4) static int HWPDOEllipse2Func(int /*type*/, HWPDrawingObject * hdo, int cmd, void * /*argp*/, int /*argv*/) diff --git a/hwpfilter/source/fontmap.cxx b/hwpfilter/source/fontmap.cxx index fcd6c4822169..7eba07c03ad3 100644 --- a/hwpfilter/source/fontmap.cxx +++ b/hwpfilter/source/fontmap.cxx @@ -17,6 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <cstddef> #include <stdio.h> #ifdef __sun #include <strings.h> @@ -151,7 +152,7 @@ const char* const RepFontTab[] = int getRepFamilyName(const char* orig, char *buf, double &ratio) { - for( int i = 0 ; i < int(SAL_N_ELEMENTS(FontMapTab)); i++) + for( std::size_t i = 0 ; i < SAL_N_ELEMENTS(FontMapTab); i++) { if( !strcmp(orig, FontMapTab[i].familyname) ){ ratio = FontMapTab[i].ratio; diff --git a/hwpfilter/source/fontmap.hxx b/hwpfilter/source/fontmap.hxx index 3ab2e0849e1d..1debe8ede2bd 100644 --- a/hwpfilter/source/fontmap.hxx +++ b/hwpfilter/source/fontmap.hxx @@ -17,13 +17,10 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_HWPFILTER_SOURCE_FONTMAP_HXX -#define INCLUDED_HWPFILTER_SOURCE_FONTMAP_HXX +#pragma once #include <sal/config.h> int getRepFamilyName(char const*, char*, double&); -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/hwpfilter/source/formula.cxx b/hwpfilter/source/formula.cxx index f9ab4566668f..e220afe9d881 100644 --- a/hwpfilter/source/formula.cxx +++ b/hwpfilter/source/formula.cxx @@ -20,13 +20,12 @@ #include "formula.h" #include "grammar.hxx" -#include "mzstring.h" #include "nodes.h" #include "mapping.h" #include "hwpeq.h" #include <iostream> -#ifndef DEBUG +#if OSL_DEBUG_LEVEL < 2 #include "hcode.h" @@ -47,7 +46,7 @@ void Formula::makeMathML(Node *res) { Node *tmp = res; if( !tmp ) return; -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inds; fprintf(stderr,"<math:math xmlns:math=\"http://www.w3.org/1998/Math/MathML\">\n"); #else @@ -59,7 +58,7 @@ void Formula::makeMathML(Node *res) if( tmp->child ) makeLines( tmp->child ); -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inds; fprintf(stderr,"<math:semantics/>\n"); indo; @@ -89,14 +88,14 @@ void Formula::makeLines(Node *res) void Formula::makeLine(Node *res) { if( !res ) return; -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inds; fprintf(stderr,"<math:mrow>\n"); #else rstartEl("math:mrow", mxList); #endif if( res->child ) makeExprList( res->child ); -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inde; fprintf(stderr,"</math:mrow>\n"); #else rendEl("math:mrow"); @@ -127,7 +126,7 @@ void Formula::makeExpr(Node *res) switch( tmp->id ) { case ID_PRIMARYEXPR: if( tmp->next ){ -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inds; fprintf(stderr,"<math:mrow>\n"); #else @@ -138,7 +137,7 @@ void Formula::makeExpr(Node *res) makePrimary(tmp); if( tmp->next ){ -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inde; fprintf(stderr,"</math:mrow>\n"); #else rendEl("math:mrow"); @@ -189,57 +188,57 @@ void Formula::makeIdentifier(Node *res) if( !tmp->value ) return; switch( tmp->id ){ case ID_CHARACTER : -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inds; - fprintf(stderr,"<math:mi>%s</math:mi>\n",tmp->value); + fprintf(stderr,"<math:mi>%s</math:mi>\n",tmp->value.get()); indo; #else rstartEl("math:mi", mxList); - rchars(OUString::createFromAscii(tmp->value)); + rchars(OUString::createFromAscii(tmp->value.get())); rendEl("math:mi"); #endif break; case ID_STRING : { -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 #else rstartEl("math:mi", mxList); - reucstr(tmp->value, strlen(tmp->value)); + reucstr(tmp->value.get(), strlen(tmp->value.get())); rendEl("math:mi"); #endif } break; case ID_IDENTIFIER : -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inds; fprintf(stderr,"<math:mi>%s</math:mi>\n", - getMathMLEntity(tmp->value).c_str()); + getMathMLEntity(tmp->value.get()).c_str()); indo; #else rstartEl("math:mi", mxList); - runistr(fromHcharStringToOUString(getMathMLEntity(tmp->value))); + runistr(fromHcharStringToOUString(getMathMLEntity(tmp->value.get()))); rendEl("math:mi"); #endif break; case ID_NUMBER : -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inds; - fprintf(stderr,"<math:mn>%s</math:mn>\n",tmp->value); + fprintf(stderr,"<math:mn>%s</math:mn>\n",tmp->value.get()); indo; #else rstartEl("math:mn", mxList); - rchars(OUString::createFromAscii(tmp->value)); + rchars(OUString::createFromAscii(tmp->value.get())); rendEl("math:mn"); #endif break; case ID_OPERATOR : case ID_DELIMITER : { -#ifdef DEBUG - inds; fprintf(stderr,"<math:mo>%s</math:mo>\n",tmp->value); indo; +#if OSL_DEBUG_LEVEL >= 2 + inds; fprintf(stderr,"<math:mo>%s</math:mo>\n",tmp->value.get()); indo; #else rstartEl("math:mo", mxList); - runistr(fromHcharStringToOUString(getMathMLEntity(tmp->value))); + runistr(fromHcharStringToOUString(getMathMLEntity(tmp->value.get()))); rendEl("math:mo"); #endif break; @@ -268,7 +267,7 @@ void Formula::makeSubSup(Node *res) Node *tmp = res; if( !tmp ) return; -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inds; if( res->id == ID_SUBEXPR ) fprintf(stderr,"<math:msub>\n"); @@ -296,7 +295,7 @@ void Formula::makeSubSup(Node *res) makeExpr(tmp->next); } -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inde; if( res->id == ID_SUBEXPR ) fprintf(stderr,"</math:msub>\n"); @@ -319,7 +318,7 @@ void Formula::makeFraction(Node *res) Node *tmp = res; if( !tmp ) return; -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inds; fprintf(stderr,"<math:mfrac>\n"); #else @@ -327,7 +326,7 @@ void Formula::makeFraction(Node *res) #endif tmp = tmp->child; -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inds; fprintf(stderr,"<math:mrow>\n"); #else @@ -339,7 +338,7 @@ void Formula::makeFraction(Node *res) else makeExprList(tmp); -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inde; fprintf(stderr,"</math:mrow>\n"); inds; @@ -354,7 +353,7 @@ void Formula::makeFraction(Node *res) else makeExprList(tmp->next); -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inde; fprintf(stderr,"</math:mrow>\n"); inde; @@ -370,9 +369,9 @@ void Formula::makeDecoration(Node *res) int isover = 1; Node *tmp = res->child; if( !tmp ) return; - if( !strncmp(tmp->value,"under", 5) ) + if( !strncmp(tmp->value.get(),"under", 5) ) isover = 0; -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inds; if( isover ) fprintf(stderr,"<math:mover>\n"); @@ -393,18 +392,18 @@ void Formula::makeDecoration(Node *res) makeBlock(tmp->next); -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inds; fprintf(stderr,"<math:mo>%s</math:mo>\n", - getMathMLEntity(tmp->value).c_str()); + getMathMLEntity(tmp->value.get()).c_str()); indo; #else rstartEl("math:mo", mxList); - runistr(fromHcharStringToOUString(getMathMLEntity(tmp->value))); + runistr(fromHcharStringToOUString(getMathMLEntity(tmp->value.get()))); rendEl("math:mo"); #endif -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inde; if( isover ) fprintf(stderr,"</math:mover>\n"); @@ -422,7 +421,7 @@ void Formula::makeRoot(Node *res) { Node *tmp = res; if( !tmp ) return; -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inds; if( tmp->id == ID_SQRTEXPR ) fprintf(stderr,"<math:msqrt>\n"); @@ -443,7 +442,7 @@ void Formula::makeRoot(Node *res) makeBlock(tmp->child->next); } -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inde; if( tmp->id == ID_SQRTEXPR ) fprintf(stderr,"</math:msqrt>\n"); @@ -464,7 +463,7 @@ void Formula::makeParenth(Node *res) { Node *tmp = res; if( !tmp ) return; -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inds; fprintf(stderr,"<math:mrow>\n"); inds; @@ -489,7 +488,7 @@ void Formula::makeParenth(Node *res) if( tmp->child ) makeExprList(tmp->child); -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inde; fprintf(stderr,"</math:mrow>\n"); inds; @@ -515,23 +514,23 @@ void Formula::makeParenth(Node *res) void Formula::makeFence(Node *res) { Node *tmp = res->child; -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inds; fprintf(stderr,"<math:mfenced open=\"%s\" close=\"%s\">\n", - getMathMLEntity(tmp->value).c_str(), - getMathMLEntity(tmp->next->next->value).c_str()); + getMathMLEntity(tmp->value.get()).c_str(), + getMathMLEntity(tmp->next->next->value.get()).c_str()); #else padd("open", "CDATA", - OUString(reinterpret_cast<sal_Unicode const *>(getMathMLEntity(tmp->value).c_str()))); + OUString(reinterpret_cast<sal_Unicode const *>(getMathMLEntity(tmp->value.get()).c_str()))); padd("close", "CDATA", - OUString(reinterpret_cast<sal_Unicode const *>(getMathMLEntity(tmp->next->next->value).c_str()))); + OUString(reinterpret_cast<sal_Unicode const *>(getMathMLEntity(tmp->next->next->value.get()).c_str()))); rstartEl("math:mfenced", mxList); mxList->clear(); #endif makeExprList(tmp->next); -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inde; fprintf(stderr,"</math:mfenced>\n"); #else @@ -546,7 +545,7 @@ void Formula::makeBracket(Node *res) void Formula::makeBlock(Node *res) { -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inds; fprintf(stderr,"<math:mrow>\n"); #else @@ -556,7 +555,7 @@ void Formula::makeBlock(Node *res) if( res->child ) makeExprList(res->child); -#ifdef DEBUG +#if OSL_DEBUG_LEVEL >= 2 inde; fprintf(stderr,"</math:mrow>\n"); #else @@ -569,22 +568,21 @@ void Formula::parse() Node *res = nullptr; if( !eq ) return; - MzString a; + OString a; // fprintf(stderr,"\n\n[BEFORE]\n[%s]\n",eq); eq2latex(a,eq); - int idx=a.find(sal::static_int_cast<char>(0xff)); - while(idx){ + int idx=a.indexOf('\xff'); + while(idx >= 0){ //printf("idx = [%d]\n",idx); - a.replace(idx,0x20); - if((idx = a.find(sal::static_int_cast<char>(0xff),idx+1)) < 0) - break; + a = a.replaceAt(idx, 1, "\x20"); + idx = a.indexOf('\xff', idx + 1); } - char *buf = static_cast<char *>(malloc(a.length()+1)); + char *buf = static_cast<char *>(malloc(a.getLength()+1)); bool bStart = false; int i, j; - for( i = 0, j=0 ; i < a.length() ; i++){ // rtrim and ltrim 32 10 13 + for( i = 0, j=0 ; i < a.getLength() ; i++){ // rtrim and ltrim 32 10 13 if( bStart ){ buf[j++] = a[i]; } @@ -605,7 +603,7 @@ void Formula::parse() } // fprintf(stderr,"\n\n[RESULT]\n[%s]\n",a.c_str()); if( buf[0] != '\0' ) - res = mainParse( a.c_str() ); + res = mainParse( a.getStr() ); else res = nullptr; free(buf); diff --git a/hwpfilter/source/grammar.cxx b/hwpfilter/source/grammar.cxx index d2c91860aeb6..199aab343208 100644 --- a/hwpfilter/source/grammar.cxx +++ b/hwpfilter/source/grammar.cxx @@ -21,9 +21,6 @@ /* A Bison parser, made from grammar.y by GNU Bison version 1.28 */ -#ifndef YYDEBUG -#define YYDEBUG 0 -#endif #ifndef YYMAXDEPTH #define YYMAXDEPTH 0 #endif @@ -94,70 +91,6 @@ const char yytranslate[] = { 0, 27, 28, 29, 30, 31 }; -#if YYDEBUG != 0 -static const short yyprhs[] = { 0, - 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, - 20, 22, 24, 26, 28, 30, 32, 34, 36, 39, - 42, 45, 48, 51, 54, 58, 60, 63, 66, 69, - 72, 75, 79, 81, 85, 89, 92, 96, 99, 103, - 106, 110, 114, 120, 124, 130, 132, 135, 137, 140, - 143, 147, 150, 154, 157, 159, 161, 165, 167, 169, - 172, 174, 176, 178, 180, 182, 184, 186, 188, 190, - 192, 194 -}; - -static const short yyrhs[] = { 4, - 0, 9, 0, 10, 0, 5, 0, 11, 0, 12, - 0, 20, 0, 21, 0, 7, 0, 6, 0, 23, - 0, 17, 0, 18, 0, 8, 0, 32, 0, 31, - 0, 22, 0, 43, 0, 44, 43, 0, 26, 33, - 0, 26, 34, 0, 26, 35, 0, 26, 36, 0, - 26, 32, 0, 26, 32, 32, 0, 29, 0, 27, - 37, 0, 27, 38, 0, 27, 39, 0, 27, 40, - 0, 27, 32, 0, 27, 32, 32, 0, 30, 0, - 45, 64, 46, 0, 33, 64, 37, 0, 33, 37, - 0, 35, 64, 39, 0, 35, 39, 0, 34, 64, - 38, 0, 34, 38, 0, 65, 41, 65, 0, 65, - 42, 65, 0, 65, 41, 49, 42, 49, 0, 14, - 49, 49, 0, 35, 64, 16, 64, 39, 0, 3, - 0, 54, 49, 0, 19, 0, 56, 49, 0, 13, - 49, 0, 13, 50, 49, 0, 24, 49, 0, 24, - 49, 49, 0, 25, 49, 0, 62, 0, 63, 0, - 62, 28, 63, 0, 64, 0, 65, 0, 64, 65, - 0, 49, 0, 48, 0, 47, 0, 51, 0, 52, - 0, 53, 0, 57, 0, 58, 0, 55, 0, 44, - 0, 59, 0, 60, 0 -}; - -#endif - -#if YYDEBUG != 0 -static const short yyrline[] = { 0, - 59, 61, 62, 63, 64, 65, 66, 67, 68, 69, - 70, 71, 72, 73, 74, 75, 76, 79, 81, 84, - 86, 87, 88, 89, 90, 91, 94, 96, 97, 98, - 99, 100, 101, 104, 108, 110, 113, 115, 118, 120, - 123, 125, 126, 129, 133, 138, 142, 145, 149, 153, - 155, 158, 160, 163, 168, 172, 174, 177, 181, 183, - 186, 188, 189, 190, 191, 192, 193, 194, 195, 196, - 197, 198 -}; -#endif - - -#if YYDEBUG != 0 || defined (YYERROR_VERBOSE) - -static const char * const yytname[] = { "$","error","$undefined.","ACCENT", -"SMALL_GREEK","CAPITAL_GREEK","BINARY_OPERATOR","RELATION_OPERATOR","ARROW", -"GENERAL_IDEN","GENERAL_OPER","BIG_SYMBOL","FUNCTION","ROOT","FRACTION","SUBSUP", -"EQOVER","DELIMETER","LARGE_DELIM","DECORATION","SPACE_SYMBOL","CHARACTER","STRING", -"OPERATOR","EQBEGIN","EQEND","EQLEFT","EQRIGHT","NEWLINE","LEFT_DELIM","RIGHT_DELIM", -"DIGIT","'|'","'('","'['","'{'","'<'","')'","']'","'}'","'>'","'_'","'^'","Identifier", -"PrimaryExpr","EQLeft","EQRight","Fence","Parenth","Block","Bracket","SubSupExpr", -"FractionExpr","OverExpr","Accent","AccentExpr","Decoration","DecorationExpr", -"RootExpr","BeginExpr","EndExpr","MathML","Lines","Line","ExprList","Expr", NULL -}; -#endif const short yyr1[] = { 0, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, @@ -363,47 +296,15 @@ const short yycheck[] = { 11, #define YYTERROR 1 -#ifndef YYPURE #define YYLEX yylex() -#endif - -#ifdef YYPURE -#ifdef YYLSP_NEEDED -#ifdef YYLEX_PARAM -#define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM) -#else -#define YYLEX yylex(&yylval, &yylloc) -#endif -#else /* not YYLSP_NEEDED */ -#ifdef YYLEX_PARAM -#define YYLEX yylex(&yylval, YYLEX_PARAM) -#else -#define YYLEX yylex(&yylval) -#endif -#endif /* not YYLSP_NEEDED */ -#endif /* If nonreentrant, generate the variables here */ -#ifndef YYPURE - static int yychar; /* the lookahead symbol */ YYSTYPE yylval; /* the semantic value of the */ /* lookahead symbol */ -#ifdef YYLSP_NEEDED -YYLTYPE yylloc; /* location data for the lookahead */ - /* symbol */ -#endif - static int yynerrs; /* number of parse errors so far */ -#endif /* not YYPURE */ - -#if YYDEBUG != 0 -int yydebug; /* nonzero means print parse trace */ -/* Since this is uninitialized, it does not stop multiple parsers - from coexisting. */ -#endif /* YYINITDEPTH indicates the initial size of the parser's stacks */ @@ -422,28 +323,13 @@ int yydebug; /* nonzero means print parse trace */ #define YYMAXDEPTH 10000 #endif -/* The user can define YYPARSE_PARAM as the name of an argument to be passed - into yyparse. The argument should have type void *. - It should actually point to an object. - Grammar actions can access the variable by casting it - to the proper pointer type. */ - -#ifdef YYPARSE_PARAM -#define YYPARSE_PARAM_ARG void *YYPARSE_PARAM -#define YYPARSE_PARAM_DECL -#else /* not YYPARSE_PARAM */ #define YYPARSE_PARAM_ARG #define YYPARSE_PARAM_DECL -#endif /* not YYPARSE_PARAM */ /* Prevent warning if -Wstrict-prototypes. */ #ifdef __GNUC__ -#ifdef YYPARSE_PARAM -int yyparse (void *); -#else static int yyparse(); #endif -#endif static int yyparse(YYPARSE_PARAM_ARG) @@ -462,26 +348,9 @@ yyparse(YYPARSE_PARAM_ARG) short *yyss = yyssa; /* refer to the stacks through separate pointers */ YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */ -#ifdef YYLSP_NEEDED - YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */ - YYLTYPE *yyls = yylsa; - YYLTYPE *yylsp; - -#define YYPOPSTACK (yyvsp--, yyssp--, yylsp--) -#endif - int yystacksize = YYINITDEPTH; int yyfree_stacks = 0; -#ifdef YYPURE - int yychar; - YYSTYPE yylval; - int yynerrs; -#ifdef YYLSP_NEEDED - YYLTYPE yylloc; -#endif -#endif - YYSTYPE yyval; /* the variable used to return */ yyval.dval = nullptr; /* semantic values from the action */ @@ -489,11 +358,6 @@ yyparse(YYPARSE_PARAM_ARG) int yylen; -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Starting parse\n"); -#endif - yystate = 0; yyerrstatus = 0; yynerrs = 0; @@ -506,9 +370,6 @@ yyparse(YYPARSE_PARAM_ARG) yyssp = yyss - 1; yyvsp = yyvs; -#ifdef YYLSP_NEEDED - yylsp = yyls; -#endif /* Push a new state, which is found in yystate . */ /* In all cases, when you get here, the value and location stacks @@ -523,36 +384,10 @@ yynewstate: /* Use copies of these so that the &'s don't force the real ones into memory. */ YYSTYPE *yyvs1 = yyvs; short *yyss1 = yyss; -#ifdef YYLSP_NEEDED - YYLTYPE *yyls1 = yyls; -#endif /* Get the current used size of the three stacks, in elements. */ int size = yyssp - yyss + 1; -#ifdef yyoverflow - /* Each stack pointer address is followed by the size of - the data in use in that stack, in bytes. */ -#ifdef YYLSP_NEEDED - /* This used to be a conditional around just the two extra args, - but that might be undefined if yyoverflow is a macro. */ - yyoverflow("parser stack overflow", - &yyss1, size * sizeof (*yyssp), - &yyvs1, size * sizeof (*yyvsp), - &yyls1, size * sizeof (*yylsp), - &yystacksize); -#else - yyoverflow("parser stack overflow", - &yyss1, size * sizeof (*yyssp), - &yyvs1, size * sizeof (*yyvsp), - &yystacksize); -#endif - - yyss = yyss1; yyvs = yyvs1; -#ifdef YYLSP_NEEDED - yyls = yyls1; -#endif -#else /* no yyoverflow */ /* Extend the stack our own way. */ if (yystacksize >= YYMAXDEPTH) { @@ -561,9 +396,6 @@ yynewstate: { free (yyss); free (yyvs); -#ifdef YYLSP_NEEDED - free (yyls); -#endif } return 2; } @@ -575,32 +407,20 @@ yynewstate: memcpy (yyss, yyss1, size * sizeof (*yyssp)); yyvs = static_cast<YYSTYPE *>(malloc (yystacksize * sizeof (*yyvsp))); memcpy (yyvs, yyvs1, size * sizeof (*yyvsp)); -#ifdef YYLSP_NEEDED - yyls = (YYLTYPE *) malloc (yystacksize * sizeof (*yylsp)); - memcpy ((char *)yyls, (char *)yyls1, size * sizeof (*yylsp)); -#endif -#endif /* no yyoverflow */ + + // https://lists.gnu.org/archive/html/bug-bison/2001-11/msg00021.html + if (yyss1 != yyssa) + free (yyss1); + if (yyvs1 != yyvsa) + free (yyvs1); yyssp = yyss + size - 1; yyvsp = yyvs + size - 1; -#ifdef YYLSP_NEEDED - yylsp = yyls + size - 1; -#endif - -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Stack size increased to %d\n", yystacksize); -#endif if (yyssp >= yyss + yystacksize - 1) YYABORT; } -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Entering state %d\n", yystate); -#endif - goto yybackup; yybackup: @@ -621,10 +441,6 @@ yynewstate: if (yychar == YYEMPTY) { -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Reading a token: "); -#endif yychar = YYLEX; } @@ -635,27 +451,11 @@ yynewstate: yychar1 = 0; yychar = YYEOF; /* Don't call YYLEX any more */ -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Now at end of input.\n"); -#endif } else { yychar1 = YYTRANSLATE(yychar); -#if YYDEBUG != 0 - if (yydebug) - { - fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]); - /* Give the individual parser a way to print the precise meaning - of a token, for further debugging info. */ -#ifdef YYPRINT - YYPRINT (stderr, yychar, yylval); -#endif - fprintf (stderr, ")\n"); - } -#endif } yyn += yychar1; @@ -686,19 +486,11 @@ yynewstate: /* Shift the lookahead token. */ -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]); -#endif - /* Discard the token being shifted unless it is eof. */ if (yychar != YYEOF) yychar = YYEMPTY; *++yyvsp = yylval; -#ifdef YYLSP_NEEDED - *++yylsp = yylloc; -#endif /* count tokens shifted since error; after three, turn off error status. */ if (yyerrstatus) yyerrstatus--; @@ -719,74 +511,58 @@ yyreduce: if (yylen > 0) yyval = yyvsp[1-yylen]; /* implement default value of the action */ -#if YYDEBUG != 0 - if (yydebug) - { - int i; - - fprintf (stderr, "Reducing via rule %d (line %d), ", - yyn, yyrline[yyn]); - - /* Print the symbols being reduced, and their result. */ - for (i = yyprhs[yyn]; yyrhs[i] > 0; i++) - fprintf (stderr, "%s ", yytname[yyrhs[i]]); - fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]); - } -#endif - - switch (yyn) { case 1: -{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr); +{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value.reset(strdup(yyvsp[0].str)); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr); break;} case 2: -{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr); +{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value.reset(strdup(yyvsp[0].str)); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr); break;} case 3: -{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr); +{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value.reset(strdup(yyvsp[0].str)); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr); break;} case 4: -{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr); +{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value.reset(strdup(yyvsp[0].str)); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr); break;} case 5: -{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr); +{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value.reset(strdup(yyvsp[0].str)); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr); break;} case 6: -{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr); +{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value.reset(strdup(yyvsp[0].str)); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr); break;} case 7: -{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr); +{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value.reset(strdup(yyvsp[0].str)); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr); break;} case 8: -{ yyval.ptr = new Node(ID_CHARACTER); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr); +{ yyval.ptr = new Node(ID_CHARACTER); yyval.ptr->value.reset(strdup(yyvsp[0].str)); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr); break;} case 9: -{ yyval.ptr = new Node(ID_OPERATOR); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr); +{ yyval.ptr = new Node(ID_OPERATOR); yyval.ptr->value.reset(strdup(yyvsp[0].str)); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr); break;} case 10: -{ yyval.ptr = new Node(ID_OPERATOR); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr); +{ yyval.ptr = new Node(ID_OPERATOR); yyval.ptr->value.reset(strdup(yyvsp[0].str)); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr); break;} case 11: -{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr); +{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value.reset(strdup(yyvsp[0].str)); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr); break;} case 12: -{ yyval.ptr = new Node(ID_DELIMITER); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr); +{ yyval.ptr = new Node(ID_DELIMITER); yyval.ptr->value.reset(strdup(yyvsp[0].str)); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr); break;} case 13: -{ yyval.ptr = new Node(ID_DELIMITER); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr); +{ yyval.ptr = new Node(ID_DELIMITER); yyval.ptr->value.reset(strdup(yyvsp[0].str)); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr); break;} case 14: -{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr); +{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value.reset(strdup(yyvsp[0].str)); debug("Identifier : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr); break;} case 15: -{ yyval.ptr = new Node(ID_CHARACTER); yyval.ptr->value = strdup("|"); debug("Identifier : '|'\n"); nodelist.emplace_back(yyval.ptr); +{ yyval.ptr = new Node(ID_CHARACTER); yyval.ptr->value.reset(strdup("|")); debug("Identifier : '|'\n"); nodelist.emplace_back(yyval.ptr); break;} case 16: -{ yyval.ptr = new Node(ID_NUMBER); yyval.ptr->value = strdup(yyvsp[0].dval); debug("Number : %s\n",yyvsp[0].dval); nodelist.emplace_back(yyval.ptr); +{ yyval.ptr = new Node(ID_NUMBER); yyval.ptr->value.reset(strdup(yyvsp[0].dval)); debug("Number : %s\n",yyvsp[0].dval); nodelist.emplace_back(yyval.ptr); break;} case 17: -{ yyval.ptr = new Node(ID_STRING); yyval.ptr->value = strdup(yyvsp[0].str); debug("String : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr); +{ yyval.ptr = new Node(ID_STRING); yyval.ptr->value.reset(strdup(yyvsp[0].str)); debug("String : %s\n",yyvsp[0].str); nodelist.emplace_back(yyval.ptr); break;} case 18: { yyval.ptr = new Node(ID_PRIMARYEXPR); yyval.ptr->child = yyvsp[0].ptr; debug("PrimaryExpr\n"); nodelist.emplace_back(yyval.ptr); @@ -795,46 +571,46 @@ case 19: { yyval.ptr = new Node(ID_PRIMARYEXPR); yyval.ptr->child = yyvsp[-1].ptr; yyval.ptr->next = yyvsp[0].ptr; debug("PrimaryExpr : PrimaryExpr Identifier\n"); nodelist.emplace_back(yyval.ptr); break;} case 20: -{ yyval.ptr = new Node(ID_LEFT); yyval.ptr->value = strdup("("); debug("EQLeft \n"); nodelist.emplace_back(yyval.ptr); +{ yyval.ptr = new Node(ID_LEFT); yyval.ptr->value.reset(strdup("(")); debug("EQLeft \n"); nodelist.emplace_back(yyval.ptr); break;} case 21: -{ yyval.ptr = new Node(ID_LEFT); yyval.ptr->value = strdup("["); debug("EQLeft \n"); nodelist.emplace_back(yyval.ptr); +{ yyval.ptr = new Node(ID_LEFT); yyval.ptr->value.reset(strdup("[")); debug("EQLeft \n"); nodelist.emplace_back(yyval.ptr); break;} case 22: -{ yyval.ptr = new Node(ID_LEFT); yyval.ptr->value = strdup("{"); debug("EQLeft \n"); nodelist.emplace_back(yyval.ptr); +{ yyval.ptr = new Node(ID_LEFT); yyval.ptr->value.reset(strdup("{")); debug("EQLeft \n"); nodelist.emplace_back(yyval.ptr); break;} case 23: -{ yyval.ptr = new Node(ID_LEFT); yyval.ptr->value = strdup("<"); debug("EQLeft \n"); nodelist.emplace_back(yyval.ptr); +{ yyval.ptr = new Node(ID_LEFT); yyval.ptr->value.reset(strdup("<")); debug("EQLeft \n"); nodelist.emplace_back(yyval.ptr); break;} case 24: -{ yyval.ptr = new Node(ID_LEFT); yyval.ptr->value = strdup("|"); debug("EQLeft \n"); nodelist.emplace_back(yyval.ptr); +{ yyval.ptr = new Node(ID_LEFT); yyval.ptr->value.reset(strdup("|")); debug("EQLeft \n"); nodelist.emplace_back(yyval.ptr); break;} case 25: -{ yyval.ptr = new Node(ID_LEFT); yyval.ptr->value =strdup("||"); debug("EQLeft \n"); nodelist.emplace_back(yyval.ptr); +{ yyval.ptr = new Node(ID_LEFT); yyval.ptr->value.reset(strdup("||")); debug("EQLeft \n"); nodelist.emplace_back(yyval.ptr); break;} case 26: -{ yyval.ptr = new Node(ID_LEFT); yyval.ptr->value = strdup(yyvsp[0].str); debug("EQLeft \n"); nodelist.emplace_back(yyval.ptr); +{ yyval.ptr = new Node(ID_LEFT); yyval.ptr->value.reset(strdup(yyvsp[0].str)); debug("EQLeft \n"); nodelist.emplace_back(yyval.ptr); break;} case 27: -{ yyval.ptr = new Node(ID_RIGHT); yyval.ptr->value = strdup(")"); debug("EQRight \n"); nodelist.emplace_back(yyval.ptr); +{ yyval.ptr = new Node(ID_RIGHT); yyval.ptr->value.reset(strdup(")")); debug("EQRight \n"); nodelist.emplace_back(yyval.ptr); break;} case 28: -{ yyval.ptr = new Node(ID_RIGHT); yyval.ptr->value = strdup("]"); debug("EQRight \n"); nodelist.emplace_back(yyval.ptr); +{ yyval.ptr = new Node(ID_RIGHT); yyval.ptr->value.reset(strdup("]")); debug("EQRight \n"); nodelist.emplace_back(yyval.ptr); break;} case 29: -{ yyval.ptr = new Node(ID_RIGHT); yyval.ptr->value = strdup("}"); debug("EQRight \n"); nodelist.emplace_back(yyval.ptr); +{ yyval.ptr = new Node(ID_RIGHT); yyval.ptr->value.reset(strdup("}")); debug("EQRight \n"); nodelist.emplace_back(yyval.ptr); break;} case 30: -{ yyval.ptr = new Node(ID_RIGHT); yyval.ptr->value = strdup(">"); debug("EQRight \n"); nodelist.emplace_back(yyval.ptr); +{ yyval.ptr = new Node(ID_RIGHT); yyval.ptr->value.reset(strdup(">")); debug("EQRight \n"); nodelist.emplace_back(yyval.ptr); break;} case 31: -{ yyval.ptr = new Node(ID_RIGHT); yyval.ptr->value = strdup("|"); debug("EQRight \n"); nodelist.emplace_back(yyval.ptr); +{ yyval.ptr = new Node(ID_RIGHT); yyval.ptr->value.reset(strdup("|")); debug("EQRight \n"); nodelist.emplace_back(yyval.ptr); break;} case 32: -{ yyval.ptr = new Node(ID_RIGHT); yyval.ptr->value = strdup("||"); debug("EQRight \n"); nodelist.emplace_back(yyval.ptr); +{ yyval.ptr = new Node(ID_RIGHT); yyval.ptr->value.reset(strdup("||")); debug("EQRight \n"); nodelist.emplace_back(yyval.ptr); break;} case 33: -{ yyval.ptr = new Node(ID_RIGHT); yyval.ptr->value = strdup(yyvsp[0].str); debug("EQRight \n"); nodelist.emplace_back(yyval.ptr); +{ yyval.ptr = new Node(ID_RIGHT); yyval.ptr->value.reset(strdup(yyvsp[0].str)); debug("EQRight \n"); nodelist.emplace_back(yyval.ptr); break;} case 34: { yyval.ptr = new Node(ID_FENCE); yyval.ptr->child=yyvsp[-2].ptr; yyvsp[-2].ptr->next=yyvsp[-1].ptr; yyvsp[-1].ptr->next=yyvsp[0].ptr; debug("Fence \n"); nodelist.emplace_back(yyval.ptr); @@ -873,13 +649,13 @@ case 45: { yyval.ptr = new Node(ID_OVER); yyval.ptr->child = yyvsp[-3].ptr; yyvsp[-3].ptr->next = yyvsp[-1].ptr; debug("OverExpr\n"); nodelist.emplace_back(yyval.ptr); break;} case 46: -{ yyval.ptr = new Node(ID_ACCENTEXPR); yyval.ptr->value = strdup(yyvsp[0].str); debug("Accent : %s\n", yyvsp[0].str); nodelist.emplace_back(yyval.ptr); +{ yyval.ptr = new Node(ID_ACCENTEXPR); yyval.ptr->value.reset(strdup(yyvsp[0].str)); debug("Accent : %s\n", yyvsp[0].str); nodelist.emplace_back(yyval.ptr); break;} case 47: { yyval.ptr = new Node(ID_ACCENTEXPR); yyval.ptr->child=yyvsp[-1].ptr; yyvsp[-1].ptr->next = yyvsp[0].ptr; debug("AccentExpr \n"); nodelist.emplace_back(yyval.ptr); break;} case 48: -{ yyval.ptr = new Node(ID_DECORATIONEXPR); yyval.ptr->value = strdup(yyvsp[0].str); debug("Decoration : %s\n", yyvsp[0].str); nodelist.emplace_back(yyval.ptr); +{ yyval.ptr = new Node(ID_DECORATIONEXPR); yyval.ptr->value.reset(strdup(yyvsp[0].str)); debug("Decoration : %s\n", yyvsp[0].str); nodelist.emplace_back(yyval.ptr); break;} case 49: { yyval.ptr = new Node(ID_DECORATIONEXPR); yyval.ptr->child = yyvsp[-1].ptr; yyvsp[-1].ptr->next = yyvsp[0].ptr; debug("DecorationExpr \n"); nodelist.emplace_back(yyval.ptr); @@ -958,40 +734,9 @@ case 72: yyvsp -= yylen; yyssp -= yylen; -#ifdef YYLSP_NEEDED - yylsp -= yylen; -#endif - -#if YYDEBUG != 0 - if (yydebug) - { - short *ssp1 = yyss - 1; - fprintf (stderr, "state stack now"); - while (ssp1 != yyssp) - fprintf (stderr, " %d", *++ssp1); - fprintf (stderr, "\n"); - } -#endif *++yyvsp = yyval; -#ifdef YYLSP_NEEDED - yylsp++; - if (yylen == 0) - { - yylsp->first_line = yylloc.first_line; - yylsp->first_column = yylloc.first_column; - yylsp->last_line = (yylsp-1)->last_line; - yylsp->last_column = (yylsp-1)->last_column; - yylsp->text = 0; - } - else - { - yylsp->last_line = (yylsp+yylen-1)->last_line; - yylsp->last_column = (yylsp+yylen-1)->last_column; - } -#endif - /* Now "shift" the result of the reduction. Determine what state that goes to, based on the state we popped back to @@ -1069,11 +814,6 @@ yyerrlab1: /* here on error raised explicitly by an action */ if (yychar == YYEOF) YYABORT; -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]); -#endif - yychar = YYEMPTY; } @@ -1098,20 +838,6 @@ yyerrpop: /* pop the current state because it cannot handle the error token */ if (yyssp == yyss) YYABORT; yyvsp--; yystate = *--yyssp; -#ifdef YYLSP_NEEDED - yylsp--; -#endif - -#if YYDEBUG != 0 - if (yydebug) - { - short *ssp1 = yyss - 1; - fprintf (stderr, "Error: state stack now"); - while (ssp1 != yyssp) - fprintf (stderr, " %d", *++ssp1); - fprintf (stderr, "\n"); - } -#endif yyerrhandle: @@ -1137,15 +863,7 @@ yyerrhandle: if (yyn == YYFINAL) YYACCEPT; -#if YYDEBUG != 0 - if (yydebug) - fprintf(stderr, "Shifting error token, "); -#endif - *++yyvsp = yylval; -#ifdef YYLSP_NEEDED - *++yylsp = yylloc; -#endif yystate = yyn; goto yynewstate; @@ -1156,9 +874,6 @@ yyerrhandle: { free (yyss); free (yyvs); -#ifdef YYLSP_NEEDED - free (yyls); -#endif } return 0; @@ -1168,19 +883,17 @@ yyerrhandle: { free (yyss); free (yyvs); -#ifdef YYLSP_NEEDED - free (yyls); -#endif } return 1; } - Node *mainParse(const char *_code) { initFlex( _code ); top = nullptr; yyparse(); + deinitFlex(); + if( top ) return top; else diff --git a/hwpfilter/source/grammar.h b/hwpfilter/source/grammar.h index 0a87a6aa1832..e18a8445590c 100644 --- a/hwpfilter/source/grammar.h +++ b/hwpfilter/source/grammar.h @@ -18,39 +18,43 @@ */ typedef union { - char *dval; - char *str; + const char *dval; + const char *str; Node *ptr; } YYSTYPE; -#define ACCENT 257 -#define SMALL_GREEK 258 -#define CAPITAL_GREEK 259 -#define BINARY_OPERATOR 260 -#define RELATION_OPERATOR 261 -#define ARROW 262 -#define GENERAL_IDEN 263 -#define GENERAL_OPER 264 -#define BIG_SYMBOL 265 -#define FUNCTION 266 -#define ROOT 267 -#define FRACTION 268 -#define SUBSUP 269 -#define EQOVER 270 -#define DELIMETER 271 -#define LARGE_DELIM 272 -#define DECORATION 273 -#define SPACE_SYMBOL 274 -#define CHARACTER 275 -#define STRING 276 -#define OPERATOR 277 -#define EQBEGIN 278 -#define EQEND 279 -#define EQLEFT 280 -#define EQRIGHT 281 -#define NEWLINE 282 -#define LEFT_DELIM 283 -#define RIGHT_DELIM 284 -#define DIGIT 285 + +enum Grammar +{ + ACCENT = 257, + SMALL_GREEK = 258, + CAPITAL_GREEK = 259, + BINARY_OPERATOR = 260, + RELATION_OPERATOR = 261, + ARROW = 262, + GENERAL_IDEN = 263, + GENERAL_OPER = 264, + BIG_SYMBOL = 265, + FUNCTION = 266, + ROOT = 267, + FRACTION = 268, + SUBSUP = 269, + EQOVER = 270, + DELIMETER = 271, + LARGE_DELIM = 272, + DECORATION = 273, + SPACE_SYMBOL = 274, + CHARACTER = 275, + STRING = 276, + OPERATOR = 277, + EQBEGIN = 278, + EQEND = 279, + EQLEFT = 280, + EQRIGHT = 281, + NEWLINE = 282, + LEFT_DELIM = 283, + RIGHT_DELIM = 284, + DIGIT = 285, +}; extern YYSTYPE yylval; diff --git a/hwpfilter/source/grammar.hxx b/hwpfilter/source/grammar.hxx index a4a2e39cb0bb..041b4606a530 100644 --- a/hwpfilter/source/grammar.hxx +++ b/hwpfilter/source/grammar.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_HWPFILTER_SOURCE_GRAMMAR_HXX -#define INCLUDED_HWPFILTER_SOURCE_GRAMMAR_HXX +#pragma once #include <sal/config.h> @@ -26,6 +25,4 @@ class Node; Node* mainParse(char const* _code); -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/hwpfilter/source/hbox.cxx b/hwpfilter/source/hbox.cxx index 6bbf6d22448b..855b73e25c6c 100644 --- a/hwpfilter/source/hbox.cxx +++ b/hwpfilter/source/hbox.cxx @@ -29,7 +29,10 @@ #include "hcode.h" #include "datecode.h" +#include <o3tl/sprintf.hxx> #include <rtl/character.hxx> +#include <rtl/strbuf.hxx> +#include <rtl/string.hxx> int HBox::boxCount = 0; @@ -107,6 +110,8 @@ DateFormat::DateFormat() // date code(8) DateCode::DateCode() : HBox(CH_DATE_CODE) + , format{0} + , date{0} , dummy(0) , key(0) { @@ -146,7 +151,7 @@ hchar_string DateCode::GetString() format[DATE_SIZE - 1] = 0; fmt = format[0] ? format : defaultform; - for (; *fmt && (static_cast<int>(ret.size()) < DATE_SIZE); fmt++) + for (; *fmt && (ret.size() < DATE_SIZE); fmt++) { form = add_zero ? "%02d" : "%d"; @@ -171,13 +176,20 @@ hchar_string DateCode::GetString() num = date[MONTH]; break; case '@': - memcpy(cbuf, eng_mon + (date[MONTH] - 1) * 3, 3); + { + static_assert((std::size(eng_mon) - 1) / 3 == 12); + size_t nIndex = o3tl::make_unsigned(date[MONTH] - 1) % 12; + memcpy(cbuf, eng_mon + nIndex * 3, 3); cbuf[3] = '.'; cbuf[4] = 0; - break; + break; + } case '*': - strncat(cbuf, en_mon[date[MONTH] - 1], sizeof(cbuf) - strlen(cbuf) - 1); + { + size_t nIndex = o3tl::make_unsigned(date[MONTH] - 1) % std::size(en_mon); + strncat(cbuf, en_mon[nIndex], sizeof(cbuf) - strlen(cbuf) - 1); break; + } case '3': /* 'D' is day of korean */ num = date[DAY]; break; @@ -210,16 +222,26 @@ hchar_string DateCode::GetString() num = date[MIN]; break; case '6': - ret.push_back(kor_week[date[WEEK]]); + { + size_t nIndex = o3tl::make_unsigned(date[WEEK]) % std::size(kor_week); + ret.push_back(kor_week[nIndex]); break; + } case '^': - memcpy(cbuf, eng_week + date[WEEK] * 3, 3); + { + static_assert((std::size(eng_week) - 1) / 3 == 7); + size_t nIndex = o3tl::make_unsigned(date[WEEK]) % 7; + memcpy(cbuf, eng_week + nIndex * 3, 3); cbuf[3] = '.'; cbuf[4] = 0; break; + } case '_': - strncat(cbuf, en_week[date[WEEK]], sizeof(cbuf) - strlen(cbuf) - 1); + { + size_t nIndex = o3tl::make_unsigned(date[WEEK]) % std::size(en_week); + strncat(cbuf, en_week[nIndex], sizeof(cbuf) - strlen(cbuf) - 1); break; + } case '7': ret.push_back(0xB5A1); ret.push_back(is_pm ? 0xD281 : 0xB8E5); @@ -255,7 +277,8 @@ hchar_string DateCode::GetString() fmt++; if (*fmt == '6') { - ret.push_back(china_week[date[WEEK]]); + size_t nIndex = o3tl::make_unsigned(date[WEEK]) % std::size(china_week); + ret.push_back(china_week[nIndex]); break; } break; @@ -265,7 +288,7 @@ hchar_string DateCode::GetString() ret.push_back(*fmt); } if (num != -1) - sprintf(cbuf, form, num); + o3tl::sprintf(cbuf, form, num); for (i = 0; 0 != cbuf[i]; i++) { ret.push_back(*(cbuf + i)); @@ -344,6 +367,7 @@ TxtBox::~TxtBox() Picture::Picture() : FBox(CH_PICTURE) + , reserved{0} , dummy(0) , follow_block_size(0) , dummy1(0) @@ -352,6 +376,10 @@ Picture::Picture() , cap_pos(0) , num(0) , pictype(0) + , skip{0} + , scale{0} + , picinfo{} + , reserved3{0} , ishyper(false) { } @@ -403,7 +431,7 @@ hchar_string MailMerge::GetString() #define OL_HANGL_JASO 0 #define OL_HANGL_KANATA 1 -static hchar olHanglJaso(int num, int type) +static hchar olHanglJaso(unsigned int num, int type) { static const unsigned char han_init[] = { 0x88, 0x90, 0x94, 0x9c, 0xa0, 0xa4, 0xac, 0xb4, 0xb8, 0xc0, 0xc4, 0xc8, 0xcc, 0xd0 }; @@ -439,7 +467,7 @@ static hchar olHanglJaso(int num, int type) static const hchar *GetOutlineStyleChars(int style) { - static const hchar out_bul_style_entry[5][8] = // extern + static const hchar out_bul_style_entry[5][MAX_OUTLINE_LEVEL+1] = // extern { { // 0 OLSTY_BULLET1 0x2f18, 0x2f12, 0x2f08, 0x2f02, 0x2f06, 0x2f00, 0x2043, 0x0000 @@ -454,7 +482,7 @@ static const hchar *GetOutlineStyleChars(int style) 0x2f18, 0x2f16, 0x2f12, 0x2f10, 0x2f06, 0x2f00, 0x2043, 0x0000 }, { - 0xAC61, 0xB677, 0xB861, 0xB8F7, 0xB781, 0x0000 + 0xAC61, 0xB677, 0xB861, 0xB8F7, 0xB781, 0x0000, 0x0000, 0x0000 }, }; if (style >= OLSTY_BULLET1 && style <= OLSTY_BULLET5) @@ -494,9 +522,9 @@ static void getOutlineNumStr(int style, int level, int num, hchar * hstr) *hstr++ = '('; if (fmt & NUM) { - sprintf(buf, "%d", num); - str2hstr(buf, hstr); - hstr += strlen(buf); + auto const numbuf = OString::number(num); + str2hstr(numbuf.buf, hstr); + hstr += numbuf.length; } else if (fmt & (U_ROM | L_ROM)) { @@ -536,7 +564,7 @@ enum number has the value. ex) '1.2.1' has '1,2,1' style has the value which starts from 1 according to the definition in hbox.h */ -hchar_string Outline::GetUnicode() const +OUString Outline::GetUnicode() const { const hchar *p; hchar buffer[255]; @@ -550,130 +578,131 @@ hchar_string Outline::GetUnicode() const case OLSTY_NUMS1: case OLSTY_NUMS2: { - char cur_num_str[10], buf[80]; - int i; - - buf[0] = 0; - for (i = 0; i <= level; i++) + OStringBuffer buf; + for (unsigned int i = 0; i <= level; ++i) { + if (i >= std::size(number)) + break; + levelnum = ((number[i] < 1) ? 1 : number[i]); - if (shape == OLSTY_NUMS2 && i && i == level) - sprintf(cur_num_str, "%d%c", levelnum, 0); - else - sprintf(cur_num_str, "%d%c", levelnum, '.'); - strcat(buf, cur_num_str); + buf.append(OString::number(levelnum)); + if (!(shape == OLSTY_NUMS2 && i && i == level)) + buf.append('.'); } - str2hstr(buf, buffer); - return hstr2ucsstr(buffer); + str2hstr(buf.getStr(), buffer); + return hstr2OUString(buffer); } case OLSTY_NUMSIG1: case OLSTY_NUMSIG2: case OLSTY_NUMSIG3: - { - getOutlineNumStr(shape, level, number[level], buffer); - return hstr2ucsstr(buffer); - } + { + if (level < std::size(number)) + getOutlineNumStr(shape, level, number[level], buffer); + return hstr2OUString(buffer); + } case OLSTY_BULLET1: case OLSTY_BULLET2: case OLSTY_BULLET3: case OLSTY_BULLET4: case OLSTY_BULLET5: + { + if (level < MAX_OUTLINE_LEVEL) { - p = GetOutlineStyleChars(shape); - buffer[0] = p[level]; - buffer[1] = 0; - return hstr2ucsstr(buffer); + p = GetOutlineStyleChars(shape); + buffer[0] = p[level]; + buffer[1] = 0; } + return hstr2OUString(buffer); + } case OLSTY_USER: case OLSTY_BULUSER: { char dest[80]; int l = 0; - int i = level; - if( deco[i][0] ){ + unsigned i = level; + if (i < std::size(deco) && deco[i][0]) { buffer[l++] = deco[i][0]; } -/* level starts from zero. ex) '1.1.1.' is the level 2. - number has the value. ex) '1.2.1' has '1,2,1' - style has the value which starts from 1 according to the definition in hbox.h - */ - switch( user_shape[i] ) + if (i < std::size(user_shape)) { - case 0: - buffer[l++] = '1' + number[i] - 1; - break; - case 1: /* Uppercase Roman */ - case 2: /* Lowercase Roman */ - num2roman(number[i], dest); - if( user_shape[i] == 1 ){ - char *ptr = dest; - while( *ptr ) - { - *ptr = sal::static_int_cast<char>(rtl::toAsciiUpperCase(static_cast<unsigned char>(*ptr))); - ptr++; + /* level starts from zero. ex) '1.1.1.' is the level 2. + number has the value. ex) '1.2.1' has '1,2,1' + style has the value which starts from 1 according to the definition in hbox.h */ + switch( user_shape[i] ) + { + case 0: + buffer[l++] = '1' + number[i] - 1; + break; + case 1: /* Uppercase Roman */ + case 2: /* Lowercase Roman */ + num2roman(number[i], dest); + if( user_shape[i] == 1 ){ + char *ptr = dest; + while( *ptr ) + { + *ptr = sal::static_int_cast<char>(rtl::toAsciiUpperCase(static_cast<unsigned char>(*ptr))); + ptr++; + } } + str2hstr(dest, buffer + l); + l += strlen(dest); + break; + case 3: + buffer[l++] = 'A' + number[i] -1; + break; + case 4: + buffer[l++] = 'a' + number[i] -1; + break; + case 5: + buffer[l++] = olHanglJaso(number[i] -1, OL_HANGL_KANATA); + break; + case 6: + buffer[l++] = olHanglJaso(number[i] -1, OL_HANGL_JASO); + break; + case 7: /* Chinese numbers: the number represented by the general */ + buffer[l++] = '1' + number[i] -1; + break; + case 8: /* Circled numbers */ + buffer[l++] = 0x2e00 + number[i]; + break; + case 9: /* Circled lowercase alphabet */ + buffer[l++] = 0x2c20 + number[i]; + break; + case 10: /* Circled Korean Alphabet */ + buffer[l++] = 0x2c50 + number[i] -1; + break; + case 11: /* Circled Korean Characters */ + buffer[l++] = 0x2c40 + number[i] -1; + break; + case 12: /* Sequenced numbers. */ + { + OStringBuffer buf; + int j; + for (j = 0; j <= level; j++) + { + levelnum = ((number[j] < 1) ? 1 : number[j]); + buf.append(OString::number(levelnum)); + if (!((j && j == level) || (j == level && deco[i][1]))) + buf.append('.'); + } + str2hstr(buf.getStr(), buffer + l); + l += buf.getLength(); + break; } - str2hstr(dest, buffer + l); - l += strlen(dest); - break; - case 3: - buffer[l++] = 'A' + number[i] -1; - break; - case 4: - buffer[l++] = 'a' + number[i] -1; - break; - case 5: - buffer[l++] = olHanglJaso(number[i] -1, OL_HANGL_KANATA); - break; - case 6: - buffer[l++] = olHanglJaso(number[i] -1, OL_HANGL_JASO); - break; - case 7: /* Chinese numbers: the number represented by the general */ - buffer[l++] = '1' + number[i] -1; - break; - case 8: /* Circled numbers */ - buffer[l++] = 0x2e00 + number[i]; - break; - case 9: /* Circled lowercase alphabet */ - buffer[l++] = 0x2c20 + number[i]; - break; - case 10: /* Circled Korean Alphabet */ - buffer[l++] = 0x2c50 + number[i] -1; - break; - case 11: /* Circled Korean Characters */ - buffer[l++] = 0x2c40 + number[i] -1; - break; - case 12: /* Sequenced numbers. */ - { - char cur_num_str[10],buf[80]; - int j; - buf[0] = 0; - for (j = 0; j <= level; j++) - { - levelnum = ((number[j] < 1) ? 1 : number[j]); - if ((j && j == level) || (j == level && deco[i][1])) - sprintf(cur_num_str, "%d%c", levelnum, 0); - else - sprintf(cur_num_str, "%d%c", levelnum, '.'); - strcat(buf, cur_num_str); - } - str2hstr(buf, buffer + l); - l += strlen(buf); - break; + default: + buffer[l++] = user_shape[i]; + break; } - default: - buffer[l++] = user_shape[i]; - break; } - if( deco[i][1] ){ + if (i < std::size(deco) && deco[i][1]) { buffer[l++] = deco[i][1]; } buffer[l] = 0; - return hstr2ucsstr(buffer); + return hstr2OUString(buffer); } } } - return hstr2ucsstr(buffer); + return hstr2OUString(buffer); } diff --git a/hwpfilter/source/hbox.h b/hwpfilter/source/hbox.h index 869fedd8ba90..e07027882350 100644 --- a/hwpfilter/source/hbox.h +++ b/hwpfilter/source/hbox.h @@ -25,6 +25,7 @@ #include <array> #include <memory> +#include <rtl/ustring.hxx> #include <sal/types.h> #include "hwplib.h" @@ -360,7 +361,9 @@ struct TxtBox: public FBox /** * Paragraph list */ - std::vector<std::vector<std::unique_ptr<HWPPara>>> plists; + typedef std::vector<std::unique_ptr<HWPPara>> plist_t; + typedef std::vector<plist_t> plists_t; + plists_t plists; /** * Caption @@ -520,15 +523,6 @@ enum pictype PICTYPE_FILE, PICTYPE_OLE, PICTYPE_EMBED, PICTYPE_DRAW, PICTYPE_UNKNOWN }; -/** - * @short External image file - */ -struct PicDefFile -{ - char path[256]; - void *img; - bool skipfind; -}; /** * @short Embedded image file @@ -538,15 +532,6 @@ struct PicDefEmbed char embname[16]; }; -/** - * @short Win32 ole object - */ -struct PicDefOle -{ - char embname[16]; - void *hwpole; -}; - struct HWPDrawingObject; /** @@ -570,9 +555,7 @@ struct PicDefUnknown typedef union { - PicDefFile picfile; PicDefEmbed picembed; - PicDefOle picole; PicDefDraw picdraw; PicDefUnknown picun; } PicDef; @@ -617,7 +600,7 @@ struct Picture: public FBox * Ratio of magnification or reduction. */ hunit scale[2]; - PicDef picinfo = {}; + PicDef picinfo; char reserved3[9]; std::vector<std::unique_ptr<HWPPara>> caption; @@ -969,7 +952,7 @@ class Outline: public HBox Outline(); virtual bool Read(HWPFile &hwpf) override; - hchar_string GetUnicode() const; + OUString GetUnicode() const; }; /* Bundle of spaces (30) */ diff --git a/hwpfilter/source/hcode.cxx b/hwpfilter/source/hcode.cxx index 514e594a2c49..d97387c54efe 100644 --- a/hwpfilter/source/hcode.cxx +++ b/hwpfilter/source/hcode.cxx @@ -23,11 +23,20 @@ * Hanja johap code => ks code => unicode * Special johap code => ks code => unicode */ + +#include <sal/config.h> + #include "precompile.h" +#include <comphelper/base64.hxx> +#include <comphelper/sequence.hxx> #include <basegfx/numeric/ftools.hxx> +#include <o3tl/safeint.hxx> +#include <o3tl/sprintf.hxx> +#include <rtl/strbuf.hxx> +#include <rtl/ustrbuf.hxx> #include <sal/types.h> #include <sal/macros.h> -#include <stdio.h> + #include <stdlib.h> #include <string.h> #include <cmath> @@ -1139,7 +1148,7 @@ hchar ksc5601_sym_to_ucs2 (hchar input) unsigned char ch = sal::static_int_cast<unsigned char>(input >> 8); unsigned char ch2 = sal::static_int_cast<unsigned char>(input & 0xff); int idx = (ch - 0xA1) * 94 + (ch2 - 0xA1); - if (idx >= 0 && idx < static_cast<int>(SAL_N_ELEMENTS(ksc5601_2uni_page21))) { + if (idx >= 0 && o3tl::make_unsigned(idx) < SAL_N_ELEMENTS(ksc5601_2uni_page21)) { hchar value = ksc5601_2uni_page21[idx]; return value ? value : 0x25a1; } @@ -1151,7 +1160,7 @@ hchar ksc5601_han_to_ucs2 (hchar input) unsigned char ch = sal::static_int_cast<unsigned char>(input >> 8); unsigned char ch2 = sal::static_int_cast<unsigned char>(input & 0xff); int idx = (ch - 0xA1) * 94 + (ch2 - 0xA1); - if (idx >= 3854 && idx < static_cast<int>(3854 + SAL_N_ELEMENTS(ksc5601_2uni_page21))) { + if (idx >= 3854 && o3tl::make_unsigned(idx) < 3854 + SAL_N_ELEMENTS(ksc5601_2uni_page21)) { // Hanja : row 42 - row 93 : 3854 = 94 * (42-1) hchar value = ksc5601_2uni_page21[idx - 3854]; return value ? value : '?'; @@ -1159,17 +1168,16 @@ hchar ksc5601_han_to_ucs2 (hchar input) return '?'; } -hchar_string hstr2ucsstr(hchar const* hstr) +OUString hstr2OUString(hchar const* hstr) { - hchar_string ret; + OUStringBuffer ret; + static_assert(sizeof(hchar) == sizeof(sal_Unicode)); hchar dest[3]; for( ; *hstr ; ){ int const res = hcharconv(*hstr++, dest, UNICODE); - for (int j = 0 ; j < res ; j++) { - ret.push_back(dest[j]); - } + ret.append(reinterpret_cast<sal_Unicode*>(dest), res); } - return ret; + return ret.makeStringAndClear(); } /** @@ -1221,24 +1229,16 @@ hchar_string kstr2hstr(uchar const* src) { ret.push_back(src[i] << 8 | src[i+1]); i++; + if (src[i] == '\0') + break; } } return ret; } -/** - * Transfer integer to string following format - */ -char* Int2Str(int value, const char *format, char *buf) -{ - sprintf(buf,format,value); - return buf; -} - - /* Convert a combination of a color index value and a shade value to the color value of LibreOffice */ -char *hcolor2str(uchar color, uchar shade, char *buf, bool bIsChar) +OUString hcolor2str(uchar color, uchar shade, bool bIsChar) { unsigned short red,green,blue; @@ -1289,12 +1289,21 @@ char *hcolor2str(uchar color, uchar shade, char *buf, bool bIsChar) blue = 0xff; break; } + return rgb2str(red, green, blue); +} + - sprintf(buf,"#%02x%02x%02x", red, green, blue); - return buf; +OUString rgb2str(unsigned char red, unsigned char green, unsigned char blue) +{ + char buf[8]; + int n = std::max(o3tl::sprintf(buf, "#%02x%02x%02x", red, green, blue), 0); + return OUString::createFromAscii(std::string_view(buf, n)); } +OUString rgb2str(int32_t rgb) { return rgb2str(rgb & 0xff, (rgb >> 8) & 0xff, (rgb >> 16) & 0xff); } + + ::std::string urltounix(const char *src) { ::std::string ret; @@ -1383,57 +1392,14 @@ char *hcolor2str(uchar color, uchar shade, char *buf, bool bIsChar) } #endif -char* base64_encode_string( const uchar *buf, unsigned int len ) +OUString base64_encode_string( const uchar *buf, unsigned int len ) { - char basis_64[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - char * out; - int inPos = 0; - int outPos = 0; - int c1, c2; - unsigned int i; - - out=static_cast<char *>(malloc( (len*4/3)+8 )); - -/* Get three characters at a time and encode them. */ - for (i=0; i < len/3; ++i) - { - c1 = buf[inPos++] & 0xFF; - c2 = buf[inPos++] & 0xFF; - int c3 = buf[inPos++] & 0xFF; - out[outPos++] = basis_64[(c1 & 0xFC) >> 2]; - out[outPos++] = basis_64[((c1 & 0x03) << 4) | ((c2 & 0xF0) >> 4)]; - out[outPos++] = basis_64[((c2 & 0x0F) << 2) | ((c3 & 0xC0) >> 6)]; - out[outPos++] = basis_64[c3 & 0x3F]; - } - -/* Encode the remaining one or two characters. */ - - switch (len % 3) - { - case 0: - break; - case 1: - c1 = buf[inPos] & 0xFF; - out[outPos++] = basis_64[(c1 & 0xFC) >> 2]; - out[outPos++] = basis_64[((c1 & 0x03) << 4)]; - out[outPos++] = '='; - out[outPos++] = '='; - break; - case 2: - c1 = buf[inPos++] & 0xFF; - c2 = buf[inPos] & 0xFF; - out[outPos++] = basis_64[(c1 & 0xFC) >> 2]; - out[outPos++] = basis_64[((c1 & 0x03) << 4) | ((c2 & 0xF0) >> 4)]; - out[outPos++] = basis_64[((c2 & 0x0F) << 2)]; - out[outPos++] = '='; - break; - } - out[outPos] = 0; - return out; + OStringBuffer aBuf; + comphelper::Base64::encode(aBuf, comphelper::arrayToSequence<sal_Int8>(buf, len)); + return OUString::createFromAscii(aBuf); } -double calcAngle(int x1, int y1, int x2, int y2) +double calcAngle(double x1, double y1, double x2, double y2) { y1 = -y1; y2 = -y2; @@ -1443,10 +1409,8 @@ double calcAngle(int x1, int y1, int x2, int y2) else return 270.; } - double angle; // atan2 handles all 4 quadrants - angle = basegfx::rad2deg(atan2(y2 - y1 , x2 - x1)); - return angle; + return basegfx::rad2deg(atan2(y2 - y1 , x2 - x1)); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/hwpfilter/source/hcode.h b/hwpfilter/source/hcode.h index 3fb2da528ef7..53c1513e246f 100644 --- a/hwpfilter/source/hcode.h +++ b/hwpfilter/source/hcode.h @@ -19,6 +19,10 @@ #pragma once +#include <sal/config.h> + +#include <rtl/ustring.hxx> + #include "hwplib.h" /** @@ -34,7 +38,7 @@ DLLEXPORT int hcharconv(hchar ch, hchar *dest, int codeType) ; DLLEXPORT int kssm_hangul_to_ucs2(hchar ch, hchar *dest) ; DLLEXPORT hchar ksc5601_han_to_ucs2 (hchar); DLLEXPORT hchar ksc5601_sym_to_ucs2 (hchar); -DLLEXPORT hchar_string hstr2ucsstr(hchar const* hstr); +DLLEXPORT OUString hstr2OUString(hchar const* hstr); /** * 한컴스트링을 완성형스트링으로 변환한다. */ @@ -56,17 +60,15 @@ DLLEXPORT ::std::string urltounix(const char *src); #ifdef _WIN32 DLLEXPORT ::std::string urltowin(const char *src); #endif -/** - * Transfer integer to string following format - */ -DLLEXPORT char* Int2Str(int value, const char *format, char *buf); /** * color인덱스 값과 음영값을 조합하여 스타오피스의 color로 변환 */ -DLLEXPORT char *hcolor2str(uchar color, uchar shade, char *buf, bool bIsChar = false); +DLLEXPORT OUString hcolor2str(uchar color, uchar shade, bool bIsChar = false); +DLLEXPORT OUString rgb2str(unsigned char red, unsigned char green, unsigned char blue); +DLLEXPORT OUString rgb2str(int32_t rgb); -DLLEXPORT char *base64_encode_string( const uchar *buf, unsigned int len ); -DLLEXPORT double calcAngle(int x1, int y1, int x2, int y2); +DLLEXPORT OUString base64_encode_string( const uchar *buf, unsigned int len ); +DLLEXPORT double calcAngle(double x1, double y1, double x2, double y2); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/hwpfilter/source/hinfo.cxx b/hwpfilter/source/hinfo.cxx index bc1d61021d99..9a4eb628b015 100644 --- a/hwpfilter/source/hinfo.cxx +++ b/hwpfilter/source/hinfo.cxx @@ -258,6 +258,17 @@ void ParaShape::Read(HWPFile & hwpf) hwpf.ReadBlock(reserved, 2); } +CharShape::CharShape() + : index(0) + , size(0) + , color{0} + , font(0) + , space(0) + , ratio(0) + , shade(0) + , attr(0) +{ +} void CharShape::Read(HWPFile & hwpf) { @@ -265,13 +276,20 @@ void CharShape::Read(HWPFile & hwpf) if (!hwpf.Read2b(tmp16)) return; size = tmp16; - hwpf.ReadBlock(font, NLanguage); - hwpf.ReadBlock(ratio, NLanguage); - hwpf.ReadBlock(space, NLanguage); + + hwpf.Read1b(font); + hwpf.SkipBlock(NLanguage - 1); //skip unused part of remaining font field + + hwpf.Read1b(ratio); + hwpf.SkipBlock(NLanguage - 1); //skip unused part of remaining ratio field + + hwpf.Read1b(space); + hwpf.SkipBlock(NLanguage - 1); //skip unused part of remaining space field + hwpf.ReadBlock(color, 2); hwpf.Read1b(shade); hwpf.Read1b(attr); - hwpf.ReadBlock(reserved, 4); + hwpf.SkipBlock(4); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/hwpfilter/source/hinfo.h b/hwpfilter/source/hinfo.h index c415783e26a2..fe473f4effc4 100644 --- a/hwpfilter/source/hinfo.h +++ b/hwpfilter/source/hinfo.h @@ -65,19 +65,19 @@ struct PaperInfo } }; -/* ?????? ??????, ???????? ???? */ +/* 페이지 배경색, 배경그림 정보 */ struct PaperBackInfo { char type; // 0- background color, 1 - external image, 2- embedded image char reserved1[8] = {}; - int luminance; /* ???? ( -100 ~ 100 ) */ - int contrast; /* ???? ( -100 ~ 100 ) */ - char effect; /* 0-????????, 1-????????????, 2-???? */ + int luminance; /* 밝기 ( -100 ~ 100 ) */ + int contrast; /* 명암 ( -100 ~ 100 ) */ + char effect; /* 0-원래그림, 1-그레이스케일, 2-흑백 */ char reserved2[8] = {}; char filename[260 + 1] = {}; // filename unsigned char color[3] = {}; //0 - red, 1 - green, 2 - blue - unsigned short flag; /* 0 - ????????, 1 - ????????, 2 - ??????, 3 - ???????? */ - int range; /* 0-????, 1-????????, 3-??????, 4-?????? */ + unsigned short flag; /* 0 - 바둑판식, 1 - 가운데로, 2 - 쪽크기, 3 - 용지크기 */ + int range; /* 0-전체, 1-첫페이지, 3-짝수쪽, 4-홀수쪽 */ char reserved3[27] = {}; int size; std::vector<char> data; // image data @@ -95,7 +95,7 @@ struct PaperBackInfo } }; -/* ???????? ???? */ +/* 연결인쇄 정보 */ /** * Information of printing for chained page */ @@ -111,7 +111,7 @@ struct DocChainInfo } }; -/* ???? ???? */ +/* 문서 요약 */ /** * Summary of document */ @@ -128,13 +128,13 @@ struct HWPSummary }; /** - HWPInfo class?? HWPFile?? ???? ?????? ???? ???? ??????????. - ?????? ???? ???? ????????(layout) ?????? ???????????? - ????????, ???? ???? ?????? ???????? ????. \\ + HWPInfo class는 HWPFile에 대한 정보를 담고 있는 클래스이다. + 종이나 여백 등의 레이아웃(layout) 정보는 쪽매기기에서 + 사용하며, 기타 내부 정보를 포함하고 있다. \\ - HWPInfo ???????? HWPFile?? #GetHWPInfo()# ?????? ???? ???? ?? ????. + HWPInfo 클래스는 HWPFile의 #GetHWPInfo()# 함수를 통해 얻을 수 있다. - @memo Hwp ???? ???? + @memo Hwp 문서 정보 */ /** * Contains the basic information of the hwp document: @@ -169,12 +169,12 @@ class DLLEXPORT HWPInfo unsigned char annotation[ANNOTATION_LEN] = {}; short encrypted; // unsigned char reserved2[6]; - short beginpagenum; /* ?????????? ???? */ + short beginpagenum; /* 시작페이지 번호 */ /** * Information about footnote */ - short beginfnnum; /* ???????????? */ - short countfn; /* ???? ???? */ + short beginfnnum; /* 각주시작번호 */ + short countfn; /* 각주 갯수 */ hunit splinetext, splinefn; hunit spfnfn; unsigned char fnchar; @@ -191,7 +191,7 @@ class DLLEXPORT HWPInfo unsigned char compressed; unsigned char reserved3; short info_block_len; -/* ?????????? 128 ?????????? */ +/* 여기까지가 128 바이트이다 */ /** * Summary of document */ @@ -205,7 +205,7 @@ class DLLEXPORT HWPInfo }; -/* ???? ???? ?????? */ +/* 글자 모양 구조체 */ /** * @short Style of character */ @@ -214,23 +214,24 @@ struct CharShape /** * Index of character style */ - int index; /* ???????? ???????? ????. */ + int index; /* 스타일의 인덱스를 저장. */ /** * Font size */ hunit size; - unsigned char font[NLanguage]; - unsigned char ratio[NLanguage]; - signed char space[NLanguage]; /* ???? */ unsigned char color[2]; + unsigned char font; + char space; /* 자간 */ + unsigned char ratio; unsigned char shade; unsigned char attr; - unsigned char reserved[4]; void Read(HWPFile &); + + CharShape(); }; -/* ?? ?????? ???? ?????? */ +/* 탭 설정에 대한 구조체 */ #define MAXTABS 40 /** @@ -276,7 +277,7 @@ struct ParaShape /** * Index of paragraph style */ - int index; /* ???????? ???????? ???? */ + int index; /* 스타일의 인덱스를 저장 */ hunit left_margin; hunit right_margin; hunit indent; diff --git a/hwpfilter/source/hpara.cxx b/hwpfilter/source/hpara.cxx index 736188f1ad9e..4cddf7d76ad7 100644 --- a/hwpfilter/source/hpara.cxx +++ b/hwpfilter/source/hpara.cxx @@ -31,30 +31,30 @@ void LineInfo::Read(HWPFile & hwpf, HWPPara const *pPara) { - if (!hwpf.Read2b(pos)) - return; unsigned short tmp16; if (!hwpf.Read2b(tmp16)) return; - space_width = tmp16; + // unused field is "pos" "Starting character position" + if (!hwpf.Read2b(tmp16)) + return; + // unused field is "space_width" if (!hwpf.Read2b(tmp16)) return; - height = tmp16; -// internal information + // unused field is "height" + // internal information if (!hwpf.Read2b(tmp16)) return; pgy = tmp16; if (!hwpf.Read2b(tmp16)) return; - sx = tmp16; + // unused field is "sx" if (!hwpf.Read2b(tmp16)) return; - psx = tmp16; + // unused field is "psx" if (!hwpf.Read2b(tmp16)) return; - pex = tmp16; - height_sp = 0; + hunit pex = tmp16; if( pex >> 15 & 0x01 ) { if (pex & 0x01) @@ -78,7 +78,6 @@ HWPPara::HWPPara() , cshape(std::make_shared<CharShape>()) , pshape(std::make_shared<ParaShape>()) { - memset(cshape.get(), 0, sizeof(CharShape)); } HWPPara::~HWPPara() @@ -145,7 +144,6 @@ bool HWPPara::Read(HWPFile & hwpf, unsigned char flag) for (ii = 0; ii < nch; ii++) { cshapep[ii] = std::make_shared<CharShape>(); - memset(cshapep[ii].get(), 0, sizeof(CharShape)); unsigned char same_cshape(0); hwpf.Read1b(same_cshape); @@ -168,12 +166,12 @@ bool HWPPara::Read(HWPFile & hwpf, unsigned char flag) auto hBox = readHBox(hwpf); if (!hBox) return false; - hhstr[ii] = std::move(hBox); - if (hhstr[ii]->hh == CH_END_PARA) + hhstr.emplace_back(std::move(hBox)); + if (hhstr.back()->hh == CH_END_PARA) break; - if( hhstr[ii]->hh < CH_END_PARA ) + if( hhstr.back()->hh < CH_END_PARA ) pshape->reserved[0] = 0; - ii += hhstr[ii]->WSize(); + ii += hhstr.back()->WSize(); } return nch && !hwpf.State(); } diff --git a/hwpfilter/source/hpara.h b/hwpfilter/source/hpara.h index 58694899ea38..53c35a2ccb7f 100644 --- a/hwpfilter/source/hpara.h +++ b/hwpfilter/source/hpara.h @@ -57,20 +57,7 @@ class HWPPara; struct LineInfo { -/* the position of the starting character: the control has a different length */ -/** - * Starting character position - */ - unsigned short pos; - hunit space_width; - hunit height; hunit pgy; /* internal */ - hunit sx; /* internal */ - hunit psx; /* internal */ - hunit pex; /* internal */ -// for formatting - hunit height_sp; - unsigned short softbreak; // column, page, section void Read(HWPFile &hwpf, HWPPara const *para); }; @@ -114,7 +101,7 @@ class DLLEXPORT HWPPara /** * Box object list */ - std::map<unsigned short, std::unique_ptr<HBox>> hhstr; + std::vector<std::unique_ptr<HBox>> hhstr; HWPPara(void); ~HWPPara(void); diff --git a/hwpfilter/source/hstyle.cxx b/hwpfilter/source/hstyle.cxx index 23ae86c68538..9a0040edcf08 100644 --- a/hwpfilter/source/hstyle.cxx +++ b/hwpfilter/source/hstyle.cxx @@ -68,14 +68,14 @@ void HWPStyle::SetName(int n, char const* name) if (name) { -#if defined __GNUC__ && (__GNUC__ >= 8 && __GNUC__ <= 11) && !defined __clang__ +#if defined __GNUC__ && (__GNUC__ >= 8 && __GNUC__ <= 14) && !defined __clang__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wstringop-truncation" #endif auto const p = style[n].name; strncpy(p, name, MAXSTYLENAME); p[MAXSTYLENAME] = '\0'; // just in case, even though the array is zero-initialized -#if defined __GNUC__ && (__GNUC__ >= 8 && __GNUC__ <= 11) && !defined __clang__ +#if defined __GNUC__ && (__GNUC__ >= 8 && __GNUC__ <= 14) && !defined __clang__ #pragma GCC diagnostic pop #endif } @@ -97,7 +97,7 @@ void HWPStyle::SetCharShape(int n, CharShape const* cshapep) if (cshapep) style[n].cshape = *cshapep; else - memset(&style[n].cshape, 0, sizeof(CharShape)); + style[n].cshape = CharShape(); } } diff --git a/hwpfilter/source/htags.cxx b/hwpfilter/source/htags.cxx index b8cafcf38675..69d0398ca952 100644 --- a/hwpfilter/source/htags.cxx +++ b/hwpfilter/source/htags.cxx @@ -19,6 +19,9 @@ #include "precompile.h" +#include <o3tl/char16_t2wchar_t.hxx> +#include <unotools/tempfile.hxx> + #include <string.h> #include "hwplib.h" @@ -49,9 +52,8 @@ bool HyperText::Read(HWPFile& hwpf) EmPicture::EmPicture(size_t tsize) : size(tsize >= 32 ? tsize - 32 : 0) + , data(size, 0) { - if (size != 0) - data.reset( new uchar[size] ); } EmPicture::~EmPicture() @@ -67,7 +69,7 @@ bool EmPicture::Read(HWPFile & hwpf) name[0] = 'H'; name[1] = 'W'; name[2] = 'P'; - return hwpf.ReadBlock(data.get(), size) != 0; + return hwpf.ReadBlock(data.data(), size) != 0; } @@ -82,13 +84,13 @@ OlePicture::OlePicture(int tsize) return; }; +#ifdef _WIN32 OlePicture::~OlePicture() { -#ifdef _WIN32 if( pis ) pis->Release(); -#endif }; +#endif #define FILESTG_SIGNATURE_NORMAL 0xF8995568 @@ -108,27 +110,20 @@ void OlePicture::Read(HWPFile & hwpf) delete [] data; return; } - FILE *fp; - char tname[200]; - wchar_t wtname[200]; - tmpnam(tname); - if (nullptr == (fp = fopen(tname, "wb"))) - { - delete [] data; - return; - } - fwrite(data, size, 1, fp); + + utl::TempFileNamed aTempFile; + aTempFile.EnableKillingFile(); + + SvFileStream aOutputStream(aTempFile.GetURL(), StreamMode::WRITE); + aOutputStream.WriteBytes(data, size); delete [] data; - fclose(fp); - MultiByteToWideChar(CP_ACP, 0, tname, -1, wtname, 200); - if( StgOpenStorage(wtname, nullptr, + aOutputStream.Close(); + if( StgOpenStorage(o3tl::toW(aTempFile.GetFileName().getStr()), nullptr, STGM_READWRITE|STGM_SHARE_EXCLUSIVE|STGM_TRANSACTED, nullptr, 0, &pis) != S_OK ) { pis = nullptr; - unlink(tname); return; } - unlink(tname); #else hwpf.SkipBlock(size); #endif diff --git a/hwpfilter/source/htags.h b/hwpfilter/source/htags.h index 7265f5d11742..d662a002ecb3 100644 --- a/hwpfilter/source/htags.h +++ b/hwpfilter/source/htags.h @@ -21,6 +21,7 @@ #define INCLUDED_HWPFILTER_SOURCE_HTAGS_H #include <memory> +#include <vector> #ifdef _WIN32 #include <objidl.h> #endif @@ -34,7 +35,7 @@ struct EmPicture size_t size; char name[16]; char type[16]; - std::unique_ptr<uchar[]> data; + std::vector<uchar> data; explicit EmPicture(size_t size); ~EmPicture(void); @@ -64,8 +65,9 @@ struct OlePicture IStorage* pis; #endif explicit OlePicture(int tsize); +#ifdef _WIN32 ~OlePicture(void); - +#endif void Read(HWPFile& hwpf); }; #endif // INCLUDED_HWPFILTER_SOURCE_HTAGS_H diff --git a/hwpfilter/source/hwpeq.cxx b/hwpfilter/source/hwpeq.cxx index a19bee24acbb..36c407ca3e18 100644 --- a/hwpfilter/source/hwpeq.cxx +++ b/hwpfilter/source/hwpeq.cxx @@ -17,6 +17,8 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <sal/config.h> + #include <assert.h> #include <stdio.h> #include <string.h> @@ -25,7 +27,6 @@ #include <istream> #include <sstream> -#include "mzstring.h" #include "hwpeq.h" #include <sal/types.h> #include <sal/macros.h> @@ -33,11 +34,6 @@ #include <rtl/character.hxx> /* @Man: change the hwp formula to LaTeX */ -#ifdef _WIN32 -# define ENDL "\r\n" -#else /* !_WIN32 */ -# define ENDL "\n" -#endif #define EQ_CASE 0x01 // case sensitive cmd #define EQ_ENV 0x02 // equiv to latex environment @@ -55,17 +51,11 @@ static bool IS_BINARY(std::istream::int_type ch) { && strchr("+-<=>", std::istream::traits_type::to_char_type(ch)); } -#ifdef _WIN32 -#define STRICMP stricmp -#else -#define STRICMP strcasecmp -#endif - // sub and sup script status enum { SCRIPT_NONE, SCRIPT_SUB, SCRIPT_SUP, SCRIPT_ALL}; -static int eq_word(MzString& outs, std::istream *strm, int script = SCRIPT_NONE); -static bool eq_sentence(MzString& outs, std::istream *strm, const char *end = nullptr); +static int eq_word(OString& outs, std::istream *strm, int script = SCRIPT_NONE); +static bool eq_sentence(OString& outs, std::istream *strm, const char *end = nullptr); namespace { @@ -413,21 +403,21 @@ static const hwpeq *lookup_eqn(char const *str) } /* If only the first character is uppercase or all characters are uppercase, change to lowercase */ -static void make_keyword( char *keyword, const char *token) +static void make_keyword( char *keyword, std::string_view token) { char* ptr; bool result = true; - int len = strlen(token); + int len = token.length(); assert(keyword); if( 255 < len ) { len = 255; } - memcpy(keyword, token, len); + memcpy(keyword, token.data(), len); keyword[len] = 0; - if( (token[0] & 0x80) || rtl::isAsciiLowerCase(static_cast<unsigned char>(token[0])) || strlen(token) < 2 ) + if( (token[0] & 0x80) || rtl::isAsciiLowerCase(static_cast<unsigned char>(token[0])) || token.length() < 2 ) return; bool capital = rtl::isAsciiUpperCase( @@ -459,14 +449,14 @@ namespace { // token reading function struct eq_stack { - MzString white; - MzString token; + OString white; + OString token; std::istream *strm; eq_stack() { strm = nullptr; }; bool state(std::istream const *s) { - if( strm != s) { white = nullptr; token = nullptr; } - return token.length() != 0; + if( strm != s) { white.clear(); token.clear(); } + return token.getLength() != 0; } }; @@ -474,10 +464,10 @@ struct eq_stack { static eq_stack *stk = nullptr; -static void push_token(MzString const &white, MzString const &token, std::istream *strm) +static void push_token(OString const &white, OString const &token, std::istream *strm) { // one time stack - assert(stk->token.length() == 0); + assert(stk->token.getLength() == 0); stk->white = white; stk->token = token; @@ -489,20 +479,20 @@ static void push_token(MzString const &white, MzString const &token, std::istrea * * control char, control sequence, binary sequence, * alphabet string, single character */ -static int next_token(MzString &white, MzString &token, std::istream *strm) +static int next_token(OString &white, OString &token, std::istream *strm) { std::istream::int_type ch = 0; if( stk->state(strm) ) { white = stk->white; token = stk->token; - stk->token = nullptr; - stk->white = nullptr; - return token.length(); + stk->token.clear(); + stk->white.clear(); + return token.getLength(); } - token = nullptr; - white = nullptr; + token.clear(); + white.clear(); if( !strm->good() ) return 0; ch = strm->get(); @@ -513,7 +503,7 @@ static int next_token(MzString &white, MzString &token, std::istream *strm) if( IS_WS(ch) ) { do { - white << static_cast<char>(ch); + white += OStringChar(static_cast<char>(ch)); ch = strm->get(); } while (IS_WS(ch)); } @@ -522,11 +512,11 @@ static int next_token(MzString &white, MzString &token, std::istream *strm) || (ch != std::istream::traits_type::eof() && rtl::isAsciiAlpha(ch)) ) { if( ch == '\\' ) { - token << static_cast<char>(ch); + token += OStringChar(static_cast<char>(ch)); ch = strm->get(); } do { - token << static_cast<char>(ch); + token += OStringChar(static_cast<char>(ch)); ch = strm->get(); } while( ch != std::istream::traits_type::eof() && (ch & 0x80 || rtl::isAsciiAlpha(ch)) ) ; @@ -534,24 +524,24 @@ static int next_token(MzString &white, MzString &token, std::istream *strm) /* special treatment of sub, sub, over, atop The reason for this is that affect next_state(). */ - if( !STRICMP("sub", token) || !STRICMP("from", token) || - !STRICMP("sup", token) || !STRICMP("to", token) || - !STRICMP("over", token) || !STRICMP("atop", token) || - !STRICMP("left", token) || !STRICMP("right", token) ) + if( token.equalsIgnoreAsciiCase("sub") || token.equalsIgnoreAsciiCase("from") || + token.equalsIgnoreAsciiCase("sup") || token.equalsIgnoreAsciiCase("to") || + token.equalsIgnoreAsciiCase("over") || token.equalsIgnoreAsciiCase("atop") || + token.equalsIgnoreAsciiCase("left") || token.equalsIgnoreAsciiCase("right") ) { char buf[256]; make_keyword(buf, token); token = buf; } - if( !token.compare("sub") || !token.compare("from") ) - token = "_"; - if( !token.compare("sup") || !token.compare("to") ) - token = "^"; + if( token == "sub" || token == "from" ) + token = "_"_ostr; + if( token == "sup" || token == "to" ) + token = "^"_ostr; } else if( IS_BINARY(ch) ) { do { - token << static_cast<char>(ch); + token += OStringChar(static_cast<char>(ch)); ch = strm->get(); } while( IS_BINARY(ch) ); @@ -559,24 +549,24 @@ static int next_token(MzString &white, MzString &token, std::istream *strm) } else if( ch != std::istream::traits_type::eof() && rtl::isAsciiDigit(ch) ) { do { - token << static_cast<char>(ch); + token += OStringChar(static_cast<char>(ch)); ch = strm->get(); } while( ch != std::istream::traits_type::eof() && rtl::isAsciiDigit(ch) ); strm->putback(static_cast<char>(ch)); } else - token << static_cast<char>(ch); + token += OStringChar(static_cast<char>(ch)); - return token.length(); + return token.getLength(); } -static std::istream::int_type read_white_space(MzString& outs, std::istream *strm) +static std::istream::int_type read_white_space(OString& outs, std::istream *strm) { std::istream::int_type result; if( stk->state(strm) ) { - outs << stk->white; - stk->white = nullptr; + outs += stk->white; + stk->white.clear(); result = std::istream::traits_type::to_int_type(stk->token[0]); } else { @@ -586,7 +576,7 @@ static std::istream::int_type read_white_space(MzString& outs, std::istream *str ch = strm->get(); if (!IS_WS(ch)) break; - outs << static_cast<char>(ch); + outs += OStringChar(static_cast<char>(ch)); } strm->putback(static_cast<char>(ch)); result = ch; @@ -608,37 +598,37 @@ static std::istream::int_type read_white_space(MzString& outs, std::istream *str a over b -> {a} over {b} */ -static int eq_word(MzString& outs, std::istream *strm, int status) +static int eq_word(OString& outs, std::istream *strm, int status) { - MzString token, white, state; + OString token, white, state; int result; char keyword[256]; const hwpeq *eq; next_token(white, token, strm); - if (token.length() <= 0) + if (token.getLength() <= 0) return 0; result = token[0]; - if( token.compare("{") == 0 ) { - state << white << token; + if( token == "{" ) { + state += white + token; eq_sentence(state, strm, "}"); } - else if( token.compare("left") == 0 ) { - state << white << token; + else if( token == "left" ) { + state += white + token; next_token(white, token, strm); - state << white << token; + state += white + token; eq_sentence(state, strm, "right"); next_token(white, token, strm); - state << white << token; + state += white + token; } else { /* Normal token */ int script_status = SCRIPT_NONE; while( true ) { - state << white << token; + state += white + token; make_keyword(keyword, token); if( token[0] == '^' ) script_status |= SCRIPT_SUP; @@ -651,9 +641,9 @@ static int eq_word(MzString& outs, std::istream *strm, int status) int nargs = eq->nargs; while( nargs-- ) { const std::istream::int_type ch = read_white_space(state, strm); - if( ch != '{' ) state << '{'; + if( ch != '{' ) state += OStringChar('{'); eq_word(state, strm, script_status); - if( ch != '{' ) state << '}'; + if( ch != '{' ) state += OStringChar('}'); } } @@ -662,52 +652,52 @@ static int eq_word(MzString& outs, std::istream *strm, int status) // end loop and restart with this if( (token[0] == '^' && status && !(status & SCRIPT_SUP)) || (token[0] == '_' && status && !(status & SCRIPT_SUB)) || - strcmp("over", token) == 0 || strcmp("atop", token) == 0 || + "over" == token || "atop" == token || strchr("{}#&`", token[0]) || - (!strchr("^_", token[0]) && white.length()) ) + (!strchr("^_", token[0]) && white.getLength()) ) { push_token(white, token, strm); break; } } } - outs << state; + outs += state; return result; } -static bool eq_sentence(MzString& outs, std::istream *strm, const char *end) +static bool eq_sentence(OString& outs, std::istream *strm, const char *end) { - MzString state; - MzString white, token; + OString state; + OString white, token; bool multiline = false; read_white_space(outs, strm); while( eq_word(state, strm) ) { if( !next_token(white, token, strm) || - (end && strcmp(token.c_str(), end) == 0) ) + (end && token == end) ) { - state << white << token; + state += white + token; break; } push_token(white, token, strm); - if( !token.compare("atop") || !token.compare("over") ) - outs << '{' << state << '}'; + if( token == "atop" || token == "over" ) + outs += OStringChar('{') + state + OStringChar('}'); else { - if( !token.compare("#") ) + if( token == "#" ) multiline = true; - outs << state; + outs += state; } - state = nullptr; + state.clear(); read_white_space(outs, strm); } - outs << state; + outs += state; return multiline; } -static char eq2ltxconv(MzString& sstr, std::istream *strm, const char *sentinel) +static char eq2ltxconv(OString& sstr, std::istream *strm, const char *sentinel) { - MzString white, token; + OString white, token; char key[256]; std::istream::int_type ch; int result; @@ -718,81 +708,81 @@ static char eq2ltxconv(MzString& sstr, std::istream *strm, const char *sentinel) make_keyword(key, token); const hwpeq *eq = nullptr; if( (eq = lookup_eqn(key)) != nullptr ) { + const bool bUpperFollowingChar = ( (eq->flag & EQ_CASE) + && rtl::isAsciiUpperCase(static_cast<unsigned char>(token[0])) ); + if( eq->latex ) - strcpy(key, eq->latex); + token = eq->latex; else { - key[0] = '\\'; - strcpy(key + 1, eq->key); + token = OString::Concat("\\") + eq->key; } - if( (eq->flag & EQ_CASE) - && rtl::isAsciiUpperCase(static_cast<unsigned char>(token[0])) ) - key[1] = sal::static_int_cast<char>( - rtl::toAsciiUpperCase(static_cast<unsigned char>(key[1]))); - token = key; + + if (bUpperFollowingChar) + token = token.replaceAt(1, 1, token.copy(1, 1).toAsciiUpperCase()); } if( token[0] == '{' ) { // grouping - sstr << white << token; + sstr += white + token; eq2ltxconv(sstr, strm, "}"); - sstr << '}'; + sstr += OStringChar('}'); } else if( eq && (eq->flag & EQ_ENV) ) { next_token(white, token, strm); if( token[0] != '{' ) return 0; - sstr << "\\begin" << "{" << eq->key << "}" << ENDL ; + sstr += OString::Concat("\\begin{") + eq->key + "}" SAL_NEWLINE_STRING ; eq2ltxconv(sstr, strm, "}"); - if( sstr[sstr.length() - 1] != '\n' ) - sstr << ENDL ; - sstr << "\\end" << "{" << eq->key << "}" << ENDL ; + if( sstr[sstr.getLength() - 1] != '\n' ) + sstr += SAL_NEWLINE_STRING ; + sstr += OString::Concat("\\end{") + eq->key + "}" SAL_NEWLINE_STRING ; } else if( eq && (eq->flag & EQ_ATOP) ) { - if( sstr.length() == 0 ) - sstr << '{'; + if( sstr.getLength() == 0 ) + sstr += OStringChar('{'); else { - int pos = sstr.rfind('}'); + int pos = sstr.lastIndexOf('}'); if( 0 < pos) - sstr.replace(pos, ' '); + sstr = sstr.replaceAt(pos, 1, " "); } - sstr << token; + sstr += token; for (;;) { ch = strm->get(); if ( ch == std::istream::traits_type::eof() || !IS_WS(ch) ) break; - sstr << static_cast<char>(ch); + sstr += OStringChar(static_cast<char>(ch)); } if( ch != '{' ) - sstr << "{}"; + sstr += "{}"; else { eq2ltxconv(sstr, strm, "}"); - sstr << '}'; + sstr += OStringChar('}'); } } else - sstr << white << token; + sstr += white + token; } return token[0]; } -void eq2latex(MzString& outs, char const *s) +void eq2latex(OString& outs, char const *s) { assert(s); if( stk == nullptr ) stk = new eq_stack; - MzString tstr; + OString tstr; std::istringstream tstrm(s); bool eqnarray = eq_sentence(tstr, &tstrm); - std::istringstream strm(tstr.c_str()); + std::istringstream strm((std::string(tstr))); if( eqnarray ) - outs << "\\begin{array}{rllll}" << ENDL; + outs += "\\begin{array}{rllll}" SAL_NEWLINE_STRING; eq2ltxconv(outs, &strm, nullptr); - outs << ENDL; + outs += SAL_NEWLINE_STRING; if( eqnarray ) - outs << "\\end{array}" << ENDL; + outs += "\\end{array}" SAL_NEWLINE_STRING; delete stk; stk = nullptr; } diff --git a/hwpfilter/source/hwpeq.h b/hwpfilter/source/hwpeq.h index cc96743c27a0..e7f0853053f9 100644 --- a/hwpfilter/source/hwpeq.h +++ b/hwpfilter/source/hwpeq.h @@ -20,9 +20,11 @@ #ifndef INCLUDED_HWPFILTER_SOURCE_HWPEQ_H #define INCLUDED_HWPFILTER_SOURCE_HWPEQ_H -#include "mzstring.h" +#include <sal/config.h> -void eq2latex(MzString& mstr, char const* str); +#include <rtl/string.hxx> + +void eq2latex(OString& outs, char const* s); #endif // INCLUDED_HWPFILTER_SOURCE_HWPEQ_H diff --git a/hwpfilter/source/hwpfile.cxx b/hwpfilter/source/hwpfile.cxx index 5f32a38c0633..c186ad8609a4 100644 --- a/hwpfilter/source/hwpfile.cxx +++ b/hwpfilter/source/hwpfile.cxx @@ -139,6 +139,16 @@ bool HWPFile::Read2b(unsigned short &out) return hiodev && hiodev->read2b(out); } +bool HWPFile::Read2b(char16_t &out) +{ + unsigned short n; + auto const ok = Read2b(n); + if (ok) { + out = n; + } + return ok; +} + bool HWPFile::Read4b(unsigned int &out) { return hiodev && hiodev->read4b(out); @@ -238,6 +248,7 @@ void HWPFile::ReadParaList(std::vector < HWPPara* > &aplist) aplist.push_back(spNode.release()); spNode.reset( new HWPPara ); } + move_to_failed(std::move(spNode)); } void HWPFile::ReadParaList(std::vector< std::unique_ptr<HWPPara> > &aplist, unsigned char flag) @@ -271,6 +282,12 @@ void HWPFile::ReadParaList(std::vector< std::unique_ptr<HWPPara> > &aplist, unsi aplist.push_back(std::move(spNode)); spNode.reset( new HWPPara ); } + move_to_failed(std::move(spNode)); +} + +void HWPFile::move_to_failed(std::unique_ptr<HWPPara> xPara) +{ + pfailedlist.push_back(std::move(xPara)); } void HWPFile::TagsRead() @@ -450,11 +467,6 @@ EmPicture *HWPFile::GetEmPictureByName(char * name) return nullptr; } -void HWPFile::AddBox(FBox * box) -{ - blist.push_back(box); -} - ParaShape *HWPFile::getParaShape(int index) { if (index < 0 || o3tl::make_unsigned(index) >= pslist.size()) @@ -554,13 +566,13 @@ void HWPFile::AddCharShape(std::shared_ptr<CharShape> const & cshape) void HWPFile::AddColumnInfo() { - columnlist.emplace_back(new ColumnInfo(m_nCurrentPage)); + columnlist.emplace_back(new HWPColumnInfo(m_nCurrentPage)); setMaxSettedPage(); } void HWPFile::SetColumnDef(const std::shared_ptr<ColumnDef>& rColdef) { - ColumnInfo *cinfo = columnlist.back().get(); + HWPColumnInfo *cinfo = columnlist.back().get(); if( cinfo->bIsSet ) return; cinfo->xColdef = rColdef; @@ -601,9 +613,9 @@ int HWPFile::compareCharShape(CharShape const *shape) CharShape *cshape = getCharShape(i); if( shape->size == cshape->size && - shape->font[0] == cshape->font[0] && - shape->ratio[0] == cshape->ratio[0] && - shape->space[0] == cshape->space[0] && + shape->font == cshape->font && + shape->ratio == cshape->ratio && + shape->space == cshape->space && shape->color[1] == cshape->color[1] && shape->color[0] == cshape->color[0] && shape->shade == cshape->shade && @@ -637,9 +649,9 @@ int HWPFile::compareParaShape(const ParaShape* shape) shape->pagebreak == pshape->pagebreak) { if (shape->cshape->size == pshape->cshape->size && - shape->cshape->font[0] == pshape->cshape->font[0] && - shape->cshape->ratio[0] == pshape->cshape->ratio[0] && - shape->cshape->space[0] == pshape->cshape->space[0] && + shape->cshape->font == pshape->cshape->font && + shape->cshape->ratio == pshape->cshape->ratio && + shape->cshape->space == pshape->cshape->space && shape->cshape->color[1] == pshape->cshape->color[1] && shape->cshape->color[0] == pshape->cshape->color[0] && shape->cshape->shade == pshape->cshape->shade && diff --git a/hwpfilter/source/hwpfile.h b/hwpfilter/source/hwpfile.h index 867a05fb7418..126b7edf0fd8 100644 --- a/hwpfilter/source/hwpfile.h +++ b/hwpfilter/source/hwpfile.h @@ -68,11 +68,11 @@ class HWPStyle; class HWPPara; class HStream; -struct ColumnInfo{ +struct HWPColumnInfo{ int start_page; bool bIsSet; std::shared_ptr<ColumnDef> xColdef; - explicit ColumnInfo(int num){ + explicit HWPColumnInfo(int num){ start_page = num; bIsSet = false; } @@ -130,6 +130,7 @@ class DLLEXPORT HWPFile * Reads two byte from HIODev */ bool Read2b(unsigned short &out); + bool Read2b(char16_t &out); /** * Reads four byte from HIODev */ @@ -202,7 +203,6 @@ class DLLEXPORT HWPFile A3Paper = 8 }; - void AddBox(FBox *); void AddPage(){ m_nCurrentPage++;} void AddColumnInfo(); void SetColumnDef(std::shared_ptr<ColumnDef> const &); @@ -253,6 +253,8 @@ class DLLEXPORT HWPFile } void pop_hpara_type() { element_import_stack.pop_back(); } + void move_to_failed(std::unique_ptr<HWPPara> rPara); + private: int compareCharShape(CharShape const *shape); int compareParaShape(ParaShape const *shape); @@ -277,11 +279,13 @@ class DLLEXPORT HWPFile HWPInfo _hwpInfo; HWPFont _hwpFont; HWPStyle _hwpStyle; - std::vector<std::unique_ptr<ColumnInfo>> columnlist; + std::vector<std::unique_ptr<HWPColumnInfo>> columnlist; // paragraph list std::vector<std::unique_ptr<HWPPara>> plist; - // floating box list - std::vector<FBox*> blist; + // keep paragraph's that failed to load until + // import is complete to avoid dangling references + // elsewhere + std::vector<std::unique_ptr<HWPPara>> pfailedlist; // embedded picture list(tag data) std::vector<std::unique_ptr<EmPicture>> emblist; std::vector<std::unique_ptr<HyperText>> hyperlist; diff --git a/hwpfilter/source/hwplib.h b/hwpfilter/source/hwplib.h index ec438d36134e..354cbce4b55c 100644 --- a/hwpfilter/source/hwplib.h +++ b/hwpfilter/source/hwplib.h @@ -33,7 +33,7 @@ /** * size of hunit is 4 since hwp96 version */ -typedef unsigned short hchar; +typedef char16_t hchar; typedef int hunit; typedef unsigned char kchar; @@ -92,10 +92,6 @@ typedef struct int mulY, divY; } ZZScaleXY; -#if !defined(_WIN32) && !defined(MAX_PATH) -# define MAX_PATH 260 -#endif /* MAX_PATH */ - #ifndef TRUE # define TRUE 1 # define FALSE 0 diff --git a/hwpfilter/source/hwpread.cxx b/hwpfilter/source/hwpread.cxx index 8e4a96c726d0..98a8e56aa5e5 100644 --- a/hwpfilter/source/hwpread.cxx +++ b/hwpfilter/source/hwpread.cxx @@ -20,7 +20,8 @@ #include "precompile.h" #include <comphelper/newarray.hxx> -#include <unotools/configmgr.hxx> +#include <comphelper/configuration.hxx> +#include <sal/log.hxx> #include <tools/long.hxx> #include <assert.h> @@ -91,10 +92,12 @@ bool FieldCode::Read(HWPFile & hwpf) str2.reset( new hchar[len2_ ? len2_ : 1] ); str3.reset( new hchar[len3_ ? len3_ : 1] ); - hwpf.Read2b(str1.get(), len1_); + if (hwpf.Read2b(str1.get(), len1_) != len1_) + return false; hwpf.SkipBlock(len1 - (len1_ * sizeof(hchar))); str1[len1_ ? (len1_ - 1) : 0] = 0; - hwpf.Read2b(str2.get(), len2_); + if (hwpf.Read2b(str2.get(), len2_) != len2_) + return false; hwpf.SkipBlock(len2 - (len2_ * sizeof(hchar))); str2[len2_ ? (len2_ - 1) : 0] = 0; if (hwpf.Read2b(str3.get(), len3_) != len3_) @@ -106,7 +109,7 @@ bool FieldCode::Read(HWPFile & hwpf) if( type[0] == 3 && type[1] == 2 ){ /* It must create a format as created date. */ DateCode *pDate = new DateCode; - for (int i = 0 ; i < static_cast<int>(len3_); i++) { + for (uint i = 0 ; i < len3_; i++) { if(str3[i] == 0 ) break; if( i >= DATE_SIZE ) break; pDate->format[i] = str3[i]; @@ -221,7 +224,6 @@ bool TxtBox::Read(HWPFile & hwpf) if (hh != dummy || CH_TEXT_BOX != dummy) { return hwpf.SetState(HWP_InvalidFileFormat); } - hwpf.AddBox(this); hwpf.Read2b(&style.cap_len, 1); hwpf.Read2b(&dummy1, 1); unsigned short next; @@ -237,7 +239,6 @@ bool TxtBox::Read(HWPFile & hwpf) hwpf.Read2b(&option, 1); hwpf.Read2b(&ctrl_ch, 1); hwpf.Read2b(style.margin, 12); - hwpf.AddFBoxStyle(&style); hwpf.Read2b(&box_xs, 1); hwpf.Read2b(&box_ys, 1); hwpf.Read2b(&cap_xs, 1); @@ -290,7 +291,7 @@ bool TxtBox::Read(HWPFile & hwpf) return hwpf.SetState(HWP_InvalidFileFormat); } - if (ncell > 4096 && utl::ConfigManager::IsFuzzing()) { + if (ncell > 4096 && comphelper::IsFuzzing()) { // cut off at an arbitrary size to speed up fuzzing return hwpf.SetState(HWP_InvalidFileFormat); } @@ -366,7 +367,10 @@ bool TxtBox::Read(HWPFile & hwpf) else m_pTable = nullptr; - return !hwpf.State(); + bSuccess = !hwpf.State(); + if (bSuccess) + hwpf.AddFBoxStyle(&style); + return bSuccess; } namespace @@ -400,7 +404,6 @@ bool Picture::Read(HWPFile & hwpf) if (hh != dummy || CH_PICTURE != dummy) { return hwpf.SetState(HWP_InvalidFileFormat); } - hwpf.AddBox(this); hwpf.Read4b(follow_block_size); @@ -455,6 +458,7 @@ bool Picture::Read(HWPFile & hwpf) scale[1] = tmp16; hwpf.ReadBlock(picinfo.picun.path, 256); /* Picture File Name: when type is not a Drawing. */ + picinfo.picun.path[255] = 0; // ensure null terminated hwpf.ReadBlock(reserved3, 9); /* Brightness / Contrast / Picture Effect, etc. */ UpdateBBox(this); @@ -487,14 +491,18 @@ bool Picture::Read(HWPFile & hwpf) if (nBlock != nReadBlock) break; if (nMaxAllowedDecompression && follow.size() > nMaxAllowedDecompression) - break; + { + SAL_WARN("filter.hwp", "too much decompression, abandoning"); + follow.clear(); + return false; + } } follow_block_size = follow.size(); if (pictype == PICTYPE_DRAW) { auto xGuard(std::make_unique<ChangeMemGuard>(follow.data(), follow_block_size)); - LoadDrawingObjectBlock(this); + LoadDrawingObjectBlock(this, hwpf); style.cell = picinfo.picdraw.hdo; xGuard.reset(); } @@ -511,12 +519,14 @@ bool Picture::Read(HWPFile & hwpf) style.boxtype = 'G'; else style.boxtype = 'D'; - hwpf.AddFBoxStyle(&style); // caption hwpf.ReadParaList(caption); - return !hwpf.State(); + bool bSuccess = !hwpf.State(); + if (bSuccess) + hwpf.AddFBoxStyle(&style); + return bSuccess; } // line(15) @@ -541,7 +551,6 @@ bool Line::Read(HWPFile & hwpf) if (hh != dummy || CH_LINE != dummy) { return hwpf.SetState(HWP_InvalidFileFormat); } - hwpf.AddBox(this); style.boxnum = fboxnum++; zorder = zindex++; @@ -554,7 +563,6 @@ bool Line::Read(HWPFile & hwpf) hwpf.Read2b(&option, 1); hwpf.Read2b(&ctrl_ch, 1); hwpf.Read2b(style.margin, 12); - hwpf.AddFBoxStyle(&style); hwpf.Read2b(&box_xs, 1); hwpf.Read2b(&box_ys, 1); hwpf.Read2b(&cap_xs, 1); @@ -583,7 +591,10 @@ bool Line::Read(HWPFile & hwpf) hwpf.Read2b(&color, 1); style.xpos = width; - return !hwpf.State(); + bool bSuccess = !hwpf.State(); + if (bSuccess) + hwpf.AddFBoxStyle(&style); + return bSuccess; } // hidden(15) diff --git a/hwpfilter/source/hwpreader.cxx b/hwpfilter/source/hwpreader.cxx index e26cbb26143a..2400192bb959 100644 --- a/hwpfilter/source/hwpreader.cxx +++ b/hwpfilter/source/hwpreader.cxx @@ -25,9 +25,12 @@ #include <cmath> #include <o3tl/safeint.hxx> +#include <o3tl/sprintf.hxx> #include <osl/diagnose.h> #include <tools/stream.hxx> #include <basegfx/numeric/ftools.hxx> +#include <basegfx/point/b2dpoint.hxx> +#include <comphelper/configuration.hxx> #include "fontmap.hxx" #include "formula.h" @@ -37,55 +40,23 @@ #include <iostream> #include <locale.h> #include <sal/types.h> +#include <rtl/character.hxx> #include <rtl/ustrbuf.hxx> - -// To be shorten source code by realking -#define hconv(x) hstr2ucsstr(x).c_str() -#define ascii(x) OUString::createFromAscii(x) -#define rstartEl(x,y) do { if (m_rxDocumentHandler.is()) m_rxDocumentHandler->startElement(x,y); } while(false) -#define rendEl(x) do { if (m_rxDocumentHandler.is()) m_rxDocumentHandler->endElement(x); } while(false) -#define rchars(x) do { if (m_rxDocumentHandler.is()) m_rxDocumentHandler->characters(x); } while(false) -#define padd(x,y,z) mxList->addAttribute(x,y,z) -#define Double2Str(x) OUString::number(x) -#define WTI(x) (static_cast<double>(x) / 1800.) // unit => inch -#define WTMM(x) (static_cast<double>(x) / 1800. * 25.4) // unit => mm -#define WTSM(x) (static_cast<int>((x) / 1800. * 2540)) // unit ==> 1/100 mm +#include <sal/log.hxx> // xmloff/xmlkyd.hxx -constexpr OUStringLiteral sXML_CDATA = u"CDATA"; - -#define STARTP padd( "text:style-name", "CDATA", ascii(getPStyleName((para->GetParaShape()).index,buf))); \ - rstartEl( "text:p",mxList ); \ - mxList->clear(); \ - pstart = true -#define STARTT \ - curr = para->GetCharShape(n > 0 ? n-1 : 0)->index; \ - padd( "text:style-name", "CDATA" , ascii( getTStyleName(curr, buf) ) ); \ - rstartEl( "text:span",mxList ); \ - mxList->clear(); \ - tstart = true -#define ENDP \ - rendEl("text:p"); \ - pstart = false -#define ENDT \ - rendEl("text:span"); \ - tstart = false - -static hchar *field = nullptr; -static char buf[1024]; +constexpr OUString sXML_CDATA = u"CDATA"_ustr; namespace { - -template<typename T> -struct Free -{ - void operator()(T* const ptr) - { - free(ptr); - } -}; - +double WTI(double x) { return x / 1800.; } // unit => inch +double WTMM(double x) { return x / 1800. * 25.4; } // unit => mm +int WTSM(double x) { return x / 1800. * 2540; } // unit ==> 1/100 mm + +constexpr OUString sBeginOfDoc(u"[\uBB38\uC11C\uC758 \uCC98\uC74C]"_ustr); + // U+BB38 HANGUL SYLLABLE MUN, U+C11C HANGUL SYLLABLE SEO, + // U+C758 HANGUL SYLLABLE YI, U+CC98 HANGUL SYLLABLE CEO, + // U+C74C HANGUL SYLLABLE EUM: "Begin of Document" } struct HwpReaderPrivate @@ -97,13 +68,15 @@ struct HwpReaderPrivate bInHeader = false; nPnPos = 0; pPn = nullptr; - + pField = nullptr; } bool bFirstPara; bool bInBody; bool bInHeader; ShowPageNum *pPn; + hchar *pField; int nPnPos; + char buf[1024]; }; HwpReader::HwpReader() : mxList(new AttributeListImpl), d(new HwpReaderPrivate) @@ -130,14 +103,56 @@ extern "C" SAL_DLLPUBLIC_EXPORT bool TestImportHWP(SvStream &rStream) stream->addData(aData, static_cast<int>(nRead)); } - HWPFile hwpfile; - if (hwpfile.ReadHwpFile(std::move(stream))) - return false; + rtl::Reference<HwpReader> hwpreader(new HwpReader); + return hwpreader->importHStream(std::move(stream)); } catch (...) { - return false; } + return false; +} + +bool HwpReader::importHStream(std::unique_ptr<HStream> stream) +{ + if (hwpfile.ReadHwpFile(std::move(stream))) + return false; + + if (m_rxDocumentHandler.is()) + m_rxDocumentHandler->startDocument(); + + mxList->addAttribute("office:class", sXML_CDATA, "text"); + mxList->addAttribute("office:version", sXML_CDATA, "0.9"); + + mxList->addAttribute("xmlns:office", "CDATA", "http://openoffice.org/2000/office"); + mxList->addAttribute("xmlns:style", "CDATA", "http://openoffice.org/2000/style"); + mxList->addAttribute("xmlns:text", "CDATA", "http://openoffice.org/2000/text"); + mxList->addAttribute("xmlns:table", "CDATA", "http://openoffice.org/2000/table"); + mxList->addAttribute("xmlns:draw", "CDATA", "http://openoffice.org/2000/drawing"); + mxList->addAttribute("xmlns:fo", "CDATA", "http://www.w3.org/1999/XSL/Format"); + mxList->addAttribute("xmlns:xlink", "CDATA", "http://www.w3.org/1999/xlink"); + mxList->addAttribute("xmlns:dc", "CDATA", "http://purl.org/dc/elements/1.1/"); + mxList->addAttribute("xmlns:meta", "CDATA", "http://openoffice.org/2000/meta"); + mxList->addAttribute("xmlns:number", "CDATA", "http://openoffice.org/2000/datastyle"); + mxList->addAttribute("xmlns:svg", "CDATA", "http://www.w3.org/2000/svg"); + mxList->addAttribute("xmlns:chart", "CDATA", "http://openoffice.org/2000/chart"); + mxList->addAttribute("xmlns:dr3d", "CDATA", "http://openoffice.org/2000/dr3d"); + mxList->addAttribute("xmlns:math", "CDATA", "http://www.w3.org/1998/Math/MathML"); + mxList->addAttribute("xmlns:form", "CDATA", "http://openoffice.org/2000/form"); + mxList->addAttribute("xmlns:script", "CDATA", "http://openoffice.org/2000/script"); + + startEl("office:document"); + mxList->clear(); + + makeMeta(); + makeStyles(); + makeAutoStyles(); + makeMasterStyles(); + makeBody(); + + endEl("office:document"); + + if (m_rxDocumentHandler.is()) + m_rxDocumentHandler->endDocument(); return true; } @@ -163,60 +178,20 @@ sal_Bool HwpReader::filter(const Sequence< PropertyValue >& rDescriptor) if( nTotal == 0 ) return false; - if (hwpfile.ReadHwpFile(std::move(stream))) - return false; - - if (m_rxDocumentHandler.is()) - m_rxDocumentHandler->startDocument(); - - padd("office:class", sXML_CDATA, "text"); - padd("office:version", sXML_CDATA, "0.9"); - - padd("xmlns:office", "CDATA", "http://openoffice.org/2000/office"); - padd("xmlns:style", "CDATA", "http://openoffice.org/2000/style"); - padd("xmlns:text", "CDATA", "http://openoffice.org/2000/text"); - padd("xmlns:table", "CDATA", "http://openoffice.org/2000/table"); - padd("xmlns:draw", "CDATA", "http://openoffice.org/2000/drawing"); - padd("xmlns:fo", "CDATA", "http://www.w3.org/1999/XSL/Format"); - padd("xmlns:xlink", "CDATA", "http://www.w3.org/1999/xlink"); - padd("xmlns:dc", "CDATA", "http://purl.org/dc/elements/1.1/"); - padd("xmlns:meta", "CDATA", "http://openoffice.org/2000/meta"); - padd("xmlns:number", "CDATA", "http://openoffice.org/2000/datastyle"); - padd("xmlns:svg", "CDATA", "http://www.w3.org/2000/svg"); - padd("xmlns:chart", "CDATA", "http://openoffice.org/2000/chart"); - padd("xmlns:dr3d", "CDATA", "http://openoffice.org/2000/dr3d"); - padd("xmlns:math", "CDATA", "http://www.w3.org/1998/Math/MathML"); - padd("xmlns:form", "CDATA", "http://openoffice.org/2000/form"); - padd("xmlns:script", "CDATA", "http://openoffice.org/2000/script"); - - rstartEl("office:document", mxList); - mxList->clear(); - - makeMeta(); - makeStyles(); - makeAutoStyles(); - makeMasterStyles(); - makeBody(); - - rendEl("office:document"); - - if (m_rxDocumentHandler.is()) - m_rxDocumentHandler->endDocument(); - return true; + return importHStream(std::move(stream)); } - /** * make office:body */ void HwpReader::makeBody() { - rstartEl("office:body", mxList); + startEl("office:body"); makeTextDecls(); HWPPara *hwppara = hwpfile.GetFirstPara(); d->bInBody = true; parsePara(hwppara); - rendEl("office:body"); + endEl("office:body"); d->bInBody = false; } @@ -226,32 +201,31 @@ void HwpReader::makeBody() */ void HwpReader::makeTextDecls() { - rstartEl("text:sequence-decls", mxList); - padd("text:display-outline-level", sXML_CDATA, "0"); - padd("text:name", sXML_CDATA, "Illustration"); - rstartEl("text:sequence-decl", mxList); + startEl("text:sequence-decls"); + mxList->addAttribute("text:display-outline-level", sXML_CDATA, "0"); + mxList->addAttribute("text:name", sXML_CDATA, "Illustration"); + startEl("text:sequence-decl"); mxList->clear(); - rendEl("text:sequence-decl"); - padd("text:display-outline-level", sXML_CDATA, "0"); - padd("text:name", sXML_CDATA, "Table"); - rstartEl("text:sequence-decl", mxList); + endEl("text:sequence-decl"); + mxList->addAttribute("text:display-outline-level", sXML_CDATA, "0"); + mxList->addAttribute("text:name", sXML_CDATA, "Table"); + startEl("text:sequence-decl"); mxList->clear(); - rendEl("text:sequence-decl"); - padd("text:display-outline-level", sXML_CDATA, "0"); - padd("text:name", sXML_CDATA, "Text"); - rstartEl("text:sequence-decl", mxList); + endEl("text:sequence-decl"); + mxList->addAttribute("text:display-outline-level", sXML_CDATA, "0"); + mxList->addAttribute("text:name", sXML_CDATA, "Text"); + startEl("text:sequence-decl"); mxList->clear(); - rendEl("text:sequence-decl"); - padd("text:display-outline-level", sXML_CDATA, "0"); - padd("text:name", sXML_CDATA, "Drawing"); - rstartEl("text:sequence-decl", mxList); + endEl("text:sequence-decl"); + mxList->addAttribute("text:display-outline-level", sXML_CDATA, "0"); + mxList->addAttribute("text:name", sXML_CDATA, "Drawing"); + startEl("text:sequence-decl"); mxList->clear(); - rendEl("text:sequence-decl"); - rendEl("text:sequence-decls"); + endEl("text:sequence-decl"); + endEl("text:sequence-decls"); } -#define ISNUMBER(x) ( (x) <= 0x39 && (x) >= 0x30 ) /** * make office:meta * Completed @@ -260,27 +234,27 @@ void HwpReader::makeMeta() { HWPInfo& hwpinfo = hwpfile.GetHWPInfo(); - rstartEl("office:meta", mxList); + startEl("office:meta"); if (hwpinfo.summary.title[0]) { - rstartEl("dc:title", mxList); - rchars(fromHcharStringToOUString(hstr2ucsstr(hwpinfo.summary.title))); - rendEl("dc:title"); + startEl("dc:title"); + chars(hstr2OUString(reinterpret_cast<hchar *>(hwpinfo.summary.title))); + endEl("dc:title"); } if (hwpinfo.summary.subject[0]) { - rstartEl("dc:subject", mxList); - rchars(fromHcharStringToOUString(hstr2ucsstr(hwpinfo.summary.subject))); - rendEl("dc:subject"); + startEl("dc:subject"); + chars(hstr2OUString(reinterpret_cast<hchar *>(hwpinfo.summary.subject))); + endEl("dc:subject"); } if (hwpinfo.summary.author[0]) { - rstartEl("meta:initial-creator", mxList); - rchars(fromHcharStringToOUString(hstr2ucsstr(hwpinfo.summary.author))); - rendEl("meta:initial-creator"); + startEl("meta:initial-creator"); + chars(hstr2OUString(reinterpret_cast<hchar *>(hwpinfo.summary.author))); + endEl("meta:initial-creator"); } if (hwpinfo.summary.date[0]) @@ -288,8 +262,8 @@ void HwpReader::makeMeta() unsigned short *pDate = hwpinfo.summary.date; int year,month,day,hour,minute; int gab = 0; - if( ISNUMBER( pDate[0] ) && ISNUMBER( pDate[1] ) && - ISNUMBER( pDate[2] ) && ISNUMBER( pDate[3] )) + if( rtl::isAsciiDigit( pDate[0] ) && rtl::isAsciiDigit( pDate[1] ) && + rtl::isAsciiDigit( pDate[2] ) && rtl::isAsciiDigit( pDate[3] )) { year = (pDate[0]-0x30) * 1000 + (pDate[1]-0x30) * 100 + (pDate[2]-0x30) * 10 + (pDate[3]-0x30); @@ -297,9 +271,9 @@ void HwpReader::makeMeta() else { year = 0; } - if( ISNUMBER( pDate[6] )) + if( rtl::isAsciiDigit( pDate[6] )) { - if( ISNUMBER( pDate[7] ) ) + if( rtl::isAsciiDigit( pDate[7] ) ) month = (pDate[6] - 0x30) * 10 + (pDate[6+ ++gab]-0x30); else month = (pDate[6] - 0x30); @@ -307,9 +281,9 @@ void HwpReader::makeMeta() else { month = 0; } - if( ISNUMBER( pDate[9 + gab] ) ) + if( rtl::isAsciiDigit( pDate[9 + gab] ) ) { - if( ISNUMBER( pDate[10 + gab])) { + if( rtl::isAsciiDigit( pDate[10 + gab])) { day = ( pDate[9 + gab] - 0x30 ) * 10 + (pDate[9+ gab + 1]-0x30); ++gab; } else @@ -318,9 +292,9 @@ void HwpReader::makeMeta() else { day = 0; } - if( ISNUMBER( pDate[17 + gab] ) ) + if( rtl::isAsciiDigit( pDate[17 + gab] ) ) { - if( ISNUMBER( pDate[18 + gab])) { + if( rtl::isAsciiDigit( pDate[18 + gab])) { hour = ( pDate[17 + gab] - 0x30 ) * 10 + (pDate[17+ gab + 1]-0x30); ++gab; } else @@ -329,9 +303,9 @@ void HwpReader::makeMeta() else { hour = 0; } - if( ISNUMBER( pDate[20 + gab] ) ) + if( rtl::isAsciiDigit( pDate[20 + gab] ) ) { - if( ISNUMBER( pDate[21 + gab])) { + if( rtl::isAsciiDigit( pDate[21 + gab])) { minute = ( pDate[20 + gab] - 0x30 ) * 10 + (pDate[20+ gab + 1]-0x30); ++gab; } else @@ -340,49 +314,49 @@ void HwpReader::makeMeta() else { minute = 0; } - sprintf(buf,"%d-%02d-%02dT%02d:%02d:00",year,month,day,hour,minute); + o3tl::sprintf(d->buf,"%d-%02d-%02dT%02d:%02d:00",year,month,day,hour,minute); - rstartEl( "meta:creation-date", mxList ); - rchars( ascii(buf)); - rendEl( "meta:creation-date" ); + startEl("meta:creation-date"); + chars( OUString::createFromAscii(d->buf)); + endEl("meta:creation-date"); } if (hwpinfo.summary.keyword[0][0] || hwpinfo.summary.etc[0][0]) { - rstartEl("meta:keywords", mxList); + startEl("meta:keywords"); if (hwpinfo.summary.keyword[0][0]) { - rstartEl("meta:keyword", mxList); - rchars(fromHcharStringToOUString(hstr2ucsstr(hwpinfo.summary.keyword[0]))); - rendEl("meta:keyword"); + startEl("meta:keyword"); + chars(hstr2OUString(reinterpret_cast<hchar *>(hwpinfo.summary.keyword[0]))); + endEl("meta:keyword"); } if (hwpinfo.summary.keyword[1][0]) { - rstartEl("meta:keyword", mxList); - rchars(fromHcharStringToOUString(hstr2ucsstr(hwpinfo.summary.keyword[1]))); - rendEl("meta:keyword"); + startEl("meta:keyword"); + chars(hstr2OUString(reinterpret_cast<hchar *>(hwpinfo.summary.keyword[1]))); + endEl("meta:keyword"); } if (hwpinfo.summary.etc[0][0]) { - rstartEl("meta:keyword", mxList); - rchars(fromHcharStringToOUString(hstr2ucsstr(hwpinfo.summary.etc[0]))); - rendEl("meta:keyword"); + startEl("meta:keyword"); + chars(hstr2OUString(reinterpret_cast<hchar *>(hwpinfo.summary.etc[0]))); + endEl("meta:keyword"); } if (hwpinfo.summary.etc[1][0]) { - rstartEl("meta:keyword", mxList); - rchars(fromHcharStringToOUString(hstr2ucsstr(hwpinfo.summary.etc[1]))); - rendEl("meta:keyword"); + startEl("meta:keyword"); + chars(hstr2OUString(reinterpret_cast<hchar *>(hwpinfo.summary.etc[1]))); + endEl("meta:keyword"); } if (hwpinfo.summary.etc[2][0]) { - rstartEl("meta:keyword", mxList); - rchars(fromHcharStringToOUString(hstr2ucsstr(hwpinfo.summary.etc[2]))); - rendEl("meta:keyword"); + startEl("meta:keyword"); + chars(hstr2OUString(reinterpret_cast<hchar *>(hwpinfo.summary.etc[2]))); + endEl("meta:keyword"); } - rendEl("meta:keywords"); + endEl("meta:keywords"); } - rendEl("office:meta"); + endEl("office:meta"); } @@ -436,76 +410,80 @@ void HwpReader::makeDrawMiscStyle( HWPDrawingObject *hdo ) if( prop->line_pstyle > 0 && prop->line_pstyle < 5 && prop->line_color <= 0xffffff) { - padd( "draw:name", sXML_CDATA, ascii(Int2Str(hdo->index, "LineType%d", buf))); - padd( "draw:style", sXML_CDATA, "round"); - padd( "draw:dots1", sXML_CDATA, "1"); - padd( "draw:dots1-length", sXML_CDATA, Double2Str( LineStyle[prop->line_pstyle].dots1 * WTMM(prop->line_width) ) + "cm"); + mxList->addAttribute( "draw:name", sXML_CDATA, "LineType" + OUString::number(hdo->index)); + mxList->addAttribute( "draw:style", sXML_CDATA, "round"); + mxList->addAttribute( "draw:dots1", sXML_CDATA, "1"); + mxList->addAttribute( "draw:dots1-length", sXML_CDATA, OUString::number( LineStyle[prop->line_pstyle].dots1 * WTMM(prop->line_width) ) + "cm"); if( prop->line_pstyle == 3 ) { - padd( "draw:dots2", sXML_CDATA, "1"); - padd( "draw:dots2-length", sXML_CDATA, Double2Str( LineStyle[prop->line_pstyle].dots2 * WTMM(prop->line_width) ) + "cm"); + mxList->addAttribute( "draw:dots2", sXML_CDATA, "1"); + mxList->addAttribute( "draw:dots2-length", sXML_CDATA, OUString::number( LineStyle[prop->line_pstyle].dots2 * WTMM(prop->line_width) ) + "cm"); } else if( prop->line_pstyle == 4 ) { - padd( "draw:dots2", sXML_CDATA, "2"); - padd( "draw:dots2-length", sXML_CDATA, Double2Str( LineStyle[prop->line_pstyle].dots2 * WTMM(prop->line_width)) + "cm"); + mxList->addAttribute( "draw:dots2", sXML_CDATA, "2"); + mxList->addAttribute( "draw:dots2-length", sXML_CDATA, OUString::number( LineStyle[prop->line_pstyle].dots2 * WTMM(prop->line_width)) + "cm"); } - padd( "draw:distance", sXML_CDATA, Double2Str( LineStyle[prop->line_pstyle].distance * WTMM(prop->line_width)) + "cm"); - rstartEl( "draw:stroke-dash", mxList); + mxList->addAttribute( "draw:distance", sXML_CDATA, OUString::number( LineStyle[prop->line_pstyle].distance * WTMM(prop->line_width)) + "cm"); + startEl("draw:stroke-dash"); mxList->clear(); - rendEl( "draw:stroke-dash" ); + endEl("draw:stroke-dash"); } if( hdo->type == HWPDO_LINE || hdo->type == HWPDO_ARC || hdo->type == HWPDO_FREEFORM || hdo->type == HWPDO_ADVANCED_ARC ) { - if( prop->line_tstyle && !ArrowShape[prop->line_tstyle].bMade ) + if( prop->line_tstyle > 0 && + o3tl::make_unsigned(prop->line_tstyle) < std::size(ArrowShape) && + !ArrowShape[prop->line_tstyle].bMade ) { ArrowShape[prop->line_tstyle].bMade = true; - padd("draw:name", sXML_CDATA, - ascii(ArrowShape[prop->line_tstyle].name)); + mxList->addAttribute("draw:name", sXML_CDATA, + OUString::createFromAscii(ArrowShape[prop->line_tstyle].name)); if( prop->line_tstyle == 1 ) { - padd("svg:viewBox", sXML_CDATA, "0 0 20 30"); - padd("svg:d", sXML_CDATA, "m10 0-10 30h20z"); + mxList->addAttribute("svg:viewBox", sXML_CDATA, "0 0 20 30"); + mxList->addAttribute("svg:d", sXML_CDATA, "m10 0-10 30h20z"); } else if( prop->line_tstyle == 2 ) { - padd("svg:viewBox", sXML_CDATA, "0 0 1122 2243"); - padd("svg:d", sXML_CDATA, "m0 2108v17 17l12 42 30 34 38 21 43 4 29-8 30-21 25-26 13-34 343-1532 339 1520 13 42 29 34 39 21 42 4 42-12 34-30 21-42v-39-12l-4 4-440-1998-9-42-25-39-38-25-43-8-42 8-38 25-26 39-8 42z"); + mxList->addAttribute("svg:viewBox", sXML_CDATA, "0 0 1122 2243"); + mxList->addAttribute("svg:d", sXML_CDATA, "m0 2108v17 17l12 42 30 34 38 21 43 4 29-8 30-21 25-26 13-34 343-1532 339 1520 13 42 29 34 39 21 42 4 42-12 34-30 21-42v-39-12l-4 4-440-1998-9-42-25-39-38-25-43-8-42 8-38 25-26 39-8 42z"); } else if( prop->line_tstyle == 3 ) { - padd("svg:viewBox", sXML_CDATA, "0 0 30 30"); - padd("svg:d", sXML_CDATA, "m0 0h30v30h-30z"); + mxList->addAttribute("svg:viewBox", sXML_CDATA, "0 0 30 30"); + mxList->addAttribute("svg:d", sXML_CDATA, "m0 0h30v30h-30z"); } - rstartEl("draw:marker", mxList); + startEl("draw:marker"); mxList->clear(); - rendEl("draw:marker"); + endEl("draw:marker"); } - if( prop->line_hstyle && !ArrowShape[prop->line_hstyle].bMade) + if (prop->line_hstyle > 0 && + o3tl::make_unsigned(prop->line_hstyle) < std::size(ArrowShape) && + !ArrowShape[prop->line_hstyle].bMade) { ArrowShape[prop->line_hstyle].bMade = true; - padd("draw:name", sXML_CDATA, - ascii(ArrowShape[prop->line_hstyle].name)); + mxList->addAttribute("draw:name", sXML_CDATA, + OUString::createFromAscii(ArrowShape[prop->line_hstyle].name)); if( prop->line_hstyle == 1 ) { - padd("svg:viewBox", sXML_CDATA, "0 0 20 30"); - padd("svg:d", sXML_CDATA, "m10 0-10 30h20z"); + mxList->addAttribute("svg:viewBox", sXML_CDATA, "0 0 20 30"); + mxList->addAttribute("svg:d", sXML_CDATA, "m10 0-10 30h20z"); } else if( prop->line_hstyle == 2 ) { - padd("svg:viewBox", sXML_CDATA, "0 0 1122 2243"); - padd("svg:d", sXML_CDATA, "m0 2108v17 17l12 42 30 34 38 21 43 4 29-8 30-21 25-26 13-34 343-1532 339 1520 13 42 29 34 39 21 42 4 42-12 34-30 21-42v-39-12l-4 4-440-1998-9-42-25-39-38-25-43-8-42 8-38 25-26 39-8 42z"); + mxList->addAttribute("svg:viewBox", sXML_CDATA, "0 0 1122 2243"); + mxList->addAttribute("svg:d", sXML_CDATA, "m0 2108v17 17l12 42 30 34 38 21 43 4 29-8 30-21 25-26 13-34 343-1532 339 1520 13 42 29 34 39 21 42 4 42-12 34-30 21-42v-39-12l-4 4-440-1998-9-42-25-39-38-25-43-8-42 8-38 25-26 39-8 42z"); } else if( prop->line_hstyle == 3 ) { - padd("svg:viewBox", sXML_CDATA, "0 0 20 20"); - padd("svg:d", sXML_CDATA, "m0 0h20v20h-20z"); + mxList->addAttribute("svg:viewBox", sXML_CDATA, "0 0 20 20"); + mxList->addAttribute("svg:d", sXML_CDATA, "m0 0h20v20h-20z"); } - rstartEl("draw:marker", mxList); + startEl("draw:marker"); mxList->clear(); - rendEl("draw:marker"); + endEl("draw:marker"); } } @@ -513,90 +491,55 @@ void HwpReader::makeDrawMiscStyle( HWPDrawingObject *hdo ) { if( prop->flag >> 18 & 0x01 ) { - padd( "draw:name", sXML_CDATA, ascii(Int2Str(hdo->index, "fillimage%d", buf))); - if( !prop->pictype ) - { - padd( "xlink:href", sXML_CDATA, - fromHcharStringToOUString(hstr2ucsstr(kstr2hstr( reinterpret_cast<uchar const *>(urltounix(prop->szPatternFile).c_str())).c_str()))); - } - else - { - EmPicture *emp = nullptr; - if ( strlen( prop->szPatternFile ) > 3) - emp = hwpfile.GetEmPictureByName(prop->szPatternFile); - if( emp ) - { - char filename[128+17+9]; - char dirname[128]; - int fd; -#ifdef _WIN32 - GetTempPathA(sizeof(dirname), dirname); - sprintf(filename, "%s%s",dirname, emp->name); - if( (fd = open( filename , _O_CREAT | _O_WRONLY | _O_BINARY , 0666)) >= 0 ) -#else - strcpy(dirname, "/tmp/"); - sprintf(filename, "%s%s", dirname, emp->name); - if( (fd = open( filename , O_CREAT | O_WRONLY , 0666)) >= 0 ) -#endif - { - size_t nWritten = write(fd, emp->data.get(), emp->size); - OSL_VERIFY(nWritten == emp->size); - close(fd); - } -#ifdef _WIN32 - int j; - for(j = 0 ; j < static_cast<int>(strlen( dirname )) ; j++) - { - if( dirname[j] == '\\' ) buf[j] = '/'; - else buf[j] = dirname[j]; - } - buf[j] = '\0'; - sprintf(filename, "file:///%s%s",buf, emp->name ); -#else - sprintf(filename, "file://%s%s",dirname, emp->name ); -#endif - padd( "xlink:href", sXML_CDATA, ascii(filename)); - } - else - { - padd( "xlink:href", sXML_CDATA, - fromHcharStringToOUString(hstr2ucsstr(kstr2hstr( reinterpret_cast<uchar const *>(urltounix(prop->szPatternFile).c_str())).c_str()))); - } + mxList->addAttribute( "draw:name", sXML_CDATA, "fillimage" + OUString::number(hdo->index)); + EmPicture *emp = nullptr; + if (prop->pictype && strlen(prop->szPatternFile) > 3) + emp = hwpfile.GetEmPictureByName(prop->szPatternFile); + if (!emp) + { + mxList->addAttribute( "xlink:href", sXML_CDATA, + hstr2OUString(kstr2hstr( reinterpret_cast<uchar const *>(urltounix(prop->szPatternFile).c_str())).c_str())); + mxList->addAttribute( "xlink:type", sXML_CDATA, "simple"); + mxList->addAttribute( "xlink:show", sXML_CDATA, "embed"); + mxList->addAttribute( "xlink:actuate", sXML_CDATA, "onLoad"); } - padd( "xlink:type", sXML_CDATA, "simple"); - padd( "xlink:show", sXML_CDATA, "embed"); - padd( "xlink:actuate", sXML_CDATA, "onLoad"); - rstartEl( "draw:fill-image", mxList); + startEl("draw:fill-image"); mxList->clear(); - rendEl( "draw:fill-image"); + if (emp) + { + startEl("office:binary-data"); + chars(base64_encode_string(emp->data.data(), emp->size)); + endEl("office:binary-data"); + } + endEl("draw:fill-image"); } /* If there is a gradient, when a bitmap file is present, this is the first. */ else if( prop->flag >> 16 & 0x01 ) /* existence gradient */ { - padd( "draw:name", sXML_CDATA, ascii(Int2Str(hdo->index, "Grad%d", buf))); + mxList->addAttribute( "draw:name", sXML_CDATA, "Grad" + OUString::number(hdo->index)); switch( prop->gstyle ) { case 1 : if( prop->center_y == 50 ) - padd( "draw:style", sXML_CDATA, "axial"); + mxList->addAttribute( "draw:style", sXML_CDATA, "axial"); else - padd( "draw:style", sXML_CDATA, "linear"); + mxList->addAttribute( "draw:style", sXML_CDATA, "linear"); break; case 2: case 3: - padd( "draw:style", sXML_CDATA, "radial"); + mxList->addAttribute( "draw:style", sXML_CDATA, "radial"); break; case 4: - padd( "draw:style", sXML_CDATA, "square"); + mxList->addAttribute( "draw:style", sXML_CDATA, "square"); break; default: - padd( "draw:style", sXML_CDATA, "linear"); + mxList->addAttribute( "draw:style", sXML_CDATA, "linear"); break; } - padd( "draw:cx", sXML_CDATA,ascii(Int2Str(prop->center_x, "%d%%", buf))); - padd( "draw:cy", sXML_CDATA,ascii(Int2Str(prop->center_y, "%d%%", buf))); + mxList->addAttribute( "draw:cx", sXML_CDATA, OUString::number(prop->center_x) + "%"); + mxList->addAttribute( "draw:cy", sXML_CDATA, OUString::number(prop->center_y) + "%"); HWPInfo& hwpinfo = hwpfile.GetHWPInfo(); int default_color = 0xffffff; @@ -617,79 +560,61 @@ void HwpReader::makeDrawMiscStyle( HWPDrawingObject *hdo ) { if( prop->center_y == 100 ) { - sprintf( buf, "#%02x%02x%02x", prop->tocolor & 0xff, - (prop->tocolor >> 8) & 0xff, (prop->tocolor >>16) & 0xff ); - padd( "draw:start-color", sXML_CDATA, ascii( buf )); - sprintf( buf, "#%02x%02x%02x", prop->fromcolor & 0xff, - (prop->fromcolor >> 8) & 0xff, (prop->fromcolor >>16) & 0xff ); - padd( "draw:end-color", sXML_CDATA, ascii( buf )); + mxList->addAttribute( "draw:start-color", sXML_CDATA, rgb2str( prop->tocolor )); + mxList->addAttribute( "draw:end-color", sXML_CDATA, rgb2str( prop->fromcolor )); } else { - sprintf( buf, "#%02x%02x%02x", prop->fromcolor & 0xff, - (prop->fromcolor >> 8) & 0xff, (prop->fromcolor >>16) & 0xff ); - padd( "draw:start-color", sXML_CDATA, ascii( buf )); - sprintf( buf, "#%02x%02x%02x", prop->tocolor & 0xff, - (prop->tocolor >> 8) & 0xff, (prop->tocolor >>16) & 0xff ); - padd( "draw:end-color", sXML_CDATA, ascii( buf )); + mxList->addAttribute( "draw:start-color", sXML_CDATA, rgb2str( prop->fromcolor )); + mxList->addAttribute( "draw:end-color", sXML_CDATA, rgb2str( prop->tocolor )); } } else { - sprintf( buf, "#%02x%02x%02x", prop->tocolor & 0xff, - (prop->tocolor >> 8) & 0xff, (prop->tocolor >>16) & 0xff ); - padd( "draw:start-color", sXML_CDATA,ascii( buf )); - - sprintf( buf, "#%02x%02x%02x", prop->fromcolor & 0xff, - (prop->fromcolor >> 8) & 0xff, (prop->fromcolor >>16) & 0xff ); - padd( "draw:end-color", sXML_CDATA,ascii( buf )); + mxList->addAttribute( "draw:start-color", sXML_CDATA,rgb2str( prop->tocolor )); + mxList->addAttribute( "draw:end-color", sXML_CDATA,rgb2str( prop->fromcolor )); } if( prop->angle > 0 && ( prop->gstyle == 1 || prop->gstyle == 4)) { - int angle = 1800 - prop->angle * 10; - padd( "draw:angle", sXML_CDATA, - ascii(Int2Str( angle, "%d", buf))); + auto normangle = prop->angle % 360; + int angle = 1800 - normangle * 10; + mxList->addAttribute( "draw:angle", sXML_CDATA, OUString::number(angle)); } - rstartEl( "draw:gradient", mxList ); + startEl("draw:gradient"); mxList->clear(); - rendEl( "draw:gradient"); + endEl("draw:gradient"); } /* hatch */ else if( prop->pattern_type >> 24 & 0x01 ) { int type = prop->pattern_type & 0xffffff; - padd( "draw:name", sXML_CDATA, - ascii(Int2Str(hdo->index, "Hatch%d", buf))); + mxList->addAttribute( "draw:name", sXML_CDATA, "Hatch" + OUString::number(hdo->index)); if( type < 4 ) - padd( "draw:style", sXML_CDATA, "single" ); + mxList->addAttribute( "draw:style", sXML_CDATA, "single" ); else - padd( "draw:style", sXML_CDATA, "double" ); - sprintf( buf, "#%02x%02x%02x", - sal_uInt16(prop->pattern_color & 0xff), - sal_uInt16((prop->pattern_color >> 8) & 0xff), - sal_uInt16((prop->pattern_color >>16) & 0xff) ); - padd( "draw:color", sXML_CDATA, ascii( buf )); - padd( "draw:distance", sXML_CDATA, "0.12cm"); + mxList->addAttribute( "draw:style", sXML_CDATA, "double" ); + mxList->addAttribute( "draw:color", sXML_CDATA, rgb2str( static_cast<int32_t>(prop->pattern_color) )); + mxList->addAttribute( "draw:distance", sXML_CDATA, "0.12cm"); switch( type ) { case 0 : case 4 : - padd( "draw:rotation", sXML_CDATA, "0"); + mxList->addAttribute( "draw:rotation", sXML_CDATA, "0"); break; case 1 : - padd( "draw:rotation", sXML_CDATA, "900"); + mxList->addAttribute( "draw:rotation", sXML_CDATA, "900"); break; case 2 : - padd( "draw:rotation", sXML_CDATA, "1350"); + mxList->addAttribute( "draw:rotation", sXML_CDATA, "1350"); break; case 3 : case 5 : - padd( "draw:rotation", sXML_CDATA, "450"); + mxList->addAttribute( "draw:rotation", sXML_CDATA, "450"); break; } - rstartEl( "draw:hatch", mxList); + startEl("draw:hatch"); mxList->clear(); - rendEl( "draw:hatch"); + endEl("draw:hatch"); } } hdo = hdo->next.get(); @@ -701,7 +626,7 @@ void HwpReader::makeStyles() { HWPStyle& hwpstyle = hwpfile.GetHWPStyle(); - rstartEl("office:styles", mxList); + startEl("office:styles"); int i; for (i = 0; i < hwpfile.getFBoxStyleCount(); i++) @@ -712,107 +637,107 @@ void HwpReader::makeStyles() } } - padd("style:name", sXML_CDATA, "Standard"); - padd("style:family", sXML_CDATA, "paragraph"); - padd("style:class", sXML_CDATA, "text"); - rstartEl("style:style", mxList); + mxList->addAttribute("style:name", sXML_CDATA, "Standard"); + mxList->addAttribute("style:family", sXML_CDATA, "paragraph"); + mxList->addAttribute("style:class", sXML_CDATA, "text"); + startEl("style:style"); mxList->clear(); - padd("fo:line-height", sXML_CDATA, "160%"); - padd("fo:text-align", sXML_CDATA, "justify"); - rstartEl("style:properties", mxList); + mxList->addAttribute("fo:line-height", sXML_CDATA, "160%"); + mxList->addAttribute("fo:text-align", sXML_CDATA, "justify"); + startEl("style:properties"); mxList->clear(); - rstartEl("style:tab-stops", mxList); + startEl("style:tab-stops"); for( i = 1 ; i < 40 ; i++) { - padd("style:position", sXML_CDATA, - Double2Str( WTI(1000 * i)) + "inch"); - rstartEl("style:tab-stop", mxList); + mxList->addAttribute("style:position", sXML_CDATA, + OUString::number( WTI(1000 * i)) + "inch"); + startEl("style:tab-stop"); mxList->clear(); - rendEl("style:tab-stop"); + endEl("style:tab-stop"); } - rendEl("style:tab-stops"); - rendEl("style:properties"); + endEl("style:tab-stops"); + endEl("style:properties"); - rendEl("style:style"); + endEl("style:style"); for (int ii = 0; ii < hwpstyle.Num(); ii++) { unsigned char *stylename = reinterpret_cast<unsigned char *>(hwpstyle.GetName(ii)); - padd("style:name", sXML_CDATA, fromHcharStringToOUString(hstr2ucsstr(kstr2hstr(stylename).c_str()))); - padd("style:family", sXML_CDATA, "paragraph"); - padd("style:parent-style-name", sXML_CDATA, "Standard"); + mxList->addAttribute("style:name", sXML_CDATA, hstr2OUString(kstr2hstr(stylename).c_str())); + mxList->addAttribute("style:family", sXML_CDATA, "paragraph"); + mxList->addAttribute("style:parent-style-name", sXML_CDATA, "Standard"); - rstartEl("style:style", mxList); + startEl("style:style"); mxList->clear(); parseCharShape(hwpstyle.GetCharShape(ii)); parseParaShape(hwpstyle.GetParaShape(ii)); - rstartEl("style:properties", mxList); + startEl("style:properties"); mxList->clear(); - rendEl("style:properties"); + endEl("style:properties"); - rendEl("style:style"); + endEl("style:style"); } { - padd( "style:name", sXML_CDATA, "Header"); - padd( "style:family", sXML_CDATA, "paragraph"); - padd( "style:parent-style-name", sXML_CDATA, "Standard"); - padd( "style:class", sXML_CDATA, "extra"); - rstartEl("style:style", mxList); + mxList->addAttribute( "style:name", sXML_CDATA, "Header"); + mxList->addAttribute( "style:family", sXML_CDATA, "paragraph"); + mxList->addAttribute( "style:parent-style-name", sXML_CDATA, "Standard"); + mxList->addAttribute( "style:class", sXML_CDATA, "extra"); + startEl("style:style"); mxList->clear(); - rendEl("style:style"); + endEl("style:style"); } { - padd( "style:name", sXML_CDATA, "Footer"); - padd( "style:family", sXML_CDATA, "paragraph"); - padd( "style:parent-style-name", sXML_CDATA, "Standard"); - padd( "style:class", sXML_CDATA, "extra"); - rstartEl("style:style", mxList); + mxList->addAttribute( "style:name", sXML_CDATA, "Footer"); + mxList->addAttribute( "style:family", sXML_CDATA, "paragraph"); + mxList->addAttribute( "style:parent-style-name", sXML_CDATA, "Standard"); + mxList->addAttribute( "style:class", sXML_CDATA, "extra"); + startEl("style:style"); mxList->clear(); - rendEl("style:style"); + endEl("style:style"); } if( hwpfile.linenumber > 0) { - padd( "style:name", sXML_CDATA, "Horizontal Line"); - padd( "style:family", sXML_CDATA, "paragraph"); - padd( "style:parent-style-name", sXML_CDATA, "Standard"); - padd( "style:class", sXML_CDATA, "html"); - rstartEl( "style:style", mxList); + mxList->addAttribute( "style:name", sXML_CDATA, "Horizontal Line"); + mxList->addAttribute( "style:family", sXML_CDATA, "paragraph"); + mxList->addAttribute( "style:parent-style-name", sXML_CDATA, "Standard"); + mxList->addAttribute( "style:class", sXML_CDATA, "html"); + startEl("style:style"); mxList->clear(); - padd( "fo:font-size", sXML_CDATA, "6pt"); - padd( "fo:margin-top", sXML_CDATA, "0cm"); - padd( "fo:margin-bottom", sXML_CDATA, "0cm"); - padd( "style:border-line-width-bottom", sXML_CDATA, "0.02cm 0.035cm 0.002cm"); - padd( "fo:padding", sXML_CDATA, "0cm"); - padd( "fo:border-bottom", sXML_CDATA, "0.039cm double #808080"); - padd( "text:number-lines", sXML_CDATA, "false"); - padd( "text:line-number", sXML_CDATA, "0"); - padd("fo:line-height", sXML_CDATA, "100%"); - rstartEl( "style:properties", mxList); + mxList->addAttribute( "fo:font-size", sXML_CDATA, "6pt"); + mxList->addAttribute( "fo:margin-top", sXML_CDATA, "0cm"); + mxList->addAttribute( "fo:margin-bottom", sXML_CDATA, "0cm"); + mxList->addAttribute( "style:border-line-width-bottom", sXML_CDATA, "0.02cm 0.035cm 0.002cm"); + mxList->addAttribute( "fo:padding", sXML_CDATA, "0cm"); + mxList->addAttribute( "fo:border-bottom", sXML_CDATA, "0.039cm double #808080"); + mxList->addAttribute( "text:number-lines", sXML_CDATA, "false"); + mxList->addAttribute( "text:line-number", sXML_CDATA, "0"); + mxList->addAttribute("fo:line-height", sXML_CDATA, "100%"); + startEl("style:properties"); mxList->clear(); - rendEl( "style:properties"); - rendEl( "style:style"); + endEl("style:properties"); + endEl("style:style"); } HWPInfo& hwpinfo = hwpfile.GetHWPInfo(); - padd("text:num-suffix", sXML_CDATA, ")"); - padd("text:num-format", sXML_CDATA, "1"); + mxList->addAttribute("text:num-suffix", sXML_CDATA, ")"); + mxList->addAttribute("text:num-format", sXML_CDATA, "1"); if( hwpinfo.beginfnnum != 1) - padd("text:offset", sXML_CDATA, ascii(Int2Str(hwpinfo.beginfnnum -1, "%d", buf))); - rstartEl("text:footnotes-configuration", mxList); + mxList->addAttribute("text:offset", sXML_CDATA, OUString::number(hwpinfo.beginfnnum - 1)); + startEl("text:footnotes-configuration"); mxList->clear(); - rendEl("text:footnotes-configuration"); + endEl("text:footnotes-configuration"); - rendEl("office:styles"); + endEl("office:styles"); } @@ -825,7 +750,7 @@ void HwpReader::makeAutoStyles() { int i; - rstartEl("office:automatic-styles", mxList); + startEl("office:automatic-styles"); for (i = 0; i < hwpfile.getParaShapeCount(); i++) makePStyle(hwpfile.getParaShape(i)); @@ -875,47 +800,46 @@ void HwpReader::makeAutoStyles() continue; if( i == 3 && !bIsRight ) continue; - padd("style:name", sXML_CDATA, - ascii(Int2Str(i,"PNPara%d", buf))); - padd("style:family", sXML_CDATA, "paragraph"); - padd("style:parent-style-name", sXML_CDATA, "Standard"); - rstartEl("style:style", mxList); + mxList->addAttribute("style:name", sXML_CDATA, "PNPara" + OUString::number(i)); + mxList->addAttribute("style:family", sXML_CDATA, "paragraph"); + mxList->addAttribute("style:parent-style-name", sXML_CDATA, "Standard"); + startEl("style:style"); mxList->clear(); if( i == 1 ) - padd("fo:text-align", sXML_CDATA, "start"); + mxList->addAttribute("fo:text-align", sXML_CDATA, "start"); else if ( i == 2 ) - padd("fo:text-align", sXML_CDATA, "center"); + mxList->addAttribute("fo:text-align", sXML_CDATA, "center"); else if ( i == 3 ) - padd("fo:text-align", sXML_CDATA, "end"); - rstartEl("style:properties", mxList); + mxList->addAttribute("fo:text-align", sXML_CDATA, "end"); + startEl("style:properties"); mxList->clear(); - rendEl( "style:properties"); - rendEl( "style:style"); + endEl("style:properties"); + endEl("style:style"); - padd("style:name", sXML_CDATA, ascii(Int2Str(i,"PNBox%d",buf))); - padd("style:family", sXML_CDATA, "graphics"); - rstartEl("style:style", mxList); + mxList->addAttribute("style:name", sXML_CDATA, "PNBox" + OUString::number(i)); + mxList->addAttribute("style:family", sXML_CDATA, "graphics"); + startEl("style:style"); mxList->clear(); - padd("fo:margin-top", sXML_CDATA, "0cm"); - padd("fo:margin-bottom", sXML_CDATA, "0cm"); - padd("style:wrap", sXML_CDATA, "run-through"); - padd("style:vertical-pos", sXML_CDATA, "from-top"); - padd("style:vertical-rel", sXML_CDATA, "paragraph"); + mxList->addAttribute("fo:margin-top", sXML_CDATA, "0cm"); + mxList->addAttribute("fo:margin-bottom", sXML_CDATA, "0cm"); + mxList->addAttribute("style:wrap", sXML_CDATA, "run-through"); + mxList->addAttribute("style:vertical-pos", sXML_CDATA, "from-top"); + mxList->addAttribute("style:vertical-rel", sXML_CDATA, "paragraph"); if( i == 1 ) - padd("style:horizontal-pos", sXML_CDATA, "left"); + mxList->addAttribute("style:horizontal-pos", sXML_CDATA, "left"); else if ( i == 2 ) - padd("style:horizontal-pos", sXML_CDATA, "center"); + mxList->addAttribute("style:horizontal-pos", sXML_CDATA, "center"); else if ( i == 3 ) - padd("style:horizontal-pos", sXML_CDATA, "right"); - padd("style:horizontal-rel", sXML_CDATA, "paragraph"); - padd("fo:padding", sXML_CDATA, "0cm"); - padd("stylefamily", sXML_CDATA, "graphics"); - rstartEl("style:properties", mxList); + mxList->addAttribute("style:horizontal-pos", sXML_CDATA, "right"); + mxList->addAttribute("style:horizontal-rel", sXML_CDATA, "paragraph"); + mxList->addAttribute("fo:padding", sXML_CDATA, "0cm"); + mxList->addAttribute("stylefamily", sXML_CDATA, "graphics"); + startEl("style:properties"); mxList->clear(); - rendEl("style:properties"); - rendEl("style:style"); + endEl("style:properties"); + endEl("style:style"); } for (i = 0; i < hwpfile.getDateFormatCount(); i++) @@ -923,7 +847,7 @@ void HwpReader::makeAutoStyles() makePageStyle(); - rendEl("office:automatic-styles"); + endEl("office:automatic-styles"); } namespace { @@ -955,11 +879,11 @@ struct PageSetting void HwpReader::makeMasterStyles() { - rstartEl("office:master-styles", mxList); + startEl("office:master-styles"); int i; int nMax = hwpfile.getMaxSettedPage(); - std::deque<PageSetting> aSet(nMax + 1); + std::vector<PageSetting> aSet(nMax + 1); for( i = 0 ; i < hwpfile.getPageNumberCount() ; i++ ) { @@ -1034,21 +958,24 @@ void HwpReader::makeMasterStyles() PageSetting *pPrevSet = nullptr; PageSetting *pPage = nullptr; + if (nMax > 512 && comphelper::IsFuzzing()) + { + SAL_WARN("filter.hwp", "too many pages: " << nMax << " clip to " << 512); + nMax = 512; + } + for( i = 1; i <= nMax ; i++ ) { if( i == 1 ) - padd("style:name", sXML_CDATA, "Standard"); + mxList->addAttribute("style:name", sXML_CDATA, "Standard"); else - padd("style:name", sXML_CDATA, - ascii(Int2Str(i, "p%d", buf))); - padd("style:page-master-name", sXML_CDATA, - ascii(Int2Str(hwpfile.GetPageMasterNum(i), "pm%d", buf))); + mxList->addAttribute("style:name", sXML_CDATA, "p" + OUString::number(i)); + mxList->addAttribute("style:page-master-name", sXML_CDATA, + "pm" + OUString::number(hwpfile.GetPageMasterNum(i))); if( i < nMax ) - padd("style:next-style-name", sXML_CDATA, - ascii(Int2Str(i+1, "p%d", buf))); - padd("draw:style-name", sXML_CDATA, - ascii(Int2Str(i, "master%d", buf))); - rstartEl("style:master-page", mxList); + mxList->addAttribute("style:next-style-name", sXML_CDATA, "p" + OUString::number(i + 1)); + mxList->addAttribute("draw:style-name", sXML_CDATA, "master" + OUString::number(i)); + startEl("style:master-page"); mxList->clear(); if( aSet[i].bIsSet ) /* If you've changed the current setting */ @@ -1099,41 +1026,42 @@ void HwpReader::makeMasterStyles() } else /* If the previous settings doesn't exist, set to the default settings */ { - rstartEl("style:header", mxList); - padd("text:style-name", sXML_CDATA, "Standard"); - rstartEl("text:p", mxList); + startEl("style:header"); + mxList->addAttribute("text:style-name", sXML_CDATA, "Standard"); + startEl("text:p"); mxList->clear(); - rendEl("text:p"); - rendEl("style:header"); + endEl("text:p"); + endEl("style:header"); - rstartEl("style:footer", mxList); - padd("text:style-name", sXML_CDATA, "Standard"); - rstartEl("text:p", mxList); + startEl("style:footer"); + mxList->addAttribute("text:style-name", sXML_CDATA, "Standard"); + startEl("text:p"); mxList->clear(); - rendEl("text:p"); - rendEl("style:footer"); + endEl("text:p"); + endEl("style:footer"); - rendEl("style:master-page"); + endEl("style:master-page"); continue; } // header if( pPage->header ) { - rstartEl("style:header", mxList); + startEl("style:header"); if( pPage->pagenumber && pPage->pagenumber->where < 4 ) { d->bInHeader = true; d->pPn = pPage->pagenumber; } - parsePara(pPage->header->plist.front().get()); + if (!pPage->header->plist.empty()) + parsePara(pPage->header->plist.front().get()); d->bInHeader = false; d->pPn = nullptr; - rendEl("style:header"); + endEl("style:header"); } if( pPage->header_even ) { - rstartEl("style:header", mxList); + startEl("style:header"); if( pPage->pagenumber && ( pPage->pagenumber->where < 4 || pPage->pagenumber->where == 7 ) ) { @@ -1141,18 +1069,19 @@ void HwpReader::makeMasterStyles() d->pPn = pPage->pagenumber; d->nPnPos = 3; } - parsePara(pPage->header_even->plist.front().get()); + if (!pPage->header_even->plist.empty()) + parsePara(pPage->header_even->plist.front().get()); d->bInHeader = false; d->pPn = nullptr; d->nPnPos = 0; - rendEl("style:header"); + endEl("style:header"); } /* Will be the default. */ else if (pPage->header_odd) { - rstartEl("style:header", mxList); - padd("text:style-name", sXML_CDATA, "Standard"); - rstartEl("text:p", mxList); + startEl("style:header"); + mxList->addAttribute("text:style-name", sXML_CDATA, "Standard"); + startEl("text:p"); mxList->clear(); if( pPage->pagenumber && ( pPage->pagenumber->where < 4 || pPage->pagenumber->where == 7 ) ) @@ -1163,12 +1092,12 @@ void HwpReader::makeMasterStyles() d->pPn = nullptr; d->nPnPos = 0; } - rendEl("text:p"); - rendEl("style:header"); + endEl("text:p"); + endEl("style:header"); } if( pPage->header_odd ) { - rstartEl("style:header-left", mxList); + startEl("style:header-left"); if( pPage->pagenumber && ( pPage->pagenumber->where < 4 || pPage->pagenumber->where == 7 ) ) { @@ -1176,18 +1105,19 @@ void HwpReader::makeMasterStyles() d->nPnPos = 1; d->pPn = pPage->pagenumber; } - parsePara(pPage->header_odd->plist.front().get()); + if (!pPage->header_odd->plist.empty()) + parsePara(pPage->header_odd->plist.front().get()); d->bInHeader = false; d->pPn = nullptr; d->nPnPos = 0; - rendEl("style:header-left"); + endEl("style:header-left"); } /* Will be the default. */ else if (pPage->header_even) { - rstartEl("style:header-left", mxList); - padd("text:style-name", sXML_CDATA, "Standard"); - rstartEl("text:p", mxList); + startEl("style:header-left"); + mxList->addAttribute("text:style-name", sXML_CDATA, "Standard"); + startEl("text:p"); mxList->clear(); if( pPage->pagenumber && ( pPage->pagenumber->where < 4 || pPage->pagenumber->where == 7 ) ) @@ -1198,14 +1128,14 @@ void HwpReader::makeMasterStyles() d->pPn = nullptr; d->nPnPos = 0; } - rendEl("text:p"); - rendEl("style:header-left"); + endEl("text:p"); + endEl("style:header-left"); } if( !pPage->header && !pPage->header_even && !pPage->header_odd ) { - rstartEl("style:header", mxList); - padd("text:style-name", sXML_CDATA, "Standard"); - rstartEl("text:p", mxList); + startEl("style:header"); + mxList->addAttribute("text:style-name", sXML_CDATA, "Standard"); + startEl("text:p"); mxList->clear(); if( pPage->pagenumber && (pPage->pagenumber->where < 4 || pPage->pagenumber->where == 7 ) ) @@ -1214,27 +1144,28 @@ void HwpReader::makeMasterStyles() makeShowPageNum(); d->pPn = nullptr; } - rendEl("text:p"); - rendEl("style:header"); + endEl("text:p"); + endEl("style:header"); } // footer if( pPage->footer ) { - rstartEl("style:footer", mxList); + startEl("style:footer"); if( pPage->pagenumber && pPage->pagenumber->where >= 4 && pPage->pagenumber->where != 7 ) { d->bInHeader = true; d->pPn = pPage->pagenumber; } - parsePara(pPage->footer->plist.front().get()); + if (!pPage->footer->plist.empty()) + parsePara(pPage->footer->plist.front().get()); d->bInHeader = false; d->pPn = nullptr; - rendEl("style:footer"); + endEl("style:footer"); } if( pPage->footer_even ) { - rstartEl("style:footer", mxList); + startEl("style:footer"); if( pPage->pagenumber && pPage->pagenumber->where >= 4 && pPage->pagenumber->where != 7 ) { @@ -1242,18 +1173,19 @@ void HwpReader::makeMasterStyles() d->pPn = pPage->pagenumber; d->nPnPos = 3; } - parsePara(pPage->footer_even->plist.front().get()); + if (!pPage->footer_even->plist.empty()) + parsePara(pPage->footer_even->plist.front().get()); d->bInHeader = false; d->pPn = nullptr; d->nPnPos = 0; - rendEl("style:footer"); + endEl("style:footer"); } /* Will be the default. */ else if (pPage->footer_odd) { - rstartEl("style:footer", mxList); - padd("text:style-name", sXML_CDATA, "Standard"); - rstartEl("text:p", mxList); + startEl("style:footer"); + mxList->addAttribute("text:style-name", sXML_CDATA, "Standard"); + startEl("text:p"); mxList->clear(); if( pPage->pagenumber && pPage->pagenumber->where >= 4 && pPage->pagenumber->where != 7 ) @@ -1264,12 +1196,12 @@ void HwpReader::makeMasterStyles() d->pPn = nullptr; d->nPnPos = 0; } - rendEl("text:p"); - rendEl("style:footer"); + endEl("text:p"); + endEl("style:footer"); } if( pPage->footer_odd ) { - rstartEl("style:footer-left", mxList); + startEl("style:footer-left"); if( pPage->pagenumber && pPage->pagenumber->where >= 4 && pPage->pagenumber->where != 7 ) { @@ -1277,18 +1209,19 @@ void HwpReader::makeMasterStyles() d->pPn = pPage->pagenumber; d->nPnPos = 1; } - parsePara(pPage->footer_odd->plist.front().get()); + if (!pPage->footer_odd->plist.empty()) + parsePara(pPage->footer_odd->plist.front().get()); d->bInHeader = false; d->pPn = nullptr; d->nPnPos = 0; - rendEl("style:footer-left"); + endEl("style:footer-left"); } /* Will be the default. */ else if (pPage->footer_even) { - rstartEl("style:footer-left", mxList); - padd("text:style-name", sXML_CDATA, "Standard"); - rstartEl("text:p", mxList); + startEl("style:footer-left"); + mxList->addAttribute("text:style-name", sXML_CDATA, "Standard"); + startEl("text:p"); mxList->clear(); if( pPage->pagenumber && pPage->pagenumber->where >= 4 && pPage->pagenumber->where != 7 ) @@ -1299,14 +1232,14 @@ void HwpReader::makeMasterStyles() d->pPn = nullptr; d->nPnPos = 0; } - rendEl("text:p"); - rendEl("style:footer-left"); + endEl("text:p"); + endEl("style:footer-left"); } if( !pPage->footer && !pPage->footer_even && !pPage->footer_odd ) { - rstartEl("style:footer", mxList); - padd("text:style-name", sXML_CDATA, "Standard"); - rstartEl("text:p", mxList); + startEl("style:footer"); + mxList->addAttribute("text:style-name", sXML_CDATA, "Standard"); + startEl("text:p"); mxList->clear(); if( pPage->pagenumber && pPage->pagenumber->where >= 4 && pPage->pagenumber->where != 7 ) @@ -1315,13 +1248,13 @@ void HwpReader::makeMasterStyles() makeShowPageNum(); d->pPn = nullptr; } - rendEl("text:p"); - rendEl("style:footer"); + endEl("text:p"); + endEl("style:footer"); } - rendEl("style:master-page"); + endEl("style:master-page"); } - rendEl("office:master-styles"); + endEl("office:master-styles"); } @@ -1336,65 +1269,63 @@ void HwpReader::parseCharShape(CharShape const * cshape) { HWPFont& hwpfont = hwpfile.GetHWPFont(); - padd("fo:font-size", sXML_CDATA, - ascii(Int2Str(cshape->size / 25, "%dpt", buf))); - padd("style:font-size-asian", sXML_CDATA, - ascii(Int2Str(cshape->size / 25, "%dpt", buf))); + mxList->addAttribute("fo:font-size", sXML_CDATA, OUString::number(cshape->size / 25) + "pt"); + mxList->addAttribute("style:font-size-asian", sXML_CDATA, OUString::number(cshape->size / 25) + "pt"); ::std::string const tmp = hstr2ksstr(kstr2hstr( - reinterpret_cast<unsigned char const *>(hwpfont.GetFontName(0, cshape->font[0]))).c_str()); + reinterpret_cast<unsigned char const *>(hwpfont.GetFontName(0, cshape->font))).c_str()); double fRatio = 1.0; - int size = getRepFamilyName(tmp.c_str(), buf, fRatio); + int size = getRepFamilyName(tmp.c_str(), d->buf, fRatio); - padd("fo:font-family", sXML_CDATA, - OUString(buf, size, RTL_TEXTENCODING_EUC_KR)); - padd("style:font-family-asian", sXML_CDATA, - OUString(buf, size, RTL_TEXTENCODING_EUC_KR)); + mxList->addAttribute("fo:font-family", sXML_CDATA, + OUString(d->buf, size, RTL_TEXTENCODING_EUC_KR)); + mxList->addAttribute("style:font-family-asian", sXML_CDATA, + OUString(d->buf, size, RTL_TEXTENCODING_EUC_KR)); - padd("style:text-scale", sXML_CDATA, - ascii(Int2Str(static_cast<int>(cshape->ratio[0] * fRatio), "%d%%", buf))); + mxList->addAttribute("style:text-scale", sXML_CDATA, + OUString::number(static_cast<int>(cshape->ratio * fRatio)) + "%"); - double sspace = (cshape->size / 25) * cshape->space[0] / 100.; + double sspace = (cshape->size / 25) * cshape->space / 100.; if (sspace != 0.) { - padd("fo:letter-spacing", sXML_CDATA, - Double2Str(sspace) + "pt"); + mxList->addAttribute("fo:letter-spacing", sXML_CDATA, + OUString::number(sspace) + "pt"); } if (cshape->color[1] != 0) - padd("fo:color", sXML_CDATA, - ascii(hcolor2str(cshape->color[1], 100, buf, true))); + mxList->addAttribute("fo:color", sXML_CDATA, + hcolor2str(cshape->color[1], 100, true)); if (cshape->shade != 0) - padd("style:text-background-color", sXML_CDATA, - ascii(hcolor2str(cshape->color[0], cshape->shade, buf))); + mxList->addAttribute("style:text-background-color", sXML_CDATA, + hcolor2str(cshape->color[0], cshape->shade)); if (cshape->attr & 0x01) { - padd("fo:font-style", sXML_CDATA, "italic"); - padd("style:font-style-asian", sXML_CDATA, "italic"); + mxList->addAttribute("fo:font-style", sXML_CDATA, "italic"); + mxList->addAttribute("style:font-style-asian", sXML_CDATA, "italic"); } else{ - padd("fo:font-style", sXML_CDATA, "normal"); - padd("style:font-style-asian", sXML_CDATA, "normal"); + mxList->addAttribute("fo:font-style", sXML_CDATA, "normal"); + mxList->addAttribute("style:font-style-asian", sXML_CDATA, "normal"); } if (cshape->attr >> 1 & 0x01) { - padd("fo:font-weight", sXML_CDATA, "bold"); - padd("style:font-weight-asian", sXML_CDATA, "bold"); + mxList->addAttribute("fo:font-weight", sXML_CDATA, "bold"); + mxList->addAttribute("style:font-weight-asian", sXML_CDATA, "bold"); } else{ - padd("fo:font-weight", sXML_CDATA, "normal"); - padd("style:font-weight-asian", sXML_CDATA, "normal"); + mxList->addAttribute("fo:font-weight", sXML_CDATA, "normal"); + mxList->addAttribute("style:font-weight-asian", sXML_CDATA, "normal"); } if (cshape->attr >> 2 & 0x01) - padd("style:text-underline", sXML_CDATA, "single"); + mxList->addAttribute("style:text-underline", sXML_CDATA, "single"); if (cshape->attr >> 3 & 0x01) - padd("style:text-outline", sXML_CDATA, "true"); + mxList->addAttribute("style:text-outline", sXML_CDATA, "true"); if (cshape->attr >> 4 & 0x01) - padd("fo:text-shadow", sXML_CDATA, "1pt 1pt"); + mxList->addAttribute("fo:text-shadow", sXML_CDATA, "1pt 1pt"); if (cshape->attr >> 5 & 0x01) - padd("style:text-position", sXML_CDATA, "super 58%"); + mxList->addAttribute("style:text-position", sXML_CDATA, "super 58%"); if (cshape->attr >> 6 & 0x01) - padd("style:text-position", sXML_CDATA, "sub 58%"); + mxList->addAttribute("style:text-position", sXML_CDATA, "sub 58%"); } @@ -1410,63 +1341,58 @@ void HwpReader::parseParaShape(ParaShape const * pshape) { if (pshape->left_margin != 0) - padd("fo:margin-left", sXML_CDATA, Double2Str + mxList->addAttribute("fo:margin-left", sXML_CDATA, OUString::number (WTI(pshape->left_margin )) + "inch"); if (pshape->right_margin != 0) - padd("fo:margin-right", sXML_CDATA, Double2Str + mxList->addAttribute("fo:margin-right", sXML_CDATA, OUString::number (WTI(pshape->right_margin)) + "inch"); if (pshape->pspacing_prev != 0) - padd("fo:margin-top", sXML_CDATA, Double2Str + mxList->addAttribute("fo:margin-top", sXML_CDATA, OUString::number (WTI(pshape->pspacing_prev)) + "inch"); if (pshape->pspacing_next != 0) - padd("fo:margin-bottom", sXML_CDATA, Double2Str + mxList->addAttribute("fo:margin-bottom", sXML_CDATA, OUString::number (WTI(pshape->pspacing_next)) + "inch"); if (pshape->indent != 0) - padd("fo:text-indent", sXML_CDATA, Double2Str + mxList->addAttribute("fo:text-indent", sXML_CDATA, OUString::number (WTI(pshape->indent)) + "inch"); if (pshape->lspacing != 0) - padd("fo:line-height", sXML_CDATA, - ascii(Int2Str (pshape->lspacing, "%d%%", buf))); + mxList->addAttribute("fo:line-height", sXML_CDATA, OUString::number(pshape->lspacing) + "%"); - unsigned char set_align = 0; + const char* align = nullptr; switch (static_cast<int>(pshape->arrange_type)) { case 1: - strcpy(buf, "start"); - set_align = 1; + align = "start"; break; case 2: - strcpy(buf, "end"); - set_align = 1; + align = "end"; break; case 3: - strcpy(buf, "center"); - set_align = 1; + align = "center"; break; case 4: case 5: case 6: - strcpy(buf, "justify"); - set_align = 1; + align = "justify"; break; } - if (set_align) - padd("fo:text-align", sXML_CDATA, ascii(buf)); + if (align) + mxList->addAttribute("fo:text-align", sXML_CDATA, OUString::createFromAscii(align)); if (pshape->outline) - padd("fo:border", sXML_CDATA, "0.002cm solid #000000"); + mxList->addAttribute("fo:border", sXML_CDATA, "0.002cm solid #000000"); if( pshape->shade > 0 ) { - padd("fo:background-color", sXML_CDATA, - ascii(hcolor2str(0, pshape->shade, buf))); + mxList->addAttribute("fo:background-color", sXML_CDATA, + hcolor2str(0, pshape->shade)); } if( pshape->pagebreak & 0x02 || pshape->pagebreak & 0x04) - padd("fo:break-before", sXML_CDATA, "page"); + mxList->addAttribute("fo:break-before", sXML_CDATA, "page"); else if( pshape->pagebreak & 0x01 ) - padd("fo:break-before", sXML_CDATA, "column"); + mxList->addAttribute("fo:break-before", sXML_CDATA, "column"); } @@ -1477,20 +1403,20 @@ void HwpReader::parseParaShape(ParaShape const * pshape) void HwpReader::makePStyle(ParaShape const * pshape) { int nscount = pshape->tabs[MAXTABS -1].type; - padd("style:name", sXML_CDATA, - ascii(Int2Str(pshape->index, "P%d", buf))); - padd("style:family", sXML_CDATA, "paragraph"); - rstartEl("style:style", mxList); + mxList->addAttribute("style:name", sXML_CDATA, "P" + OUString::number(pshape->index)); + mxList->addAttribute("style:family", sXML_CDATA, "paragraph"); + startEl("style:style"); mxList->clear(); parseParaShape(pshape); - parseCharShape(pshape->cshape.get()); - rstartEl("style:properties", mxList); + if (pshape->cshape) + parseCharShape(pshape->cshape.get()); + startEl("style:properties"); mxList->clear(); if( nscount ) { unsigned char tf = 0; - rstartEl("style:tab-stops",mxList); + startEl("style:tab-stops"); int tab_margin = pshape->left_margin + pshape->indent; if( tab_margin < 0 ) @@ -1501,43 +1427,43 @@ void HwpReader::makePStyle(ParaShape const * pshape) break; if( pshape->tabs[i].position <= tab_margin ) continue; - padd("style:position", sXML_CDATA, - Double2Str(WTMM(pshape->tabs[i].position - tab_margin )) + "mm"); + mxList->addAttribute("style:position", sXML_CDATA, + OUString::number(WTMM(pshape->tabs[i].position - tab_margin )) + "mm"); if( pshape->tabs[i].type ) { tf = 1; switch(pshape->tabs[i].type) { case 1 : - padd("style:type", sXML_CDATA, "right"); + mxList->addAttribute("style:type", sXML_CDATA, "right"); break; case 2: - padd("style:type", sXML_CDATA, "center"); + mxList->addAttribute("style:type", sXML_CDATA, "center"); break; case 3: - padd("style:type", sXML_CDATA, "char"); - padd("style:char", sXML_CDATA, "."); + mxList->addAttribute("style:type", sXML_CDATA, "char"); + mxList->addAttribute("style:char", sXML_CDATA, "."); break; } } if( pshape->tabs[i].dot_continue ) { tf = 1; - padd("style:leader-char", sXML_CDATA, "."); + mxList->addAttribute("style:leader-char", sXML_CDATA, "."); } - rstartEl( "style:tab-stop", mxList); + startEl("style:tab-stop"); mxList->clear(); - rendEl( "style:tab-stop" ); + endEl("style:tab-stop"); if( (pshape->tabs[i].position != 1000 * i ) || tf ) { if( !--nscount ) break; } } - rendEl( "style:tab-stops"); + endEl("style:tab-stops"); } - rendEl("style:properties"); - rendEl("style:style"); + endEl("style:properties"); + endEl("style:style"); } @@ -1550,9 +1476,15 @@ void HwpReader::makePageStyle() HWPInfo& hwpinfo = hwpfile.GetHWPInfo(); int pmCount = hwpfile.getColumnCount(); + if (pmCount > 512 && comphelper::IsFuzzing()) + { + SAL_WARN("filter.hwp", "too many pages: " << pmCount << " clip to " << 512); + pmCount = 512; + } + for( int i = 0 ; i < pmCount ; i++ ){ - padd("style:name", sXML_CDATA, ascii(Int2Str(i + 1, "pm%d", buf))); - rstartEl("style:page-master",mxList); + mxList->addAttribute("style:name", sXML_CDATA, "pm" + OUString::number(i + 1)); + startEl("style:page-master"); mxList->clear(); @@ -1561,73 +1493,73 @@ void HwpReader::makePageStyle() case 3: // A4 if( hwpinfo.paper.paper_direction ) { - padd("fo:page-height",sXML_CDATA, "210mm"); - padd("fo:page-width",sXML_CDATA, "297mm"); + mxList->addAttribute("fo:page-height",sXML_CDATA, "210mm"); + mxList->addAttribute("fo:page-width",sXML_CDATA, "297mm"); } else { - padd("fo:page-width",sXML_CDATA, "210mm"); - padd("fo:page-height",sXML_CDATA, "297mm"); + mxList->addAttribute("fo:page-width",sXML_CDATA, "210mm"); + mxList->addAttribute("fo:page-height",sXML_CDATA, "297mm"); } break; case 4: // 80 column if( hwpinfo.paper.paper_direction ) { - padd("fo:page-height",sXML_CDATA, "8.5inch"); - padd("fo:page-width",sXML_CDATA, "11inch"); + mxList->addAttribute("fo:page-height",sXML_CDATA, "8.5inch"); + mxList->addAttribute("fo:page-width",sXML_CDATA, "11inch"); } else { - padd("fo:page-width",sXML_CDATA, "8.5inch"); - padd("fo:page-height",sXML_CDATA, "11inch"); + mxList->addAttribute("fo:page-width",sXML_CDATA, "8.5inch"); + mxList->addAttribute("fo:page-height",sXML_CDATA, "11inch"); } break; case 5: // B5 if( hwpinfo.paper.paper_direction ) { - padd("fo:page-height",sXML_CDATA, "176mm"); - padd("fo:page-width",sXML_CDATA, "250mm"); + mxList->addAttribute("fo:page-height",sXML_CDATA, "176mm"); + mxList->addAttribute("fo:page-width",sXML_CDATA, "250mm"); } else { - padd("fo:page-width",sXML_CDATA, "176mm"); - padd("fo:page-height",sXML_CDATA, "250mm"); + mxList->addAttribute("fo:page-width",sXML_CDATA, "176mm"); + mxList->addAttribute("fo:page-height",sXML_CDATA, "250mm"); } break; case 6: // B4 if( hwpinfo.paper.paper_direction ) { - padd("fo:page-height",sXML_CDATA, "250mm"); - padd("fo:page-width",sXML_CDATA, "353mm"); + mxList->addAttribute("fo:page-height",sXML_CDATA, "250mm"); + mxList->addAttribute("fo:page-width",sXML_CDATA, "353mm"); } else { - padd("fo:page-width",sXML_CDATA, "250mm"); - padd("fo:page-height",sXML_CDATA, "353mm"); + mxList->addAttribute("fo:page-width",sXML_CDATA, "250mm"); + mxList->addAttribute("fo:page-height",sXML_CDATA, "353mm"); } break; case 7: if( hwpinfo.paper.paper_direction ) { - padd("fo:page-height",sXML_CDATA, "8.5inch"); - padd("fo:page-width",sXML_CDATA, "14inch"); + mxList->addAttribute("fo:page-height",sXML_CDATA, "8.5inch"); + mxList->addAttribute("fo:page-width",sXML_CDATA, "14inch"); } else { - padd("fo:page-width",sXML_CDATA, "8.5inch"); - padd("fo:page-height",sXML_CDATA, "14inch"); + mxList->addAttribute("fo:page-width",sXML_CDATA, "8.5inch"); + mxList->addAttribute("fo:page-height",sXML_CDATA, "14inch"); } break; case 8: if( hwpinfo.paper.paper_direction ) { - padd("fo:page-height",sXML_CDATA, "297mm"); - padd("fo:page-width",sXML_CDATA, "420mm"); + mxList->addAttribute("fo:page-height",sXML_CDATA, "297mm"); + mxList->addAttribute("fo:page-width",sXML_CDATA, "420mm"); } else { - padd("fo:page-width",sXML_CDATA, "297mm"); - padd("fo:page-height",sXML_CDATA, "420mm"); + mxList->addAttribute("fo:page-width",sXML_CDATA, "297mm"); + mxList->addAttribute("fo:page-height",sXML_CDATA, "420mm"); } break; case 0: @@ -1636,87 +1568,87 @@ void HwpReader::makePageStyle() default: if( hwpinfo.paper.paper_direction ) { - padd("fo:page-width",sXML_CDATA, - Double2Str(WTI(hwpinfo.paper.paper_height)) + "inch"); - padd("fo:page-height",sXML_CDATA, - Double2Str(WTI(hwpinfo.paper.paper_width)) + "inch"); + mxList->addAttribute("fo:page-width",sXML_CDATA, + OUString::number(WTI(hwpinfo.paper.paper_height)) + "inch"); + mxList->addAttribute("fo:page-height",sXML_CDATA, + OUString::number(WTI(hwpinfo.paper.paper_width)) + "inch"); } else { - padd("fo:page-width",sXML_CDATA, - Double2Str(WTI(hwpinfo.paper.paper_width)) + "inch"); - padd("fo:page-height",sXML_CDATA, - Double2Str(WTI(hwpinfo.paper.paper_height)) + "inch"); + mxList->addAttribute("fo:page-width",sXML_CDATA, + OUString::number(WTI(hwpinfo.paper.paper_width)) + "inch"); + mxList->addAttribute("fo:page-height",sXML_CDATA, + OUString::number(WTI(hwpinfo.paper.paper_height)) + "inch"); } break; } - padd("style:print-orientation",sXML_CDATA, - ascii(hwpinfo.paper.paper_direction ? "landscape" : "portrait")); + mxList->addAttribute("style:print-orientation",sXML_CDATA, + OUString::createFromAscii(hwpinfo.paper.paper_direction ? "landscape" : "portrait")); if( hwpinfo.beginpagenum != 1) - padd("style:first-page-number",sXML_CDATA, - ascii(Int2Str(hwpinfo.beginpagenum, "%d", buf))); + mxList->addAttribute("style:first-page-number",sXML_CDATA, OUString::number(hwpinfo.beginpagenum)); if( hwpinfo.borderline ){ - padd("fo:margin-left",sXML_CDATA, - Double2Str(WTI(hwpinfo.paper.left_margin - hwpinfo.bordermargin[0] + hwpinfo.paper.gutter_length)) + "inch"); - padd("fo:margin-right",sXML_CDATA, - Double2Str(WTI(hwpinfo.paper.right_margin - hwpinfo.bordermargin[1])) + "inch"); - padd("fo:margin-top",sXML_CDATA, - Double2Str(WTI(hwpinfo.paper.top_margin - hwpinfo.bordermargin[2])) + "inch"); - padd("fo:margin-bottom",sXML_CDATA, - Double2Str(WTI(hwpinfo.paper.bottom_margin - hwpinfo.bordermargin[3])) + "inch"); + mxList->addAttribute("fo:margin-left",sXML_CDATA, + OUString::number(WTI(hwpinfo.paper.left_margin - hwpinfo.bordermargin[0] + hwpinfo.paper.gutter_length)) + "inch"); + mxList->addAttribute("fo:margin-right",sXML_CDATA, + OUString::number(WTI(hwpinfo.paper.right_margin - hwpinfo.bordermargin[1])) + "inch"); + mxList->addAttribute("fo:margin-top",sXML_CDATA, + OUString::number(WTI(hwpinfo.paper.top_margin - hwpinfo.bordermargin[2])) + "inch"); + mxList->addAttribute("fo:margin-bottom",sXML_CDATA, + OUString::number(WTI(hwpinfo.paper.bottom_margin - hwpinfo.bordermargin[3])) + "inch"); } else{ - padd("fo:margin-left",sXML_CDATA, - Double2Str(WTI(hwpinfo.paper.left_margin + hwpinfo.paper.gutter_length)) + "inch"); - padd("fo:margin-right",sXML_CDATA, - Double2Str(WTI(hwpinfo.paper.right_margin)) + "inch"); - padd("fo:margin-top",sXML_CDATA, - Double2Str(WTI(hwpinfo.paper.top_margin)) + "inch"); - padd("fo:margin-bottom",sXML_CDATA, - Double2Str(WTI(hwpinfo.paper.bottom_margin)) + "inch"); + mxList->addAttribute("fo:margin-left",sXML_CDATA, + OUString::number(WTI(hwpinfo.paper.left_margin + hwpinfo.paper.gutter_length)) + "inch"); + mxList->addAttribute("fo:margin-right",sXML_CDATA, + OUString::number(WTI(hwpinfo.paper.right_margin)) + "inch"); + mxList->addAttribute("fo:margin-top",sXML_CDATA, + OUString::number(WTI(hwpinfo.paper.top_margin)) + "inch"); + mxList->addAttribute("fo:margin-bottom",sXML_CDATA, + OUString::number(WTI(hwpinfo.paper.bottom_margin)) + "inch"); } switch( hwpinfo.borderline ) { case 1: - padd("fo:border", sXML_CDATA,"0.002cm solid #000000"); + mxList->addAttribute("fo:border", sXML_CDATA,"0.002cm solid #000000"); break; case 3: - padd("fo:border", sXML_CDATA,"0.002cm dotted #000000"); + mxList->addAttribute("fo:border", sXML_CDATA,"0.002cm dotted #000000"); break; case 2: - padd("fo:border", sXML_CDATA,"0.035cm solid #000000"); + mxList->addAttribute("fo:border", sXML_CDATA,"0.035cm solid #000000"); break; case 4: - padd("style:border-line-width", sXML_CDATA,"0.002cm 0.035cm 0.002cm"); - padd("fo:border", sXML_CDATA,"0.039cm double #000000"); + mxList->addAttribute("style:border-line-width", sXML_CDATA,"0.002cm 0.035cm 0.002cm"); + mxList->addAttribute("fo:border", sXML_CDATA,"0.039cm double #000000"); break; } - padd("fo:padding-left", sXML_CDATA, - Double2Str(WTI(hwpinfo.bordermargin[0])) + "inch"); - padd("fo:padding-right", sXML_CDATA, - Double2Str(WTI(hwpinfo.bordermargin[1])) + "inch"); - padd("fo:padding-top", sXML_CDATA, - Double2Str(WTI(hwpinfo.bordermargin[2])) + "inch"); - padd("fo:padding-bottom", sXML_CDATA, - Double2Str(WTI(hwpinfo.bordermargin[3])) + "inch"); + mxList->addAttribute("fo:padding-left", sXML_CDATA, + OUString::number(WTI(hwpinfo.bordermargin[0])) + "inch"); + mxList->addAttribute("fo:padding-right", sXML_CDATA, + OUString::number(WTI(hwpinfo.bordermargin[1])) + "inch"); + mxList->addAttribute("fo:padding-top", sXML_CDATA, + OUString::number(WTI(hwpinfo.bordermargin[2])) + "inch"); + mxList->addAttribute("fo:padding-bottom", sXML_CDATA, + OUString::number(WTI(hwpinfo.bordermargin[3])) + "inch"); /* background color */ if( hwpinfo.back_info.isset ) { if( hwpinfo.back_info.color[0] > 0 || hwpinfo.back_info.color[1] > 0 || hwpinfo.back_info.color[2] > 0 ){ - sprintf(buf,"#%02x%02x%02x",hwpinfo.back_info.color[0], - hwpinfo.back_info.color[1],hwpinfo.back_info.color[2] ); - padd("fo:background-color", sXML_CDATA, ascii(buf)); + mxList->addAttribute("fo:background-color", sXML_CDATA, + rgb2str(hwpinfo.back_info.color[0], + hwpinfo.back_info.color[1], + hwpinfo.back_info.color[2])); } } - rstartEl("style:properties",mxList); + startEl("style:properties"); mxList->clear(); /* background image */ @@ -1724,149 +1656,147 @@ void HwpReader::makePageStyle() { if( hwpinfo.back_info.type == 1 ){ #ifdef _WIN32 - padd("xlink:href", sXML_CDATA, - fromHcharStringToOUString(hstr2ucsstr(kstr2hstr(reinterpret_cast<uchar const *>(urltowin(hwpinfo.back_info.filename).c_str())).c_str()))); + mxList->addAttribute("xlink:href", sXML_CDATA, + hstr2OUString(kstr2hstr(reinterpret_cast<uchar const *>(urltowin(hwpinfo.back_info.filename).c_str())).c_str())); #else - padd("xlink:href", sXML_CDATA, - fromHcharStringToOUString(hstr2ucsstr(kstr2hstr( reinterpret_cast<uchar const *>(urltounix(hwpinfo.back_info.filename).c_str())).c_str()))); + mxList->addAttribute("xlink:href", sXML_CDATA, + hstr2OUString(kstr2hstr( reinterpret_cast<uchar const *>(urltounix(hwpinfo.back_info.filename).c_str())).c_str())); #endif - padd("xlink:type", sXML_CDATA, "simple"); - padd("xlink:actuate", sXML_CDATA, "onLoad"); + mxList->addAttribute("xlink:type", sXML_CDATA, "simple"); + mxList->addAttribute("xlink:actuate", sXML_CDATA, "onLoad"); } if( hwpinfo.back_info.flag >= 2) - padd("style:repeat", sXML_CDATA, "stretch"); + mxList->addAttribute("style:repeat", sXML_CDATA, "stretch"); else if( hwpinfo.back_info.flag == 1 ){ - padd("style:repeat", sXML_CDATA, "no-repeat"); - padd("style:position", sXML_CDATA, "center"); + mxList->addAttribute("style:repeat", sXML_CDATA, "no-repeat"); + mxList->addAttribute("style:position", sXML_CDATA, "center"); } - rstartEl("style:background-image",mxList); + startEl("style:background-image"); if( hwpinfo.back_info.type == 2 ){ - rstartEl("office:binary-data", mxList); + startEl("office:binary-data"); mxList->clear(); - std::shared_ptr<char> pStr(base64_encode_string(reinterpret_cast<unsigned char *>(hwpinfo.back_info.data.data()), hwpinfo.back_info.size ), Free<char>()); - rchars(ascii(pStr.get())); - rendEl("office:binary-data"); + chars(base64_encode_string(reinterpret_cast<unsigned char*>(hwpinfo.back_info.data.data()), hwpinfo.back_info.size)); + endEl("office:binary-data"); } - rendEl("style:background-image"); + endEl("style:background-image"); } makeColumns( hwpfile.GetColumnDef(i) ); - rendEl("style:properties"); + endEl("style:properties"); /* header style */ - rstartEl("style:header-style", mxList); - padd("svg:height", sXML_CDATA, - Double2Str(WTI(hwpinfo.paper.header_length)) + "inch"); - padd("fo:margin-bottom", sXML_CDATA, "0mm"); + startEl("style:header-style"); + mxList->addAttribute("svg:height", sXML_CDATA, + OUString::number(WTI(hwpinfo.paper.header_length)) + "inch"); + mxList->addAttribute("fo:margin-bottom", sXML_CDATA, "0mm"); - rstartEl("style:properties",mxList); + startEl("style:properties"); mxList->clear(); - rendEl("style:properties"); - rendEl("style:header-style"); + endEl("style:properties"); + endEl("style:header-style"); /* footer style */ - rstartEl("style:footer-style", mxList); - padd("svg:height", sXML_CDATA, - Double2Str(WTI(hwpinfo.paper.footer_length)) + "inch"); - padd("fo:margin-top", sXML_CDATA, "0mm"); - rstartEl("style:properties",mxList); + startEl("style:footer-style"); + mxList->addAttribute("svg:height", sXML_CDATA, + OUString::number(WTI(hwpinfo.paper.footer_length)) + "inch"); + mxList->addAttribute("fo:margin-top", sXML_CDATA, "0mm"); + startEl("style:properties"); mxList->clear(); - rendEl("style:properties"); - rendEl("style:footer-style"); + endEl("style:properties"); + endEl("style:footer-style"); /* Footnote style */ - rstartEl("style:page-layout-properties", mxList); + startEl("style:page-layout-properties"); - padd("style:distance-before-sep", sXML_CDATA, - Double2Str(WTI(hwpinfo.splinetext)) + "inch"); - padd("style:distance-after-sep", sXML_CDATA, - Double2Str(WTI(hwpinfo.splinefn)) + "inch"); - rstartEl("style:properties",mxList); + mxList->addAttribute("style:distance-before-sep", sXML_CDATA, + OUString::number(WTI(hwpinfo.splinetext)) + "inch"); + mxList->addAttribute("style:distance-after-sep", sXML_CDATA, + OUString::number(WTI(hwpinfo.splinefn)) + "inch"); + startEl("style:properties"); mxList->clear(); - rendEl("style:properties"); + endEl("style:properties"); if ( hwpinfo.fnlinetype == 2 ) - padd("style:width", sXML_CDATA, "15cm"); + mxList->addAttribute("style:width", sXML_CDATA, "15cm"); else if ( hwpinfo.fnlinetype == 1) - padd("style:width", sXML_CDATA, "2cm"); + mxList->addAttribute("style:width", sXML_CDATA, "2cm"); else if ( hwpinfo.fnlinetype == 3) - padd("style:width", sXML_CDATA, "0cm"); + mxList->addAttribute("style:width", sXML_CDATA, "0cm"); else - padd("style:width", sXML_CDATA, "5cm"); + mxList->addAttribute("style:width", sXML_CDATA, "5cm"); - rstartEl("style:footnote-sep",mxList); + startEl("style:footnote-sep"); mxList->clear(); - rendEl("style:footnote-sep"); + endEl("style:footnote-sep"); - rendEl("style:page-layout-properties"); + endEl("style:page-layout-properties"); - rendEl("style:page-master"); + endEl("style:page-master"); } } void HwpReader::makeColumns(ColumnDef const *coldef) { if( !coldef ) return; - padd("fo:column-count", sXML_CDATA, ascii(Int2Str(coldef->ncols, "%d", buf))); - rstartEl("style:columns",mxList); + mxList->addAttribute("fo:column-count", sXML_CDATA, OUString::number(coldef->ncols)); + startEl("style:columns"); mxList->clear(); if( coldef->separator != 0 ) { switch( coldef->separator ) { case 1: /* thin line */ - padd("style:width", sXML_CDATA, "0.02mm"); + mxList->addAttribute("style:width", sXML_CDATA, "0.02mm"); [[fallthrough]]; case 3: /* dotted line */ - padd("style:style", sXML_CDATA, "dotted"); - padd("style:width", sXML_CDATA, "0.02mm"); + mxList->addAttribute("style:style", sXML_CDATA, "dotted"); + mxList->addAttribute("style:width", sXML_CDATA, "0.02mm"); break; case 2: /* thick line */ case 4: /* double line */ - padd("style:width", sXML_CDATA, "0.35mm"); + mxList->addAttribute("style:width", sXML_CDATA, "0.35mm"); break; case 0: /* None */ default: - padd("style:style", sXML_CDATA, "none"); + mxList->addAttribute("style:style", sXML_CDATA, "none"); break; } - rstartEl("style:column-sep",mxList); + startEl("style:column-sep"); mxList->clear(); - rendEl("style:column-sep"); + endEl("style:column-sep"); } double spacing = WTI(coldef->spacing)/ 2. ; for(int ii = 0 ; ii < coldef->ncols ; ii++) { if( ii == 0 ) - padd("fo:margin-left", sXML_CDATA, "0mm"); + mxList->addAttribute("fo:margin-left", sXML_CDATA, "0mm"); else - padd("fo:margin-left", sXML_CDATA, - Double2Str( spacing) + "inch"); + mxList->addAttribute("fo:margin-left", sXML_CDATA, + OUString::number( spacing) + "inch"); if( ii == ( coldef->ncols -1) ) - padd("fo:margin-right", sXML_CDATA,"0mm"); + mxList->addAttribute("fo:margin-right", sXML_CDATA,"0mm"); else - padd("fo:margin-right", sXML_CDATA, - Double2Str( spacing) + "inch"); - rstartEl("style:column",mxList); + mxList->addAttribute("fo:margin-right", sXML_CDATA, + OUString::number( spacing) + "inch"); + startEl("style:column"); mxList->clear(); - rendEl("style:column"); + endEl("style:column"); } - rendEl("style:columns"); + endEl("style:columns"); } void HwpReader::makeTStyle(CharShape const * cshape) { - padd("style:name", sXML_CDATA, - ascii(Int2Str(cshape->index, "T%d", buf))); - padd("style:family", sXML_CDATA, "text"); - rstartEl("style:style", mxList); + mxList->addAttribute("style:name", sXML_CDATA, "T" + OUString::number(cshape->index)); + mxList->addAttribute("style:family", sXML_CDATA, "text"); + startEl("style:style"); mxList->clear(); parseCharShape(cshape); - rstartEl("style:properties", mxList); + startEl("style:properties"); mxList->clear(); - rendEl("style:properties"); - rendEl("style:style"); + endEl("style:properties"); + endEl("style:style"); } @@ -1875,63 +1805,68 @@ void HwpReader::makeTableStyle(Table *tbl) // table TxtBox *hbox = tbl->box; - padd("style:name", sXML_CDATA, - ascii(Int2Str(hbox->style.boxnum, "Table%d", buf))); - padd("style:family", sXML_CDATA,"table"); - rstartEl("style:style", mxList); + mxList->addAttribute("style:name", sXML_CDATA, "Table" + OUString::number(hbox->style.boxnum)); + mxList->addAttribute("style:family", sXML_CDATA,"table"); + startEl("style:style"); mxList->clear(); - padd("style:width", sXML_CDATA, - Double2Str(WTMM(hbox->box_xs)) + "mm"); - padd("table:align", sXML_CDATA,"left"); - padd("fo:keep-with-next", sXML_CDATA,"false"); - rstartEl("style:properties", mxList); + mxList->addAttribute("style:width", sXML_CDATA, + OUString::number(WTMM(hbox->box_xs)) + "mm"); + mxList->addAttribute("table:align", sXML_CDATA,"left"); + mxList->addAttribute("fo:keep-with-next", sXML_CDATA,"false"); + startEl("style:properties"); mxList->clear(); - rendEl("style:properties"); - rendEl("style:style"); + endEl("style:properties"); + endEl("style:style"); // column for (size_t i = 0 ; i < tbl->columns.nCount -1 ; i++) { - sprintf(buf,"Table%d.%c",hbox->style.boxnum, static_cast<char>('A'+i)); - padd("style:name", sXML_CDATA, ascii( buf )); - padd("style:family", sXML_CDATA,"table-column"); - rstartEl("style:style", mxList); + mxList->addAttribute( + "style:name", sXML_CDATA, + "Table" + OUString::number(hbox->style.boxnum) + "." + + OUStringChar(static_cast<char>('A'+i))); + mxList->addAttribute("style:family", sXML_CDATA,"table-column"); + startEl("style:style"); mxList->clear(); - padd("style:column-width", sXML_CDATA, - Double2Str(WTMM(tbl->columns.data[i+1] - tbl->columns.data[i])) + "mm"); - rstartEl("style:properties", mxList); + mxList->addAttribute("style:column-width", sXML_CDATA, + OUString::number(WTMM(tbl->columns.data[i+1] - tbl->columns.data[i])) + "mm"); + startEl("style:properties"); mxList->clear(); - rendEl("style:properties"); - rendEl("style:style"); + endEl("style:properties"); + endEl("style:style"); } // row for (size_t i = 0 ; i < tbl->rows.nCount -1 ; i++) { - sprintf(buf,"Table%d.row%" SAL_PRI_SIZET "u",hbox->style.boxnum, i + 1); - padd("style:name", sXML_CDATA, ascii( buf )); - padd("style:family", sXML_CDATA,"table-row"); - rstartEl("style:style", mxList); + mxList->addAttribute( + "style:name", sXML_CDATA, + "Table" + OUString::number(hbox->style.boxnum) + ".row" + OUString::number(i + 1)); + mxList->addAttribute("style:family", sXML_CDATA,"table-row"); + startEl("style:style"); mxList->clear(); - padd("style:row-height", sXML_CDATA, - Double2Str(WTMM(tbl->rows.data[i+1] - tbl->rows.data[i])) + "mm"); - rstartEl("style:properties", mxList); + mxList->addAttribute("style:row-height", sXML_CDATA, + OUString::number(WTMM(tbl->rows.data[i+1] - tbl->rows.data[i])) + "mm"); + startEl("style:properties"); mxList->clear(); - rendEl("style:properties"); - rendEl("style:style"); + endEl("style:properties"); + endEl("style:style"); } // cell for (auto const& tcell : tbl->cells) { - sprintf(buf,"Table%d.%c%d",hbox->style.boxnum, 'A'+ tcell->nColumnIndex, tcell->nRowIndex +1); - padd("style:name", sXML_CDATA, ascii( buf )); - padd("style:family", sXML_CDATA,"table-cell"); - rstartEl("style:style", mxList); + mxList->addAttribute( + "style:name", sXML_CDATA, + "Table" + OUString::number(hbox->style.boxnum) + "." + + OUStringChar(char('A'+ tcell->nColumnIndex)) + + OUString::number(tcell->nRowIndex +1)); + mxList->addAttribute("style:family", sXML_CDATA,"table-cell"); + startEl("style:style"); mxList->clear(); Cell *cl = tcell->pCell; if( cl->ver_align == 1 ) - padd("fo:vertical-align", sXML_CDATA,"middle"); + mxList->addAttribute("fo:vertical-align", sXML_CDATA,"middle"); if(cl->linetype[2] == cl->linetype[3] && cl->linetype[2] == cl->linetype[0] && cl->linetype[2] == cl->linetype[1]) @@ -1940,14 +1875,14 @@ void HwpReader::makeTableStyle(Table *tbl) { case 1: /* A thin solid line */ case 3: /* Dotted line -> LibreOffice, there is no dotted line */ - padd("fo:border", sXML_CDATA,"0.002cm solid #000000"); + mxList->addAttribute("fo:border", sXML_CDATA,"0.002cm solid #000000"); break; case 2: /* Bold lines */ - padd("fo:border", sXML_CDATA,"0.035cm solid #000000"); + mxList->addAttribute("fo:border", sXML_CDATA,"0.035cm solid #000000"); break; case 4: /* Double line */ - padd("style:border-line-width", sXML_CDATA,"0.002cm 0.035cm 0.002cm"); - padd("fo:border", sXML_CDATA,"0.039cm double #000000"); + mxList->addAttribute("style:border-line-width", sXML_CDATA,"0.002cm 0.035cm 0.002cm"); + mxList->addAttribute("fo:border", sXML_CDATA,"0.039cm double #000000"); break; } } @@ -1957,69 +1892,69 @@ void HwpReader::makeTableStyle(Table *tbl) { case 1: /* A thin solid line */ case 3: /* Dotted line -> LibreOffice, there is no dotted line */ - padd("fo:border-left", sXML_CDATA,"0.002cm solid #000000"); + mxList->addAttribute("fo:border-left", sXML_CDATA,"0.002cm solid #000000"); break; case 2: /* Bold lines */ - padd("fo:border-left", sXML_CDATA,"0.035cm solid #000000"); + mxList->addAttribute("fo:border-left", sXML_CDATA,"0.035cm solid #000000"); break; case 4: /* Double line */ - padd("style:border-line-width-left", sXML_CDATA,"0.002cm 0.035cm 0.002cm"); - padd("fo:border-left", sXML_CDATA,"0.039cm double #000000"); + mxList->addAttribute("style:border-line-width-left", sXML_CDATA,"0.002cm 0.035cm 0.002cm"); + mxList->addAttribute("fo:border-left", sXML_CDATA,"0.039cm double #000000"); break; } switch( cl->linetype[1] ) { case 1: /* A thin solid line */ case 3: /* Dotted line -> LibreOffice, there is no dotted line */ - padd("fo:border-right", sXML_CDATA,"0.002cm solid #000000"); + mxList->addAttribute("fo:border-right", sXML_CDATA,"0.002cm solid #000000"); break; case 2: /* Bold lines */ - padd("fo:border-right", sXML_CDATA,"0.035cm solid #000000"); + mxList->addAttribute("fo:border-right", sXML_CDATA,"0.035cm solid #000000"); break; case 4: /* Double line */ - padd("style:border-line-width-right", sXML_CDATA,"0.002cm 0.035cm 0.002cm"); - padd("fo:border-right", sXML_CDATA,"0.039cm double #000000"); + mxList->addAttribute("style:border-line-width-right", sXML_CDATA,"0.002cm 0.035cm 0.002cm"); + mxList->addAttribute("fo:border-right", sXML_CDATA,"0.039cm double #000000"); break; } switch( cl->linetype[2] ) { case 1: /* A thin solid line */ case 3: /* Dotted line -> LibreOffice, there is no dotted line */ - padd("fo:border-top", sXML_CDATA,"0.002cm solid #000000"); + mxList->addAttribute("fo:border-top", sXML_CDATA,"0.002cm solid #000000"); break; case 2: /* Bold lines */ - padd("fo:border-top", sXML_CDATA,"0.035cm solid #000000"); + mxList->addAttribute("fo:border-top", sXML_CDATA,"0.035cm solid #000000"); break; case 4: /* Double line */ - padd("style:border-line-width-top", sXML_CDATA,"0.002cm 0.035cm 0.002cm"); - padd("fo:border-top", sXML_CDATA,"0.039cm double #000000"); + mxList->addAttribute("style:border-line-width-top", sXML_CDATA,"0.002cm 0.035cm 0.002cm"); + mxList->addAttribute("fo:border-top", sXML_CDATA,"0.039cm double #000000"); break; } switch( cl->linetype[3] ) { case 1: /* A thin solid line */ case 3: /* Dotted line -> LibreOffice, there is no dotted line */ - padd("fo:border-bottom", sXML_CDATA,"0.002cm solid #000000"); + mxList->addAttribute("fo:border-bottom", sXML_CDATA,"0.002cm solid #000000"); break; case 2: /* Bold lines */ - padd("fo:border-bottom", sXML_CDATA,"0.035cm solid #000000"); + mxList->addAttribute("fo:border-bottom", sXML_CDATA,"0.035cm solid #000000"); break; case 4: /* Double line */ - padd("style:border-line-width-bottom", sXML_CDATA,"0.002cm 0.035cm 0.002cm"); - padd("fo:border-bottom", sXML_CDATA,"0.039cm double #000000"); + mxList->addAttribute("style:border-line-width-bottom", sXML_CDATA,"0.002cm 0.035cm 0.002cm"); + mxList->addAttribute("fo:border-bottom", sXML_CDATA,"0.039cm double #000000"); break; } } if(cl->shade != 0) - padd("fo:background-color", sXML_CDATA, - ascii(hcolor2str(sal::static_int_cast<uchar>(cl->color), - sal::static_int_cast<uchar>(cl->shade), buf))); + mxList->addAttribute("fo:background-color", sXML_CDATA, + hcolor2str(sal::static_int_cast<uchar>(cl->color), + sal::static_int_cast<uchar>(cl->shade))); - rstartEl("style:properties", mxList); + startEl("style:properties"); mxList->clear(); - rendEl("style:properties"); + endEl("style:properties"); - rendEl("style:style"); + endEl("style:style"); } } @@ -2028,11 +1963,10 @@ void HwpReader::makeDrawStyle( HWPDrawingObject * hdo, FBoxStyle * fstyle) { while( hdo ) { - padd("style:name", sXML_CDATA, - ascii(Int2Str(hdo->index, "Draw%d", buf))); - padd("style:family", sXML_CDATA, "graphics"); + mxList->addAttribute("style:name", sXML_CDATA, "Draw" + OUString::number(hdo->index)); + mxList->addAttribute("style:family", sXML_CDATA, "graphics"); - rstartEl("style:style", mxList); + startEl("style:style"); mxList->clear(); switch (fstyle->txtflow) @@ -2040,83 +1974,80 @@ void HwpReader::makeDrawStyle( HWPDrawingObject * hdo, FBoxStyle * fstyle) case 0: break; case 1: - padd("style:wrap", sXML_CDATA, "run-through"); + mxList->addAttribute("style:wrap", sXML_CDATA, "run-through"); break; case 2: - padd("style:wrap", sXML_CDATA, "dynamic"); + mxList->addAttribute("style:wrap", sXML_CDATA, "dynamic"); break; } tools::Long color; // invisible line if( hdo->property.line_color > 0xffffff ) { - padd("draw:stroke", sXML_CDATA, "none" ); + mxList->addAttribute("draw:stroke", sXML_CDATA, "none" ); } else { if( hdo->property.line_pstyle == 0 ) - padd("draw:stroke", sXML_CDATA, "solid" ); + mxList->addAttribute("draw:stroke", sXML_CDATA, "solid" ); else if( hdo->property.line_pstyle < 5 ) { - padd("draw:stroke", sXML_CDATA, "dash" ); - padd("draw:stroke-dash", sXML_CDATA, - ascii(Int2Str(hdo->index, "LineType%d", buf))); + mxList->addAttribute("draw:stroke", sXML_CDATA, "dash" ); + mxList->addAttribute("draw:stroke-dash", sXML_CDATA, "LineType" + OUString::number(hdo->index)); } - padd("svg:stroke-width", sXML_CDATA, - Double2Str( WTMM(hdo->property.line_width)) + "mm"); - color = hdo->property.line_color; - sprintf( buf, "#%02x%02x%02x", - sal_uInt16(color & 0xff), - sal_uInt16((color >> 8) & 0xff), - sal_uInt16((color >>16) & 0xff) ); - padd("svg:stroke-color", sXML_CDATA, ascii( buf) ); + mxList->addAttribute("svg:stroke-width", sXML_CDATA, + OUString::number( WTMM(hdo->property.line_width)) + "mm"); + mxList->addAttribute("svg:stroke-color", sXML_CDATA, + rgb2str(static_cast<int32_t>(hdo->property.line_color))); } if( hdo->type == HWPDO_LINE || hdo->type == HWPDO_ARC || hdo->type == HWPDO_FREEFORM || hdo->type == HWPDO_ADVANCED_ARC ) { - if( hdo->property.line_tstyle > 0 ) + if( hdo->property.line_tstyle > 0 && + o3tl::make_unsigned(hdo->property.line_tstyle) < std::size(ArrowShape) ) { - padd("draw:marker-start", sXML_CDATA, - ascii(ArrowShape[hdo->property.line_tstyle].name) ); + mxList->addAttribute("draw:marker-start", sXML_CDATA, + OUString::createFromAscii(ArrowShape[hdo->property.line_tstyle].name) ); if( hdo->property.line_width > 100 ) - padd("draw:marker-start-width", sXML_CDATA, - Double2Str( WTMM(hdo->property.line_width * 3)) + "mm"); + mxList->addAttribute("draw:marker-start-width", sXML_CDATA, + OUString::number( WTMM(hdo->property.line_width * 3)) + "mm"); else if( hdo->property.line_width > 80 ) - padd("draw:marker-start-width", sXML_CDATA, - Double2Str( WTMM(hdo->property.line_width * 4)) + "mm"); + mxList->addAttribute("draw:marker-start-width", sXML_CDATA, + OUString::number( WTMM(hdo->property.line_width * 4)) + "mm"); else if( hdo->property.line_width > 60 ) - padd("draw:marker-start-width", sXML_CDATA, - Double2Str( WTMM(hdo->property.line_width * 5)) + "mm"); + mxList->addAttribute("draw:marker-start-width", sXML_CDATA, + OUString::number( WTMM(hdo->property.line_width * 5)) + "mm"); else if( hdo->property.line_width > 40 ) - padd("draw:marker-start-width", sXML_CDATA, - Double2Str( WTMM(hdo->property.line_width * 6)) + "mm"); + mxList->addAttribute("draw:marker-start-width", sXML_CDATA, + OUString::number( WTMM(hdo->property.line_width * 6)) + "mm"); else - padd("draw:marker-start-width", sXML_CDATA, - Double2Str( WTMM(hdo->property.line_width * 7)) + "mm"); + mxList->addAttribute("draw:marker-start-width", sXML_CDATA, + OUString::number( WTMM(hdo->property.line_width * 7)) + "mm"); } - if( hdo->property.line_hstyle > 0 ) + if( hdo->property.line_hstyle > 0 && + o3tl::make_unsigned(hdo->property.line_hstyle) < std::size(ArrowShape) ) { - padd("draw:marker-end", sXML_CDATA, - ascii(ArrowShape[hdo->property.line_hstyle].name) ); + mxList->addAttribute("draw:marker-end", sXML_CDATA, + OUString::createFromAscii(ArrowShape[hdo->property.line_hstyle].name) ); if( hdo->property.line_width > 100 ) - padd("draw:marker-end-width", sXML_CDATA, - Double2Str( WTMM(hdo->property.line_width * 3)) + "mm"); + mxList->addAttribute("draw:marker-end-width", sXML_CDATA, + OUString::number( WTMM(hdo->property.line_width * 3)) + "mm"); else if( hdo->property.line_width > 80 ) - padd("draw:marker-end-width", sXML_CDATA, - Double2Str( WTMM(hdo->property.line_width * 4)) + "mm"); + mxList->addAttribute("draw:marker-end-width", sXML_CDATA, + OUString::number( WTMM(hdo->property.line_width * 4)) + "mm"); else if( hdo->property.line_width > 60 ) - padd("draw:marker-end-width", sXML_CDATA, - Double2Str( WTMM(hdo->property.line_width * 5)) + "mm"); + mxList->addAttribute("draw:marker-end-width", sXML_CDATA, + OUString::number( WTMM(hdo->property.line_width * 5)) + "mm"); else if( hdo->property.line_width > 40 ) - padd("draw:marker-end-width", sXML_CDATA, - Double2Str( WTMM(hdo->property.line_width * 6)) + "mm"); + mxList->addAttribute("draw:marker-end-width", sXML_CDATA, + OUString::number( WTMM(hdo->property.line_width * 6)) + "mm"); else - padd("draw:marker-end-width", sXML_CDATA, - Double2Str( WTMM(hdo->property.line_width * 7)) + "mm"); + mxList->addAttribute("draw:marker-end-width", sXML_CDATA, + OUString::number( WTMM(hdo->property.line_width * 7)) + "mm"); } } @@ -2124,32 +2055,32 @@ void HwpReader::makeDrawStyle( HWPDrawingObject * hdo, FBoxStyle * fstyle) { if( hdo->property.flag >> 19 & 0x01 ) { - padd( "draw:textarea-horizontal-align", sXML_CDATA, "center"); + mxList->addAttribute( "draw:textarea-horizontal-align", sXML_CDATA, "center"); } color = hdo->property.fill_color; if( hdo->property.flag >> 18 & 0x01 ) // bitmap pattern { - padd("draw:fill", sXML_CDATA, "bitmap"); - padd("draw:fill-image-name", sXML_CDATA, - ascii(Int2Str(hdo->index, "fillimage%d", buf))); + mxList->addAttribute("draw:fill", sXML_CDATA, "bitmap"); + mxList->addAttribute("draw:fill-image-name", sXML_CDATA, + "fillimage" + OUString::number(hdo->index)); // bitmap resizing if( hdo->property.flag >> 3 & 0x01 ) { - padd("style:repeat", sXML_CDATA, "stretch"); + mxList->addAttribute("style:repeat", sXML_CDATA, "stretch"); } else { - padd("style:repeat", sXML_CDATA, "repeat"); - padd("draw:fill-image-ref-point", sXML_CDATA, "top-left"); + mxList->addAttribute("style:repeat", sXML_CDATA, "repeat"); + mxList->addAttribute("draw:fill-image-ref-point", sXML_CDATA, "top-left"); } if( hdo->property.flag >> 20 & 0x01 ) { if( hdo->property.luminance > 0 ) { - padd("draw:transparency", sXML_CDATA, - ascii(Int2Str(hdo->property.luminance, "%d%%", buf))); + mxList->addAttribute("draw:transparency", sXML_CDATA, + OUString::number(hdo->property.luminance) + "%"); } } @@ -2157,52 +2088,43 @@ void HwpReader::makeDrawStyle( HWPDrawingObject * hdo, FBoxStyle * fstyle) // Gradation else if( hdo->property.flag >> 16 & 0x01 ) { - padd("draw:fill", sXML_CDATA, "gradient"); - padd("draw:fill-gradient-name", sXML_CDATA, - ascii(Int2Str(hdo->index, "Grad%d", buf))); - padd("draw:gradient-step-count", sXML_CDATA, - ascii(Int2Str(hdo->property.nstep, "%d", buf))); + mxList->addAttribute("draw:fill", sXML_CDATA, "gradient"); + mxList->addAttribute("draw:fill-gradient-name", sXML_CDATA, "Grad" + OUString::number(hdo->index)); + mxList->addAttribute("draw:gradient-step-count", sXML_CDATA, OUString::number(hdo->property.nstep)); } // Hatching else if( hdo->property.pattern_type >> 24 & 0x01 ) { - padd("draw:fill", sXML_CDATA, "hatch"); - padd("draw:fill-hatch-name", sXML_CDATA, - ascii(Int2Str(hdo->index, "Hatch%d", buf))); + mxList->addAttribute("draw:fill", sXML_CDATA, "hatch"); + mxList->addAttribute("draw:fill-hatch-name", sXML_CDATA, "Hatch" + OUString::number(hdo->index)); if( color < 0xffffff ) { - sprintf( buf, "#%02x%02x%02x", - sal_uInt16(color & 0xff), - sal_uInt16((color >> 8) & 0xff), - sal_uInt16((color >>16) & 0xff) ); - padd("draw:fill-color", sXML_CDATA, ascii( buf) ); - padd("draw:fill-hatch-solid", sXML_CDATA, "true"); + mxList->addAttribute("draw:fill-color", sXML_CDATA, + rgb2str(static_cast<int32_t>(color))); + mxList->addAttribute("draw:fill-hatch-solid", sXML_CDATA, "true"); } } else if( color <= 0xffffff ) { - padd("draw:fill", sXML_CDATA, "solid"); - sprintf( buf, "#%02x%02x%02x", - sal_uInt16(color & 0xff), - sal_uInt16((color >> 8) & 0xff), - sal_uInt16((color >>16) & 0xff) ); - padd("draw:fill-color", sXML_CDATA, ascii( buf) ); + mxList->addAttribute("draw:fill", sXML_CDATA, "solid"); + mxList->addAttribute("draw:fill-color", sXML_CDATA, + rgb2str(static_cast<int32_t>(color))); } else - padd("draw:fill", sXML_CDATA, "none"); + mxList->addAttribute("draw:fill", sXML_CDATA, "none"); } if( fstyle->anchor_type == CHAR_ANCHOR ) { - padd("style:vertical-pos", sXML_CDATA, "top"); - padd("style:vertical-rel", sXML_CDATA, "baseline"); + mxList->addAttribute("style:vertical-pos", sXML_CDATA, "top"); + mxList->addAttribute("style:vertical-rel", sXML_CDATA, "baseline"); } - rstartEl("style:properties", mxList); + startEl("style:properties"); mxList->clear(); - rendEl("style:properties"); - rendEl("style:style"); + endEl("style:properties"); + endEl("style:style"); if( hdo->type == 0 ) { @@ -2215,36 +2137,35 @@ void HwpReader::makeDrawStyle( HWPDrawingObject * hdo, FBoxStyle * fstyle) void HwpReader::makeCaptionStyle(FBoxStyle * fstyle) { - padd("style:name", sXML_CDATA, - ascii(Int2Str(fstyle->boxnum, "CapBox%d", buf))); - padd("style:family", sXML_CDATA, "graphics"); - rstartEl("style:style", mxList); + mxList->addAttribute("style:name", sXML_CDATA, "CapBox" + OUString::number(fstyle->boxnum)); + mxList->addAttribute("style:family", sXML_CDATA, "graphics"); + startEl("style:style"); mxList->clear(); - padd("fo:margin-left", sXML_CDATA, "0cm"); - padd("fo:margin-right", sXML_CDATA, "0cm"); - padd("fo:margin-top", sXML_CDATA, "0cm"); - padd("fo:margin-bottom", sXML_CDATA, "0cm"); - padd("fo:padding", sXML_CDATA, "0cm"); + mxList->addAttribute("fo:margin-left", sXML_CDATA, "0cm"); + mxList->addAttribute("fo:margin-right", sXML_CDATA, "0cm"); + mxList->addAttribute("fo:margin-top", sXML_CDATA, "0cm"); + mxList->addAttribute("fo:margin-bottom", sXML_CDATA, "0cm"); + mxList->addAttribute("fo:padding", sXML_CDATA, "0cm"); switch (fstyle->txtflow) { case 0: - padd("style:wrap", sXML_CDATA, "none"); + mxList->addAttribute("style:wrap", sXML_CDATA, "none"); break; case 1: if( fstyle->boxtype == 'G' ) - padd("style:run-through", sXML_CDATA, "background"); - padd("style:wrap", sXML_CDATA, "run-through"); + mxList->addAttribute("style:run-through", sXML_CDATA, "background"); + mxList->addAttribute("style:wrap", sXML_CDATA, "run-through"); break; case 2: - padd("style:wrap", sXML_CDATA, "dynamic"); + mxList->addAttribute("style:wrap", sXML_CDATA, "dynamic"); break; } if (fstyle->anchor_type == CHAR_ANCHOR) { - padd("style:vertical-pos", sXML_CDATA, "top"); - padd("style:vertical-rel", sXML_CDATA, "baseline"); - padd("style:horizontal-pos", sXML_CDATA, "center"); - padd("style:horizontal-rel", sXML_CDATA, "paragraph"); + mxList->addAttribute("style:vertical-pos", sXML_CDATA, "top"); + mxList->addAttribute("style:vertical-rel", sXML_CDATA, "baseline"); + mxList->addAttribute("style:horizontal-pos", sXML_CDATA, "center"); + mxList->addAttribute("style:horizontal-rel", sXML_CDATA, "paragraph"); } else { @@ -2252,84 +2173,80 @@ void HwpReader::makeCaptionStyle(FBoxStyle * fstyle) switch (-(fstyle->xpos)) { case 2: - padd("style:horizontal-pos", sXML_CDATA, "right"); + mxList->addAttribute("style:horizontal-pos", sXML_CDATA, "right"); break; case 3: - padd("style:horizontal-pos", sXML_CDATA, "center"); + mxList->addAttribute("style:horizontal-pos", sXML_CDATA, "center"); break; case 1: default: - padd("style:horizontal-pos", sXML_CDATA, "from-left"); + mxList->addAttribute("style:horizontal-pos", sXML_CDATA, "from-left"); break; } switch (-(fstyle->ypos)) { case 2: - padd("style:vertical-pos", sXML_CDATA, "bottom"); + mxList->addAttribute("style:vertical-pos", sXML_CDATA, "bottom"); break; case 3: - padd("style:vertical-pos", sXML_CDATA, "middle"); + mxList->addAttribute("style:vertical-pos", sXML_CDATA, "middle"); break; case 1: default: - padd("style:vertical-pos", sXML_CDATA, "from-top"); + mxList->addAttribute("style:vertical-pos", sXML_CDATA, "from-top"); break; } if ( fstyle->anchor_type == PARA_ANCHOR ) { - padd("style:vertical-rel", sXML_CDATA, "paragraph"); - padd("style:horizontal-rel", sXML_CDATA, "paragraph"); + mxList->addAttribute("style:vertical-rel", sXML_CDATA, "paragraph"); + mxList->addAttribute("style:horizontal-rel", sXML_CDATA, "paragraph"); } else { - padd("style:vertical-rel", sXML_CDATA, "page-content"); - padd("style:horizontal-rel", sXML_CDATA, "page-content"); + mxList->addAttribute("style:vertical-rel", sXML_CDATA, "page-content"); + mxList->addAttribute("style:horizontal-rel", sXML_CDATA, "page-content"); } } - rstartEl("style:properties", mxList); + startEl("style:properties"); mxList->clear(); - rendEl("style:properties"); - rendEl("style:style"); + endEl("style:properties"); + endEl("style:style"); if( fstyle->boxtype == 'G' ) { - padd("style:name", sXML_CDATA, - ascii(Int2Str(fstyle->boxnum, "G%d", buf))); + mxList->addAttribute("style:name", sXML_CDATA, "G" + OUString::number(fstyle->boxnum)); } else { - padd("style:name", sXML_CDATA, - ascii(Int2Str(fstyle->boxnum, "Txtbox%d", buf))); + mxList->addAttribute("style:name", sXML_CDATA, "Txtbox" + OUString::number(fstyle->boxnum)); } - padd("style:family", sXML_CDATA, "graphics"); - rstartEl("style:style", mxList); + mxList->addAttribute("style:family", sXML_CDATA, "graphics"); + startEl("style:style"); mxList->clear(); - padd("fo:margin-left", sXML_CDATA, "0cm"); - padd("fo:margin-right", sXML_CDATA, "0cm"); - padd("fo:margin-top", sXML_CDATA, "0cm"); - padd("fo:margin-bottom", sXML_CDATA, "0cm"); - padd("fo:padding", sXML_CDATA, "0cm"); - padd("style:wrap", sXML_CDATA, "none"); - padd("style:vertical-pos", sXML_CDATA, "from-top"); - padd("style:vertical-rel", sXML_CDATA, "paragraph"); - padd("style:horizontal-pos", sXML_CDATA, "from-left"); - padd("style:horizontal-rel", sXML_CDATA, "paragraph"); - if( fstyle->boxtype == 'G' ) + mxList->addAttribute("fo:margin-left", sXML_CDATA, "0cm"); + mxList->addAttribute("fo:margin-right", sXML_CDATA, "0cm"); + mxList->addAttribute("fo:margin-top", sXML_CDATA, "0cm"); + mxList->addAttribute("fo:margin-bottom", sXML_CDATA, "0cm"); + mxList->addAttribute("fo:padding", sXML_CDATA, "0cm"); + mxList->addAttribute("style:wrap", sXML_CDATA, "none"); + mxList->addAttribute("style:vertical-pos", sXML_CDATA, "from-top"); + mxList->addAttribute("style:vertical-rel", sXML_CDATA, "paragraph"); + mxList->addAttribute("style:horizontal-pos", sXML_CDATA, "from-left"); + mxList->addAttribute("style:horizontal-rel", sXML_CDATA, "paragraph"); + if (fstyle->boxtype == 'G' && fstyle->cell) { char *cell = static_cast<char *>(fstyle->cell); - padd("draw:luminance", sXML_CDATA, - ascii(Int2Str(cell[0], "%d%%", buf))); - padd("draw:contrast", sXML_CDATA, - ascii(Int2Str(cell[1], "%d%%", buf))); + mxList->addAttribute("draw:luminance", sXML_CDATA, OUString::number(cell[0]) + "%"); + mxList->addAttribute("draw:contrast", sXML_CDATA, OUString::number(cell[1]) + "%"); if( cell[2] == 0 ) - padd("draw:color-mode", sXML_CDATA, "standard"); + mxList->addAttribute("draw:color-mode", sXML_CDATA, "standard"); else if( cell[2] == 1 ) - padd("draw:color-mode", sXML_CDATA, "greyscale"); + mxList->addAttribute("draw:color-mode", sXML_CDATA, "greyscale"); else if( cell[2] == 2 ) - padd("draw:color-mode", sXML_CDATA, "mono"); + mxList->addAttribute("draw:color-mode", sXML_CDATA, "mono"); } - else + else if (fstyle->cell) { Cell *cell = static_cast<Cell *>(fstyle->cell); if(cell->linetype[0] == cell->linetype[1] && @@ -2339,18 +2256,18 @@ void HwpReader::makeCaptionStyle(FBoxStyle * fstyle) switch( cell->linetype[0] ) { case 0: - padd("fo:padding", sXML_CDATA,"0mm"); + mxList->addAttribute("fo:padding", sXML_CDATA,"0mm"); break; case 1: /* A thin solid line */ case 3: /* Dotted line -> LibreOffice, there is no dotted line */ - padd("fo:border", sXML_CDATA,"0.002cm solid #000000"); + mxList->addAttribute("fo:border", sXML_CDATA,"0.002cm solid #000000"); break; case 2: /* Bold lines */ - padd("fo:border", sXML_CDATA,"0.035cm solid #000000"); + mxList->addAttribute("fo:border", sXML_CDATA,"0.035cm solid #000000"); break; case 4: /* Double line */ - padd("style:border-line-width", sXML_CDATA,"0.002cm 0.035cm 0.002cm"); - padd("fo:border", sXML_CDATA,"0.039cm double #000000"); + mxList->addAttribute("style:border-line-width", sXML_CDATA,"0.002cm 0.035cm 0.002cm"); + mxList->addAttribute("fo:border", sXML_CDATA,"0.039cm double #000000"); break; } } @@ -2360,68 +2277,68 @@ void HwpReader::makeCaptionStyle(FBoxStyle * fstyle) { case 1: /* A thin solid line */ case 3: /* Dotted line -> LibreOffice, there is no dotted line */ - padd("fo:border-left", sXML_CDATA,"0.002cm solid #000000"); + mxList->addAttribute("fo:border-left", sXML_CDATA,"0.002cm solid #000000"); break; case 2: /* Bold lines */ - padd("fo:border-left", sXML_CDATA,"0.035cm solid #000000"); + mxList->addAttribute("fo:border-left", sXML_CDATA,"0.035cm solid #000000"); break; case 4: /* Double line */ - padd("style:border-line-width-left", sXML_CDATA,"0.002cm 0.035cm 0.002cm"); - padd("fo:border-left", sXML_CDATA,"0.039cm double #000000"); + mxList->addAttribute("style:border-line-width-left", sXML_CDATA,"0.002cm 0.035cm 0.002cm"); + mxList->addAttribute("fo:border-left", sXML_CDATA,"0.039cm double #000000"); break; } switch( cell->linetype[1] ) { case 1: /* A thin solid line */ case 3: /* Dotted line -> LibreOffice, there is no dotted line */ - padd("fo:border-right", sXML_CDATA,"0.002cm solid #000000"); + mxList->addAttribute("fo:border-right", sXML_CDATA,"0.002cm solid #000000"); break; case 2: /* Bold lines */ - padd("fo:border-right", sXML_CDATA,"0.035cm solid #000000"); + mxList->addAttribute("fo:border-right", sXML_CDATA,"0.035cm solid #000000"); break; case 4: /* Double line */ - padd("style:border-line-width-right", sXML_CDATA,"0.002cm 0.035cm 0.002cm"); - padd("fo:border-right", sXML_CDATA,"0.039cm double #000000"); + mxList->addAttribute("style:border-line-width-right", sXML_CDATA,"0.002cm 0.035cm 0.002cm"); + mxList->addAttribute("fo:border-right", sXML_CDATA,"0.039cm double #000000"); break; } switch( cell->linetype[2] ) { case 1: /* A thin solid line */ case 3: /* Dotted line -> LibreOffice, there is no dotted line */ - padd("fo:border-top", sXML_CDATA,"0.002cm solid #000000"); + mxList->addAttribute("fo:border-top", sXML_CDATA,"0.002cm solid #000000"); break; case 2: /* Bold lines */ - padd("fo:border-top", sXML_CDATA,"0.035cm solid #000000"); + mxList->addAttribute("fo:border-top", sXML_CDATA,"0.035cm solid #000000"); break; case 4: /* Double line */ - padd("style:border-line-width-top", sXML_CDATA,"0.002cm 0.035cm 0.002cm"); - padd("fo:border-top", sXML_CDATA,"0.039cm double #000000"); + mxList->addAttribute("style:border-line-width-top", sXML_CDATA,"0.002cm 0.035cm 0.002cm"); + mxList->addAttribute("fo:border-top", sXML_CDATA,"0.039cm double #000000"); break; } switch( cell->linetype[3] ) { case 1: /* A thin solid line */ case 3: /* Dotted line -> LibreOffice, there is no dotted line */ - padd("fo:border-bottom", sXML_CDATA,"0.002cm solid #000000"); + mxList->addAttribute("fo:border-bottom", sXML_CDATA,"0.002cm solid #000000"); break; case 2: /* Bold lines */ - padd("fo:border-bottom", sXML_CDATA,"0.035cm solid #000000"); + mxList->addAttribute("fo:border-bottom", sXML_CDATA,"0.035cm solid #000000"); break; case 4: /* Double line */ - padd("style:border-line-width-bottom", sXML_CDATA,"0.002cm 0.035cm 0.002cm"); - padd("fo:border-bottom", sXML_CDATA,"0.039cm double #000000"); + mxList->addAttribute("style:border-line-width-bottom", sXML_CDATA,"0.002cm 0.035cm 0.002cm"); + mxList->addAttribute("fo:border-bottom", sXML_CDATA,"0.039cm double #000000"); break; } } if(cell->shade != 0) - padd("fo:background-color", sXML_CDATA, ascii(hcolor2str( + mxList->addAttribute("fo:background-color", sXML_CDATA, hcolor2str( sal::static_int_cast<uchar>(cell->color), - sal::static_int_cast<uchar>(cell->shade), buf))); + sal::static_int_cast<uchar>(cell->shade))); } - rstartEl("style:properties", mxList); + startEl("style:properties"); mxList->clear(); - rendEl("style:properties"); - rendEl("style:style"); + endEl("style:properties"); + endEl("style:style"); } @@ -2443,62 +2360,59 @@ void HwpReader::makeFStyle(FBoxStyle * fstyle) case 'B' : // button case 'O' : // other case 'T' : // table - padd("style:name", sXML_CDATA, - ascii(Int2Str(fstyle->boxnum, "Txtbox%d", buf))); - padd("style:family", sXML_CDATA, "graphics"); + mxList->addAttribute("style:name", sXML_CDATA, "Txtbox" + OUString::number(fstyle->boxnum)); + mxList->addAttribute("style:family", sXML_CDATA, "graphics"); break; case 'G' : // graphics - padd("style:name", sXML_CDATA, - ascii(Int2Str(fstyle->boxnum, "G%d", buf))); - padd("style:family", sXML_CDATA, "graphics"); + mxList->addAttribute("style:name", sXML_CDATA, "G" + OUString::number(fstyle->boxnum)); + mxList->addAttribute("style:family", sXML_CDATA, "graphics"); break; case 'L' : // line TODO : all - padd("style:name", sXML_CDATA, - ascii(Int2Str(fstyle->boxnum, "L%d", buf))); - padd( "style:family" , sXML_CDATA , "paragraph" ); + mxList->addAttribute("style:name", sXML_CDATA, "L" + OUString::number(fstyle->boxnum)); + mxList->addAttribute( "style:family" , sXML_CDATA , "paragraph" ); break; } - rstartEl("style:style", mxList); + startEl("style:style"); mxList->clear(); if ( fstyle->boxtype == 'T') { - padd("fo:padding", sXML_CDATA, "0cm"); + mxList->addAttribute("fo:padding", sXML_CDATA, "0cm"); } if( fstyle->boxtype != 'G' || fstyle->cap_len <= 0 ) { - padd("fo:margin-left", sXML_CDATA, - Double2Str(WTMM(fstyle->margin[0][0]) ) + "mm"); - padd("fo:margin-right", sXML_CDATA, - Double2Str(WTMM(fstyle->margin[0][1])) + "mm"); - padd("fo:margin-top", sXML_CDATA, - Double2Str(WTMM(fstyle->margin[0][2])) + "mm"); - padd("fo:margin-bottom", sXML_CDATA, - Double2Str(WTMM(fstyle->margin[0][3])) + "mm"); + mxList->addAttribute("fo:margin-left", sXML_CDATA, + OUString::number(WTMM(fstyle->margin[0][0]) ) + "mm"); + mxList->addAttribute("fo:margin-right", sXML_CDATA, + OUString::number(WTMM(fstyle->margin[0][1])) + "mm"); + mxList->addAttribute("fo:margin-top", sXML_CDATA, + OUString::number(WTMM(fstyle->margin[0][2])) + "mm"); + mxList->addAttribute("fo:margin-bottom", sXML_CDATA, + OUString::number(WTMM(fstyle->margin[0][3])) + "mm"); } switch (fstyle->txtflow) { case 0: - padd("style:wrap", sXML_CDATA, "none"); + mxList->addAttribute("style:wrap", sXML_CDATA, "none"); break; case 1: if( fstyle->boxtype == 'G' || fstyle->boxtype == 'B' || fstyle->boxtype == 'O') - padd("style:run-through", sXML_CDATA, "background"); - padd("style:wrap", sXML_CDATA, "run-through"); + mxList->addAttribute("style:run-through", sXML_CDATA, "background"); + mxList->addAttribute("style:wrap", sXML_CDATA, "run-through"); break; case 2: - padd("style:wrap", sXML_CDATA, "dynamic"); + mxList->addAttribute("style:wrap", sXML_CDATA, "dynamic"); break; } if (fstyle->anchor_type == CHAR_ANCHOR) { - padd("style:vertical-pos", sXML_CDATA, "top"); - padd("style:vertical-rel", sXML_CDATA, "baseline"); - padd("style:horizontal-pos", sXML_CDATA, "center"); - padd("style:horizontal-rel", sXML_CDATA, "paragraph"); + mxList->addAttribute("style:vertical-pos", sXML_CDATA, "top"); + mxList->addAttribute("style:vertical-rel", sXML_CDATA, "baseline"); + mxList->addAttribute("style:horizontal-pos", sXML_CDATA, "center"); + mxList->addAttribute("style:horizontal-rel", sXML_CDATA, "paragraph"); } else { @@ -2506,41 +2420,41 @@ void HwpReader::makeFStyle(FBoxStyle * fstyle) switch (-(fstyle->xpos)) { case 2: - padd("style:horizontal-pos", sXML_CDATA, "right"); + mxList->addAttribute("style:horizontal-pos", sXML_CDATA, "right"); break; case 3: - padd("style:horizontal-pos", sXML_CDATA, "center"); + mxList->addAttribute("style:horizontal-pos", sXML_CDATA, "center"); break; case 1: default: - padd("style:horizontal-pos", sXML_CDATA, "from-left"); + mxList->addAttribute("style:horizontal-pos", sXML_CDATA, "from-left"); break; } switch (-(fstyle->ypos)) { case 2: - padd("style:vertical-pos", sXML_CDATA, "bottom"); + mxList->addAttribute("style:vertical-pos", sXML_CDATA, "bottom"); break; case 3: - padd("style:vertical-pos", sXML_CDATA, "middle"); + mxList->addAttribute("style:vertical-pos", sXML_CDATA, "middle"); break; case 1: default: - padd("style:vertical-pos", sXML_CDATA, "from-top"); + mxList->addAttribute("style:vertical-pos", sXML_CDATA, "from-top"); break; } if ( fstyle->anchor_type == PARA_ANCHOR ) { - padd("style:vertical-rel", sXML_CDATA, "paragraph"); - padd("style:horizontal-rel", sXML_CDATA, "paragraph"); + mxList->addAttribute("style:vertical-rel", sXML_CDATA, "paragraph"); + mxList->addAttribute("style:horizontal-rel", sXML_CDATA, "paragraph"); } else { - padd("style:vertical-rel", sXML_CDATA, "page-content"); - padd("style:horizontal-rel", sXML_CDATA, "page-content"); + mxList->addAttribute("style:vertical-rel", sXML_CDATA, "page-content"); + mxList->addAttribute("style:horizontal-rel", sXML_CDATA, "page-content"); } } - if( fstyle->boxtype == 'X' || fstyle->boxtype == 'B' ) + if (fstyle->cell && (fstyle->boxtype == 'X' || fstyle->boxtype == 'B')) { Cell *cell = static_cast<Cell *>(fstyle->cell); if(cell->linetype[0] == cell->linetype[1] && @@ -2550,18 +2464,18 @@ void HwpReader::makeFStyle(FBoxStyle * fstyle) switch( cell->linetype[0] ) { case 0: - padd("fo:border", sXML_CDATA, "none"); + mxList->addAttribute("fo:border", sXML_CDATA, "none"); break; case 1: /* A thin solid line */ case 3: /* Dotted line -> LibreOffice, there is no dotted line */ - padd("fo:border", sXML_CDATA,"0.002cm solid #000000"); + mxList->addAttribute("fo:border", sXML_CDATA,"0.002cm solid #000000"); break; case 2: /* Bold lines */ - padd("fo:border", sXML_CDATA,"0.035cm solid #000000"); + mxList->addAttribute("fo:border", sXML_CDATA,"0.035cm solid #000000"); break; case 4: /* Double line */ - padd("style:border-line-width", sXML_CDATA,"0.002cm 0.035cm 0.002cm"); - padd("fo:border", sXML_CDATA,"0.039cm double #000000"); + mxList->addAttribute("style:border-line-width", sXML_CDATA,"0.002cm 0.035cm 0.002cm"); + mxList->addAttribute("fo:border", sXML_CDATA,"0.039cm double #000000"); break; } } @@ -2571,136 +2485,133 @@ void HwpReader::makeFStyle(FBoxStyle * fstyle) { case 1: /* A thin solid line */ case 3: /* Dotted line -> LibreOffice, there is no dotted line */ - padd("fo:border-left", sXML_CDATA,"0.002cm solid #000000"); + mxList->addAttribute("fo:border-left", sXML_CDATA,"0.002cm solid #000000"); break; case 2: /* Bold lines */ - padd("fo:border-left", sXML_CDATA,"0.035cm solid #000000"); + mxList->addAttribute("fo:border-left", sXML_CDATA,"0.035cm solid #000000"); break; case 4: /* Double line */ - padd("style:border-line-width-left", sXML_CDATA,"0.002cm 0.035cm 0.002cm"); - padd("fo:border-left", sXML_CDATA,"0.039cm double #000000"); + mxList->addAttribute("style:border-line-width-left", sXML_CDATA,"0.002cm 0.035cm 0.002cm"); + mxList->addAttribute("fo:border-left", sXML_CDATA,"0.039cm double #000000"); break; } switch( cell->linetype[1] ) { case 1: /* A thin solid line */ case 3: /* Dotted line -> LibreOffice, there is no dotted line */ - padd("fo:border-right", sXML_CDATA,"0.002cm solid #000000"); + mxList->addAttribute("fo:border-right", sXML_CDATA,"0.002cm solid #000000"); break; case 2: /* Bold lines */ - padd("fo:border-right", sXML_CDATA,"0.035cm solid #000000"); + mxList->addAttribute("fo:border-right", sXML_CDATA,"0.035cm solid #000000"); break; case 4: /* Double line */ - padd("style:border-line-width-right", sXML_CDATA,"0.002cm 0.035cm 0.002cm"); - padd("fo:border-right", sXML_CDATA,"0.039cm double #000000"); + mxList->addAttribute("style:border-line-width-right", sXML_CDATA,"0.002cm 0.035cm 0.002cm"); + mxList->addAttribute("fo:border-right", sXML_CDATA,"0.039cm double #000000"); break; } switch( cell->linetype[2] ) { case 1: /* A thin solid line */ case 3: /* Dotted line -> LibreOffice, there is no dotted line */ - padd("fo:border-top", sXML_CDATA,"0.002cm solid #000000"); + mxList->addAttribute("fo:border-top", sXML_CDATA,"0.002cm solid #000000"); break; case 2: /* Bold lines */ - padd("fo:border-top", sXML_CDATA,"0.035cm solid #000000"); + mxList->addAttribute("fo:border-top", sXML_CDATA,"0.035cm solid #000000"); break; case 4: /* Double line */ - padd("style:border-line-width-top", sXML_CDATA,"0.002cm 0.035cm 0.002cm"); - padd("fo:border-top", sXML_CDATA,"0.039cm double #000000"); + mxList->addAttribute("style:border-line-width-top", sXML_CDATA,"0.002cm 0.035cm 0.002cm"); + mxList->addAttribute("fo:border-top", sXML_CDATA,"0.039cm double #000000"); break; } switch( cell->linetype[3] ) { case 1: /* A thin solid line */ case 3: /* Dotted line -> LibreOffice, there is no dotted line */ - padd("fo:border-bottom", sXML_CDATA,"0.002cm solid #000000"); + mxList->addAttribute("fo:border-bottom", sXML_CDATA,"0.002cm solid #000000"); break; case 2: /* Bold lines */ - padd("fo:border-bottom", sXML_CDATA,"0.035cm solid #000000"); + mxList->addAttribute("fo:border-bottom", sXML_CDATA,"0.035cm solid #000000"); break; case 4: /* Double line */ - padd("style:border-line-width-bottom", sXML_CDATA,"0.002cm 0.035cm 0.002cm"); - padd("fo:border-bottom", sXML_CDATA,"0.039cm double #000000"); + mxList->addAttribute("style:border-line-width-bottom", sXML_CDATA,"0.002cm 0.035cm 0.002cm"); + mxList->addAttribute("fo:border-bottom", sXML_CDATA,"0.039cm double #000000"); break; } } if( cell->linetype[0] == 0 && cell->linetype[1] == 0 && cell->linetype[2] == 0 && cell->linetype[3] == 0 ){ - padd("fo:padding", sXML_CDATA,"0mm"); + mxList->addAttribute("fo:padding", sXML_CDATA,"0mm"); } else{ - padd("fo:padding-left", sXML_CDATA, - Double2Str(WTMM(fstyle->margin[1][0])) + "mm"); - padd("fo:padding-right", sXML_CDATA, - Double2Str(WTMM(fstyle->margin[1][1])) + "mm"); - padd("fo:padding-top", sXML_CDATA, - Double2Str(WTMM(fstyle->margin[1][2])) + "mm"); - padd("fo:padding-bottom", sXML_CDATA, - Double2Str(WTMM(fstyle->margin[1][3])) + "mm"); + mxList->addAttribute("fo:padding-left", sXML_CDATA, + OUString::number(WTMM(fstyle->margin[1][0])) + "mm"); + mxList->addAttribute("fo:padding-right", sXML_CDATA, + OUString::number(WTMM(fstyle->margin[1][1])) + "mm"); + mxList->addAttribute("fo:padding-top", sXML_CDATA, + OUString::number(WTMM(fstyle->margin[1][2])) + "mm"); + mxList->addAttribute("fo:padding-bottom", sXML_CDATA, + OUString::number(WTMM(fstyle->margin[1][3])) + "mm"); } if(cell->shade != 0) - padd("fo:background-color", sXML_CDATA, - ascii(hcolor2str( + mxList->addAttribute("fo:background-color", sXML_CDATA, + hcolor2str( sal::static_int_cast<uchar>(cell->color), - sal::static_int_cast<uchar>(cell->shade), - buf))); + sal::static_int_cast<uchar>(cell->shade))); } else if( fstyle->boxtype == 'E' ) { - padd("fo:padding", sXML_CDATA,"0mm"); + mxList->addAttribute("fo:padding", sXML_CDATA,"0mm"); } else if( fstyle->boxtype == 'L' ) { - padd( "style:border-line-width-bottom", sXML_CDATA, "0.02mm 0.35mm 0.02mm"); - padd("fo:border-bottom", sXML_CDATA,"0.039cm double #808080"); + mxList->addAttribute( "style:border-line-width-bottom", sXML_CDATA, "0.02mm 0.35mm 0.02mm"); + mxList->addAttribute("fo:border-bottom", sXML_CDATA,"0.039cm double #808080"); } - else if( fstyle->boxtype == 'G' ) + else if( fstyle->boxtype == 'G' && fstyle->cell ) { if( fstyle->margin[1][0] || fstyle->margin[1][1] || fstyle->margin[1][2] || fstyle->margin[1][3] ){ OUString clip = "rect(" + - Double2Str(WTMM(-fstyle->margin[1][0]) ) + "mm " + - Double2Str(WTMM(-fstyle->margin[1][1]) ) + "mm " + - Double2Str(WTMM(-fstyle->margin[1][2]) ) + "mm " + - Double2Str(WTMM(-fstyle->margin[1][3]) ) + "mm)"; - padd("style:mirror", sXML_CDATA, "none"); - padd("fo:clip", sXML_CDATA, clip); + OUString::number(WTMM(-fstyle->margin[1][0]) ) + "mm " + + OUString::number(WTMM(-fstyle->margin[1][1]) ) + "mm " + + OUString::number(WTMM(-fstyle->margin[1][2]) ) + "mm " + + OUString::number(WTMM(-fstyle->margin[1][3]) ) + "mm)"; + mxList->addAttribute("style:mirror", sXML_CDATA, "none"); + mxList->addAttribute("fo:clip", sXML_CDATA, clip); } char *cell = static_cast<char *>(fstyle->cell); - padd("draw:luminance", sXML_CDATA, - ascii(Int2Str(cell[0], "%d%%", buf))); - padd("draw:contrast", sXML_CDATA, - ascii(Int2Str(cell[1], "%d%%", buf))); + mxList->addAttribute("draw:luminance", sXML_CDATA, OUString::number(cell[0]) + "%"); + mxList->addAttribute("draw:contrast", sXML_CDATA, OUString::number(cell[1]) + "%"); if( cell[2] == 0 ) - padd("draw:color-mode", sXML_CDATA, "standard"); + mxList->addAttribute("draw:color-mode", sXML_CDATA, "standard"); else if( cell[2] == 1 ) - padd("draw:color-mode", sXML_CDATA, "greyscale"); + mxList->addAttribute("draw:color-mode", sXML_CDATA, "greyscale"); else if( cell[2] == 2 ) - padd("draw:color-mode", sXML_CDATA, "mono"); + mxList->addAttribute("draw:color-mode", sXML_CDATA, "mono"); } - rstartEl("style:properties", mxList); + startEl("style:properties"); mxList->clear(); - rendEl("style:properties"); - rendEl("style:style"); + endEl("style:properties"); + endEl("style:style"); } -char *HwpReader::getTStyleName(int index, char *_buf) +OUString HwpReader::getTStyleName(int index) { - return Int2Str(index, "T%d", _buf); + return "T" + OUString::number(index); } -char *HwpReader::getPStyleName(int index, char *_buf) +OUString HwpReader::getPStyleName(int index) { - return Int2Str(index, "P%d", _buf); + return "P" + OUString::number(index); } void HwpReader::makeChars(hchar_string & rStr) { - rchars(fromHcharStringToOUString(rStr)); + chars(fromHcharStringToOUString(rStr)); rStr.clear(); } @@ -2711,29 +2622,22 @@ void HwpReader::makeChars(hchar_string & rStr) void HwpReader::make_text_p0(HWPPara * para, bool bParaStart) { hchar_string str; - int n; int res; hchar dest[3]; unsigned char firstspace = 0; if( !bParaStart) { - padd("text:style-name", sXML_CDATA, - ascii(getPStyleName(para->GetParaShape().index, buf))); - rstartEl("text:p", mxList); + mxList->addAttribute("text:style-name", sXML_CDATA, + getPStyleName(para->GetParaShape().index)); + startEl("text:p"); mxList->clear(); } if( d->bFirstPara && d->bInBody ) { - strcpy( - buf, - "[\xEB\xAC\xB8\xEC\x84\x9C\xEC\x9D\x98 \xEC\xB2\x98\xEC\x9D\x8C]"); - // U+BB38 HANGUL SYLLABLE MUN, U+C11C HANGUL SYLLABLE SEO, - // U+C758 HANGUL SYLLABLE YI, U+CC98 HANGUL SYLLABLE CEO, - // U+C74C HANGUL SYLLABLE EUM: "Begin of Document" - padd("text:name", sXML_CDATA, OUString(buf, strlen(buf), RTL_TEXTENCODING_UTF8)); - rstartEl("text:bookmark", mxList); + mxList->addAttribute("text:name", sXML_CDATA, sBeginOfDoc); + startEl("text:bookmark"); mxList->clear(); - rendEl("text:bookmark"); + endEl("text:bookmark"); d->bFirstPara = false; } if( d->bInHeader ) @@ -2741,34 +2645,36 @@ void HwpReader::make_text_p0(HWPPara * para, bool bParaStart) makeShowPageNum(); d->bInHeader = false; } - padd("text:style-name", sXML_CDATA, - ascii(getTStyleName(para->cshape->index, buf))); - rstartEl("text:span", mxList); + mxList->addAttribute("text:style-name", sXML_CDATA, + getTStyleName(para->cshape->index)); + startEl("text:span"); mxList->clear(); - for (n = 0; n < para->nch && para->hhstr[n]->hh; - n += para->hhstr[n]->WSize()) + for (const auto& box : para->hhstr) { - if (para->hhstr[n]->hh == CH_SPACE && !firstspace) + if (!box->hh) + break; + + if (box->hh == CH_SPACE && !firstspace) { makeChars(str); - rstartEl("text:s", mxList); - rendEl("text:s"); + startEl("text:s"); + endEl("text:s"); } - else if (para->hhstr[n]->hh == CH_END_PARA) + else if (box->hh == CH_END_PARA) { makeChars(str); - rendEl("text:span"); - rendEl("text:p"); + endEl("text:span"); + endEl("text:p"); break; } else { - if (para->hhstr[n]->hh == CH_SPACE) + if (box->hh == CH_SPACE) firstspace = 0; else firstspace = 1; - res = hcharconv(para->hhstr[n]->hh, dest, UNICODE); + res = hcharconv(box->hh, dest, UNICODE); for( int j = 0 ; j < res; j++ ) { str.push_back(dest[j]); @@ -2784,7 +2690,6 @@ void HwpReader::make_text_p0(HWPPara * para, bool bParaStart) void HwpReader::make_text_p1(HWPPara * para,bool bParaStart) { hchar_string str; - int n; int res; hchar dest[3]; int curr = para->cshape->index; @@ -2792,24 +2697,18 @@ void HwpReader::make_text_p1(HWPPara * para,bool bParaStart) if( !bParaStart ) { - padd("text:style-name", sXML_CDATA, - ascii(getPStyleName(para->GetParaShape().index, buf))); - rstartEl("text:p", mxList); + mxList->addAttribute("text:style-name", sXML_CDATA, + getPStyleName(para->GetParaShape().index)); + startEl("text:p"); mxList->clear(); } if( d->bFirstPara && d->bInBody ) { /* for HWP's Bookmark */ - strcpy( - buf, - "[\xEB\xAC\xB8\xEC\x84\x9C\xEC\x9D\x98 \xEC\xB2\x98\xEC\x9D\x8C]"); - // U+BB38 HANGUL SYLLABLE MUN, U+C11C HANGUL SYLLABLE SEO, - // U+C758 HANGUL SYLLABLE YI, U+CC98 HANGUL SYLLABLE CEO, - // U+C74C HANGUL SYLLABLE EUM: "Begin of Document" - padd("text:name", sXML_CDATA, OUString(buf, strlen(buf), RTL_TEXTENCODING_UTF8)); - rstartEl("text:bookmark", mxList); + mxList->addAttribute("text:name", sXML_CDATA, sBeginOfDoc); + startEl("text:bookmark"); mxList->clear(); - rendEl("text:bookmark"); + endEl("text:bookmark"); d->bFirstPara = false; } if( d->bInHeader ) @@ -2817,51 +2716,55 @@ void HwpReader::make_text_p1(HWPPara * para,bool bParaStart) makeShowPageNum(); d->bInHeader = false; } - padd("text:style-name", sXML_CDATA, - ascii(getTStyleName(curr, buf))); - rstartEl("text:span", mxList); + mxList->addAttribute("text:style-name", sXML_CDATA, + getTStyleName(curr)); + startEl("text:span"); mxList->clear(); - for (n = 0; n < para->nch && para->hhstr[n]->hh; - n += para->hhstr[n]->WSize()) + int n = 0; + for (const auto& box : para->hhstr) { + if (!box->hh) + break; + if (para->GetCharShape(n)->index != curr) { makeChars(str); - rendEl("text:span"); + endEl("text:span"); curr = para->GetCharShape(n)->index; - padd("text:style-name", sXML_CDATA, - ascii(getTStyleName(curr, buf))); - rstartEl("text:span", mxList); + mxList->addAttribute("text:style-name", sXML_CDATA, + getTStyleName(curr)); + startEl("text:span"); mxList->clear(); } - if (para->hhstr[n]->hh == CH_SPACE && !firstspace) + if (box->hh == CH_SPACE && !firstspace) { makeChars(str); - rstartEl("text:s", mxList); - rendEl("text:s"); + startEl("text:s"); + endEl("text:s"); } - else if (para->hhstr[n]->hh == CH_END_PARA) + else if (box->hh == CH_END_PARA) { makeChars(str); - rendEl("text:span"); - rendEl("text:p"); + endEl("text:span"); + endEl("text:p"); break; } else { - if( para->hhstr[n]->hh < CH_SPACE ) + if( box->hh < CH_SPACE ) continue; - if (para->hhstr[n]->hh == CH_SPACE) + if (box->hh == CH_SPACE) firstspace = 0; else firstspace = 1; - res = hcharconv(para->hhstr[n]->hh, dest, UNICODE); + res = hcharconv(box->hh, dest, UNICODE); for( int j = 0 ; j < res; j++ ) { str.push_back(dest[j]); } } + n += box->WSize(); } } @@ -2872,96 +2775,120 @@ void HwpReader::make_text_p1(HWPPara * para,bool bParaStart) void HwpReader::make_text_p3(HWPPara * para,bool bParaStart) { hchar_string str; - int n, res; + int res; hchar dest[3]; unsigned char firstspace = 0; bool pstart = bParaStart; bool tstart = false; bool infield = false; - int curr; + + const auto STARTP = [this, para, &pstart]() + { + mxList->addAttribute("text:style-name", "CDATA", + getPStyleName(para->GetParaShape().index)); + startEl("text:p"); + mxList->clear(); + pstart = true; + }; + const auto STARTT = [this, para, &tstart](int pos) + { + auto curr = para->GetCharShape(pos > 0 ? pos - 1 : 0)->index; + mxList->addAttribute("text:style-name", "CDATA", getTStyleName(curr)); + startEl("text:span"); + mxList->clear(); + tstart = true; + }; + const auto ENDP = [this, &pstart]() + { + endEl("text:p"); + pstart = false; + }; + const auto ENDT = [this, &tstart]() + { + endEl("text:span"); + tstart = false; + }; + if( d->bFirstPara && d->bInBody ) { if ( !pstart ) { - STARTP; + STARTP(); } - strcpy( - buf, - "[\xEB\xAC\xB8\xEC\x84\x9C\xEC\x9D\x98 \xEC\xB2\x98\xEC\x9D\x8C]"); - // U+BB38 HANGUL SYLLABLE MUN, U+C11C HANGUL SYLLABLE SEO, - // U+C758 HANGUL SYLLABLE YI, U+CC98 HANGUL SYLLABLE CEO, - // U+C74C HANGUL SYLLABLE EUM: "Begin of Document" - padd("text:name", sXML_CDATA, OUString(buf, strlen(buf), RTL_TEXTENCODING_UTF8)); - rstartEl("text:bookmark", mxList); + mxList->addAttribute("text:name", sXML_CDATA, sBeginOfDoc); + startEl("text:bookmark"); mxList->clear(); - rendEl("text:bookmark"); + endEl("text:bookmark"); d->bFirstPara = false; } if( d->bInHeader ) { if ( !pstart ) { - STARTP; + STARTP(); } makeShowPageNum(); d->bInHeader = false; } - for (n = 0; n < para->nch && para->hhstr[n]->hh; - n += para->hhstr[n]->WSize()) + int n = 0; + for (const auto& box : para->hhstr) { - if( para->hhstr[n]->hh == CH_END_PARA ) + if (!box->hh) + break; + + if (box->hh == CH_END_PARA) { if (!str.empty()) { - if( !pstart ){ STARTP;} - if( !tstart ){ STARTT;} + if( !pstart ){ STARTP(); } + if( !tstart ){ STARTT(n);} makeChars(str); } - if( tstart ){ ENDT;} - if( !pstart ){ STARTP;} - if( pstart ){ ENDP;} + if( tstart ){ ENDT();} + if( !pstart ){ STARTP(); } + if( pstart ){ ENDP(); } break; } - else if( para->hhstr[n]->hh == CH_SPACE && !firstspace) + else if (box->hh == CH_SPACE && !firstspace) { - if( !pstart ) {STARTP;} - if( !tstart ) {STARTT;} + if( !pstart ) {STARTP(); } + if( !tstart ) {STARTT(n);} makeChars(str); - rstartEl("text:s", mxList); + startEl("text:s"); mxList->clear(); - rendEl("text:s"); + endEl("text:s"); } - else if ( para->hhstr[n]->hh >= CH_SPACE ) + else if (box->hh >= CH_SPACE) { if( n > 0 ) if( para->GetCharShape(n)->index != para->GetCharShape(n-1)->index && !infield ) { - if( !pstart ) {STARTP;} - if( !tstart ) {STARTT;} + if( !pstart ) {STARTP(); } + if( !tstart ) {STARTT(n);} makeChars(str); - ENDT; + ENDT(); } - if( para->hhstr[n]->hh == CH_SPACE ) + if (box->hh == CH_SPACE) firstspace = 0; else firstspace = 1; - res = hcharconv(para->hhstr[n]->hh, dest, UNICODE); + res = hcharconv(box->hh, dest, UNICODE); for( int j = 0 ; j < res; j++ ) { str.push_back(dest[j]); } } - else if (para->hhstr[n]->hh == CH_FIELD) + else if (box->hh == CH_FIELD) { - FieldCode *hbox = static_cast<FieldCode*>(para->hhstr[n].get()); + FieldCode *hbox = static_cast<FieldCode*>(box.get()); if( hbox->location_info == 1) { - if( !pstart ) {STARTP;} - if( !tstart ) {STARTT;} + if( !pstart ) {STARTP(); } + if( !tstart ) {STARTT(n);} makeChars(str); firstspace = 1; if( hbox->type[0] == 4 && hbox->type[1] == 0 ) { - field = hbox->str3.get(); + d->pField = hbox->str3.get(); } else{ makeFieldCode(str, hbox); @@ -2974,7 +2901,7 @@ void HwpReader::make_text_p3(HWPPara * para,bool bParaStart) if( hbox->type[0] == 4 && hbox->type[1] == 0 ) { makeFieldCode(str, hbox); - field = nullptr; + d->pField = nullptr; } infield = false; str.clear(); @@ -2982,27 +2909,27 @@ void HwpReader::make_text_p3(HWPPara * para,bool bParaStart) } else { - switch (para->hhstr[n]->hh) + switch (box->hh) { case CH_BOOKMARK: - if( !pstart ) {STARTP;} - if( !tstart ) {STARTT;} + if( !pstart ) {STARTP(); } + if( !tstart ) {STARTT(n);} makeChars(str); - makeBookmark(static_cast<Bookmark*>(para->hhstr[n].get())); + makeBookmark(static_cast<Bookmark*>(box.get())); break; case CH_DATE_FORM: // 7 break; case CH_DATE_CODE: // 8 - if( !pstart ) {STARTP;} - if( !tstart ) {STARTT;} + if( !pstart ) {STARTP(); } + if( !tstart ) {STARTT(n);} makeChars(str); - makeDateCode(static_cast<DateCode*>(para->hhstr[n].get())); + makeDateCode(static_cast<DateCode*>(box.get())); break; case CH_TAB: // 9 - if( !pstart ) {STARTP;} + if( !pstart ) {STARTP(); } if (!str.empty()) { - if( !tstart ) {STARTT;} + if( !tstart ) {STARTT(n);} makeChars(str); } makeTab(); @@ -3010,23 +2937,23 @@ void HwpReader::make_text_p3(HWPPara * para,bool bParaStart) case CH_TEXT_BOX: /* 10 - ordered by Table/text box/formula/button/hypertext */ { /* produce tables first, and treat formula as being in text:p. */ - TxtBox *hbox = static_cast<TxtBox*>(para->hhstr[n].get()); + TxtBox *hbox = static_cast<TxtBox*>(box.get()); if( hbox->style.anchor_type == 0 ) { - if( !pstart ) {STARTP;} - if( !tstart ) {STARTT;} + if( !pstart ) {STARTP(); } + if( !tstart ) {STARTT(n);} makeChars(str); } else { - if( !pstart ) {STARTP;} + if( !pstart ) {STARTP(); } if (!str.empty()) { - if( !tstart ) {STARTT;} + if( !tstart ) {STARTT(n);} makeChars(str); } - if( tstart ) {ENDT;} + if( tstart ) {ENDT();} } switch (hbox->type) { @@ -3044,22 +2971,22 @@ void HwpReader::make_text_p3(HWPPara * para,bool bParaStart) } case CH_PICTURE: // 11 { - Picture *hbox = static_cast<Picture*>(para->hhstr[n].get()); + Picture *hbox = static_cast<Picture*>(box.get()); if( hbox->style.anchor_type == 0 ) { - if( !pstart ) {STARTP;} - if( !tstart ) {STARTT;} + if( !pstart ) {STARTP(); } + if( !tstart ) {STARTT(n);} makeChars(str); } else { - if( !pstart ) {STARTP;} + if( !pstart ) {STARTP(); } if (!str.empty()) { - if( !tstart ) {STARTT;} + if( !tstart ) {STARTT(n);} makeChars(str); } - if( tstart ) {ENDT;} + if( tstart ) {ENDT();} } makePicture(hbox); break; @@ -3068,63 +2995,63 @@ void HwpReader::make_text_p3(HWPPara * para,bool bParaStart) { if (!str.empty()) { - if( !pstart ) {STARTP;} - if( !tstart ) {STARTT;} + if( !pstart ) {STARTP();} + if( !tstart ) {STARTT(n);} makeChars(str); } - if( tstart ) {ENDT;} - if( pstart ) {ENDP;} + if( tstart ) {ENDT();} + if( pstart ) {ENDP();} makeLine(); pstart = true; break; } case CH_HIDDEN: // 15 - if( !pstart ) {STARTP;} - if( !tstart ) {STARTT;} + if( !pstart ) {STARTP();} + if( !tstart ) {STARTT(n);} makeChars(str); - makeHidden(static_cast<Hidden*>(para->hhstr[n].get())); + makeHidden(static_cast<Hidden*>(box.get())); break; case CH_FOOTNOTE: // 17 - if( !pstart ) {STARTP;} - if( !tstart ) {STARTT;} + if( !pstart ) {STARTP();} + if( !tstart ) {STARTT(n);} makeChars(str); - makeFootnote(static_cast<Footnote*>(para->hhstr[n].get())); + makeFootnote(static_cast<Footnote*>(box.get())); break; case CH_AUTO_NUM: // 18 - if( !pstart ) {STARTP;} - if( !tstart ) {STARTT;} + if( !pstart ) {STARTP();} + if( !tstart ) {STARTT(n);} makeChars(str); - makeAutoNum(static_cast<AutoNum*>(para->hhstr[n].get())); + makeAutoNum(static_cast<AutoNum*>(box.get())); break; case CH_NEW_NUM: // 19 -skip break; case CH_PAGE_NUM_CTRL: // 21 break; case CH_MAIL_MERGE: // 22 - if( !pstart ) {STARTP;} - if( !tstart ) {STARTT;} + if( !pstart ) {STARTP();} + if( !tstart ) {STARTT(n);} makeChars(str); - makeMailMerge(static_cast<MailMerge*>(para->hhstr[n].get())); + makeMailMerge(static_cast<MailMerge*>(box.get())); break; case CH_COMPOSE: /* 23 - overlapping letters */ break; case CH_HYPHEN: // 24 break; case CH_TOC_MARK: /* 25 Need to fix below 3 */ - if( !pstart ) {STARTP;} - if( !tstart ) {STARTT;} + if( !pstart ) {STARTP();} + if( !tstart ) {STARTT(n);} makeChars(str); break; case CH_INDEX_MARK: // 26 - if( !pstart ) {STARTP;} - if( !tstart ) {STARTT;} + if( !pstart ) {STARTP();} + if( !tstart ) {STARTT(n);} makeChars(str); break; case CH_OUTLINE: // 28 - if( !pstart ) {STARTP;} - if( !tstart ) {STARTT;} + if( !pstart ) {STARTP();} + if( !tstart ) {STARTT(n);} makeChars(str); - makeOutline(static_cast<Outline *>(para->hhstr[n].get())); + makeOutline(static_cast<Outline *>(box.get())); break; case CH_FIXED_SPACE: case CH_KEEP_SPACE: @@ -3132,6 +3059,7 @@ void HwpReader::make_text_p3(HWPPara * para,bool bParaStart) break; } } + n += box->WSize(); } } @@ -3141,119 +3069,117 @@ void HwpReader::makeFieldCode(hchar_string const & rStr, FieldCode const *hbox) /* Push frame */ if( hbox->type[0] == 4 && hbox->type[1] == 0 ) { - padd("text:placeholder-type", sXML_CDATA, "text"); - if( field ) - padd("text:description", sXML_CDATA, fromHcharStringToOUString(hstr2ucsstr(field))); - rstartEl( "text:placeholder", mxList); + mxList->addAttribute("text:placeholder-type", sXML_CDATA, "text"); + if (d->pField) + mxList->addAttribute("text:description", sXML_CDATA, hstr2OUString(d->pField)); + startEl("text:placeholder"); mxList->clear(); - rchars( fromHcharStringToOUString(rStr) ); - rendEl( "text:placeholder" ); + chars( fromHcharStringToOUString(rStr) ); + endEl("text:placeholder"); } /* Document Summary */ else if( hbox->type[0] == 3 && hbox->type[1] == 0 ) { - if (reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3.get())) - == std::u16string_view(u"title")) + const OUString uStr3 = hstr2OUString(hbox->str3.get()); + if (uStr3 == "title") { - rstartEl( "text:title", mxList ); - rchars( fromHcharStringToOUString(hstr2ucsstr(hbox->str2.get())) ); - rendEl( "text:title" ); + startEl("text:title"); + chars( hstr2OUString(hbox->str2.get()) ); + endEl("text:title"); } - else if (reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3.get())) == std::u16string_view(u"subject")) + else if (uStr3 == "subject") { - rstartEl( "text:subject", mxList ); - rchars( fromHcharStringToOUString(hstr2ucsstr(hbox->str2.get())) ); - rendEl( "text:subject" ); + startEl("text:subject"); + chars( hstr2OUString(hbox->str2.get()) ); + endEl("text:subject"); } - else if (reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3.get())) == std::u16string_view(u"author")) + else if (uStr3 == "author") { - rstartEl( "text:author-name", mxList ); - rchars( fromHcharStringToOUString(hstr2ucsstr(hbox->str2.get())) ); - rendEl( "text:author-name" ); + startEl("text:author-name"); + chars( hstr2OUString(hbox->str2.get()) ); + endEl("text:author-name"); } - else if (reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3.get())) == std::u16string_view(u"keywords")) + else if (uStr3 == "keywords") { - rstartEl( "text:keywords", mxList ); - rchars( fromHcharStringToOUString(hstr2ucsstr(hbox->str2.get())) ); - rendEl( "text:keywords" ); + startEl("text:keywords"); + chars( hstr2OUString(hbox->str2.get()) ); + endEl("text:keywords"); } } /* Personal Information */ else if( hbox->type[0] == 3 && hbox->type[1] == 1 ) { - if (reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3.get())) - == std::u16string_view(u"User")) + const OUString uStr3 = hstr2OUString(hbox->str3.get()); + if (uStr3 == "User") { - rstartEl( "text:sender-lastname", mxList ); - rchars( fromHcharStringToOUString(hstr2ucsstr(hbox->str2.get())) ); - rendEl( "text:sender-lastname" ); + startEl("text:sender-lastname"); + chars( hstr2OUString(hbox->str2.get()) ); + endEl("text:sender-lastname"); } - else if (reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3.get())) == std::u16string_view(u"Company")) + else if (uStr3 == "Company") { - rstartEl( "text:sender-company", mxList ); - rchars( fromHcharStringToOUString(hstr2ucsstr(hbox->str2.get())) ); - rendEl( "text:sender-company" ); + startEl("text:sender-company"); + chars( hstr2OUString(hbox->str2.get()) ); + endEl("text:sender-company"); } - else if (reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3.get())) == std::u16string_view(u"Position")) + else if (uStr3 == "Position") { - rstartEl( "text:sender-title", mxList ); - rchars( fromHcharStringToOUString(hstr2ucsstr(hbox->str2.get())) ); - rendEl( "text:sender-title" ); + startEl("text:sender-title"); + chars( hstr2OUString(hbox->str2.get()) ); + endEl("text:sender-title"); } - else if (reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3.get())) == std::u16string_view(u"Division")) + else if (uStr3 == "Division") { - rstartEl( "text:sender-position", mxList ); - rchars( fromHcharStringToOUString(hstr2ucsstr(hbox->str2.get())) ); - rendEl( "text:sender-position" ); + startEl("text:sender-position"); + chars( hstr2OUString(hbox->str2.get()) ); + endEl("text:sender-position"); } - else if (reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3.get())) - == std::u16string_view(u"Fax")) + else if (uStr3 == "Fax") { - rstartEl( "text:sender-fax", mxList ); - rchars( fromHcharStringToOUString(hstr2ucsstr(hbox->str2.get())) ); - rendEl( "text:sender-fax" ); + startEl("text:sender-fax"); + chars( hstr2OUString(hbox->str2.get()) ); + endEl("text:sender-fax"); } - else if (reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3.get())) == std::u16string_view(u"Pager")) + else if (uStr3 == "Pager") { - rstartEl( "text:phone-private", mxList ); - rchars( fromHcharStringToOUString(hstr2ucsstr(hbox->str2.get())) ); - rendEl( "text:phone-private" ); + startEl("text:phone-private"); + chars( hstr2OUString(hbox->str2.get()) ); + endEl("text:phone-private"); } - else if (reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3.get())) == std::u16string_view(u"E-mail")) + else if (uStr3 == "E-mail") { - rstartEl( "text:sender-email", mxList ); - rchars( fromHcharStringToOUString(hstr2ucsstr(hbox->str2.get())) ); - rendEl( "text:sender-email" ); + startEl("text:sender-email"); + chars( hstr2OUString(hbox->str2.get()) ); + endEl("text:sender-email"); } - else if (reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3.get())) == std::u16string_view(u"Zipcode(office)")) + else if (uStr3 == "Zipcode(office)") { - rstartEl( "text:sender-postal-code", mxList ); - rchars( fromHcharStringToOUString(hstr2ucsstr(hbox->str2.get())) ); - rendEl( "text:sender-postal-code" ); + startEl("text:sender-postal-code"); + chars( hstr2OUString(hbox->str2.get()) ); + endEl("text:sender-postal-code"); } - else if (reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3.get())) == std::u16string_view(u"Phone(office)")) + else if (uStr3 == "Phone(office)") { - rstartEl( "text:sender-phone-work", mxList ); - rchars( fromHcharStringToOUString(hstr2ucsstr(hbox->str2.get())) ); - rendEl( "text:sender-phone-work" ); + startEl("text:sender-phone-work"); + chars( hstr2OUString(hbox->str2.get()) ); + endEl("text:sender-phone-work"); } - else if (reinterpret_cast<sal_Unicode const *>(hconv(hbox->str3.get())) == std::u16string_view(u"Address(office)")) + else if (uStr3 == "Address(office)") { - rstartEl( "text:sender-street", mxList ); - rchars( fromHcharStringToOUString(hstr2ucsstr(hbox->str2.get())) ); - rendEl( "text:sender-street" ); + startEl("text:sender-street"); + chars( hstr2OUString(hbox->str2.get()) ); + endEl("text:sender-street"); } } else if( hbox->type[0] == 3 && hbox->type[1] == 2 ) /* creation date */ { if( hbox->m_pDate ) - padd("style:data-style-name", sXML_CDATA, - ascii(Int2Str(hbox->m_pDate->key, "N%d", buf))); - rstartEl( "text:creation-date", mxList ); + mxList->addAttribute("style:data-style-name", sXML_CDATA, "N" + OUString::number(hbox->m_pDate->key)); + startEl("text:creation-date"); mxList->clear(); - rchars( fromHcharStringToOUString(hstr2ucsstr(hbox->str2.get())) ); - rendEl( "text:creation-date" ); + chars( hstr2OUString(hbox->str2.get()) ); + endEl("text:creation-date"); } } @@ -3266,37 +3192,36 @@ void HwpReader::makeBookmark(Bookmark const * hbox) { if (hbox->type == 0) { - padd("text:name", sXML_CDATA, fromHcharStringToOUString(hstr2ucsstr(hbox->id))); - rstartEl("text:bookmark", mxList); + mxList->addAttribute("text:name", sXML_CDATA, hstr2OUString(hbox->id)); + startEl("text:bookmark"); mxList->clear(); - rendEl("text:bookmark"); + endEl("text:bookmark"); } else if (hbox->type == 1) /* Block bookmarks days begin and end there if */ { - padd("text:name", sXML_CDATA, fromHcharStringToOUString(hstr2ucsstr(hbox->id))); - rstartEl("text:bookmark-start", mxList); + mxList->addAttribute("text:name", sXML_CDATA, hstr2OUString(hbox->id)); + startEl("text:bookmark-start"); mxList->clear(); - rendEl("text:bookmark-start"); + endEl("text:bookmark-start"); } else if (hbox->type == 2) { - padd("text:name", sXML_CDATA, fromHcharStringToOUString(hstr2ucsstr(hbox->id))); - rstartEl("text:bookmark-end", mxList); + mxList->addAttribute("text:name", sXML_CDATA, hstr2OUString(hbox->id)); + startEl("text:bookmark-end"); mxList->clear(); - rendEl("text:bookmark-end"); + endEl("text:bookmark-end"); } } void HwpReader::makeDateFormat(DateCode * hbox) { - padd("style:name", sXML_CDATA, - ascii(Int2Str(hbox->key, "N%d", buf))); - padd("style:family", sXML_CDATA,"data-style"); - padd("number:language", sXML_CDATA,"ko"); - padd("number:country", sXML_CDATA,"KR"); + mxList->addAttribute("style:name", sXML_CDATA, "N" + OUString::number(hbox->key)); + mxList->addAttribute("style:family", sXML_CDATA,"data-style"); + mxList->addAttribute("number:language", sXML_CDATA,"ko"); + mxList->addAttribute("number:country", sXML_CDATA,"KR"); - rstartEl("number:date-style", mxList); + startEl("number:date-style"); mxList->clear(); bool add_zero = false; @@ -3321,104 +3246,104 @@ void HwpReader::makeDateFormat(DateCode * hbox) add_zero = true; break; case '1': - padd("number:style", sXML_CDATA, "long"); - rstartEl("number:year", mxList); + mxList->addAttribute("number:style", sXML_CDATA, "long"); + startEl("number:year"); mxList->clear(); - rendEl("number:year"); + endEl("number:year"); break; case '!': - rstartEl("number:year", mxList); + startEl("number:year"); mxList->clear(); - rendEl("number:year"); + endEl("number:year"); break; case '2': if( add_zero ) - padd("number:style", sXML_CDATA, "long"); - rstartEl("number:month", mxList); + mxList->addAttribute("number:style", sXML_CDATA, "long"); + startEl("number:month"); mxList->clear(); - rendEl("number:month"); + endEl("number:month"); break; case '@': - padd("number:textual", sXML_CDATA, "true"); - rstartEl("number:month", mxList); + mxList->addAttribute("number:textual", sXML_CDATA, "true"); + startEl("number:month"); mxList->clear(); - rendEl("number:month"); + endEl("number:month"); break; case '*': - padd("number:textual", sXML_CDATA, "true"); - padd("number:style", sXML_CDATA, "long"); - rstartEl("number:month", mxList); + mxList->addAttribute("number:textual", sXML_CDATA, "true"); + mxList->addAttribute("number:style", sXML_CDATA, "long"); + startEl("number:month"); mxList->clear(); - rendEl("number:month"); + endEl("number:month"); break; case '3': if( add_zero ) - padd("number:style", sXML_CDATA, "long"); - rstartEl("number:day", mxList); + mxList->addAttribute("number:style", sXML_CDATA, "long"); + startEl("number:day"); mxList->clear(); - rendEl("number:day"); + endEl("number:day"); break; case '#': if( add_zero ) - padd("number:style", sXML_CDATA, "long"); - rstartEl("number:day", mxList); + mxList->addAttribute("number:style", sXML_CDATA, "long"); + startEl("number:day"); mxList->clear(); - rendEl("number:day"); + endEl("number:day"); switch( hbox->date[DateCode::DAY] % 10) { case 1: - rstartEl("number:text", mxList); - rchars("st"); - rendEl("number:text"); + startEl("number:text"); + chars("st"); + endEl("number:text"); break; case 2: - rstartEl("number:text", mxList); - rchars("nd"); - rendEl("number:text"); + startEl("number:text"); + chars("nd"); + endEl("number:text"); break; case 3: - rstartEl("number:text", mxList); - rchars("rd"); - rendEl("number:text"); + startEl("number:text"); + chars("rd"); + endEl("number:text"); break; default: - rstartEl("number:text", mxList); - rchars("th"); - rendEl("number:text"); + startEl("number:text"); + chars("th"); + endEl("number:text"); break; } break; case '4': case '$': if( add_zero ) - padd("number:style", sXML_CDATA, "long"); - rstartEl("number:hours", mxList); + mxList->addAttribute("number:style", sXML_CDATA, "long"); + startEl("number:hours"); mxList->clear(); - rendEl("number:hours"); + endEl("number:hours"); break; case '5': case '%': if( add_zero ) - padd("number:style", sXML_CDATA, "long"); - rstartEl("number:minutes", mxList); + mxList->addAttribute("number:style", sXML_CDATA, "long"); + startEl("number:minutes"); mxList->clear(); - rendEl("number:minutes"); + endEl("number:minutes"); break; case '_': - padd("number:style", sXML_CDATA, "long"); + mxList->addAttribute("number:style", sXML_CDATA, "long"); [[fallthrough]]; case '6': case '^': - rstartEl("number:day-of-week", mxList); + startEl("number:day-of-week"); mxList->clear(); - rendEl("number:day-of-week"); + endEl("number:day-of-week"); break; case '7': case '&': case '+': - rstartEl("number:am-pm", mxList); + startEl("number:am-pm"); mxList->clear(); - rendEl("number:am-pm"); + endEl("number:am-pm"); break; case '~': // Chinese Locale break; @@ -3426,54 +3351,53 @@ void HwpReader::makeDateFormat(DateCode * hbox) hchar sbuf[2]; sbuf[0] = *fmt; sbuf[1] = 0; - rstartEl("number:text", mxList); - rchars(fromHcharStringToOUString(hstr2ucsstr(sbuf))); - rendEl("number:text"); + startEl("number:text"); + chars(hstr2OUString(sbuf)); + endEl("number:text"); break; } } mxList->clear(); - rendEl("number:date-style"); + endEl("number:date-style"); } void HwpReader::makeDateCode(DateCode * hbox) { - padd("style:data-style-name", sXML_CDATA, - ascii(Int2Str(hbox->key, "N%d", buf))); - rstartEl( "text:date", mxList ); + mxList->addAttribute("style:data-style-name", sXML_CDATA, "N" + OUString::number(hbox->key)); + startEl("text:date"); mxList->clear(); hchar_string const boxstr = hbox->GetString(); - rchars(fromHcharStringToOUString(hstr2ucsstr(boxstr.c_str()))); - rendEl( "text:date" ); + chars(hstr2OUString(boxstr.c_str())); + endEl("text:date"); } void HwpReader::makeTab() { - rstartEl("text:tab-stop", mxList); - rendEl("text:tab-stop"); + startEl("text:tab-stop"); + endEl("text:tab-stop"); } void HwpReader::makeTable(TxtBox * hbox) { - padd("table:name", sXML_CDATA, - ascii(Int2Str(hbox->style.boxnum, "Table%d", buf))); - padd("table:style-name", sXML_CDATA, - ascii(Int2Str(hbox->style.boxnum, "Table%d", buf))); - rstartEl("table:table", mxList); + mxList->addAttribute("table:name", sXML_CDATA, "Table" + OUString::number(hbox->style.boxnum)); + mxList->addAttribute("table:style-name", sXML_CDATA, "Table" + OUString::number(hbox->style.boxnum)); + startEl("table:table"); mxList->clear(); Table *tbl = hbox->m_pTable; // column for (size_t i = 0 ; i < tbl->columns.nCount -1 ; i++) { - sprintf(buf,"Table%d.%c",hbox->style.boxnum, static_cast<char>('A'+i)); - padd("table:style-name", sXML_CDATA, ascii( buf )); - rstartEl("table:table-column", mxList); + mxList->addAttribute( + "table:style-name", sXML_CDATA, + "Table" + OUString::number(hbox->style.boxnum) + "." + + OUStringChar(static_cast<char>('A'+i))); + startEl("table:table-column"); mxList->clear(); - rendEl("table:table-column"); + endEl("table:table-column"); } // cell @@ -3484,35 +3408,40 @@ void HwpReader::makeTable(TxtBox * hbox) { if( j > k ) { - rendEl("table:table-row"); + endEl("table:table-row"); k = j; } // row - sprintf(buf,"Table%d.row%d",hbox->style.boxnum, tcell->nRowIndex + 1); - padd("table:style-name", sXML_CDATA, ascii( buf )); - rstartEl("table:table-row", mxList); + mxList->addAttribute( + "table:style-name", sXML_CDATA, + "Table" + OUString::number(hbox->style.boxnum) + ".row" + + OUString::number(tcell->nRowIndex + 1)); + startEl("table:table-row"); mxList->clear(); j = tcell->nRowIndex; } - sprintf(buf,"Table%d.%c%d",hbox->style.boxnum, 'A'+ tcell->nColumnIndex, tcell->nRowIndex +1); - padd("table:style-name", sXML_CDATA, ascii( buf )); + mxList->addAttribute( + "table:style-name", sXML_CDATA, + "Table" + OUString::number(hbox->style.boxnum) + "." + + OUStringChar(char('A'+ tcell->nColumnIndex)) + + OUString::number(tcell->nRowIndex +1)); if( tcell->nColumnSpan > 1 ) - padd("table:number-columns-spanned", sXML_CDATA, - ascii(Int2Str(tcell->nColumnSpan, "%d", buf))); + mxList->addAttribute("table:number-columns-spanned", sXML_CDATA, OUString::number(tcell->nColumnSpan)); if( tcell->nRowSpan > 1 ) - padd("table:number-rows-spanned", sXML_CDATA, - ascii(Int2Str(tcell->nRowSpan, "%d", buf))); - padd("table:value-type", sXML_CDATA,"string"); + mxList->addAttribute("table:number-rows-spanned", sXML_CDATA, OUString::number(tcell->nRowSpan)); + mxList->addAttribute("table:value-type", sXML_CDATA,"string"); if( tcell->pCell->protect ) - padd("table:protected", sXML_CDATA,"true"); - rstartEl("table:table-cell", mxList); + mxList->addAttribute("table:protected", sXML_CDATA,"true"); + startEl("table:table-cell"); mxList->clear(); - parsePara(hbox->plists[tcell->pCell->key].front().get()); - rendEl("table:table-cell"); + TxtBox::plist_t& rVec = hbox->plists[tcell->pCell->key]; + if (!rVec.empty()) + parsePara(rVec.front().get()); + endEl("table:table-cell"); } - rendEl("table:table-row"); - rendEl("table:table"); + endEl("table:table-row"); + endEl("table:table"); } @@ -3526,59 +3455,52 @@ void HwpReader::makeTextBox(TxtBox * hbox) { if( hbox->style.cap_len > 0 && hbox->type == TXT_TYPE) { - padd("draw:style-name", sXML_CDATA, - ascii(Int2Str(hbox->style.boxnum, "CapBox%d", buf))); - padd("draw:name", sXML_CDATA, - ascii(Int2Str(hbox->style.boxnum, "CaptionBox%d", buf))); - padd("draw:z-index", sXML_CDATA, - ascii(Int2Str(hbox->zorder, "%d", buf))); + mxList->addAttribute("draw:style-name", sXML_CDATA, "CapBox" + OUString::number(hbox->style.boxnum)); + mxList->addAttribute("draw:name", sXML_CDATA, "CaptionBox" + OUString::number(hbox->style.boxnum)); + mxList->addAttribute("draw:z-index", sXML_CDATA, OUString::number(hbox->zorder)); switch (hbox->style.anchor_type) { case CHAR_ANCHOR: - padd("text:anchor-type", sXML_CDATA, "as-char"); + mxList->addAttribute("text:anchor-type", sXML_CDATA, "as-char"); break; case PARA_ANCHOR: - padd("text:anchor-type", sXML_CDATA, "paragraph"); + mxList->addAttribute("text:anchor-type", sXML_CDATA, "paragraph"); break; case PAGE_ANCHOR: case PAPER_ANCHOR: { - padd("text:anchor-type", sXML_CDATA, "page"); - padd("text:anchor-page-number", sXML_CDATA, - ascii(Int2Str(hbox->pgno +1, "%d", buf))); + mxList->addAttribute("text:anchor-type", sXML_CDATA, "page"); + mxList->addAttribute("text:anchor-page-number", sXML_CDATA, OUString::number(hbox->pgno + 1)); break; } } if (hbox->style.anchor_type != CHAR_ANCHOR) { - padd("svg:x", sXML_CDATA, - Double2Str(WTMM( ( hbox->pgx + hbox->style.margin[0][0] ) )) + "mm"); - padd("svg:y", sXML_CDATA, - Double2Str(WTMM( ( hbox->pgy + hbox->style.margin[0][2] ) )) + "mm"); + mxList->addAttribute("svg:x", sXML_CDATA, + OUString::number(WTMM( hbox->pgx + hbox->style.margin[0][0] )) + "mm"); + mxList->addAttribute("svg:y", sXML_CDATA, + OUString::number(WTMM( hbox->pgy + hbox->style.margin[0][2] )) + "mm"); } - padd("svg:width", sXML_CDATA, - Double2Str(WTMM(( hbox->box_xs + hbox->cap_xs) )) + "mm"); - padd("fo:min-height", sXML_CDATA, - Double2Str(WTMM(( hbox->box_ys + hbox->cap_ys) )) + "mm"); - rstartEl("draw:text-box", mxList); + mxList->addAttribute("svg:width", sXML_CDATA, + OUString::number(WTMM( hbox->box_xs + hbox->cap_xs )) + "mm"); + mxList->addAttribute("fo:min-height", sXML_CDATA, + OUString::number(WTMM( hbox->box_ys + hbox->cap_ys )) + "mm"); + startEl("draw:text-box"); mxList->clear(); - if( hbox->cap_pos % 2 ) /* The caption is on the top */ + if (!hbox->caption.empty() && hbox->cap_pos % 2) /* The caption is on the top */ { parsePara(hbox->caption.front().get()); } - padd( "text:style-name", sXML_CDATA, "Standard"); - rstartEl("text:p", mxList); + mxList->addAttribute( "text:style-name", sXML_CDATA, "Standard"); + startEl("text:p"); mxList->clear(); } else{ - padd("draw:z-index", sXML_CDATA, - ascii(Int2Str(hbox->zorder, "%d", buf))); + mxList->addAttribute("draw:z-index", sXML_CDATA, OUString::number(hbox->zorder)); } - padd("draw:style-name", sXML_CDATA, - ascii(Int2Str(hbox->style.boxnum, "Txtbox%d", buf))); - padd("draw:name", sXML_CDATA, - ascii(Int2Str(hbox->style.boxnum, "Frame%d", buf))); + mxList->addAttribute("draw:style-name", sXML_CDATA, "Txtbox" + OUString::number(hbox->style.boxnum)); + mxList->addAttribute("draw:name", sXML_CDATA, "Frame" + OUString::number(hbox->style.boxnum)); if( hbox->style.cap_len <= 0 || hbox->type != TXT_TYPE ) { @@ -3587,17 +3509,16 @@ void HwpReader::makeTextBox(TxtBox * hbox) switch (hbox->style.anchor_type) { case CHAR_ANCHOR: - padd("text:anchor-type", sXML_CDATA, "as-char"); + mxList->addAttribute("text:anchor-type", sXML_CDATA, "as-char"); break; case PARA_ANCHOR: - padd("text:anchor-type", sXML_CDATA, "paragraph"); + mxList->addAttribute("text:anchor-type", sXML_CDATA, "paragraph"); break; case PAGE_ANCHOR: case PAPER_ANCHOR: { - padd("text:anchor-type", sXML_CDATA, "page"); - padd("text:anchor-page-number", sXML_CDATA, - ascii(Int2Str(hbox->pgno +1, "%d", buf))); + mxList->addAttribute("text:anchor-type", sXML_CDATA, "page"); + mxList->addAttribute("text:anchor-page-number", sXML_CDATA, OUString::number(hbox->pgno + 1)); break; } } @@ -3606,31 +3527,31 @@ void HwpReader::makeTextBox(TxtBox * hbox) x += hbox->style.margin[0][0]; y += hbox->style.margin[0][2]; } - padd("svg:x", sXML_CDATA, - Double2Str(WTMM( hbox->pgx + x )) + "mm"); - padd("svg:y", sXML_CDATA, - Double2Str(WTMM( hbox->pgy + y )) + "mm"); + mxList->addAttribute("svg:x", sXML_CDATA, + OUString::number(WTMM( hbox->pgx + x )) + "mm"); + mxList->addAttribute("svg:y", sXML_CDATA, + OUString::number(WTMM( hbox->pgy + y )) + "mm"); } else { - padd("text:anchor-type", sXML_CDATA, "as-char"); - padd("svg:y", sXML_CDATA, "0cm"); + mxList->addAttribute("text:anchor-type", sXML_CDATA, "as-char"); + mxList->addAttribute("svg:y", sXML_CDATA, "0cm"); } - padd("svg:width", sXML_CDATA, - Double2Str(WTMM( hbox->box_xs )) + "mm"); + mxList->addAttribute("svg:width", sXML_CDATA, + OUString::number(WTMM( hbox->box_xs )) + "mm"); if( hbox->style.cap_len > 0 && hbox->type != TXT_TYPE) - padd("fo:min-height", sXML_CDATA, - Double2Str(WTMM( hbox->box_ys + hbox->cap_ys)) + "mm"); + mxList->addAttribute("fo:min-height", sXML_CDATA, + OUString::number(WTMM( hbox->box_ys + hbox->cap_ys)) + "mm"); else - padd("svg:height", sXML_CDATA, - Double2Str(WTMM(hbox->box_ys )) + "mm"); + mxList->addAttribute("svg:height", sXML_CDATA, + OUString::number(WTMM(hbox->box_ys )) + "mm"); if( hbox->type != EQU_TYPE ) { - rstartEl("draw:text-box", mxList); + startEl("draw:text-box"); mxList->clear(); /* If captions are present and it is on the top */ - if( hbox->style.cap_len > 0 && (hbox->cap_pos % 2) && hbox->type == TBL_TYPE ) + if (hbox->style.cap_len > 0 && (hbox->cap_pos % 2) && hbox->type == TBL_TYPE && !hbox->caption.empty()) { parsePara(hbox->caption.front().get()); } @@ -3638,33 +3559,33 @@ void HwpReader::makeTextBox(TxtBox * hbox) { makeTable(hbox); } - else // Is TextBox + else if (!hbox->plists[0].empty()) // Is TextBox { parsePara(hbox->plists[0].front().get()); } /* If captions are present and it is on the bottom */ - if( hbox->style.cap_len > 0 && !(hbox->cap_pos % 2) && hbox->type == TBL_TYPE) + if (hbox->style.cap_len > 0 && !(hbox->cap_pos % 2) && hbox->type == TBL_TYPE && !hbox->caption.empty()) { parsePara(hbox->caption.front().get()); } - rendEl("draw:text-box"); + endEl("draw:text-box"); // Caption exist and it is text-box if( hbox->style.cap_len > 0 && hbox->type == TXT_TYPE) { - rendEl( "text:p"); - if( !(hbox->cap_pos % 2)) + endEl("text:p"); + if (!(hbox->cap_pos % 2) && !hbox->caption.empty()) { parsePara(hbox->caption.front().get()); } - rendEl( "draw:text-box"); + endEl("draw:text-box"); } } else // is Formula { - rstartEl("draw:object", mxList); + startEl("draw:object"); mxList->clear(); makeFormula(hbox); - rendEl("draw:object"); + endEl("draw:object"); } } @@ -3678,21 +3599,22 @@ void HwpReader::makeFormula(TxtBox * hbox) char mybuf[3000]; HWPPara* pPar; - int n, c, res; hchar dest[3]; size_t l = 0; - pPar = hbox->plists[0].front().get(); + pPar = hbox->plists[0].empty() ? nullptr : hbox->plists[0].front().get(); while( pPar ) { - for( n = 0; n < pPar->nch && pPar->hhstr[n]->hh; - n += pPar->hhstr[n]->WSize() ) + for (const auto& box : pPar->hhstr) { + if (!box->hh) + break; + if (l >= sizeof(mybuf)-7) break; - res = hcharconv(pPar->hhstr[n]->hh, dest, UNICODE); + int res = hcharconv(box->hh, dest, UNICODE); for( int j = 0 ; j < res; j++ ){ - c = dest[j]; + int c = dest[j]; if( c < 32 ) c = ' '; if( c < 256 ) @@ -3735,33 +3657,33 @@ void HwpReader::makeHyperText(TxtBox * hbox) #else reinterpret_cast<uchar const *>(urltounix(reinterpret_cast<char *>(hypert->filename)).c_str())).c_str()); #endif - padd("xlink:type", sXML_CDATA, "simple"); + mxList->addAttribute("xlink:type", sXML_CDATA, "simple"); if (!tmp.empty() && strcmp(tmp.c_str(), "[HTML]")) { ::std::string tmp3(tmp2); tmp3.push_back('#'); tmp3.append(tmp); - padd("xlink:href", sXML_CDATA, + mxList->addAttribute("xlink:href", sXML_CDATA, OUString(tmp3.c_str(), tmp3.size()+1, RTL_TEXTENCODING_EUC_KR)); } else{ - padd("xlink:href", sXML_CDATA, + mxList->addAttribute("xlink:href", sXML_CDATA, OUString(tmp2.c_str(), tmp2.size()+1, RTL_TEXTENCODING_EUC_KR)); } } else { - padd("xlink:type", sXML_CDATA, "simple"); + mxList->addAttribute("xlink:type", sXML_CDATA, "simple"); ::std::string tmp; tmp.push_back('#'); tmp.append(hstr2ksstr(hypert->bookmark)); - padd("xlink:href", sXML_CDATA, + mxList->addAttribute("xlink:href", sXML_CDATA, OUString(tmp.c_str(), tmp.size()+1, RTL_TEXTENCODING_EUC_KR)); } - rstartEl("draw:a", mxList); + startEl("draw:a"); mxList->clear(); makeTextBox(hbox); - rendEl("draw:a"); + endEl("draw:a"); } @@ -3780,141 +3702,135 @@ void HwpReader::makePicture(Picture * hbox) { if( hbox->style.cap_len > 0 ) { - padd("draw:style-name", sXML_CDATA, - ascii(Int2Str(hbox->style.boxnum, "CapBox%d", buf))); - padd("draw:name", sXML_CDATA, - ascii(Int2Str(hbox->style.boxnum, "CaptionBox%d", buf))); - padd("draw:z-index", sXML_CDATA, - ascii(Int2Str(hbox->zorder, "%d", buf))); + mxList->addAttribute("draw:style-name", sXML_CDATA, + "CapBox" + OUString::number(hbox->style.boxnum)); + mxList->addAttribute("draw:name", sXML_CDATA, "CaptionBox" + OUString::number(hbox->style.boxnum)); + mxList->addAttribute("draw:z-index", sXML_CDATA, OUString::number(hbox->zorder)); switch (hbox->style.anchor_type) { case CHAR_ANCHOR: - padd("text:anchor-type", sXML_CDATA, "as-char"); + mxList->addAttribute("text:anchor-type", sXML_CDATA, "as-char"); break; case PARA_ANCHOR: - padd("text:anchor-type", sXML_CDATA, "paragraph"); + mxList->addAttribute("text:anchor-type", sXML_CDATA, "paragraph"); break; case PAGE_ANCHOR: case PAPER_ANCHOR: { - padd("text:anchor-type", sXML_CDATA, "page"); - padd("text:anchor-page-number", sXML_CDATA, - ascii(Int2Str(hbox->pgno +1, "%d", buf))); + mxList->addAttribute("text:anchor-type", sXML_CDATA, "page"); + mxList->addAttribute("text:anchor-page-number", sXML_CDATA, + OUString::number(hbox->pgno + 1)); break; } } if (hbox->style.anchor_type != CHAR_ANCHOR) { - padd("svg:x", sXML_CDATA, - Double2Str(WTMM( hbox->pgx + hbox->style.margin[0][0] )) + "mm"); - padd("svg:y", sXML_CDATA, - Double2Str(WTMM( hbox->pgy + hbox->style.margin[0][2] )) + "mm"); + mxList->addAttribute("svg:x", sXML_CDATA, + OUString::number(WTMM( hbox->pgx + hbox->style.margin[0][0] )) + "mm"); + mxList->addAttribute("svg:y", sXML_CDATA, + OUString::number(WTMM( hbox->pgy + hbox->style.margin[0][2] )) + "mm"); } - padd("svg:width", sXML_CDATA, - Double2Str(WTMM( hbox->box_xs + hbox->style.margin[1][0] + hbox->style.margin[1][1] )) + "mm"); - padd("fo:min-height", sXML_CDATA, - Double2Str(WTMM( hbox->box_ys + hbox->style.margin[1][2] + hbox->style.margin[1][3] + hbox->cap_ys )) + "mm"); - rstartEl("draw:text-box", mxList); + mxList->addAttribute("svg:width", sXML_CDATA, + OUString::number(WTMM( hbox->box_xs + hbox->style.margin[1][0] + hbox->style.margin[1][1] )) + "mm"); + mxList->addAttribute("fo:min-height", sXML_CDATA, + OUString::number(WTMM( hbox->box_ys + hbox->style.margin[1][2] + hbox->style.margin[1][3] + hbox->cap_ys )) + "mm"); + startEl("draw:text-box"); mxList->clear(); - if( hbox->cap_pos % 2 ) /* Caption is on the top */ + if (!hbox->caption.empty() && hbox->cap_pos % 2) /* Caption is on the top */ { parsePara(hbox->caption.front().get()); } - padd( "text:style-name", sXML_CDATA, "Standard"); - rstartEl("text:p", mxList); + mxList->addAttribute( "text:style-name", sXML_CDATA, "Standard"); + startEl("text:p"); mxList->clear(); } if( hbox->ishyper ) { - padd("xlink:type", sXML_CDATA, "simple"); + mxList->addAttribute("xlink:type", sXML_CDATA, "simple"); #ifdef _WIN32 if( hbox->follow[4] != 0 ) - padd("xlink:href", sXML_CDATA, fromHcharStringToOUString(hstr2ucsstr(kstr2hstr(hbox->follow.data() + 4).c_str()))); + mxList->addAttribute("xlink:href", sXML_CDATA, hstr2OUString(kstr2hstr(hbox->follow.data() + 4).c_str())); else - padd("xlink:href", sXML_CDATA, fromHcharStringToOUString(hstr2ucsstr(kstr2hstr(hbox->follow.data() + 5).c_str()))); + mxList->addAttribute("xlink:href", sXML_CDATA, hstr2OUString(kstr2hstr(hbox->follow.data() + 5).c_str())); #else if( hbox->follow[4] != 0 ) - padd("xlink:href", sXML_CDATA, - fromHcharStringToOUString(hstr2ucsstr(kstr2hstr(reinterpret_cast<uchar const *>(urltounix(reinterpret_cast<char *>(hbox->follow.data() + 4)).c_str())).c_str()))); + mxList->addAttribute("xlink:href", sXML_CDATA, + hstr2OUString(kstr2hstr(reinterpret_cast<uchar const *>(urltounix(reinterpret_cast<char *>(hbox->follow.data() + 4)).c_str())).c_str())); else - padd("xlink:href", sXML_CDATA, - fromHcharStringToOUString(hstr2ucsstr(kstr2hstr(reinterpret_cast<uchar const *>(urltounix(reinterpret_cast<char *>(hbox->follow.data() + 5)).c_str())).c_str()))); + mxList->addAttribute("xlink:href", sXML_CDATA, + hstr2OUString(kstr2hstr(reinterpret_cast<uchar const *>(urltounix(reinterpret_cast<char *>(hbox->follow.data() + 5)).c_str())).c_str())); #endif - rstartEl("draw:a", mxList); + startEl("draw:a"); mxList->clear(); } - padd("draw:style-name", sXML_CDATA, - ascii(Int2Str(hbox->style.boxnum, "G%d", buf))); - padd("draw:name", sXML_CDATA, - ascii(Int2Str(hbox->style.boxnum, "Image%d", buf))); + mxList->addAttribute("draw:style-name", sXML_CDATA, "G" + OUString::number(hbox->style.boxnum)); + mxList->addAttribute("draw:name", sXML_CDATA, "Image" + OUString::number(hbox->style.boxnum)); if( hbox->style.cap_len <= 0 ) { - padd("draw:z-index", sXML_CDATA, - ascii(Int2Str(hbox->zorder, "%d", buf))); + mxList->addAttribute("draw:z-index", sXML_CDATA, OUString::number(hbox->zorder)); switch (hbox->style.anchor_type) { case CHAR_ANCHOR: - padd("text:anchor-type", sXML_CDATA, "as-char"); + mxList->addAttribute("text:anchor-type", sXML_CDATA, "as-char"); break; case PARA_ANCHOR: - padd("text:anchor-type", sXML_CDATA, "paragraph"); + mxList->addAttribute("text:anchor-type", sXML_CDATA, "paragraph"); break; case PAGE_ANCHOR: case PAPER_ANCHOR: { - padd("text:anchor-type", sXML_CDATA, "page"); - padd("text:anchor-page-number", sXML_CDATA, - ascii(Int2Str(hbox->pgno +1, "%d", buf))); + mxList->addAttribute("text:anchor-type", sXML_CDATA, "page"); + mxList->addAttribute("text:anchor-page-number", sXML_CDATA, + OUString::number(hbox->pgno + 1)); break; } } if (hbox->style.anchor_type != CHAR_ANCHOR) { - padd("svg:x", sXML_CDATA, - Double2Str(WTMM( hbox->pgx + hbox->style.margin[0][0] )) + "mm"); - padd("svg:y", sXML_CDATA, - Double2Str(WTMM( hbox->pgy + hbox->style.margin[0][2] )) + "mm"); + mxList->addAttribute("svg:x", sXML_CDATA, + OUString::number(WTMM( hbox->pgx + hbox->style.margin[0][0] )) + "mm"); + mxList->addAttribute("svg:y", sXML_CDATA, + OUString::number(WTMM( hbox->pgy + hbox->style.margin[0][2] )) + "mm"); } } else { - padd("text:anchor-type", sXML_CDATA, "as-char"); - padd("svg:y", sXML_CDATA, "0cm"); + mxList->addAttribute("text:anchor-type", sXML_CDATA, "as-char"); + mxList->addAttribute("svg:y", sXML_CDATA, "0cm"); } - padd("svg:width", sXML_CDATA, - Double2Str(WTMM( hbox->box_xs + hbox->style.margin[1][0] + hbox->style.margin[1][1])) + "mm"); - padd("svg:height", sXML_CDATA, - Double2Str(WTMM( hbox->box_ys + hbox->style.margin[1][2] + hbox->style.margin[1][3])) + "mm"); + mxList->addAttribute("svg:width", sXML_CDATA, + OUString::number(WTMM( hbox->box_xs + hbox->style.margin[1][0] + hbox->style.margin[1][1])) + "mm"); + mxList->addAttribute("svg:height", sXML_CDATA, + OUString::number(WTMM( hbox->box_ys + hbox->style.margin[1][2] + hbox->style.margin[1][3])) + "mm"); if ( hbox->pictype == PICTYPE_FILE ){ #ifdef _WIN32 - sprintf(buf, "file:///%s", hbox->picinfo.picun.path ); - padd("xlink:href", sXML_CDATA, fromHcharStringToOUString(hstr2ucsstr(kstr2hstr(reinterpret_cast<uchar *>(buf)).c_str()))); + sprintf(d->buf, "file:///%s", hbox->picinfo.picun.path ); + mxList->addAttribute("xlink:href", sXML_CDATA, hstr2OUString(kstr2hstr(reinterpret_cast<uchar *>(d->buf)).c_str())); #else - padd("xlink:href", sXML_CDATA, - fromHcharStringToOUString(hstr2ucsstr(kstr2hstr(reinterpret_cast<uchar const *>(urltounix(hbox->picinfo.picun.path).c_str())).c_str()))); + mxList->addAttribute("xlink:href", sXML_CDATA, + hstr2OUString(kstr2hstr(reinterpret_cast<uchar const *>(urltounix(hbox->picinfo.picun.path).c_str())).c_str())); #endif - padd("xlink:type", sXML_CDATA, "simple"); - padd("xlink:show", sXML_CDATA, "embed"); - padd("xlink:actuate", sXML_CDATA, "onLoad"); + mxList->addAttribute("xlink:type", sXML_CDATA, "simple"); + mxList->addAttribute("xlink:show", sXML_CDATA, "embed"); + mxList->addAttribute("xlink:actuate", sXML_CDATA, "onLoad"); } if( hbox->pictype == PICTYPE_OLE ) - rstartEl("draw:object-ole", mxList); + startEl("draw:object-ole"); else - rstartEl("draw:image", mxList); + startEl("draw:image"); mxList->clear(); if (hbox->pictype == PICTYPE_EMBED || hbox->pictype == PICTYPE_OLE) { - rstartEl("office:binary-data", mxList); + startEl("office:binary-data"); mxList->clear(); if( hbox->pictype == PICTYPE_EMBED ){ EmPicture *emp = hwpfile.GetEmPicture(hbox); if( emp ) { - std::shared_ptr<char> pStr(base64_encode_string( emp->data.get(), emp->size ), Free<char>()); - rchars(ascii(pStr.get())); + chars(base64_encode_string(emp->data.data(), emp->size)); } } else{ @@ -3924,55 +3840,54 @@ void HwpReader::makePicture(Picture * hbox) LPUNKNOWN pObj; wchar_t pathname[200]; - MultiByteToWideChar(CP_ACP, 0, hbox->picinfo.picole.embname, -1, pathname, 200); + MultiByteToWideChar(CP_ACP, 0, hbox->picinfo.picembed.embname, -1, pathname, 200); int rc = hwpfile.oledata->pis->OpenStorage(pathname, nullptr, STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_TRANSACTED, nullptr, 0, &srcsto); if (rc != S_OK) { - rchars(""); + chars(""); } else{ rc = OleLoad(srcsto, IID_IUnknown, nullptr, reinterpret_cast<LPVOID*>(&pObj)); if( rc != S_OK ){ srcsto->Release(); - rchars(""); + chars(""); } else{ - std::shared_ptr<char> pStr(base64_encode_string( reinterpret_cast<uchar *>(pObj), strlen(reinterpret_cast<char *>(pObj))), Free<char>()); - rchars(ascii(pStr.get())); + chars(base64_encode_string(reinterpret_cast<uchar*>(pObj), strlen(reinterpret_cast<char*>(pObj)))); pObj->Release(); srcsto->Release(); } } #else - rchars(""); + chars(""); #endif } } - rendEl("office:binary-data"); + endEl("office:binary-data"); } if( hbox->pictype == PICTYPE_OLE ) - rendEl("draw:object-ole"); + endEl("draw:object-ole"); else - rendEl("draw:image"); + endEl("draw:image"); if( hbox->ishyper ) { - rendEl("draw:a"); + endEl("draw:a"); } if( hbox->style.cap_len > 0 ) { - rendEl( "text:p"); - if( !(hbox->cap_pos % 2)) /* Caption is at the bottom, */ + endEl("text:p"); + if (!hbox->caption.empty() && !(hbox->cap_pos % 2)) /* Caption is at the bottom, */ { parsePara(hbox->caption.front().get()); } - rendEl( "draw:text-box"); + endEl("draw:text-box"); } break; } case PICTYPE_DRAW: if( hbox->picinfo.picdraw.zorder > 0 ) - padd("draw:z-index", sXML_CDATA, - ascii(Int2Str( hbox->picinfo.picdraw.zorder + 10000, "%d", buf))); + mxList->addAttribute("draw:z-index", sXML_CDATA, + OUString::number(hbox->picinfo.picdraw.zorder + 10000)); makePictureDRAW(hbox->picinfo.picdraw.hdo, hbox); break; case PICTYPE_UNKNOWN: @@ -3980,36 +3895,30 @@ void HwpReader::makePicture(Picture * hbox) } } - -#define DBL(x) ((x) * (x)) -void HwpReader::makePictureDRAW(HWPDrawingObject *drawobj, Picture * hbox) +void HwpReader::makePictureDRAW(HWPDrawingObject *drawobj, const Picture* hbox) { - int x = hbox->pgx; - int y = hbox->pgy; bool bIsRotate = false; while (drawobj) { - padd("draw:style-name", sXML_CDATA, - ascii(Int2Str(drawobj->index, "Draw%d", buf))); + mxList->addAttribute("draw:style-name", sXML_CDATA, "Draw" + OUString::number(drawobj->index)); int a = 0; int b = 0; switch (hbox->style.anchor_type) { case CHAR_ANCHOR: - padd("text:anchor-type", sXML_CDATA, "as-char"); + mxList->addAttribute("text:anchor-type", sXML_CDATA, "as-char"); break; case PARA_ANCHOR: - padd("text:anchor-type", sXML_CDATA, "paragraph"); + mxList->addAttribute("text:anchor-type", sXML_CDATA, "paragraph"); break; case PAGE_ANCHOR: case PAPER_ANCHOR: { HWPInfo& hwpinfo = hwpfile.GetHWPInfo(); - padd("text:anchor-type", sXML_CDATA, "page"); - padd("text:anchor-page-number", sXML_CDATA, - ascii(Int2Str(hbox->pgno +1, "%d", buf))); + mxList->addAttribute("text:anchor-type", sXML_CDATA, "page"); + mxList->addAttribute("text:anchor-page-number", sXML_CDATA, OUString::number(hbox->pgno + 1)); a = hwpinfo.paper.left_margin; b = hwpinfo.paper.top_margin + hwpinfo.paper.header_length; break; @@ -4018,13 +3927,16 @@ void HwpReader::makePictureDRAW(HWPDrawingObject *drawobj, Picture * hbox) if (drawobj->type == HWPDO_CONTAINER) { - rstartEl("draw:g", mxList); + startEl("draw:g"); mxList->clear(); makePictureDRAW(drawobj->child.get(), hbox); - rendEl("draw:g"); + endEl("draw:g"); } else { + double x = hbox->pgx; + double y = hbox->pgy; + bIsRotate = false; if( (drawobj->property.flag & HWPDO_FLAG_ROTATION) && (drawobj->property.parall.pt[0].y != drawobj->property.parall.pt[1].y) && @@ -4034,30 +3946,31 @@ void HwpReader::makePictureDRAW(HWPDrawingObject *drawobj, Picture * hbox) { int i; - ZZParall *pal = &drawobj->property.parall; + ZZParall& pal = drawobj->property.parall; - ZZPoint pt[3], r_pt[3]; + basegfx::B2DPoint pt[3], r_pt[3]; for(i = 0 ; i < 3 ; i++ ){ - pt[i].x = pal->pt[i].x - drawobj->property.rot_originx; + basegfx::B2DPoint rot_origin(drawobj->property.rot_originx, drawobj->property.rot_originy); + pt[i].setX(pal.pt[i].x - rot_origin.getX()); /* Convert to a physical coordinate */ - pt[i].y = -(pal->pt[i].y - drawobj->property.rot_originy); + pt[i].setY(-(pal.pt[i].y - rot_origin.getY())); } - double rotate, skewX ; + double skewX; /* 2 - rotation angle calculation */ - rotate = atan2( pt[1].y - pt[0].y, pt[1].x - pt[0].x ); + double rotate = atan2(pt[1].getY() - pt[0].getY(), pt[1].getX() - pt[0].getX()); for( i = 0 ; i < 3 ; i++){ - r_pt[i].x = static_cast<int>(pt[i].x * cos(-rotate) - pt[i].y * sin(-rotate)); - r_pt[i].y = static_cast<int>(pt[i].y * cos(-rotate) + pt[i].x * sin(-rotate)); + r_pt[i].setX(pt[i].getX() * cos(-rotate) - pt[i].getY() * sin(-rotate)); + r_pt[i].setY(pt[i].getY() * cos(-rotate) + pt[i].getX() * sin(-rotate)); } /* 4 - Calculation of reflex angle */ - if( r_pt[2].y == r_pt[1].y ) + if (r_pt[2].getY() == r_pt[1].getY()) skewX = 0; else - skewX = atan(static_cast<double>(r_pt[2].x - r_pt[1].x )/( r_pt[2].y - r_pt[1].y )); + skewX = atan((r_pt[2].getX() - r_pt[1].getX()) / (r_pt[2].getY() - r_pt[1].getY())); if( skewX >= M_PI_2 ) skewX -= M_PI; if( skewX <= -M_PI_2 ) @@ -4065,28 +3978,28 @@ void HwpReader::makePictureDRAW(HWPDrawingObject *drawobj, Picture * hbox) OUString trans; if( skewX != 0.0 && rotate != 0.0 ){ - trans = "skewX (" + Double2Str(skewX) - + ") rotate (" + Double2Str(rotate) - + ") translate (" + Double2Str(WTMM(x + a + drawobj->offset2.x + pal->pt[0].x)) + "mm " - + Double2Str(WTMM(y + b + drawobj->offset2.y + pal->pt[0].y)) + "mm)"; + trans = "skewX (" + OUString::number(skewX) + + ") rotate (" + OUString::number(rotate) + + ") translate (" + OUString::number(WTMM(x + a + drawobj->offset2.x + pal.pt[0].x)) + "mm " + + OUString::number(WTMM(y + b + drawobj->offset2.y + pal.pt[0].y)) + "mm)"; bIsRotate = true; } else if( skewX != 0.0 ){ - trans = "skewX (" + Double2Str(skewX) - + ") translate (" + Double2Str(WTMM(x + a + drawobj->offset2.x + pal->pt[0].x)) + "mm " - + Double2Str(WTMM(y + b + drawobj->offset2.y + pal->pt[0].y)) + "mm)"; + trans = "skewX (" + OUString::number(skewX) + + ") translate (" + OUString::number(WTMM(x + a + drawobj->offset2.x + pal.pt[0].x)) + "mm " + + OUString::number(WTMM(y + b + drawobj->offset2.y + pal.pt[0].y)) + "mm)"; bIsRotate = true; } else if( rotate != 0.0 ){ - trans = "rotate (" + Double2Str(rotate) - + ") translate (" + Double2Str(WTMM(x + a + drawobj->offset2.x + pal->pt[0].x)) + "mm " - + Double2Str(WTMM(y + b + drawobj->offset2.y + pal->pt[0].y)) + "mm)"; + trans = "rotate (" + OUString::number(rotate) + + ") translate (" + OUString::number(WTMM(x + a + drawobj->offset2.x + pal.pt[0].x)) + "mm " + + OUString::number(WTMM(y + b + drawobj->offset2.y + pal.pt[0].y)) + "mm)"; bIsRotate = true; } if( bIsRotate ){ - drawobj->extent.w = static_cast<int>(sqrt(double(DBL(pt[1].x-pt[0].x)+DBL(pt[1].y-pt[0].y)))); - drawobj->extent.h = static_cast<int>(sqrt(double(DBL(pt[2].x-pt[1].x)+DBL(pt[2].y-pt[1].y)))); - padd("draw:transform", sXML_CDATA, trans); + drawobj->extent.w = static_cast<int>(std::hypot(pt[1].getX() - pt[0].getX(), pt[1].getY() - pt[0].getY())); + drawobj->extent.h = static_cast<int>(std::hypot(pt[2].getX() - pt[1].getX(), pt[2].getY() - pt[1].getY())); + mxList->addAttribute("draw:transform", sXML_CDATA, trans); } } switch (drawobj->type) @@ -4094,65 +4007,65 @@ void HwpReader::makePictureDRAW(HWPDrawingObject *drawobj, Picture * hbox) case HWPDO_LINE: /* Line-starting coordinates, ending coordinates. */ if( drawobj->u.line_arc.flip & 0x01 ) { - padd("svg:x1", sXML_CDATA, - Double2Str (WTMM(x + a + drawobj->offset2.x + drawobj->extent.w)) + "mm"); - padd("svg:x2", sXML_CDATA, - Double2Str (WTMM( x + a + drawobj->offset2.x )) + "mm"); + mxList->addAttribute("svg:x1", sXML_CDATA, + OUString::number (WTMM(x + a + drawobj->offset2.x + drawobj->extent.w)) + "mm"); + mxList->addAttribute("svg:x2", sXML_CDATA, + OUString::number (WTMM( x + a + drawobj->offset2.x )) + "mm"); } else { - padd("svg:x1", sXML_CDATA, - Double2Str (WTMM( x + a + drawobj->offset2.x )) + "mm"); - padd("svg:x2", sXML_CDATA, - Double2Str (WTMM(x + a + drawobj->offset2.x + drawobj->extent.w)) + "mm"); + mxList->addAttribute("svg:x1", sXML_CDATA, + OUString::number (WTMM( x + a + drawobj->offset2.x )) + "mm"); + mxList->addAttribute("svg:x2", sXML_CDATA, + OUString::number (WTMM(x + a + drawobj->offset2.x + drawobj->extent.w)) + "mm"); } if( drawobj->u.line_arc.flip & 0x02 ) { - padd("svg:y1", sXML_CDATA, - Double2Str (WTMM( y + b + drawobj->offset2.y + drawobj->extent.h ) ) + "mm"); - padd("svg:y2", sXML_CDATA, - Double2Str (WTMM( y + b + drawobj->offset2.y )) + "mm"); + mxList->addAttribute("svg:y1", sXML_CDATA, + OUString::number (WTMM( y + b + drawobj->offset2.y + drawobj->extent.h ) ) + "mm"); + mxList->addAttribute("svg:y2", sXML_CDATA, + OUString::number (WTMM( y + b + drawobj->offset2.y )) + "mm"); } else { - padd("svg:y1", sXML_CDATA, - Double2Str (WTMM( y + b + drawobj->offset2.y)) + "mm"); - padd("svg:y2", sXML_CDATA, - Double2Str (WTMM(y + b + drawobj->offset2.y + drawobj->extent.h)) + "mm"); + mxList->addAttribute("svg:y1", sXML_CDATA, + OUString::number (WTMM( y + b + drawobj->offset2.y)) + "mm"); + mxList->addAttribute("svg:y2", sXML_CDATA, + OUString::number (WTMM(y + b + drawobj->offset2.y + drawobj->extent.h)) + "mm"); } - rstartEl("draw:line", mxList); + startEl("draw:line"); mxList->clear(); - rendEl("draw:line"); + endEl("draw:line"); break; case HWPDO_RECT: /* rectangle - the starting position, vertical/horizontal */ if( !bIsRotate ) { - padd("svg:x", sXML_CDATA, - Double2Str (WTMM( x + a + drawobj->offset2.x)) + "mm"); - padd("svg:y", sXML_CDATA, - Double2Str (WTMM( y + b + drawobj->offset2.y)) + "mm"); + mxList->addAttribute("svg:x", sXML_CDATA, + OUString::number (WTMM( x + a + drawobj->offset2.x)) + "mm"); + mxList->addAttribute("svg:y", sXML_CDATA, + OUString::number (WTMM( y + b + drawobj->offset2.y)) + "mm"); } - padd("svg:width", sXML_CDATA, - Double2Str (WTMM( drawobj->extent.w )) + "mm"); - padd("svg:height", sXML_CDATA, - Double2Str (WTMM( drawobj->extent.h )) + "mm"); + mxList->addAttribute("svg:width", sXML_CDATA, + OUString::number (WTMM( drawobj->extent.w )) + "mm"); + mxList->addAttribute("svg:height", sXML_CDATA, + OUString::number (WTMM( drawobj->extent.h )) + "mm"); if( drawobj->property.flag & 0x01 ) { int value = drawobj->extent.w < drawobj->extent.h ? drawobj->extent.w : drawobj->extent.h ; - padd("draw:corner-radius", sXML_CDATA, - Double2Str (WTMM( value/10 )) + "mm"); + mxList->addAttribute("draw:corner-radius", sXML_CDATA, + OUString::number (WTMM( value/10 )) + "mm"); } else if( drawobj->property.flag & 0x04 ) { int value = drawobj->extent.w < drawobj->extent.h ? drawobj->extent.w : drawobj->extent.h ; - padd("draw:corner-radius", sXML_CDATA, - Double2Str (WTMM( value / 2)) + "mm"); + mxList->addAttribute("draw:corner-radius", sXML_CDATA, + OUString::number (WTMM( value / 2)) + "mm"); } - rstartEl("draw:rect", mxList); + startEl("draw:rect"); mxList->clear(); if( (drawobj->property.flag & HWPDO_FLAG_AS_TEXTBOX) && drawobj->property.pPara ) // As Textbox @@ -4165,42 +4078,46 @@ void HwpReader::makePictureDRAW(HWPDrawingObject *drawobj, Picture * hbox) pPara = pPara->Next(); } } - rendEl("draw:rect"); + endEl("draw:rect"); break; case HWPDO_ELLIPSE: /* Ellipse - the starting position, vertical/horizontal */ case HWPDO_ADVANCED_ELLIPSE: /* modified ellipse */ { if( !bIsRotate ) { - padd("svg:x", sXML_CDATA, - Double2Str (WTMM( x + a + drawobj->offset2.x)) + "mm"); - padd("svg:y", sXML_CDATA, - Double2Str (WTMM( y + b + drawobj->offset2.y)) + "mm"); + mxList->addAttribute("svg:x", sXML_CDATA, + OUString::number (WTMM( x + a + drawobj->offset2.x)) + "mm"); + mxList->addAttribute("svg:y", sXML_CDATA, + OUString::number (WTMM( y + b + drawobj->offset2.y)) + "mm"); } - padd("svg:width", sXML_CDATA, - Double2Str (WTMM( drawobj->extent.w )) + "mm"); - padd("svg:height", sXML_CDATA, - Double2Str (WTMM( drawobj->extent.h )) + "mm"); + mxList->addAttribute("svg:width", sXML_CDATA, + OUString::number (WTMM( drawobj->extent.w )) + "mm"); + mxList->addAttribute("svg:height", sXML_CDATA, + OUString::number (WTMM( drawobj->extent.h )) + "mm"); if( drawobj->type == HWPDO_ADVANCED_ELLIPSE ){ - if( drawobj->u.arc.radial[0].x != drawobj->u.arc.radial[1].x - || drawobj->u.arc.radial[0].y != drawobj->u.arc.radial[1].y ){ - int Cx,Cy; - Cx = ( drawobj->offset2.x + drawobj->extent.w ) / 2; - Cy = ( drawobj->offset2.y + drawobj->extent.h ) / 2; - - double start_angle, end_angle; - start_angle = calcAngle( Cx, Cy, drawobj->u.arc.radial[0].x, drawobj->u.arc.radial[0].y ); - end_angle = calcAngle( Cx, Cy, drawobj->u.arc.radial[1].x, drawobj->u.arc.radial[1].y ); - if( drawobj->property.fill_color < 0xffffff ) - padd("draw:kind", sXML_CDATA, "section"); - else - padd("draw:kind", sXML_CDATA, "arc"); - padd("draw:start-angle", sXML_CDATA, Double2Str(start_angle )); - padd("draw:end-angle", sXML_CDATA, Double2Str(end_angle)); - } + if (drawobj->u.arc.radial[0].x != drawobj->u.arc.radial[1].x || + drawobj->u.arc.radial[0].y != drawobj->u.arc.radial[1].y) { + + int Cx, Cy; + if (!o3tl::checked_add(drawobj->offset2.x, drawobj->extent.w, Cx) && + !o3tl::checked_add(drawobj->offset2.y, drawobj->extent.h, Cy)) + { + Cx /= 2; + Cy /= 2; + + double start_angle = calcAngle( Cx, Cy, drawobj->u.arc.radial[0].x, drawobj->u.arc.radial[0].y ); + double end_angle = calcAngle( Cx, Cy, drawobj->u.arc.radial[1].x, drawobj->u.arc.radial[1].y ); + if( drawobj->property.fill_color < 0xffffff ) + mxList->addAttribute("draw:kind", sXML_CDATA, "section"); + else + mxList->addAttribute("draw:kind", sXML_CDATA, "arc"); + mxList->addAttribute("draw:start-angle", sXML_CDATA, OUString::number(start_angle )); + mxList->addAttribute("draw:end-angle", sXML_CDATA, OUString::number(end_angle)); + } + } } - rstartEl("draw:ellipse", mxList); + startEl("draw:ellipse"); mxList->clear(); if( drawobj->property.flag >> 19 & 0x01 && drawobj->property.pPara ) // As Textbox @@ -4213,7 +4130,7 @@ void HwpReader::makePictureDRAW(HWPDrawingObject *drawobj, Picture * hbox) pPara = pPara->Next(); } } - rendEl("draw:ellipse"); + endEl("draw:ellipse"); break; } @@ -4225,69 +4142,66 @@ void HwpReader::makePictureDRAW(HWPDrawingObject *drawobj, Picture * hbox) if( !bIsRotate ) { if( ( flip == 0 || flip == 2 ) && drawobj->type == HWPDO_ARC) - padd("svg:x", sXML_CDATA, - Double2Str (WTMM( x + a + drawobj->offset2.x - drawobj->extent.w)) + "mm"); + mxList->addAttribute("svg:x", sXML_CDATA, + OUString::number (WTMM( x + a + drawobj->offset2.x - drawobj->extent.w)) + "mm"); else - padd("svg:x", sXML_CDATA, - Double2Str (WTMM( x + a + drawobj->offset2.x)) + "mm"); + mxList->addAttribute("svg:x", sXML_CDATA, + OUString::number (WTMM( x + a + drawobj->offset2.x)) + "mm"); if( ( flip == 0 || flip == 1 ) && drawobj->type == HWPDO_ARC) - padd("svg:y", sXML_CDATA, - Double2Str (WTMM( y + b + drawobj->offset2.y - drawobj->extent.h)) + "mm"); + mxList->addAttribute("svg:y", sXML_CDATA, + OUString::number (WTMM( y + b + drawobj->offset2.y - drawobj->extent.h)) + "mm"); else - padd("svg:y", sXML_CDATA, - Double2Str (WTMM( y + b + drawobj->offset2.y)) + "mm"); + mxList->addAttribute("svg:y", sXML_CDATA, + OUString::number (WTMM( y + b + drawobj->offset2.y)) + "mm"); } - padd("svg:width", sXML_CDATA, - Double2Str (WTMM( drawobj->extent.w * 2)) + "mm"); - padd("svg:height", sXML_CDATA, - Double2Str (WTMM( drawobj->extent.h * 2)) + "mm"); + mxList->addAttribute("svg:width", sXML_CDATA, + OUString::number (WTMM( drawobj->extent.w * 2)) + "mm"); + mxList->addAttribute("svg:height", sXML_CDATA, + OUString::number (WTMM( drawobj->extent.h * 2)) + "mm"); if( drawobj->property.flag & HWPDO_FLAG_DRAW_PIE || drawobj->property.fill_color < 0xffffff ) - padd("draw:kind", sXML_CDATA, "section"); + mxList->addAttribute("draw:kind", sXML_CDATA, "section"); else - padd("draw:kind", sXML_CDATA, "arc"); + mxList->addAttribute("draw:kind", sXML_CDATA, "arc"); if( drawobj->type == HWPDO_ADVANCED_ARC ){ double start_angle, end_angle; - ZZParall *pal = &drawobj->property.parall; + ZZParall& pal = drawobj->property.parall; - start_angle = atan2(pal->pt[0].y - pal->pt[1].y,pal->pt[1].x - pal->pt[0].x ); - end_angle = atan2(pal->pt[2].y - pal->pt[1].y, pal->pt[1].x - pal->pt[2].x); + start_angle = atan2(pal.pt[0].y - pal.pt[1].y,pal.pt[1].x - pal.pt[0].x ); + end_angle = atan2(pal.pt[2].y - pal.pt[1].y, pal.pt[1].x - pal.pt[2].x); - if( ( start_angle > end_angle ) && (start_angle - end_angle < M_PI )){ - double tmp_angle = start_angle; - start_angle = end_angle; - end_angle = tmp_angle; - } - padd("draw:start-angle", sXML_CDATA, Double2Str(basegfx::rad2deg(start_angle))); - padd("draw:end-angle", sXML_CDATA, Double2Str(basegfx::rad2deg(end_angle))); + if( ( start_angle > end_angle ) && (start_angle - end_angle < M_PI )) + std::swap( start_angle, end_angle ); + mxList->addAttribute("draw:start-angle", sXML_CDATA, OUString::number(basegfx::rad2deg(start_angle))); + mxList->addAttribute("draw:end-angle", sXML_CDATA, OUString::number(basegfx::rad2deg(end_angle))); } else { if( drawobj->u.line_arc.flip == 0 ) { - padd("draw:start-angle", sXML_CDATA, "270"); - padd("draw:end-angle", sXML_CDATA, "0"); + mxList->addAttribute("draw:start-angle", sXML_CDATA, "270"); + mxList->addAttribute("draw:end-angle", sXML_CDATA, "0"); } else if( drawobj->u.line_arc.flip == 1 ) { - padd("draw:start-angle", sXML_CDATA, "180"); - padd("draw:end-angle", sXML_CDATA, "270"); + mxList->addAttribute("draw:start-angle", sXML_CDATA, "180"); + mxList->addAttribute("draw:end-angle", sXML_CDATA, "270"); } else if( drawobj->u.line_arc.flip == 2 ) { - padd("draw:start-angle", sXML_CDATA, "0"); - padd("draw:end-angle", sXML_CDATA, "90"); + mxList->addAttribute("draw:start-angle", sXML_CDATA, "0"); + mxList->addAttribute("draw:end-angle", sXML_CDATA, "90"); } else { - padd("draw:start-angle", sXML_CDATA, "90"); - padd("draw:end-angle", sXML_CDATA, "180"); + mxList->addAttribute("draw:start-angle", sXML_CDATA, "90"); + mxList->addAttribute("draw:end-angle", sXML_CDATA, "180"); } } - rstartEl("draw:ellipse", mxList); + startEl("draw:ellipse"); mxList->clear(); if( drawobj->property.flag >> 19 & 0x01 && drawobj->property.pPara ) // As Textbox @@ -4300,7 +4214,7 @@ void HwpReader::makePictureDRAW(HWPDrawingObject *drawobj, Picture * hbox) pPara = pPara->Next(); } } - rendEl("draw:ellipse"); + endEl("draw:ellipse"); break; } @@ -4312,17 +4226,19 @@ void HwpReader::makePictureDRAW(HWPDrawingObject *drawobj, Picture * hbox) } if( !bIsRotate ) { - padd("svg:x", sXML_CDATA, - Double2Str (WTMM( x + a + drawobj->offset2.x)) + "mm"); - padd("svg:y", sXML_CDATA, - Double2Str (WTMM( y + b + drawobj->offset2.y)) + "mm"); + mxList->addAttribute("svg:x", sXML_CDATA, + OUString::number (WTMM( x + a + drawobj->offset2.x)) + "mm"); + mxList->addAttribute("svg:y", sXML_CDATA, + OUString::number (WTMM( y + b + drawobj->offset2.y)) + "mm"); } - padd("svg:width", sXML_CDATA, - Double2Str (WTMM( drawobj->extent.w )) + "mm"); - padd("svg:height", sXML_CDATA, - Double2Str (WTMM( drawobj->extent.h )) + "mm"); - sprintf(buf, "0 0 %d %d", WTSM(drawobj->extent.w) , WTSM(drawobj->extent.h) ); - padd("svg:viewBox", sXML_CDATA, ascii(buf) ); + mxList->addAttribute("svg:width", sXML_CDATA, + OUString::number (WTMM( drawobj->extent.w )) + "mm"); + mxList->addAttribute("svg:height", sXML_CDATA, + OUString::number (WTMM( drawobj->extent.h )) + "mm"); + mxList->addAttribute( + "svg:viewBox", sXML_CDATA, + "0 0 " + OUString::number(WTSM(drawobj->extent.w)) + " " + + OUString::number(WTSM(drawobj->extent.h))); OUStringBuffer oustr; @@ -4368,30 +4284,35 @@ void HwpReader::makePictureDRAW(HWPDrawingObject *drawobj, Picture * hbox) NaturalSpline(n, tarr.get(), yarr.get(), yb, carr, darr); } - sprintf(buf, "M%d %dC%d %d", WTSM(xarr[0]), WTSM(yarr[0]), - WTSM(xarr[0] + xb[0]/3), WTSM(yarr[0] + yb[0]/3) ); - oustr.append(ascii(buf)); + oustr.append( + "M" + OUString::number(WTSM(xarr[0])) + " " + + OUString::number(WTSM(yarr[0])) + "C" + + OUString::number(WTSM(xarr[0] + xb[0]/3)) + " " + + OUString::number(WTSM(yarr[0] + yb[0]/3))); for( i = 1 ; i < n ; i++ ){ if( i == n -1 ){ - sprintf(buf, " %d %d %d %dz", - WTSM(xarr[i] - xb[i]/3), WTSM(yarr[i] - yb[i]/3), - WTSM(xarr[i]), WTSM(yarr[i]) ); + oustr.append( + " " + OUString::number(WTSM(xarr[i] - xb[i]/3)) + " " + + OUString::number(WTSM(yarr[i] - yb[i]/3)) + " " + + OUString::number(WTSM(xarr[i])) + " " + + OUString::number(WTSM(yarr[i])) + "z"); } else{ - sprintf(buf, " %d %d %d %d %d %d", - WTSM(xarr[i] - xb[i]/3), WTSM(yarr[i] - yb[i]/3), - WTSM(xarr[i]), WTSM(yarr[i]), - WTSM(xarr[i] + xb[i]/3), WTSM(yarr[i] + yb[i]/3) ); + oustr.append( + " " + OUString::number(WTSM(xarr[i] - xb[i]/3)) + " " + + OUString::number(WTSM(yarr[i] - yb[i]/3)) + " " + + OUString::number(WTSM(xarr[i])) + " " + + OUString::number(WTSM(yarr[i])) + " " + + OUString::number(WTSM(xarr[i] + xb[i]/3)) + " " + + OUString::number(WTSM(yarr[i] + yb[i]/3))); } - - oustr.append(ascii(buf)); } } - padd("svg:d", sXML_CDATA, oustr.makeStringAndClear()); + mxList->addAttribute("svg:d", sXML_CDATA, oustr.makeStringAndClear()); - rstartEl("draw:path", mxList); + startEl("draw:path"); mxList->clear(); // As Textbox if( drawobj->property.flag >> 19 & 0x01 && drawobj->property.pPara ) @@ -4403,7 +4324,7 @@ void HwpReader::makePictureDRAW(HWPDrawingObject *drawobj, Picture * hbox) pPara = pPara->Next(); } } - rendEl("draw:path"); + endEl("draw:path"); break; } case HWPDO_CLOSED_FREEFORM: @@ -4411,32 +4332,31 @@ void HwpReader::makePictureDRAW(HWPDrawingObject *drawobj, Picture * hbox) { bool bIsPolygon = false; - padd("svg:x", sXML_CDATA, - Double2Str (WTMM( x + a + drawobj->offset2.x)) + "mm"); - padd("svg:y", sXML_CDATA, - Double2Str (WTMM( y + b + drawobj->offset2.y)) + "mm"); + mxList->addAttribute("svg:x", sXML_CDATA, + OUString::number (WTMM( x + a + drawobj->offset2.x)) + "mm"); + mxList->addAttribute("svg:y", sXML_CDATA, + OUString::number (WTMM( y + b + drawobj->offset2.y)) + "mm"); - padd("svg:width", sXML_CDATA, - Double2Str (WTMM( drawobj->extent.w )) + "mm"); - padd("svg:height", sXML_CDATA, - Double2Str (WTMM( drawobj->extent.h )) + "mm"); + mxList->addAttribute("svg:width", sXML_CDATA, + OUString::number (WTMM( drawobj->extent.w )) + "mm"); + mxList->addAttribute("svg:height", sXML_CDATA, + OUString::number (WTMM( drawobj->extent.h )) + "mm"); - sprintf(buf, "0 0 %d %d", WTSM(drawobj->extent.w), WTSM(drawobj->extent.h)); - padd("svg:viewBox", sXML_CDATA, ascii(buf) ); + mxList->addAttribute("svg:viewBox", sXML_CDATA, "0 0 " + OUString::number(WTSM(drawobj->extent.w)) + " " + OUString::number(WTSM(drawobj->extent.h))); OUStringBuffer oustr; if (drawobj->u.freeform.npt > 0) { - sprintf(buf, "%d,%d", WTSM(drawobj->u.freeform.pt[0].x), WTSM(drawobj->u.freeform.pt[0].y)); - oustr.append(ascii(buf)); + oustr.append( + OUString::number(WTSM(drawobj->u.freeform.pt[0].x)) + "," + + OUString::number(WTSM(drawobj->u.freeform.pt[0].y))); int i; for (i = 1; i < drawobj->u.freeform.npt ; i++) { - sprintf(buf, " %d,%d", - WTSM(drawobj->u.freeform.pt[i].x), - WTSM(drawobj->u.freeform.pt[i].y)); - oustr.append(ascii(buf)); + oustr.append( + " " + OUString::number(WTSM(drawobj->u.freeform.pt[i].x)) + "," + + OUString::number(WTSM(drawobj->u.freeform.pt[i].y))); } if( drawobj->u.freeform.pt[0].x == drawobj->u.freeform.pt[i-1].x && drawobj->u.freeform.pt[0].y == drawobj->u.freeform.pt[i-1].y ) @@ -4444,7 +4364,7 @@ void HwpReader::makePictureDRAW(HWPDrawingObject *drawobj, Picture * hbox) bIsPolygon = true; } } - padd("draw:points", sXML_CDATA, oustr.makeStringAndClear()); + mxList->addAttribute("draw:points", sXML_CDATA, oustr.makeStringAndClear()); if( drawobj->property.fill_color <= 0xffffff || drawobj->property.pattern_type != 0) @@ -4454,7 +4374,7 @@ void HwpReader::makePictureDRAW(HWPDrawingObject *drawobj, Picture * hbox) if(bIsPolygon) { - rstartEl("draw:polygon", mxList); + startEl("draw:polygon"); mxList->clear(); if( drawobj->property.flag >> 19 & 0x01 && // As Textbox @@ -4468,11 +4388,11 @@ void HwpReader::makePictureDRAW(HWPDrawingObject *drawobj, Picture * hbox) pPara = pPara->Next(); } } - rendEl("draw:polygon"); + endEl("draw:polygon"); } else { - rstartEl("draw:polyline", mxList); + startEl("draw:polyline"); mxList->clear(); if( drawobj->property.flag >> 19 & 0x01 && // As Textbox @@ -4486,38 +4406,38 @@ void HwpReader::makePictureDRAW(HWPDrawingObject *drawobj, Picture * hbox) pPara = pPara->Next(); } } - rendEl("draw:polyline"); + endEl("draw:polyline"); } break; } case HWPDO_TEXTBOX: if( !bIsRotate ) { - padd("svg:x", sXML_CDATA, - Double2Str (WTMM( x + a + drawobj->offset2.x)) + "mm"); - padd("svg:y", sXML_CDATA, - Double2Str (WTMM( y + b + drawobj->offset2.y)) + "mm"); + mxList->addAttribute("svg:x", sXML_CDATA, + OUString::number (WTMM( x + a + drawobj->offset2.x)) + "mm"); + mxList->addAttribute("svg:y", sXML_CDATA, + OUString::number (WTMM( y + b + drawobj->offset2.y)) + "mm"); } - padd("svg:width", sXML_CDATA, - Double2Str (WTMM( drawobj->extent.w )) + "mm"); - padd("svg:height", sXML_CDATA, - Double2Str (WTMM( drawobj->extent.h )) + "mm"); + mxList->addAttribute("svg:width", sXML_CDATA, + OUString::number (WTMM( drawobj->extent.w )) + "mm"); + mxList->addAttribute("svg:height", sXML_CDATA, + OUString::number (WTMM( drawobj->extent.h )) + "mm"); if( drawobj->property.flag & 0x01 ) { int value = drawobj->extent.w < drawobj->extent.h ? drawobj->extent.w : drawobj->extent.h ; - padd("draw:corner-radius", sXML_CDATA, - Double2Str (WTMM( value/10 )) + "mm"); + mxList->addAttribute("draw:corner-radius", sXML_CDATA, + OUString::number (WTMM( value/10 )) + "mm"); } else if( drawobj->property.flag & 0x04 ) { int value = drawobj->extent.w < drawobj->extent.h ? drawobj->extent.w : drawobj->extent.h ; - padd("draw:corner-radius", sXML_CDATA, - Double2Str (WTMM( value / 2)) + "mm"); + mxList->addAttribute("draw:corner-radius", sXML_CDATA, + OUString::number (WTMM( value / 2)) + "mm"); } - rstartEl("draw:text-box", mxList); + startEl("draw:text-box"); mxList->clear(); HWPPara *pPara = drawobj->u.textbox.h; @@ -4528,7 +4448,7 @@ void HwpReader::makePictureDRAW(HWPDrawingObject *drawobj, Picture * hbox) pPara = pPara->Next(); } - rendEl("draw:text-box"); + endEl("draw:text-box"); break; } } @@ -4537,15 +4457,13 @@ void HwpReader::makePictureDRAW(HWPDrawingObject *drawobj, Picture * hbox) } } - void HwpReader::makeLine() { - padd("text:style-name", sXML_CDATA, "Horizontal Line"); - rstartEl( "text:p", mxList); + mxList->addAttribute("text:style-name", sXML_CDATA, "Horizontal Line"); + startEl("text:p"); mxList->clear(); } - /** * Input-comment-hidden description: shows a hidden explanation to the users. * Parse out only strings, but it may contain paragraphs. @@ -4556,18 +4474,20 @@ void HwpReader::makeHidden(Hidden * hbox) int res; hchar dest[3]; - padd("text:condition", sXML_CDATA, ""); - padd("text:string-value", sXML_CDATA, ""); - rstartEl("text:hidden-text", mxList); + mxList->addAttribute("text:condition", sXML_CDATA, ""); + mxList->addAttribute("text:string-value", sXML_CDATA, ""); + startEl("text:hidden-text"); mxList->clear(); - HWPPara *para = hbox->plist.front().get(); + HWPPara *para = !hbox->plist.empty() ? hbox->plist.front().get() : nullptr; while (para) { - for (int n = 0; n < para->nch && para->hhstr[n]->hh; - n += para->hhstr[n]->WSize()) + for (const auto& box : para->hhstr) { - res = hcharconv(para->hhstr[n]->hh, dest, UNICODE); + if (!box->hh) + break; + + res = hcharconv(box->hh, dest, UNICODE); for( int j = 0 ; j < res ; j++ ) { str.push_back(dest[j]); @@ -4576,7 +4496,7 @@ void HwpReader::makeHidden(Hidden * hbox) para = para->Next(); } makeChars(str); - rendEl("text:hidden-text"); + endEl("text:hidden-text"); } @@ -4587,37 +4507,35 @@ void HwpReader::makeFootnote(Footnote * hbox) { if (hbox->type) { - padd("text:id", sXML_CDATA, - ascii(Int2Str(hbox->number, "edn%d", buf))); - rstartEl("text:endnote", mxList); + mxList->addAttribute("text:id", sXML_CDATA, "edn" + OUString::number(hbox->number)); + startEl("text:endnote"); mxList->clear(); - padd("text:label", sXML_CDATA, - ascii(Int2Str(hbox->number, "%d", buf))); - rstartEl("text:endnote-citation", mxList); + mxList->addAttribute("text:label", sXML_CDATA, OUString::number(hbox->number)); + startEl("text:endnote-citation"); mxList->clear(); - rchars(ascii(Int2Str(hbox->number, "%d", buf))); - rendEl("text:endnote-citation"); - rstartEl("text:endnote-body", mxList); - parsePara(hbox->plist.front().get()); - rendEl("text:endnote-body"); - rendEl("text:endnote"); + chars(OUString::number(hbox->number)); + endEl("text:endnote-citation"); + startEl("text:endnote-body"); + if (!hbox->plist.empty()) + parsePara(hbox->plist.front().get()); + endEl("text:endnote-body"); + endEl("text:endnote"); } else { - padd("text:id", sXML_CDATA, - ascii(Int2Str(hbox->number, "ftn%d", buf))); - rstartEl("text:footnote", mxList); + mxList->addAttribute("text:id", sXML_CDATA, "ftn" + OUString::number(hbox->number)); + startEl("text:footnote"); mxList->clear(); - padd("text:label", sXML_CDATA, - ascii(Int2Str(hbox->number, "%d", buf))); - rstartEl("text:footnote-citation", mxList); + mxList->addAttribute("text:label", sXML_CDATA, OUString::number(hbox->number)); + startEl("text:footnote-citation"); mxList->clear(); - rchars(ascii(Int2Str(hbox->number, "%d", buf))); - rendEl("text:footnote-citation"); - rstartEl("text:footnote-body", mxList); - parsePara(hbox->plist.front().get()); - rendEl("text:footnote-body"); - rendEl("text:footnote"); + chars(OUString::number(hbox->number)); + endEl("text:footnote-citation"); + startEl("text:footnote-body"); + if (!hbox->plist.empty()) + parsePara(hbox->plist.front().get()); + endEl("text:footnote-body"); + endEl("text:footnote"); } } @@ -4630,9 +4548,9 @@ void HwpReader::makeAutoNum(AutoNum const * hbox) switch (hbox->type) { case PGNUM_AUTO: - rstartEl("text:page-number", mxList); - rchars(ascii(Int2Str(hbox->number, "%d", buf))); - rendEl("text:page-number"); + startEl("text:page-number"); + chars(OUString::number(hbox->number)); + endEl("text:page-number"); break; case FNNUM_AUTO: break; @@ -4640,22 +4558,20 @@ void HwpReader::makeAutoNum(AutoNum const * hbox) break; case EQUNUM_AUTO: case PICNUM_AUTO: - padd("text:ref-name",sXML_CDATA, - ascii(Int2Str(hbox->number, "refIllustration%d", buf))); - padd("text:name",sXML_CDATA, "Illustration"); - padd("style:num-format",sXML_CDATA, "1"); - rstartEl("text:sequence", mxList); - rchars(ascii(Int2Str(hbox->number, "%d", buf))); - rendEl("text:sequence"); + mxList->addAttribute("text:ref-name",sXML_CDATA, "refIllustration" + OUString::number(hbox->number)); + mxList->addAttribute("text:name",sXML_CDATA, "Illustration"); + mxList->addAttribute("style:num-format",sXML_CDATA, "1"); + startEl("text:sequence"); + chars(OUString::number(hbox->number)); + endEl("text:sequence"); break; case TBLNUM_AUTO: - padd("text:ref-name",sXML_CDATA, - ascii(Int2Str(hbox->number, "refTable%d", buf))); - padd("text:name",sXML_CDATA, "Table"); - padd("style:num-format",sXML_CDATA, "1"); - rstartEl("text:sequence", mxList); - rchars(ascii(Int2Str(hbox->number, "%d", buf))); - rendEl("text:sequence"); + mxList->addAttribute("text:ref-name",sXML_CDATA, "refTable" + OUString::number(hbox->number)); + mxList->addAttribute("text:name",sXML_CDATA, "Table"); + mxList->addAttribute("style:num-format",sXML_CDATA, "1"); + startEl("text:sequence"); + chars(OUString::number(hbox->number)); + endEl("text:sequence"); break; } } @@ -4679,38 +4595,35 @@ void HwpReader::makeShowPageNum() nPos = 3; } - padd("draw:style-name", sXML_CDATA, - ascii(Int2Str(nPos, "PNBox%d", buf))); - padd("draw:name", sXML_CDATA, - ascii(Int2Str(nPos, "PageNumber%d", buf))); - padd("text:anchor-type", sXML_CDATA, "paragraph"); - padd("svg:y", sXML_CDATA, "0cm"); - padd("svg:width", sXML_CDATA, "2.0cm"); - padd("fo:min-height", sXML_CDATA, "0.5cm"); - rstartEl("draw:text-box", mxList); + mxList->addAttribute("draw:style-name", sXML_CDATA, "PNBox" + OUString::number(nPos)); + mxList->addAttribute("draw:name", sXML_CDATA, "PageNumber" + OUString::number(nPos)); + mxList->addAttribute("text:anchor-type", sXML_CDATA, "paragraph"); + mxList->addAttribute("svg:y", sXML_CDATA, "0cm"); + mxList->addAttribute("svg:width", sXML_CDATA, "2.0cm"); + mxList->addAttribute("fo:min-height", sXML_CDATA, "0.5cm"); + startEl("draw:text-box"); mxList->clear(); - padd("text:style-name", sXML_CDATA, - ascii(Int2Str(nPos, "PNPara%d", buf))); - rstartEl("text:p", mxList); + mxList->addAttribute("text:style-name", sXML_CDATA, "PNPara" + OUString::number(nPos)); + startEl("text:p"); mxList->clear(); if( hbox->shape > 2 ) - rchars("- "); + chars("- "); if( hbox->shape % 3 == 0 ) - padd("style:num-format", sXML_CDATA, "1"); + mxList->addAttribute("style:num-format", sXML_CDATA, "1"); else if( hbox->shape % 3 == 1 ) - padd("style:num-format", sXML_CDATA, "I"); + mxList->addAttribute("style:num-format", sXML_CDATA, "I"); else - padd("style:num-format", sXML_CDATA, "i"); - padd("text:select-page", sXML_CDATA, "current"); - rstartEl("text:page-number", mxList); + mxList->addAttribute("style:num-format", sXML_CDATA, "i"); + mxList->addAttribute("text:select-page", sXML_CDATA, "current"); + startEl("text:page-number"); mxList->clear(); - rchars("2"); - rendEl("text:page-number"); + chars("2"); + endEl("text:page-number"); if( hbox->shape > 2 ) - rchars(" -"); - rendEl("text:p"); - rendEl("draw:text-box"); + chars(" -"); + endEl("text:p"); + endEl("draw:text-box"); } @@ -4721,14 +4634,14 @@ void HwpReader::makeShowPageNum() void HwpReader::makeMailMerge(MailMerge *) { hchar_string const boxstr = MailMerge::GetString(); - rchars(fromHcharStringToOUString(hstr2ucsstr(boxstr.c_str()))); + chars(hstr2OUString(boxstr.c_str())); } void HwpReader::makeOutline(Outline const * hbox) { if( hbox->kind == 1 ) - rchars( fromHcharStringToOUString(hbox->GetUnicode()) ); + chars( hbox->GetUnicode() ); } @@ -4741,25 +4654,18 @@ void HwpReader::parsePara(HWPPara * para) { if( !bParaStart ) { - padd("text:style-name", sXML_CDATA, - ascii(getPStyleName(para->GetParaShape().index, buf))); - rstartEl( "text:p",mxList); + mxList->addAttribute("text:style-name", sXML_CDATA, + getPStyleName(para->GetParaShape().index)); + startEl("text:p"); mxList->clear(); } if( d->bFirstPara && d->bInBody ) { /* for HWP's Bookmark */ - strcpy( - buf, - "[\xEB\xAC\xB8\xEC\x84\x9C\xEC\x9D\x98" - " \xEC\xB2\x98\xEC\x9D\x8C]"); - // U+BB38 HANGUL SYLLABLE MUN, U+C11C HANGUL SYLLABLE SEO, - // U+C758 HANGUL SYLLABLE YI, U+CC98 HANGUL SYLLABLE CEO, - // U+C74C HANGUL SYLLABLE EUM: "Begin of Document" - padd("text:name", sXML_CDATA, OUString(buf, strlen(buf), RTL_TEXTENCODING_UTF8)); - rstartEl("text:bookmark", mxList); + mxList->addAttribute("text:name", sXML_CDATA, sBeginOfDoc); + startEl("text:bookmark"); mxList->clear(); - rendEl("text:bookmark"); + endEl("text:bookmark"); d->bFirstPara = false; } if( d->bInHeader ) @@ -4768,7 +4674,7 @@ void HwpReader::parsePara(HWPPara * para) d->bInHeader = false; } - rendEl( "text:p" ); + endEl("text:p"); } else { @@ -4788,12 +4694,33 @@ void HwpReader::parsePara(HWPPara * para) } +void HwpReader::startEl(const OUString& el) +{ + if (m_rxDocumentHandler) + m_rxDocumentHandler->startElement(el, mxList); +} + + +void HwpReader::endEl(const OUString& el) +{ + if (m_rxDocumentHandler) + m_rxDocumentHandler->endElement(el); +} + + +void HwpReader::chars(const OUString& s) +{ + if (m_rxDocumentHandler) + m_rxDocumentHandler->characters(s); +} + + namespace { constexpr OUStringLiteral IMPLEMENTATION_NAME = u"com.sun.comp.hwpimport.HwpImportFilter"; -constexpr OUStringLiteral SERVICE_NAME1 = u"com.sun.star.document.ImportFilter"; -constexpr OUStringLiteral SERVICE_NAME2 = u"com.sun.star.document.ExtendedTypeDetection"; +constexpr OUString SERVICE_NAME1 = u"com.sun.star.document.ImportFilter"_ustr; +constexpr OUString SERVICE_NAME2 = u"com.sun.star.document.ExtendedTypeDetection"_ustr; class HwpImportFilter : public WeakImplHelper< XFilter, XImporter, XServiceInfo, XExtendedFilterDetection > { @@ -4830,13 +4757,12 @@ HwpImportFilter::HwpImportFilter(const Reference< XComponentContext >& rxContext rtl::Reference<HwpReader> p = new HwpReader; p->setDocumentHandler( xHandler ); - Reference< XImporter > xImporter( xHandler, UNO_QUERY ); - rImporter = xImporter; + rImporter.set(xHandler, UNO_QUERY); rFilter = p; } catch( Exception & ) { - printf(" fail to instantiate %s\n", OUString(WRITER_IMPORTER_NAME).toUtf8().getStr() ); + printf(" fail to instantiate %s\n", WRITER_IMPORTER_NAME.toUtf8().getStr() ); exit( 1 ); } } diff --git a/hwpfilter/source/hwpreader.hxx b/hwpfilter/source/hwpreader.hxx index 91021a326186..4638ffb5aa57 100644 --- a/hwpfilter/source/hwpreader.hxx +++ b/hwpfilter/source/hwpreader.hxx @@ -17,12 +17,15 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_HWPFILTER_SOURCE_HWPREADER_HXX -#define INCLUDED_HWPFILTER_SOURCE_HWPREADER_HXX +#pragma once + +#include <sal/config.h> #include <errno.h> #include <stdio.h> #include <string.h> + +#include <rtl/ustring.hxx> #include <sal/alloca.h> #include <com/sun/star/lang/XServiceInfo.hpp> @@ -44,15 +47,6 @@ #include <cppuhelper/weak.hxx> #include <memory> -using namespace ::cppu; -using namespace ::com::sun::star::lang; -using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::io; -using namespace ::com::sun::star::registry; -using namespace ::com::sun::star::document; -using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::xml::sax; - #include <assert.h> #include <unotools/mediadescriptor.hxx> @@ -65,7 +59,16 @@ using namespace ::com::sun::star::xml::sax; #include "drawdef.h" #include "attributes.hxx" -inline constexpr OUStringLiteral WRITER_IMPORTER_NAME = u"com.sun.star.comp.Writer.XMLImporter"; +using namespace ::cppu; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::io; +using namespace ::com::sun::star::registry; +using namespace ::com::sun::star::document; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::xml::sax; + +inline constexpr OUString WRITER_IMPORTER_NAME = u"com.sun.star.comp.Writer.XMLImporter"_ustr; struct HwpReaderPrivate; /** @@ -73,7 +76,6 @@ struct HwpReaderPrivate; */ class HwpReader : public WeakImplHelper<XFilter> { - public: HwpReader(); virtual ~HwpReader() override; @@ -82,22 +84,26 @@ public: /** * parseStream does Parser-startup initializations */ - virtual sal_Bool SAL_CALL filter(const Sequence< PropertyValue >& aDescriptor) override; + virtual sal_Bool SAL_CALL filter(const Sequence<PropertyValue>& aDescriptor) override; virtual void SAL_CALL cancel() override {} - void setDocumentHandler(Reference< XDocumentHandler > const & xHandler) + void setDocumentHandler(Reference<XDocumentHandler> const& xHandler) { m_rxDocumentHandler = xHandler; } + + bool importHStream(std::unique_ptr<HStream> stream); + private: - Reference< XDocumentHandler > m_rxDocumentHandler; + Reference<XDocumentHandler> m_rxDocumentHandler; rtl::Reference<AttributeListImpl> mxList; HWPFile hwpfile; std::unique_ptr<HwpReaderPrivate> d; + private: /* -------- Document Parsing --------- */ void makeMeta(); void makeStyles(); - void makeDrawMiscStyle(HWPDrawingObject *); + void makeDrawMiscStyle(HWPDrawingObject*); void makeAutoStyles(); void makeMasterStyles(); void makeBody(); @@ -105,50 +111,51 @@ private: void makeTextDecls(); /* -------- Paragraph Parsing --------- */ - void parsePara(HWPPara *para); - void make_text_p0(HWPPara *para, bool bParaStart); - void make_text_p1(HWPPara *para, bool bParaStart); - void make_text_p3(HWPPara *para, bool bParaStart); + void parsePara(HWPPara* para); + void make_text_p0(HWPPara* para, bool bParaStart); + void make_text_p1(HWPPara* para, bool bParaStart); + void make_text_p3(HWPPara* para, bool bParaStart); /* -------- rDocument->characters(x) --------- */ - void makeChars(hchar_string & rStr); + void makeChars(hchar_string& rStr); /* -------- Special Char Parsing --------- */ - void makeFieldCode(hchar_string const & rStr, FieldCode const *hbox); //6 - void makeBookmark(Bookmark const *hbox); //6 - void makeDateFormat(DateCode *hbox); //7 - void makeDateCode(DateCode *hbox); //8 - void makeTab(); //9 - void makeTable(TxtBox *hbox); - void makeTextBox(TxtBox *hbox); - void makeFormula(TxtBox *hbox); - void makeHyperText(TxtBox *hbox); - void makePicture(Picture *hbox); - void makePictureDRAW(HWPDrawingObject *drawobj, Picture *hbox); + void makeFieldCode(hchar_string const& rStr, FieldCode const* hbox); //6 + void makeBookmark(Bookmark const* hbox); //6 + void makeDateFormat(DateCode* hbox); //7 + void makeDateCode(DateCode* hbox); //8 + void makeTab(); //9 + void makeTable(TxtBox* hbox); + void makeTextBox(TxtBox* hbox); + void makeFormula(TxtBox* hbox); + void makeHyperText(TxtBox* hbox); + void makePicture(Picture* hbox); + void makePictureDRAW(HWPDrawingObject* drawobj, const Picture* hbox); void makeLine(); - void makeHidden(Hidden *hbox); - void makeFootnote(Footnote *hbox); - void makeAutoNum(AutoNum const *hbox); + void makeHidden(Hidden* hbox); + void makeFootnote(Footnote* hbox); + void makeAutoNum(AutoNum const* hbox); void makeShowPageNum(); - void makeMailMerge(MailMerge *hbox); - void makeOutline(Outline const *hbox); + void makeMailMerge(MailMerge* hbox); + void makeOutline(Outline const* hbox); /* --------- Styles Parsing ------------ */ void makePageStyle(); - void makeColumns(ColumnDef const *); - void makeTStyle(CharShape const *); - void makePStyle(ParaShape const *); - void makeFStyle(FBoxStyle *); - void makeCaptionStyle(FBoxStyle *); - void makeDrawStyle(HWPDrawingObject *,FBoxStyle *); - void makeTableStyle(Table *); - void parseCharShape(CharShape const *); - void parseParaShape(ParaShape const *); - static char* getTStyleName(int, char *); - static char* getPStyleName(int, char *); + void makeColumns(ColumnDef const*); + void makeTStyle(CharShape const*); + void makePStyle(ParaShape const*); + void makeFStyle(FBoxStyle*); + void makeCaptionStyle(FBoxStyle*); + void makeDrawStyle(HWPDrawingObject*, FBoxStyle*); + void makeTableStyle(Table*); + void parseCharShape(CharShape const*); + void parseParaShape(ParaShape const*); + static OUString getTStyleName(int); + static OUString getPStyleName(int); + + void startEl(const OUString& el); + void endEl(const OUString& el); + void chars(const OUString& s); }; - -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/hwpfilter/source/lexer.cxx b/hwpfilter/source/lexer.cxx index 5d0cef7e2f9d..cb6ae3fc4b49 100644 --- a/hwpfilter/source/lexer.cxx +++ b/hwpfilter/source/lexer.cxx @@ -942,7 +942,6 @@ static char *yytext; #include "nodes.h" #ifdef _WIN32 -#define strdup _strdup #define fileno _fileno #define isatty _isatty #endif @@ -1167,91 +1166,91 @@ do_action: /* This label is used only to access EOF actions. */ case 1: YY_RULE_SETUP -{ yylval.str = yytext+1; token_debug(" ==>Begin[%s]\n",yytext+1); return EQBEGIN; } +{ yylval.str = yytext+1; token_debug(" ==>Begin[%s]\n",yytext+1); return Grammar::EQBEGIN; } //YY_BREAK case 2: YY_RULE_SETUP -{ yylval.str = yytext+1; token_debug(" ==>End[%s]\n",yytext+1); return EQEND; } +{ yylval.str = yytext+1; token_debug(" ==>End[%s]\n",yytext+1); return Grammar::EQEND; } //YY_BREAK case 3: YY_RULE_SETUP -{ yylval.str = yytext+1; token_debug(" ==>Left[%s]\n",yytext+1); return EQLEFT; } +{ yylval.str = yytext+1; token_debug(" ==>Left[%s]\n",yytext+1); return Grammar::EQLEFT; } //YY_BREAK case 4: YY_RULE_SETUP -{ yylval.str = yytext+1; token_debug(" ==>LeftDelim[%s]\n",yytext+1); return LEFT_DELIM; } +{ yylval.str = yytext+1; token_debug(" ==>LeftDelim[%s]\n",yytext+1); return Grammar::LEFT_DELIM; } //YY_BREAK case 5: YY_RULE_SETUP -{ yylval.str = yytext+1; token_debug(" ==>RightDelim[%s]\n",yytext+1); return RIGHT_DELIM; } +{ yylval.str = yytext+1; token_debug(" ==>RightDelim[%s]\n",yytext+1); return Grammar::RIGHT_DELIM; } //YY_BREAK case 6: YY_RULE_SETUP -{ yylval.str = yytext+1; token_debug(" ==>Right[%s]\n",yytext+1); return EQRIGHT; } +{ yylval.str = yytext+1; token_debug(" ==>Right[%s]\n",yytext+1); return Grammar::EQRIGHT; } //YY_BREAK case 7: YY_RULE_SETUP -{ yylval.str = yytext; token_debug(" ==>NewLine[%s]\n",yytext); return NEWLINE; } +{ yylval.str = yytext; token_debug(" ==>NewLine[%s]\n",yytext); return Grammar::NEWLINE; } //YY_BREAK case 8: YY_RULE_SETUP -{ yylval.str = yytext+1; token_debug(" ==>Accent[%s]\n",yytext+1); return ACCENT; } +{ yylval.str = yytext+1; token_debug(" ==>Accent[%s]\n",yytext+1); return Grammar::ACCENT; } //YY_BREAK case 9: YY_RULE_SETUP -{ yylval.str = yytext+1; token_debug(" ==>Small_Greek[%s]\n",yytext+1); return SMALL_GREEK; } +{ yylval.str = yytext+1; token_debug(" ==>Small_Greek[%s]\n",yytext+1); return Grammar::SMALL_GREEK; } //YY_BREAK case 10: YY_RULE_SETUP -{ yylval.str = yytext+1; token_debug(" ==>Capital_Greek[%s]\n",yytext+1); return CAPITAL_GREEK; } +{ yylval.str = yytext+1; token_debug(" ==>Capital_Greek[%s]\n",yytext+1); return Grammar::CAPITAL_GREEK; } //YY_BREAK case 11: YY_RULE_SETUP -{ yylval.str = yytext+1; token_debug(" ==>Binary_Operator[%s]\n",yytext+1); return BINARY_OPERATOR; } +{ yylval.str = yytext+1; token_debug(" ==>Binary_Operator[%s]\n",yytext+1); return Grammar::BINARY_OPERATOR; } //YY_BREAK case 12: YY_RULE_SETUP -{ yylval.str = yytext+1; token_debug(" ==>Relation_Symbol[%s]\n",yytext+1); return RELATION_OPERATOR; } +{ yylval.str = yytext+1; token_debug(" ==>Relation_Symbol[%s]\n",yytext+1); return Grammar::RELATION_OPERATOR; } //YY_BREAK case 13: YY_RULE_SETUP -{ yylval.str = strdup("neq"); token_debug(" ==>Relation_Symbol[neq]\n"); return RELATION_OPERATOR; } +{ yylval.str = "neq"; token_debug(" ==>Relation_Symbol[neq]\n"); return Grammar::RELATION_OPERATOR; } //YY_BREAK case 14: YY_RULE_SETUP -{ yylval.str = strdup("vmlt"); token_debug(" ==>Relation_Symbol[neq]\n"); return RELATION_OPERATOR; } +{ yylval.str = "vmlt"; token_debug(" ==>Relation_Symbol[neq]\n"); return Grammar::RELATION_OPERATOR; } //YY_BREAK case 15: YY_RULE_SETUP -{ yylval.str = strdup("vmgt"); token_debug(" ==>Relation_Symbol[neq]\n"); return RELATION_OPERATOR; } +{ yylval.str = "vmgt"; token_debug(" ==>Relation_Symbol[neq]\n"); return Grammar::RELATION_OPERATOR; } //YY_BREAK case 16: YY_RULE_SETUP -{ yylval.str = strdup("mlt"); token_debug(" ==>Relation_Symbol[neq]\n"); return RELATION_OPERATOR; } +{ yylval.str = "mlt"; token_debug(" ==>Relation_Symbol[neq]\n"); return Grammar::RELATION_OPERATOR; } //YY_BREAK case 17: YY_RULE_SETUP -{ yylval.str = strdup("mgt"); token_debug(" ==>Relation_Symbol[neq]\n"); return RELATION_OPERATOR; } +{ yylval.str = "mgt"; token_debug(" ==>Relation_Symbol[neq]\n"); return Grammar::RELATION_OPERATOR; } //YY_BREAK case 18: YY_RULE_SETUP -{ yylval.str = yytext; token_debug(" ==>Relation_Symbol[neq]\n"); return RELATION_OPERATOR; } +{ yylval.str = yytext; token_debug(" ==>Relation_Symbol[neq]\n"); return Grammar::RELATION_OPERATOR; } //YY_BREAK case 19: YY_RULE_SETUP -{ yylval.str = yytext+1; token_debug(" ==>Arrow[%s]\n",yytext+1); return ARROW; } +{ yylval.str = yytext+1; token_debug(" ==>Arrow[%s]\n",yytext+1); return Grammar::ARROW; } //YY_BREAK case 20: YY_RULE_SETUP -{ yylval.str = strdup("leftrightarrow"); token_debug(" ==>Arrow[leftrightarrow]\n"); return ARROW; } +{ yylval.str = "leftrightarrow"; token_debug(" ==>Arrow[leftrightarrow]\n"); return Grammar::ARROW; } //YY_BREAK case 21: YY_RULE_SETUP -{ yylval.str = strdup("rightarrow"); token_debug(" ==>Arrow[rightarrow]\n"); return ARROW; } +{ yylval.str = "rightarrow"; token_debug(" ==>Arrow[rightarrow]\n"); return Grammar::ARROW; } //YY_BREAK case 22: YY_RULE_SETUP -{ yylval.str = strdup("leftarrow"); token_debug(" ==>Arrow[leftarrow]\n"); return ARROW; } +{ yylval.str = "leftarrow"; token_debug(" ==>Arrow[leftarrow]\n"); return Grammar::ARROW; } //YY_BREAK case 23: @@ -1261,61 +1260,61 @@ YY_RULE_SETUP [[fallthrough]]; case 24: YY_RULE_SETUP -{ yylval.str = yytext+1; token_debug(" ==>General_Iden[%s]\n",yytext+1); return GENERAL_IDEN; } +{ yylval.str = yytext+1; token_debug(" ==>General_Iden[%s]\n",yytext+1); return Grammar::GENERAL_IDEN; } //YY_BREAK case 25: YY_RULE_SETUP -{ yylval.str = yytext+1; token_debug(" ==>General_Oper[%s]\n",yytext+1); return GENERAL_OPER; } +{ yylval.str = yytext+1; token_debug(" ==>General_Oper[%s]\n",yytext+1); return Grammar::GENERAL_OPER; } //YY_BREAK case 26: YY_RULE_SETUP -{ yylval.str = yytext+1; token_debug(" ==>Big_Symbol[%s]\n",yytext+1); return BIG_SYMBOL; } +{ yylval.str = yytext+1; token_debug(" ==>Big_Symbol[%s]\n",yytext+1); return Grammar::BIG_SYMBOL; } //YY_BREAK case 27: YY_RULE_SETUP -{ yylval.str = yytext+1; token_debug(" ==>Function[%s]\n",yytext+1); return FUNCTION; } +{ yylval.str = yytext+1; token_debug(" ==>Function[%s]\n",yytext+1); return Grammar::FUNCTION; } //YY_BREAK case 28: YY_RULE_SETUP -{ yylval.str = yytext+1; token_debug(" ==>Root[%s]\n",yytext+1); return ROOT; } +{ yylval.str = yytext+1; token_debug(" ==>Root[%s]\n",yytext+1); return Grammar::ROOT; } //YY_BREAK case 29: YY_RULE_SETUP -{ yylval.str = yytext+1; token_debug(" ==>Fraction[%s]\n",yytext+1); return FRACTION; } +{ yylval.str = yytext+1; token_debug(" ==>Fraction[%s]\n",yytext+1); return Grammar::FRACTION; } //YY_BREAK case 30: YY_RULE_SETUP -{ yylval.str = yytext+1; token_debug(" ==>Over[%s]\n",yytext+1); return EQOVER; } +{ yylval.str = yytext+1; token_debug(" ==>Over[%s]\n",yytext+1); return Grammar::EQOVER; } //YY_BREAK case 31: YY_RULE_SETUP -{ yylval.str = yytext+1; token_debug(" ==>Delimeter[%s]\n",yytext+1); return DELIMETER; } +{ yylval.str = yytext+1; token_debug(" ==>Delimeter[%s]\n",yytext+1); return Grammar::DELIMETER; } //YY_BREAK case 32: YY_RULE_SETUP -{ yylval.str = yytext+1; token_debug(" ==>Large_Delim[%s]\n",yytext+1); return LARGE_DELIM; } +{ yylval.str = yytext+1; token_debug(" ==>Large_Delim[%s]\n",yytext+1); return Grammar::LARGE_DELIM; } //YY_BREAK case 33: YY_RULE_SETUP -{ yylval.str = yytext+1; token_debug(" ==>Decoration[%s]\n",yytext+1); return DECORATION; } +{ yylval.str = yytext+1; token_debug(" ==>Decoration[%s]\n",yytext+1); return Grammar::DECORATION; } //YY_BREAK case 34: YY_RULE_SETUP -{ yylval.str = yytext+1; token_debug(" ==>Space_Symbol[%s]\n",yytext+1); /*return SPACE_SYMBOL;*/ } +{ yylval.str = yytext+1; token_debug(" ==>Space_Symbol[%s]\n",yytext+1); /*return Grammar::SPACE_SYMBOL;*/ } //YY_BREAK [[fallthrough]]; case 35: YY_RULE_SETUP -{ yylval.str = strdup("quad"); token_debug(" ==>Space_Symbol[quad]\n"); /* return SPACE_SYMBOL;*/ } +{ yylval.str = "quad"; token_debug(" ==>Space_Symbol[quad]\n"); /* return Grammar::SPACE_SYMBOL;*/ } //YY_BREAK [[fallthrough]]; case 36: YY_RULE_SETUP -{ yylval.dval = yytext; token_debug(" ==>Digit[%s]\n",yytext); return DIGIT; } +{ yylval.dval = yytext; token_debug(" ==>Digit[%s]\n",yytext); return Grammar::DIGIT; } //YY_BREAK case 37: YY_RULE_SETUP -{ yylval.str = yytext; token_debug(" ==>Operator[%s]\n",yytext); return OPERATOR; } +{ yylval.str = yytext; token_debug(" ==>Operator[%s]\n",yytext); return Grammar::OPERATOR; } //YY_BREAK case 38: YY_RULE_SETUP @@ -1339,11 +1338,11 @@ YY_RULE_SETUP YY_BREAK case 43: YY_RULE_SETUP -{ yylval.str = yytext; token_debug(" ==>String[%s]\n",yytext); return STRING; } +{ yylval.str = yytext; token_debug(" ==>String[%s]\n",yytext); return Grammar::STRING; } //YY_BREAK case 44: YY_RULE_SETUP -{ yylval.str = yytext; token_debug(" ==>Else[%s]\n",yytext); return CHARACTER; } +{ yylval.str = yytext; token_debug(" ==>Else[%s]\n",yytext); return Grammar::CHARACTER; } //YY_BREAK case 45: YY_RULE_SETUP @@ -2107,6 +2106,13 @@ void initFlex(const char *_code ) yy_switch_to_buffer( yy_scan_string(_code) ); } +void deinitFlex() +{ + // flex faq-memory-leak + yy_delete_buffer(YY_CURRENT_BUFFER); + yy_init = 1; +} + int yywrap() { yy_delete_buffer( YY_CURRENT_BUFFER ); diff --git a/hwpfilter/source/lexer.hxx b/hwpfilter/source/lexer.hxx index 0f0c1fe1525e..41835f13b51a 100644 --- a/hwpfilter/source/lexer.hxx +++ b/hwpfilter/source/lexer.hxx @@ -17,13 +17,11 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_HWPFILTER_SOURCE_LEXER_HXX -#define INCLUDED_HWPFILTER_SOURCE_LEXER_HXX +#pragma once void initFlex(char const* s); +void deinitFlex(); int yylex(); -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/hwpfilter/source/mapping.h b/hwpfilter/source/mapping.h index 2b573cb80e8b..5235f7e777d5 100644 --- a/hwpfilter/source/mapping.h +++ b/hwpfilter/source/mapping.h @@ -360,7 +360,7 @@ const struct FormulaEntry FormulaMapTab[] = { }; -#ifndef DEBUG +#if OSL_DEBUG_LEVEL < 2 hchar_string getMathMLEntity(const char *tex) { static const size_t tabSize = SAL_N_ELEMENTS(FormulaMapTab); diff --git a/hwpfilter/source/mzstring.cxx b/hwpfilter/source/mzstring.cxx deleted file mode 100644 index 462ed91ad3fc..000000000000 --- a/hwpfilter/source/mzstring.cxx +++ /dev/null @@ -1,268 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -/* PURPOSE - * supposed to be used instead of std::string - */ - -#include "mzstring.h" - -#ifdef _WIN32 -# if !defined WIN32_LEAN_AND_MEAN -# define WIN32_LEAN_AND_MEAN -# endif -# include <windows.h> -#endif -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#ifndef _WIN32 -# define wsprintfA sprintf -#endif - -const int AllocSize = 8; - -static int get_alloc_size(int len) -{ - return (len + AllocSize - 1) / AllocSize * AllocSize; -} - - -MzString::MzString() -{ - Length = 0; - Allocated = 0; - Data = nullptr; -} - - -MzString::~MzString() -{ - if (Data) - free(Data); -} - - -MzString &MzString::operator=(const MzString &s) -{ - if(this == &s) - return *this; - - int n = s.length(); - if (allocate(n)) - { - if (n > 0) memcpy(Data, s.Data, n); - Length = n; - } - return *this; -} - - -MzString &MzString::operator = (const char *s) -{ - if (s == nullptr) - s = ""; - int n = strlen(s); - if (allocate(n)) - { - if (n > 0) memcpy(Data, s, n); - Length = n; - } - return *this; -} - - -void MzString::append(const char *s, int slen) -{ - if(!s || slen <= 0) - return; - - int new_len = Length + slen; - if (allocate(new_len)) - { - memcpy(Data + Length, s, slen); - Length = new_len; - } -} - - -void MzString::append(MzString const &s) -{ - if (s.Data) - append(s.Data, s.length()); -} - - -void MzString::append(const char *s) -{ - if (!s) return; - append(s, strlen(s)); -} - - -int MzString::compare(const char *s) -{ - if (!Data) return -1; - if (s==nullptr) return 1; - - Data[Length] = 0; - return strcmp(Data, s); -} - - -int MzString::find(char ch) -{ - return find(ch,0); -} - - -int MzString::find(char ch, int pos) -{ - for (int i = pos; i < Length; i++) - { - if (Data[i] == ch) - return i; - } - return -1; -} - - -int MzString::rfind(char ch) -{ - return rfind(ch, Length - 1); -} - - -int MzString::rfind(char ch, int pos) -{ - if (pos >= Length) - return -1; - - while (pos >= 0) - { - if (Data[pos] == ch) - return pos; - pos--; - } - return -1; -} - - -// << operator -MzString &MzString::operator << (const char *str) -{ - append(str); - return *this; -} - - -MzString &MzString::operator << (char ch) -{ - append(&ch, 1); - return *this; -} - - -MzString &MzString::operator << (int i) -{ - char str[80]; - - wsprintfA(str, "%d", i); - append(str); - return *this; -} - - -MzString &MzString::operator << (tools::Long l) -{ - char str[80]; - - wsprintfA(str, "%ld", l); - append(str); - return *this; -} - - -MzString &MzString::operator << (MzString const &s) -{ - append(s); - return *this; -} - - -char MzString::operator [] (int n) -{ - if (Data && 0 <= n && n < Length) - return Data[n]; - - return 0; -} - - -void MzString::replace(int pos, char ch) -{ - if (Data && 0 <= pos && pos < Length) - Data[pos] = ch; -} - - -// Private Methods. - - -bool MzString::allocate(int len) -{ - len++; // In case we want to add a null. - - if (len < 0) - return false; - - if (Data) - { - if (len < Allocated) - return true; - else - { - int n = get_alloc_size(len); - char *p = static_cast<char *>(realloc(Data, n)); - if (p) - { - Data = p; - Allocated = n; - return true; - } - } - } - else - { -// In case we want to add a null. - int n = get_alloc_size(len); - Data = static_cast<char *>(malloc(n)); - if (Data) - { - Allocated = n; - return true; - } - } - - return false; -} - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/hwpfilter/source/mzstring.h b/hwpfilter/source/mzstring.h deleted file mode 100644 index 475ab31e283b..000000000000 --- a/hwpfilter/source/mzstring.h +++ /dev/null @@ -1,167 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_HWPFILTER_SOURCE_MZSTRING_H -#define INCLUDED_HWPFILTER_SOURCE_MZSTRING_H - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif -#include <tools/long.hxx> - -/** @name MzString class - - It was supposed to be used instead of std::string. - - Notes for usage: - - When you declare an MzString, it is initially empty. There is no need to - do things like #MzString a = "";#, especially not in constructors. - - If you want to use a default empty MzString as a parameter, use - -#void foo(MzString par = MzString()); // Correct# - -rather than - -#void foo(MzString par = ""); // WRONG!# -#void foo(MzString par = 0); // WRONG!# - -(The last one is only wrong because some compilers can't handle it.) - -Methods that take an index as parameter all follow this rule: Valid indexes -go from 0 to length()-1. -\begin{tabular}{rl} -Correct: & #foo.substr(0, length()-1);# \\ -Wrong: & #bar.substr(0, length());# -\end{tabular} - -It is important that you declare MzStrings as const if possible, because -some methods are much more efficient in const versions. - -If you want to check whether a string is empty, do - -#if (foo.empty()) something right# - -rather than something along the lines of - -#if (!foo) completely wrong# - -When you use the #.copy()# method, MzString calls "#new []#", so you have to -release the memory with #delete[]#. Don't preallocate memory. - -When you want to copy an MzString, just do - -#MzString a, b = "String";# -#a = b; // That's it!# - -not something like - -#MzString a, b = "String";# -#a = b.copy();# - -The class automatically handles deep copying when required. -*/ - -class MzString -{ - public: - MzString(); // Create an empty string - ~MzString(); - - int length() const; - const char* c_str() const; - operator char*() { return const_cast<char *>(c_str()); } - -// Assignment - MzString &operator = (const MzString &s); - MzString &operator = (const char *s); - -// Appending - - MzString &operator << (const char *); - MzString &operator << (char); - MzString &operator << (unsigned char c) { return *this<<static_cast<char>(c); } - MzString &operator << (int); - MzString &operator << (tools::Long); - MzString &operator << (short i) { return *this<<static_cast<int>(i); } - MzString &operator << (MzString const &); -/* MzString &operator << (MzString *s) { return *this<<*s; } - - // Removing - char operator >> (char &c); -*/ -// Access to specific characters -//char &operator [] (int n); - char operator [] (int n); - -// Comparison -// Return: -// 0 : 'this' is equal to 's'. -// -1 : 'this' is less than 's'. -// 1 : 'this' is greater than 's'. - int compare(const char *s); - -// Searching for parts - int find (char c); - int find (char c, int pos); - int rfind (char c); - int rfind (char c, int pos); - -// Manipulation - void replace(int, char c); - - void append (MzString const &s); - void append (const char *s); - void append (const char *s, int n); - - private: - int Length; // Current Length - int Allocated; // Total space allocated - char *Data; // The actual contents - -// Allocate some space for the data. -// Delete Data if it has been allocated. - bool allocate(int len); -}; - -inline int MzString::length() const -{ - return Length; -} - - -inline const char* MzString::c_str() const -{ - if (Data) - { - Data[Length] = '\0'; // We always leave room for this. - return Data; - } - else - return ""; -} - - - -// Non friend, non member operators - -#endif // INCLUDED_HWPFILTER_SOURCE_MZSTRING_H - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/hwpfilter/source/nodes.h b/hwpfilter/source/nodes.h index 9d238e75c945..dce473e13fa5 100644 --- a/hwpfilter/source/nodes.h +++ b/hwpfilter/source/nodes.h @@ -26,6 +26,7 @@ #include <vector> #include <stdio.h> #include <stdlib.h> +#include <o3tl/deleter.hxx> #include <osl/diagnose.h> enum IDLIST { @@ -68,7 +69,6 @@ class Node{ public: explicit Node(int _id) : id(_id) { - value = nullptr; child = nullptr; next = nullptr; #ifdef NODE_DEBUG @@ -78,9 +78,6 @@ public: } ~Node() { - if( value ) free( value ); - // if( child ) delete child; - // if( next ) delete next; next = nullptr; child = nullptr; #ifdef NODE_DEBUG @@ -91,7 +88,7 @@ public: public: static int count; /* For memory debugging */ int id; - char *value; + std::unique_ptr<char, o3tl::free_delete> value; Node *child; Node *next; }; |