mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-07-20 01:04:34 +08:00
fix bug #72328
This commit is contained in:
@ -754,7 +754,8 @@ void _docx_drawing::serialize(std::wostream & strm/*, bool insideOtherDrawing*/)
|
||||
return docx_serialize_child(strm, *this);
|
||||
|
||||
if (type == typeMsObject ||
|
||||
type == typeOleObject)
|
||||
type == typeOleObject ||
|
||||
type == typePDF)
|
||||
{
|
||||
docx_serialize_object(strm, *this);
|
||||
}
|
||||
|
||||
@ -43,8 +43,13 @@
|
||||
|
||||
#include "../../../DesktopEditor/common/Directory.h"
|
||||
#include "../../../DesktopEditor/raster/ImageFileFormatChecker.h"
|
||||
#include "../../../Common/OfficeFileFormatChecker.h"
|
||||
#include "../../../DesktopEditor/graphics/pro/Fonts.h"
|
||||
|
||||
#include "../../../DesktopEditor/graphics/MetafileToGraphicsRenderer.h"
|
||||
#include "../../../DesktopEditor/graphics/Image.h"
|
||||
#include "../../../PdfFile/PdfFile.h"
|
||||
|
||||
namespace cpdoccore {
|
||||
namespace oox {
|
||||
|
||||
@ -89,7 +94,7 @@ mediaitems::mediaitems(const std::wstring & odfPacket) : odf_packet_(odfPacket)
|
||||
count_activeX = 0;
|
||||
count_control = 0;
|
||||
|
||||
applicationFonts_ = NSFonts::NSApplication::Create();
|
||||
applicationFonts_ = NSFonts::NSApplication::Create();
|
||||
}
|
||||
mediaitems::~mediaitems()
|
||||
{
|
||||
@ -98,8 +103,13 @@ mediaitems::~mediaitems()
|
||||
}
|
||||
void mediaitems::set_font_directory(std::wstring pathFonts)
|
||||
{
|
||||
if (applicationFonts_)
|
||||
applicationFonts_->InitializeFromFolder(pathFonts);
|
||||
if (applicationFonts_)
|
||||
{
|
||||
if (pathFonts.empty())
|
||||
applicationFonts_->Initialize();
|
||||
else
|
||||
applicationFonts_->InitializeFromFolder(pathFonts);
|
||||
}
|
||||
}
|
||||
bool mediaitems::is_internal_path(const std::wstring& uri, const std::wstring& packetRoot)
|
||||
{
|
||||
@ -171,6 +181,7 @@ std::wstring static get_default_file_name(_rels_type type)
|
||||
case typeMsObject:
|
||||
return L"msObject";
|
||||
case typeOleObject:
|
||||
case typePDF:
|
||||
return L"oleObject";
|
||||
case typeMedia:
|
||||
return L"media";
|
||||
@ -183,7 +194,7 @@ std::wstring static get_default_file_name(_rels_type type)
|
||||
case typeControl:
|
||||
return L"control";
|
||||
case typeControlProps:
|
||||
return L"controlProps";
|
||||
return L"controlProps";
|
||||
default:
|
||||
return L"";
|
||||
}
|
||||
@ -227,6 +238,8 @@ std::wstring mediaitems::create_file_name(const std::wstring & uri, _rels_type t
|
||||
sExt = L".bin";
|
||||
else if ( type == typeChart)
|
||||
sExt = L".xml";
|
||||
else if ( type == typePDF)
|
||||
sExt = L".bin";
|
||||
|
||||
return get_default_file_name(type) + std::to_wstring(Num) + sExt;
|
||||
}
|
||||
@ -246,6 +259,16 @@ std::wstring mediaitems::detectImageFileExtension(const std::wstring &fileName)
|
||||
CImageFileFormatChecker image_checker;
|
||||
sExt = image_checker.DetectFormatByData(buffer, buffer_size);
|
||||
|
||||
if (sExt.empty())
|
||||
{
|
||||
std::wstring documentID;
|
||||
COfficeFileFormatChecker office_checker;
|
||||
|
||||
if (office_checker.isPdfFormatFile(buffer, buffer_size, documentID))
|
||||
{
|
||||
sExt = L"pdf";
|
||||
}
|
||||
}
|
||||
if (sExt.empty())
|
||||
{
|
||||
size_t n = fileName.rfind(L".");
|
||||
@ -268,7 +291,7 @@ std::wstring mediaitems::add_or_find(const std::wstring & href, _rels_type type,
|
||||
{
|
||||
sub_path = L"charts/";
|
||||
}
|
||||
else if ( type == typeMsObject || type == typeOleObject)
|
||||
else if ( type == typeMsObject || type == typeOleObject || type == typePDF)
|
||||
{
|
||||
isMediaInternal = is_internal(href, odf_packet_);
|
||||
sub_path = L"embeddings/";
|
||||
@ -293,8 +316,9 @@ std::wstring mediaitems::add_or_find(const std::wstring & href, _rels_type type,
|
||||
else if ( type == typeAudio) number = count_audio + 1;
|
||||
else if ( type == typeVideo) number = count_video + 1;
|
||||
else if ( type == typeSlide) number = count_slide + 1;
|
||||
else if ( type == typeMsObject ||
|
||||
type == typeOleObject) number = count_object + 1;
|
||||
else if ( type == typeMsObject ||
|
||||
type == typeOleObject ||
|
||||
type == typePDF) number = count_object + 1;
|
||||
else if ( type == typeControl) number = count_control + 1;
|
||||
else
|
||||
number = items_.size() + 1;
|
||||
@ -342,7 +366,7 @@ std::wstring mediaitems::add_or_find(const std::wstring & href, _rels_type type,
|
||||
id = std::wstring(L"picId") + std::to_wstring(count_image + 1);
|
||||
count_image++;
|
||||
}
|
||||
else if ( type == typeMsObject || type == typeOleObject)
|
||||
else if ( type == typeMsObject || type == typeOleObject || type == typePDF)
|
||||
{
|
||||
id = std::wstring(L"objId") + std::to_wstring(count_object + 1);
|
||||
count_object++;
|
||||
@ -414,6 +438,71 @@ void mediaitems::dump_rels(rels & Rels, _rels_type_place type_place)
|
||||
items_[i].count_used++;
|
||||
}
|
||||
}
|
||||
bool mediaitems::pdf2image(const std::wstring& pdf_file_name, const std::wstring& image_file_name)
|
||||
{
|
||||
_UINT32 nRes = 0;
|
||||
IOfficeDrawingFile* pReader = new CPdfFile(applicationFonts_);
|
||||
if (!pReader) return false;
|
||||
|
||||
bool bResult = pReader->LoadFromFile(pdf_file_name.c_str(), L"");
|
||||
|
||||
if (bResult)
|
||||
{
|
||||
// default as in CMetafileToRenderterRaster
|
||||
int nRasterFormat = 4;
|
||||
int nSaveType = 2;
|
||||
bool bIsOnlyFirst = true;
|
||||
bool bIsZip = true;
|
||||
int nRasterW = 100;
|
||||
int nRasterH = 100;
|
||||
|
||||
int nSaveFlags = (nSaveType & 0xF0) >> 4;
|
||||
nSaveType = nSaveType & 0x0F;
|
||||
|
||||
int nPagesCount = 1;
|
||||
|
||||
{
|
||||
int nRasterWCur = nRasterW;
|
||||
int nRasterHCur = nRasterH;
|
||||
|
||||
double dPageDpiX, dPageDpiY;
|
||||
double dWidth, dHeight;
|
||||
pReader->GetPageInfo(0, &dWidth, &dHeight, &dPageDpiX, &dPageDpiY);
|
||||
|
||||
if (nSaveFlags & 0x0F)
|
||||
{
|
||||
if (((dWidth < dHeight) && (nRasterWCur > nRasterHCur)) ||
|
||||
((dWidth > dHeight) && (nRasterWCur < nRasterHCur)))
|
||||
{
|
||||
int nTmp = nRasterWCur;
|
||||
nRasterWCur = nRasterHCur;
|
||||
nRasterHCur = nTmp;
|
||||
}
|
||||
}
|
||||
|
||||
if (1 == nSaveType)
|
||||
{
|
||||
double dKoef1 = nRasterWCur / dWidth;
|
||||
double dKoef2 = nRasterHCur / dHeight;
|
||||
if (dKoef1 > dKoef2)
|
||||
dKoef1 = dKoef2;
|
||||
|
||||
nRasterWCur = (int)(dWidth * dKoef1 + 0.5);
|
||||
nRasterHCur = (int)(dHeight * dKoef1 + 0.5);
|
||||
}
|
||||
else if (2 == nSaveType)
|
||||
{
|
||||
nRasterWCur = -1;
|
||||
nRasterHCur = -1;
|
||||
}
|
||||
|
||||
pReader->ConvertToRaster(0, image_file_name, nRasterFormat, nRasterWCur, nRasterHCur);
|
||||
}
|
||||
}
|
||||
|
||||
delete pReader;
|
||||
return bResult;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -106,6 +106,7 @@ public:
|
||||
case typeImage: return L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image";
|
||||
case typeChart: return L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart";
|
||||
case typeMsObject: return L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/package";
|
||||
case typePDF:
|
||||
case typeOleObject: return L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject";
|
||||
case typeHyperlink: return L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink";
|
||||
case typeMedia: return L"http://schemas.microsoft.com/office/2007/relationships/media";
|
||||
@ -146,6 +147,8 @@ public:
|
||||
return typeMedia;
|
||||
}
|
||||
|
||||
bool pdf2image(const std::wstring& pdf_file_name, const std::wstring& image_file_name);
|
||||
|
||||
private:
|
||||
std::wstring create_file_name (const std::wstring & uri, _rels_type type, bool & isInternal, size_t Num);
|
||||
std::wstring detectImageFileExtension (const std::wstring &fileName);
|
||||
|
||||
@ -43,6 +43,8 @@
|
||||
#include "../../../DesktopEditor/raster/Metafile/MetaFileCommon.h"
|
||||
#include "../../../DesktopEditor/raster/ImageFileFormatChecker.h"
|
||||
#include "../../../OOXML/Base/Base.h"
|
||||
#include "../../../Common/cfcpp/compoundfile.h"
|
||||
#include "../../../Common/3dParty/pole/pole.h"
|
||||
|
||||
namespace cpdoccore {
|
||||
namespace oox {
|
||||
@ -387,9 +389,9 @@ void media::write(const std::wstring & RootPath)
|
||||
for (size_t i = 0; i < items.size(); i++ )
|
||||
{
|
||||
if (items[i].valid && ( items[i].type == typeImage ||
|
||||
items[i].type == typeMedia ||
|
||||
items[i].type == typeAudio ||
|
||||
items[i].type == typeVideo ))
|
||||
items[i].type == typeMedia ||
|
||||
items[i].type == typeAudio ||
|
||||
items[i].type == typeVideo ))
|
||||
{
|
||||
std::wstring &file_name = items[i].href;
|
||||
std::wstring file_name_out = RootPath + FILE_SEPARATOR_STR + items[i].outputName;
|
||||
@ -431,18 +433,143 @@ void embeddings::write(const std::wstring & RootPath)
|
||||
|
||||
for (size_t i = 0; i < items.size(); i++ )
|
||||
{
|
||||
if ( items[i].mediaInternal && items[i].valid &&
|
||||
(items[i].type == typeMsObject || items[i].type == typeOleObject))
|
||||
{
|
||||
int pos = items[i].outputName.rfind(L".");
|
||||
std::wstring extension = pos >= 0 ? items[i].outputName.substr(pos + 1) : L"";
|
||||
|
||||
content_types.add_or_find_default(extension);
|
||||
int pos = items[i].outputName.rfind(L".");
|
||||
std::wstring extension = pos >= 0 ? items[i].outputName.substr(pos + 1) : L"";
|
||||
|
||||
std::wstring file_name_out = RootPath + FILE_SEPARATOR_STR + items[i].outputName;
|
||||
|
||||
content_types.add_or_find_default(extension);
|
||||
|
||||
std::wstring file_name_out = RootPath + FILE_SEPARATOR_STR + items[i].outputName;
|
||||
|
||||
if ( items[i].mediaInternal && items[i].valid &&
|
||||
(items[i].type == typeMsObject || items[i].type == typeOleObject ))
|
||||
{
|
||||
NSFile::CFileBinary::Copy(items[i].href, file_name_out);
|
||||
}
|
||||
else if (items[i].type == typePDF)
|
||||
{
|
||||
std::string name = "Acrobat Document";
|
||||
std::string class_name = "Acrobat Document";
|
||||
std::string class_name2 = "Acrobat.Document.DC";
|
||||
|
||||
_UINT32 name_size = (_UINT32)name.length() + 1;
|
||||
_UINT32 class_name_size = class_name.size() + 1;
|
||||
_UINT32 class_name2_size = class_name2.size() + 1;
|
||||
|
||||
DWORD nativeDataSize = 0;
|
||||
BYTE* nativeData = NULL;
|
||||
|
||||
NSFile::CFileBinary file;
|
||||
file.ReadAllBytes(items[i].href, &nativeData, nativeDataSize);
|
||||
|
||||
CFCPP::CompoundFile* storageOut = new CFCPP::CompoundFile(CFCPP::Ver_3, CFCPP::Default);
|
||||
if (storageOut && nativeData)
|
||||
{
|
||||
_UINT32 tmp = 0;
|
||||
//CompObj
|
||||
BYTE dataCompObjHeader[28] = { 0x01, 0x00, 0xfe, 0xff, 0x03, 0x0a, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
|
||||
0x65, 0xca, 0x01, 0xb8, 0xfc, 0xa1, 0xd0, 0x11, 0x85, 0xad, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00 };
|
||||
|
||||
std::shared_ptr<CFCPP::CFStream> oStreamCompObj = storageOut->RootStorage()->AddStream(L"\001CompObj");
|
||||
long long posStreamCompObj = 0;
|
||||
oStreamCompObj->Write((char*)dataCompObjHeader, 0, 28); posStreamCompObj += 28;
|
||||
|
||||
oStreamCompObj->Write((char*)&class_name_size, posStreamCompObj, 4); posStreamCompObj += 4;
|
||||
oStreamCompObj->Write((char*)class_name.c_str(), posStreamCompObj, class_name_size); posStreamCompObj += class_name_size;
|
||||
|
||||
tmp = 0;
|
||||
oStreamCompObj->Write((char*)&tmp, posStreamCompObj, 4); posStreamCompObj += 4;
|
||||
|
||||
oStreamCompObj->Write((char*)&class_name2_size, posStreamCompObj, 4); posStreamCompObj += 4;
|
||||
oStreamCompObj->Write((char*)class_name2.c_str(), posStreamCompObj, class_name2_size); posStreamCompObj += class_name2_size;
|
||||
|
||||
tmp = 0x71B239F4;
|
||||
oStreamCompObj->Write((char*)&tmp, posStreamCompObj, 4); posStreamCompObj += 4;// UnicodeMarker
|
||||
|
||||
tmp = 0;
|
||||
oStreamCompObj->Write((char*)&tmp, posStreamCompObj, 4); posStreamCompObj += 4;// UnicodeUserType
|
||||
oStreamCompObj->Write((char*)&tmp, posStreamCompObj, 4); posStreamCompObj += 4;// UnicodeClipboardFormat
|
||||
oStreamCompObj->Write((char*)&tmp, posStreamCompObj, 4); posStreamCompObj += 4;//
|
||||
|
||||
//Ole
|
||||
BYTE dataOleInfo[] = { 0x01, 0x00, 0x00, 0x02, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
|
||||
|
||||
std::shared_ptr<CFCPP::CFStream> oStreamOle = storageOut->RootStorage()->AddStream(L"\001Ole");
|
||||
oStreamOle->Write((char*)dataOleInfo, 0, 20);
|
||||
|
||||
//CONTENTS
|
||||
std::shared_ptr<CFCPP::CFStream> oStreamCONTENTS = storageOut->RootStorage()->AddStream(L"CONTENTS");
|
||||
oStreamCONTENTS->Write((char*)nativeData, 0, nativeDataSize);
|
||||
|
||||
//ObjInfo
|
||||
std::shared_ptr<CFCPP::CFStream> oStreamObjInfo = storageOut->RootStorage()->AddStream(L"\003ObjInfo");
|
||||
|
||||
BYTE dataObjInfo[] = { 0x00, 0x00, 0x03, 0x00, 0x0D, 0x00 };
|
||||
oStreamObjInfo->Write((char*)dataObjInfo, 0, 6);
|
||||
|
||||
bool result = storageOut->Save(file_name_out);
|
||||
storageOut->Close();
|
||||
}
|
||||
if (storageOut) delete storageOut;
|
||||
|
||||
//POLE::Storage* storageOut = new POLE::Storage(file_name_out.c_str());
|
||||
//if ((storageOut) && (storageOut->open(true, true)))
|
||||
//{
|
||||
// _UINT32 tmp = 0;
|
||||
// std::string name = class_name;
|
||||
// _UINT32 name_size = (_UINT32)name.length() + 1;
|
||||
////Ole
|
||||
// BYTE dataOleInfo[] = { 0x01, 0x00, 0x00, 0x02, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
|
||||
// POLE::Stream oStream3(storageOut, L"\001Ole", true, 20);
|
||||
// oStream3.write(dataOleInfo, 20);
|
||||
// oStream3.flush();
|
||||
////CompObj
|
||||
// BYTE dataCompObjHeader[28] = { 0x01, 0x00, 0xfe, 0xff, 0x03, 0x0a, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
|
||||
// 0x65, 0xca, 0x01, 0xb8, 0xfc, 0xa1, 0xd0, 0x11, 0x85, 0xad, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00 };
|
||||
|
||||
// POLE::Stream oStream1(storageOut, L"\001CompObj", true, 28 + (class_name_size + 4) + (class_name2_size + 4) + 4 * 4);
|
||||
// oStream1.write(dataCompObjHeader, 28);
|
||||
|
||||
// oStream1.write((BYTE*)&class_name_size, 4);
|
||||
// oStream1.write((BYTE*)class_name.c_str(), class_name_size);
|
||||
|
||||
// tmp = 0;
|
||||
// oStream1.write((BYTE*)&tmp, 4);
|
||||
|
||||
// oStream1.write((BYTE*)&class_name2_size, 4);
|
||||
// oStream1.write((BYTE*)class_name2.c_str(), class_name2_size);
|
||||
|
||||
// tmp = 0x71B239F4;
|
||||
// oStream1.write((BYTE*)&tmp, 4); // UnicodeMarker
|
||||
|
||||
// tmp = 0;
|
||||
// oStream1.write((BYTE*)&tmp, 4); // UnicodeUserType
|
||||
// oStream1.write((BYTE*)&tmp, 4); // UnicodeClipboardFormat
|
||||
// oStream1.write((BYTE*)&tmp, 4); //
|
||||
// oStream1.flush();
|
||||
|
||||
// //ObjInfo
|
||||
// BYTE dataObjInfo[] = { 0x00,0x00,0x03,0x00,0x0D,0x00 };
|
||||
// POLE::Stream oStream2(storageOut, L"\003ObjInfo", true, 6);
|
||||
// oStream2.write(dataObjInfo, 6);
|
||||
// oStream2.flush();
|
||||
|
||||
// POLE::Stream streamData(storageOut, L"CONTENTS", true, nativeDataSize);
|
||||
// _UINT32 sz_write = 0;
|
||||
// _UINT32 sz = 4096;
|
||||
// while (sz_write < nativeDataSize)
|
||||
// {
|
||||
// if (sz_write + sz > nativeDataSize)
|
||||
// sz = nativeDataSize - sz_write;
|
||||
// streamData.write(nativeData + sz_write, sz);
|
||||
// sz_write += sz;
|
||||
// }
|
||||
// streamData.flush();
|
||||
|
||||
// storageOut->close();
|
||||
// delete storageOut;
|
||||
//}
|
||||
if (nativeData) delete[]nativeData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -61,7 +61,8 @@ enum _rels_type
|
||||
typeActiveX,
|
||||
typeControl,
|
||||
typeControlProps,
|
||||
typeChartUserShapes
|
||||
typeChartUserShapes,
|
||||
typePDF
|
||||
};
|
||||
enum _rels_type_place
|
||||
{
|
||||
|
||||
@ -82,8 +82,9 @@ void draw_chart_attlist::add_attributes( const xml::attributes_wc_ptr & Attribut
|
||||
{
|
||||
//CP_APPLY_ATTR(L"draw:filter-name", draw_filter_name_);
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
// draw:image
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
const wchar_t * draw_image::ns = L"draw";
|
||||
const wchar_t * draw_image::name = L"image";
|
||||
|
||||
@ -100,7 +101,6 @@ void draw_image::add_attributes( const xml::attributes_wc_ptr & Attributes )
|
||||
draw_image_attlist_.add_attributes(Attributes);
|
||||
xlink_attlist_.add_attributes(Attributes);
|
||||
}
|
||||
|
||||
void draw_image::add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name)
|
||||
{
|
||||
if CP_CHECK_NAME(L"office", L"binary-data")
|
||||
@ -116,8 +116,9 @@ std::wostream & draw_image::text_to_stream(std::wostream & _Wostream, bool bXmlE
|
||||
{
|
||||
return _Wostream;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
// draw:chart
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
const wchar_t * draw_chart::ns = L"draw";
|
||||
const wchar_t * draw_chart::name = L"chart";
|
||||
|
||||
@ -145,8 +146,9 @@ void draw_chart::add_child_element( xml::sax * Reader, const std::wstring & Ns,
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
// draw:g
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
const wchar_t * draw_g::ns = L"draw";
|
||||
const wchar_t * draw_g::name = L"g";
|
||||
void draw_g::add_attributes( const xml::attributes_wc_ptr & Attributes )
|
||||
@ -242,8 +244,9 @@ std::wostream & draw_g::text_to_stream(std::wostream & _Wostream, bool bXmlEncod
|
||||
return _Wostream;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
// draw:frame
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
const wchar_t * draw_frame::ns = L"draw";
|
||||
const wchar_t * draw_frame::name = L"frame";
|
||||
|
||||
@ -252,7 +255,6 @@ std::wostream & draw_frame::text_to_stream(std::wostream & _Wostream, bool bXmlE
|
||||
CP_SERIALIZE_TEXT(content_, bXmlEncode);
|
||||
return _Wostream;
|
||||
}
|
||||
|
||||
void draw_frame::add_attributes( const xml::attributes_wc_ptr & Attributes )
|
||||
{
|
||||
idx_in_owner = -1;
|
||||
@ -263,7 +265,6 @@ void draw_frame::add_attributes( const xml::attributes_wc_ptr & Attributes )
|
||||
|
||||
draw_frame_attlist_.add_attributes(Attributes);
|
||||
}
|
||||
|
||||
void draw_frame::add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name)
|
||||
{
|
||||
if (CP_CHECK_NAME(L"draw", L"text-box") ||
|
||||
@ -325,8 +326,9 @@ void draw_text_box_attlist::add_attributes( const xml::attributes_wc_ptr & Attri
|
||||
CP_APPLY_ATTR(L"fo:max-height", fo_max_height_);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
// draw:text-box
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
const wchar_t * draw_text_box::ns = L"draw";
|
||||
const wchar_t * draw_text_box::name = L"text-box";
|
||||
|
||||
@ -352,8 +354,9 @@ void draw_text_box::add_child_element( xml::sax * Reader, const std::wstring & N
|
||||
CP_CREATE_ELEMENT(content_);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
// draw:object
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
const wchar_t * draw_object::ns = L"draw";
|
||||
const wchar_t * draw_object::name = L"object";
|
||||
|
||||
@ -379,8 +382,9 @@ void draw_object::add_child_element( xml::sax * Reader, const std::wstring & Ns,
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
// draw:object-ole
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
const wchar_t * draw_object_ole::ns = L"draw";
|
||||
const wchar_t * draw_object_ole::name = L"object-ole";
|
||||
|
||||
@ -444,7 +448,8 @@ void draw_object_ole::detectObject(const std::wstring &fileName, std::wstring &p
|
||||
COfficeFileFormatChecker checker(fileName);
|
||||
switch(checker.nFileType)
|
||||
{
|
||||
case AVS_OFFICESTUDIO_FILE_DOCUMENT_DOC: extension = L".doc"; prog = L"Word"; rels = oox::typeOleObject; break;
|
||||
case AVS_OFFICESTUDIO_FILE_DOCUMENT_DOC:
|
||||
case AVS_OFFICESTUDIO_FILE_DOCUMENT_DOC_FLAT: extension = L".doc"; prog = L"Word"; rels = oox::typeOleObject; break;
|
||||
case AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX: extension = L".docx"; prog = L"Word"; rels = oox::typeMsObject; break;
|
||||
|
||||
case AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLS: extension = L".xls"; prog = L"Excel"; rels = oox::typeOleObject; break;
|
||||
@ -517,8 +522,9 @@ std::wstring draw_object::office_convert(odf_document_ptr odfDocument, int type)
|
||||
|
||||
return href_result;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
// draw:param
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
const wchar_t * draw_param::ns = L"draw";
|
||||
const wchar_t * draw_param::name = L"param";
|
||||
|
||||
@ -532,8 +538,9 @@ void draw_param::add_child_element( xml::sax * Reader, const std::wstring & Ns,
|
||||
{
|
||||
CP_NOT_APPLICABLE_ELM();
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
// draw:plugin
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
const wchar_t * draw_plugin::ns = L"draw";
|
||||
const wchar_t * draw_plugin::name = L"plugin";
|
||||
|
||||
|
||||
@ -85,6 +85,8 @@ private:
|
||||
office_element_ptr office_binary_data_;
|
||||
|
||||
office_element_ptr draw_frame_ptr; //openoffice xml 1.0
|
||||
|
||||
bool convert_pdf2image(NSFonts::IApplicationFonts* applicationFonts, const std::wstring& pdf_file_name, const std::wstring& image_file_name);
|
||||
};
|
||||
|
||||
CP_REGISTER_OFFICE_ELEMENT2(draw_image);
|
||||
@ -146,10 +148,10 @@ public:
|
||||
class draw_frame : public office_element_impl<draw_frame>
|
||||
{
|
||||
public:
|
||||
static const wchar_t * ns;
|
||||
static const wchar_t * name;
|
||||
static const xml::NodeType xml_type = xml::typeElement;
|
||||
static const ElementType type = typeDrawFrame;
|
||||
static const wchar_t *ns;
|
||||
static const wchar_t *name;
|
||||
static const xml::NodeType xml_type = xml::typeElement;
|
||||
static const ElementType type = typeDrawFrame;
|
||||
CPDOCCORE_DEFINE_VISITABLE();
|
||||
|
||||
draw_frame() : oox_drawing_(), idx_in_owner(-1), is_object_(false) {}
|
||||
@ -165,33 +167,33 @@ public:
|
||||
|
||||
int idx_in_owner ;
|
||||
|
||||
odf_types::union_common_draw_attlists common_draw_attlists_;
|
||||
odf_types::union_common_draw_attlists common_draw_attlists_;
|
||||
|
||||
draw_frame_attlist draw_frame_attlist_;
|
||||
draw_frame_attlist draw_frame_attlist_;
|
||||
|
||||
// draw-text-box, draw-image, draw-object, draw-object-ole, draw-applet, draw-floating-frame, draw-plugin
|
||||
office_element_ptr_array content_;
|
||||
office_element_ptr_array content_;
|
||||
|
||||
office_element_ptr office_event_listeners_;
|
||||
office_element_ptr office_event_listeners_;
|
||||
|
||||
office_element_ptr draw_glue_point_;
|
||||
office_element_ptr draw_image_map_;
|
||||
office_element_ptr draw_glue_point_;
|
||||
office_element_ptr draw_image_map_;
|
||||
|
||||
office_element_ptr draw_contour_; // draw-contour-polygon or draw-contour-path
|
||||
office_element_ptr draw_contour_; // draw-contour-polygon or draw-contour-path
|
||||
|
||||
office_element_ptr svg_title_;
|
||||
office_element_ptr svg_desc_;
|
||||
office_element_ptr svg_title_;
|
||||
office_element_ptr svg_desc_;
|
||||
|
||||
friend class odf_document;
|
||||
friend class draw_image;
|
||||
friend class draw_chart;
|
||||
|
||||
oox_drawing_ptr oox_drawing_;
|
||||
oox_drawing_ptr oox_drawing_;
|
||||
|
||||
bool is_object_;
|
||||
bool is_object_;
|
||||
private:
|
||||
virtual void add_attributes ( const xml::attributes_wc_ptr & Attributes );
|
||||
virtual void add_child_element ( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name);
|
||||
virtual void add_attributes( const xml::attributes_wc_ptr & Attributes );
|
||||
virtual void add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name);
|
||||
|
||||
void docx_convert_start(oox::docx_conversion_context & Context);
|
||||
void docx_convert_end(oox::docx_conversion_context & Context);
|
||||
|
||||
@ -1200,6 +1200,7 @@ void draw_image::docx_convert(oox::docx_conversion_context & Context)
|
||||
|
||||
std::wstring href = xlink_attlist_.href_.get_value_or(L"");
|
||||
|
||||
oox::_rels_type type = oox::typeImage;
|
||||
if (true == href.empty())
|
||||
{
|
||||
office_binary_data* binary_data = dynamic_cast<office_binary_data*>(office_binary_data_.get());
|
||||
@ -1207,6 +1208,7 @@ void draw_image::docx_convert(oox::docx_conversion_context & Context)
|
||||
if (binary_data)
|
||||
{
|
||||
href = binary_data->write_to(Context.root()->get_folder());
|
||||
type = (oox::_rels_type)binary_data->type_binary_data;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -1229,7 +1231,7 @@ void draw_image::docx_convert(oox::docx_conversion_context & Context)
|
||||
if (href[0] == L'#') href = href.substr(1);
|
||||
|
||||
if (drawing->type == oox::typeUnknown)
|
||||
drawing->type = oox::typeImage;
|
||||
drawing->type = type;
|
||||
|
||||
oox::StreamsManPtr prev = Context.get_stream_man();
|
||||
|
||||
@ -1264,10 +1266,26 @@ void draw_image::docx_convert(oox::docx_conversion_context & Context)
|
||||
drawing->fill.bitmap = oox::oox_bitmap_fill::create();
|
||||
drawing->fill.type = 2;
|
||||
drawing->fill.bitmap->isInternal = false;
|
||||
drawing->fill.bitmap->rId = Context.get_mediaitems()->add_or_find(href, oox::typeImage, drawing->fill.bitmap->isInternal, href, Context.get_type_place());
|
||||
drawing->fill.bitmap->bStretch = true;
|
||||
|
||||
const std::wstring styleName = frame->common_draw_attlists_.shape_with_text_and_styles_.
|
||||
std::wstring href_out;
|
||||
if (drawing->type == oox::typePDF)
|
||||
{
|
||||
drawing->objectProgId = L"Acrobat.Document.DC";
|
||||
drawing->objectId = Context.get_mediaitems()->add_or_find(href, type, drawing->fill.bitmap->isInternal, href_out, Context.get_type_place());
|
||||
|
||||
std::wstring image_file = NSFile::CFileBinary::CreateTempFileWithUniqueName(Context.root()->get_folder() + FILE_SEPARATOR_STR, L"img");
|
||||
|
||||
if (Context.get_mediaitems()->pdf2image(Context.root()->get_folder() + FILE_SEPARATOR_STR + href, image_file))
|
||||
{
|
||||
int pos = image_file.rfind(FILE_SEPARATOR_STR);
|
||||
href = image_file.substr(pos + 1);
|
||||
}
|
||||
}
|
||||
|
||||
drawing->fill.bitmap->rId = Context.get_mediaitems()->add_or_find(href, oox::typeImage, drawing->fill.bitmap->isInternal, href_out, Context.get_type_place());
|
||||
|
||||
const std::wstring styleName = frame->common_draw_attlists_.shape_with_text_and_styles_.
|
||||
common_shape_draw_attlist_.draw_style_name_.get_value_or(L"");
|
||||
|
||||
odf_reader::style_instance* styleInst = Context.root()->odf_context().styleContainer().style_by_name(styleName, odf_types::style_family::Graphic,Context.process_headers_footers_);
|
||||
|
||||
@ -31,14 +31,12 @@
|
||||
*/
|
||||
|
||||
#include "office_binary_data.h"
|
||||
|
||||
#include <xml/xmlchar.h>
|
||||
#include "../../../DesktopEditor/raster/ImageFileFormatChecker.h"
|
||||
#include "../../../Common/OfficeFileFormatChecker.h"
|
||||
|
||||
namespace cpdoccore {
|
||||
namespace odf_reader {
|
||||
|
||||
|
||||
|
||||
// office:binary-data
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
const wchar_t * office_binary_data::ns = L"office";
|
||||
@ -72,9 +70,24 @@ std::wstring office_binary_data::write_to(const std::wstring & path)
|
||||
NSFile::CBase64Converter::Decode(base64Binary_.c_str(), base64Binary_.length(), pData, nLength);
|
||||
if (pData)
|
||||
{
|
||||
CImageFileFormatChecker image_checker;
|
||||
std::wstring sExt = image_checker.DetectFormatByData(pData, nLength);
|
||||
|
||||
if (sExt.empty())
|
||||
{
|
||||
std::wstring documentID;
|
||||
COfficeFileFormatChecker office_checker;
|
||||
|
||||
if (office_checker.isPdfFormatFile(pData, nLength, documentID))
|
||||
{
|
||||
type_binary_data = 20; // oox::_rels_type = typePDF;
|
||||
sExt = L"pdf";
|
||||
}
|
||||
}
|
||||
|
||||
NSFile::CFileBinary file;
|
||||
|
||||
std::wstring bin_file = file.CreateTempFileWithUniqueName(path + FILE_SEPARATOR_STR, L"bin");
|
||||
std::wstring bin_file = file.CreateTempFileWithUniqueName(path + FILE_SEPARATOR_STR, sExt);
|
||||
if (file.CreateFileW(bin_file))
|
||||
{
|
||||
file.WriteFile(pData, nLength);
|
||||
|
||||
@ -53,6 +53,7 @@ public:
|
||||
virtual std::wostream & text_to_stream(std::wostream & _Wostream, bool bXmlEncode = true) const;
|
||||
|
||||
std::wstring write_to(const std::wstring & path);
|
||||
int type_binary_data = 2; //_rels_type type = Image;
|
||||
private:
|
||||
virtual void add_attributes( const xml::attributes_wc_ptr & Attributes );
|
||||
virtual void add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name);
|
||||
|
||||
Reference in New Issue
Block a user