Commit 467cb760 authored by ElenaSubbotina's avatar ElenaSubbotina

OdfFormatReader - fix backgroud presentation

parent 23718718
...@@ -86,7 +86,7 @@ std::wstring static get_default_file_name(RelsType type) ...@@ -86,7 +86,7 @@ std::wstring static get_default_file_name(RelsType type)
return L""; return L"";
} }
} }
std::wstring mediaitems::create_file_name(const std::wstring & uri, RelsType type, size_t Num) std::wstring mediaitems::create_file_name(const std::wstring & uri, RelsType type, bool & isInternal, size_t Num)
{ {
if (uri.empty()) return L""; if (uri.empty()) return L"";
...@@ -106,6 +106,8 @@ std::wstring mediaitems::create_file_name(const std::wstring & uri, RelsType typ ...@@ -106,6 +106,8 @@ std::wstring mediaitems::create_file_name(const std::wstring & uri, RelsType typ
int n = uri.find(L"ObjectReplacements"); int n = uri.find(L"ObjectReplacements");
if (n >= 0) if (n >= 0)
{ {
if (!isInternal) return L"";
f_name = odf_packet_ + uri.substr(1, uri.length() - 1); f_name = odf_packet_ + uri.substr(1, uri.length() - 1);
sExt = detectImageFileExtension(f_name); sExt = detectImageFileExtension(f_name);
} }
...@@ -119,7 +121,7 @@ std::wstring mediaitems::create_file_name(const std::wstring & uri, RelsType typ ...@@ -119,7 +121,7 @@ std::wstring mediaitems::create_file_name(const std::wstring & uri, RelsType typ
} }
} }
return get_default_file_name(type) + boost::lexical_cast<std::wstring>(Num) + sExt; return get_default_file_name(type) + std::to_wstring(Num) + sExt;
} }
std::wstring mediaitems::detectImageFileExtension(std::wstring &fileName) std::wstring mediaitems::detectImageFileExtension(std::wstring &fileName)
...@@ -145,7 +147,7 @@ std::wstring mediaitems::detectImageFileExtension(std::wstring &fileName) ...@@ -145,7 +147,7 @@ std::wstring mediaitems::detectImageFileExtension(std::wstring &fileName)
std::wstring mediaitems::add_or_find(const std::wstring & href, RelsType type, bool & isInternal, std::wstring & ref) std::wstring mediaitems::add_or_find(const std::wstring & href, RelsType type, bool & isInternal, std::wstring & ref)
{ {
const bool isMediaInternal = utils::media::is_internal(href, odf_packet_); bool isMediaInternal = utils::media::is_internal(href, odf_packet_);
std::wstring sub_path = L"media/"; std::wstring sub_path = L"media/";
...@@ -156,36 +158,41 @@ std::wstring mediaitems::add_or_find(const std::wstring & href, RelsType type, b ...@@ -156,36 +158,41 @@ std::wstring mediaitems::add_or_find(const std::wstring & href, RelsType type, b
} }
int number=0; int number=0;
if ( type == typeChart) number= count_charts+1; if ( type == typeChart) number = count_charts + 1;
else if ( type == typeImage) number= count_image+1; else if ( type == typeImage) number = count_image + 1;
else if ( type == typeShape) number= count_shape+1; else if ( type == typeShape) number = count_shape + 1;
else if ( type == typeMedia) number= count_media+1; else if ( type == typeMedia) number = count_media + 1;
else else
number= items_.size()+1; number = items_.size()+1;
inputFileName = create_file_name(href, type, number); inputFileName = create_file_name(href, type, isMediaInternal, number);
std::wstring inputPath = isMediaInternal ? odf_packet_ + FILE_SEPARATOR_STR + href : href; std::wstring inputPath = isMediaInternal ? odf_packet_ + FILE_SEPARATOR_STR + href : href;
std::wstring outputPath = isMediaInternal ? ( sub_path + inputFileName) : href; std::wstring outputPath = isMediaInternal ? ( sub_path + inputFileName) : href;
if ( type == typeChart)outputPath= outputPath + L".xml"; if ( type == typeChart) outputPath= outputPath + L".xml";
std::wstring id; std::wstring id;
BOOST_FOREACH(item & elm, items_) for (int i = 0 ; i < items_.size(); i++)
{ {
if (elm.href == inputPath) if (items_[i].href == inputPath)
{ {
id = elm.Id; id = items_[i].Id;
outputPath = elm.outputName; outputPath = items_[i].outputName;
elm.count_add++;
items_[i].count_add++;
break; break;
} }
} }
if (id.length() < 1)
ref = outputPath;
isInternal = isMediaInternal;
if (id.empty())
{ {
if ( type == typeChart) if ( type == typeChart)
{ {
id = std::wstring(L"chId") + boost::lexical_cast<std::wstring>(count_charts+1); id = std::wstring(L"chId") + std::to_wstring(count_charts+1);
count_charts++; count_charts++;
} }
else if ( type == typeImage) else if ( type == typeImage)
...@@ -196,12 +203,14 @@ std::wstring mediaitems::add_or_find(const std::wstring & href, RelsType type, b ...@@ -196,12 +203,14 @@ std::wstring mediaitems::add_or_find(const std::wstring & href, RelsType type, b
outputPath = outputPath.substr(0, n_svm) + L".png"; outputPath = outputPath.substr(0, n_svm) + L".png";
} }
//------------------------------------------------ //------------------------------------------------
id = std::wstring(L"picId") + boost::lexical_cast<std::wstring>(count_image+1); if (inputFileName.empty()) return L"";
id = std::wstring(L"picId") + std::to_wstring(count_image+1);
count_image++; count_image++;
} }
else else
{ {
id = std::wstring(L"rId") + boost::lexical_cast<std::wstring>(count_shape+1); id = std::wstring(L"rId") + std::to_wstring(count_shape+1);
count_shape++; count_shape++;
} }
...@@ -210,7 +219,7 @@ std::wstring mediaitems::add_or_find(const std::wstring & href, RelsType type, b ...@@ -210,7 +219,7 @@ std::wstring mediaitems::add_or_find(const std::wstring & href, RelsType type, b
ref = outputPath; ref = outputPath;
isInternal = isMediaInternal; isInternal = isMediaInternal;
return id; return id;
} }
void mediaitems::dump_rels(rels & Rels) void mediaitems::dump_rels(rels & Rels)
......
...@@ -85,7 +85,7 @@ public: ...@@ -85,7 +85,7 @@ public:
items_array & items() { return items_; } items_array & items() { return items_; }
private: private:
std::wstring create_file_name (const std::wstring & uri, RelsType type, size_t Num); std::wstring create_file_name (const std::wstring & uri, RelsType type, bool & isInternal, size_t Num);
std::wstring detectImageFileExtension (std::wstring &fileName); std::wstring detectImageFileExtension (std::wstring &fileName);
items_array items_; items_array items_;
......
...@@ -108,7 +108,8 @@ void oox_serialize_solid_fill(std::wostream & strm, const _oox_fill & val) ...@@ -108,7 +108,8 @@ void oox_serialize_solid_fill(std::wostream & strm, const _oox_fill & val)
} }
void oox_serialize_bitmap_fill(std::wostream & strm, const _oox_fill & val) void oox_serialize_bitmap_fill(std::wostream & strm, const _oox_fill & val)
{ {
if (!val.bitmap)return; if (!val.bitmap) return;
CP_XML_WRITER(strm) CP_XML_WRITER(strm)
{ {
CP_XML_NODE(std::wstring(val.bitmap->name_space + L":blipFill")) CP_XML_NODE(std::wstring(val.bitmap->name_space + L":blipFill"))
...@@ -116,17 +117,17 @@ void oox_serialize_bitmap_fill(std::wostream & strm, const _oox_fill & val) ...@@ -116,17 +117,17 @@ void oox_serialize_bitmap_fill(std::wostream & strm, const _oox_fill & val)
//if (val.bitmap->rotate) CP_XML_ATTR(L"a:rotWithShape",*(val.bitmap->rotate)); //if (val.bitmap->rotate) CP_XML_ATTR(L"a:rotWithShape",*(val.bitmap->rotate));
//else CP_XML_ATTR(L"a:rotWithShape",1); //else CP_XML_ATTR(L"a:rotWithShape",1);
if (val.bitmap->dpi) CP_XML_ATTR(L"a:dpi",*val.bitmap->dpi); if (val.bitmap->dpi) CP_XML_ATTR(L"a:dpi", *val.bitmap->dpi);
CP_XML_NODE(L"a:blip") CP_XML_NODE(L"a:blip")
{ {
if (val.bitmap->isInternal) if (val.bitmap->isInternal)
{ {
CP_XML_ATTR(L"xmlns:r", L"http://schemas.openxmlformats.org/officeDocument/2006/relationships"); CP_XML_ATTR(L"xmlns:r", L"http://schemas.openxmlformats.org/officeDocument/2006/relationships");
CP_XML_ATTR(L"r:embed",val.bitmap->rId ); CP_XML_ATTR(L"r:embed", val.bitmap->rId );
} }
else else
CP_XML_ATTR(L"r:link",val.bitmap->rId ); CP_XML_ATTR(L"r:link", val.bitmap->rId );
if (val.opacity) if (val.opacity)
{ {
...@@ -151,8 +152,8 @@ void oox_serialize_bitmap_fill(std::wostream & strm, const _oox_fill & val) ...@@ -151,8 +152,8 @@ void oox_serialize_bitmap_fill(std::wostream & strm, const _oox_fill & val)
CP_XML_NODE(L"a:tile") CP_XML_NODE(L"a:tile")
{ {
//tx="0" ty="0" sx="100000" sy="100000" //tx="0" ty="0" sx="100000" sy="100000"
CP_XML_ATTR(L"flip","none"); CP_XML_ATTR(L"flip", "none");
CP_XML_ATTR(L"algn",L"ctr"); CP_XML_ATTR(L"algn", L"ctr");
} }
} }
else if (val.bitmap->bStretch) else if (val.bitmap->bStretch)
...@@ -173,7 +174,11 @@ void oox_serialize_bitmap_fill(std::wostream & strm, const _oox_fill & val) ...@@ -173,7 +174,11 @@ void oox_serialize_bitmap_fill(std::wostream & strm, const _oox_fill & val)
} }
void oox_serialize_gradient_fill(std::wostream & strm, const _oox_fill & val) void oox_serialize_gradient_fill(std::wostream & strm, const _oox_fill & val)
{ {
if (!val.gradient)return; if (!val.gradient)
{
return;
}
CP_XML_WRITER(strm) CP_XML_WRITER(strm)
{ {
CP_XML_NODE(L"a:gradFill") CP_XML_NODE(L"a:gradFill")
...@@ -186,8 +191,8 @@ void oox_serialize_gradient_fill(std::wostream & strm, const _oox_fill & val) ...@@ -186,8 +191,8 @@ void oox_serialize_gradient_fill(std::wostream & strm, const _oox_fill & val)
{ {
CP_XML_NODE(L"a:gs") CP_XML_NODE(L"a:gs")
{ {
CP_XML_ATTR(L"pos",(int)(col.pos *1000));//% CP_XML_ATTR(L"pos", (int)(col.pos * 1000));//%
oox_serialize_srgb(CP_XML_STREAM(),col.color_ref,col.opacity); oox_serialize_srgb(CP_XML_STREAM(), col.color_ref, col.opacity);
} }
} }
} }
...@@ -234,13 +239,13 @@ void oox_serialize_hatch_fill(std::wostream & strm, const _oox_fill & val) ...@@ -234,13 +239,13 @@ void oox_serialize_hatch_fill(std::wostream & strm, const _oox_fill & val)
CP_XML_ATTR(L"prst",val.hatch->preset); CP_XML_ATTR(L"prst",val.hatch->preset);
CP_XML_NODE(L"a:fgClr")//опять для ms важно что этот цвет перед back CP_XML_NODE(L"a:fgClr")//опять для ms важно что этот цвет перед back
{ {
oox_serialize_srgb(CP_XML_STREAM(),val.hatch->color_ref,val.opacity); oox_serialize_srgb(CP_XML_STREAM(), val.hatch->color_ref, val.opacity);
} }
if (val.hatch->color_back_ref) if (val.hatch->color_back_ref)
{ {
CP_XML_NODE(L"a:bgClr") CP_XML_NODE(L"a:bgClr")
{ {
oox_serialize_srgb(CP_XML_STREAM(),*val.hatch->color_back_ref,val.opacity); oox_serialize_srgb(CP_XML_STREAM(), *val.hatch->color_back_ref ,val.opacity);
} }
} }
......
...@@ -44,17 +44,18 @@ namespace oox { ...@@ -44,17 +44,18 @@ namespace oox {
class oox_solid_fill; class oox_solid_fill;
typedef _CP_PTR(oox_solid_fill) oox_solid_fill_ptr; typedef _CP_PTR(oox_solid_fill) oox_solid_fill_ptr;
class oox_solid_fill class oox_solid_fill
{ {
public: public:
std::wstring color; std::wstring color;
static oox_solid_fill_ptr create(); static oox_solid_fill_ptr create();
}; };
/////////////////////////////////// ///////////////////////////////////
class oox_bitmap_fill; class oox_bitmap_fill;
typedef _CP_PTR(oox_bitmap_fill) oox_bitmap_fill_ptr; typedef _CP_PTR(oox_bitmap_fill) oox_bitmap_fill_ptr;
class oox_bitmap_fill class oox_bitmap_fill
{ {
public: public:
...@@ -78,6 +79,7 @@ namespace oox { ...@@ -78,6 +79,7 @@ namespace oox {
///////////////////////////////////////////////////////// /////////////////////////////////////////////////////////
class oox_hatch_fill; class oox_hatch_fill;
typedef _CP_PTR(oox_hatch_fill) oox_hatch_fill_ptr; typedef _CP_PTR(oox_hatch_fill) oox_hatch_fill_ptr;
class oox_hatch_fill class oox_hatch_fill
{ {
public: public:
...@@ -92,25 +94,26 @@ namespace oox { ...@@ -92,25 +94,26 @@ namespace oox {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
class oox_gradient_fill; class oox_gradient_fill;
typedef _CP_PTR(oox_gradient_fill) oox_gradient_fill_ptr; typedef _CP_PTR(oox_gradient_fill) oox_gradient_fill_ptr;
class oox_gradient_fill class oox_gradient_fill
{ {
public: public:
struct _color_position struct _color_position
{ {
double pos; double pos;
std::wstring color_ref; std::wstring color_ref;
_CP_OPT(double) opacity; _CP_OPT(double) opacity;
}; };
static oox_gradient_fill_ptr create(); static oox_gradient_fill_ptr create();
oox_gradient_fill() : style(0), angle(0) oox_gradient_fill() : style(0), angle(90)//from top to bottom
{ {
memset(rect,0,sizeof(double)*4); memset(rect, 0, sizeof(double) * 4);
} }
int style; int style;
double rect[4]; double rect[4];
double angle; double angle;
std::vector<_color_position> colors; std::vector<_color_position> colors;
...@@ -119,14 +122,14 @@ namespace oox { ...@@ -119,14 +122,14 @@ namespace oox {
struct _oox_fill struct _oox_fill
{ {
_oox_fill() : type(-1){} _oox_fill() : type(-1){}
oox_gradient_fill_ptr gradient; oox_gradient_fill_ptr gradient;
oox_hatch_fill_ptr hatch; oox_hatch_fill_ptr hatch;
oox_bitmap_fill_ptr bitmap; oox_bitmap_fill_ptr bitmap;
oox_solid_fill_ptr solid; oox_solid_fill_ptr solid;
_CP_OPT(double) opacity; _CP_OPT(double) opacity;
int type; int type;
void clear() void clear()
{ {
......
...@@ -454,7 +454,7 @@ void pptx_slide_context::process_images() ...@@ -454,7 +454,7 @@ void pptx_slide_context::process_images()
std::wstring rId = impl_->get_mediaitems().add_or_find(L"", typeShape, isMediaInternal, ref); std::wstring rId = impl_->get_mediaitems().add_or_find(L"", typeShape, isMediaInternal, ref);
impl_->add_drawing(drawing, isMediaInternal, rId, ref, typeShape);//объект impl_->add_drawing(drawing, isMediaInternal, rId, ref, typeShape);//объект
}else }else if (!drawing.fill.bitmap->rId.empty())
{ {
impl_->add_drawing(drawing, isMediaInternal, drawing.fill.bitmap->rId , ref, drawing.type);//объект impl_->add_drawing(drawing, isMediaInternal, drawing.fill.bitmap->rId , ref, drawing.type);//объект
} }
......
...@@ -501,7 +501,34 @@ void Compute_GraphicFill(const common_draw_fill_attlist & props, const office_el ...@@ -501,7 +501,34 @@ void Compute_GraphicFill(const common_draw_fill_attlist & props, const office_el
} }
} }
if (props.draw_fill_) if (props.draw_fill_)
{
fill.type = props.draw_fill_->get_type(); fill.type = props.draw_fill_->get_type();
}
switch(fill.type)
{
case 1:
if (!fill.solid) fill.type = -1;
case 2:
if (!fill.bitmap)
{
if (fill.solid) fill.type = 1;
else fill.type = -1;
}
break;
case 3:
if (!fill.gradient)
{
fill.gradient = oox::oox_gradient_fill::create();
}
break;
case 4:
if (!fill.hatch)
{
fill.hatch = oox::oox_hatch_fill::create();
}
break;
}
} }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
......
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