Kaydet (Commit) b462fa97 authored tarafından Noel Grandin's avatar Noel Grandin

use std::unique_ptr in hwpfilter

Change-Id: I3aa6e1342f975420b19e9e21058a0331ed2d71e0
Reviewed-on: https://gerrit.libreoffice.org/43525Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
Tested-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 3991cd38
...@@ -347,18 +347,6 @@ TxtBox::TxtBox() ...@@ -347,18 +347,6 @@ TxtBox::TxtBox()
TxtBox::~TxtBox() TxtBox::~TxtBox()
{ {
for (auto& entry : plists)
{
for (auto const& para : entry)
{
delete para;
}
}
for (auto const& para : caption)
{
delete para;
}
} }
// picture(11) // picture(11)
...@@ -382,11 +370,6 @@ Picture::~Picture() ...@@ -382,11 +370,6 @@ Picture::~Picture()
{ {
if( pictype == PICTYPE_DRAW && picinfo.picdraw.hdo ) if( pictype == PICTYPE_DRAW && picinfo.picdraw.hdo )
delete static_cast<HWPDrawingObject *>(picinfo.picdraw.hdo); delete static_cast<HWPDrawingObject *>(picinfo.picdraw.hdo);
for (auto const& para : caption)
{
delete para;
}
} }
...@@ -394,30 +377,18 @@ Picture::~Picture() ...@@ -394,30 +377,18 @@ Picture::~Picture()
// hidden(15) // hidden(15)
Hidden::~Hidden() Hidden::~Hidden()
{ {
for (auto const& para : plist)
{
delete para;
}
} }
// header/footer(16) // header/footer(16)
HeaderFooter::~HeaderFooter() HeaderFooter::~HeaderFooter()
{ {
for (auto const& para : plist)
{
delete para;
}
} }
// footnote(17) // footnote(17)
Footnote::~Footnote() Footnote::~Footnote()
{ {
for (auto const& para : plist)
{
delete para;
}
} }
......
...@@ -363,12 +363,12 @@ struct TxtBox: public FBox ...@@ -363,12 +363,12 @@ struct TxtBox: public FBox
/** /**
* Paragraph list * Paragraph list
*/ */
std::vector<std::vector<HWPPara*>> plists; std::vector<std::vector<std::unique_ptr<HWPPara>>> plists;
/** /**
* Caption * Caption
*/ */
std::vector<HWPPara*> caption; std::vector<std::unique_ptr<HWPPara>> caption;
TxtBox(); TxtBox();
virtual ~TxtBox() override; virtual ~TxtBox() override;
...@@ -625,7 +625,7 @@ struct Picture: public FBox ...@@ -625,7 +625,7 @@ struct Picture: public FBox
PicDef picinfo; PicDef picinfo;
char reserved3[9]; char reserved3[9];
std::vector<HWPPara*> caption; std::vector<std::unique_ptr<HWPPara>> caption;
/** /**
* It's for the Drawing object * It's for the Drawing object
*/ */
...@@ -668,7 +668,7 @@ struct Hidden: public HBox ...@@ -668,7 +668,7 @@ struct Hidden: public HBox
hchar dummy; hchar dummy;
unsigned char info[8]; // h, next, dummy unsigned char info[8]; // h, next, dummy
std::vector<HWPPara*> plist; std::vector<std::unique_ptr<HWPPara>> plist;
Hidden(); Hidden();
virtual ~Hidden() override; virtual ~Hidden() override;
...@@ -697,7 +697,7 @@ struct HeaderFooter: public HBox ...@@ -697,7 +697,7 @@ struct HeaderFooter: public HBox
/** /**
* Paragraph list of header or footer * Paragraph list of header or footer
*/ */
std::vector<HWPPara*> plist; std::vector<std::unique_ptr<HWPPara>> plist;
HeaderFooter(); HeaderFooter();
virtual ~HeaderFooter() override; virtual ~HeaderFooter() override;
...@@ -730,7 +730,7 @@ struct Footnote: public HBox ...@@ -730,7 +730,7 @@ struct Footnote: public HBox
/** /**
* Paragraph list of Footnote objects * Paragraph list of Footnote objects
*/ */
std::vector<HWPPara*> plist; std::vector<std::unique_ptr<HWPPara>> plist;
Footnote(); Footnote();
virtual ~Footnote() override; virtual ~Footnote() override;
......
...@@ -267,6 +267,41 @@ bool HWPFile::ReadParaList(std::vector < HWPPara* > &aplist, unsigned char flag) ...@@ -267,6 +267,41 @@ bool HWPFile::ReadParaList(std::vector < HWPPara* > &aplist, unsigned char flag)
return true; return true;
} }
bool HWPFile::ReadParaList(std::vector< std::unique_ptr<HWPPara> > &aplist, unsigned char flag)
{
std::unique_ptr<HWPPara> spNode( new HWPPara );
unsigned char tmp_etcflag;
unsigned char prev_etcflag = 0;
while (spNode->Read(*this, flag))
{
if( !(spNode->etcflag & 0x04) ){
tmp_etcflag = spNode->etcflag;
spNode->etcflag = prev_etcflag;
prev_etcflag = tmp_etcflag;
}
if (spNode->nch && spNode->reuse_shape)
{
if (!aplist.empty()){
spNode->pshape = aplist.back()->pshape;
}
else{
spNode->nch = 0;
spNode->reuse_shape = 0;
}
}
spNode->pshape->pagebreak = spNode->etcflag;
if (spNode->nch)
AddParaShape(spNode->pshape);
if (!aplist.empty())
aplist.back()->SetNext(spNode.get());
aplist.push_back(std::move(spNode));
spNode.reset( new HWPPara );
}
return true;
}
void HWPFile::TagsRead() void HWPFile::TagsRead()
{ {
while (true) while (true)
......
...@@ -160,6 +160,7 @@ class DLLEXPORT HWPFile ...@@ -160,6 +160,7 @@ class DLLEXPORT HWPFile
/** /**
* Reads main paragraph list * Reads main paragraph list
*/ */
bool ReadParaList(std::vector<std::unique_ptr<HWPPara>> &aplist, unsigned char flag = 0);
bool ReadParaList(std::vector<HWPPara*> &aplist, unsigned char flag = 0); bool ReadParaList(std::vector<HWPPara*> &aplist, unsigned char flag = 0);
/** /**
* Sets if the stream is compressed * Sets if the stream is compressed
......
...@@ -1125,7 +1125,7 @@ void HwpReader::makeMasterStyles() ...@@ -1125,7 +1125,7 @@ void HwpReader::makeMasterStyles()
d->bInHeader = true; d->bInHeader = true;
d->pPn = pPage->pagenumber; d->pPn = pPage->pagenumber;
} }
parsePara(pPage->header->plist.front()); parsePara(pPage->header->plist.front().get());
d->bInHeader = false; d->bInHeader = false;
d->pPn = nullptr; d->pPn = nullptr;
rendEl("style:header"); rendEl("style:header");
...@@ -1140,7 +1140,7 @@ void HwpReader::makeMasterStyles() ...@@ -1140,7 +1140,7 @@ void HwpReader::makeMasterStyles()
d->pPn = pPage->pagenumber; d->pPn = pPage->pagenumber;
d->nPnPos = 3; d->nPnPos = 3;
} }
parsePara(pPage->header_even->plist.front()); parsePara(pPage->header_even->plist.front().get());
d->bInHeader = false; d->bInHeader = false;
d->pPn = nullptr; d->pPn = nullptr;
d->nPnPos = 0; d->nPnPos = 0;
...@@ -1175,7 +1175,7 @@ void HwpReader::makeMasterStyles() ...@@ -1175,7 +1175,7 @@ void HwpReader::makeMasterStyles()
d->nPnPos = 1; d->nPnPos = 1;
d->pPn = pPage->pagenumber; d->pPn = pPage->pagenumber;
} }
parsePara(pPage->header_odd->plist.front()); parsePara(pPage->header_odd->plist.front().get());
d->bInHeader = false; d->bInHeader = false;
d->pPn = nullptr; d->pPn = nullptr;
d->nPnPos = 0; d->nPnPos = 0;
...@@ -1226,7 +1226,7 @@ void HwpReader::makeMasterStyles() ...@@ -1226,7 +1226,7 @@ void HwpReader::makeMasterStyles()
d->bInHeader = true; d->bInHeader = true;
d->pPn = pPage->pagenumber; d->pPn = pPage->pagenumber;
} }
parsePara(pPage->footer->plist.front()); parsePara(pPage->footer->plist.front().get());
d->bInHeader = false; d->bInHeader = false;
d->pPn = nullptr; d->pPn = nullptr;
rendEl("style:footer"); rendEl("style:footer");
...@@ -1241,7 +1241,7 @@ void HwpReader::makeMasterStyles() ...@@ -1241,7 +1241,7 @@ void HwpReader::makeMasterStyles()
d->pPn = pPage->pagenumber; d->pPn = pPage->pagenumber;
d->nPnPos = 3; d->nPnPos = 3;
} }
parsePara(pPage->footer_even->plist.front()); parsePara(pPage->footer_even->plist.front().get());
d->bInHeader = false; d->bInHeader = false;
d->pPn = nullptr; d->pPn = nullptr;
d->nPnPos = 0; d->nPnPos = 0;
...@@ -1276,7 +1276,7 @@ void HwpReader::makeMasterStyles() ...@@ -1276,7 +1276,7 @@ void HwpReader::makeMasterStyles()
d->pPn = pPage->pagenumber; d->pPn = pPage->pagenumber;
d->nPnPos = 1; d->nPnPos = 1;
} }
parsePara(pPage->footer_odd->plist.front()); parsePara(pPage->footer_odd->plist.front().get());
d->bInHeader = false; d->bInHeader = false;
d->pPn = nullptr; d->pPn = nullptr;
d->nPnPos = 0; d->nPnPos = 0;
...@@ -3504,7 +3504,7 @@ void HwpReader::makeTable(TxtBox * hbox) ...@@ -3504,7 +3504,7 @@ void HwpReader::makeTable(TxtBox * hbox)
padd("table:protected", sXML_CDATA,"true"); padd("table:protected", sXML_CDATA,"true");
rstartEl("table:table-cell", mxList.get()); rstartEl("table:table-cell", mxList.get());
mxList->clear(); mxList->clear();
parsePara(hbox->plists[tcell->pCell->key].front()); parsePara(hbox->plists[tcell->pCell->key].front().get());
rendEl("table:table-cell"); rendEl("table:table-cell");
} }
rendEl("table:table-row"); rendEl("table:table-row");
...@@ -3560,7 +3560,7 @@ void HwpReader::makeTextBox(TxtBox * hbox) ...@@ -3560,7 +3560,7 @@ void HwpReader::makeTextBox(TxtBox * hbox)
mxList->clear(); mxList->clear();
if( hbox->cap_pos % 2 ) /* The caption is on the top */ if( hbox->cap_pos % 2 ) /* The caption is on the top */
{ {
parsePara(hbox->caption.front()); parsePara(hbox->caption.front().get());
} }
padd( "text:style-name", sXML_CDATA, "Standard"); padd( "text:style-name", sXML_CDATA, "Standard");
rstartEl("text:p", mxList.get()); rstartEl("text:p", mxList.get());
...@@ -3628,7 +3628,7 @@ void HwpReader::makeTextBox(TxtBox * hbox) ...@@ -3628,7 +3628,7 @@ void HwpReader::makeTextBox(TxtBox * hbox)
/* If captions are present and it is on the top */ /* 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 )
{ {
parsePara(hbox->caption.front()); parsePara(hbox->caption.front().get());
} }
if( hbox->type == TBL_TYPE) // Is Table if( hbox->type == TBL_TYPE) // Is Table
{ {
...@@ -3636,12 +3636,12 @@ void HwpReader::makeTextBox(TxtBox * hbox) ...@@ -3636,12 +3636,12 @@ void HwpReader::makeTextBox(TxtBox * hbox)
} }
else // Is TextBox else // Is TextBox
{ {
parsePara(hbox->plists[0].front()); parsePara(hbox->plists[0].front().get());
} }
/* If captions are present and it is on the bottom */ /* 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)
{ {
parsePara(hbox->caption.front()); parsePara(hbox->caption.front().get());
} }
rendEl("draw:text-box"); rendEl("draw:text-box");
// Caption exist and it is text-box // Caption exist and it is text-box
...@@ -3650,7 +3650,7 @@ void HwpReader::makeTextBox(TxtBox * hbox) ...@@ -3650,7 +3650,7 @@ void HwpReader::makeTextBox(TxtBox * hbox)
rendEl( "text:p"); rendEl( "text:p");
if( !(hbox->cap_pos % 2)) if( !(hbox->cap_pos % 2))
{ {
parsePara(hbox->caption.front()); parsePara(hbox->caption.front().get());
} }
rendEl( "draw:text-box"); rendEl( "draw:text-box");
} }
...@@ -3678,7 +3678,7 @@ void HwpReader::makeFormula(TxtBox * hbox) ...@@ -3678,7 +3678,7 @@ void HwpReader::makeFormula(TxtBox * hbox)
hchar dest[3]; hchar dest[3];
size_t l = 0; size_t l = 0;
pPar = hbox->plists[0].front(); pPar = hbox->plists[0].front().get();
while( pPar ) while( pPar )
{ {
for( n = 0; n < pPar->nch && pPar->hhstr[n]->hh; for( n = 0; n < pPar->nch && pPar->hhstr[n]->hh;
...@@ -3814,7 +3814,7 @@ void HwpReader::makePicture(Picture * hbox) ...@@ -3814,7 +3814,7 @@ void HwpReader::makePicture(Picture * hbox)
mxList->clear(); mxList->clear();
if( hbox->cap_pos % 2 ) /* Caption is on the top */ if( hbox->cap_pos % 2 ) /* Caption is on the top */
{ {
parsePara(hbox->caption.front()); parsePara(hbox->caption.front().get());
} }
padd( "text:style-name", sXML_CDATA, "Standard"); padd( "text:style-name", sXML_CDATA, "Standard");
rstartEl("text:p", mxList.get()); rstartEl("text:p", mxList.get());
...@@ -3959,7 +3959,7 @@ void HwpReader::makePicture(Picture * hbox) ...@@ -3959,7 +3959,7 @@ void HwpReader::makePicture(Picture * hbox)
rendEl( "text:p"); rendEl( "text:p");
if( !(hbox->cap_pos % 2)) /* Caption is at the bottom, */ if( !(hbox->cap_pos % 2)) /* Caption is at the bottom, */
{ {
parsePara(hbox->caption.front()); parsePara(hbox->caption.front().get());
} }
rendEl( "draw:text-box"); rendEl( "draw:text-box");
} }
...@@ -4601,7 +4601,7 @@ void HwpReader::makeHidden(Hidden * hbox) ...@@ -4601,7 +4601,7 @@ void HwpReader::makeHidden(Hidden * hbox)
padd("text:string-value", sXML_CDATA, ""); padd("text:string-value", sXML_CDATA, "");
rstartEl("text:hidden-text", mxList.get()); rstartEl("text:hidden-text", mxList.get());
mxList->clear(); mxList->clear();
HWPPara *para = hbox->plist.front(); HWPPara *para = hbox->plist.front().get();
while (para) while (para)
{ {
...@@ -4639,7 +4639,7 @@ void HwpReader::makeFootnote(Footnote * hbox) ...@@ -4639,7 +4639,7 @@ void HwpReader::makeFootnote(Footnote * hbox)
rchars(ascii(Int2Str(hbox->number, "%d", buf))); rchars(ascii(Int2Str(hbox->number, "%d", buf)));
rendEl("text:endnote-citation"); rendEl("text:endnote-citation");
rstartEl("text:endnote-body", mxList.get()); rstartEl("text:endnote-body", mxList.get());
parsePara(hbox->plist.front()); parsePara(hbox->plist.front().get());
rendEl("text:endnote-body"); rendEl("text:endnote-body");
rendEl("text:endnote"); rendEl("text:endnote");
} }
...@@ -4656,7 +4656,7 @@ void HwpReader::makeFootnote(Footnote * hbox) ...@@ -4656,7 +4656,7 @@ void HwpReader::makeFootnote(Footnote * hbox)
rchars(ascii(Int2Str(hbox->number, "%d", buf))); rchars(ascii(Int2Str(hbox->number, "%d", buf)));
rendEl("text:footnote-citation"); rendEl("text:footnote-citation");
rstartEl("text:footnote-body", mxList.get()); rstartEl("text:footnote-body", mxList.get());
parsePara(hbox->plist.front()); parsePara(hbox->plist.front().get());
rendEl("text:footnote-body"); rendEl("text:footnote-body");
rendEl("text:footnote"); rendEl("text:footnote");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment