Commit 29a58ecf authored by Sergey.Konovalov's avatar Sergey.Konovalov Committed by Alexander Trofimov

CDrawingConverter::GetThemeBinary возврашает массив byte*, theme надо писать в...

CDrawingConverter::GetThemeBinary возврашает массив byte*, theme надо писать в начале, а в docx и xlsx хотелось в конце.

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@58435 954022d7-b5bf-4e40-9824-e11837661b57
parent b0be73c0
......@@ -392,6 +392,12 @@ namespace BinDocxRW
m_oStream.WriteBYTEArray((BYTE *)pBinaryObj->pvData, pBinaryObj->rgsabound[0].cElements);
WriteItemWithLengthEnd(nCurPos);
}
void WriteBytesArray(BYTE* pData, long nDataSize)
{
int nCurPos = WriteItemWithLengthStart();
m_oStream.WriteBYTEArray(pData, nDataSize);
WriteItemWithLengthEnd(nCurPos);
}
};
class BinaryHeaderFooterTableWriter
......@@ -2362,10 +2368,11 @@ namespace BinDocxRW
}
};
BinaryCommonWriter m_oBcw;
OOX::CTheme* m_pTheme;
BYTE* m_pThemeData;
long m_nThemeDataSize;
ParamsWriter& m_oParamsWriter;
public:
BinaryOtherTableWriter(ParamsWriter& oParamsWriter, OOX::CTheme* pTheme):m_oParamsWriter(oParamsWriter),m_oBcw(oParamsWriter),m_pTheme(pTheme)
BinaryOtherTableWriter(ParamsWriter& oParamsWriter, BYTE* pThemeData, long nThemeDataSize):m_oParamsWriter(oParamsWriter),m_oBcw(oParamsWriter),m_pThemeData(pThemeData),m_nThemeDataSize(nThemeDataSize)
{
};
void Write()
......@@ -2388,11 +2395,10 @@ namespace BinDocxRW
m_oBcw.m_pEmbeddedFontsManager->WriteEmbeddedFonts<EmbeddedBinaryWriter>(&oEmbeddedBinaryWriter);
m_oBcw.WriteItemEnd(nStart);
}
if(NULL != m_pTheme)
if(NULL != m_pThemeData)
{
int nStart = m_oBcw.WriteItemStart(c_oSerOtherTableTypes::DocxTheme);
m_oParamsWriter.m_pOfficeDrawingConverter->GetThemeBinary(m_pTheme->m_oReadPath.GetPath());
m_oBcw.WriteItemEnd(nStart);
m_oBcw.m_oStream.WriteBYTE(c_oSerOtherTableTypes::DocxTheme);
m_oBcw.WriteBytesArray(m_pThemeData, m_nThemeDataSize);
}
};
//void WriteImageMapContent()
......@@ -6135,11 +6141,11 @@ namespace BinDocxRW
oBinarySigTableWriter.Write();
WriteTableEnd(nCurPos);
}
void WriteMainTableEnd(OOX::CTheme* pTheme)
void WriteMainTableEnd(BYTE* pThemeData, long& nThemeDataSize)
{
//OtherTable
int nCurPos = WriteTableStart(c_oSerTableTypes::Other);
BinaryOtherTableWriter oBinaryOtherTableWriter(m_oParamsWriter, pTheme);
BinaryOtherTableWriter oBinaryOtherTableWriter(m_oParamsWriter, pThemeData, nThemeDataSize);
oBinaryOtherTableWriter.Write();
WriteTableEnd(nCurPos);
......@@ -6192,6 +6198,11 @@ namespace BinDocxRW
this->WriteMainTableStart();
int nCurPos = 0;
// Theme ClrMap, rgb
BYTE* pThemeData = NULL;
long nThemeDataSize = 0;
if(NULL != m_oParamsWriter.m_poTheme)
m_oParamsWriter.m_pOfficeDrawingConverter->GetThemeBinary(&pThemeData, nThemeDataSize, m_oParamsWriter.m_poTheme->m_oReadPath.GetPath());
//Write Settings
OOX::CSettings* pSettings = oDocx.GetSettings();
......@@ -6255,7 +6266,8 @@ namespace BinDocxRW
oBinaryHeaderFooterTableWriter.Write();
this->WriteTableEnd(nCurPos);
this->WriteMainTableEnd(m_oParamsWriter.m_poTheme);
this->WriteMainTableEnd(pThemeData, nThemeDataSize);
RELEASEARRAYOBJECTS(pThemeData);
}
void ParagraphAddBreak(OOX::Logic::CParagraph* pParagraph)
{
......
......@@ -3025,8 +3025,10 @@ void CDrawingConverter::CheckPenShape(PPTX::Logic::SpTreeElem& oElem, XmlUtils::
}
}
HRESULT CDrawingConverter::GetThemeBinary(CString& bsThemeFilePath)
HRESULT CDrawingConverter::GetThemeBinary(BYTE** ppBinary, long& lBinarySize, CString& bsThemeFilePath)
{
if(NULL == ppBinary)
return S_FALSE;
CString strOldRels = m_strCurrentRelsPath;
m_strCurrentRelsPath = bsThemeFilePath;
......@@ -3037,11 +3039,18 @@ HRESULT CDrawingConverter::GetThemeBinary(CString& bsThemeFilePath)
smart_ptr<PPTX::Theme> pTheme = new PPTX::Theme(oPath, oFileMap);
//m_pBinaryWriter->ClearNoAttack();
//ULONG lOldPos = m_pBinaryWriter->GetPosition();
ULONG lOldPos = m_pBinaryWriter->GetPosition();
m_pBinaryWriter->m_pCommon->CheckFontPicker();
pTheme->toPPTY(m_pBinaryWriter);
//m_pBinaryWriter->SetPosition(lOldPos);
lBinarySize = m_pBinaryWriter->GetPosition() - lOldPos;
*ppBinary = new BYTE[lBinarySize];
BYTE* pDataD = *ppBinary;
BYTE* pDataS = m_pBinaryWriter->GetBuffer() + lOldPos;
memcpy(pDataD, pDataS, lBinarySize);
m_pBinaryWriter->SetPosition(lOldPos);
*m_pBinaryWriter->ThemeDoc = pTheme.smart_dynamic_cast<PPTX::FileContainer>();
//m_pBinaryWriter->ThemeDoc.reset();
......
......@@ -175,7 +175,7 @@ namespace NSBinPptxRW
STDMETHOD(AddShapeType)(CString& bsXml);
STDMETHOD(AddObject)(CString& bsXml, CString** pMainProps);
STDMETHOD(GetThemeBinary)(CString& bsThemeFilePath);
STDMETHOD(GetThemeBinary)(BYTE** ppBinary, long& lBinarySize, CString& bsThemeFilePath);
STDMETHOD(SaveThemeXml)(LONG lStart, LONG lLength, CString& bsThemePath);
STDMETHOD(SaveObject)(LONG lStart, LONG lLength, CString& bsMainProps, CString** bsXml);
......
......@@ -3165,10 +3165,11 @@ namespace BinXlsxRW {
};
BinaryCommonWriter m_oBcw;
NSFontCutter::CEmbeddedFontsManager* m_pEmbeddedFontsManager;
OOX::CTheme* m_pTheme;
BYTE* m_pThemeData;
long m_nThemeDataSize;
NSBinPptxRW::CDrawingConverter* m_pOfficeDrawingConverter;
public:
BinaryOtherTableWriter(NSBinPptxRW::CBinaryFileWriter &oCBufferedStream, NSFontCutter::CEmbeddedFontsManager* pEmbeddedFontsManager, OOX::CTheme* pTheme, NSBinPptxRW::CDrawingConverter* pOfficeDrawingConverter):m_oBcw(oCBufferedStream),m_pEmbeddedFontsManager(pEmbeddedFontsManager),m_pTheme(pTheme),m_pOfficeDrawingConverter(pOfficeDrawingConverter)
BinaryOtherTableWriter(NSBinPptxRW::CBinaryFileWriter &oCBufferedStream, NSFontCutter::CEmbeddedFontsManager* pEmbeddedFontsManager, BYTE* pThemeData, long nThemeDataSize, NSBinPptxRW::CDrawingConverter* pOfficeDrawingConverter):m_oBcw(oCBufferedStream),m_pEmbeddedFontsManager(pEmbeddedFontsManager),m_pThemeData(pThemeData),m_nThemeDataSize(nThemeDataSize),m_pOfficeDrawingConverter(pOfficeDrawingConverter)
{
};
void Write()
......@@ -3189,43 +3190,12 @@ namespace BinXlsxRW {
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
//Theme
if(NULL != m_pTheme)
if(NULL != m_pThemeData)
{
m_oBcw.m_oStream.WriteBYTE(c_oSer_OtherType::Theme);
nCurPos = m_oBcw.WriteItemWithLengthStart();
#ifdef DEFAULT_TABLE_STYLES
long nThemeStartPos = m_oBcw.m_oStream.GetPosition();
#endif
m_pOfficeDrawingConverter->GetThemeBinary(m_pTheme->m_oReadPath.GetPath());
#ifdef DEFAULT_TABLE_STYLES
long nThemeLength = m_oBcw.m_oStream.GetPosition() - nThemeStartPos;
writeTheme(m_oBcw.m_oStream.GetBuffer(), nThemeStartPos, nThemeLength, CString(_T("c:\\defaultTheme.bin")));
#endif
m_oBcw.WriteItemWithLengthEnd(nCurPos);
m_oBcw.WriteBytesArray(m_pThemeData, m_nThemeDataSize);
}
};
#ifdef DEFAULT_TABLE_STYLES
CString WriteDefaultFileHeader(int nDataSize)
{
CString sHeader;
sHeader.Format(_T("%s;;%d;"), g_sFormatSignature, nDataSize);
return sHeader;
}
void writeTheme(BYTE* pData, long nStart, long nLength, CString& sFileOutput)
{
int nBase64BufferLen = Base64::Base64EncodeGetRequiredLength(nLength, Base64::B64_BASE64_FLAG_NOCRLF);
BYTE* pbBase64Buffer = new BYTE[nBase64BufferLen];
if(TRUE == Base64::Base64Encode(pData + nStart, nLength, (LPSTR)pbBase64Buffer, &nBase64BufferLen, Base64::B64_BASE64_FLAG_NOCRLF))
{
CFile oFile;
oFile.CreateFileW(sFileOutput);
oFile.WriteStringUTF8(WriteDefaultFileHeader(nLength));
oFile.WriteFile(pbBase64Buffer, nBase64BufferLen);
oFile.CloseFile();
}
RELEASEARRAYOBJECTS(pbBase64Buffer);
}
#endif
};
class BinaryFileWriter {
private:
......@@ -3313,7 +3283,16 @@ namespace BinXlsxRW {
OOX::Spreadsheet::CIndexedColors* pIndexedColors = NULL;
if(NULL != pStyle && pStyle->m_oColors.IsInit() && pStyle->m_oColors->m_oIndexedColors.IsInit())
pIndexedColors = pStyle->m_oColors->m_oIndexedColors.operator ->();
// Theme ClrMap, rgb
OOX::CTheme* pTheme = oXlsx.GetTheme();
BYTE* pThemeData = NULL;
long nThemeDataSize = 0;
if(NULL != pTheme)
pOfficeDrawingConverter->GetThemeBinary(&pThemeData, nThemeDataSize, oXlsx.GetTheme()->m_oReadPath.GetPath());
#ifdef DEFAULT_TABLE_STYLES
writeTheme(pThemeData, nThemeDataSize, CString(_T("c:\\defaultTheme.bin")));
getDefaultCellStyles(CString(_T("D:\\Projects\\AVS\\Sources\\TeamlabOffice\\trunk\\ServerComponents\\XlsxSerializerCom\\XlsxDefaults\\presetCellStylesNew.xml")), CString(_T("C:\\presetCellStyles_output.bin")), pEmbeddedFontsManager, pIndexedColors, oXlsx.GetTheme(), m_oFontProcessor);
getDefaultTableStyles(CString(_T("D:\\Projects\\AVS\\Sources\\TeamlabOffice\\trunk\\ServerComponents\\XlsxSerializerCom\\XlsxDefaults\\presetTableStyles.xml")), CString(_T("C:\\presetTableStyles_output.bin")), pEmbeddedFontsManager, pIndexedColors, oXlsx.GetTheme(), m_oFontProcessor);
#endif
......@@ -3358,16 +3337,14 @@ namespace BinXlsxRW {
WriteTableEnd(nCurPos);
}
//theme data
OOX::CTheme* pTheme = oXlsx.GetTheme();
//OtherTable
nCurPos = WriteTableStart(c_oSerTableTypes::Other);
BinaryOtherTableWriter oBinaryOtherTableWriter(oBufferedStream, pEmbeddedFontsManager, pTheme, pOfficeDrawingConverter);
BinaryOtherTableWriter oBinaryOtherTableWriter(oBufferedStream, pEmbeddedFontsManager, pThemeData, nThemeDataSize, pOfficeDrawingConverter);
oBinaryOtherTableWriter.Write();
WriteTableEnd(nCurPos);
WriteMainTableEnd();
RELEASEARRAYOBJECTS(pThemeData);
}
CString WriteFileHeader(int nDataSize)
{
......@@ -3427,6 +3404,20 @@ namespace BinXlsxRW {
sHeader.Format(_T("%s;;%d;"), g_sFormatSignature, nDataSize);
return sHeader;
}
void writeTheme(BYTE* pData, long nLength, CString& sFileOutput)
{
int nBase64BufferLen = Base64::Base64EncodeGetRequiredLength(nLength, Base64::B64_BASE64_FLAG_NOCRLF);
BYTE* pbBase64Buffer = new BYTE[nBase64BufferLen];
if(TRUE == Base64::Base64Encode(pData, nLength, (LPSTR)pbBase64Buffer, &nBase64BufferLen, Base64::B64_BASE64_FLAG_NOCRLF))
{
CFile oFile;
oFile.CreateFileW(sFileOutput);
oFile.WriteStringUTF8(WriteDefaultFileHeader(nLength));
oFile.WriteFile(pbBase64Buffer, nBase64BufferLen);
oFile.CloseFile();
}
RELEASEARRAYOBJECTS(pbBase64Buffer);
}
void getDefaultCellStyles(CString& sFileInput, CString& sFileOutput, NSFontCutter::CEmbeddedFontsManager* pEmbeddedFontsManager, OOX::Spreadsheet::CIndexedColors* oIndexedColors, OOX::CTheme* pTheme, BinXlsxRW::FontProcessor& oFontProcessor)
{
enum Types
......
......@@ -6061,10 +6061,12 @@ namespace BinXlsxRW{
if (pFile.IsInit() && OOX::FileTypes::ThemeOverride == pFile->type())
{
OOX::CThemeOverride* pThemeOverride = static_cast<OOX::CThemeOverride*>(pFile.operator->());
BYTE* pThemeData = NULL;
long nThemeDataSize = 0;
m_pOfficeDrawingConverter->GetThemeBinary(&pThemeData, nThemeDataSize, pThemeOverride->m_oReadPath.GetPath());
m_oBcw.m_oStream.WriteBYTE(c_oserct_chartspaceTHEMEOVERRIDE);
int nCurPos = m_oBcw.WriteItemWithLengthStart();
m_pOfficeDrawingConverter->GetThemeBinary(pThemeOverride->m_oReadPath.GetPath());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
m_oBcw.WriteBytesArray(pThemeData, nThemeDataSize);
RELEASEARRAYOBJECTS(pThemeData);
}
}
void BinaryChartWriter::WriteCT_Boolean(CT_Boolean& oVal)
......
......@@ -102,4 +102,10 @@ namespace BinXlsxRW {
m_oStream.WriteBYTEArray((BYTE *)pBinaryObj->pvData, pBinaryObj->rgsabound[0].cElements);
WriteItemWithLengthEnd(nCurPos);
}
void BinaryCommonWriter::WriteBytesArray(BYTE* pData, long nDataSize)
{
int nCurPos = WriteItemWithLengthStart();
m_oStream.WriteBYTEArray(pData, nDataSize);
WriteItemWithLengthEnd(nCurPos);
}
}
\ No newline at end of file
......@@ -16,6 +16,7 @@ namespace BinXlsxRW {
void WriteItemWithLengthEnd(int nStart);
void WriteColor(const OOX::Spreadsheet::CColor& color, OOX::Spreadsheet::CIndexedColors* pIndexedColors, OOX::CTheme* theme);
void WriteSafeArray(SAFEARRAY* pBinaryObj);
void WriteBytesArray(BYTE* pData, long nDataSize);
};
}
#endif // #ifndef COMMON_WRITER
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment