init repo
This commit is contained in:
267
ActiveX/ASCOfficePPTXFile/Editor/BinReaderWriterDefines.h
Normal file
267
ActiveX/ASCOfficePPTXFile/Editor/BinReaderWriterDefines.h
Normal file
@@ -0,0 +1,267 @@
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2014
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
* version 3 as published by the Free Software Foundation. In accordance with
|
||||
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||
* of any third-party rights.
|
||||
*
|
||||
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||
*
|
||||
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
|
||||
* EU, LV-1021.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of the Program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU AGPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||
* grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||
* well as technical writing content are licensed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
namespace NSBinPptxRW
|
||||
{
|
||||
const double eps = 0.001;
|
||||
|
||||
const double g_dKoef_mm_to_pt = 72 / (2.54 * 10);
|
||||
const double g_dKoef_mm_to_twips = 20 * g_dKoef_mm_to_pt;
|
||||
const double g_dKoef_mm_to_emu = 36000;
|
||||
const double g_dKoef_mm_to_eightpoint = 8 * g_dKoef_mm_to_pt;
|
||||
|
||||
const BYTE g_nodeAttributeStart = 0xFA;
|
||||
const BYTE g_nodeAttributeEnd = 0xFB;
|
||||
|
||||
namespace NSSerFormat
|
||||
{
|
||||
enum SerFormat
|
||||
{
|
||||
Version = 0,
|
||||
Signature = 0x50505459
|
||||
};
|
||||
}
|
||||
|
||||
namespace NSMainTables
|
||||
{
|
||||
enum MainTables
|
||||
{
|
||||
Main = 255,
|
||||
App = 1,
|
||||
Core = 2,
|
||||
Presentation = 3,
|
||||
ViewProps = 4,
|
||||
VmlDrawing = 5,
|
||||
TableStyles = 6,
|
||||
|
||||
Themes = 20,
|
||||
ThemeOverride = 21,
|
||||
SlideMasters = 22,
|
||||
SlideLayouts = 23,
|
||||
Slides = 24,
|
||||
NotesMasters = 25,
|
||||
NotesSlides = 26,
|
||||
|
||||
HandoutMasters = 30,
|
||||
|
||||
SlideRels = 40,
|
||||
ThemeRels = 41,
|
||||
|
||||
ImageMap = 42,
|
||||
FontMap = 43,
|
||||
|
||||
FontsEmbedded = 44
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#define COLOR_TYPE_NONE 0
|
||||
#define COLOR_TYPE_SRGB 1
|
||||
#define COLOR_TYPE_PRST 2
|
||||
#define COLOR_TYPE_SCHEME 3
|
||||
#define COLOR_TYPE_SYS 4
|
||||
|
||||
#define FILL_TYPE_NONE 0
|
||||
#define FILL_TYPE_BLIP 1
|
||||
#define FILL_TYPE_NOFILL 2
|
||||
#define FILL_TYPE_SOLID 3
|
||||
#define FILL_TYPE_GRAD 4
|
||||
#define FILL_TYPE_PATT 5
|
||||
|
||||
#define EFFECT_TYPE_NONE 0
|
||||
#define EFFECT_TYPE_OUTERSHDW 1
|
||||
#define EFFECT_TYPE_GLOW 2
|
||||
#define EFFECT_TYPE_DUOTONE 3
|
||||
#define EFFECT_TYPE_XFRM 4
|
||||
#define EFFECT_TYPE_BLUR 5
|
||||
#define EFFECT_TYPE_PRSTSHDW 6
|
||||
#define EFFECT_TYPE_INNERSHDW 7
|
||||
#define EFFECT_TYPE_REFLECTION 8
|
||||
#define EFFECT_TYPE_SOFTEDGE 9
|
||||
#define EFFECT_TYPE_FILLOVERLAY 10
|
||||
#define EFFECT_TYPE_ALPHACEILING 11
|
||||
#define EFFECT_TYPE_ALPHAFLOOR 12
|
||||
#define EFFECT_TYPE_TINTEFFECT 13
|
||||
#define EFFECT_TYPE_RELOFF 14
|
||||
#define EFFECT_TYPE_LUM 15
|
||||
#define EFFECT_TYPE_HSL 16
|
||||
#define EFFECT_TYPE_GRAYSCL 17
|
||||
#define EFFECT_TYPE_ELEMENT 18
|
||||
#define EFFECT_TYPE_ALPHAREPL 19
|
||||
#define EFFECT_TYPE_ALPHAOUTSET 20
|
||||
#define EFFECT_TYPE_ALPHAMODFIX 21
|
||||
#define EFFECT_TYPE_ALPHABILEVEL 22
|
||||
#define EFFECT_TYPE_BILEVEL 23
|
||||
#define EFFECT_TYPE_DAG 24
|
||||
#define EFFECT_TYPE_FILL 25
|
||||
#define EFFECT_TYPE_CLRREPL 26
|
||||
#define EFFECT_TYPE_CLRCHANGE 27
|
||||
#define EFFECT_TYPE_ALPHAINV 28
|
||||
#define EFFECT_TYPE_ALPHAMOD 29
|
||||
#define EFFECT_TYPE_BLEND 30
|
||||
|
||||
#define GEOMETRY_TYPE_NONE 0
|
||||
#define GEOMETRY_TYPE_PRST 1
|
||||
#define GEOMETRY_TYPE_CUSTOM 2
|
||||
|
||||
#define GEOMETRY_TYPE_AH_NONE 0
|
||||
#define GEOMETRY_TYPE_AH_POLAR 1
|
||||
#define GEOMETRY_TYPE_AH_XY 2
|
||||
|
||||
#define GEOMETRY_TYPE_PATH_NONE 0
|
||||
#define GEOMETRY_TYPE_PATH_MOVETO 1
|
||||
#define GEOMETRY_TYPE_PATH_LINETO 2
|
||||
#define GEOMETRY_TYPE_PATH_CLOZE 3
|
||||
#define GEOMETRY_TYPE_PATH_CUBICBEZTO 4
|
||||
#define GEOMETRY_TYPE_PATH_ARCTO 5
|
||||
#define GEOMETRY_TYPE_PATH_QUADBEZTO 6
|
||||
|
||||
#define EFFECTPROPERTIES_TYPE_NONE 0
|
||||
#define EFFECTPROPERTIES_TYPE_LIST 1
|
||||
#define EFFECTPROPERTIES_TYPE_DAG EFFECT_TYPE_DAG
|
||||
|
||||
#define BULLET_TYPE_COLOR_NONE 0
|
||||
#define BULLET_TYPE_COLOR_CLRTX 1
|
||||
#define BULLET_TYPE_COLOR_CLR 2
|
||||
|
||||
#define BULLET_TYPE_SIZE_NONE 0
|
||||
#define BULLET_TYPE_SIZE_TX 1
|
||||
#define BULLET_TYPE_SIZE_PCT 2
|
||||
#define BULLET_TYPE_SIZE_PTS 3
|
||||
|
||||
#define BULLET_TYPE_TYPEFACE_NONE 0
|
||||
#define BULLET_TYPE_TYPEFACE_TX 1
|
||||
#define BULLET_TYPE_TYPEFACE_BUFONT 2
|
||||
|
||||
#define BULLET_TYPE_BULLET_NONE 0
|
||||
#define BULLET_TYPE_BULLET_CHAR 1
|
||||
#define BULLET_TYPE_BULLET_AUTONUM 2
|
||||
#define BULLET_TYPE_BULLET_BLIP 3
|
||||
|
||||
#define PARRUN_TYPE_NONE 0
|
||||
#define PARRUN_TYPE_RUN 1
|
||||
#define PARRUN_TYPE_FLD 2
|
||||
#define PARRUN_TYPE_BR 3
|
||||
|
||||
#define SPTREE_TYPE_NONE 0
|
||||
#define SPTREE_TYPE_SHAPE 1
|
||||
#define SPTREE_TYPE_PIC 2
|
||||
#define SPTREE_TYPE_CXNSP 3
|
||||
#define SPTREE_TYPE_SPTREE 4
|
||||
#define SPTREE_TYPE_GRFRAME 5
|
||||
|
||||
static BYTE SchemeClr_GetBYTECode(const CString& sValue)
|
||||
{
|
||||
if (_T("accent1") == sValue)
|
||||
return 0;
|
||||
if (_T("accent2") == sValue)
|
||||
return 1;
|
||||
if (_T("accent3") == sValue)
|
||||
return 2;
|
||||
if (_T("accent4") == sValue)
|
||||
return 3;
|
||||
if (_T("accent5") == sValue)
|
||||
return 4;
|
||||
if (_T("accent6") == sValue)
|
||||
return 5;
|
||||
if (_T("bg1") == sValue)
|
||||
return 6;
|
||||
if (_T("bg2") == sValue)
|
||||
return 7;
|
||||
if (_T("dk1") == sValue)
|
||||
return 8;
|
||||
if (_T("dk2") == sValue)
|
||||
return 9;
|
||||
if (_T("folHlink") == sValue)
|
||||
return 10;
|
||||
if (_T("hlink") == sValue)
|
||||
return 11;
|
||||
if (_T("lt1") == sValue)
|
||||
return 12;
|
||||
if (_T("lt2") == sValue)
|
||||
return 13;
|
||||
if (_T("phClr") == sValue)
|
||||
return 14;
|
||||
if (_T("tx1") == sValue)
|
||||
return 15;
|
||||
if (_T("tx2") == sValue)
|
||||
return 16;
|
||||
return 0;
|
||||
}
|
||||
static CString SchemeClr_GetStringCode(const BYTE& val)
|
||||
{
|
||||
switch (val)
|
||||
{
|
||||
case 0:
|
||||
return _T("accent1");
|
||||
case 1:
|
||||
return _T("accent2");
|
||||
case 2:
|
||||
return _T("accent3");
|
||||
case 3:
|
||||
return _T("accent4");
|
||||
case 4:
|
||||
return _T("accent5");
|
||||
case 5:
|
||||
return _T("accent6");
|
||||
case 6:
|
||||
return _T("bg1");
|
||||
case 7:
|
||||
return _T("bg2");
|
||||
case 8:
|
||||
return _T("dk1");
|
||||
case 9:
|
||||
return _T("dk2");
|
||||
case 10:
|
||||
return _T("folHlink");
|
||||
case 11:
|
||||
return _T("hlink");
|
||||
case 12:
|
||||
return _T("lt1");
|
||||
case 13:
|
||||
return _T("lt2");
|
||||
case 14:
|
||||
return _T("phClr");
|
||||
case 15:
|
||||
return _T("tx1");
|
||||
case 16:
|
||||
return _T("tx2");
|
||||
}
|
||||
return _T("accent1");
|
||||
}
|
||||
|
||||
#define XMLWRITER_DOC_TYPE_PPTX 0
|
||||
#define XMLWRITER_DOC_TYPE_DOCX 1
|
||||
#define XMLWRITER_DOC_TYPE_XLSX 2
|
||||
#define XMLWRITER_DOC_TYPE_CHART 3
|
||||
|
||||
#define XMLWRITER_RECORD_TYPE_SPPR 0
|
||||
1439
ActiveX/ASCOfficePPTXFile/Editor/BinWriters.h
Normal file
1439
ActiveX/ASCOfficePPTXFile/Editor/BinWriters.h
Normal file
File diff suppressed because it is too large
Load Diff
118
ActiveX/ASCOfficePPTXFile/Editor/CalculatorCRC32.h
Normal file
118
ActiveX/ASCOfficePPTXFile/Editor/CalculatorCRC32.h
Normal file
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2014
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
* version 3 as published by the Free Software Foundation. In accordance with
|
||||
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||
* of any third-party rights.
|
||||
*
|
||||
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||
*
|
||||
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
|
||||
* EU, LV-1021.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of the Program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU AGPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||
* grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||
* well as technical writing content are licensed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
const long g_clFilePartSize = 20*1024;
|
||||
class CCalculatorCRC32
|
||||
{
|
||||
public:
|
||||
CCalculatorCRC32()
|
||||
{
|
||||
m_dwMagicWord = 0xEDB88320;
|
||||
m_dwInitCrc = 0xFFFFFFFF;
|
||||
m_bInitTable = FALSE;
|
||||
}
|
||||
public:
|
||||
DWORD Calc(BYTE const*pStream, int nSize)
|
||||
{
|
||||
InitCRCTable();
|
||||
DWORD dwRes = m_dwInitCrc;
|
||||
for (int i=0;i<nSize;i++)
|
||||
{
|
||||
dwRes = m_arCRCTable[(dwRes ^ pStream[i])& 0xFF] ^ (dwRes >> 8);
|
||||
}
|
||||
|
||||
dwRes = dwRes ^ 0xFFFFFFFF;
|
||||
return dwRes;
|
||||
}
|
||||
|
||||
DWORD Calc(const CString &sStream)
|
||||
{
|
||||
InitCRCTable();
|
||||
DWORD dwRes = m_dwInitCrc;
|
||||
int nSize = sStream.GetLength();
|
||||
for (int i=0;i<nSize;i++)
|
||||
{
|
||||
dwRes = m_arCRCTable[(dwRes ^ (BYTE)sStream[i]) & 0xFF] ^ (dwRes >> 8);
|
||||
}
|
||||
|
||||
dwRes = dwRes ^ 0xFFFFFFFF;
|
||||
return dwRes;
|
||||
}
|
||||
DWORD CalcPartFile(const CString &sFilepath)
|
||||
{
|
||||
DWORD dwRet = 0xFFFFFFFF;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return dwRet;
|
||||
}
|
||||
private:
|
||||
void InitCRCTable()
|
||||
{
|
||||
if (m_bInitTable)
|
||||
return;
|
||||
|
||||
DWORD dwTemp;
|
||||
for (int i=0;i<256;i++)
|
||||
{
|
||||
dwTemp = i;
|
||||
for (int j=0;j<8;j++)
|
||||
{
|
||||
if (0x1==(dwTemp & 0x1))
|
||||
dwTemp = (dwTemp >> 1) ^ m_dwMagicWord;
|
||||
else
|
||||
dwTemp = dwTemp >> 1;
|
||||
}
|
||||
m_arCRCTable[i] = dwTemp;
|
||||
}
|
||||
}
|
||||
|
||||
DWORD m_dwMagicWord;
|
||||
DWORD m_dwInitCrc;
|
||||
DWORD m_arCRCTable[255];
|
||||
BOOL m_bInitTable;
|
||||
};
|
||||
426
ActiveX/ASCOfficePPTXFile/Editor/Converter.h
Normal file
426
ActiveX/ASCOfficePPTXFile/Editor/Converter.h
Normal file
@@ -0,0 +1,426 @@
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2014
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
* version 3 as published by the Free Software Foundation. In accordance with
|
||||
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||
* of any third-party rights.
|
||||
*
|
||||
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||
*
|
||||
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
|
||||
* EU, LV-1021.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of the Program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU AGPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||
* grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||
* well as technical writing content are licensed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
#include "../stdafx.h"
|
||||
#include "../PPTXFormat/PPTX.h"
|
||||
|
||||
#include "BinWriters.h"
|
||||
|
||||
namespace PPTX2EditorAdvanced
|
||||
{
|
||||
using namespace NSBinPptxRW;
|
||||
|
||||
DWORD Convert(NSBinPptxRW::CBinaryFileWriter& oBinaryWriter, PPTX::Folder& oFolder, const CString& strSourceDirectory, const CString& strDstFile)
|
||||
{
|
||||
|
||||
NSBinPptxRW::CCommonWriter* pCommon = &oBinaryWriter.m_oCommon;
|
||||
|
||||
CAtlArray<smart_ptr<PPTX::Theme>> _themes;
|
||||
CAtlArray<smart_ptr<PPTX::SlideMaster>> _slideMasters;
|
||||
CAtlArray<smart_ptr<PPTX::Slide>> _slides;
|
||||
CAtlArray<smart_ptr<PPTX::SlideLayout>> _layouts;
|
||||
CAtlArray<smart_ptr<PPTX::NotesSlide>> _notes;
|
||||
CAtlArray<smart_ptr<PPTX::NotesMaster>> _notesMasters;
|
||||
|
||||
smart_ptr<PPTX::Presentation> presentation = oFolder.get(OOX::FileTypes::Presentation).smart_dynamic_cast<PPTX::Presentation>();
|
||||
int cx = presentation->sldSz->cx;
|
||||
int cy = presentation->sldSz->cy;
|
||||
|
||||
|
||||
size_t nCountMasters = presentation->sldMasterIdLst.GetCount();
|
||||
for (size_t nMaster = 0; nMaster < nCountMasters; ++nMaster)
|
||||
{
|
||||
smart_ptr<PPTX::SlideMaster> slideMaster = ((*presentation)[presentation->sldMasterIdLst[nMaster].rid.get()]).smart_dynamic_cast<PPTX::SlideMaster>();
|
||||
size_t pPointerSM = (size_t)(slideMaster.operator ->());
|
||||
|
||||
CAtlMap<size_t, LONG>::CPair* pSearchSM = pCommon->slideMasters.Lookup(pPointerSM);
|
||||
if (NULL != pSearchSM)
|
||||
{
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
oBinaryWriter.m_oCommon.m_oRels.Add();
|
||||
CMasterSlideInfo& oMasterInfo = oBinaryWriter.m_oCommon.m_oRels[oBinaryWriter.m_oCommon.m_oRels.GetCount() - 1];
|
||||
|
||||
|
||||
LONG lCountSM = (LONG)_slideMasters.GetCount();
|
||||
pCommon->slideMasters.SetAt(pPointerSM, lCountSM);
|
||||
_slideMasters.Add(slideMaster);
|
||||
|
||||
|
||||
size_t pPointerTh = (size_t)(slideMaster->Theme.operator ->());
|
||||
CAtlMap<size_t, LONG>::CPair* pSearchTh = pCommon->themes.Lookup(pPointerTh);
|
||||
if (NULL == pSearchTh)
|
||||
{
|
||||
LONG lCountTh = (LONG)_themes.GetCount();
|
||||
pCommon->themes.SetAt(pPointerTh, lCountTh);
|
||||
_themes.Add(slideMaster->Theme);
|
||||
oMasterInfo.m_lThemeIndex = lCountTh;
|
||||
}
|
||||
else
|
||||
{
|
||||
oMasterInfo.m_lThemeIndex = pSearchTh->m_value;
|
||||
}
|
||||
|
||||
size_t nCountLayouts = slideMaster->sldLayoutIdLst.GetCount();
|
||||
for (size_t iLayout = 0; iLayout < nCountLayouts; ++iLayout)
|
||||
{
|
||||
smart_ptr<PPTX::SlideLayout> slideLayout = ((*slideMaster)[slideMaster->sldLayoutIdLst[iLayout].rid.get()]).smart_dynamic_cast<PPTX::SlideLayout>();
|
||||
|
||||
|
||||
size_t pPointerL = (size_t)(slideLayout.operator ->());
|
||||
CAtlMap<size_t, LONG>::CPair* pSearchL = pCommon->layouts.Lookup(pPointerL);
|
||||
if (NULL == pSearchL)
|
||||
{
|
||||
LONG lCountL = (LONG)_layouts.GetCount();
|
||||
pCommon->layouts.SetAt(pPointerL, lCountL);
|
||||
_layouts.Add(slideLayout);
|
||||
|
||||
oMasterInfo.m_arLayoutIndexes.Add(lCountL);
|
||||
oMasterInfo.m_arLayoutImagesBase64.Add("");
|
||||
}
|
||||
else
|
||||
{
|
||||
oMasterInfo.m_arLayoutIndexes.Add(pSearchL->m_value);
|
||||
oMasterInfo.m_arLayoutImagesBase64.Add("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
size_t nCountNoteMasters = presentation->notesMasterIdLst.GetCount();
|
||||
for (size_t nNote = 0; nNote < nCountNoteMasters; ++nNote)
|
||||
{
|
||||
smart_ptr<PPTX::NotesMaster> noteMaster = ((*presentation)[presentation->notesMasterIdLst[nNote].rid.get()]).smart_dynamic_cast<PPTX::NotesMaster>();
|
||||
size_t pPointerNM = (size_t)(noteMaster.operator ->());
|
||||
|
||||
CAtlMap<size_t, LONG>::CPair* pSearchNM = pCommon->notesMasters.Lookup(pPointerNM);
|
||||
if (NULL != pSearchNM)
|
||||
{
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
LONG lCountNM = (LONG)_notesMasters.GetCount();
|
||||
pCommon->notesMasters.SetAt(pPointerNM, lCountNM);
|
||||
_notesMasters.Add(noteMaster);
|
||||
|
||||
|
||||
size_t pPointerTh = (size_t)(noteMaster->Theme.operator ->());
|
||||
CAtlMap<size_t, LONG>::CPair* pSearchTh = pCommon->themes.Lookup(pPointerTh);
|
||||
if (NULL == pSearchTh)
|
||||
{
|
||||
LONG lCountTh = (LONG)_themes.GetCount();
|
||||
pCommon->themes.SetAt(pPointerTh, lCountTh);
|
||||
_themes.Add(noteMaster->Theme);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
size_t nCount = presentation->sldIdLst.GetCount();
|
||||
for (size_t i = 0; i < nCount; ++i)
|
||||
{
|
||||
smart_ptr<PPTX::Slide> slide = ((*presentation)[presentation->sldIdLst[i].rid.get()]).smart_dynamic_cast<PPTX::Slide>();
|
||||
|
||||
size_t pPointerS = (size_t)(slide.operator ->());
|
||||
|
||||
CAtlMap<size_t, LONG>::CPair* pSearchS = pCommon->slides.Lookup(pPointerS);
|
||||
if (NULL != pSearchS)
|
||||
{
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
size_t pPointerL = (size_t)(slide->Layout.operator ->());
|
||||
CAtlMap<size_t, LONG>::CPair* pSearchL = pCommon->layouts.Lookup(pPointerL);
|
||||
if (NULL == pSearchL)
|
||||
{
|
||||
|
||||
oBinaryWriter.m_oCommon.m_oSlide_Layout_Rels.Add(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
oBinaryWriter.m_oCommon.m_oSlide_Layout_Rels.Add(pSearchL->m_value);
|
||||
}
|
||||
|
||||
LONG lCountS = (LONG)_slides.GetCount();
|
||||
pCommon->slides.SetAt(pPointerS, lCountS);
|
||||
_slides.Add(slide);
|
||||
|
||||
|
||||
size_t pPointerN = (size_t)(slide->Note.operator ->());
|
||||
|
||||
if (NULL != pPointerN)
|
||||
{
|
||||
CAtlMap<size_t, LONG>::CPair* pSearchN = pCommon->notes.Lookup(pPointerN);
|
||||
if (NULL == pSearchN)
|
||||
{
|
||||
LONG lCountN = (LONG)_notes.GetCount();
|
||||
pCommon->notes.SetAt(pPointerN, lCountN);
|
||||
_notes.Add(slide->Note);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
oBinaryWriter.WriteReserved(5 * 30);
|
||||
|
||||
|
||||
oBinaryWriter.StartMainRecord(NSMainTables::Main);
|
||||
oBinaryWriter.WriteULONG(NSSerFormat::Signature);
|
||||
oBinaryWriter.WriteULONG(0);
|
||||
|
||||
|
||||
smart_ptr<PPTX::App> app = oFolder.get(OOX::FileTypes::App).smart_dynamic_cast<PPTX::App>();
|
||||
if (app.is_init())
|
||||
{
|
||||
oBinaryWriter.StartMainRecord(NSMainTables::App);
|
||||
app->toPPTY(&oBinaryWriter);
|
||||
}
|
||||
|
||||
|
||||
smart_ptr<PPTX::Core> core = oFolder.get(OOX::FileTypes::Core).smart_dynamic_cast<PPTX::Core>();
|
||||
if (core.is_init())
|
||||
{
|
||||
oBinaryWriter.StartMainRecord(NSMainTables::Core);
|
||||
core->toPPTY(&oBinaryWriter);
|
||||
}
|
||||
|
||||
|
||||
smart_ptr<PPTX::ViewProps> viewProps = presentation->get(OOX::FileTypes::ViewProps).smart_dynamic_cast<PPTX::ViewProps>();
|
||||
if (viewProps.is_init())
|
||||
{
|
||||
oBinaryWriter.StartMainRecord(NSMainTables::ViewProps);
|
||||
viewProps->toPPTY(&oBinaryWriter);
|
||||
}
|
||||
|
||||
|
||||
smart_ptr<PPTX::TableStyles> tablestyles = presentation->get(OOX::FileTypes::TableStyles).smart_dynamic_cast<PPTX::TableStyles>();
|
||||
if (tablestyles.is_init())
|
||||
{
|
||||
oBinaryWriter.StartMainRecord(NSMainTables::TableStyles);
|
||||
tablestyles->toPPTY(&oBinaryWriter);
|
||||
}
|
||||
|
||||
|
||||
oBinaryWriter.StartMainRecord(NSMainTables::Presentation);
|
||||
presentation->toPPTY(&oBinaryWriter);
|
||||
|
||||
|
||||
oBinaryWriter.StartMainRecord(NSMainTables::Themes);
|
||||
ULONG nCountThemes = (ULONG)_themes.GetCount();
|
||||
oBinaryWriter.WriteULONG(nCountThemes);
|
||||
for (ULONG i = 0; i < nCountThemes; ++i)
|
||||
{
|
||||
_themes[i]->toPPTY(&oBinaryWriter);
|
||||
}
|
||||
|
||||
|
||||
oBinaryWriter.StartMainRecord(NSMainTables::SlideMasters);
|
||||
ULONG nCountSM = (ULONG)_slideMasters.GetCount();
|
||||
oBinaryWriter.WriteULONG(nCountSM);
|
||||
for (ULONG i = 0; i < nCountSM; ++i)
|
||||
{
|
||||
_slideMasters[i]->toPPTY(&oBinaryWriter);
|
||||
}
|
||||
|
||||
|
||||
oBinaryWriter.StartMainRecord(NSMainTables::SlideLayouts);
|
||||
ULONG nCountL = (ULONG)_layouts.GetCount();
|
||||
oBinaryWriter.WriteULONG(nCountL);
|
||||
for (ULONG i = 0; i < nCountL; ++i)
|
||||
{
|
||||
_layouts[i]->toPPTY(&oBinaryWriter);
|
||||
}
|
||||
|
||||
|
||||
oBinaryWriter.StartMainRecord(NSMainTables::Slides);
|
||||
ULONG nCountS = (ULONG)_slides.GetCount();
|
||||
oBinaryWriter.WriteULONG(nCountS);
|
||||
for (ULONG i = 0; i < nCountS; ++i)
|
||||
{
|
||||
_slides[i]->toPPTY(&oBinaryWriter);
|
||||
}
|
||||
|
||||
if (FALSE)
|
||||
{
|
||||
|
||||
|
||||
|
||||
oBinaryWriter.StartMainRecord(NSMainTables::NotesSlides);
|
||||
ULONG nCountN = (ULONG)_notes.GetCount();
|
||||
oBinaryWriter.WriteULONG(nCountN);
|
||||
for (ULONG i = 0; i < nCountN; ++i)
|
||||
{
|
||||
_notes[i]->toPPTY(&oBinaryWriter);
|
||||
}
|
||||
|
||||
|
||||
oBinaryWriter.StartMainRecord(NSMainTables::NotesMasters);
|
||||
ULONG nCountNM = (ULONG)_notesMasters.GetCount();
|
||||
oBinaryWriter.WriteULONG(nCountNM);
|
||||
for (ULONG i = 0; i < nCountNM; ++i)
|
||||
{
|
||||
_notesMasters[i]->toPPTY(&oBinaryWriter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
oBinaryWriter.StartMainRecord(NSMainTables::ImageMap);
|
||||
oBinaryWriter.StartRecord(NSMainTables::ImageMap);
|
||||
oBinaryWriter.WriteBYTE(NSBinPptxRW::g_nodeAttributeStart);
|
||||
|
||||
CAtlMap<CString, NSShapeImageGen::CImageInfo>* pIMaps = &oBinaryWriter.m_oCommon.m_oImageManager.m_mapImagesFile;
|
||||
POSITION pos1 = pIMaps->GetStartPosition();
|
||||
|
||||
LONG lIndexI = 0;
|
||||
while (NULL != pos1)
|
||||
{
|
||||
NSShapeImageGen::CImageInfo& oRec = pIMaps->GetNextValue(pos1);
|
||||
oBinaryWriter.WriteString1(lIndexI++, oRec.GetPath2());
|
||||
}
|
||||
|
||||
oBinaryWriter.WriteBYTE(NSBinPptxRW::g_nodeAttributeEnd);
|
||||
oBinaryWriter.EndRecord();
|
||||
|
||||
|
||||
|
||||
|
||||
oBinaryWriter.StartMainRecord(NSMainTables::FontMap);
|
||||
oBinaryWriter.StartRecord(NSMainTables::FontMap);
|
||||
oBinaryWriter.WriteBYTE(NSBinPptxRW::g_nodeAttributeStart);
|
||||
|
||||
CAtlMap<CString, CString>* pFMaps = &oBinaryWriter.m_oCommon.m_pNativePicker->m_mapPicks;
|
||||
POSITION pos2 = pFMaps->GetStartPosition();
|
||||
|
||||
LONG lIndexF = 0;
|
||||
while (NULL != pos2)
|
||||
{
|
||||
CString& oRec = pFMaps->GetNextValue(pos2);
|
||||
oBinaryWriter.WriteString1(lIndexF++, oRec);
|
||||
}
|
||||
|
||||
oBinaryWriter.WriteBYTE(NSBinPptxRW::g_nodeAttributeEnd);
|
||||
oBinaryWriter.EndRecord();
|
||||
|
||||
|
||||
|
||||
if (TRUE)
|
||||
{
|
||||
|
||||
oBinaryWriter.StartMainRecord(NSMainTables::SlideRels);
|
||||
oBinaryWriter.StartRecord(NSMainTables::SlideRels);
|
||||
oBinaryWriter.WriteBYTE(NSBinPptxRW::g_nodeAttributeStart);
|
||||
|
||||
size_t _s_rels = oBinaryWriter.m_oCommon.m_oSlide_Layout_Rels.GetCount();
|
||||
for (size_t i = 0; i < _s_rels; ++i)
|
||||
{
|
||||
oBinaryWriter.WriteInt1(0, oBinaryWriter.m_oCommon.m_oSlide_Layout_Rels[i]);
|
||||
}
|
||||
|
||||
oBinaryWriter.WriteBYTE(NSBinPptxRW::g_nodeAttributeEnd);
|
||||
oBinaryWriter.EndRecord();
|
||||
|
||||
|
||||
|
||||
|
||||
oBinaryWriter.StartMainRecord(NSMainTables::ThemeRels);
|
||||
oBinaryWriter.StartRecord(NSMainTables::ThemeRels);
|
||||
|
||||
CAtlArray<NSBinPptxRW::CMasterSlideInfo>* th_rels = &oBinaryWriter.m_oCommon.m_oRels;
|
||||
oBinaryWriter.WriteULONG((ULONG)th_rels->GetCount());
|
||||
|
||||
for (size_t i = 0; i < th_rels->GetCount(); i++)
|
||||
{
|
||||
NSBinPptxRW::CMasterSlideInfo& oTh = th_rels->GetAt(i);
|
||||
|
||||
oBinaryWriter.StartRecord(0);
|
||||
|
||||
oBinaryWriter.WriteBYTE(NSBinPptxRW::g_nodeAttributeStart);
|
||||
oBinaryWriter.WriteInt1(0, oTh.m_lThemeIndex);
|
||||
|
||||
|
||||
oBinaryWriter.WriteBYTE(NSBinPptxRW::g_nodeAttributeEnd);
|
||||
|
||||
ULONG lay_count = (ULONG)oTh.m_arLayoutIndexes.GetCount();
|
||||
oBinaryWriter.WriteULONG(lay_count);
|
||||
|
||||
for (ULONG j = 0; j < lay_count; ++j)
|
||||
{
|
||||
oBinaryWriter.StartRecord(0);
|
||||
|
||||
oBinaryWriter.WriteBYTE(NSBinPptxRW::g_nodeAttributeStart);
|
||||
oBinaryWriter.WriteInt1(0, oTh.m_arLayoutIndexes[j]);
|
||||
|
||||
|
||||
oBinaryWriter.WriteBYTE(NSBinPptxRW::g_nodeAttributeEnd);
|
||||
|
||||
oBinaryWriter.EndRecord();
|
||||
}
|
||||
|
||||
oBinaryWriter.EndRecord();
|
||||
}
|
||||
|
||||
oBinaryWriter.EndRecord();
|
||||
}
|
||||
|
||||
|
||||
|
||||
oBinaryWriter.WriteEmbeddedFonts();
|
||||
oBinaryWriter.WriteMainPart();
|
||||
|
||||
|
||||
BYTE* pbBinBuffer = oBinaryWriter.GetBuffer();
|
||||
int nBinBufferLen = (int)oBinaryWriter.GetPosition();
|
||||
int nBase64BufferLen = Base64::Base64EncodeGetRequiredLength(nBinBufferLen, Base64::B64_BASE64_FLAG_NOCRLF);
|
||||
BYTE* pbBase64Buffer = new BYTE[nBase64BufferLen];
|
||||
if (TRUE == Base64::Base64Encode(pbBinBuffer, nBinBufferLen, (LPSTR)pbBase64Buffer, &nBase64BufferLen, Base64::B64_BASE64_FLAG_NOCRLF))
|
||||
{
|
||||
CFile oFile;
|
||||
oFile.CreateFileW(strDstFile);
|
||||
|
||||
CString strPrefix = _T("");
|
||||
strPrefix.Format(_T("PPTY;v1;%d;"), nBinBufferLen);
|
||||
CStringA sW = (CStringA)strPrefix;
|
||||
oFile.WriteFile(sW.GetBuffer(), (DWORD)sW.GetLength());
|
||||
oFile.WriteFile(pbBase64Buffer, nBase64BufferLen);
|
||||
oFile.CloseFile();
|
||||
}
|
||||
|
||||
RELEASEARRAYOBJECTS(pbBase64Buffer);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
438
ActiveX/ASCOfficePPTXFile/Editor/FontCutter.h
Normal file
438
ActiveX/ASCOfficePPTXFile/Editor/FontCutter.h
Normal file
@@ -0,0 +1,438 @@
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2014
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
* version 3 as published by the Free Software Foundation. In accordance with
|
||||
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||
* of any third-party rights.
|
||||
*
|
||||
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||
*
|
||||
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
|
||||
* EU, LV-1021.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of the Program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU AGPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||
* grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||
* well as technical writing content are licensed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
#include "../../Common/DocxFormat/Source/SystemUtility/File.h"
|
||||
#include "BinReaderWriterDefines.h"
|
||||
|
||||
namespace NSFontCutter
|
||||
{
|
||||
class CEmbeddedFontsManager
|
||||
{
|
||||
private:
|
||||
class CEmbeddedFontInfo
|
||||
{
|
||||
public:
|
||||
CString Name;
|
||||
|
||||
CString PathRegular;
|
||||
LONG FaceRegular;
|
||||
|
||||
CString PathBold;
|
||||
LONG FaceBold;
|
||||
|
||||
CString PathItalic;
|
||||
LONG FaceItalic;
|
||||
|
||||
CString PathBoldItalic;
|
||||
LONG FaceBoldItalic;
|
||||
|
||||
public:
|
||||
CEmbeddedFontInfo()
|
||||
{
|
||||
Name = _T("");
|
||||
|
||||
PathRegular = _T("");
|
||||
FaceRegular = -1;
|
||||
|
||||
PathBold = _T("");
|
||||
FaceBold = -1;
|
||||
|
||||
PathItalic = _T("");
|
||||
FaceItalic = -1;
|
||||
|
||||
PathBoldItalic = _T("");
|
||||
FaceBoldItalic = -1;
|
||||
}
|
||||
|
||||
CEmbeddedFontInfo(const CEmbeddedFontInfo& oSrc)
|
||||
{
|
||||
*this = oSrc;
|
||||
}
|
||||
|
||||
CEmbeddedFontInfo& operator=(const CEmbeddedFontInfo& oSrc)
|
||||
{
|
||||
Name = oSrc.Name;
|
||||
|
||||
PathRegular = oSrc.PathRegular;
|
||||
FaceRegular = oSrc.FaceRegular;
|
||||
|
||||
PathBold = oSrc.PathBold;
|
||||
FaceBold = oSrc.FaceBold;
|
||||
|
||||
PathItalic = oSrc.PathItalic;
|
||||
FaceItalic = oSrc.FaceItalic;
|
||||
|
||||
PathBoldItalic = oSrc.PathBoldItalic;
|
||||
FaceBoldItalic = oSrc.FaceBoldItalic;
|
||||
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
CAtlMap<CString, CEmbeddedFontInfo> m_mapFontsEmbeddded;
|
||||
CAtlMap<WCHAR, BOOL> m_CharMap;
|
||||
|
||||
public:
|
||||
CString m_strEmbeddedFontsFolder;
|
||||
|
||||
public:
|
||||
CEmbeddedFontsManager()
|
||||
{
|
||||
m_strEmbeddedFontsFolder = _T("");
|
||||
}
|
||||
|
||||
void CheckFont(const CString& strName, ASCGraphics::IASCFontManager* pManager)
|
||||
{
|
||||
CAtlMap<CString, CEmbeddedFontInfo>::CPair* pPair = m_mapFontsEmbeddded.Lookup(strName);
|
||||
if (NULL != pPair)
|
||||
return;
|
||||
|
||||
CEmbeddedFontInfo oInfo;
|
||||
oInfo.Name = strName;
|
||||
|
||||
VARIANT var;
|
||||
var.vt = VT_BSTR;
|
||||
var.bstrVal = strName.AllocSysString();
|
||||
|
||||
pManager->GetAdditionalParam(L"GetAllStylesByFontName", &var);
|
||||
CString strXml = (CString)var.bstrVal;
|
||||
|
||||
XmlUtils::CXmlNode oNode;
|
||||
if (oNode.FromXmlString(strXml))
|
||||
{
|
||||
XmlUtils::CXmlNodes oNodes;
|
||||
if (oNode.GetNodes(_T("font"), oNodes))
|
||||
{
|
||||
int nCount = oNodes.GetCount();
|
||||
for (int i = 0; i < nCount; ++i)
|
||||
{
|
||||
XmlUtils::CXmlNode oNodeF;
|
||||
oNodes.GetAt(i, oNodeF);
|
||||
|
||||
LONG lStyle = oNodeF.ReadAttributeInt(_T("style"));
|
||||
switch (lStyle)
|
||||
{
|
||||
case 0:
|
||||
oInfo.PathRegular = oNodeF.GetAttribute(_T("path"));
|
||||
oInfo.FaceRegular = oNodeF.ReadAttributeInt(_T("faceindex"));
|
||||
break;
|
||||
case 1:
|
||||
oInfo.PathBold = oNodeF.GetAttribute(_T("path"));
|
||||
oInfo.FaceBold = oNodeF.ReadAttributeInt(_T("faceindex"));
|
||||
break;
|
||||
case 2:
|
||||
oInfo.PathItalic = oNodeF.GetAttribute(_T("path"));
|
||||
oInfo.FaceItalic = oNodeF.ReadAttributeInt(_T("faceindex"));
|
||||
break;
|
||||
case 3:
|
||||
oInfo.PathBoldItalic = oNodeF.GetAttribute(_T("path"));
|
||||
oInfo.FaceBoldItalic = oNodeF.ReadAttributeInt(_T("faceindex"));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_mapFontsEmbeddded.SetAt(strName, oInfo);
|
||||
}
|
||||
|
||||
void CheckString(const nullable_string& val)
|
||||
{
|
||||
if (val.is_init())
|
||||
CheckString(*val);
|
||||
}
|
||||
void CheckString(const CString& val)
|
||||
{
|
||||
int len = val.GetLength();
|
||||
LPWSTR pCBuf1 = new WCHAR[len + 1];
|
||||
LPWSTR pCBuf2 = new WCHAR[len + 1];
|
||||
|
||||
LPCWSTR pSrc = (LPCWSTR)val;
|
||||
memcpy(pCBuf1, pSrc, len * sizeof(WCHAR));
|
||||
memcpy(pCBuf2, pSrc, len * sizeof(WCHAR));
|
||||
|
||||
pCBuf1[len] = 0;
|
||||
pCBuf2[len] = 0;
|
||||
|
||||
LPWSTR ch1 = CharLower(pCBuf1);
|
||||
LPWSTR ch2 = CharUpper(pCBuf2);
|
||||
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
m_CharMap.SetAt(ch1[i], TRUE);
|
||||
m_CharMap.SetAt(ch2[i], TRUE);
|
||||
}
|
||||
|
||||
RELEASEARRAYOBJECTS(pCBuf1);
|
||||
RELEASEARRAYOBJECTS(pCBuf2);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void WriteEmbeddedFonts(T* pWriter)
|
||||
{
|
||||
#ifdef BUILD_CONFIG_FULL_VERSION
|
||||
ULONG nCount = 0;
|
||||
POSITION pos = m_mapFontsEmbeddded.GetStartPosition();
|
||||
while (pos != NULL)
|
||||
{
|
||||
CEmbeddedFontInfo& oInfo = m_mapFontsEmbeddded.GetNextValue(pos);
|
||||
|
||||
if (_T("") != oInfo.PathRegular)
|
||||
++nCount;
|
||||
|
||||
if (_T("") != oInfo.PathBold)
|
||||
++nCount;
|
||||
|
||||
if (_T("") != oInfo.PathItalic)
|
||||
++nCount;
|
||||
|
||||
if (_T("") != oInfo.PathBoldItalic)
|
||||
++nCount;
|
||||
}
|
||||
|
||||
pWriter->WriteULONG(nCount);
|
||||
|
||||
CString strFileWrite = m_strEmbeddedFontsFolder + _T("\\fonts.js");
|
||||
CFile oFile;
|
||||
oFile.CreateFile(strFileWrite);
|
||||
|
||||
CStringA strWrite = "var embedded_fonts = [\n";
|
||||
oFile.WriteFile(strWrite.GetBuffer(), strWrite.GetLength());
|
||||
|
||||
strWrite = ",\n";
|
||||
bool bIsFirst = true;
|
||||
ULONG lIndexF = 0;
|
||||
|
||||
SAFEARRAY* pArrayUnicodes = GenerateSafearray();
|
||||
Fonts::IFontConverter* pFontConverter = NULL;
|
||||
CoCreateInstance(__uuidof(Fonts::CFontConverter), NULL, CLSCTX_ALL, __uuidof(Fonts::IFontConverter), (void**)&pFontConverter);
|
||||
|
||||
pos = m_mapFontsEmbeddded.GetStartPosition();
|
||||
while (pos != NULL)
|
||||
{
|
||||
CEmbeddedFontInfo& oInfo = m_mapFontsEmbeddded.GetNextValue(pos);
|
||||
|
||||
if (_T("") != oInfo.PathRegular)
|
||||
{
|
||||
if (!bIsFirst)
|
||||
oFile.WriteFile(strWrite.GetBuffer(), strWrite.GetLength());
|
||||
|
||||
bIsFirst = false;
|
||||
WriteFont(oInfo.Name, oInfo.FaceRegular, oInfo.PathRegular, &oFile, pArrayUnicodes, pFontConverter);
|
||||
|
||||
pWriter->WriteBYTE(NSBinPptxRW::g_nodeAttributeStart);
|
||||
|
||||
pWriter->WriteBYTE(0);
|
||||
pWriter->WriteString(oInfo.Name);
|
||||
|
||||
pWriter->WriteBYTE(1);
|
||||
pWriter->WriteULONG(0);
|
||||
|
||||
pWriter->WriteBYTE(2);
|
||||
pWriter->WriteBYTE(1);
|
||||
|
||||
pWriter->WriteBYTE(3);
|
||||
pWriter->WriteULONG(lIndexF);
|
||||
|
||||
pWriter->WriteBYTE(NSBinPptxRW::g_nodeAttributeEnd);
|
||||
|
||||
lIndexF++;
|
||||
}
|
||||
|
||||
if (_T("") != oInfo.PathBold)
|
||||
{
|
||||
if (!bIsFirst)
|
||||
oFile.WriteFile(strWrite.GetBuffer(), strWrite.GetLength());
|
||||
|
||||
bIsFirst = false;
|
||||
WriteFont(oInfo.Name, oInfo.FaceBold, oInfo.PathBold, &oFile, pArrayUnicodes, pFontConverter);
|
||||
|
||||
pWriter->WriteBYTE(NSBinPptxRW::g_nodeAttributeStart);
|
||||
|
||||
pWriter->WriteBYTE(0);
|
||||
pWriter->WriteString(oInfo.Name);
|
||||
|
||||
pWriter->WriteBYTE(1);
|
||||
pWriter->WriteULONG(1);
|
||||
|
||||
pWriter->WriteBYTE(2);
|
||||
pWriter->WriteBYTE(1);
|
||||
|
||||
pWriter->WriteBYTE(3);
|
||||
pWriter->WriteULONG(lIndexF);
|
||||
|
||||
pWriter->WriteBYTE(NSBinPptxRW::g_nodeAttributeEnd);
|
||||
|
||||
lIndexF++;
|
||||
}
|
||||
|
||||
if (_T("") != oInfo.PathItalic)
|
||||
{
|
||||
if (!bIsFirst)
|
||||
oFile.WriteFile(strWrite.GetBuffer(), strWrite.GetLength());
|
||||
|
||||
bIsFirst = false;
|
||||
WriteFont(oInfo.Name, oInfo.FaceItalic, oInfo.PathItalic, &oFile, pArrayUnicodes, pFontConverter);
|
||||
|
||||
pWriter->WriteBYTE(NSBinPptxRW::g_nodeAttributeStart);
|
||||
|
||||
pWriter->WriteBYTE(0);
|
||||
pWriter->WriteString(oInfo.Name);
|
||||
|
||||
pWriter->WriteBYTE(1);
|
||||
pWriter->WriteULONG(2);
|
||||
|
||||
pWriter->WriteBYTE(2);
|
||||
pWriter->WriteBYTE(1);
|
||||
|
||||
pWriter->WriteBYTE(3);
|
||||
pWriter->WriteULONG(lIndexF);
|
||||
|
||||
pWriter->WriteBYTE(NSBinPptxRW::g_nodeAttributeEnd);
|
||||
|
||||
lIndexF++;
|
||||
}
|
||||
|
||||
if (_T("") != oInfo.PathBoldItalic)
|
||||
{
|
||||
if (!bIsFirst)
|
||||
oFile.WriteFile(strWrite.GetBuffer(), strWrite.GetLength());
|
||||
|
||||
bIsFirst = false;
|
||||
WriteFont(oInfo.Name, oInfo.FaceBoldItalic, oInfo.PathBoldItalic, &oFile, pArrayUnicodes, pFontConverter);
|
||||
|
||||
pWriter->WriteBYTE(NSBinPptxRW::g_nodeAttributeStart);
|
||||
|
||||
pWriter->WriteBYTE(0);
|
||||
pWriter->WriteString(oInfo.Name);
|
||||
|
||||
pWriter->WriteBYTE(1);
|
||||
pWriter->WriteULONG(3);
|
||||
|
||||
pWriter->WriteBYTE(2);
|
||||
pWriter->WriteBYTE(1);
|
||||
|
||||
pWriter->WriteBYTE(3);
|
||||
pWriter->WriteULONG(lIndexF);
|
||||
|
||||
pWriter->WriteBYTE(NSBinPptxRW::g_nodeAttributeEnd);
|
||||
|
||||
lIndexF++;
|
||||
}
|
||||
}
|
||||
|
||||
strWrite = "\n];";
|
||||
oFile.WriteFile(strWrite.GetBuffer(), strWrite.GetLength());
|
||||
|
||||
oFile.CloseFile();
|
||||
|
||||
RELEASEARRAY(pArrayUnicodes);
|
||||
RELEASEINTERFACE(pFontConverter);
|
||||
#endif
|
||||
}
|
||||
|
||||
SAFEARRAY* GenerateSafearray()
|
||||
{
|
||||
|
||||
CheckString(_T("0123456789"));
|
||||
m_CharMap.SetAt((WCHAR)0x00B0, TRUE);
|
||||
m_CharMap.SetAt((WCHAR)0x00B7, TRUE);
|
||||
m_CharMap.SetAt((WCHAR)0x00B6, TRUE);
|
||||
m_CharMap.SetAt((WCHAR)0x00A4, TRUE);
|
||||
m_CharMap.SetAt((WCHAR)0x00A0, TRUE);
|
||||
m_CharMap.SetAt((WCHAR)0x0022, TRUE);
|
||||
m_CharMap.SetAt((WCHAR)0x0032, TRUE);
|
||||
m_CharMap.SetAt((WCHAR)0x0038, TRUE);
|
||||
m_CharMap.SetAt((WCHAR)0x0097, TRUE);
|
||||
|
||||
ULONG nCount = (ULONG)m_CharMap.GetCount();
|
||||
|
||||
SAFEARRAYBOUND rgsab;
|
||||
rgsab.lLbound = 0;
|
||||
rgsab.cElements = nCount;
|
||||
|
||||
SAFEARRAY* pArray = SafeArrayCreate(VT_UI2, 1, &rgsab);
|
||||
USHORT* pBuffer = (USHORT*)(pArray->pvData);
|
||||
|
||||
POSITION pos = m_CharMap.GetStartPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
CAtlMap<WCHAR, BOOL>::CPair* pPair = m_CharMap.GetNext(pos);
|
||||
*pBuffer = pPair->m_key;
|
||||
++pBuffer;
|
||||
}
|
||||
return pArray;
|
||||
}
|
||||
|
||||
#ifdef BUILD_CONFIG_FULL_VERSION
|
||||
void WriteFont(CString& strName, LONG& lFaceIndex, CString& strFontPath, CFile* pFile, SAFEARRAY* pArrayUnicodes, Fonts::IFontConverter* pFontConverter)
|
||||
{
|
||||
LONG lFontConverterFlag = 16;
|
||||
|
||||
BSTR bsFontIn = strFontPath.AllocSysString();
|
||||
|
||||
CString _strName = strName + _T("_Embedded");
|
||||
BSTR bsName = _strName.AllocSysString();
|
||||
|
||||
SAFEARRAY* pArrayData = NULL;
|
||||
|
||||
pFontConverter->ToOTF2(bsFontIn, pArrayUnicodes, bsName, lFontConverterFlag, lFaceIndex, &pArrayData);
|
||||
|
||||
SysFreeString(bsFontIn);
|
||||
SysFreeString(bsName);
|
||||
|
||||
BYTE* pbBinBuffer = (BYTE*)pArrayData->pvData;
|
||||
int nBinBufferLen = pArrayData->rgsabound[0].cElements;
|
||||
int nBase64BufferLen = Base64::Base64EncodeGetRequiredLength(nBinBufferLen, Base64::B64_BASE64_FLAG_NOCRLF);
|
||||
BYTE* pbBase64Buffer = new BYTE[nBase64BufferLen];
|
||||
if (TRUE == Base64::Base64Encode(pbBinBuffer, nBinBufferLen, (LPSTR)pbBase64Buffer, &nBase64BufferLen, Base64::B64_BASE64_FLAG_NOCRLF))
|
||||
{
|
||||
CStringA s = "\"";
|
||||
pFile->WriteFile(s.GetBuffer(), s.GetLength());
|
||||
|
||||
pFile->WriteFile(pbBase64Buffer, nBase64BufferLen);
|
||||
|
||||
pFile->WriteFile(s.GetBuffer(), s.GetLength());
|
||||
}
|
||||
|
||||
RELEASEARRAYOBJECTS(pbBase64Buffer);
|
||||
|
||||
RELEASEARRAY(pArrayData);
|
||||
}
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
#define FONT_PICKER_BINARYDATA_SAVEEMBEDDED 0
|
||||
#define FONT_PICKER_BINARYDATA_SAVEMAP 1
|
||||
58
ActiveX/ASCOfficePPTXFile/Editor/FontPicker.cpp
Normal file
58
ActiveX/ASCOfficePPTXFile/Editor/FontPicker.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2014
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
* version 3 as published by the Free Software Foundation. In accordance with
|
||||
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||
* of any third-party rights.
|
||||
*
|
||||
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||
*
|
||||
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
|
||||
* EU, LV-1021.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of the Program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU AGPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||
* grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||
* well as technical writing content are licensed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
*
|
||||
*/
|
||||
#include "stdafx.h"
|
||||
#include "BinWriters.h"
|
||||
|
||||
HRESULT COfficeFontPicker::GetBinaryData(LONG lType, SAFEARRAY** ppBinaryArray)
|
||||
{
|
||||
if (NULL == ppBinaryArray)
|
||||
return S_FALSE;
|
||||
|
||||
*ppBinaryArray = NULL;
|
||||
if (FONT_PICKER_BINARYDATA_SAVEEMBEDDED == lType)
|
||||
{
|
||||
NSBinPptxRW::CBinaryFileWriter oWriter;
|
||||
m_oPicker.m_oEmbeddedFonts.CheckString(_T(".)abcdefghijklmnopqrstuvwxyz"));
|
||||
m_oPicker.m_oEmbeddedFonts.CheckFont(_T("Wingdings 3"), m_oPicker.m_pFontManager);
|
||||
m_oPicker.m_oEmbeddedFonts.CheckFont(_T("Arial"), m_oPicker.m_pFontManager);
|
||||
|
||||
oWriter.StartRecord(NSBinPptxRW::NSMainTables::FontsEmbedded);
|
||||
m_oPicker.m_oEmbeddedFonts.WriteEmbeddedFonts(&oWriter);
|
||||
oWriter.EndRecord();
|
||||
|
||||
*ppBinaryArray = oWriter.GetSafearray();
|
||||
}
|
||||
else if (FONT_PICKER_BINARYDATA_SAVEMAP == lType)
|
||||
{
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
310
ActiveX/ASCOfficePPTXFile/Editor/FontPicker.h
Normal file
310
ActiveX/ASCOfficePPTXFile/Editor/FontPicker.h
Normal file
@@ -0,0 +1,310 @@
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2014
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
* version 3 as published by the Free Software Foundation. In accordance with
|
||||
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||
* of any third-party rights.
|
||||
*
|
||||
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||
*
|
||||
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
|
||||
* EU, LV-1021.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of the Program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU AGPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||
* grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||
* well as technical writing content are licensed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
#include "../stdafx.h"
|
||||
#include "../../Common/DocxFormat/Source/SystemUtility/File.h"
|
||||
#include "BinReaderWriterDefines.h"
|
||||
#include "FontCutter.h"
|
||||
|
||||
namespace NSFontCutter
|
||||
{
|
||||
class CFontDstManager
|
||||
{
|
||||
public:
|
||||
CAtlMap<CString, CString> m_mapPicks;
|
||||
ASCGraphics::IASCFontManager* m_pFontManager;
|
||||
|
||||
CString m_strFontsDir;
|
||||
|
||||
BOOL m_bIsEmbeddedFonts;
|
||||
CEmbeddedFontsManager m_oEmbeddedFonts;
|
||||
|
||||
public:
|
||||
CFontDstManager() : m_mapPicks()
|
||||
{
|
||||
m_strFontsDir = _T("");
|
||||
|
||||
m_pFontManager = NULL;
|
||||
CoCreateInstance(ASCGraphics::CLSID_CASCFontManager, NULL, CLSCTX_ALL, ASCGraphics::IID_IASCFontManager, (void**)&m_pFontManager);
|
||||
|
||||
m_bIsEmbeddedFonts = FALSE;
|
||||
}
|
||||
~CFontDstManager()
|
||||
{
|
||||
RELEASEINTERFACE(m_pFontManager);
|
||||
}
|
||||
|
||||
void Init(const CString& strDir)
|
||||
{
|
||||
m_strFontsDir = strDir;
|
||||
|
||||
if (_T("") != m_strFontsDir)
|
||||
{
|
||||
VARIANT var;
|
||||
var.vt = VT_BSTR;
|
||||
var.bstrVal = m_strFontsDir.AllocSysString();
|
||||
m_pFontManager->SetAdditionalParam(L"InitializeFromFolder", var);
|
||||
RELEASESYSSTRING(var.bstrVal);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef BUILD_CONFIG_OPENSOURCE_VERSION
|
||||
m_pFontManager->Init(L"", VARIANT_TRUE, VARIANT_FALSE);
|
||||
#else
|
||||
m_pFontManager->Initialize(L"");
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef BUILD_CONFIG_FULL_VERSION
|
||||
CString defaultFontName = _T("Arial");
|
||||
BSTR defFontName = defaultFontName.AllocSysString();
|
||||
m_pFontManager->SetDefaultFont(defFontName);
|
||||
SysFreeString(defFontName);
|
||||
#endif
|
||||
}
|
||||
|
||||
CString GetTypefacePickByName(const CString& strTypeface)
|
||||
{
|
||||
CString sFind = strTypeface;
|
||||
|
||||
int nFindTh = sFind.Find(_T("+mj"));
|
||||
if (0 == nFindTh)
|
||||
return sFind;
|
||||
nFindTh = sFind.Find(_T("+mn"));
|
||||
if (0 == nFindTh)
|
||||
return sFind;
|
||||
|
||||
if (_T("") == sFind)
|
||||
{
|
||||
sFind = _T("Arial");
|
||||
}
|
||||
|
||||
CAtlMap<CString, CString>::CPair* pPair = m_mapPicks.Lookup(sFind);
|
||||
if (NULL != pPair)
|
||||
return pPair->m_value;
|
||||
|
||||
CString sInputSave = sFind;
|
||||
|
||||
sFind.Replace(_T("'"), _T("'"));
|
||||
sFind.Replace(_T("<"), _T("<"));
|
||||
sFind.Replace(_T(">"), _T(">"));
|
||||
sFind.Replace(_T("\""), _T("""));
|
||||
sFind.Replace(_T("&"), _T("&"));
|
||||
|
||||
CString strPick = _T("<FontProperties><Name value=\"") + sFind + _T("\"/></FontProperties>");
|
||||
|
||||
BSTR bsResult = NULL;
|
||||
LONG lFontIndex = 0;
|
||||
BSTR bsInput = strPick.AllocSysString();
|
||||
|
||||
#ifdef BUILD_CONFIG_OPENSOURCE_VERSION
|
||||
m_pFontManager->GetWinFontByParams(bsInput, &bsResult, NULL, NULL, &lFontIndex);
|
||||
#else
|
||||
m_pFontManager->GetWinFontByParams(bsInput, &bsResult, &lFontIndex);
|
||||
CString strPath = (CString)bsResult;
|
||||
|
||||
m_pFontManager->LoadFontFromFile(bsResult, 12, 72, 72, lFontIndex);
|
||||
|
||||
SysFreeString(bsInput);
|
||||
SysFreeString(bsResult);
|
||||
|
||||
m_pFontManager->GetFamilyName(&bsResult);
|
||||
#endif
|
||||
|
||||
CString sRes = bsResult;
|
||||
|
||||
SysFreeString(bsResult);
|
||||
|
||||
if (m_bIsEmbeddedFonts)
|
||||
m_oEmbeddedFonts.CheckFont(sRes, m_pFontManager);
|
||||
|
||||
m_mapPicks.SetAt(sInputSave, sRes);
|
||||
return sRes;
|
||||
}
|
||||
|
||||
template<typename TTextFont>
|
||||
CString GetTypefacePick(TTextFont& textFont)
|
||||
{
|
||||
return GetTypefacePickByName(textFont.typeface);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
[object, uuid("5061C3D5-E67E-4bd8-8E32-BE2CFC2D112D"), dual, pointer_default(unique)]
|
||||
__interface IOfficeFontPicker : IDispatch
|
||||
{
|
||||
[id(1)] HRESULT Init([in] BSTR bsFontsDirectory);
|
||||
|
||||
[propget, id(2)] HRESULT FontManager([out, retval] IUnknown** pVal);
|
||||
[propput, id(2)] HRESULT FontManager([in] IUnknown* newVal);
|
||||
|
||||
[id(10)] HRESULT SetEmbeddedFontsDirectory([in] BSTR bsFontsDirectory);
|
||||
[id(11)] HRESULT SetEmbeddedFontsParam([in] LONG lParam);
|
||||
|
||||
[id(20)] HRESULT CheckString([in] BSTR bsText);
|
||||
[id(21)] HRESULT CheckFont([in] BSTR bsFontName);
|
||||
|
||||
[id(22)] HRESULT PickFont([in] LONG lParamType, [in] BSTR bsParams, [out, retval] BSTR* pDstName);
|
||||
|
||||
[id(30)] HRESULT GetBinaryData([in] LONG lType, [out, satype("BYTE")] SAFEARRAY** ppBinaryArray);
|
||||
|
||||
[id(50)] HRESULT SetAdditionalParam([in] BSTR ParamName, [in] VARIANT ParamValue);
|
||||
[id(51)] HRESULT GetAdditionalParam([in] BSTR ParamName, [out, retval] VARIANT* ParamValue);
|
||||
};
|
||||
|
||||
|
||||
[coclass, uuid("C489E74B-FCAF-450f-A1CB-881CACB65501"), threading(apartment), vi_progid("Office.OfficeFontPicker"), progid("Office.Picker.1"), version(1.0), registration_script("control.rgs")]
|
||||
class ATL_NO_VTABLE COfficeFontPicker
|
||||
: public IOfficeFontPicker
|
||||
{
|
||||
private:
|
||||
NSFontCutter::CFontDstManager m_oPicker;
|
||||
|
||||
public:
|
||||
COfficeFontPicker()
|
||||
{
|
||||
}
|
||||
|
||||
~COfficeFontPicker()
|
||||
{
|
||||
}
|
||||
|
||||
DECLARE_PROTECT_FINAL_CONSTRUCT()
|
||||
|
||||
HRESULT FinalConstruct()
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void FinalRelease()
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
STDMETHOD(Init)(BSTR bsFontsDirectory)
|
||||
{
|
||||
m_oPicker.Init((CString)bsFontsDirectory);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHOD(get_FontManager)(IUnknown** pVal)
|
||||
{
|
||||
if (NULL == pVal)
|
||||
return S_FALSE;
|
||||
|
||||
*pVal = NULL;
|
||||
if (NULL == m_oPicker.m_pFontManager)
|
||||
return S_OK;
|
||||
|
||||
m_oPicker.m_pFontManager->QueryInterface(IID_IUnknown, (void**)pVal);
|
||||
return S_OK;
|
||||
}
|
||||
STDMETHOD(put_FontManager)(IUnknown* newVal)
|
||||
{
|
||||
if (NULL == newVal)
|
||||
return S_OK;
|
||||
|
||||
RELEASEINTERFACE((m_oPicker.m_pFontManager));
|
||||
newVal->QueryInterface(ASCGraphics::IID_IASCFontManager, (void**)&(m_oPicker.m_pFontManager));
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHOD(SetEmbeddedFontsDirectory)(BSTR bsFontsDirectory)
|
||||
{
|
||||
m_oPicker.m_oEmbeddedFonts.m_strEmbeddedFontsFolder = (CString)bsFontsDirectory;
|
||||
return S_OK;
|
||||
}
|
||||
STDMETHOD(SetEmbeddedFontsParam)(LONG lParam)
|
||||
{
|
||||
switch (lParam)
|
||||
{
|
||||
case 0:
|
||||
m_oPicker.m_bIsEmbeddedFonts = FALSE;
|
||||
break;
|
||||
case 1:
|
||||
m_oPicker.m_bIsEmbeddedFonts = TRUE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHOD(CheckString)(BSTR bsText)
|
||||
{
|
||||
m_oPicker.m_oEmbeddedFonts.CheckString((CString)bsText);
|
||||
return S_OK;
|
||||
}
|
||||
STDMETHOD(CheckFont)(BSTR bsFontName)
|
||||
{
|
||||
m_oPicker.m_oEmbeddedFonts.CheckFont((CString)bsFontName, m_oPicker.m_pFontManager);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHOD(PickFont)(LONG lParamType, BSTR bsParams, BSTR* pDstName)
|
||||
{
|
||||
if (NULL == pDstName)
|
||||
return S_FALSE;
|
||||
|
||||
if (0 == lParamType)
|
||||
{
|
||||
CString strResult = m_oPicker.GetTypefacePickByName((CString)bsParams);
|
||||
*pDstName = strResult.AllocSysString();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHOD(GetBinaryData)(LONG lType, SAFEARRAY** ppBinaryArray);
|
||||
STDMETHOD(SetAdditionalParam)(BSTR ParamName, VARIANT ParamValue)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
STDMETHOD(GetAdditionalParam)(BSTR ParamName, VARIANT* ParamValue)
|
||||
{
|
||||
CString name = (CString)ParamName;
|
||||
if (name == _T("NativePicker"))
|
||||
{
|
||||
ParamValue->vt = VT_PTR;
|
||||
ParamValue->pvRecord = &m_oPicker;
|
||||
}
|
||||
else if (name == _T("NativeCutter"))
|
||||
{
|
||||
ParamValue->vt = VT_PTR;
|
||||
ParamValue->pvRecord = &m_oPicker.m_oEmbeddedFonts;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
};
|
||||
1032
ActiveX/ASCOfficePPTXFile/Editor/PPTXWriter.h
Normal file
1032
ActiveX/ASCOfficePPTXFile/Editor/PPTXWriter.h
Normal file
File diff suppressed because it is too large
Load Diff
183
ActiveX/ASCOfficePPTXFile/Editor/ResourceFiles/notesMaster.xml
Normal file
183
ActiveX/ASCOfficePPTXFile/Editor/ResourceFiles/notesMaster.xml
Normal file
@@ -0,0 +1,183 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<p:notesMaster xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main">
|
||||
<p:cSld>
|
||||
<p:bg>
|
||||
<p:bgPr>
|
||||
<a:solidFill>
|
||||
<a:schemeClr val="bg1"/>
|
||||
</a:solidFill>
|
||||
<a:effectLst/>
|
||||
</p:bgPr>
|
||||
</p:bg>
|
||||
<p:spTree>
|
||||
<p:nvGrpSpPr>
|
||||
<p:cNvPr id="1" name=""/>
|
||||
<p:cNvGrpSpPr/>
|
||||
<p:nvPr/>
|
||||
</p:nvGrpSpPr>
|
||||
<p:grpSpPr>
|
||||
<a:xfrm>
|
||||
<a:off x="0" y="0"/>
|
||||
<a:ext cx="0" cy="0"/>
|
||||
<a:chOff x="0" y="0"/>
|
||||
<a:chExt cx="0" cy="0"/>
|
||||
</a:xfrm>
|
||||
</p:grpSpPr>
|
||||
<p:sp>
|
||||
<p:nvSpPr>
|
||||
<p:cNvPr id="11271" name="Rectangle 7"/>
|
||||
<p:cNvSpPr>
|
||||
<a:spLocks noGrp="1" noChangeArrowheads="1"/>
|
||||
</p:cNvSpPr>
|
||||
<p:nvPr>
|
||||
<p:ph type="body" idx="1"/>
|
||||
</p:nvPr>
|
||||
</p:nvSpPr>
|
||||
<p:spPr bwMode="auto">
|
||||
<a:xfrm>
|
||||
<a:off x="3884613" y="8685213"/>
|
||||
<a:ext cx="2971800" cy="457200"/>
|
||||
</a:xfrm>
|
||||
<a:prstGeom prst="rect">
|
||||
<a:avLst/>
|
||||
</a:prstGeom>
|
||||
<a:extLst/>
|
||||
</p:spPr>
|
||||
<p:txBody>
|
||||
<a:bodyPr/>
|
||||
<a:lstStyle>
|
||||
<a:lvl1pPr algn="l">
|
||||
<a:defRPr sz="1200">
|
||||
<a:latin typeface="Arial" charset="0"/>
|
||||
</a:defRPr>
|
||||
</a:lvl1pPr>
|
||||
</a:lstStyle>
|
||||
<a:p><a:endParaRPr/></a:p>
|
||||
</p:txBody>
|
||||
</p:sp>
|
||||
</p:spTree>
|
||||
</p:cSld>
|
||||
<p:clrMap bg1="lt1" tx1="dk1" bg2="lt2" tx2="dk2" accent1="accent1" accent2="accent2" accent3="accent3" accent4="accent4" accent5="accent5" accent6="accent6" hlink="hlink" folHlink="folHlink"/>
|
||||
<p:notesStyle>
|
||||
<a:lvl1pPr algn="l" rtl="0" fontAlgn="base">
|
||||
<a:spcBef>
|
||||
<a:spcPct val="30000"/>
|
||||
</a:spcBef>
|
||||
<a:spcAft>
|
||||
<a:spcPct val="0"/>
|
||||
</a:spcAft>
|
||||
<a:defRPr sz="1200" kern="1200">
|
||||
<a:solidFill>
|
||||
<a:schemeClr val="tx1"/>
|
||||
</a:solidFill>
|
||||
<a:latin typeface="Arial" charset="0"/>
|
||||
<a:ea typeface="+mn-ea"/>
|
||||
<a:cs typeface="+mn-cs"/>
|
||||
</a:defRPr>
|
||||
</a:lvl1pPr>
|
||||
<a:lvl2pPr marL="457200" algn="l" rtl="0" fontAlgn="base">
|
||||
<a:spcBef>
|
||||
<a:spcPct val="30000"/>
|
||||
</a:spcBef>
|
||||
<a:spcAft>
|
||||
<a:spcPct val="0"/>
|
||||
</a:spcAft>
|
||||
<a:defRPr sz="1200" kern="1200">
|
||||
<a:solidFill>
|
||||
<a:schemeClr val="tx1"/>
|
||||
</a:solidFill>
|
||||
<a:latin typeface="Arial" charset="0"/>
|
||||
<a:ea typeface="+mn-ea"/>
|
||||
<a:cs typeface="+mn-cs"/>
|
||||
</a:defRPr>
|
||||
</a:lvl2pPr>
|
||||
<a:lvl3pPr marL="914400" algn="l" rtl="0" fontAlgn="base">
|
||||
<a:spcBef>
|
||||
<a:spcPct val="30000"/>
|
||||
</a:spcBef>
|
||||
<a:spcAft>
|
||||
<a:spcPct val="0"/>
|
||||
</a:spcAft>
|
||||
<a:defRPr sz="1200" kern="1200">
|
||||
<a:solidFill>
|
||||
<a:schemeClr val="tx1"/>
|
||||
</a:solidFill>
|
||||
<a:latin typeface="Arial" charset="0"/>
|
||||
<a:ea typeface="+mn-ea"/>
|
||||
<a:cs typeface="+mn-cs"/>
|
||||
</a:defRPr>
|
||||
</a:lvl3pPr>
|
||||
<a:lvl4pPr marL="1371600" algn="l" rtl="0" fontAlgn="base">
|
||||
<a:spcBef>
|
||||
<a:spcPct val="30000"/>
|
||||
</a:spcBef>
|
||||
<a:spcAft>
|
||||
<a:spcPct val="0"/>
|
||||
</a:spcAft>
|
||||
<a:defRPr sz="1200" kern="1200">
|
||||
<a:solidFill>
|
||||
<a:schemeClr val="tx1"/>
|
||||
</a:solidFill>
|
||||
<a:latin typeface="Arial" charset="0"/>
|
||||
<a:ea typeface="+mn-ea"/>
|
||||
<a:cs typeface="+mn-cs"/>
|
||||
</a:defRPr>
|
||||
</a:lvl4pPr>
|
||||
<a:lvl5pPr marL="1828800" algn="l" rtl="0" fontAlgn="base">
|
||||
<a:spcBef>
|
||||
<a:spcPct val="30000"/>
|
||||
</a:spcBef>
|
||||
<a:spcAft>
|
||||
<a:spcPct val="0"/>
|
||||
</a:spcAft>
|
||||
<a:defRPr sz="1200" kern="1200">
|
||||
<a:solidFill>
|
||||
<a:schemeClr val="tx1"/>
|
||||
</a:solidFill>
|
||||
<a:latin typeface="Arial" charset="0"/>
|
||||
<a:ea typeface="+mn-ea"/>
|
||||
<a:cs typeface="+mn-cs"/>
|
||||
</a:defRPr>
|
||||
</a:lvl5pPr>
|
||||
<a:lvl6pPr marL="2286000" algn="l" defTabSz="914400" rtl="0" eaLnBrk="1" latinLnBrk="0" hangingPunct="1">
|
||||
<a:defRPr sz="1200" kern="1200">
|
||||
<a:solidFill>
|
||||
<a:schemeClr val="tx1"/>
|
||||
</a:solidFill>
|
||||
<a:latin typeface="+mn-lt"/>
|
||||
<a:ea typeface="+mn-ea"/>
|
||||
<a:cs typeface="+mn-cs"/>
|
||||
</a:defRPr>
|
||||
</a:lvl6pPr>
|
||||
<a:lvl7pPr marL="2743200" algn="l" defTabSz="914400" rtl="0" eaLnBrk="1" latinLnBrk="0" hangingPunct="1">
|
||||
<a:defRPr sz="1200" kern="1200">
|
||||
<a:solidFill>
|
||||
<a:schemeClr val="tx1"/>
|
||||
</a:solidFill>
|
||||
<a:latin typeface="+mn-lt"/>
|
||||
<a:ea typeface="+mn-ea"/>
|
||||
<a:cs typeface="+mn-cs"/>
|
||||
</a:defRPr>
|
||||
</a:lvl7pPr>
|
||||
<a:lvl8pPr marL="3200400" algn="l" defTabSz="914400" rtl="0" eaLnBrk="1" latinLnBrk="0" hangingPunct="1">
|
||||
<a:defRPr sz="1200" kern="1200">
|
||||
<a:solidFill>
|
||||
<a:schemeClr val="tx1"/>
|
||||
</a:solidFill>
|
||||
<a:latin typeface="+mn-lt"/>
|
||||
<a:ea typeface="+mn-ea"/>
|
||||
<a:cs typeface="+mn-cs"/>
|
||||
</a:defRPr>
|
||||
</a:lvl8pPr>
|
||||
<a:lvl9pPr marL="3657600" algn="l" defTabSz="914400" rtl="0" eaLnBrk="1" latinLnBrk="0" hangingPunct="1">
|
||||
<a:defRPr sz="1200" kern="1200">
|
||||
<a:solidFill>
|
||||
<a:schemeClr val="tx1"/>
|
||||
</a:solidFill>
|
||||
<a:latin typeface="+mn-lt"/>
|
||||
<a:ea typeface="+mn-ea"/>
|
||||
<a:cs typeface="+mn-cs"/>
|
||||
</a:defRPr>
|
||||
</a:lvl9pPr>
|
||||
</p:notesStyle>
|
||||
</p:notesMaster>
|
||||
File diff suppressed because one or more lines are too long
249
ActiveX/ASCOfficePPTXFile/Editor/WMFToImageConverter.h
Normal file
249
ActiveX/ASCOfficePPTXFile/Editor/WMFToImageConverter.h
Normal file
@@ -0,0 +1,249 @@
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2014
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
* version 3 as published by the Free Software Foundation. In accordance with
|
||||
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||
* of any third-party rights.
|
||||
*
|
||||
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||
*
|
||||
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
|
||||
* EU, LV-1021.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of the Program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU AGPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||
* grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||
* well as technical writing content are licensed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
#include "../stdafx.h"
|
||||
|
||||
#ifdef BUILD_CONFIG_FULL_VERSION
|
||||
|
||||
namespace NSWMFToImageConverter
|
||||
{
|
||||
class CImageExt
|
||||
{
|
||||
private:
|
||||
IASCRenderer* m_pSVGRenderer;
|
||||
|
||||
void Init()
|
||||
{
|
||||
if (NULL != m_pSVGRenderer)
|
||||
{
|
||||
VARIANT var;
|
||||
var.vt = VT_I4;
|
||||
var.lVal = 0;
|
||||
m_pSVGRenderer->SetAdditionalParam(L"ReInit", var);
|
||||
}
|
||||
else
|
||||
{
|
||||
CoCreateInstance( HtmlRenderer::CLSID_CASCSVGWriter, NULL, CLSCTX_ALL, __uuidof(IASCRenderer), (void**)(&m_pSVGRenderer) );
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
CImageExt()
|
||||
{
|
||||
m_pSVGRenderer = NULL;
|
||||
}
|
||||
~CImageExt()
|
||||
{
|
||||
RELEASEINTERFACE(m_pSVGRenderer);
|
||||
}
|
||||
|
||||
public:
|
||||
LONG GetImageType(CString strFile)
|
||||
{
|
||||
CFile oFile;
|
||||
if (S_OK != oFile.OpenFile(strFile))
|
||||
{
|
||||
oFile.CloseFile();
|
||||
return 0;
|
||||
}
|
||||
|
||||
DWORD dwSize = (DWORD)oFile.GetFileSize();
|
||||
|
||||
if (44 > dwSize)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
DWORD dwKey = 0;
|
||||
oFile.ReadFile((BYTE*)(&dwKey), 4);
|
||||
|
||||
if (0x9AC6CDD7 == dwKey)
|
||||
{
|
||||
|
||||
oFile.CloseFile();
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (0x00000001 == dwKey)
|
||||
{
|
||||
oFile.SetPosition(40);
|
||||
oFile.ReadFile((BYTE*)(&dwKey), 4);
|
||||
oFile.CloseFile();
|
||||
|
||||
if (0x464D4520 == dwKey)
|
||||
{
|
||||
|
||||
return 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
oFile.CloseFile();
|
||||
|
||||
if (0x00090001 == dwKey)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MetaDrawOnRenderer(IASCRenderer* pRenderer, BSTR strFile, double dW, double dH)
|
||||
{
|
||||
if (NULL == pRenderer)
|
||||
return;
|
||||
|
||||
|
||||
LONG brush_Alpha1 = 0;
|
||||
LONG brush_Alpha2 = 0;
|
||||
LONG brush_Color1 = 0;
|
||||
LONG brush_Color2 = 0;
|
||||
double brush_LinearAngle = 0;
|
||||
BSTR brush_TexturePath = NULL;
|
||||
LONG brush_TextureMode = 0;
|
||||
LONG brush_TextureAlpha = 0;
|
||||
LONG brush_Type = 0;
|
||||
|
||||
pRenderer->get_BrushAlpha1( &brush_Alpha1 );
|
||||
pRenderer->get_BrushAlpha2( &brush_Alpha2 );
|
||||
pRenderer->get_BrushColor1( &brush_Color1 );
|
||||
pRenderer->get_BrushColor2( &brush_Color2 );
|
||||
pRenderer->get_BrushLinearAngle( &brush_LinearAngle );
|
||||
pRenderer->get_BrushTextureMode( &brush_TextureMode );
|
||||
pRenderer->get_BrushTextureAlpha( &brush_TextureAlpha );
|
||||
pRenderer->get_BrushTexturePath( &brush_TexturePath );
|
||||
pRenderer->get_BrushType( &brush_Type );
|
||||
|
||||
BSTR font_Path = NULL;
|
||||
BSTR font_Name = NULL;
|
||||
double font_Size = 0;
|
||||
LONG font_Style = 0;
|
||||
BOOL font_GID = 0;
|
||||
|
||||
pRenderer->get_FontName( &font_Name );
|
||||
pRenderer->get_FontPath( &font_Path );
|
||||
pRenderer->get_FontSize( &font_Size );
|
||||
pRenderer->get_FontStyle( &font_Style );
|
||||
pRenderer->get_FontStringGID( &font_GID );
|
||||
|
||||
LONG pen_Align = 0;
|
||||
LONG pen_Alpha = 0;
|
||||
LONG pen_Color = 0;
|
||||
pRenderer->get_PenAlign( &pen_Align );
|
||||
pRenderer->get_PenAlpha( &pen_Alpha );
|
||||
pRenderer->get_PenColor( &pen_Color );
|
||||
|
||||
ASCGraphics::IAVSImage *pImage = NULL;
|
||||
CoCreateInstance( __uuidof(ASCGraphics::CAVSImage), NULL, CLSCTX_ALL, __uuidof(ASCGraphics::IAVSImage), (void**)(&pImage) );
|
||||
|
||||
pImage->put_FontManager(NULL);
|
||||
|
||||
pImage->LoadFromFile( strFile );
|
||||
|
||||
if (dW <= 0 && dH <= 0)
|
||||
{
|
||||
LONG _lw = 0;
|
||||
LONG _lh = 0;
|
||||
pImage->get_Width(&_lw);
|
||||
pImage->get_Height(&_lh);
|
||||
|
||||
LONG lMax = max(_lw, _lh);
|
||||
double dKoef = 1000.0 / lMax;
|
||||
|
||||
dW = (double)dKoef * _lw * 100;
|
||||
dH = (double)dKoef * _lh * 100;
|
||||
|
||||
m_pSVGRenderer->put_Width(dW);
|
||||
m_pSVGRenderer->put_Height(dH);
|
||||
}
|
||||
|
||||
pImage->DrawOnRenderer( pRenderer, 0, 0, dW, dH );
|
||||
|
||||
RELEASEINTERFACE( pImage );
|
||||
|
||||
|
||||
pRenderer->put_BrushAlpha1( brush_Alpha1 );
|
||||
pRenderer->put_BrushAlpha2( brush_Alpha2 );
|
||||
pRenderer->put_BrushColor1( brush_Color1 );
|
||||
pRenderer->put_BrushColor2( brush_Color2 );
|
||||
pRenderer->put_BrushLinearAngle( brush_LinearAngle );
|
||||
pRenderer->put_BrushTextureMode( brush_TextureMode );
|
||||
pRenderer->put_BrushTextureAlpha( brush_TextureAlpha );
|
||||
pRenderer->put_BrushTexturePath( brush_TexturePath ); if ( brush_TexturePath ) ::SysFreeString( brush_TexturePath );
|
||||
pRenderer->put_BrushType( brush_Type );
|
||||
|
||||
pRenderer->put_FontName( font_Name ); if ( font_Name ) ::SysFreeString( font_Name );
|
||||
pRenderer->put_FontPath( font_Path ); if ( font_Path ) ::SysFreeString( font_Path );
|
||||
pRenderer->put_FontSize( font_Size );
|
||||
pRenderer->put_FontStyle( font_Style );
|
||||
pRenderer->put_FontStringGID( font_GID );
|
||||
|
||||
pRenderer->put_PenAlign( pen_Align );
|
||||
pRenderer->put_PenAlpha( pen_Alpha );
|
||||
pRenderer->put_PenColor( pen_Color );
|
||||
|
||||
|
||||
pRenderer->PathCommandEnd();
|
||||
}
|
||||
|
||||
bool Convert(CString strPath, LONG lWidth, LONG lHeight, CString strDstPath)
|
||||
{
|
||||
Init();
|
||||
|
||||
m_pSVGRenderer->put_Width(lWidth);
|
||||
m_pSVGRenderer->put_Height(lHeight);
|
||||
|
||||
BSTR bsFilePath = strPath.AllocSysString();
|
||||
MetaDrawOnRenderer(m_pSVGRenderer, bsFilePath, (double)lWidth, (double)lHeight);
|
||||
SysFreeString(bsFilePath);
|
||||
|
||||
VARIANT var;
|
||||
m_pSVGRenderer->GetAdditionalParam(L"IsRaster", &var);
|
||||
|
||||
if (VARIANT_TRUE == var.boolVal)
|
||||
return false;
|
||||
|
||||
var.vt = VT_BSTR;
|
||||
var.bstrVal = strDstPath.AllocSysString();
|
||||
m_pSVGRenderer->SetAdditionalParam(L"SaveFile", var);
|
||||
SysFreeString((var.bstrVal));
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
746
ActiveX/ASCOfficePPTXFile/Editor/XmlWriter.h
Normal file
746
ActiveX/ASCOfficePPTXFile/Editor/XmlWriter.h
Normal file
@@ -0,0 +1,746 @@
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2014
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
* version 3 as published by the Free Software Foundation. In accordance with
|
||||
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||
* of any third-party rights.
|
||||
*
|
||||
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||
*
|
||||
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
|
||||
* EU, LV-1021.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of the Program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU AGPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||
* grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||
* well as technical writing content are licensed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
#include "../../Common/DocxFormat/Source/SystemUtility/File.h"
|
||||
#include "./BinReaderWriterDefines.h"
|
||||
|
||||
namespace NSBinPptxRW
|
||||
{
|
||||
static _bstr_t g_bstr_nodeopen = L"<";
|
||||
static _bstr_t g_bstr_nodeclose = L">";
|
||||
static _bstr_t g_bstr_nodeopen_slash = L"</";
|
||||
static _bstr_t g_bstr_nodeclose_slash = L"/>";
|
||||
static _bstr_t g_bstr_node_space = L" ";
|
||||
static _bstr_t g_bstr_node_equal = L"=";
|
||||
static _bstr_t g_bstr_node_quote = L"\"";
|
||||
static _bstr_t g_bstr_boolean_true = L"true";
|
||||
static _bstr_t g_bstr_boolean_false = L"false";
|
||||
static _bstr_t g_bstr_boolean_true2 = L"1";
|
||||
static _bstr_t g_bstr_boolean_false2 = L"0";
|
||||
|
||||
AVSINLINE static double FABS(double dVal)
|
||||
{
|
||||
return (dVal >= 0) ? dVal : -dVal;
|
||||
}
|
||||
AVSINLINE static int round(double dVal)
|
||||
{
|
||||
return (int)(dVal + 0.5);
|
||||
}
|
||||
|
||||
class CStringWriter
|
||||
{
|
||||
private:
|
||||
wchar_t* m_pData;
|
||||
size_t m_lSize;
|
||||
|
||||
wchar_t* m_pDataCur;
|
||||
size_t m_lSizeCur;
|
||||
|
||||
public:
|
||||
CStringWriter()
|
||||
{
|
||||
m_pData = NULL;
|
||||
m_lSize = 0;
|
||||
|
||||
m_pDataCur = m_pData;
|
||||
m_lSizeCur = m_lSize;
|
||||
}
|
||||
~CStringWriter()
|
||||
{
|
||||
RELEASEMEM(m_pData);
|
||||
}
|
||||
|
||||
__forceinline void AddSize(size_t nSize)
|
||||
{
|
||||
if (NULL == m_pData)
|
||||
{
|
||||
m_lSize = max(nSize, 1000);
|
||||
m_pData = (wchar_t*)malloc(m_lSize * sizeof(wchar_t));
|
||||
|
||||
m_lSizeCur = 0;
|
||||
m_pDataCur = m_pData;
|
||||
return;
|
||||
}
|
||||
|
||||
if ((m_lSizeCur + nSize) > m_lSize)
|
||||
{
|
||||
while ((m_lSizeCur + nSize) > m_lSize)
|
||||
{
|
||||
m_lSize *= 2;
|
||||
}
|
||||
|
||||
wchar_t* pRealloc = (wchar_t*)realloc(m_pData, m_lSize * sizeof(wchar_t));
|
||||
if (NULL != pRealloc)
|
||||
{
|
||||
|
||||
m_pData = pRealloc;
|
||||
m_pDataCur = m_pData + m_lSizeCur;
|
||||
}
|
||||
else
|
||||
{
|
||||
wchar_t* pMalloc = (wchar_t*)malloc(m_lSize * sizeof(wchar_t));
|
||||
memcpy(pMalloc, m_pData, m_lSizeCur * sizeof(wchar_t));
|
||||
|
||||
free(m_pData);
|
||||
m_pData = pMalloc;
|
||||
m_pDataCur = m_pData + m_lSizeCur;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
__forceinline void WriteString(wchar_t* pString, size_t& nLen)
|
||||
{
|
||||
AddSize(nLen);
|
||||
|
||||
memcpy(m_pDataCur, pString, nLen << 1);
|
||||
m_pDataCur += nLen;
|
||||
m_lSizeCur += nLen;
|
||||
}
|
||||
__forceinline void WriteString(_bstr_t& bsString)
|
||||
{
|
||||
size_t nLen = bsString.length();
|
||||
WriteString(bsString.GetBSTR(), nLen);
|
||||
}
|
||||
__forceinline void WriteString(const CString& sString)
|
||||
{
|
||||
size_t nLen = (size_t)sString.GetLength();
|
||||
|
||||
#ifdef _UNICODE
|
||||
CString* pString = const_cast<CString*>(&sString);
|
||||
WriteString(pString->GetBuffer(), nLen);
|
||||
pString->ReleaseBuffer();
|
||||
#else
|
||||
CStringW str = (CStringW)sString;
|
||||
WriteString(str.GetBuffer(), nLen);
|
||||
str.ReleaseBuffer();
|
||||
#endif
|
||||
}
|
||||
__forceinline void WriteStringXML(const CString& strValue)
|
||||
{
|
||||
|
||||
CString s = strValue;
|
||||
s.Replace(_T("&"), _T("&"));
|
||||
s.Replace(_T("'"), _T("'"));
|
||||
s.Replace(_T("<"), _T("<"));
|
||||
s.Replace(_T(">"), _T(">"));
|
||||
s.Replace(_T("\""), _T("""));
|
||||
WriteString(s);
|
||||
}
|
||||
|
||||
__forceinline size_t GetCurSize()
|
||||
{
|
||||
return m_lSizeCur;
|
||||
}
|
||||
|
||||
__forceinline void Write(CStringWriter& oWriter)
|
||||
{
|
||||
WriteString(oWriter.m_pData, oWriter.m_lSizeCur);
|
||||
}
|
||||
|
||||
__forceinline void WriteBefore(CStringWriter& oWriter)
|
||||
{
|
||||
size_t nNewS = oWriter.GetCurSize();
|
||||
AddSize(nNewS);
|
||||
memmove(m_pData + nNewS, m_pData, m_lSizeCur << 1);
|
||||
memcpy(m_pData, oWriter.m_pData, nNewS << 1);
|
||||
m_pDataCur += nNewS;
|
||||
m_lSizeCur += nNewS;
|
||||
}
|
||||
|
||||
inline void Clear()
|
||||
{
|
||||
RELEASEMEM(m_pData);
|
||||
|
||||
m_pData = NULL;
|
||||
m_lSize = 0;
|
||||
|
||||
m_pDataCur = m_pData;
|
||||
m_lSizeCur = 0;
|
||||
}
|
||||
inline void ClearNoAttack()
|
||||
{
|
||||
m_pDataCur = m_pData;
|
||||
m_lSizeCur = 0;
|
||||
}
|
||||
|
||||
CString GetData()
|
||||
{
|
||||
CString str(m_pData, (int)m_lSizeCur);
|
||||
return str;
|
||||
}
|
||||
|
||||
__forceinline void AddCharNoCheck(const WCHAR& wc)
|
||||
{
|
||||
*m_pDataCur++ = wc;
|
||||
++m_lSizeCur;
|
||||
}
|
||||
__forceinline void AddIntNoCheck(int val)
|
||||
{
|
||||
if (0 == val)
|
||||
{
|
||||
*m_pDataCur++ = (WCHAR)'0';
|
||||
++m_lSizeCur;
|
||||
return;
|
||||
}
|
||||
if (val < 0)
|
||||
{
|
||||
val = -val;
|
||||
*m_pDataCur++ = (WCHAR)'-';
|
||||
++m_lSizeCur;
|
||||
}
|
||||
|
||||
int len = 0;
|
||||
int oval = val;
|
||||
while (oval > 0)
|
||||
{
|
||||
oval /= 10;
|
||||
++len;
|
||||
}
|
||||
|
||||
oval = 1;
|
||||
while (val > 0)
|
||||
{
|
||||
m_pDataCur[len - oval] = (WCHAR)('0' + (val % 10));
|
||||
++oval;
|
||||
val /= 10;
|
||||
}
|
||||
|
||||
m_pDataCur += len;
|
||||
m_lSizeCur += len;
|
||||
}
|
||||
|
||||
__forceinline void AddStringNoCheck(const wchar_t* pData, const int& len)
|
||||
{
|
||||
memcpy(m_pDataCur, pData, len << 1);
|
||||
m_pDataCur += len;
|
||||
m_lSizeCur += len;
|
||||
}
|
||||
__forceinline void AddSpaceNoCheck()
|
||||
{
|
||||
*m_pDataCur = WCHAR(' ');
|
||||
++m_pDataCur;
|
||||
++m_lSizeCur;
|
||||
}
|
||||
};
|
||||
|
||||
class CXmlWriter
|
||||
{
|
||||
public:
|
||||
CStringWriter m_oWriter;
|
||||
|
||||
public:
|
||||
BYTE m_lDocType;
|
||||
|
||||
LONG m_lFlag;
|
||||
LONG m_lGroupIndex;
|
||||
LONG m_lObjectId;
|
||||
LONG m_lObjectIdVML;
|
||||
|
||||
public:
|
||||
BOOL m_bIsUseOffice2007;
|
||||
CString m_strStyleMain;
|
||||
CString m_strAttributesMain;
|
||||
CString m_strNodes;
|
||||
IASCRenderer* m_pOOXToVMLRenderer;
|
||||
bool m_bIsTop;
|
||||
|
||||
public:
|
||||
|
||||
CXmlWriter() : m_oWriter()
|
||||
{
|
||||
m_lDocType = XMLWRITER_DOC_TYPE_PPTX;
|
||||
|
||||
m_lFlag = 0;
|
||||
m_lGroupIndex = 0;
|
||||
m_lObjectId = 0;
|
||||
m_lObjectIdVML = 0;
|
||||
|
||||
m_bIsUseOffice2007 = FALSE;
|
||||
m_strStyleMain = _T("");
|
||||
m_strAttributesMain = _T("");
|
||||
m_strNodes = _T("");
|
||||
|
||||
m_pOOXToVMLRenderer = NULL;
|
||||
m_bIsTop = false;
|
||||
}
|
||||
~CXmlWriter()
|
||||
{
|
||||
RELEASEINTERFACE(m_pOOXToVMLRenderer);
|
||||
}
|
||||
|
||||
AVSINLINE CString GetXmlString()
|
||||
{
|
||||
return m_oWriter.GetData();
|
||||
}
|
||||
AVSINLINE void ClearNoAttack()
|
||||
{
|
||||
m_oWriter.ClearNoAttack();
|
||||
}
|
||||
AVSINLINE int GetSize()
|
||||
{
|
||||
return (int)m_oWriter.GetCurSize();
|
||||
}
|
||||
|
||||
|
||||
AVSINLINE void WriteString(const CString& strValue)
|
||||
{
|
||||
m_oWriter.WriteString(strValue);
|
||||
}
|
||||
AVSINLINE void WriteStringXML(CString strValue)
|
||||
{
|
||||
|
||||
CString s = strValue;
|
||||
s.Replace(_T("&"), _T("&"));
|
||||
s.Replace(_T("'"), _T("'"));
|
||||
s.Replace(_T("<"), _T("<"));
|
||||
s.Replace(_T(">"), _T(">"));
|
||||
s.Replace(_T("\""), _T("""));
|
||||
m_oWriter.WriteString(s);
|
||||
}
|
||||
AVSINLINE void WriteDouble(const double& val)
|
||||
{
|
||||
CString str = _T("");
|
||||
str.Format(_T("%lf"), val);
|
||||
m_oWriter.WriteString(str);
|
||||
}
|
||||
AVSINLINE void WriteLONG(const long& val)
|
||||
{
|
||||
CString str = _T("");
|
||||
str.Format(_T("%d"), val);
|
||||
m_oWriter.WriteString(str);
|
||||
}
|
||||
AVSINLINE void WriteINT(const int& val)
|
||||
{
|
||||
CString str = _T("");
|
||||
str.Format(_T("%d"), val);
|
||||
m_oWriter.WriteString(str);
|
||||
}
|
||||
AVSINLINE void WriteDWORD(const DWORD& val)
|
||||
{
|
||||
CString str = _T("");
|
||||
str.Format(_T("%u"), val);
|
||||
m_oWriter.WriteString(str);
|
||||
}
|
||||
AVSINLINE void WriteDWORD_hex(const DWORD& val)
|
||||
{
|
||||
CString str = _T("");
|
||||
str.Format(_T("%x"), val);
|
||||
m_oWriter.WriteString(str);
|
||||
}
|
||||
AVSINLINE void WriteBool(const bool& val)
|
||||
{
|
||||
if (val)
|
||||
m_oWriter.WriteString(g_bstr_boolean_true2);
|
||||
else
|
||||
m_oWriter.WriteString(g_bstr_boolean_false2);
|
||||
}
|
||||
|
||||
AVSINLINE void WriteAttributeCSS(const CString& strAttributeName, const CString& val)
|
||||
{
|
||||
m_oWriter.WriteString(strAttributeName);
|
||||
m_oWriter.AddSize(15);
|
||||
m_oWriter.AddCharNoCheck(WCHAR(':'));
|
||||
m_oWriter.WriteString(val);
|
||||
m_oWriter.AddCharNoCheck(WCHAR(';'));
|
||||
}
|
||||
AVSINLINE void WriteAttributeCSS_int(const CString& strAttributeName, const int& val)
|
||||
{
|
||||
m_oWriter.WriteString(strAttributeName);
|
||||
m_oWriter.AddSize(15);
|
||||
m_oWriter.AddCharNoCheck(WCHAR(':'));
|
||||
m_oWriter.AddIntNoCheck(val);
|
||||
m_oWriter.AddCharNoCheck(WCHAR(';'));
|
||||
}
|
||||
AVSINLINE void WriteAttributeCSS_double1(const CString& strAttributeName, const double& val)
|
||||
{
|
||||
m_oWriter.WriteString(strAttributeName);
|
||||
m_oWriter.AddSize(15);
|
||||
CString s = _T("");
|
||||
s.Format(_T("%.1lf"), val);
|
||||
m_oWriter.AddCharNoCheck(WCHAR(':'));
|
||||
m_oWriter.WriteString(s);
|
||||
m_oWriter.AddCharNoCheck(WCHAR(';'));
|
||||
}
|
||||
AVSINLINE void WriteAttributeCSS_int_pt(const CString& strAttributeName, const int& val)
|
||||
{
|
||||
m_oWriter.WriteString(strAttributeName);
|
||||
m_oWriter.AddSize(15);
|
||||
m_oWriter.AddCharNoCheck(WCHAR(':'));
|
||||
m_oWriter.AddIntNoCheck(val);
|
||||
m_oWriter.AddCharNoCheck(WCHAR('p'));
|
||||
m_oWriter.AddCharNoCheck(WCHAR('t'));
|
||||
m_oWriter.AddCharNoCheck(WCHAR(';'));
|
||||
}
|
||||
AVSINLINE void WriteAttributeCSS_double1_pt(const CString& strAttributeName, const double& val)
|
||||
{
|
||||
m_oWriter.WriteString(strAttributeName);
|
||||
m_oWriter.AddSize(20);
|
||||
CString s = _T("");
|
||||
s.Format(_T("%.1lf"), val);
|
||||
m_oWriter.AddCharNoCheck(WCHAR(':'));
|
||||
m_oWriter.WriteString(s);
|
||||
m_oWriter.AddCharNoCheck(WCHAR('p'));
|
||||
m_oWriter.AddCharNoCheck(WCHAR('t'));
|
||||
m_oWriter.AddCharNoCheck(WCHAR(';'));
|
||||
}
|
||||
|
||||
AVSINLINE void WriteAttribute(const CString& strAttributeName, const CString& val)
|
||||
{
|
||||
m_oWriter.WriteString(g_bstr_node_space);
|
||||
m_oWriter.WriteString(strAttributeName);
|
||||
m_oWriter.WriteString(g_bstr_node_equal);
|
||||
m_oWriter.WriteString(g_bstr_node_quote);
|
||||
m_oWriter.WriteString(val);
|
||||
m_oWriter.WriteString(g_bstr_node_quote);
|
||||
}
|
||||
AVSINLINE void WriteAttribute2(const CString& strAttributeName, const CString& val)
|
||||
{
|
||||
m_oWriter.WriteString(g_bstr_node_space);
|
||||
m_oWriter.WriteString(strAttributeName);
|
||||
m_oWriter.WriteString(g_bstr_node_equal);
|
||||
m_oWriter.WriteString(g_bstr_node_quote);
|
||||
m_oWriter.WriteStringXML(val);
|
||||
m_oWriter.WriteString(g_bstr_node_quote);
|
||||
}
|
||||
AVSINLINE void WriteAttribute(const CString& strAttributeName, const double& val)
|
||||
{
|
||||
m_oWriter.WriteString(g_bstr_node_space);
|
||||
m_oWriter.WriteString(strAttributeName);
|
||||
m_oWriter.WriteString(g_bstr_node_equal);
|
||||
m_oWriter.WriteString(g_bstr_node_quote);
|
||||
WriteDouble(val);
|
||||
m_oWriter.WriteString(g_bstr_node_quote);
|
||||
}
|
||||
AVSINLINE void WriteAttribute(const CString& strAttributeName, const int& val)
|
||||
{
|
||||
m_oWriter.WriteString(g_bstr_node_space);
|
||||
m_oWriter.WriteString(strAttributeName);
|
||||
m_oWriter.WriteString(g_bstr_node_equal);
|
||||
m_oWriter.WriteString(g_bstr_node_quote);
|
||||
WriteINT(val);
|
||||
m_oWriter.WriteString(g_bstr_node_quote);
|
||||
}
|
||||
AVSINLINE void WriteAttribute(const CString& strAttributeName, const bool& val)
|
||||
{
|
||||
m_oWriter.WriteString(g_bstr_node_space);
|
||||
m_oWriter.WriteString(strAttributeName);
|
||||
m_oWriter.WriteString(g_bstr_node_equal);
|
||||
m_oWriter.WriteString(g_bstr_node_quote);
|
||||
WriteBool(val);
|
||||
m_oWriter.WriteString(g_bstr_node_quote);
|
||||
}
|
||||
AVSINLINE void WriteAttribute(const CString& strAttributeName, const LONG& val)
|
||||
{
|
||||
m_oWriter.WriteString(g_bstr_node_space);
|
||||
m_oWriter.WriteString(strAttributeName);
|
||||
m_oWriter.WriteString(g_bstr_node_equal);
|
||||
m_oWriter.WriteString(g_bstr_node_quote);
|
||||
WriteLONG(val);
|
||||
m_oWriter.WriteString(g_bstr_node_quote);
|
||||
}
|
||||
AVSINLINE void WriteAttribute(const CString& strAttributeName, const DWORD& val)
|
||||
{
|
||||
m_oWriter.WriteString(g_bstr_node_space);
|
||||
m_oWriter.WriteString(strAttributeName);
|
||||
m_oWriter.WriteString(g_bstr_node_equal);
|
||||
m_oWriter.WriteString(g_bstr_node_quote);
|
||||
WriteDWORD(val);
|
||||
m_oWriter.WriteString(g_bstr_node_quote);
|
||||
}
|
||||
AVSINLINE void WriteAttributeDWORD_hex(const CString& strAttributeName, const DWORD& val)
|
||||
{
|
||||
m_oWriter.WriteString(g_bstr_node_space);
|
||||
m_oWriter.WriteString(strAttributeName);
|
||||
m_oWriter.WriteString(g_bstr_node_equal);
|
||||
m_oWriter.WriteString(g_bstr_node_quote);
|
||||
WriteDWORD_hex(val);
|
||||
m_oWriter.WriteString(g_bstr_node_quote);
|
||||
}
|
||||
|
||||
AVSINLINE void WriteNodeBegin(CString strNodeName, BOOL bAttributed = FALSE)
|
||||
{
|
||||
m_oWriter.WriteString(g_bstr_nodeopen);
|
||||
m_oWriter.WriteString(strNodeName);
|
||||
|
||||
if (!bAttributed)
|
||||
m_oWriter.WriteString(g_bstr_nodeclose);
|
||||
}
|
||||
AVSINLINE void WriteNodeEnd(CString strNodeName, BOOL bEmptyNode = FALSE, BOOL bEndNode = TRUE)
|
||||
{
|
||||
if (bEmptyNode)
|
||||
{
|
||||
if (bEndNode)
|
||||
m_oWriter.WriteString(g_bstr_nodeclose_slash);
|
||||
else
|
||||
m_oWriter.WriteString(g_bstr_nodeclose);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_oWriter.WriteString(g_bstr_nodeopen_slash);
|
||||
m_oWriter.WriteString(strNodeName);
|
||||
m_oWriter.WriteString(g_bstr_nodeclose);
|
||||
}
|
||||
}
|
||||
|
||||
AVSINLINE void WriteNodeValue(const CString& strNodeName, const CString& val)
|
||||
{
|
||||
WriteNodeBegin(strNodeName);
|
||||
WriteString(val);
|
||||
WriteNodeEnd(strNodeName);
|
||||
}
|
||||
AVSINLINE void WriteNodeValue(const CString& strNodeName, const bool& val)
|
||||
{
|
||||
WriteNodeBegin(strNodeName);
|
||||
|
||||
if (val)
|
||||
WriteString(_T("1"));
|
||||
else
|
||||
WriteString(_T("0"));
|
||||
|
||||
WriteNodeEnd(strNodeName);
|
||||
}
|
||||
AVSINLINE void WriteNodeValue(const CString& strNodeName, const double& val)
|
||||
{
|
||||
WriteNodeBegin(strNodeName);
|
||||
WriteDouble(val);
|
||||
WriteNodeEnd(strNodeName);
|
||||
}
|
||||
AVSINLINE void WriteNodeValue(const CString& strNodeName, const LONG& val)
|
||||
{
|
||||
WriteNodeBegin(strNodeName);
|
||||
WriteLONG(val);
|
||||
WriteNodeEnd(strNodeName);
|
||||
}
|
||||
AVSINLINE void WriteNodeValue(const CString& strNodeName, const int& val)
|
||||
{
|
||||
WriteNodeBegin(strNodeName);
|
||||
WriteINT(val);
|
||||
WriteNodeEnd(strNodeName);
|
||||
}
|
||||
AVSINLINE void WriteNodeValue(const CString& strNodeName, const DWORD& val)
|
||||
{
|
||||
WriteNodeBegin(strNodeName);
|
||||
WriteDWORD(val);
|
||||
WriteNodeEnd(strNodeName);
|
||||
}
|
||||
AVSINLINE void WriteNodeValueDWORD_hex(const CString& strNodeName, const DWORD& val)
|
||||
{
|
||||
WriteNodeBegin(strNodeName);
|
||||
WriteDWORD_hex(val);
|
||||
WriteNodeEnd(strNodeName);
|
||||
}
|
||||
|
||||
BOOL SaveToFile(CString strFilePath, BOOL bEncodingToUTF8 = TRUE, BOOL bIsClearNoAttack = TRUE)
|
||||
{
|
||||
CString strData = m_oWriter.GetData();
|
||||
if (!bEncodingToUTF8)
|
||||
{
|
||||
CFile oFile;
|
||||
oFile.CreateFile(strFilePath);
|
||||
oFile.WriteFile((void*)strData.GetBuffer(), strData.GetLength());
|
||||
oFile.CloseFile();
|
||||
}
|
||||
else
|
||||
{
|
||||
CDirectory::SaveToFile(strFilePath, strData);
|
||||
|
||||
int nLength = strData.GetLength();
|
||||
|
||||
CStringA saStr;
|
||||
|
||||
#ifdef UNICODE
|
||||
|
||||
WideCharToMultiByte(CP_UTF8, 0, strData.GetBuffer(), nLength + 1, saStr.GetBuffer(nLength*3 + 1), nLength*3, NULL, NULL);
|
||||
saStr.ReleaseBuffer();
|
||||
#else
|
||||
wchar_t* pWStr = new wchar_t[nLength + 1];
|
||||
if (!pWStr)
|
||||
return;
|
||||
|
||||
|
||||
pWStr[nLength] = 0;
|
||||
|
||||
|
||||
MultiByteToWideChar(CP_ACP, 0, strData, nLength, pWStr, nLength);
|
||||
|
||||
int nLengthW = (int)wcslen(pWStr);
|
||||
|
||||
|
||||
WideCharToMultiByte(CP_UTF8, 0, pWStr, nLengthW + 1, saStr.GetBuffer(nLengthW*3 + 1), nLengthW*3, NULL, NULL);
|
||||
saStr.ReleaseBuffer();
|
||||
|
||||
delete[] pWStr;
|
||||
#endif
|
||||
|
||||
CFile oFile;
|
||||
oFile.CreateFile(strFilePath);
|
||||
CString strHead = _T("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>");
|
||||
oFile.WriteStringUTF8(strHead);
|
||||
oFile.WriteFile((void*)saStr.GetBuffer(), saStr.GetLength());
|
||||
oFile.CloseFile();
|
||||
}
|
||||
|
||||
if (bIsClearNoAttack)
|
||||
{
|
||||
m_oWriter.ClearNoAttack();
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
AVSINLINE void WriteAttribute(const CString& strName, const nullable_int& value)
|
||||
{
|
||||
if (value.IsInit())
|
||||
WriteAttribute(strName, *value);
|
||||
}
|
||||
AVSINLINE void WriteAttribute(const CString& strName, const nullable_double& value)
|
||||
{
|
||||
if (value.IsInit())
|
||||
WriteAttribute(strName, *value);
|
||||
}
|
||||
AVSINLINE void WriteAttribute(const CString& strName, const nullable_string& value)
|
||||
{
|
||||
if (value.IsInit())
|
||||
WriteAttribute(strName, *value);
|
||||
}
|
||||
AVSINLINE void WriteAttribute2(const CString& strName, const nullable_string& value)
|
||||
{
|
||||
if (value.IsInit())
|
||||
WriteAttribute2(strName, *value);
|
||||
}
|
||||
AVSINLINE void WriteAttribute(const CString& strName, const nullable_bool& value)
|
||||
{
|
||||
if (value.IsInit())
|
||||
WriteAttribute(strName, *value);
|
||||
}
|
||||
template <typename T>
|
||||
AVSINLINE void WriteAttribute(const CString& strName, const nullable_limit<T>& value)
|
||||
{
|
||||
if (value.IsInit())
|
||||
WriteAttribute(strName, (*value).get());
|
||||
}
|
||||
|
||||
|
||||
AVSINLINE void WriteNodeValue(const CString& strName, const nullable_int& value)
|
||||
{
|
||||
if (value.IsInit())
|
||||
WriteNodeValue(strName, *value);
|
||||
}
|
||||
AVSINLINE void WriteNodeValue(const CString& strName, const nullable_double& value)
|
||||
{
|
||||
if (value.IsInit())
|
||||
WriteNodeValue(strName, *value);
|
||||
}
|
||||
AVSINLINE void WriteNodeValue(const CString& strName, const nullable_string& value)
|
||||
{
|
||||
if (value.IsInit())
|
||||
WriteNodeValue(strName, *value);
|
||||
}
|
||||
AVSINLINE void WriteNodeValue(const CString& strName, const nullable_bool& value)
|
||||
{
|
||||
if (value.IsInit())
|
||||
WriteNodeValue(strName, *value);
|
||||
}
|
||||
template <typename T>
|
||||
AVSINLINE void WriteNodeValue(const CString& strName, const nullable_limit<T>& value)
|
||||
{
|
||||
if (value.IsInit())
|
||||
WriteNodeValue(strName, (*value).get);
|
||||
}
|
||||
|
||||
|
||||
AVSINLINE void StartNode(const CString& name)
|
||||
{
|
||||
m_oWriter.WriteString(g_bstr_nodeopen);
|
||||
m_oWriter.WriteString(name);
|
||||
}
|
||||
AVSINLINE void StartAttributes()
|
||||
{
|
||||
|
||||
}
|
||||
AVSINLINE void EndAttributes()
|
||||
{
|
||||
m_oWriter.WriteString(g_bstr_nodeclose);
|
||||
}
|
||||
AVSINLINE void EndNode(const CString& name)
|
||||
{
|
||||
m_oWriter.WriteString(g_bstr_nodeopen_slash);
|
||||
m_oWriter.WriteString(name);
|
||||
m_oWriter.WriteString(g_bstr_nodeclose);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
AVSINLINE void WriteArray(const CString& strName, const CAtlArray<T>& arr)
|
||||
{
|
||||
size_t nCount = arr.GetCount();
|
||||
if (0 != nCount)
|
||||
{
|
||||
StartNode(strName);
|
||||
m_oWriter.WriteString(g_bstr_nodeclose);
|
||||
for (size_t i = 0; i < nCount; ++i)
|
||||
arr[i].toXmlWriter(this);
|
||||
EndNode(strName);
|
||||
}
|
||||
}
|
||||
template<typename T>
|
||||
AVSINLINE void WriteArray2(const CAtlArray<T>& arr)
|
||||
{
|
||||
size_t nCount = arr.GetCount();
|
||||
if (0 != nCount)
|
||||
{
|
||||
for (size_t i = 0; i < nCount; ++i)
|
||||
arr[i].toXmlWriter(this);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
AVSINLINE void Write(const nullable<T>& val)
|
||||
{
|
||||
if (val.is_init())
|
||||
val->toXmlWriter(this);
|
||||
}
|
||||
|
||||
|
||||
void ReplaceString(CString str1, CString str2)
|
||||
{
|
||||
|
||||
CString sCur = m_oWriter.GetData();
|
||||
sCur.Replace(str1, str2);
|
||||
ClearNoAttack();
|
||||
WriteString(sCur);
|
||||
}
|
||||
};
|
||||
}
|
||||
948
ActiveX/ASCOfficePPTXFile/Editor/imagemanager.h
Normal file
948
ActiveX/ASCOfficePPTXFile/Editor/imagemanager.h
Normal file
@@ -0,0 +1,948 @@
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2014
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
* version 3 as published by the Free Software Foundation. In accordance with
|
||||
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||
* of any third-party rights.
|
||||
*
|
||||
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||
*
|
||||
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
|
||||
* EU, LV-1021.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of the Program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU AGPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||
* grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||
* well as technical writing content are licensed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
#include "math.h"
|
||||
#include "CalculatorCRC32.h"
|
||||
|
||||
#include "../../Common/DocxFormat/Source/SystemUtility/File.h"
|
||||
#include "FontPicker.h"
|
||||
using namespace NSFontCutter;
|
||||
|
||||
#ifndef AVSINLINE
|
||||
#define AVSINLINE __forceinline
|
||||
#endif
|
||||
|
||||
#include "../../ASCPresentationEditor/PPTXWriter/FileDownloader.h"
|
||||
#include "WMFToImageConverter.h"
|
||||
#include "../../Common/MediaFormatDefine.h"
|
||||
|
||||
namespace NSShapeImageGen
|
||||
{
|
||||
const long c_nMaxImageSize = 2000;
|
||||
|
||||
static BOOL _CopyFile(CString strExists, CString strNew, LPPROGRESS_ROUTINE lpFunc, LPVOID lpData)
|
||||
{
|
||||
::DeleteFile(strNew);
|
||||
return ::CopyFileEx(strExists, strNew, lpFunc, lpData, FALSE, 0);
|
||||
}
|
||||
|
||||
enum ImageType
|
||||
{
|
||||
itJPG = 0,
|
||||
itPNG = 1,
|
||||
itVIF = 2,
|
||||
itWMF = 3,
|
||||
itEMF = 4
|
||||
};
|
||||
|
||||
class CImageInfo
|
||||
{
|
||||
public:
|
||||
NSShapeImageGen::ImageType m_eType;
|
||||
LONG m_lID;
|
||||
bool m_bValid;
|
||||
|
||||
CImageInfo()
|
||||
{
|
||||
m_eType = itJPG;
|
||||
m_lID = -1;
|
||||
m_bValid = true;
|
||||
}
|
||||
CImageInfo(const CImageInfo& oSrc)
|
||||
{
|
||||
*this = oSrc;
|
||||
}
|
||||
CImageInfo& operator=(const CImageInfo& oSrc)
|
||||
{
|
||||
m_eType = oSrc.m_eType;
|
||||
m_lID = oSrc.m_lID;
|
||||
m_bValid = oSrc.m_bValid;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
AVSINLINE CString GetPath(const CString& strMedia)
|
||||
{
|
||||
CString strExt = _T("");
|
||||
strExt.Format(_T("\\image%d.%s"), m_lID, (itJPG == m_eType) ? _T("jpg") : _T("png"));
|
||||
return strMedia + strExt;
|
||||
}
|
||||
|
||||
AVSINLINE CString GetPath2()
|
||||
{
|
||||
CString _strExt = _T("png");
|
||||
switch (m_eType)
|
||||
{
|
||||
case itJPG:
|
||||
_strExt = _T("jpg");
|
||||
break;
|
||||
case itWMF:
|
||||
_strExt = _T("wmf");
|
||||
break;
|
||||
case itEMF:
|
||||
_strExt = _T("emf");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
CString strExt = _T("");
|
||||
strExt.Format(_T("image%d.%s"), m_lID, _strExt);
|
||||
return strExt;
|
||||
}
|
||||
};
|
||||
|
||||
class CImageManager
|
||||
{
|
||||
public:
|
||||
CAtlMap<CString, CImageInfo> m_mapImagesFile;
|
||||
CAtlMap<DWORD, CImageInfo> m_mapImageData;
|
||||
|
||||
CAtlArray<void*> m_listDrawings;
|
||||
CAtlList<CImageInfo> m_listImages;
|
||||
|
||||
CString m_strDstMedia;
|
||||
|
||||
LONG m_lMaxSizeImage;
|
||||
LONG m_lNextIDImage;
|
||||
|
||||
CCalculatorCRC32 m_oCRC;
|
||||
|
||||
LONG m_lDstFormat;
|
||||
|
||||
#ifdef BUILD_CONFIG_FULL_VERSION
|
||||
NSWMFToImageConverter::CImageExt m_oExt;
|
||||
#endif
|
||||
|
||||
public:
|
||||
|
||||
CImageManager()
|
||||
{
|
||||
m_strDstMedia = _T("");
|
||||
m_lMaxSizeImage = c_nMaxImageSize;
|
||||
m_lNextIDImage = 0;
|
||||
m_lDstFormat = 0;
|
||||
}
|
||||
|
||||
AVSINLINE void NewDocument()
|
||||
{
|
||||
m_strDstMedia = _T("");
|
||||
m_lMaxSizeImage = 800;
|
||||
m_lNextIDImage = 0;
|
||||
|
||||
m_mapImageData.RemoveAll();
|
||||
m_mapImagesFile.RemoveAll();
|
||||
m_listImages.RemoveAll();
|
||||
}
|
||||
|
||||
public:
|
||||
template <typename T>
|
||||
void Serialize(T* pWriter)
|
||||
{
|
||||
pWriter->WriteINT(m_lMaxSizeImage);
|
||||
pWriter->WriteINT(m_lNextIDImage);
|
||||
pWriter->WriteINT(m_lDstFormat);
|
||||
pWriter->WriteString(m_strDstMedia);
|
||||
|
||||
int lCount = (int)m_mapImagesFile.GetCount();
|
||||
pWriter->WriteINT(lCount);
|
||||
|
||||
POSITION pos = m_mapImagesFile.GetStartPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
CAtlMap<CString, CImageInfo>::CPair* pPair = m_mapImagesFile.GetNext(pos);
|
||||
|
||||
pWriter->WriteString(pPair->m_key);
|
||||
pWriter->WriteINT((int)pPair->m_value.m_eType);
|
||||
pWriter->WriteINT((int)pPair->m_value.m_lID);
|
||||
pWriter->WriteBYTE(pPair->m_value.m_bValid ? 1 : 0);
|
||||
}
|
||||
|
||||
lCount = (int)m_mapImageData.GetCount();
|
||||
pWriter->WriteINT(lCount);
|
||||
|
||||
pos = m_mapImageData.GetStartPosition();
|
||||
while (NULL != pos)
|
||||
{
|
||||
CAtlMap<DWORD, CImageInfo>::CPair* pPair = m_mapImageData.GetNext(pos);
|
||||
|
||||
pWriter->WriteULONG(pPair->m_key);
|
||||
pWriter->WriteINT((int)pPair->m_value.m_eType);
|
||||
pWriter->WriteINT((int)pPair->m_value.m_lID);
|
||||
pWriter->WriteBYTE(pPair->m_value.m_bValid ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Deserialize(T* pReader)
|
||||
{
|
||||
m_lMaxSizeImage = pReader->GetLong();
|
||||
m_lNextIDImage = pReader->GetLong();
|
||||
m_lDstFormat = pReader->GetLong();
|
||||
m_strDstMedia = pReader->GetString2();
|
||||
|
||||
m_mapImageData.RemoveAll();
|
||||
m_mapImagesFile.RemoveAll();
|
||||
|
||||
LONG lCount = pReader->GetLong();
|
||||
for (LONG i = 0; i < lCount; ++i)
|
||||
{
|
||||
CString sKey = pReader->GetString2();
|
||||
|
||||
CImageInfo oInfo;
|
||||
oInfo.m_eType = (NSShapeImageGen::ImageType)pReader->GetLong();
|
||||
oInfo.m_lID = pReader->GetLong();
|
||||
oInfo.m_bValid = pReader->GetBool();
|
||||
|
||||
m_mapImagesFile.SetAt(sKey, oInfo);
|
||||
}
|
||||
|
||||
lCount = pReader->GetLong();
|
||||
for (LONG i = 0; i < lCount; ++i)
|
||||
{
|
||||
DWORD dwKey = (DWORD)pReader->GetULong();
|
||||
|
||||
CImageInfo oInfo;
|
||||
oInfo.m_eType = (NSShapeImageGen::ImageType)pReader->GetLong();
|
||||
oInfo.m_lID = pReader->GetLong();
|
||||
oInfo.m_bValid = pReader->GetBool();
|
||||
|
||||
m_mapImageData.SetAt(dwKey, oInfo);
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
CImageInfo WriteImage(IUnknown* punkImage, double& x, double& y, double& width, double& height)
|
||||
{
|
||||
CImageInfo info;
|
||||
if (NULL == punkImage)
|
||||
return info;
|
||||
|
||||
if (height < 0)
|
||||
{
|
||||
FlipY(punkImage);
|
||||
height = -height;
|
||||
y -= height;
|
||||
}
|
||||
|
||||
return GenerateImageID(punkImage, max(1.0, width), max(1.0, height));
|
||||
}
|
||||
CImageInfo WriteImage(CString& strFile, double& x, double& y, double& width, double& height)
|
||||
{
|
||||
bool bIsDownload = false;
|
||||
int n1 = strFile.Find(_T("www"));
|
||||
int n2 = strFile.Find(_T("http"));
|
||||
int n3 = strFile.Find(_T("ftp"));
|
||||
int n4 = strFile.Find(_T("https"));
|
||||
|
||||
if (((n1 >= 0) && (n1 < 10)) || ((n2 >= 0) && (n2 < 10)) || ((n3 >= 0) && (n3 < 10)) || ((n4 >= 0) && (n4 < 10)))
|
||||
bIsDownload = true;
|
||||
|
||||
if (bIsDownload)
|
||||
{
|
||||
CString strFile1 = strFile;
|
||||
strFile1.Replace(_T("\\"), _T("/"));
|
||||
strFile1.Replace(_T("http:/"), _T("http://"));
|
||||
strFile1.Replace(_T("https:/"), _T("https://"));
|
||||
strFile1.Replace(_T("ftp:/"), _T("ftp://"));
|
||||
|
||||
CImageInfo oInfo;
|
||||
CAtlMap<CString, CImageInfo>::CPair* pPair = m_mapImagesFile.Lookup(strFile1);
|
||||
if (pPair != NULL)
|
||||
return pPair->m_value;
|
||||
|
||||
CString strDownload = _T("");
|
||||
CFileDownloader oDownloader(strFile1, TRUE);
|
||||
oDownloader.Start( 1 );
|
||||
while ( oDownloader.IsRunned() )
|
||||
{
|
||||
::Sleep( 10 );
|
||||
}
|
||||
|
||||
if ( oDownloader.IsFileDownloaded() )
|
||||
strDownload = oDownloader.GetFilePath();
|
||||
|
||||
return GenerateImageID_2(strDownload, strFile1, max(1.0, width), max(1.0, height));
|
||||
}
|
||||
|
||||
CImageInfo info;
|
||||
CFile oFile;
|
||||
if (S_OK != oFile.OpenFile(strFile))
|
||||
return info;
|
||||
|
||||
oFile.CloseFile();
|
||||
|
||||
if (-1 == width && -1 == height)
|
||||
return GenerateImageID(strFile, width, height);
|
||||
return GenerateImageID(strFile, max(1.0, width), max(1.0, height));
|
||||
}
|
||||
|
||||
protected:
|
||||
inline void CopyFile(CString& strFileSrc, CString& strFileDst)
|
||||
{
|
||||
_CopyFile(strFileSrc, strFileDst, NULL, NULL);
|
||||
}
|
||||
|
||||
#ifdef BUILD_CONFIG_OPENSOURCE_VERSION
|
||||
static IUnknown* CreateEmptyImage(int nWidth, int nHeight, BOOL bFlipVertical = TRUE)
|
||||
{
|
||||
if (nWidth < 1 || nHeight < 1)
|
||||
return NULL;
|
||||
|
||||
MediaCore::IAVSUncompressedVideoFrame* pMediaData = NULL;
|
||||
CoCreateInstance(MediaCore::CLSID_CAVSUncompressedVideoFrame, NULL, CLSCTX_ALL, MediaCore::IID_IAVSUncompressedVideoFrame, (void**)(&pMediaData));
|
||||
if (NULL == pMediaData)
|
||||
return NULL;
|
||||
|
||||
if (bFlipVertical)
|
||||
pMediaData->put_ColorSpace(CSP_BGRA | CSP_VFLIP);
|
||||
else
|
||||
pMediaData->put_ColorSpace(CSP_BGRA);
|
||||
|
||||
|
||||
pMediaData->put_Width(nWidth);
|
||||
pMediaData->put_Height(nHeight);
|
||||
pMediaData->put_AspectRatioX(nWidth);
|
||||
pMediaData->put_AspectRatioY(nHeight);
|
||||
pMediaData->put_Interlaced(VARIANT_FALSE);
|
||||
pMediaData->put_Stride(0, 4*nWidth);
|
||||
pMediaData->AllocateBuffer(4*nWidth*nHeight);
|
||||
|
||||
|
||||
BYTE* pBufferPtr = 0;
|
||||
long nCreatedBufferSize = 0;
|
||||
pMediaData->get_Buffer(&pBufferPtr);
|
||||
pMediaData->get_BufferSize(&nCreatedBufferSize);
|
||||
pMediaData->put_Plane(0, pBufferPtr);
|
||||
|
||||
|
||||
if (!pBufferPtr || nCreatedBufferSize != 4*nWidth*nHeight)
|
||||
{
|
||||
RELEASEINTERFACE(pMediaData);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
memset(pBufferPtr, 0xFF, nCreatedBufferSize);
|
||||
|
||||
|
||||
IUnknown* punkInterface = NULL;
|
||||
pMediaData->QueryInterface(IID_IUnknown, (void**)&punkInterface);
|
||||
|
||||
RELEASEINTERFACE(pMediaData);
|
||||
return punkInterface;
|
||||
}
|
||||
|
||||
void SaveImage(CString& strFileSrc, CImageInfo& oInfo, LONG __width, LONG __height)
|
||||
{
|
||||
OfficeCore::IImageGdipFilePtr pImageFile;
|
||||
pImageFile.CreateInstance(OfficeCore::CLSID_CImageGdipFile);
|
||||
|
||||
BSTR bsSrc = strFileSrc.AllocSysString();
|
||||
pImageFile->OpenFile(bsSrc);
|
||||
SysFreeString(bsSrc);
|
||||
|
||||
IUnknown* punkFrame = NULL;
|
||||
pImageFile->get_Frame(&punkFrame);
|
||||
|
||||
if (NULL == punkFrame)
|
||||
punkFrame = CreateEmptyImage(10, 10);
|
||||
|
||||
MediaCore::IAVSUncompressedVideoFrame* pFrame = NULL;
|
||||
punkFrame->QueryInterface(MediaCore::IID_IAVSUncompressedVideoFrame, (void**)&pFrame);
|
||||
|
||||
RELEASEINTERFACE(punkFrame);
|
||||
|
||||
LONG lWidth = 0;
|
||||
LONG lHeight = 0;
|
||||
pFrame->get_Width(&lWidth);
|
||||
pFrame->get_Height(&lHeight);
|
||||
|
||||
oInfo.m_eType = GetImageType(pFrame);
|
||||
|
||||
RELEASEINTERFACE(pFrame);
|
||||
|
||||
LONG lMaxSize = min(max(lWidth, lHeight), m_lMaxSizeImage);
|
||||
|
||||
if ((lWidth > lMaxSize) || (lHeight > lMaxSize))
|
||||
{
|
||||
LONG lW = 0;
|
||||
LONG lH = 0;
|
||||
double dAspect = (double)lWidth / lHeight;
|
||||
|
||||
if (lWidth >= lHeight)
|
||||
{
|
||||
lW = lMaxSize;
|
||||
lH = (LONG)((double)lW / dAspect);
|
||||
}
|
||||
else
|
||||
{
|
||||
lH = lMaxSize;
|
||||
lW = (LONG)(dAspect * lH);
|
||||
}
|
||||
|
||||
pImageFile->Resize(lW, lH, 3);
|
||||
}
|
||||
|
||||
LONG lSaveType = 4;
|
||||
CString strSaveItem = _T("");
|
||||
strSaveItem.Format(_T("\\image%d."), oInfo.m_lID);
|
||||
if (itJPG == oInfo.m_eType)
|
||||
{
|
||||
strSaveItem = m_strDstMedia + strSaveItem + _T("jpg");
|
||||
lSaveType = 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
strSaveItem = m_strDstMedia + strSaveItem + _T("png");
|
||||
}
|
||||
BSTR bsDst = strSaveItem.AllocSysString();
|
||||
pImageFile->SaveFile(bsDst, lSaveType);
|
||||
SysFreeString(bsDst);
|
||||
}
|
||||
void SaveImage(IUnknown* punkImage, CImageInfo& oInfo, LONG __width, LONG __height)
|
||||
{
|
||||
MediaCore::IAVSUncompressedVideoFrame* pFrame = NULL;
|
||||
punkImage->QueryInterface(MediaCore::IID_IAVSUncompressedVideoFrame, (void**)&pFrame);
|
||||
|
||||
if (NULL == pFrame)
|
||||
return;
|
||||
|
||||
LONG lWidth = 0;
|
||||
LONG lHeight = 0;
|
||||
pFrame->get_Width(&lWidth);
|
||||
pFrame->get_Height(&lHeight);
|
||||
|
||||
oInfo.m_eType = GetImageType(pFrame);
|
||||
|
||||
RELEASEINTERFACE(pFrame);
|
||||
|
||||
OfficeCore::IImageGdipFilePtr pImageFile;
|
||||
pImageFile.CreateInstance(OfficeCore::CLSID_CImageGdipFile);
|
||||
pImageFile->put_Frame(punkImage);
|
||||
|
||||
LONG lMaxSize = min(max(lWidth, lHeight), m_lMaxSizeImage);
|
||||
|
||||
if ((lWidth > lMaxSize) || (lHeight > lMaxSize))
|
||||
{
|
||||
LONG lW = 0;
|
||||
LONG lH = 0;
|
||||
double dAspect = (double)lWidth / lHeight;
|
||||
|
||||
if (lWidth >= lHeight)
|
||||
{
|
||||
lW = lMaxSize;
|
||||
lH = (LONG)((double)lW / dAspect);
|
||||
}
|
||||
else
|
||||
{
|
||||
lH = lMaxSize;
|
||||
lW = (LONG)(dAspect * lH);
|
||||
}
|
||||
|
||||
pImageFile->Resize(lW, lH, 3);
|
||||
}
|
||||
|
||||
LONG lSaveType = 4;
|
||||
CString strSaveItem = _T("");
|
||||
strSaveItem.Format(_T("\\image%d."), oInfo.m_lID);
|
||||
if (itJPG == oInfo.m_eType)
|
||||
{
|
||||
strSaveItem = m_strDstMedia + strSaveItem + _T("jpg");
|
||||
lSaveType = 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
strSaveItem = m_strDstMedia + strSaveItem + _T("png");
|
||||
}
|
||||
BSTR bsDst = strSaveItem.AllocSysString();
|
||||
pImageFile->SaveFile(bsDst, lSaveType);
|
||||
SysFreeString(bsDst);
|
||||
}
|
||||
#else
|
||||
void SaveImage(CString& strFileSrc, CImageInfo& oInfo, LONG __width, LONG __height)
|
||||
{
|
||||
CString strLoadXml = _T("<transforms><ImageFile-LoadImage sourcepath=\"") + strFileSrc + _T("\"/></transforms>");
|
||||
|
||||
ImageStudio::IImageTransforms* pTransform = NULL;
|
||||
CoCreateInstance(ImageStudio::CLSID_ImageTransforms, NULL, CLSCTX_INPROC_SERVER, ImageStudio::IID_IImageTransforms, (void**)&pTransform);
|
||||
|
||||
VARIANT_BOOL vbRes = VARIANT_FALSE;
|
||||
BSTR bsLoad = strLoadXml.AllocSysString();
|
||||
pTransform->SetXml(bsLoad, &vbRes);
|
||||
SysFreeString(bsLoad);
|
||||
|
||||
pTransform->Transform(&vbRes);
|
||||
|
||||
VARIANT var;
|
||||
var.punkVal = NULL;
|
||||
pTransform->GetResult(0, &var);
|
||||
|
||||
if (NULL == var.punkVal)
|
||||
{
|
||||
RELEASEINTERFACE(pTransform);
|
||||
return;
|
||||
}
|
||||
|
||||
MediaCore::IAVSUncompressedVideoFrame* pFrame = NULL;
|
||||
var.punkVal->QueryInterface(MediaCore::IID_IAVSUncompressedVideoFrame, (void**)&pFrame);
|
||||
|
||||
RELEASEINTERFACE((var.punkVal));
|
||||
|
||||
if (NULL == pFrame)
|
||||
{
|
||||
RELEASEINTERFACE(pTransform);
|
||||
return;
|
||||
}
|
||||
|
||||
LONG lWidth = 0;
|
||||
LONG lHeight = 0;
|
||||
pFrame->get_Width(&lWidth);
|
||||
pFrame->get_Height(&lHeight);
|
||||
|
||||
oInfo.m_eType = GetImageType(pFrame);
|
||||
|
||||
RELEASEINTERFACE(pFrame);
|
||||
|
||||
CString strSaveItem = _T("");
|
||||
strSaveItem.Format(_T("\\image%d."), oInfo.m_lID);
|
||||
if (itJPG == oInfo.m_eType)
|
||||
{
|
||||
strSaveItem = _T("<ImageFile-SaveAsJpeg destinationpath=\"") + m_strDstMedia + strSaveItem + _T("jpg\" format=\"888\"/>");
|
||||
}
|
||||
else
|
||||
{
|
||||
strSaveItem = _T("<ImageFile-SaveAsPng destinationpath=\"") + m_strDstMedia + strSaveItem + _T("png\" format=\"888\"/>");
|
||||
}
|
||||
|
||||
CString strXml = _T("");
|
||||
|
||||
LONG lMaxSize = min(max(lWidth, lHeight), m_lMaxSizeImage);
|
||||
|
||||
if ((lWidth <= lMaxSize) && (lHeight <= lMaxSize))
|
||||
{
|
||||
strXml = _T("<transforms>") + strSaveItem + _T("</transforms>");
|
||||
}
|
||||
else
|
||||
{
|
||||
LONG lW = 0;
|
||||
LONG lH = 0;
|
||||
double dAspect = (double)lWidth / lHeight;
|
||||
|
||||
if (lWidth >= lHeight)
|
||||
{
|
||||
lW = lMaxSize;
|
||||
lH = (LONG)((double)lW / dAspect);
|
||||
}
|
||||
else
|
||||
{
|
||||
lH = lMaxSize;
|
||||
lW = (LONG)(dAspect * lH);
|
||||
}
|
||||
|
||||
CString strResize = _T("");
|
||||
strResize.Format(_T("<ImageTransform-TransformResize type=\"65536\" width=\"%d\" height=\"%d\"/>"), lW, lH);
|
||||
|
||||
strXml = _T("<transforms>") + strResize + strSaveItem + _T("</transforms>");
|
||||
}
|
||||
|
||||
VARIANT_BOOL vbSuccess = VARIANT_FALSE;
|
||||
BSTR bsXml = strXml.AllocSysString();
|
||||
pTransform->SetXml(bsXml, &vbSuccess);
|
||||
SysFreeString(bsXml);
|
||||
|
||||
pTransform->Transform(&vbSuccess);
|
||||
|
||||
RELEASEINTERFACE(pTransform);
|
||||
}
|
||||
void SaveImage(IUnknown* punkImage, CImageInfo& oInfo, LONG __width, LONG __height)
|
||||
{
|
||||
MediaCore::IAVSUncompressedVideoFrame* pFrame = NULL;
|
||||
punkImage->QueryInterface(MediaCore::IID_IAVSUncompressedVideoFrame, (void**)&pFrame);
|
||||
|
||||
if (NULL == pFrame)
|
||||
return;
|
||||
|
||||
LONG lWidth = 0;
|
||||
LONG lHeight = 0;
|
||||
pFrame->get_Width(&lWidth);
|
||||
pFrame->get_Height(&lHeight);
|
||||
|
||||
oInfo.m_eType = GetImageType(pFrame);
|
||||
|
||||
RELEASEINTERFACE(pFrame);
|
||||
|
||||
ImageStudio::IImageTransforms* pTransform = NULL;
|
||||
CoCreateInstance(ImageStudio::CLSID_ImageTransforms, NULL ,CLSCTX_INPROC_SERVER, ImageStudio::IID_IImageTransforms, (void**)&pTransform);
|
||||
|
||||
VARIANT var;
|
||||
var.vt = VT_UNKNOWN;
|
||||
var.punkVal = punkImage;
|
||||
pTransform->SetSource(0, var);
|
||||
|
||||
CString strSaveItem = _T("");
|
||||
strSaveItem.Format(_T("\\image%d."), oInfo.m_lID);
|
||||
if (itJPG == oInfo.m_eType)
|
||||
{
|
||||
strSaveItem = _T("<ImageFile-SaveAsJpeg destinationpath=\"") + m_strDstMedia + strSaveItem + _T("jpg\" format=\"888\"/>");
|
||||
}
|
||||
else
|
||||
{
|
||||
strSaveItem = _T("<ImageFile-SaveAsPng destinationpath=\"") + m_strDstMedia + strSaveItem + _T("png\" format=\"888\"/>");
|
||||
}
|
||||
|
||||
LONG lMaxSize = min(max(__width, __height), m_lMaxSizeImage);
|
||||
|
||||
CString strXml = _T("");
|
||||
if ((lWidth <= lMaxSize) && (lHeight <= lMaxSize))
|
||||
{
|
||||
strXml = _T("<transforms>") + strSaveItem + _T("</transforms>");
|
||||
}
|
||||
else
|
||||
{
|
||||
LONG lW = 0;
|
||||
LONG lH = 0;
|
||||
double dAspect = (double)lWidth / lHeight;
|
||||
|
||||
if (lWidth >= lHeight)
|
||||
{
|
||||
lW = lMaxSize;
|
||||
lH = (LONG)((double)lW / dAspect);
|
||||
}
|
||||
else
|
||||
{
|
||||
lH = lMaxSize;
|
||||
lW = (LONG)(dAspect * lH);
|
||||
}
|
||||
|
||||
CString strResize = _T("");
|
||||
strResize.Format(_T("<ImageTransform-TransformResize type=\"65536\" width=\"%d\" height=\"%d\"/>"), lW, lH);
|
||||
|
||||
strXml = _T("<transforms>") + strResize + strSaveItem + _T("</transforms>");
|
||||
}
|
||||
|
||||
VARIANT_BOOL vbSuccess = VARIANT_FALSE;
|
||||
BSTR bsXml = strXml.AllocSysString();
|
||||
pTransform->SetXml(bsXml, &vbSuccess);
|
||||
SysFreeString(bsXml);
|
||||
|
||||
pTransform->Transform(&vbSuccess);
|
||||
|
||||
RELEASEINTERFACE(pTransform);
|
||||
}
|
||||
#endif
|
||||
|
||||
CImageInfo GenerateImageID(IUnknown* punkData, double dWidth, double dHeight)
|
||||
{
|
||||
CImageInfo oInfo;
|
||||
|
||||
if (NULL == punkData)
|
||||
return oInfo;
|
||||
|
||||
LONG lWidth = (LONG)(dWidth * 96 / 25.4);
|
||||
LONG lHeight = (LONG)(dHeight * 96 / 25.4);
|
||||
|
||||
MediaCore::IAVSUncompressedVideoFrame* pFrame = NULL;
|
||||
punkData->QueryInterface(MediaCore::IID_IAVSUncompressedVideoFrame, (void**)&pFrame);
|
||||
|
||||
BYTE* pBuffer = NULL;
|
||||
LONG lLen = 0;
|
||||
|
||||
pFrame->get_Buffer(&pBuffer);
|
||||
pFrame->get_BufferSize(&lLen);
|
||||
|
||||
DWORD dwSum = m_oCRC.Calc(pBuffer, lLen);
|
||||
|
||||
CAtlMap<DWORD, CImageInfo>::CPair* pPair = m_mapImageData.Lookup(dwSum);
|
||||
if (NULL == pPair)
|
||||
{
|
||||
|
||||
++m_lNextIDImage;
|
||||
|
||||
oInfo.m_lID = m_lNextIDImage;
|
||||
SaveImage(punkData, oInfo, lWidth, lHeight);
|
||||
m_mapImageData.SetAt(dwSum, oInfo);
|
||||
m_listImages.AddTail(oInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
oInfo = pPair->m_value;
|
||||
}
|
||||
|
||||
RELEASEINTERFACE(pFrame);
|
||||
|
||||
return oInfo;
|
||||
}
|
||||
|
||||
CImageInfo GenerateImageID(CString& strFileName, double dWidth, double dHeight)
|
||||
{
|
||||
CImageInfo oInfo;
|
||||
CAtlMap<CString, CImageInfo>::CPair* pPair = m_mapImagesFile.Lookup(strFileName);
|
||||
|
||||
LONG lWidth = (LONG)(dWidth * 96 / 25.4);
|
||||
LONG lHeight = (LONG)(dHeight * 96 / 25.4);
|
||||
|
||||
if (NULL == pPair)
|
||||
{
|
||||
#ifdef BUILD_CONFIG_FULL_VERSION
|
||||
LONG lImageType = m_oExt.GetImageType(strFileName);
|
||||
|
||||
if (1 == lImageType || 2 == lImageType)
|
||||
{
|
||||
++m_lNextIDImage;
|
||||
oInfo.m_lID = m_lNextIDImage;
|
||||
oInfo.m_eType = (1 == lImageType) ? itWMF : itEMF;
|
||||
|
||||
CString strSaveItem = _T("");
|
||||
strSaveItem.Format(_T("\\image%d."), oInfo.m_lID);
|
||||
strSaveItem = m_strDstMedia + strSaveItem;
|
||||
|
||||
double dKoef = 100 * 96 / 25.4;
|
||||
bool bIsSuccess = m_oExt.Convert(strFileName, LONG(dWidth * dKoef), LONG(dHeight * dKoef), strSaveItem + _T("svg"));
|
||||
if (bIsSuccess)
|
||||
{
|
||||
if (itWMF == lImageType)
|
||||
{
|
||||
CDirectory::CopyFile(strFileName, strSaveItem + _T("wmf"), NULL, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
CDirectory::CopyFile(strFileName, strSaveItem + _T("emf"), NULL, NULL);
|
||||
}
|
||||
|
||||
m_mapImagesFile.SetAt(strFileName, oInfo);
|
||||
m_listImages.AddTail(oInfo);
|
||||
return oInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
--m_lNextIDImage;
|
||||
oInfo.m_eType = itJPG;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
++m_lNextIDImage;
|
||||
|
||||
oInfo.m_lID = m_lNextIDImage;
|
||||
SaveImage(strFileName, oInfo, lWidth, lHeight);
|
||||
m_mapImagesFile.SetAt(strFileName, oInfo);
|
||||
m_listImages.AddTail(oInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
oInfo = pPair->m_value;
|
||||
}
|
||||
|
||||
return oInfo;
|
||||
}
|
||||
|
||||
CImageInfo GenerateImageID_2(CString& strFileName, CString& strUrl, double dWidth, double dHeight)
|
||||
{
|
||||
CImageInfo oInfo;
|
||||
LONG lWidth = (LONG)(dWidth * 96 / 25.4);
|
||||
LONG lHeight = (LONG)(dHeight * 96 / 25.4);
|
||||
|
||||
#ifdef BUILD_CONFIG_FULL_VERSION
|
||||
LONG lImageType = m_oExt.GetImageType(strFileName);
|
||||
|
||||
if (1 == lImageType || 2 == lImageType)
|
||||
{
|
||||
++m_lNextIDImage;
|
||||
oInfo.m_lID = m_lNextIDImage;
|
||||
oInfo.m_eType = (1 == lImageType) ? itWMF : itEMF;
|
||||
|
||||
CString strSaveItem = _T("");
|
||||
strSaveItem.Format(_T("\\image%d."), oInfo.m_lID);
|
||||
strSaveItem = m_strDstMedia + strSaveItem;
|
||||
|
||||
double dKoef = 100 * 96 / 25.4;
|
||||
bool bIsSuccess = m_oExt.Convert(strFileName, LONG(dWidth * dKoef), LONG(dHeight * dKoef), strSaveItem + _T("svg"));
|
||||
if (bIsSuccess)
|
||||
{
|
||||
if (itWMF == lImageType)
|
||||
{
|
||||
CDirectory::CopyFile(strFileName, strSaveItem + _T("wmf"), NULL, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
CDirectory::CopyFile(strFileName, strSaveItem + _T("emf"), NULL, NULL);
|
||||
}
|
||||
m_mapImagesFile.SetAt(strFileName, oInfo);
|
||||
m_listImages.AddTail(oInfo);
|
||||
return oInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
--m_lNextIDImage;
|
||||
oInfo.m_eType = itJPG;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
++m_lNextIDImage;
|
||||
|
||||
oInfo.m_lID = m_lNextIDImage;
|
||||
SaveImage(strFileName, oInfo, lWidth, lHeight);
|
||||
m_mapImagesFile.SetAt(strUrl, oInfo);
|
||||
m_listImages.AddTail(oInfo);
|
||||
|
||||
return oInfo;
|
||||
}
|
||||
|
||||
ImageType GetImageType(MediaCore::IAVSUncompressedVideoFrame* pFrame)
|
||||
{
|
||||
if (2 == m_lDstFormat)
|
||||
return itJPG;
|
||||
|
||||
LONG lWidth = 0;
|
||||
LONG lHeight = 0;
|
||||
BYTE* pBuffer = NULL;
|
||||
|
||||
pFrame->get_Width(&lWidth);
|
||||
pFrame->get_Height(&lHeight);
|
||||
pFrame->get_Buffer(&pBuffer);
|
||||
|
||||
BYTE* pBufferMem = pBuffer + 3;
|
||||
LONG lCountPix = lWidth * lHeight;
|
||||
|
||||
for (LONG i = 0; i < lCountPix; ++i, pBufferMem += 4)
|
||||
{
|
||||
if (255 != *pBufferMem)
|
||||
return itPNG;
|
||||
}
|
||||
return itJPG;
|
||||
}
|
||||
|
||||
void FlipY(IUnknown* punkImage)
|
||||
{
|
||||
if (NULL == punkImage)
|
||||
return;
|
||||
|
||||
MediaCore::IAVSUncompressedVideoFrame* pFrame = NULL;
|
||||
punkImage->QueryInterface(MediaCore::IID_IAVSUncompressedVideoFrame, (void**)&pFrame);
|
||||
|
||||
if (NULL == pFrame)
|
||||
return;
|
||||
|
||||
BYTE* pBuffer = NULL;
|
||||
LONG lWidth = 0;
|
||||
LONG lHeight = 0;
|
||||
LONG lStride = 0;
|
||||
|
||||
pFrame->get_Buffer(&pBuffer);
|
||||
pFrame->get_Width(&lWidth);
|
||||
pFrame->get_Height(&lHeight);
|
||||
pFrame->get_Stride(0, &lStride);
|
||||
|
||||
if (lStride < 0)
|
||||
lStride = -lStride;
|
||||
|
||||
if ((lWidth * 4) != lStride)
|
||||
{
|
||||
RELEASEINTERFACE(pFrame);
|
||||
return;
|
||||
}
|
||||
|
||||
BYTE* pBufferMem = new BYTE[lStride];
|
||||
|
||||
BYTE* pBufferEnd = pBuffer + lStride * (lHeight - 1);
|
||||
|
||||
LONG lCountV = lHeight / 2;
|
||||
|
||||
for (LONG lIndexV = 0; lIndexV < lCountV; ++lIndexV)
|
||||
{
|
||||
memcpy(pBufferMem, pBuffer, lStride);
|
||||
memcpy(pBuffer, pBufferEnd, lStride);
|
||||
memcpy(pBufferEnd, pBufferMem, lStride);
|
||||
|
||||
pBuffer += lStride;
|
||||
pBufferEnd -= lStride;
|
||||
}
|
||||
|
||||
RELEASEARRAYOBJECTS(pBufferMem);
|
||||
RELEASEINTERFACE(pFrame);
|
||||
}
|
||||
|
||||
void FlipX(IUnknown* punkImage)
|
||||
{
|
||||
if (NULL == punkImage)
|
||||
return;
|
||||
|
||||
MediaCore::IAVSUncompressedVideoFrame* pFrame = NULL;
|
||||
punkImage->QueryInterface(MediaCore::IID_IAVSUncompressedVideoFrame, (void**)&pFrame);
|
||||
|
||||
if (NULL == pFrame)
|
||||
return;
|
||||
|
||||
BYTE* pBuffer = NULL;
|
||||
LONG lWidth = 0;
|
||||
LONG lHeight = 0;
|
||||
LONG lStride = 0;
|
||||
|
||||
pFrame->get_Buffer(&pBuffer);
|
||||
pFrame->get_Width(&lWidth);
|
||||
pFrame->get_Height(&lHeight);
|
||||
pFrame->get_Stride(0, &lStride);
|
||||
|
||||
if (lStride < 0)
|
||||
lStride = -lStride;
|
||||
|
||||
if ((lWidth * 4) != lStride)
|
||||
{
|
||||
RELEASEINTERFACE(pFrame);
|
||||
return;
|
||||
}
|
||||
|
||||
DWORD* pBufferDWORD = (DWORD*)pBuffer;
|
||||
|
||||
LONG lW2 = lWidth / 2;
|
||||
for (LONG lIndexV = 0; lIndexV < lHeight; ++lIndexV)
|
||||
{
|
||||
DWORD* pMem1 = pBufferDWORD;
|
||||
DWORD* pMem2 = pBufferDWORD + lWidth - 1;
|
||||
|
||||
LONG lI = 0;
|
||||
while (lI < lW2)
|
||||
{
|
||||
DWORD dwMem = *pMem1;
|
||||
*pMem1++ = *pMem2;
|
||||
*pMem2-- = dwMem;
|
||||
}
|
||||
}
|
||||
|
||||
RELEASEINTERFACE(pFrame);
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user