hwpfilter/source/hcode.cxx     |    7 ++-
 hwpfilter/source/hcode.h       |    2 -
 hwpfilter/source/hwpreader.cxx |   80 +++++++++++++++++++----------------------
 3 files changed, 44 insertions(+), 45 deletions(-)

New commits:
commit a8b43900d60c8bb060a3c04b4beb9f3619e1aeca
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Fri Mar 4 11:33:32 2022 +0300
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Fri Mar 4 12:03:28 2022 +0100

    Expand ascii macro
    
    Change-Id: Ief7ce8c5477c0904cf1f9796913aa02d30ffce3a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130957
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/hwpfilter/source/hwpreader.cxx b/hwpfilter/source/hwpreader.cxx
index b51607cb3294..1d7b95479fee 100644
--- a/hwpfilter/source/hwpreader.cxx
+++ b/hwpfilter/source/hwpreader.cxx
@@ -40,7 +40,6 @@
 #include <rtl/ustrbuf.hxx>
 
 // To be shorten source code by realking
-#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)
@@ -347,7 +346,7 @@ void HwpReader::makeMeta()
         sprintf(buf,"%d-%02d-%02dT%02d:%02d:00",year,month,day,hour,minute);
 
         rstartEl( "meta:creation-date", mxList );
-        rchars( ascii(buf));
+        rchars( OUString::createFromAscii(buf));
         rendEl( "meta:creation-date" );
     }
 
@@ -469,7 +468,7 @@ void HwpReader::makeDrawMiscStyle( HWPDrawingObject *hdo )
             {
                 ArrowShape[prop->line_tstyle].bMade = true;
                 padd("draw:name", sXML_CDATA,
-                    ascii(ArrowShape[prop->line_tstyle].name));
+                    
OUString::createFromAscii(ArrowShape[prop->line_tstyle].name));
                 if( prop->line_tstyle == 1 )
                 {
                     padd("svg:viewBox", sXML_CDATA, "0 0 20 30");
@@ -495,7 +494,7 @@ void HwpReader::makeDrawMiscStyle( HWPDrawingObject *hdo )
             {
                 ArrowShape[prop->line_hstyle].bMade = true;
                 padd("draw:name", sXML_CDATA,
-                    ascii(ArrowShape[prop->line_hstyle].name));
+                    
OUString::createFromAscii(ArrowShape[prop->line_hstyle].name));
                 if( prop->line_hstyle == 1 )
                 {
                     padd("svg:viewBox", sXML_CDATA, "0 0 20 30");
@@ -592,30 +591,30 @@ void HwpReader::makeDrawMiscStyle( HWPDrawingObject *hdo )
                     {
                         sprintf( buf, "#%02x%02x%02x", prop->tocolor & 0xff,
                             (prop->tocolor >> 8) & 0xff, (prop->tocolor >>16) 
& 0xff );
-                        padd( "draw:start-color", sXML_CDATA, ascii( buf ));
+                        padd( "draw:start-color", sXML_CDATA, 
OUString::createFromAscii( 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 ));
+                        padd( "draw:end-color", sXML_CDATA, 
OUString::createFromAscii( buf ));
                     }
                     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 ));
+                        padd( "draw:start-color", sXML_CDATA, 
OUString::createFromAscii( 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 ));
+                        padd( "draw:end-color", sXML_CDATA, 
OUString::createFromAscii( buf ));
                     }
                 }
                 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 ));
+                    padd( "draw:start-color", 
sXML_CDATA,OUString::createFromAscii( 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 ));
+                    padd( "draw:end-color", 
sXML_CDATA,OUString::createFromAscii( buf ));
                 }
                 if( prop->angle > 0 && ( prop->gstyle == 1 || prop->gstyle == 
4))
                 {
@@ -639,7 +638,7 @@ void HwpReader::makeDrawMiscStyle( HWPDrawingObject *hdo )
                     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:color", sXML_CDATA, OUString::createFromAscii( buf 
));
                 padd( "draw:distance", sXML_CDATA, "0.12cm");
                 switch( type )
                 {
@@ -1419,7 +1418,7 @@ void HwpReader::parseParaShape(ParaShape const * pshape)
     }
 
     if (align)
-        padd("fo:text-align", sXML_CDATA, ascii(align));
+        padd("fo:text-align", sXML_CDATA, OUString::createFromAscii(align));
 
     if (pshape->outline)
         padd("fo:border", sXML_CDATA, "0.002cm solid #000000");
@@ -1619,7 +1618,7 @@ void HwpReader::makePageStyle()
          }
 
          padd("style:print-orientation",sXML_CDATA,
-              ascii(hwpinfo.paper.paper_direction ? "landscape" : "portrait"));
+              OUString::createFromAscii(hwpinfo.paper.paper_direction ? 
"landscape" : "portrait"));
          if( hwpinfo.beginpagenum != 1)
               padd("style:first-page-number",sXML_CDATA, 
OUString::number(hwpinfo.beginpagenum));
 
@@ -1677,7 +1676,7 @@ void HwpReader::makePageStyle()
                      || 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));
+                 padd("fo:background-color", sXML_CDATA, 
OUString::createFromAscii(buf));
              }
          }
 
@@ -1855,7 +1854,7 @@ void HwpReader::makeTableStyle(Table *tbl)
     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:name", sXML_CDATA, OUString::createFromAscii( buf ));
         padd("style:family", sXML_CDATA,"table-column");
         rstartEl("style:style", mxList);
         mxList->clear();
@@ -1871,7 +1870,7 @@ void HwpReader::makeTableStyle(Table *tbl)
     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:name", sXML_CDATA, OUString::createFromAscii( buf ));
         padd("style:family", sXML_CDATA,"table-row");
         rstartEl("style:style", mxList);
         mxList->clear();
@@ -1887,7 +1886,7 @@ void HwpReader::makeTableStyle(Table *tbl)
     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:name", sXML_CDATA, OUString::createFromAscii( buf ));
         padd("style:family", sXML_CDATA,"table-cell");
         rstartEl("style:style", mxList);
         mxList->clear();
@@ -2030,7 +2029,7 @@ void HwpReader::makeDrawStyle( HWPDrawingObject * hdo, 
FBoxStyle * fstyle)
                     sal_uInt16(color & 0xff),
                     sal_uInt16((color >> 8) & 0xff),
                     sal_uInt16((color >>16) & 0xff) );
-            padd("svg:stroke-color", sXML_CDATA, ascii( buf) );
+            padd("svg:stroke-color", sXML_CDATA, OUString::createFromAscii( 
buf) );
         }
 
         if( hdo->type == HWPDO_LINE || hdo->type == HWPDO_ARC ||
@@ -2041,7 +2040,7 @@ void HwpReader::makeDrawStyle( HWPDrawingObject * hdo, 
FBoxStyle * fstyle)
                 o3tl::make_unsigned(hdo->property.line_tstyle) < 
std::size(ArrowShape) )
             {
                 padd("draw:marker-start", sXML_CDATA,
-                    ascii(ArrowShape[hdo->property.line_tstyle].name) );
+                    
OUString::createFromAscii(ArrowShape[hdo->property.line_tstyle].name) );
                 if( hdo->property.line_width > 100 )
                          padd("draw:marker-start-width", sXML_CDATA,
                               OUString::number( WTMM(hdo->property.line_width 
* 3)) + "mm");
@@ -2063,7 +2062,7 @@ void HwpReader::makeDrawStyle( HWPDrawingObject * hdo, 
FBoxStyle * fstyle)
                 o3tl::make_unsigned(hdo->property.line_hstyle) < 
std::size(ArrowShape) )
             {
                 padd("draw:marker-end", sXML_CDATA,
-                    ascii(ArrowShape[hdo->property.line_hstyle].name) );
+                    
OUString::createFromAscii(ArrowShape[hdo->property.line_hstyle].name) );
                 if( hdo->property.line_width > 100 )
                          padd("draw:marker-end-width", sXML_CDATA,
                               OUString::number( WTMM(hdo->property.line_width 
* 3)) + "mm");
@@ -2135,7 +2134,7 @@ void HwpReader::makeDrawStyle( HWPDrawingObject * hdo, 
FBoxStyle * fstyle)
                         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-color", sXML_CDATA, 
OUString::createFromAscii( buf) );
                     padd("draw:fill-hatch-solid", sXML_CDATA, "true");
                 }
             }
@@ -2146,7 +2145,7 @@ void HwpReader::makeDrawStyle( HWPDrawingObject * hdo, 
FBoxStyle * fstyle)
                     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-color", sXML_CDATA, OUString::createFromAscii( 
buf) );
             }
             else
                 padd("draw:fill", sXML_CDATA, "none");
@@ -3394,7 +3393,7 @@ void HwpReader::makeTable(TxtBox * hbox)
     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 ));
+        padd("table:style-name", sXML_CDATA, OUString::createFromAscii( buf ));
         rstartEl("table:table-column", mxList);
         mxList->clear();
         rendEl("table:table-column");
@@ -3413,14 +3412,14 @@ void HwpReader::makeTable(TxtBox * hbox)
             }
 // row
             sprintf(buf,"Table%d.row%d",hbox->style.boxnum, tcell->nRowIndex + 
1);
-            padd("table:style-name", sXML_CDATA, ascii( buf ));
+            padd("table:style-name", sXML_CDATA, OUString::createFromAscii( 
buf ));
             rstartEl("table:table-row", mxList);
             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 ));
+        padd("table:style-name", sXML_CDATA, OUString::createFromAscii( buf ));
         if( tcell->nColumnSpan > 1 )
             padd("table:number-columns-spanned", sXML_CDATA, 
OUString::number(tcell->nColumnSpan));
         if( tcell->nRowSpan > 1 )
@@ -4225,7 +4224,7 @@ void HwpReader::makePictureDRAW(HWPDrawingObject 
*drawobj, Picture * hbox)
                     padd("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) );
+                    padd("svg:viewBox", sXML_CDATA, 
OUString::createFromAscii(buf) );
 
                     OUStringBuffer oustr;
 
@@ -4273,7 +4272,7 @@ void HwpReader::makePictureDRAW(HWPDrawingObject 
*drawobj, Picture * hbox)
 
                               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.appendAscii(buf);
 
                               for( i = 1 ; i < n  ; i++ ){
                                   if( i == n -1 ){
@@ -4288,7 +4287,7 @@ void HwpReader::makePictureDRAW(HWPDrawingObject 
*drawobj, Picture * hbox)
                                               WTSM(xarr[i] + xb[i]/3), 
WTSM(yarr[i] + yb[i]/3) );
                                   }
 
-                                  oustr.append(ascii(buf));
+                                  oustr.appendAscii(buf);
                               }
                     }
 
@@ -4325,21 +4324,21 @@ void HwpReader::makePictureDRAW(HWPDrawingObject 
*drawobj, Picture * hbox)
                         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) );
+                    padd("svg:viewBox", sXML_CDATA, 
OUString::createFromAscii(buf) );
 
                     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.appendAscii(buf);
                         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.appendAscii(buf);
                         }
                         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 )
commit a400cdb4555d32e9648dae32c01296a075843bd1
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Fri Mar 4 11:23:07 2022 +0300
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Fri Mar 4 12:03:15 2022 +0100

    Change hcolor2str to return OUString
    
    Change-Id: I9d2a34a2cc20df20453aa048c32f619a8e17ae72
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130956
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/hwpfilter/source/hcode.cxx b/hwpfilter/source/hcode.cxx
index c8cc6c13b15e..3e9b08086f23 100644
--- a/hwpfilter/source/hcode.cxx
+++ b/hwpfilter/source/hcode.cxx
@@ -1237,7 +1237,7 @@ hchar_string kstr2hstr(uchar const* src)
 
 
 /* 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,8 +1289,9 @@ char *hcolor2str(uchar color, uchar shade, char *buf, 
bool bIsChar)
             break;
     }
 
-    sprintf(buf,"#%02x%02x%02x", red, green, blue);
-    return buf;
+    char buf[8];
+    int n = std::max(sprintf(buf, "#%02x%02x%02x", red, green, blue), 0);
+    return OUString::createFromAscii(std::string_view(buf, n));
 }
 
 
diff --git a/hwpfilter/source/hcode.h b/hwpfilter/source/hcode.h
index df77061a1736..0f8362e0128a 100644
--- a/hwpfilter/source/hcode.h
+++ b/hwpfilter/source/hcode.h
@@ -64,7 +64,7 @@ DLLEXPORT ::std::string urltowin(const char *src);
 /**
  * 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 base64_encode_string( const uchar *buf, unsigned int len );
 DLLEXPORT double calcAngle(int x1, int y1, int x2, int y2);
diff --git a/hwpfilter/source/hwpreader.cxx b/hwpfilter/source/hwpreader.cxx
index 9397b827b6c4..b51607cb3294 100644
--- a/hwpfilter/source/hwpreader.cxx
+++ b/hwpfilter/source/hwpreader.cxx
@@ -1334,10 +1334,10 @@ void HwpReader::parseCharShape(CharShape const * cshape)
     }
     if (cshape->color[1] != 0)
         padd("fo:color", sXML_CDATA,
-            ascii(hcolor2str(cshape->color[1], 100, buf, true)));
+            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)));
+            hcolor2str(cshape->color[0], cshape->shade));
     if (cshape->attr & 0x01)
     {
         padd("fo:font-style", sXML_CDATA, "italic");
@@ -1426,7 +1426,7 @@ void HwpReader::parseParaShape(ParaShape const * pshape)
     if( pshape->shade > 0 )
     {
         padd("fo:background-color", sXML_CDATA,
-            ascii(hcolor2str(0, pshape->shade, buf)));
+            hcolor2str(0, pshape->shade));
     }
 
     if( pshape->pagebreak & 0x02 || pshape->pagebreak & 0x04)
@@ -1974,8 +1974,8 @@ void HwpReader::makeTableStyle(Table *tbl)
         }
         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)));
+                hcolor2str(sal::static_int_cast<uchar>(cl->color),
+                                sal::static_int_cast<uchar>(cl->shade)));
 
         rstartEl("style:properties", mxList);
         mxList->clear();
@@ -2368,9 +2368,9 @@ void HwpReader::makeCaptionStyle(FBoxStyle * fstyle)
             }
         }
         if(cell->shade != 0)
-            padd("fo:background-color", sXML_CDATA, ascii(hcolor2str(
+            padd("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);
     mxList->clear();
@@ -2592,10 +2592,9 @@ void HwpReader::makeFStyle(FBoxStyle * fstyle)
         }
         if(cell->shade != 0)
             padd("fo:background-color", sXML_CDATA,
-            ascii(hcolor2str(
+            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' )
      {

Reply via email to