This commit is contained in:
Elena.Subbotina
2023-07-24 09:51:17 +03:00
parent f10c620ddb
commit fa2595612e
2 changed files with 70 additions and 79 deletions

View File

@ -112,7 +112,7 @@ namespace PPTX
XmlMacroReadAttributeBase(node, L"cstate", cstate); XmlMacroReadAttributeBase(node, L"cstate", cstate);
Effects.clear(); Effects.clear();
XmlMacroLoadArray(node, _T("*"), Effects, UniEffect); XmlMacroLoadArray(node, L"*", Effects, UniEffect);
FillParentPointersForChilds(); FillParentPointersForChilds();
} }
@ -121,15 +121,15 @@ namespace PPTX
XmlUtils::CAttribute oAttr; XmlUtils::CAttribute oAttr;
if (embed.IsInit()) if (embed.IsInit())
oAttr.Write(_T("r:embed"), embed->ToString()); oAttr.Write(L"r:embed", embed->ToString());
if (link.IsInit()) if (link.IsInit())
oAttr.Write(_T("r:link"), link->ToString()); oAttr.Write(L"r:link", link->ToString());
oAttr.WriteLimitNullable(_T("cstate"), cstate); oAttr.WriteLimitNullable(L"cstate", cstate);
XmlUtils::CNodeValue oValue; XmlUtils::CNodeValue oValue;
oValue.WriteArray(Effects); oValue.WriteArray(Effects);
std::wstring strName = (_T("") == m_namespace) ? _T("blip") : (m_namespace + _T(":blip")); std::wstring strName = m_namespace.empty() ? L"blip" : m_namespace + L":blip";
return XmlUtils::CreateNode(strName, oAttr, oValue); return XmlUtils::CreateNode(strName, oAttr, oValue);
} }
void Blip::FillParentPointersForChilds() void Blip::FillParentPointersForChilds()
@ -152,7 +152,7 @@ namespace PPTX
if(parentFileIs<FileContainer>()) if(parentFileIs<FileContainer>())
return parentFileAs<FileContainer>().GetImagePathNameFromRId(*embed); return parentFileAs<FileContainer>().GetImagePathNameFromRId(*embed);
return _T(""); return L"";
} }
else if(link.IsInit()) else if(link.IsInit())
{ {
@ -166,9 +166,9 @@ namespace PPTX
if(parentFileIs<FileContainer>()) if(parentFileIs<FileContainer>())
return parentFileAs<FileContainer>().GetImagePathNameFromRId(*link); return parentFileAs<FileContainer>().GetImagePathNameFromRId(*link);
return _T(""); return L"";
} }
return _T(""); return L"";
} }
std::wstring Blip::GetFullOleName(const OOX::RId& oRId, OOX::IFileContainer* pRels)const std::wstring Blip::GetFullOleName(const OOX::RId& oRId, OOX::IFileContainer* pRels)const
{ {
@ -190,15 +190,15 @@ namespace PPTX
} }
void Blip::toXmlWriter(NSBinPptxRW::CXmlWriter* pWriter) const void Blip::toXmlWriter(NSBinPptxRW::CXmlWriter* pWriter) const
{ {
std::wstring strName = (_T("") == m_namespace) ? _T("blip") : (m_namespace + _T(":blip")); std::wstring strName = m_namespace.empty() ? L"blip" : (m_namespace + L":blip");
pWriter->StartNode(strName); pWriter->StartNode(strName);
pWriter->StartAttributes(); pWriter->StartAttributes();
if (embed.IsInit()) if (embed.IsInit())
pWriter->WriteAttribute(_T("r:embed"), embed->ToString()); pWriter->WriteAttribute(L"r:embed", embed->ToString());
if (link.IsInit()) if (link.IsInit())
pWriter->WriteAttribute(_T("r:link"), link->ToString()); pWriter->WriteAttribute(L"r:link", link->ToString());
pWriter->WriteAttribute(_T("cstate"), cstate); pWriter->WriteAttribute(L"cstate", cstate);
pWriter->EndAttributes(); pWriter->EndAttributes();
size_t nCount = Effects.size(); size_t nCount = Effects.size();
@ -348,23 +348,21 @@ namespace PPTX
pReader->Skip(6); // len + start attributes + type pReader->Skip(6); // len + start attributes + type
std::wstring strImagePath = pReader->GetString2(true); std::wstring strImagePath = pReader->GetString2(true);
bool bIsTheme = false;
if (0 != strImagePath.find(_T("http:")) && if (0 != strImagePath.find(L"http:") &&
0 != strImagePath.find(_T("https:")) && 0 != strImagePath.find(L"https:") &&
0 != strImagePath.find(_T("ftp:")) && 0 != strImagePath.find(L"ftp:") &&
0 != strImagePath.find(_T("file:"))) 0 != strImagePath.find(L"file:"))
{ {
OOX::CPath pathNormalizer; OOX::CPath pathNormalizer;
if (0 == strImagePath.find(_T("theme"))) if (0 == strImagePath.find(L"theme"))
{ {
pathNormalizer = pReader->m_strFolderExternalThemes; pathNormalizer = pReader->m_strFolderExternalThemes;
bIsTheme = true;
} }
else else
{ {
pathNormalizer = pReader->m_strFolder + FILE_SEPARATOR_STR + _T("media"); pathNormalizer = pReader->m_strFolder + FILE_SEPARATOR_STR + L"media";
} }
std::wstring strPath = pathNormalizer.GetPath(); std::wstring strPath = pathNormalizer.GetPath();
@ -373,7 +371,7 @@ namespace PPTX
pathNormalizer = strImagePath; pathNormalizer = strImagePath;
strImagePath = pathNormalizer.GetPath(); strImagePath = pathNormalizer.GetPath();
if (!bIsTheme && std::wstring::npos != strImagePath.find(strPath)) if (std::wstring::npos != strImagePath.find(strPath))
{ {
CImageFileFormatChecker checker; CImageFileFormatChecker checker;
if (false == checker.isImageFile(strImagePath)) if (false == checker.isImageFile(strImagePath))

View File

@ -70,8 +70,8 @@ namespace PPTX
void BlipFill::ReadAttributes(XmlUtils::CXmlLiteReader& oReader) void BlipFill::ReadAttributes(XmlUtils::CXmlLiteReader& oReader)
{ {
WritingElement_ReadAttributes_Start_No_NS (oReader ) WritingElement_ReadAttributes_Start_No_NS (oReader )
WritingElement_ReadAttributes_Read_if ( oReader, _T("dpi"), dpi) WritingElement_ReadAttributes_Read_if ( oReader, L"dpi", dpi)
WritingElement_ReadAttributes_Read_else_if ( oReader, _T("rotWithShape"), rotWithShape ) WritingElement_ReadAttributes_Read_else_if ( oReader, L"rotWithShape", rotWithShape )
WritingElement_ReadAttributes_End_No_NS ( oReader ) WritingElement_ReadAttributes_End_No_NS ( oReader )
} }
void BlipFill::FillParentPointersForChilds() void BlipFill::FillParentPointersForChilds()
@ -102,13 +102,13 @@ namespace PPTX
while( oReader.ReadNextSiblingNode( nCurDepth ) ) while( oReader.ReadNextSiblingNode( nCurDepth ) )
{ {
std::wstring strName = XmlUtils::GetNameNoNS(oReader.GetName()); std::wstring strName = XmlUtils::GetNameNoNS(oReader.GetName());
if (_T("blip") == strName) if (L"blip" == strName)
blip = oReader; blip = oReader;
else if (_T("srcRect") == strName) else if (L"srcRect" == strName)
srcRect = oReader; srcRect = oReader;
else if (_T("tile") == strName) else if (L"tile" == strName)
tile = oReader; tile = oReader;
else if (_T("stretch") == strName) else if (L"stretch" == strName)
stretch = oReader; stretch = oReader;
} }
} }
@ -120,7 +120,7 @@ namespace PPTX
XmlMacroReadAttributeBase(node, L"rotWithShape", rotWithShape); XmlMacroReadAttributeBase(node, L"rotWithShape", rotWithShape);
std::vector<XmlUtils::CXmlNode> oNodes; std::vector<XmlUtils::CXmlNode> oNodes;
if (node.GetNodes(_T("*"), oNodes)) if (node.GetNodes(L"*", oNodes))
{ {
size_t nCount = oNodes.size(); size_t nCount = oNodes.size();
for (size_t i = 0; i < nCount; ++i) for (size_t i = 0; i < nCount; ++i)
@ -128,22 +128,22 @@ namespace PPTX
XmlUtils::CXmlNode& oNode = oNodes[i]; XmlUtils::CXmlNode& oNode = oNodes[i];
std::wstring strName = XmlUtils::GetNameNoNS(oNode.GetName()); std::wstring strName = XmlUtils::GetNameNoNS(oNode.GetName());
if (_T("blip") == strName) if (L"blip" == strName)
{ {
if (!blip.IsInit()) if (!blip.IsInit())
blip = oNode; blip = oNode;
} }
else if (_T("srcRect") == strName) else if (L"srcRect" == strName)
{ {
if (!srcRect.IsInit()) if (!srcRect.IsInit())
srcRect = oNode; srcRect = oNode;
} }
else if (_T("tile") == strName) else if (L"tile" == strName)
{ {
if (!tile.IsInit()) if (!tile.IsInit())
tile = oNode; tile = oNode;
} }
else if (_T("stretch") == strName) else if (L"stretch" == strName)
{ {
if (!stretch.IsInit()) if (!stretch.IsInit())
stretch = oNode; stretch = oNode;
@ -156,8 +156,8 @@ namespace PPTX
std::wstring BlipFill::toXML() const std::wstring BlipFill::toXML() const
{ {
XmlUtils::CAttribute oAttr; XmlUtils::CAttribute oAttr;
oAttr.Write(_T("dpi"), dpi); oAttr.Write(L"dpi", dpi);
oAttr.Write(_T("rotWithShape"), rotWithShape); oAttr.Write(L"rotWithShape", rotWithShape);
XmlUtils::CNodeValue oValue; XmlUtils::CNodeValue oValue;
oValue.WriteNullable(blip); oValue.WriteNullable(blip);
@ -165,33 +165,33 @@ namespace PPTX
oValue.WriteNullable(tile); oValue.WriteNullable(tile);
oValue.WriteNullable(stretch); oValue.WriteNullable(stretch);
std::wstring strName = (_T("") == m_namespace) ? _T("blipFill") : (m_namespace + _T(":blipFill")); std::wstring strName = m_namespace.empty() ? L"blipFill" : (m_namespace + L":blipFill");
return XmlUtils::CreateNode(strName, oAttr, oValue); return XmlUtils::CreateNode(strName, oAttr, oValue);
} }
void BlipFill::toXmlWriter(NSBinPptxRW::CXmlWriter* pWriter) const void BlipFill::toXmlWriter(NSBinPptxRW::CXmlWriter* pWriter) const
{ {
std::wstring strName = (_T("") == m_namespace) ? _T("blipFill") : (m_namespace + _T(":blipFill")); std::wstring strName = m_namespace.empty() ? L"blipFill" : (m_namespace + L":blipFill");
pWriter->StartNode(strName); pWriter->StartNode(strName);
pWriter->StartAttributes(); pWriter->StartAttributes();
pWriter->WriteAttribute(_T("dpi"), dpi); pWriter->WriteAttribute(L"dpi", dpi);
pWriter->WriteAttribute(_T("rotWithShape"), rotWithShape); pWriter->WriteAttribute(L"rotWithShape", rotWithShape);
pWriter->EndAttributes(); pWriter->EndAttributes();
pWriter->Write(blip); pWriter->Write(blip);
if (srcRect.is_init()) if (srcRect.is_init())
{ {
pWriter->StartNode(_T("a:srcRect")); pWriter->StartNode(L"a:srcRect");
pWriter->StartAttributes(); pWriter->StartAttributes();
pWriter->WriteAttribute(_T("l"), srcRect->l); pWriter->WriteAttribute(L"l", srcRect->l);
pWriter->WriteAttribute(_T("t"), srcRect->t); pWriter->WriteAttribute(L"t", srcRect->t);
pWriter->WriteAttribute(_T("r"), srcRect->r); pWriter->WriteAttribute(L"r", srcRect->r);
pWriter->WriteAttribute(_T("b"), srcRect->b); pWriter->WriteAttribute(L"b", srcRect->b);
pWriter->EndAttributes(); pWriter->EndAttributes();
pWriter->EndNode(_T("a:srcRect")); pWriter->EndNode(L"a:srcRect");
} }
pWriter->Write(tile); pWriter->Write(tile);
@ -315,31 +315,29 @@ namespace PPTX
std::wstring strOrigBase64; std::wstring strOrigBase64;
std::wstring strTempFile ; std::wstring strTempFile ;
bool bIsUrl = false;
bool bIsTheme = false;
if (!blip.is_init()) if (!blip.is_init())
blip = new PPTX::Logic::Blip(); blip = new PPTX::Logic::Blip();
if (0 == strImagePath.find(_T("data:"))) if (0 == strImagePath.find(L"data:"))
{ {
blip->dataFilepathImage = strImagePath; blip->dataFilepathImage = strImagePath;
bool bBase64 = false; bool bBase64 = false;
strOrigBase64 = strImagePath; strOrigBase64 = strImagePath;
int nFind = (int)strImagePath.find(_T(",")); size_t nFind = strImagePath.find(L",");
std::wstring sImageExtension; std::wstring sImageExtension;
std::wstring sFormatDataString = XmlUtils::GetLower(strImagePath.substr(5,nFind-5)); if (std::wstring::npos != nFind)
{ {
int nFind1 = (int)sFormatDataString.find(_T("base64")); std::wstring sFormatDataString = XmlUtils::GetLower(strImagePath.substr(5, nFind - 5));
if (nFind1 >=0 ) bBase64 = true; size_t nFind1 = sFormatDataString.find(L"base64");
if (std::wstring::npos != nFind1) bBase64 = true;
nFind1 = (int)sFormatDataString.find(_T("image/")); nFind1 = sFormatDataString.find(L"image/");
if (nFind1 >= 0) if (std::wstring::npos != nFind1)
{ {
int nFind2 = (int)sFormatDataString.find(_T(";")); int nFind2 = (int)sFormatDataString.find(L";");
if (nFind2 < 0) nFind2 = (int)sFormatDataString.length(); if (nFind2 < 0) nFind2 = (int)sFormatDataString.length();
sImageExtension = sFormatDataString.substr(nFind1 + 6, nFind2 - 6 - nFind1); sImageExtension = sFormatDataString.substr(nFind1 + 6, nFind2 - 6 - nFind1);
@ -348,7 +346,8 @@ namespace PPTX
strImagePath.erase(0, nFind + 1); strImagePath.erase(0, nFind + 1);
std::string __s = std::string(strImagePath.begin(), strImagePath.end()); std::string __s = std::string(strImagePath.begin(), strImagePath.end());
int len = (int)__s.length(); size_t len = __s.length();
BYTE* pDstBuffer = NULL; BYTE* pDstBuffer = NULL;
int dstLen = 0; int dstLen = 0;
@ -376,14 +375,14 @@ namespace PPTX
//папки media может не быть в случае, когда все картинки base64(поскольку файл временный, папку media не создаем) //папки media может не быть в случае, когда все картинки base64(поскольку файл временный, папку media не создаем)
std::wstring tempFilePath = pReader->m_strFolder + FILE_SEPARATOR_STR; std::wstring tempFilePath = pReader->m_strFolder + FILE_SEPARATOR_STR;
OOX::CPath pathTemp = NSFile::CFileBinary::CreateTempFileWithUniqueName(tempFilePath, _T("img")) + _T(".") + sImageExtension; OOX::CPath pathTemp = NSFile::CFileBinary::CreateTempFileWithUniqueName(tempFilePath, L"img") + L"." + sImageExtension;
NSFile::CFileBinary oTempFile; NSFile::CFileBinary oTempFile;
oTempFile.CreateFile(pathTemp.GetPath()); oTempFile.CreateFile(pathTemp.GetPath());
oTempFile.WriteFile((void*)pDstBuffer, (DWORD)dstLen); oTempFile.WriteFile((void*)pDstBuffer, (DWORD)dstLen);
oTempFile.CloseFile(); oTempFile.CloseFile();
strImagePath = strTempFile =pathTemp.GetPath(); // strTempFile для удаления strImagePath = strTempFile = pathTemp.GetPath(); // strTempFile для удаления
} }
else else
{// бяка {// бяка
@ -396,36 +395,30 @@ namespace PPTX
} }
else else
{ {
if (0 != strImagePath.find(_T("http:")) && if (0 != strImagePath.find(L"http:") &&
0 != strImagePath.find(_T("https:")) && 0 != strImagePath.find(L"https:") &&
0 != strImagePath.find(_T("ftp:")) && 0 != strImagePath.find(L"ftp:") &&
0 != strImagePath.find(_T("file:"))) 0 != strImagePath.find(L"file:"))
{ {
if (0 == strImagePath.find(_T("theme"))) if (0 == strImagePath.find(L"theme"))
{ {
strImagePath = pReader->m_strFolderExternalThemes + FILE_SEPARATOR_STR + strImagePath; strImagePath = pReader->m_strFolderExternalThemes + FILE_SEPARATOR_STR + strImagePath;
bIsTheme = true;
} }
else else
{ {
strImagePath = pReader->m_strFolder + FILE_SEPARATOR_STR + _T("media") + FILE_SEPARATOR_STR + strImagePath; strImagePath = pReader->m_strFolder + FILE_SEPARATOR_STR + L"media" + FILE_SEPARATOR_STR + strImagePath;
OOX::CPath pathUrl = strImagePath;
strImagePath = pathUrl.GetPath();
if (std::wstring::npos == strImagePath.find(pReader->m_strFolder))
{
strImagePath.clear();
}
} }
} }
else
bIsUrl = true;
}
// -------------------
//в случае url не надо нормализовать путь
if(!bIsUrl && !bIsTheme)
{
OOX::CPath pathUrl = strImagePath;
strImagePath = pathUrl.GetPath();
if (std::wstring::npos == strImagePath.find(pReader->m_strFolder))
{
strImagePath.clear();
}
} }
// -------------------
NSBinPptxRW::_relsGeneratorInfo oRelsGeneratorInfo = pReader->m_pRels->WriteImage(strImagePath, additionalFile, oleData, strOrigBase64); NSBinPptxRW::_relsGeneratorInfo oRelsGeneratorInfo = pReader->m_pRels->WriteImage(strImagePath, additionalFile, oleData, strOrigBase64);
// ------------------- // -------------------