Fixed a bug with glued text in hwpx

This commit is contained in:
Green
2025-07-09 15:46:06 +03:00
parent 98c998b3ee
commit 00e5c8bd2e
3 changed files with 51 additions and 13 deletions

View File

@ -63,6 +63,14 @@ std::wstring CXMLReader::GetText()
return (m_bParseAttribute) ? m_pReader->GetText() : m_pReader->GetText2(); return (m_bParseAttribute) ? m_pReader->GetText() : m_pReader->GetText2();
} }
const char* CXMLReader::GetTextChar()
{
if (nullptr == m_pReader)
return "";
return m_pReader->GetTextChar();
}
template<typename T> template<typename T>
T CXMLReader::GetAttribute(const std::string& sName, T _default, T (*GetValue)(CXMLReader&)) T CXMLReader::GetAttribute(const std::string& sName, T _default, T (*GetValue)(CXMLReader&))
{ {
@ -155,6 +163,11 @@ bool CXMLReader::ReadNextNode()
return (nullptr != m_pReader) ? m_pReader->ReadNextNode() : false; return (nullptr != m_pReader) ? m_pReader->ReadNextNode() : false;
} }
bool CXMLReader::Read(XmlUtils::XmlNodeType& eNodeType)
{
return (nullptr != m_pReader) ? m_pReader->Read(eNodeType) : false;
}
int CXMLReader::GetIntValue(CXMLReader& oXmlReader) int CXMLReader::GetIntValue(CXMLReader& oXmlReader)
{ {
return std::atoi(oXmlReader.GetTextA().c_str()); return std::atoi(oXmlReader.GetTextA().c_str());
@ -231,7 +244,7 @@ double CXMLReader::GetDoubleValue(CXMLReader& oXmlReader)
if (bExpNegative) if (bExpNegative)
nExponent = -nExponent; nExponent = -nExponent;
dResult *= std::pow(10., nExponent); dResult *= pow(10., nExponent);
} }
return bNegative ? -dResult : dResult; return bNegative ? -dResult : dResult;

View File

@ -24,6 +24,7 @@ public:
double GetDouble(); double GetDouble();
std::string GetTextA(); std::string GetTextA();
std::wstring GetText(); std::wstring GetText();
const char* GetTextChar();
int GetAttributeInt(const std::string& sName, int nDefault = 0); int GetAttributeInt(const std::string& sName, int nDefault = 0);
bool GetAttributeBool(const std::string& sName); bool GetAttributeBool(const std::string& sName);
@ -40,6 +41,7 @@ public:
std::string GetName(); std::string GetName();
bool ReadNextSiblingNode(unsigned int unDepth); bool ReadNextSiblingNode(unsigned int unDepth);
bool ReadNextNode(); bool ReadNextNode();
bool Read(XmlUtils::XmlNodeType& eNodeType);
private: private:
static int GetIntValue(CXMLReader& oXmlReader); static int GetIntValue(CXMLReader& oXmlReader);
static bool GetBoolValue(CXMLReader& oXmlReader); static bool GetBoolValue(CXMLReader& oXmlReader);

View File

@ -19,6 +19,8 @@
#include "CtrlShapeVideo.h" #include "CtrlShapeVideo.h"
#include "ParaText.h" #include "ParaText.h"
#include "../../../DesktopEditor/common/File.h"
namespace HWP namespace HWP
{ {
CHWPPargraph::CHWPPargraph() CHWPPargraph::CHWPPargraph()
@ -101,21 +103,42 @@ bool CHWPPargraph::ParseHWPParagraph(CXMLReader& oReader, int nCharShapeID, int
} }
else if ("hp:t" == sNodeName) else if ("hp:t" == sNodeName)
{ {
m_arP.push_back(new CParaText(L"____", oReader.GetText(), 0, nCharShapeID)); if (oReader.IsEmptyNode())
return false;
WHILE_READ_NEXT_NODE_WITH_DEPTH_AND_NAME(oReader, Child) const int nDepth = oReader.GetDepth();
XmlUtils::XmlNodeType eNodeType = XmlUtils::XmlNodeType_EndElement;
while (oReader.Read(eNodeType) && oReader.GetDepth() >= nDepth && XmlUtils::XmlNodeType_EndElement != eNodeType)
{ {
if ("hp:lineBreak" == sNodeChildName) if (eNodeType == XmlUtils::XmlNodeType_Text ||
m_arP.push_back(new CCtrlCharacter(L" _", ECtrlCharType::LINE_BREAK)); eNodeType == XmlUtils::XmlNodeType_Whitespace ||
else if ("hp:hyphen" == sNodeChildName) eNodeType == XmlUtils::XmlNodeType_SIGNIFICANT_WHITESPACE ||
m_arP.push_back(new CCtrlCharacter(L" _", ECtrlCharType::HARD_HYPHEN)); eNodeType == XmlUtils::XmlNodeType_CDATA)
else if ("hp:nbSpace" == sNodeChildName || {
"hp:fwSpace" == sNodeChildName) const char* pValue = oReader.GetTextChar();
m_arP.push_back(new CCtrlCharacter(L" _", ECtrlCharType::HARD_SPACE)); std::wstring wsValue;
else if ("hp:tab" == sNodeChildName)
m_arP.push_back(new CCtrlCharacter(L" _", ECtrlCharType::TABULATION)); if('\0' != pValue[0])
{
NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)pValue, (LONG)strlen(pValue), wsValue);
m_arP.push_back(new CParaText(L"____", wsValue, 0, nCharShapeID));
}
}
else if (eNodeType == XmlUtils::XmlNodeType_Element)
{
const std::string sChildNodeName{oReader.GetName()};
if ("hp:lineBreak" == sChildNodeName)
m_arP.push_back(new CCtrlCharacter(L" _", ECtrlCharType::LINE_BREAK));
else if ("hp:hyphen" == sChildNodeName)
m_arP.push_back(new CCtrlCharacter(L" _", ECtrlCharType::HARD_HYPHEN));
else if ("hp:nbSpace" == sChildNodeName ||
"hp:fwSpace" == sChildNodeName)
m_arP.push_back(new CCtrlCharacter(L" _", ECtrlCharType::HARD_SPACE));
else if ("hp:tab" == sChildNodeName)
m_arP.push_back(new CCtrlCharacter(L" _", ECtrlCharType::TABULATION));
}
} }
END_WHILE
} }
else if ("hp:tbl" == sNodeName) else if ("hp:tbl" == sNodeName)
m_arP.push_back(new CCtrlTable(L" lbt", oReader, nVersion)); m_arP.push_back(new CCtrlTable(L" lbt", oReader, nVersion));