Commit b898a069 authored by Elen.Subbotina's avatar Elen.Subbotina Committed by Alexander Trofimov

XlsFile2

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@63758 954022d7-b5bf-4e40-9824-e11837661b57
parent 8dd81a89
......@@ -20,13 +20,9 @@ public:
void writeFields(CFRecord& record);
void readFields(CFRecord& record);
//-----------------------------
ODRAW::OfficeArtDggContainer rgChildRec;
public:
//BO_ATTRIB_MARKUP_BEGIN
//BO_ATTRIB_MARKUP_COMPLEX(rgChildRec)
//BO_ATTRIB_MARKUP_END
};
......
......@@ -38,6 +38,7 @@ public:
//-----------------------------
FtCmo cmo;
FtCf pictFormat;
FtPioGrbit pictFlags;
FtSbs sbs;
FtNts nts;
......
......@@ -13,14 +13,11 @@ class FtCmo : public BiffStructure
public:
BiffStructurePtr clone();
//virtual void setXMLAttributes(MSXML2::IXMLDOMElementPtr own_tag);
//virtual void getXMLAttributes(MSXML2::IXMLDOMElementPtr own_tag);
virtual void load(CFRecord& record);
virtual void store(CFRecord& record);
public:
unsigned short ot;
private:
unsigned short id;
bool fLocked;
......
......@@ -26,8 +26,6 @@ public:
delete rgfb[i];
}
}
virtual void loadFields(XLS::CFRecord& record);
virtual void storeFields(XLS::CFRecord& record);
......@@ -35,7 +33,6 @@ public:
// overriden
const unsigned short GetInstanceToStore();
public:
std::vector<OfficeArtBStoreContainerFileBlock*> rgfb;
};
......
......@@ -14,19 +14,6 @@ XLS::BiffStructurePtr OfficeArtBStoreContainerFileBlock::clone()
}
//void OfficeArtBStoreContainerFileBlock::setXMLAttributes(MSXML2::IXMLDOMElementPtr xml_tag)
//{
// bin_data_id = Document::appendBinaryData(xml_tag, pict_data, data_size);
// xml_tag->setAttribute("bin_data_id", bin_data_id);
// xml_tag->setAttribute("type", pict_type);
// xml_tag->setAttribute("rgbUid1", rgbUid1.c_str());
// xml_tag->setAttribute("rgbUid2", rgbUid2.c_str());
//}
//
//void OfficeArtBStoreContainerFileBlock::getXMLAttributes(MSXML2::IXMLDOMElementPtr xml_tag)
//{
//}
void OfficeArtBStoreContainerFileBlock::store(XLS::CFRecord& record)
{
}
......@@ -91,7 +78,7 @@ void OfficeArtBStoreContainerFileBlock::load(XLS::CFRecord& record)
{
case OfficeArtRecord::BlipEMF:
{
pict_type = L"emf";
pict_type = L".emf";
if (rc_header.recInstance == 0x3D4)
rgbUid1 = ReadMD4Digest(record);
else
......@@ -112,7 +99,7 @@ void OfficeArtBStoreContainerFileBlock::load(XLS::CFRecord& record)
break;
case OfficeArtRecord::BlipWMF:
{
pict_type = L"wmf";
pict_type = L".wmf";
if (rc_header.recInstance == 0x216)
rgbUid1 = ReadMD4Digest(record);
else
......@@ -152,7 +139,7 @@ void OfficeArtBStoreContainerFileBlock::load(XLS::CFRecord& record)
}
break;
case OfficeArtRecord::BlipJPEG:
pict_type = L"jpeg";
pict_type = L".jpeg";
if ((rc_header.recInstance == 0x46A) || (rc_header.recInstance == 0x6E2))
{
skipLen = 17;
......@@ -168,7 +155,7 @@ void OfficeArtBStoreContainerFileBlock::load(XLS::CFRecord& record)
}
break;
case OfficeArtRecord::BlipPNG:
pict_type = L"png";
pict_type = L".png";
if (rc_header.recInstance == 0x6E0) {
skipLen = 17;
rgbUid1 = ReadMD4Digest(record);
......@@ -200,7 +187,7 @@ void OfficeArtBStoreContainerFileBlock::load(XLS::CFRecord& record)
dumpToFile = false;
break;
case OfficeArtRecord::BlipTIFF:
pict_type = L"tiff";
pict_type = L".tiff";
if (rc_header.recInstance == 0x6E4)
{
skipLen = 17;
......
......@@ -24,7 +24,7 @@ public:
{
data_size = 0;
pict_data = NULL;
pict_type = L"jpeg";
pict_type = L".jpeg";
rgbUid1 = L"";
rgbUid2 = L"";
result = false;
......@@ -38,14 +38,22 @@ public:
pict_data = NULL;
}
}
virtual void load(XLS::CFRecord& record);
virtual void store(XLS::CFRecord& record);
void readCompressedData(XLS::CFRecord& record, OfficeArtMetafileHeader metafileHeader);
int bin_data_id;
size_t data_size;
char* pict_data;
std::wstring pict_type;
size_t recType;
std::wstring rgbUid1;
std::wstring rgbUid2;
bool result;
private:
const std::wstring ReadMD4Digest(XLS::CFRecord& record)
{
......@@ -59,18 +67,6 @@ private:
return result;
}
private:
int bin_data_id;
size_t data_size;
char* pict_data;
std::wstring pict_type;
public:
size_t recType;
std::wstring rgbUid1;
std::wstring rgbUid2;
bool result;
};
typedef boost::shared_ptr<OfficeArtBStoreContainerFileBlock> OfficeArtBStoreContainerFileBlockPtr;
......
......@@ -17,18 +17,15 @@ class OfficeArtContainer : public OfficeArtRecord
public:
OfficeArtContainer(const unsigned char recVer, const unsigned short recType, const OfficeArtClientAnchorType anchor_type);
// overridden:
virtual void loadFields(XLS::CFRecord& record);
virtual void storeFields(XLS::CFRecord& record);
static OfficeArtRecordPtr loadAnyArtRecord(XLS::CFRecord& record);
private:
std::vector<OfficeArtRecordPtr> child_records;
OfficeArtClientAnchorType anchor_type_;
std::vector<OfficeArtRecordPtr> child_records;
OfficeArtClientAnchorType anchor_type_;
};
typedef boost::shared_ptr<OfficeArtContainer> OfficeArtContainerPtr;
......
......@@ -29,8 +29,6 @@ public:
OfficeArtRecordHeader rh_own;
public:
enum OfficeArtRecordType
{
DggContainer = 0xF000,
......@@ -74,6 +72,7 @@ public:
SecondaryFOPT = 0xF121,
TertiaryFOPT = 0xF122, // Implemented
};
enum OfficeArtClientAnchorType
{
CA_Sheet,
......
......@@ -11,16 +11,6 @@ XLS::BiffStructurePtr OfficeArtRecordHeader::clone()
{
return XLS::BiffStructurePtr(new OfficeArtRecordHeader(*this));
}
//
//
//void OfficeArtRecordHeader::setXMLAttributes(MSXML2::IXMLDOMElementPtr xml_tag)
//{
//}
//
//void OfficeArtRecordHeader::getXMLAttributes(MSXML2::IXMLDOMElementPtr xml_tag)
//{
//}
//
void OfficeArtRecordHeader::store(XLS::CFRecord& record)
{
......@@ -36,7 +26,7 @@ void OfficeArtRecordHeader::load(XLS::CFRecord& record)
{
unsigned short ver_inst;
record >> ver_inst >> recType >> recLen;
recVer = GETBITS(ver_inst, 0, 3);
recVer = GETBITS(ver_inst, 0, 3);
recInstance = GETBITS(ver_inst, 4, 15);
}
......
......@@ -16,19 +16,16 @@ class OfficeArtRecordHeader : public XLS::BiffStructure
BASE_STRUCTURE_DEFINE_CLASS_NAME(OfficeArtRecordHeader)
public:
XLS::BiffStructurePtr clone();
virtual void load(XLS::CFRecord& record);
virtual void store(XLS::CFRecord& record);
const size_t size() const;
public:
unsigned char recVer;
unsigned short recInstance;
unsigned short recType;
unsigned int recLen;
unsigned char recVer;
unsigned short recInstance;
unsigned short recType;
unsigned int recLen;
};
typedef boost::shared_ptr<OfficeArtRecordHeader> OfficeArtRecordHeaderPtr;
......
......@@ -31,6 +31,9 @@ const bool MSODRAWINGGROUP::loadContent(BinProcessor& proc)
{
return false;
}
m_MsoDrawingGroup = elements_.back();
elements_.pop_back();
proc.repeated<Continue>(0, 0);
return true;
......
......@@ -20,6 +20,8 @@ public:
static const ElementType type = typeMSODRAWINGGROUP;
BaseObjectPtr m_MsoDrawingGroup;
bool is_inside_chart_sheet_;
};
......
......@@ -30,6 +30,10 @@ const bool OBJ::loadContent(BinProcessor& proc)
{
return false;
}
m_Obj = elements_.back();
elements_.pop_back();
proc.repeated<Continue>(0, 0);
return true;
......
......@@ -18,6 +18,8 @@ public:
virtual const bool loadContent(BinProcessor& proc);
BaseObjectPtr m_Obj;
static const ElementType type = typeOBJ;
};
......
......@@ -7,11 +7,11 @@
long ConvertXls2Xlsx(const std::wstring & srcFile, const std::wstring & dstPath, const ProgressCallback* pCallBack)
{
XlsConverter converter(srcFile, pCallBack);
XlsConverter converter(srcFile, dstPath, pCallBack);
converter.convertDocument();
converter.write(dstPath);
converter.write();
return 0;
......
......@@ -18,20 +18,30 @@
#include "../XlsFormat/Logic/Biff_unions/HLINK.h"
#include "../XlsFormat/Logic/Biff_unions/LBL.h"
#include "../XlsFormat/Logic/Biff_unions/OBJECTS.h"
#include "../XlsFormat/Logic/Biff_unions/MSODRAWINGGROUP.h"
#include "../XlsFormat/Logic/Biff_unions/OBJ.h"
#include <Logic/Biff_records/HLink.h>
#include <Logic/Biff_records/MsoDrawingGroup.h>
#include <Logic/Biff_records/MsoDrawing.h>
#include <Logic/Biff_records/Obj.h>
#include <Logic/Biff_structures/URLMoniker.h>
#include <Logic/Biff_structures/FileMoniker.h>
#include <Logic/Biff_structures/ODRAW/OfficeArtBStoreContainer.h>
#include "xlsx_conversion_context.h"
#include "xlsx_package.h"
#include <simple_xml_writer.h>
#include <vector>
#include <boost/lexical_cast.hpp>
#include "../../../DesktopEditor/common/File.h"
XlsConverter::XlsConverter(const std::wstring & path, const ProgressCallback* CallBack)
XlsConverter::XlsConverter(const std::wstring & xls_file, const std::wstring & _xlsx_path, const ProgressCallback* CallBack)
{
xlsx_path = _xlsx_path;
output_document = NULL;
xlsx_context = NULL;
......@@ -39,7 +49,7 @@ XlsConverter::XlsConverter(const std::wstring & path, const ProgressCallback* Ca
bUserStopConvert = false;
try{
XLS::CompoundFile cfile(path, XLS::CompoundFile::cf_ReadMode);
XLS::CompoundFile cfile(xls_file, XLS::CompoundFile::cf_ReadMode);
XLS::CFStreamPtr summary;
XLS::CFStreamPtr doc_summary;
......@@ -120,10 +130,10 @@ bool XlsConverter::UpdateProgress(long nComplete)
return FALSE;
}
void XlsConverter::write(const std::wstring & path)
void XlsConverter::write()
{
if (!output_document)return;
output_document->write(path);
output_document->write(xlsx_path);
delete output_document; output_document = NULL;
......@@ -243,7 +253,7 @@ void XlsConverter::convert(XLS::WorksheetSubstream* sheet)
}
for (long i = 0 ; i < sheet->m_HLINK.size(); i++)
{
convert(sheet->m_HLINK[i].get());
convert((XLS::HLINK*)sheet->m_HLINK[i].get());
}
convert((XLS::OBJECTS*)sheet->m_OBJECTS.get());
......@@ -269,7 +279,9 @@ void XlsConverter::convert(XLS::GlobalsSubstream* global)
}
for (long i = 0 ; i < global->m_MSODRAWINGGROUP.size(); i++)
{
convert((XLS::MSODRAWINGGROUP*)global->m_MSODRAWINGGROUP[i].get());
}
}
typedef boost::unordered_map<XLS::FillInfo, int> mapFillInfo;
......@@ -351,8 +363,61 @@ std::wstring XlsConverter::GetTargetMoniker(XLS::BiffStructure *moniker)
void XlsConverter::convert(XLS::MSODRAWINGGROUP * mso_drawing)
{
if ( mso_drawing == NULL) return;
XLS::MsoDrawingGroup * mso_group = dynamic_cast<XLS::MsoDrawingGroup*>(mso_drawing->m_MsoDrawingGroup.get());
if (mso_group == NULL) return;
for (long i = 0 ; i < mso_group->rgChildRec.child_records.size(); i++)
{
ODRAW::OfficeArtRecord * art_record = dynamic_cast<ODRAW::OfficeArtRecord*>(mso_group->rgChildRec.child_records[i].get());
if (art_record == NULL) return;
switch(art_record->rh_own.recType)
{
case ODRAW::OfficeArtRecord::BStoreContainer:
{
convert((ODRAW::OfficeArtBStoreContainer*)art_record);
}break;
case ODRAW::OfficeArtRecord::BlipPICT:
{
}break;
}
}
}
void XlsConverter::convert(ODRAW::OfficeArtBStoreContainer* art_bstore)
{
if (art_bstore == NULL) return;
for (long i =0 ; i < art_bstore->rgfb.size(); i++)
{
int bin_id = i + 1;
if (art_bstore->rgfb[i]->data_size > 0)
{
FileSystem::Directory::CreateDirectory((xlsx_path + FILE_SEPARATOR_STR + L"media").c_str());
std::wstring file_name = L"image" + boost::lexical_cast<std::wstring>(bin_id) + art_bstore->rgfb[i]->pict_type;
NSFile::CFileBinary file;
if (file.CreateFileW(xlsx_path + FILE_SEPARATOR_STR + L"media" + FILE_SEPARATOR_STR + file_name))
{
file.WriteFile((BYTE*)art_bstore->rgfb[i]->pict_data, art_bstore->rgfb[i]->data_size);
file.CloseFile();
}
xlsx_context->get_mediaitems().add_image(L"media/" + file_name, bin_id);
}
else
{
//???
}
}
}
void XlsConverter::convert(XLS::HLINK * HLINK_)
{
XLS::HLink * hLink = dynamic_cast<XLS::HLink*>(HLINK_->m_HLink.get());
......@@ -384,10 +449,16 @@ void XlsConverter::convert(XLS::OBJECTS* objects)
for (long i = 0 ; i < objects->m_OBJs.size(); i++)
{
xlsx_context->get_drawing_context().start_drawing(L"", 1);
XLS::OBJ* OBJ = dynamic_cast<XLS::OBJ*>(objects->m_OBJs[i].get());
XLS::Obj *obj = dynamic_cast<XLS::Obj*>(OBJ->m_Obj.get());
if (obj->cmo.ot == 0x08)//image
{
xlsx_context->get_drawing_context().start_drawing(L"", obj->cmo.id);
xlsx_context->get_drawing_context().end_drawing();
xlsx_context->get_drawing_context().end_drawing();
}
}
for (long i = 0 ; i < objects->m_CHARTs.size(); i++)
......
......@@ -35,13 +35,17 @@ namespace XLS
class LBL;
class OBJECTS;
class MSODRAWINGGROUP;
}
namespace ODRAW
{
class OfficeArtBStoreContainer;
}
class XlsConverter
{
public:
XlsConverter(const std::wstring & path, const ProgressCallback* ffCallBack);
XlsConverter(const std::wstring & xls_file, const std::wstring & xlsx_path, const ProgressCallback* ffCallBack);
~XlsConverter() ;
const ProgressCallback* pCallBack;
......@@ -49,11 +53,12 @@ public:
bool UpdateProgress(long nComplete);
void convertDocument();
void write(const std::wstring & path);
void write();
void convert(XLS::BaseObject *xls_unknown);
private:
std::wstring xlsx_path;
oox::package::xlsx_document *output_document;
oox::xlsx_conversion_context *xlsx_context;
......@@ -70,6 +75,7 @@ private:
void convert(XLS::LBL * def_name);
void convert(XLS::OBJECTS * objects);
void convert(XLS::MSODRAWINGGROUP * mso_drawing);
void convert(ODRAW::OfficeArtBStoreContainer* art_bstore);
std::wstring GetTargetMoniker(XLS::BiffStructure *moniker);
......
#include "external_items.h"
#include <boost/regex.hpp>
#include <boost/foreach.hpp>
#include <boost/algorithm/string/case_conv.hpp>
#include <boost/lexical_cast.hpp>
#include <utils.h>
#include "oox_rels.h"
#include "mediaitems_utils.h"
#include "../../../Common/DocxFormat/Source/Base/Base.h"
#include "../../../Common/DocxFormat/Source/SystemUtility/File.h"
#include "../../../DesktopEditor/raster/ImageFileFormatChecker.h"
namespace oox {
external_items::item::item( std::wstring const & _uri, Type _type, bool _mediaInternal, int _id, std::wstring const & _rId )
: uri(_uri), type(_type), mediaInternal(_mediaInternal), id(_id), rId(_rId)
{
}
//std::wstring external_items::add_or_find(const std::wstring & href, Type type, bool & isInternal)
//{
// std::wstring ref;
// return add_or_find(href, type, isInternal, ref);
//}
std::wstring static get_default_file_name(external_items::Type type)
{
switch (type)
{
case external_items::typeImage:
return L"image";
case external_items::typeChart:
return L"chart";
case external_items::typeMedia:
return L"media";
default:
return L"";
}
}
//std::wstring external_items::create_file_name(const std::wstring & uri, external_items::Type type, size_t Num)
//{
// if (uri.empty()) return L"";
//
// std::wstring sExt;
// int n = uri.rfind(L".");
// if (n>0) sExt = uri.substr(n);
// else if (n==0)
// {
//
// }
// //todooo
//
// return get_default_file_name(type) + boost::lexical_cast<std::wstring>(Num) + sExt;
//}
std::wstring external_items::add_image(const std::wstring & image, int bin_id)
{
const bool isMediaInternal = true;
std::wstring rId = std::wstring(L"picId") + boost::lexical_cast<std::wstring>(count_image+1);
count_image++;
items_.push_back( item(image, typeImage, isMediaInternal, bin_id, rId) );
return rId;
}
std::wstring external_items::find_image(int _id, std::wstring & target, bool & isInternal)
{
for (long i=0 ; i <items_.size(); i ++)
{
if (items_[i].type == typeImage && items_[i].id == _id)
{
target = items_[i].uri;
isInternal = items_[i].mediaInternal;
return items_[i].rId;
}
}
return L"";
}
void external_items::dump_rels(rels & Rels)
{
size_t i = 0;
BOOST_FOREACH(item & elm, items_)
{
Rels.add( relationship(
elm.rId,
utils::media::get_rel_type(elm.type),
elm.uri,
elm.mediaInternal ? L"" : L"External" )
);
}
}
}
......@@ -7,12 +7,12 @@ namespace oox {
class rels;
class mediaitems
class external_items
{
public:
enum Type { typeUnknown = 0, typeImage, typeChart, typeShape, typeTable, typeHyperlink, typeComment, typeMedia};
mediaitems()
external_items()
{
count_charts =0;
count_shape =0;
......@@ -25,20 +25,18 @@ public:
struct item
{
item(
std::wstring const & _href,
std::wstring const & _uri,
Type _type,
std::wstring const & _outputName,
bool _mediaInternal,
std::wstring const & _Id);
bool _mediaInternal, int id,
std::wstring const & _rId);
std::wstring href;
int id;
std::wstring uri;
Type type;
std::wstring outputName;
bool mediaInternal;
bool valid;
std::wstring Id;
int count_used;
int count_add;
std::wstring rId;
//int count_used;
//int count_add;
};
typedef std::vector< item > items_array;
......@@ -48,17 +46,17 @@ public:
size_t count_shape;
size_t count_tables;
std::wstring add_or_find(const std::wstring & href, Type type, bool & isInternal);//
std::wstring add_or_find(const std::wstring & href, Type type, bool & isInternal, std::wstring & ref);
//std::wstring add_or_find(const std::wstring & href, Type type, bool & isInternal);//
std::wstring add_image(const std::wstring & file_name, int bin_id);
std::wstring find_image(int id, std::wstring & target, bool & isExternal);
void dump_rels(rels & Rels);
items_array & items() { return items_; }
private:
std::wstring create_file_name(const std::wstring & uri, mediaitems::Type type, size_t Num);
std::wstring create_file_name(const std::wstring & uri, external_items::Type type, size_t Num);
items_array items_;
std::wstring odf_packet_;
};
......
#include "mediaitems.h"
#include <boost/regex.hpp>
#include <boost/foreach.hpp>
#include <boost/algorithm/string/case_conv.hpp>
#include <boost/lexical_cast.hpp>
#include <utils.h>
#include "oox_rels.h"
#include "mediaitems_utils.h"
#include "../../../Common/DocxFormat/Source/Base/Base.h"
#include "../../../Common/DocxFormat/Source/SystemUtility/File.h"
#include "../../../DesktopEditor/raster/ImageFileFormatChecker.h"
namespace oox {
mediaitems::item::item( std::wstring const & _href,
Type _type,
std::wstring const & _outputName,
bool _mediaInternal,
std::wstring const & _Id
)
: href(_href),
type(_type),
outputName(_outputName),
mediaInternal(_mediaInternal),
Id(_Id),
valid(true) // ""
{
count_add = 1;
count_used = 0;
}
std::wstring mediaitems::add_or_find(const std::wstring & href, Type type, bool & isInternal)
{
std::wstring ref;
return add_or_find(href, type, isInternal, ref);
}
std::wstring static get_default_file_name(mediaitems::Type type)
{
switch (type)
{
case mediaitems::typeImage:
return L"image";
case mediaitems::typeChart:
return L"chart";
case mediaitems::typeMedia:
return L"media";
default:
return L"";
}
}
std::wstring mediaitems::create_file_name(const std::wstring & uri, mediaitems::Type type, size_t Num)
{
if (uri.empty()) return L"";
std::wstring sExt;
int n = uri.rfind(L".");
if (n>0) sExt = uri.substr(n);
else if (n==0)
{
}
//todooo
return get_default_file_name(type) + boost::lexical_cast<std::wstring>(Num) + sExt;
}
std::wstring mediaitems::add_or_find(const std::wstring & href, Type type, bool & isInternal, std::wstring & ref)
{
const bool isMediaInternal = utils::media::is_internal(href, odf_packet_);
std::wstring sub_path = L"media/";
std::wstring inputFileName;
if ( type == typeChart)
{
sub_path = L"charts/";
}
int number=0;
if ( type == typeChart)
number= count_charts+1;
else if ( type == typeImage)
number= count_image+1;
else if ( type == typeShape)
number= count_shape+1;
else if ( type == typeMedia)
number= count_media+1;
else
number= items_.size()+1;
inputFileName = create_file_name(href, type, number);
std::wstring inputPath = isMediaInternal ? odf_packet_ + FILE_SEPARATOR_STR + href : href;
std::wstring outputPath = isMediaInternal ? ( sub_path + inputFileName) : href;
if ( type == typeChart)outputPath= outputPath + L".xml";
std::wstring id;
BOOST_FOREACH(item & elm, items_)
{
if (elm.href == inputPath)
{
id = elm.Id;
outputPath = elm.outputName;
elm.count_add++;
break;
}
}
if (id.length() < 1)
{
if ( type == typeChart)
{
id = std::wstring(L"chId") + boost::lexical_cast<std::wstring>(count_charts+1);
count_charts++;
}
else if ( type == typeImage)
{
int n_svm = outputPath.rfind (L".svm");
if ( n_svm >= 0 )
{
outputPath = outputPath.substr(0, n_svm) + L".png";
}
id = std::wstring(L"picId") + boost::lexical_cast<std::wstring>(count_image+1);
count_image++;
}
else
{
id = std::wstring(L"rId") + boost::lexical_cast<std::wstring>(count_shape+1);
count_shape++;
}
items_.push_back( item(inputPath, type, xml::utils::replace_text_to_xml(outputPath), isMediaInternal, id) );
}
ref = outputPath;
isInternal = isMediaInternal;
return id;
}
void mediaitems::dump_rels(rels & Rels)
{
size_t i = 0;
BOOST_FOREACH(item & elm, items_)
{
if (elm.count_used > elm.count_add)continue; // ( ....)
Rels.add( relationship(
elm.Id,
utils::media::get_rel_type(elm.type),
elm.valid ? elm.outputName : L"NULL",
elm.mediaInternal ? L"" : L"External" )
);
elm.count_used++;
}
}
}
......@@ -14,26 +14,20 @@ namespace utils {
namespace media {
bool is_internal(const std::wstring & uri, const std::wstring & packetRoot)
bool is_internal(const std::wstring & uri)
{
if (uri.empty())return false;
std::wstring mediaPath = boost::regex_search(uri.begin(), uri.end(), boost::wregex(L"^/[A-Za-z]:"))
? std::wstring(uri.begin() + 1, uri.end())
: uri;
std::wstring resultPath = packetRoot + FILE_SEPARATOR_STR + mediaPath;
return FileSystem::Directory::IsExist(resultPath);
return FileSystem::Directory::IsExist(uri);
}
std::wstring get_rel_type(mediaitems::Type type)
std::wstring get_rel_type(external_items::Type type)
{
switch (type)
{
case mediaitems::typeImage:
case external_items::typeImage:
return L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image";
case mediaitems::typeChart:
case external_items::typeChart:
return L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart";
default:
return L"";
......
......@@ -2,14 +2,14 @@
#include <string>
#include "mediaitems.h"
#include "external_items.h"
namespace oox {
namespace utils {
namespace media {
bool is_internal(const std::wstring & uri, const std::wstring & packetRoot);
std::wstring get_rel_type(mediaitems::Type type);
bool is_internal(const std::wstring & uri);
std::wstring get_rel_type(external_items::Type type);
}
}
......
......@@ -7,7 +7,7 @@
#include "../../../ASCOfficeOdfFile/include/cpdoccore/utf8cpp/utf8.h"
#include "mediaitems.h"
#include "external_items.h"
#include "../../../DesktopEditor/common/File.h"
#include "../../../DesktopEditor/raster/ImageFileFormatChecker.h"
......@@ -55,16 +55,16 @@ bool content_types_file::add_or_find_default(const std::wstring & extension)
content_type_.add_default(extension, get_mime_type(extension));
return true;
}
void content_types_file::set_media(mediaitems & _Mediaitems)
void content_types_file::set_media(external_items & _Mediaitems)
{
BOOST_FOREACH( mediaitems::item & item, _Mediaitems.items() )
BOOST_FOREACH( external_items::item & item, _Mediaitems.items() )
{
if ((item.type == mediaitems::typeImage || item.type == mediaitems::typeMedia) && item.mediaInternal)
if ((item.type == external_items::typeImage || item.type == external_items::typeMedia) && item.mediaInternal)
{
int n = item.outputName.rfind(L".");
int n = item.uri.rfind(L".");
if (n > 0)
{
add_or_find_default(item.outputName.substr(n+1, item.outputName.length() - n));
add_or_find_default(item.uri.substr(n+1, item.uri.length() - n));
}
}
}
......@@ -209,31 +209,30 @@ void docProps_files::write(const std::wstring & RootPath)
////////////
media::media(mediaitems & _Mediaitems) : mediaitems_(_Mediaitems)
media::media(external_items & _Mediaitems) : mediaitems_(_Mediaitems)
{
}
void media::write(const std::wstring & RootPath)
{
std::wstring path = RootPath + FILE_SEPARATOR_STR + L"media";
FileSystem::Directory::CreateDirectory(path.c_str());
// std::wstring path = RootPath + FILE_SEPARATOR_STR + L"media";
BOOST_FOREACH( mediaitems::item & item, mediaitems_.items() )
{
if (item.mediaInternal && item.valid && item.type == mediaitems::typeImage )
{
std::wstring & file_name = item.href;
std::wstring file_name_out = RootPath + FILE_SEPARATOR_STR + item.outputName;
NSFile::CFileBinary::Copy(item.href, file_name_out);
}
}
// BOOST_FOREACH( external_items::item & item, mediaitems_.items() )
// {
// if (item.mediaInternal && item.type == external_items::typeImage )
// {
////std::wstring & file_name = item.href;
////std::wstring file_name_out = RootPath + FILE_SEPARATOR_STR + item.outputName;
////
////NSFile::CFileBinary::Copy(item.href, file_name_out);
// }
// }
}
///////////////////////////////////////////////////////////////////////////////////
charts::charts(mediaitems & _ChartsItems) : chartsitems_(_ChartsItems)
charts::charts(external_items & _ChartsItems) : chartsitems_(_ChartsItems)
{
}
......
......@@ -15,7 +15,7 @@
namespace oox {
class mediaitems;
class external_items;
namespace package
{
......@@ -52,7 +52,7 @@ public:
virtual void write(const std::wstring & RootPath);
content_type & get_content_type() { return content_type_; }
bool add_or_find_default(const std::wstring & extension);
void set_media(mediaitems & _Mediaitems);
void set_media(external_items & _Mediaitems);
protected:
content_type content_type_;
......@@ -173,26 +173,26 @@ private:
class media : public element
{
public:
media(mediaitems & _Mediaitems);
media(external_items & _Mediaitems);
public:
virtual void write(const std::wstring & RootPath);
private:
mediaitems & mediaitems_;
external_items & mediaitems_;
};
class charts : public element
{
public:
charts(mediaitems & _ChartsItems);
charts(external_items & _ChartsItems);
public:
virtual void write(const std::wstring & RootPath);
private:
mediaitems & chartsitems_;
external_items & chartsitems_;
};
......
......@@ -9,7 +9,7 @@
#include "xlsx_output_xml.h"
#include "mediaitems.h"
#include "external_items.h"
namespace oox {
......@@ -46,14 +46,14 @@ public:
// xlsx_comments_context & get_comments_context();
// xlsx_comments_context_handle & get_comments_context_handle();
mediaitems & get_mediaitems() { return mediaitems_; }
external_items & get_mediaitems() { return mediaitems_; }
private:
void create_new_sheet(std::wstring const & name);
package::xlsx_document *output_document_;
mediaitems mediaitems_;
external_items mediaitems_;
//CApplicationFonts *applicationFonts_;
std::vector<xlsx_xml_worksheet_ptr> sheets_;
......
......@@ -17,12 +17,12 @@ namespace oox {
class xlsx_drawing_context_handle::Impl
{
public:
Impl(mediaitems & items)
Impl(external_items & items)
: items_(items), next_rId_(1), next_drawing_id_(1)
{
}
mediaitems & get_mediaitems() { return items_; }
external_items & get_mediaitems() { return items_; }
size_t next_rId()
{
......@@ -46,7 +46,7 @@ public:
xlsx_drawings_ptr get_drawings();
private:
mediaitems & items_;
external_items & items_;
size_t next_rId_;
std::vector<drawing_elm> drawings_;
......@@ -54,7 +54,7 @@ private:
size_t next_drawing_id_;
};
xlsx_drawing_context_handle::xlsx_drawing_context_handle(mediaitems & items)
xlsx_drawing_context_handle::xlsx_drawing_context_handle(external_items & items)
: impl_(new xlsx_drawing_context_handle::Impl(items))
{
}
......@@ -82,16 +82,23 @@ xlsx_drawing_context::xlsx_drawing_context(xlsx_drawing_context_handle & h)
void xlsx_drawing_context::start_drawing(std::wstring const & name, int type)
{
count_object++;
bool isIternal = false;
std::wstring target;
std::wstring rId = handle_.impl_->get_mediaitems().find_image(type, target, isIternal);
if (!rId.empty())
{
xlsx_drawings_->add(stream_.str(), isIternal, rId , target, external_items::typeImage);
}
}
void xlsx_drawing_context::end_drawing()
{
bool isMediaInternal = true;
//std::wstring ref = L"A8";
//std::wstring rId = handle_.impl_->get_mediaitems().add_or_find(L"", mediaitems::typeImage, isMediaInternal, ref);
//xlsx_drawings_->add(stream_.str(), isMediaInternal, rId , ref, mediaitems::typeImage);
//xlsx_drawings_->add(stream_.str(), isMediaInternal, rId , ref, external_items::typeImage);
stream_.clear();
}
......
......@@ -6,12 +6,12 @@
namespace oox {
class mediaitems;
class external_items;
class xlsx_drawing_context_handle
{
public:
xlsx_drawing_context_handle(mediaitems & items);
xlsx_drawing_context_handle(external_items & items);
~xlsx_drawing_context_handle();
std::pair<std::wstring, std::wstring> add_drawing_xml(std::wstring const & content, xlsx_drawings_ptr drawings);
......
......@@ -16,58 +16,59 @@ class xlsx_drawings::Impl
{
struct rel_
{
rel_(bool is_internal, std::wstring const & rid, std::wstring const & ref, mediaitems::Type type) :
rel_(bool is_internal, std::wstring const & rid, std::wstring const & target, external_items::Type type) :
is_internal_(is_internal),
rid_(rid),
ref_(ref),
target_(target),
type_(type)
{}
bool is_internal_;
std::wstring rid_;
std::wstring ref_;
mediaitems::Type type_;
std::wstring target_;
external_items::Type type_;
};
public:
void add(std::wstring const & d,
bool isInternal,
std::wstring const & rid,
std::wstring const & ref,
mediaitems::Type type)
std::wstring const & target,
external_items::Type type)
{
xlsx_drawings_.push_back(d);
bool present = false;
BOOST_FOREACH(rel_ const & r, xlsx_drawing_rels_)
{
if (r.rid_ == rid && r.ref_ == ref)
if (r.rid_ == rid && r.target_ == target)
present = true;
}
if (!present)
{
xlsx_drawing_rels_.push_back(rel_(isInternal, rid, ref, type));
xlsx_drawing_rels_.push_back(rel_(isInternal, rid, target, type));
}
// BOOST_FOREACH(_hlink_desc h, d.hlinks)
// {
// xlsx_drawing_rels_.push_back(rel_(false, h.hId, h.hRef, mediaitems::typeHyperlink));
// xlsx_drawing_rels_.push_back(rel_(false, h.hId, h.hRef, external_items::typeHyperlink));
//}
}
void add(
bool isInternal,
std::wstring const & rid,
std::wstring const & ref,
mediaitems::Type type)
std::wstring const & target,
external_items::Type type)
{
bool present = false;
BOOST_FOREACH(rel_ const & r, xlsx_drawing_rels_)
BOOST_FOREACH(rel_ const & r, xlsx_drawing_rels_)
{
if (r.rid_ == rid && r.ref_ == ref)
if (r.rid_ == rid && r.target_ == target)
present = true;
}
if (!present)
{
xlsx_drawing_rels_.push_back(rel_(isInternal, rid, ref, type));
xlsx_drawing_rels_.push_back(rel_(isInternal, rid, target, type));
}
}
......@@ -99,33 +100,33 @@ public:
{
BOOST_FOREACH(rel_ const & r, xlsx_drawing_rels_)
{
if (r.type_ == mediaitems::typeChart)// -
if (r.type_ == external_items::typeChart)// -
{
Rels.add(relationship(
r.rid_,
utils::media::get_rel_type(r.type_),
(r.is_internal_ ? std::wstring(L"../") + r.ref_ : r.ref_),
(r.is_internal_ ? std::wstring(L"../") + r.target_ : r.target_),
(r.is_internal_ ? L"" : L"External")
)
);
}
else if (r.type_ == mediaitems::typeImage)
else if (r.type_ == external_items::typeImage)
{
Rels.add(relationship(
r.rid_,
utils::media::get_rel_type(r.type_),
r.is_internal_ ? std::wstring(L"../") + r.ref_ : r.ref_,
r.is_internal_ ? std::wstring(L"../") + r.target_ : r.target_,
(r.is_internal_ ? L"" : L"External")
)
);
}
//typeShape -
else if (r.type_ == mediaitems::typeHyperlink)// ... ... ..
else if (r.type_ == external_items::typeHyperlink)// ... ... ..
{
Rels.add(relationship(
r.rid_,
L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink",
r.ref_,
r.target_,
L"External")
);
}
......@@ -149,18 +150,18 @@ xlsx_drawings::~xlsx_drawings()
void xlsx_drawings::add(std::wstring const & d,
bool isInternal,
std::wstring const & rid,
std::wstring const & ref,
mediaitems::Type type)
std::wstring const & target,
external_items::Type type)
{
impl_->add(d, isInternal, rid, ref, type);
impl_->add(d, isInternal, rid, target, type);
}
void xlsx_drawings::add(
bool isInternal,
std::wstring const & rid,
std::wstring const & ref,
mediaitems::Type type)
std::wstring const & target,
external_items::Type type)
{
impl_->add(isInternal, rid, ref, type);
impl_->add(isInternal, rid, target, type);
}
void xlsx_drawings::serialize(std::wostream & _Wostream)
{
......
......@@ -3,7 +3,7 @@
#include <sstream>
#include <common.h>
#include "mediaitems.h"
#include "external_items.h"
namespace oox {
......@@ -34,14 +34,14 @@ public:
void add(std::wstring const & d,
bool isInternal,
std::wstring const & rid,
std::wstring const & ref,
mediaitems::Type type
std::wstring const & target,
external_items::Type type
);
void add(
bool isInternal,
std::wstring const & rid,
std::wstring const & ref,
mediaitems::Type type
std::wstring const & target,
external_items::Type type
);
bool empty() const;
......
......@@ -209,7 +209,7 @@ void xl_files::add_sheet(sheet_content_ptr sheet)
sheets_files_.add_sheet(sheet);
}
void xl_files::set_media(mediaitems & _Mediaitems)
void xl_files::set_media(external_items & _Mediaitems)
{
media_ = element_ptr( new media(_Mediaitems) );
}
......
......@@ -146,7 +146,7 @@ public:
void set_styles(element_ptr Element);
void set_sharedStrings(element_ptr Element);
void add_sheet(sheet_content_ptr sheet);
void set_media(mediaitems & _Mediaitems/*, CApplicationFonts *pAppFonts*/);
void set_media(external_items & _Mediaitems/*, CApplicationFonts *pAppFonts*/);
void set_drawings(element_ptr Element);
void set_vml_drawings(element_ptr Element);
void set_comments(element_ptr Element);
......
......@@ -305,11 +305,11 @@
Name="xlsx"
>
<File
RelativePath="..\XlsXlsxConverter\mediaitems.cpp"
RelativePath="..\XlsXlsxConverter\external_items.cpp"
>
</File>
<File
RelativePath="..\XlsXlsxConverter\mediaitems.h"
RelativePath="..\XlsXlsxConverter\external_items.h"
>
</File>
<File
......
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