summaryrefslogtreecommitdiff
path: root/hwpfilter/source/hwpreader.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'hwpfilter/source/hwpreader.cxx')
-rw-r--r--hwpfilter/source/hwpreader.cxx91
1 files changed, 32 insertions, 59 deletions
diff --git a/hwpfilter/source/hwpreader.cxx b/hwpfilter/source/hwpreader.cxx
index 4144d20e0bde..12eb4960f97f 100644
--- a/hwpfilter/source/hwpreader.cxx
+++ b/hwpfilter/source/hwpreader.cxx
@@ -24,6 +24,7 @@
#include <math.h>
#include <osl/diagnose.h>
+#include <o3tl/safeint.hxx>
#include <tools/stream.hxx>
#include "fontmap.hxx"
@@ -70,7 +71,6 @@
rendEl("text:span"); \
tstart = false
-static hchar *field = nullptr;
static char buf[1024];
namespace
@@ -96,12 +96,13 @@ struct HwpReaderPrivate
bInHeader = false;
nPnPos = 0;
pPn = nullptr;
-
+ pField = nullptr;
}
bool bFirstPara;
bool bInBody;
bool bInHeader;
ShowPageNum *pPn;
+ hchar *pField;
int nPnPos;
};
@@ -460,7 +461,9 @@ void HwpReader::makeDrawMiscStyle( HWPDrawingObject *hdo )
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,
@@ -484,7 +487,9 @@ void HwpReader::makeDrawMiscStyle( HWPDrawingObject *hdo )
mxList->clear();
rendEl("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,
@@ -515,62 +520,28 @@ 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 )
+
+ EmPicture *emp = nullptr;
+ if (prop->pictype && strlen(prop->szPatternFile) > 3)
+ emp = hwpfile.GetEmPictureByName(prop->szPatternFile);
+ if (!emp)
{
padd( "xlink:href", sXML_CDATA,
reinterpret_cast<sal_Unicode const *>(hconv(kstr2hstr( reinterpret_cast<uchar const *>(urltounix(prop->szPatternFile).c_str())).c_str())));
+ padd( "xlink:type", sXML_CDATA, "simple");
+ padd( "xlink:show", sXML_CDATA, "embed");
+ padd( "xlink:actuate", sXML_CDATA, "onLoad");
}
- 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,
- reinterpret_cast<sal_Unicode const *>(hconv(kstr2hstr( reinterpret_cast<uchar const *>(urltounix(prop->szPatternFile).c_str())).c_str())));
- }
-
- }
- padd( "xlink:type", sXML_CDATA, "simple");
- padd( "xlink:show", sXML_CDATA, "embed");
- padd( "xlink:actuate", sXML_CDATA, "onLoad");
rstartEl( "draw:fill-image", mxList.get());
mxList->clear();
+ if (emp)
+ {
+ rstartEl("office:binary-data", mxList.get());
+ std::shared_ptr<char> pStr(base64_encode_string(emp->data.get(), emp->size), Free<char>());
+ rchars(ascii(pStr.get()));
+ rendEl("office:binary-data");
+ }
rendEl( "draw:fill-image");
}
/* If there is a gradient, when a bitmap file is present, this is the first. */
@@ -2075,7 +2046,8 @@ void HwpReader::makeDrawStyle( HWPDrawingObject * hdo, FBoxStyle * fstyle)
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) );
@@ -2096,7 +2068,8 @@ void HwpReader::makeDrawStyle( HWPDrawingObject * hdo, FBoxStyle * fstyle)
Double2Str( 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) );
@@ -2959,7 +2932,7 @@ void HwpReader::make_text_p3(HWPPara * para,bool bParaStart)
firstspace = 1;
if( hbox->type[0] == 4 && hbox->type[1] == 0 )
{
- field = hbox->str3.get();
+ d->pField = hbox->str3.get();
}
else{
makeFieldCode(str, hbox);
@@ -2972,7 +2945,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();
@@ -3140,8 +3113,8 @@ void HwpReader::makeFieldCode(hchar_string const & rStr, FieldCode const *hbox)
if( hbox->type[0] == 4 && hbox->type[1] == 0 )
{
padd("text:placeholder-type", sXML_CDATA, "text");
- if( field )
- padd("text:description", sXML_CDATA, reinterpret_cast<sal_Unicode const *>(hconv(field)));
+ if (d->pField)
+ padd("text:description", sXML_CDATA, reinterpret_cast<sal_Unicode const *>(hconv(d->pField)));
rstartEl( "text:placeholder", mxList.get());
mxList->clear();
rchars( reinterpret_cast<sal_Unicode const *>(rStr.c_str()) );