Fixed bugs in hwpx conversion

This commit is contained in:
Green
2025-01-21 02:49:10 +03:00
parent 4324ea847c
commit 84042360ab
17 changed files with 331 additions and 177 deletions

View File

@ -37,6 +37,11 @@ void CWriterContext::Clear()
} }
} }
EHanType CWriterContext::GetType()
{
return m_eType;
}
VECTOR<const CHWPSection*> CWriterContext::GetSections() VECTOR<const CHWPSection*> CWriterContext::GetSections()
{ {
switch(m_eType) switch(m_eType)
@ -280,66 +285,57 @@ HWP_STRING CWriterContext::GetBinFilename(const HWP_STRING& sId)
return (nullptr != pBinData) ? pBinData->GetPath() : HWP_STRING(); return (nullptr != pBinData) ? pBinData->GetPath() : HWP_STRING();
} }
bool CWriterContext::GetBinBytes(const HWP_STRING& sId, CHWPStream& oBuffer, HWP_STRING& sFormat) bool CWriterContext::GetBinBytes(const HWP_STRING& sId, CHWPStream& oBuffer, HWP_STRING& sFileName)
{ {
const CHWPDocInfo* pDocInfo = nullptr; const CHWPDocInfo* pDocInfo = nullptr;
switch (m_eType) pDocInfo = GetDocInfo();
if (nullptr == pDocInfo)
return false;
const CHWPRecordBinData* pBinData = dynamic_cast<const CHWPRecordBinData*>(pDocInfo->GetBinData(sId));
if (nullptr == pBinData)
return false;
if (EType::LINK == pBinData->GetType())
{ {
case EHanType::HWP: switch (m_eType)
{ {
if (nullptr == m_pHWPFile) case EHanType::HWPX:
return false;
pDocInfo = m_pHWPFile->GetDocInfo();
if (nullptr == pDocInfo)
return false;
const CHWPRecordBinData* pBinData = dynamic_cast<const CHWPRecordBinData*>(pDocInfo->GetBinData(sId));
if (nullptr == pBinData)
return false;
if (EType::LINK == pBinData->GetType())
{ {
NSFile::CFileBinary oFile; sFileName = NSFile::GetFileName(pBinData->GetPath());
unsigned char *pBuffer = nullptr; return m_pHWPXFile->GetChildStream(pBinData->GetPath(), oBuffer);
unsigned long ulSize = 0;
oFile.ReadAllBytes(pBinData->GetPath(), &pBuffer, ulSize);
oBuffer.SetStream((HWP_BYTE*)pBuffer, ulSize, false);
sFormat = NSFile::GetFileExtention(pBinData->GetPath());
} }
else default:
{ return false;
std::wostringstream oStringStream; }
oStringStream << L"BIN" << std::setw(4) << std::setfill(L'0') << std::hex << pBinData->GetBinDataID() << L"." << pBinData->GetFormat(); }
sFormat = pBinData->GetFormat(); else
{
std::wostringstream oStringStream;
switch (m_eType)
{
case EHanType::HWP:
{
oStringStream << L"BIN" << std::setw(4) << std::setfill(L'0') << std::hex << pBinData->GetBinDataID() << L"." << pBinData->GetFormat();
sFileName = oStringStream.str();
return m_pHWPFile->GetChildStream(oStringStream.str(), pBinData->GetCompressed(), oBuffer); return m_pHWPFile->GetChildStream(oStringStream.str(), pBinData->GetCompressed(), oBuffer);
} }
case EHanType::HWPX:
{
oStringStream << sId << L"." << pBinData->GetFormat();
sFileName = oStringStream.str();
return m_pHWPXFile->GetChildStream(L"BinData/" + oStringStream.str(), oBuffer);
}
default:
return false;
} }
case EHanType::HWPX:
{
if (nullptr == m_pHWPXFile)
return false;
pDocInfo = m_pHWPXFile->GetDocInfo();
if (nullptr == pDocInfo)
return false;
const CHWPRecordBinData* pBinData = dynamic_cast<const CHWPRecordBinData*>(pDocInfo->GetBinData(sId));
if (nullptr == pBinData)
return false;
//TODO:: реализовать
}
case EHanType::NONE:
return false;
} }
return false;
} }
HWP_STRING CWriterContext::GetBinFormat(const HWP_STRING& sId) HWP_STRING CWriterContext::GetBinFormat(const HWP_STRING& sId)

View File

@ -24,6 +24,7 @@ public:
~CWriterContext(); ~CWriterContext();
void Clear(); void Clear();
EHanType GetType();
VECTOR<const CHWPSection*> GetSections(); VECTOR<const CHWPSection*> GetSections();
static EHanType DetectHancom(const HWP_STRING& sPathToFile); static EHanType DetectHancom(const HWP_STRING& sPathToFile);
@ -41,7 +42,7 @@ public:
const CHwpRecordTabDef* GetTabDef(short shId); const CHwpRecordTabDef* GetTabDef(short shId);
HWP_STRING GetBinFilename(const HWP_STRING& sId); HWP_STRING GetBinFilename(const HWP_STRING& sId);
bool GetBinBytes(const HWP_STRING& sId, CHWPStream& oBuffer, HWP_STRING& sFormat); bool GetBinBytes(const HWP_STRING& sId, CHWPStream& oBuffer, HWP_STRING& sFileName);
HWP_STRING GetBinFormat(const HWP_STRING& sId); HWP_STRING GetBinFormat(const HWP_STRING& sId);
}; };
} }

View File

@ -412,12 +412,7 @@ void CConverter2OOXML::WriteParagraph(const CHWPPargraph* pParagraph, NSStringUt
{ {
case ECtrlObjectType::ParaText: case ECtrlObjectType::ParaText:
{ {
std::wstring wsText = ((const CParaText*)pCtrl)->GetText(); WriteText(((const CParaText*)pCtrl)->GetText(), pParagraph->GetShapeID(), ((const CParaText*)pCtrl)->GetCharShapeID(), oBuilder, oState);
if (wsText.empty())
wsText = L" ";
WriteText(wsText, pParagraph->GetShapeID(), ((const CParaText*)pCtrl)->GetCharShapeID(), oBuilder, oState);
break; break;
} }
case ECtrlObjectType::Character: case ECtrlObjectType::Character:
@ -801,9 +796,8 @@ void CConverter2OOXML::WriteGeometryShape(const CCtrlGeneralShape* pGeneralShape
oBuilder.WriteString(L"<w:r><w:rPr><w:noProof/></w:rPr>"); oBuilder.WriteString(L"<w:r><w:rPr><w:noProof/></w:rPr>");
oBuilder.WriteString(L"<mc:AlternateContent><mc:Choice Requires=\"wps\">"); oBuilder.WriteString(L"<mc:AlternateContent><mc:Choice Requires=\"wps\">");
oBuilder.WriteString(L"<w:drawing>");
OpenAnchorNode(pGeneralShape, oBuilder); OpenDrawingNode(pGeneralShape, oBuilder);
oBuilder.WriteString(L"<a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\">"); oBuilder.WriteString(L"<a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\">");
oBuilder.WriteString(L"<a:graphicData uri=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\">"); oBuilder.WriteString(L"<a:graphicData uri=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\">");
@ -883,8 +877,8 @@ void CConverter2OOXML::WriteGeometryShape(const CCtrlGeneralShape* pGeneralShape
oBuilder.WriteString(L"<wps:bodyPr/>"); oBuilder.WriteString(L"<wps:bodyPr/>");
oBuilder.WriteString(L"</wps:wsp></a:graphicData></a:graphic>"); oBuilder.WriteString(L"</wps:wsp></a:graphicData></a:graphic>");
CloseAnchorNode(oBuilder); CloseDrawingNode(pGeneralShape, oBuilder);
oBuilder.WriteString(L"</w:drawing></mc:Choice></mc:AlternateContent></w:r>"); oBuilder.WriteString(L"</mc:Choice></mc:AlternateContent></w:r>");
if (!oState.m_bOpenedP) if (!oState.m_bOpenedP)
oBuilder.WriteString(L"</w:p>"); oBuilder.WriteString(L"</w:p>");
@ -919,9 +913,9 @@ void CConverter2OOXML::WriteOleShape(const CCtrlShapeOle* pOleShape, NSStringUti
return; return;
CHWPStream oBuffer; CHWPStream oBuffer;
HWP_STRING sFormat; HWP_STRING sFileName;
if (!m_pContext->GetBinBytes(pOleShape->GetBinDataID(), oBuffer, sFormat)) if (!m_pContext->GetBinBytes(pOleShape->GetBinDataID(), oBuffer, sFileName))
return; return;
m_oOleConverter.CreateChart(oBuffer); m_oOleConverter.CreateChart(oBuffer);
@ -938,18 +932,16 @@ void CConverter2OOXML::WriteOleShape(const CCtrlShapeOle* pOleShape, NSStringUti
if (!oState.m_bOpenedP) if (!oState.m_bOpenedP)
oBuilder.WriteString(L"<w:p>"); oBuilder.WriteString(L"<w:p>");
oBuilder.WriteString(L"<w:r><w:rPr><w:noProof/></w:rPr>"); oBuilder.WriteString(L"<w:r><w:rPr><w:noProof/></w:rPr>");
oBuilder.WriteString(L"<w:drawing>");
OpenAnchorNode(pOleShape, oBuilder); OpenDrawingNode(pOleShape, oBuilder);
oBuilder.WriteString(L"<a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\">"); oBuilder.WriteString(L"<a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\">");
oBuilder.WriteString(L"<a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/chart\">"); oBuilder.WriteString(L"<a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/chart\">");
oBuilder.WriteString(L"<c:chart xmlns:c=\"http://schemas.openxmlformats.org/drawingml/2006/chart\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" r:id=\"" + wsRelID + L"\"/>"); oBuilder.WriteString(L"<c:chart xmlns:c=\"http://schemas.openxmlformats.org/drawingml/2006/chart\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" r:id=\"" + wsRelID + L"\"/>");
oBuilder.WriteString(L"</a:graphicData></a:graphic>"); oBuilder.WriteString(L"</a:graphicData></a:graphic>");
CloseAnchorNode(oBuilder); CloseDrawingNode(pOleShape, oBuilder);
oBuilder.WriteString(L"</w:drawing></w:r>"); oBuilder.WriteString(L"</w:r>");
if (!oState.m_bOpenedP) if (!oState.m_bOpenedP)
oBuilder.WriteString(L"</w:p>"); oBuilder.WriteString(L"</w:p>");
@ -1025,23 +1017,23 @@ void CConverter2OOXML::WritePicture(const CCtrlShapePic* pCtrlPic, NSStringUtils
if (!oState.m_bOpenedP) if (!oState.m_bOpenedP)
oBuilder.WriteString(L"<w:p>"); oBuilder.WriteString(L"<w:p>");
oBuilder.WriteString(L"<w:r><w:rPr><w:noProof/></w:rPr><w:drawing>"); oBuilder.WriteString(L"<w:r><w:rPr><w:noProof/></w:rPr>");
OpenAnchorNode(pCtrlPic, oBuilder); OpenDrawingNode(pCtrlPic, oBuilder);
oBuilder.WriteString(L"<a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\">"); oBuilder.WriteString(L"<a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\">");
oBuilder.WriteString(L"<a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">"); oBuilder.WriteString(L"<a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">");
oBuilder.WriteString(L"<pic:pic xmlns:pic=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">"); oBuilder.WriteString(L"<pic:pic xmlns:pic=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">");
oBuilder.WriteString(L"<pic:nvPicPr><pic:cNvPr id=\"" + pCtrlPic->GetBinDataID() + L"\" name=\"Picture" + pCtrlPic->GetBinDataID() + L"\"/>"); oBuilder.WriteString(L"<pic:nvPicPr><pic:cNvPr id=\"" + std::to_wstring(m_ushShapeCount) + L"\" name=\"Shape " + std::to_wstring(m_ushShapeCount) + L"\"/>");
oBuilder.WriteString(L"<pic:cNvPicPr/></pic:nvPicPr>"); oBuilder.WriteString(L"<pic:cNvPicPr/></pic:nvPicPr>");
oBuilder.WriteString(L"<pic:blipFill><a:blip r:embed=\"" + sPictureID + L"\"><a:extLst><a:ext uri=\"{28A0092B-C50C-407E-A947-70E740481C1C}\"><a14:useLocalDpi xmlns:a14=\"http://schemas.microsoft.com/office/drawing/2010/main\" val=\"0\"/></a:ext></a:extLst></a:blip><a:srcRect/><a:stretch><a:fillRect/></a:stretch></pic:blipFill>"); oBuilder.WriteString(L"<pic:blipFill><a:blip r:embed=\"" + sPictureID + L"\"><a:extLst><a:ext uri=\"{28A0092B-C50C-407E-A947-70E740481C1C}\"><a14:useLocalDpi xmlns:a14=\"http://schemas.microsoft.com/office/drawing/2010/main\" val=\"0\"/></a:ext></a:extLst></a:blip><a:srcRect/><a:stretch><a:fillRect/></a:stretch></pic:blipFill>");
oBuilder.WriteString(L"<pic:spPr bwMode=\"auto\"><a:xfrm><a:off x=\"0\" y=\"0\"/><a:ext cx=\"" + std::to_wstring(Transform::HWPUINT2OOXML(pCtrlPic->GetCurWidth())) + L"\" cy=\"" + std::to_wstring(Transform::HWPUINT2OOXML(pCtrlPic->GetCurHeight())) + L"\"/></a:xfrm>"); oBuilder.WriteString(L"<pic:spPr bwMode=\"auto\"><a:xfrm><a:off x=\"0\" y=\"0\"/><a:ext cx=\"" + std::to_wstring(Transform::HWPUINT2OOXML(pCtrlPic->GetFinalWidth())) + L"\" cy=\"" + std::to_wstring(Transform::HWPUINT2OOXML(pCtrlPic->GetFinalHeight())) + L"\"/></a:xfrm>");
oBuilder.WriteString(L"<a:prstGeom prst=\"rect\"><a:avLst/></a:prstGeom><a:noFill/>"); oBuilder.WriteString(L"<a:prstGeom prst=\"rect\"><a:avLst/></a:prstGeom><a:noFill/>");
WriteBorderSettings(pCtrlPic, oBuilder); WriteBorderSettings(pCtrlPic, oBuilder);
oBuilder.WriteString(L"</pic:spPr></pic:pic></a:graphicData></a:graphic>"); oBuilder.WriteString(L"</pic:spPr></pic:pic></a:graphicData></a:graphic>");
oBuilder.WriteString(L"<wp14:sizeRelH relativeFrom=\"page\"><wp14:pctWidth>0</wp14:pctWidth></wp14:sizeRelH><wp14:sizeRelV relativeFrom=\"page\"><wp14:pctHeight>0</wp14:pctHeight></wp14:sizeRelV>"); oBuilder.WriteString(L"<wp14:sizeRelH relativeFrom=\"page\"><wp14:pctWidth>0</wp14:pctWidth></wp14:sizeRelH><wp14:sizeRelV relativeFrom=\"page\"><wp14:pctHeight>0</wp14:pctHeight></wp14:sizeRelV>");
CloseAnchorNode(oBuilder); CloseDrawingNode(pCtrlPic, oBuilder);
oBuilder.WriteString(L"</w:drawing></w:r>"); oBuilder.WriteString(L"</w:r>");
if (!oState.m_bOpenedP) if (!oState.m_bOpenedP)
oBuilder.WriteString(L"</w:p>"); oBuilder.WriteString(L"</w:p>");
@ -1060,9 +1052,9 @@ void CConverter2OOXML::WriteVideo(const CCtrlShapeVideo* pCtrlVideo, NSStringUti
if (!oState.m_bOpenedP) if (!oState.m_bOpenedP)
oBuilder.WriteString(L"<w:p>"); oBuilder.WriteString(L"<w:p>");
oBuilder.WriteString(L"<w:r><w:rPr><w:noProof/></w:rPr><w:drawing>"); oBuilder.WriteString(L"<w:r><w:rPr><w:noProof/></w:rPr>");
OpenAnchorNode(pCtrlVideo, oBuilder); OpenDrawingNode(pCtrlVideo, oBuilder);
oBuilder.WriteString(L"<a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\">"); oBuilder.WriteString(L"<a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\">");
oBuilder.WriteString(L"<a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">"); oBuilder.WriteString(L"<a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">");
@ -1070,17 +1062,17 @@ void CConverter2OOXML::WriteVideo(const CCtrlShapeVideo* pCtrlVideo, NSStringUti
oBuilder.WriteString(L"<pic:nvPicPr><pic:cNvPr id=\"" + pCtrlVideo->GetThumnailBinID() + L"\" name=\"Video " + pCtrlVideo->GetThumnailBinID() + L"\"/>"); oBuilder.WriteString(L"<pic:nvPicPr><pic:cNvPr id=\"" + pCtrlVideo->GetThumnailBinID() + L"\" name=\"Video " + pCtrlVideo->GetThumnailBinID() + L"\"/>");
oBuilder.WriteString(L"<pic:cNvPicPr/></pic:nvPicPr>"); oBuilder.WriteString(L"<pic:cNvPicPr/></pic:nvPicPr>");
oBuilder.WriteString(L"<pic:blipFill><a:blip r:embed=\"" + sPictureID + L"\"><a:extLst><a:ext uri=\"{28A0092B-C50C-407E-A947-70E740481C1C}\"><a14:useLocalDpi xmlns:a14=\"http://schemas.microsoft.com/office/drawing/2010/main\" val=\"0\"/></a:ext></a:extLst></a:blip><a:srcRect/><a:stretch><a:fillRect/></a:stretch></pic:blipFill>"); oBuilder.WriteString(L"<pic:blipFill><a:blip r:embed=\"" + sPictureID + L"\"><a:extLst><a:ext uri=\"{28A0092B-C50C-407E-A947-70E740481C1C}\"><a14:useLocalDpi xmlns:a14=\"http://schemas.microsoft.com/office/drawing/2010/main\" val=\"0\"/></a:ext></a:extLst></a:blip><a:srcRect/><a:stretch><a:fillRect/></a:stretch></pic:blipFill>");
oBuilder.WriteString(L"<pic:spPr bwMode=\"auto\"><a:xfrm><a:off x=\"0\" y=\"0\"/><a:ext cx=\"" + std::to_wstring(Transform::HWPUINT2OOXML(pCtrlVideo->GetCurWidth())) + L"\" cy=\"" + std::to_wstring(Transform::HWPUINT2OOXML(pCtrlVideo->GetCurHeight())) + L"\"/></a:xfrm>"); oBuilder.WriteString(L"<pic:spPr bwMode=\"auto\"><a:xfrm><a:off x=\"0\" y=\"0\"/><a:ext cx=\"" + std::to_wstring(Transform::HWPUINT2OOXML(pCtrlVideo->GetFinalWidth())) + L"\" cy=\"" + std::to_wstring(Transform::HWPUINT2OOXML(pCtrlVideo->GetFinalHeight())) + L"\"/></a:xfrm>");
oBuilder.WriteString(L"<a:prstGeom prst=\"rect\"><a:avLst/></a:prstGeom><a:noFill/><a:ln><a:noFill/></a:ln></pic:spPr></pic:pic></a:graphicData></a:graphic>"); oBuilder.WriteString(L"<a:prstGeom prst=\"rect\"><a:avLst/></a:prstGeom><a:noFill/><a:ln><a:noFill/></a:ln></pic:spPr></pic:pic></a:graphicData></a:graphic>");
oBuilder.WriteString(L"<wp14:sizeRelH relativeFrom=\"page\"><wp14:pctWidth>0</wp14:pctWidth></wp14:sizeRelH><wp14:sizeRelV relativeFrom=\"page\"><wp14:pctHeight>0</wp14:pctHeight></wp14:sizeRelV>");
CloseAnchorNode(oBuilder); CloseDrawingNode(pCtrlVideo, oBuilder);
oBuilder.WriteString(L"</w:drawing></w:r>"); oBuilder.WriteString(L"</w:r>");
if (!oState.m_bOpenedP) if (!oState.m_bOpenedP)
oBuilder.WriteString(L"</w:p>"); oBuilder.WriteString(L"</w:p>");
} }
bool CConverter2OOXML::SaveSVGFile(const HWP_STRING& sSVG, const HWP_STRING& sIndex) bool CConverter2OOXML::SaveSVGFile(const HWP_STRING& sSVG, HWP_STRING& sFileName)
{ {
if (sSVG.empty()) if (sSVG.empty())
return false; return false;
@ -1164,7 +1156,7 @@ bool CConverter2OOXML::SaveSVGFile(const HWP_STRING& sSVG, const HWP_STRING& sIn
pSvgReader->SetTempDirectory(m_sTempDirectory); pSvgReader->SetTempDirectory(m_sTempDirectory);
pSvgReader->DrawOnRenderer(pGrRenderer, 0, 0, dWidth, dHeight); pSvgReader->DrawOnRenderer(pGrRenderer, 0, 0, dWidth, dHeight);
oFrame.SaveFile(m_sTempDirectory + L"/word/media/image" + sIndex + L".png", 4); oFrame.SaveFile(m_sTempDirectory + L"/word/media/" + sFileName, 4);
oFrame.put_Data(NULL); oFrame.put_Data(NULL);
RELEASEINTERFACE(pGrRenderer); RELEASEINTERFACE(pGrRenderer);
@ -1185,17 +1177,17 @@ HWP_STRING CConverter2OOXML::SavePicture(const HWP_STRING& sBinItemId)
//TODO:: добавить поддержку устновки размеров изображения из свойств шейпа //TODO:: добавить поддержку устновки размеров изображения из свойств шейпа
CHWPStream oBuffer; CHWPStream oBuffer;
HWP_STRING sFormat; HWP_STRING sFileName;
if (!m_pContext->GetBinBytes(sBinItemId, oBuffer, sFormat)) if (!m_pContext->GetBinBytes(sBinItemId, oBuffer, sFileName))
return HWP_STRING(); return HWP_STRING();
oBuffer.MoveToStart(); oBuffer.MoveToStart();
if (IsRasterFormat(sFormat)) if (IsRasterFormat(NSFile::GetFileExtention(sFileName)))
{ {
NSFile::CFileBinary oFile; NSFile::CFileBinary oFile;
oFile.CreateFileW(m_sTempDirectory + L"/word/media/image" + sBinItemId + L'.' + sFormat); oFile.CreateFileW(m_sTempDirectory + L"/word/media/" + sFileName);
if (!oFile.WriteFile((unsigned char*)oBuffer.GetCurPtr(), oBuffer.GetSize())) if (!oFile.WriteFile((unsigned char*)oBuffer.GetCurPtr(), oBuffer.GetSize()))
{ {
oFile.CloseFile(); oFile.CloseFile();
@ -1203,18 +1195,15 @@ HWP_STRING CConverter2OOXML::SavePicture(const HWP_STRING& sBinItemId)
} }
oFile.CloseFile(); oFile.CloseFile();
} }
else if (L"svg" == sFormat) else if (L"svg" == NSFile::GetFileExtention(sFileName))
{ {
std::string sSVG(oBuffer.GetCurPtr(), oBuffer.GetSize()); std::string sSVG(oBuffer.GetCurPtr(), oBuffer.GetSize());
if (!SaveSVGFile(UTF8_TO_U(sSVG), sBinItemId)) if (!SaveSVGFile(UTF8_TO_U(sSVG), sFileName))
return HWP_STRING(); return HWP_STRING();
sFormat = L"png";
} }
AddContentType(L"media/image" + sBinItemId + L'.' + sFormat, L"image/" + sFormat); AddContentType(L"media/" + sFileName, L"image/" + NSFile::GetFileExtention(sFileName));
return AddRelationship(L"image", L"media/" + sFileName);
return AddRelationship(L"image", L"media/image" + sBinItemId + L'.' + sFormat);
} }
void CConverter2OOXML::WriteRunnerStyle(short shCharShapeID, NSStringUtils::CStringBuilder& oBuilder, const TConversionState& oState) void CConverter2OOXML::WriteRunnerStyle(short shCharShapeID, NSStringUtils::CStringBuilder& oBuilder, const TConversionState& oState)
@ -1240,9 +1229,9 @@ void CConverter2OOXML::WriteRunnerStyle(short shCharShapeID, NSStringUtils::CStr
if (!sFontFamily.empty() && !sFontFamilyAsian.empty()) if (!sFontFamily.empty() && !sFontFamilyAsian.empty())
{ {
oBuilder.WriteString(L"<w:rFonts w:ascii=\"" + sFontFamily + oBuilder.WriteString(L"<w:rFonts w:ascii=\"" + sFontFamily +
L"\" w:hAnsi=\"" + sFontFamily + L"\" w:hAnsi=\"" + sFontFamily +
L"\" w:cs=\"" + sFontFamily + L"\" w:cs=\"" + sFontFamily +
L"\" w:eastAsia=\"" + sFontFamilyAsian + L"\"/>"); L"\" w:eastAsia=\"" + sFontFamilyAsian + L"\"/>");
} }
if (pCharShape->Bold()) if (pCharShape->Bold())
@ -1314,25 +1303,45 @@ void CConverter2OOXML::WriteRunnerStyle(short shCharShapeID, NSStringUtils::CStr
oBuilder.WriteString(L"</w:rPr>"); oBuilder.WriteString(L"</w:rPr>");
} }
void CConverter2OOXML::OpenAnchorNode(const CCtrlCommon* pCtrlShape, NSStringUtils::CStringBuilder& oBuilder) void CConverter2OOXML::OpenDrawingNode(const CCtrlCommon* pCtrlShape, NSStringUtils::CStringBuilder& oBuilder)
{ {
if (nullptr == pCtrlShape) if (nullptr == pCtrlShape)
return; return;
oBuilder.WriteString(L"<wp:anchor behindDoc=\"" + std::wstring((ETextWrap::BEHIND_TEXT == pCtrlShape->GetTextWrap() ? L"1" : L"0")) + oBuilder.WriteString(L"<w:drawing>");
L"\" relativeHeight=\"" + std::to_wstring(pCtrlShape->GetZOrder()) +
L"\" distT=\"" + std::to_wstring(Transform::HWPUINT2OOXML(pCtrlShape->GetTopMargin() / 10)) + if (pCtrlShape->GetTreatAsChar())
L"\" distB=\"" + std::to_wstring(Transform::HWPUINT2OOXML(pCtrlShape->GetBottomMargin() / 10)) + oBuilder.WriteString(L"<wp:inline distT=\"" + std::to_wstring(Transform::HWPUINT2OOXML(pCtrlShape->GetTopMargin() / 10)) +
L"\" distL=\"" + std::to_wstring(Transform::HWPUINT2OOXML(pCtrlShape->GetLeftMargin() / 10)) + L"\" distB=\"" + std::to_wstring(Transform::HWPUINT2OOXML(pCtrlShape->GetBottomMargin() / 10)) +
L"\" distR=\"" + std::to_wstring(Transform::HWPUINT2OOXML(pCtrlShape->GetRightMargin() / 10)) + L"\" distL=\"" + std::to_wstring(Transform::HWPUINT2OOXML(pCtrlShape->GetLeftMargin() / 10)) +
L"\" simplePos=\"0\" locked=\"0\" layoutInCell=\"1\" allowOverlap=\"1\">"); L"\" distR=\"" + std::to_wstring(Transform::HWPUINT2OOXML(pCtrlShape->GetRightMargin() / 10)) +
L"\">");
else
oBuilder.WriteString(L"<wp:anchor behindDoc=\"" + std::wstring((ETextWrap::BEHIND_TEXT == pCtrlShape->GetTextWrap() ? L"1" : L"0")) +
L"\" relativeHeight=\"" + std::to_wstring(pCtrlShape->GetZOrder()) +
L"\" distT=\"" + std::to_wstring(Transform::HWPUINT2OOXML(pCtrlShape->GetTopMargin() / 10)) +
L"\" distB=\"" + std::to_wstring(Transform::HWPUINT2OOXML(pCtrlShape->GetBottomMargin() / 10)) +
L"\" distL=\"" + std::to_wstring(Transform::HWPUINT2OOXML(pCtrlShape->GetLeftMargin() / 10)) +
L"\" distR=\"" + std::to_wstring(Transform::HWPUINT2OOXML(pCtrlShape->GetRightMargin() / 10)) +
L"\" simplePos=\"0\" locked=\"0\" layoutInCell=\"1\" allowOverlap=\"1\">");
WriteShapeProperty(pCtrlShape, oBuilder); WriteShapeProperty(pCtrlShape, oBuilder);
} }
void CConverter2OOXML::CloseAnchorNode(NSStringUtils::CStringBuilder& oBuilder) void CConverter2OOXML::CloseDrawingNode(const CCtrlCommon* pCtrlShape, NSStringUtils::CStringBuilder& oBuilder)
{ {
oBuilder.WriteString(L"</wp:anchor>"); if (nullptr == pCtrlShape)
return;
if (pCtrlShape->GetTreatAsChar())
oBuilder.WriteString(L"</wp:inline>");
else
{
oBuilder.WriteString(L"<wp14:sizeRelH relativeFrom=\"page\"><wp14:pctWidth>0</wp14:pctWidth></wp14:sizeRelH><wp14:sizeRelV relativeFrom=\"page\"><wp14:pctHeight>0</wp14:pctHeight></wp14:sizeRelV>");
oBuilder.WriteString(L"</wp:anchor>");
}
oBuilder.WriteString(L"</w:drawing>");
} }
HWP_STRING GetVRelativeFrom(EVRelTo eRelTo) HWP_STRING GetVRelativeFrom(EVRelTo eRelTo)
@ -1460,6 +1469,12 @@ void CConverter2OOXML::WriteText(const std::wstring& wsText, short shParaShapeID
{ {
OpenParagraph(shParaShapeID, oBuilder, oState); OpenParagraph(shParaShapeID, oBuilder, oState);
if (wsText.empty())
{
WriteRunnerStyle(shCharShapeID, oBuilder, oState);
return;
}
for (const std::wstring& wsTextElement : SplitText(wsText)) for (const std::wstring& wsTextElement : SplitText(wsText))
{ {
oBuilder.WriteString(L"<w:r>"); oBuilder.WriteString(L"<w:r>");
@ -1623,8 +1638,6 @@ void CConverter2OOXML::WriteAutoNumber(const CCtrlAutoNumber* pAutoNumber,short
ushValue = m_ushTableCount; break; ushValue = m_ushTableCount; break;
case ENumType::EQUATION: case ENumType::EQUATION:
ushValue = m_ushEquationCount; break; ushValue = m_ushEquationCount; break;
case ENumType::null:
break;
} }
if (0 == ushValue) if (0 == ushValue)

View File

@ -93,14 +93,14 @@ class CConverter2OOXML
void WriteSectionSettings(TConversionState& oState); void WriteSectionSettings(TConversionState& oState);
void WritePicture(const CCtrlShapePic* pCtrlPic, NSStringUtils::CStringBuilder& oBuilder, const TConversionState& oState); void WritePicture(const CCtrlShapePic* pCtrlPic, NSStringUtils::CStringBuilder& oBuilder, const TConversionState& oState);
void WriteVideo(const CCtrlShapeVideo* pCtrlVideo, NSStringUtils::CStringBuilder& oBuilder, const TConversionState& oState); void WriteVideo(const CCtrlShapeVideo* pCtrlVideo, NSStringUtils::CStringBuilder& oBuilder, const TConversionState& oState);
bool SaveSVGFile(const HWP_STRING& sSVG, const HWP_STRING& sIndex); bool SaveSVGFile(const HWP_STRING& sSVG, HWP_STRING& sFileName);
HWP_STRING SavePicture(const HWP_STRING& sBinItemId); HWP_STRING SavePicture(const HWP_STRING& sBinItemId);
void WriteParaShapeProperties(short shParaShapeID, NSStringUtils::CStringBuilder& oBuilder, const TConversionState& oState); void WriteParaShapeProperties(short shParaShapeID, NSStringUtils::CStringBuilder& oBuilder, const TConversionState& oState);
void WriteRunnerStyle(short shCharShapeID, NSStringUtils::CStringBuilder& oBuilder, const TConversionState& oState); void WriteRunnerStyle(short shCharShapeID, NSStringUtils::CStringBuilder& oBuilder, const TConversionState& oState);
void OpenAnchorNode(const CCtrlCommon* pCtrlShape, NSStringUtils::CStringBuilder& oBuilder); void OpenDrawingNode(const CCtrlCommon* pCtrlShape, NSStringUtils::CStringBuilder& oBuilder);
void CloseAnchorNode(NSStringUtils::CStringBuilder& oBuilder); void CloseDrawingNode(const CCtrlCommon* pCtrlShape, NSStringUtils::CStringBuilder& oBuilder);
void WriteShapeProperty(const CCtrlCommon* pCtrlShape, NSStringUtils::CStringBuilder& oBuilder); void WriteShapeProperty(const CCtrlCommon* pCtrlShape, NSStringUtils::CStringBuilder& oBuilder);
void OpenParagraph(short shParaShapeID, NSStringUtils::CStringBuilder& oBuilder, TConversionState& oState); void OpenParagraph(short shParaShapeID, NSStringUtils::CStringBuilder& oBuilder, TConversionState& oState);

View File

@ -21,14 +21,18 @@ std::wstring CFootnoteConverter::CreateNote(const CCtrlNote* pNote, CConverter2O
NSStringUtils::CStringBuilder *pXMLBuilder = &m_oFootnoteXml; NSStringUtils::CStringBuilder *pXMLBuilder = &m_oFootnoteXml;
std::wstring wsPrefix = L"foot"; std::wstring wsPrefix = L"foot";
std::wstring wsIndex;
if (L" ne" == pNote->GetID()) if (L" ne" == pNote->GetID())
{ {
wsPrefix = L"end"; wsPrefix = L"end";
pXMLBuilder = &m_oEndnoteXml; pXMLBuilder = &m_oEndnoteXml;
wsIndex = std::to_wstring(++m_ushCountEndnotes);
} }
else
wsIndex = std::to_wstring(++m_ushCountFootnotes);
pXMLBuilder->WriteString(L"<w:" + wsPrefix + L"note w:id=\"" + std::to_wstring(++m_ushCountFootnotes) + L"\">"); pXMLBuilder->WriteString(L"<w:" + wsPrefix + L"note w:id=\"" + wsIndex + L"\">");
TConversionState oState; TConversionState oState;
@ -37,7 +41,7 @@ std::wstring CFootnoteConverter::CreateNote(const CCtrlNote* pNote, CConverter2O
pXMLBuilder->WriteString(L"</w:" + wsPrefix + L"note>"); pXMLBuilder->WriteString(L"</w:" + wsPrefix + L"note>");
return L"<w:" + wsPrefix + L"noteReference w:id=\"" + std::to_wstring(m_ushCountFootnotes) + L"\"/>"; return L"<w:" + wsPrefix + L"noteReference w:id=\"" + wsIndex + L"\"/>";
} }
std::wstring CFootnoteConverter::CreateHeadOrFoot(const CCtrlHeadFoot* pCtrlHeadFoot, CConverter2OOXML& oConverter) std::wstring CFootnoteConverter::CreateHeadOrFoot(const CCtrlHeadFoot* pCtrlHeadFoot, CConverter2OOXML& oConverter)

View File

@ -14,6 +14,8 @@ CHWPFile::CHWPFile(const HWP_STRING& sFileName)
CHWPFile::~CHWPFile() CHWPFile::~CHWPFile()
{ {
Close();
CLEAR_ARRAY(CHWPSection, m_arBodyTexts); CLEAR_ARRAY(CHWPSection, m_arBodyTexts);
CLEAR_ARRAY(CHWPSection, m_arViewTexts); CLEAR_ARRAY(CHWPSection, m_arViewTexts);
} }

View File

@ -122,6 +122,26 @@ const CHWPDocInfo* CHWPXFile::GetDocInfo() const
return &m_oDocInfo; return &m_oDocInfo;
} }
bool CHWPXFile::GetChildStream(const HWP_STRING& sFileName, CHWPStream& oBuffer)
{
if (nullptr == m_pZipFolder || !m_pZipFolder->exists(sFileName))
return false;
CZipFolderMemory::CBuffer *pFileBuffer = nullptr;
m_pZipFolder->read(sFileName, pFileBuffer);
if (nullptr == pFileBuffer)
return false;
pFileBuffer->UnsetDestroy();
oBuffer.SetStream((HWP_BYTE*)pFileBuffer->Buffer, pFileBuffer->Size);
delete pFileBuffer;
return true;
}
bool CHWPXFile::GetDocInfo(int nVersion) bool CHWPXFile::GetDocInfo(int nVersion)
{ {
CXMLNode oContent{GetDocument(L"Contents/content.hpf")}; CXMLNode oContent{GetDocument(L"Contents/content.hpf")};

View File

@ -22,6 +22,7 @@ public:
VECTOR<const CHWPSection*> GetSections() const; VECTOR<const CHWPSection*> GetSections() const;
const CHWPDocInfo* GetDocInfo() const; const CHWPDocInfo* GetDocInfo() const;
bool GetChildStream(const HWP_STRING& sFileName, CHWPStream& oBuffer);
bool Detect(); bool Detect();
bool Open(); bool Open();

View File

@ -2,6 +2,31 @@
namespace HWP namespace HWP
{ {
ENumType GetNumType(int nValue)
{
SWITCH(ENumType, nValue)
{
DEFAULT(ENumType::PAGE);
CASE(ENumType::FOOTNOTE);
CASE(ENumType::ENDNOTE);
CASE(ENumType::FIGURE);
CASE(ENumType::TABLE);
CASE(ENumType::EQUATION);
CASE(ENumType::TOTAL_PAGE);
}
}
ENumType GetNumType(const HWP_STRING& sValue)
{
IF_STRING_IN_ENUM(FOOTNOTE, sValue, ENumType);
ELSE_IF_STRING_IN_ENUM(ENDNOTE, sValue, ENumType);
ELSE_IF_STRING_IN_ENUM(FIGURE, sValue, ENumType);
ELSE_IF_STRING_IN_ENUM(TABLE, sValue, ENumType);
ELSE_IF_STRING_IN_ENUM(EQUATION, sValue, ENumType);
ELSE_IF_STRING_IN_ENUM(TOTAL_PAGE, sValue, ENumType);
ELSE_STRING_IN_ENUM(PAGE, ENumType);
}
CCtrlAutoNumber::CCtrlAutoNumber(const HWP_STRING& sCtrlID) CCtrlAutoNumber::CCtrlAutoNumber(const HWP_STRING& sCtrlID)
: CCtrl(sCtrlID) : CCtrl(sCtrlID)
{} {}
@ -22,7 +47,7 @@ CCtrlAutoNumber::CCtrlAutoNumber(const HWP_STRING& sCtrlID, int nSize, CHWPStrea
CCtrlAutoNumber::CCtrlAutoNumber(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion) CCtrlAutoNumber::CCtrlAutoNumber(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion)
: CCtrl(sCtrlID) : CCtrl(sCtrlID)
{ {
m_eNumType = ::HWP::GetNumType(oNode.GetAttributeInt(L"numType")); m_eNumType = ::HWP::GetNumType(oNode.GetAttribute(L"numType"));
HWP_STRING sType; HWP_STRING sType;

View File

@ -18,26 +18,11 @@ enum class ENumType
FIGURE, FIGURE,
TABLE, TABLE,
EQUATION, EQUATION,
TOTAL_PAGE, TOTAL_PAGE
null
}; };
inline ENumType GetNumType(int nValue) inline ENumType GetNumType(int nValue);
{ inline ENumType GetNumType(const HWP_STRING& sValue);
switch(static_cast<ENumType>(nValue))
{
case ENumType::PAGE:
case ENumType::FOOTNOTE:
case ENumType::ENDNOTE:
case ENumType::FIGURE:
case ENumType::TABLE:
case ENumType::EQUATION:
case ENumType::TOTAL_PAGE:
return static_cast<ENumType>(nValue);
default:
return ENumType::null;
}
}
class CCtrlAutoNumber : public CCtrl class CCtrlAutoNumber : public CCtrl
{ {

View File

@ -5,6 +5,27 @@
namespace HWP namespace HWP
{ {
EVertAlign GetVertAlign(int nValue)
{
SWITCH(EVertAlign, nValue)
{
DEFAULT(EVertAlign::TOP);
CASE(EVertAlign::CENTER);
CASE(EVertAlign::BOTTOM);
CASE(EVertAlign::INSIDE);
CASE(EVertAlign::OUTSIDE);
}
}
EVertAlign GetVertAlign(const HWP_STRING& sValue)
{
IF_STRING_IN_ENUM(CENTER, sValue, EVertAlign);
ELSE_IF_STRING_IN_ENUM(BOTTOM, sValue, EVertAlign);
ELSE_IF_STRING_IN_ENUM(INSIDE, sValue, EVertAlign);
ELSE_IF_STRING_IN_ENUM(OUTSIDE, sValue, EVertAlign);
ELSE_STRING_IN_ENUM(TOP, EVertAlign);
}
EVRelTo GetVRelTo(int nValue) EVRelTo GetVRelTo(int nValue)
{ {
SWITCH(EVRelTo, nValue) SWITCH(EVRelTo, nValue)
@ -15,6 +36,14 @@ namespace HWP
} }
} }
EVRelTo GetVRelTo(const HWP_STRING& sValue)
{
IF_STRING_IN_ENUM(PARA, sValue, EVRelTo);
ELSE_IF_STRING_IN_ENUM(PAGE, sValue, EVRelTo);
ELSE_IF_STRING_IN_ENUM(PAPER, sValue, EVRelTo);
ELSE_STRING_IN_ENUM(PARA, EVRelTo);
}
EHRelTo GetHRelTo(int nValue) EHRelTo GetHRelTo(int nValue)
{ {
SWITCH(EHRelTo, nValue) SWITCH(EHRelTo, nValue)
@ -26,6 +55,14 @@ namespace HWP
} }
} }
EHRelTo GetHRelTo(const HWP_STRING& sValue)
{
IF_STRING_IN_ENUM(PAGE, sValue, EHRelTo);
ELSE_IF_STRING_IN_ENUM(PARA, sValue, EHRelTo);
ELSE_IF_STRING_IN_ENUM(COLUMN, sValue, EHRelTo);
ELSE_STRING_IN_ENUM(PAPER, EHRelTo);
}
EWidthRelTo GetWidthRelTo(int nValue) EWidthRelTo GetWidthRelTo(int nValue)
{ {
SWITCH(EWidthRelTo, nValue) SWITCH(EWidthRelTo, nValue)
@ -38,6 +75,15 @@ namespace HWP
} }
} }
EWidthRelTo GetWidthRelTo(const HWP_STRING& sValue)
{
IF_STRING_IN_ENUM(PAGE, sValue, EWidthRelTo);
ELSE_IF_STRING_IN_ENUM(PARA, sValue, EWidthRelTo);
ELSE_IF_STRING_IN_ENUM(COLUMN, sValue, EWidthRelTo);
ELSE_IF_STRING_IN_ENUM(ABSOLUTE, sValue, EWidthRelTo);
ELSE_STRING_IN_ENUM(PAPER, EWidthRelTo);
}
EHeightRelTo GetHeightRelTo(int nValue) EHeightRelTo GetHeightRelTo(int nValue)
{ {
SWITCH(EHeightRelTo, nValue) SWITCH(EHeightRelTo, nValue)
@ -48,6 +94,13 @@ namespace HWP
} }
} }
EHeightRelTo GetHeightRelTo(const HWP_STRING& sValue)
{
IF_STRING_IN_ENUM(PAGE, sValue, EHeightRelTo);
ELSE_IF_STRING_IN_ENUM(ABSOLUTE, sValue, EHeightRelTo);
ELSE_STRING_IN_ENUM(PAPER, EHeightRelTo);
}
EHorzAlign GetHorzAlign(int nValue) EHorzAlign GetHorzAlign(int nValue)
{ {
SWITCH(EHorzAlign, nValue) SWITCH(EHorzAlign, nValue)
@ -60,6 +113,15 @@ namespace HWP
} }
} }
EHorzAlign GetHorzAlign(const HWP_STRING& sValue)
{
IF_STRING_IN_ENUM(CENTER, sValue, EHorzAlign);
ELSE_IF_STRING_IN_ENUM(RIGHT, sValue, EHorzAlign);
ELSE_IF_STRING_IN_ENUM(INSIDE, sValue, EHorzAlign);
ELSE_IF_STRING_IN_ENUM(OUTSIDE, sValue, EHorzAlign);
ELSE_STRING_IN_ENUM(LEFT, EHorzAlign);
}
ETextWrap GetTextWrap(int nValue) ETextWrap GetTextWrap(int nValue)
{ {
SWITCH(ETextWrap, nValue) SWITCH(ETextWrap, nValue)
@ -71,6 +133,14 @@ namespace HWP
} }
} }
ETextWrap GetTextWrap(const HWP_STRING& sValue)
{
IF_STRING_IN_ENUM(TOP_AND_BOTTOM, sValue, ETextWrap);
ELSE_IF_STRING_IN_ENUM(BEHIND_TEXT, sValue, ETextWrap);
ELSE_IF_STRING_IN_ENUM(IN_FRONT_OF_TEXT, sValue, ETextWrap);
ELSE_STRING_IN_ENUM(SQUARE, ETextWrap);
}
CCtrlCommon::CCtrlCommon() CCtrlCommon::CCtrlCommon()
: m_nVertOffset(0), m_nHorzOffset(0) : m_nVertOffset(0), m_nHorzOffset(0)
{} {}
@ -214,9 +284,9 @@ namespace HWP
if (L"hp:sz" == oChild.GetName()) if (L"hp:sz" == oChild.GetName())
{ {
m_nWidth = oChild.GetAttributeInt(L"width"); m_nWidth = oChild.GetAttributeInt(L"width");
m_eWidthRelTo = ::HWP::GetWidthRelTo(oChild.GetAttributeInt(L"widthRelTo")); m_eWidthRelTo = ::HWP::GetWidthRelTo(oChild.GetAttribute(L"widthRelTo"));
m_nHeight = oChild.GetAttributeInt(L"height"); m_nHeight = oChild.GetAttributeInt(L"height");
m_eHeightRelTo = ::HWP::GetHeightRelTo(oChild.GetAttributeInt(L"heightRelTo")); m_eHeightRelTo = ::HWP::GetHeightRelTo(oChild.GetAttribute(L"heightRelTo"));
} }
else if (L"hp:pos" == oChild.GetName()) else if (L"hp:pos" == oChild.GetName())
{ {
@ -227,14 +297,14 @@ namespace HWP
else else
m_bAllowOverlap = oChild.GetAttributeBool(L"allowOverlap"); m_bAllowOverlap = oChild.GetAttributeBool(L"allowOverlap");
m_eVertRelTo = GetVRelTo(oChild.GetAttributeInt(L"vertRelTo")); m_eVertRelTo = GetVRelTo(oChild.GetAttribute(L"vertRelTo"));
m_eHorzRelTo = GetHRelTo(oChild.GetAttributeInt(L"horzRelTo")); m_eHorzRelTo = GetHRelTo(oChild.GetAttribute(L"horzRelTo"));
if (EVRelTo::PARA == m_eVertRelTo) if (EVRelTo::PARA == m_eVertRelTo)
m_bFlowWithText = oChild.GetAttributeBool(L"flowWithText"); m_bFlowWithText = oChild.GetAttributeBool(L"flowWithText");
m_eVertAlign = GetVertAlign(oChild.GetAttributeInt(L"vertAlign")); m_eVertAlign = GetVertAlign(oChild.GetAttribute(L"vertAlign"));
m_eHorzAlign = GetHorzAlign(oChild.GetAttributeInt(L"horzAlign")); m_eHorzAlign = GetHorzAlign(oChild.GetAttribute(L"horzAlign"));
m_nVertOffset = oChild.GetAttributeInt(L"vertOffset"); m_nVertOffset = oChild.GetAttributeInt(L"vertOffset");
m_nHorzOffset = oChild.GetAttributeInt(L"horzOffset"); m_nHorzOffset = oChild.GetAttributeInt(L"horzOffset");
} }
@ -347,6 +417,16 @@ namespace HWP
return m_arOutMargin[3]; return m_arOutMargin[3];
} }
bool CCtrlCommon::GetTreatAsChar() const
{
return m_bTreatAsChar;
}
bool CCtrlCommon::GetFlowWithText() const
{
return m_bFlowWithText;
}
int CCtrlCommon::GetHorzOffset() const int CCtrlCommon::GetHorzOffset() const
{ {
return m_nHorzOffset; return m_nHorzOffset;

View File

@ -48,20 +48,8 @@ enum class EVertAlign
OUTSIDE OUTSIDE
}; };
inline EVertAlign GetVertAlign(int nValue) inline EVertAlign GetVertAlign(int nValue);
{ inline EVertAlign GetVertAlign(const HWP_STRING& sValue);
switch(static_cast<EVertAlign>(nValue))
{
case EVertAlign::CENTER:
case EVertAlign::BOTTOM:
case EVertAlign::INSIDE:
case EVertAlign::OUTSIDE:
return static_cast<EVertAlign>(nValue);
case EVertAlign::TOP:
default:
return EVertAlign::TOP;
}
}
enum class EHorzAlign enum class EHorzAlign
{ {
@ -144,6 +132,8 @@ public:
short GetRightMargin() const; short GetRightMargin() const;
short GetBottomMargin() const; short GetBottomMargin() const;
bool GetTreatAsChar() const;
bool GetFlowWithText() const;
int GetHorzOffset() const; int GetHorzOffset() const;
int GetVertOffset() const; int GetVertOffset() const;
EVRelTo GetVertRelTo() const; EVRelTo GetVertRelTo() const;

View File

@ -19,9 +19,9 @@ CCtrlNote::CCtrlNote(const HWP_STRING& sCtrlID, int nSize, CHWPStream& oBuffer,
CCtrlNote::CCtrlNote(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion) CCtrlNote::CCtrlNote(const HWP_STRING& sCtrlID, CXMLNode& oNode, int nVersion)
: CCtrl(sCtrlID) : CCtrl(sCtrlID)
{ {
for (CXMLNode& oChild : oNode.GetChilds(L"subList")) for (CXMLNode& oChild : oNode.GetChilds(L"hp:subList"))
{ {
for (CXMLNode& oGrandChild : oChild.GetChilds(L"p")) for (CXMLNode& oGrandChild : oChild.GetChilds(L"hp:p"))
m_arParas.push_back(new CHWPPargraph(oGrandChild, nVersion)); m_arParas.push_back(new CHWPPargraph(oGrandChild, nVersion));
} }

View File

@ -53,45 +53,41 @@ CCtrlObjElement::CCtrlObjElement(const HWP_STRING& sCtrlID, CXMLNode& oNode, int
m_shNGrp = oNode.GetAttributeInt(L"groupLevel"); m_shNGrp = oNode.GetAttributeInt(L"groupLevel");
m_arMatrix.resize(6);
m_arMatrixSeq.resize((m_shNGrp + 1) * 6 * 2); m_arMatrixSeq.resize((m_shNGrp + 1) * 6 * 2);
short shScaMatCnt = 0, shRotMatCnt = 0; short shScaMatCnt = 0, shRotMatCnt = 0;
std::vector<CXMLNode> arChilds{oNode.GetChilds()}; for (CXMLNode& oChild : oNode.GetChilds())
//TODO:: проверить чтение не в обратном порядке
for (std::vector<CXMLNode>::reverse_iterator itNode = arChilds.rbegin(); itNode < arChilds.rend(); ++itNode)
{ {
if (L"hp:offset" == (*itNode).GetName()) if (L"hp:offset" == oChild.GetName())
{ {
m_nXGrpOffset = (*itNode).GetAttributeInt(L"x"); m_nXGrpOffset = oChild.GetAttributeInt(L"x");
m_nYGrpOffset = (*itNode).GetAttributeInt(L"y"); m_nYGrpOffset = oChild.GetAttributeInt(L"y");
} }
else if (L"hp:orgSz" == (*itNode).GetName()) else if (L"hp:orgSz" == oChild.GetName())
{ {
m_nIniWidth = (*itNode).GetAttributeInt(L"width"); m_nIniWidth = oChild.GetAttributeInt(L"width");
m_nIniHeight = (*itNode).GetAttributeInt(L"height"); m_nIniHeight = oChild.GetAttributeInt(L"height");
} }
else if (L"hp:curSz" == (*itNode).GetName()) else if (L"hp:curSz" == oChild.GetName())
{ {
m_nCurWidth = (*itNode).GetAttributeInt(L"width"); m_nCurWidth = oChild.GetAttributeInt(L"width");
m_nCurHeight = (*itNode).GetAttributeInt(L"height"); m_nCurHeight = oChild.GetAttributeInt(L"height");
} }
else if (L"hp:flip" == (*itNode).GetName()) else if (L"hp:flip" == oChild.GetName())
{ {
m_bHorzFlip = (*itNode).GetAttributeBool(L"horizontal"); m_bHorzFlip = oChild.GetAttributeBool(L"horizontal");
m_bVerFlip = (*itNode).GetAttributeBool(L"vertical"); m_bVerFlip = oChild.GetAttributeBool(L"vertical");
} }
else if (L"hp:rotationInfo" == (*itNode).GetName()) else if (L"hp:rotationInfo" == oChild.GetName())
{ {
m_shRotat = (*itNode).GetAttributeInt(L"angle"); m_shRotat = oChild.GetAttributeInt(L"angle");
m_nXCenter = (*itNode).GetAttributeInt(L"centerX"); m_nXCenter = oChild.GetAttributeInt(L"centerX");
m_nYCenter = (*itNode).GetAttributeInt(L"centerY"); m_nYCenter = oChild.GetAttributeInt(L"centerY");
} }
else if (L"hp:renderingInfo" == (*itNode).GetName()) else if (L"hp:renderingInfo" == oChild.GetName())
{ {
for (CXMLNode& oGrandChild : (*itNode).GetChilds()) for (CXMLNode& oGrandChild : oChild.GetChilds())
{ {
if (L"hc:transMatrix" == oGrandChild.GetName()) if (L"hc:transMatrix" == oGrandChild.GetName())
SetMatrix(oGrandChild, m_arMatrix, 0); SetMatrix(oGrandChild, m_arMatrix, 0);
@ -120,6 +116,22 @@ int CCtrlObjElement::GetCurHeight() const
return m_nCurHeight; return m_nCurHeight;
} }
int CCtrlObjElement::GetFinalWidth() const
{
if (0 != m_nCurWidth)
return m_nCurWidth;
return CCtrlCommon::GetWidth();
}
int CCtrlObjElement::GetFinalHeight() const
{
if (0 != m_nCurHeight)
return m_nCurHeight;
return CCtrlCommon::GetHeight();
}
int CCtrlObjElement::ParseCtrl(CCtrlObjElement& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion) int CCtrlObjElement::ParseCtrl(CCtrlObjElement& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion)
{ {
oBuffer.SavePosition(); oBuffer.SavePosition();

View File

@ -37,6 +37,9 @@ public:
int GetCurWidth() const; int GetCurWidth() const;
int GetCurHeight() const; int GetCurHeight() const;
int GetFinalWidth() const;
int GetFinalHeight() const;
static int ParseCtrl(CCtrlObjElement& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion); static int ParseCtrl(CCtrlObjElement& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion);
}; };
} }

View File

@ -70,8 +70,10 @@ CHWPPargraph::~CHWPPargraph()
CLEAR_ARRAY(TRangeTag, m_arRangeTags); CLEAR_ARRAY(TRangeTag, m_arRangeTags);
} }
void CHWPPargraph::ParseHWPParagraph(CXMLNode& oNode, int nCharShapeID, int nVersion) bool CHWPPargraph::ParseHWPParagraph(CXMLNode& oNode, int nCharShapeID, int nVersion)
{ {
const size_t unCurrentParaCount = m_arP.size();
if (L"hp:secPr" == oNode.GetName()) if (L"hp:secPr" == oNode.GetName())
m_arP.push_back(new CCtrlSectionDef(L"dces", oNode, nVersion)); m_arP.push_back(new CCtrlSectionDef(L"dces", oNode, nVersion));
else if (L"hp:ctrl" == oNode.GetName()) else if (L"hp:ctrl" == oNode.GetName())
@ -124,6 +126,26 @@ void CHWPPargraph::ParseHWPParagraph(CXMLNode& oNode, int nCharShapeID, int nVer
m_arP.push_back(new CCtrlShapeTextArt(L"tat$", oNode, nVersion)); m_arP.push_back(new CCtrlShapeTextArt(L"tat$", oNode, nVersion));
else if (L"hp:video" == oNode.GetName()) else if (L"hp:video" == oNode.GetName())
m_arP.push_back(new CCtrlShapeVideo(L"div$", oNode, nVersion)); m_arP.push_back(new CCtrlShapeVideo(L"div$", oNode, nVersion));
if (unCurrentParaCount != m_arP.size())
return true;
if (L"hp:switch" == oNode.GetName())
{
for (CXMLNode& oCaseChild : oNode.GetChilds(L"hp:case"))
{
for (CXMLNode& oChild : oCaseChild.GetChilds())
if (ParseHWPParagraph(oChild, nCharShapeID, nVersion))
return true;
}
CXMLNode oDefaultChild{oNode.GetChild(L"hp:default")};
for (CXMLNode& oChild : oDefaultChild.GetChilds())
if (ParseHWPParagraph(oChild, nCharShapeID, nVersion))
return true;
}
return false;
} }

View File

@ -26,7 +26,7 @@ class CHWPPargraph : public IRef
VECTOR<CCtrl*> m_arP; //HWPTAG_PARA_TEXT VECTOR<CCtrl*> m_arP; //HWPTAG_PARA_TEXT
void ParseHWPParagraph(CXMLNode& oNode, int nCharShapeID, int nVersion); bool ParseHWPParagraph(CXMLNode& oNode, int nCharShapeID, int nVersion);
public: public:
CHWPPargraph(); CHWPPargraph();
CHWPPargraph(CXMLNode& oNode, int nVersion); CHWPPargraph(CXMLNode& oNode, int nVersion);