Fixed a problem with text rendering in OFD

This commit is contained in:
Green
2025-07-26 18:58:32 +03:00
parent c1987b196e
commit 66501ab353
4 changed files with 26 additions and 10 deletions

View File

@ -248,15 +248,14 @@ TCGTransform TCGTransform::Read(CXmlReader& oLiteReader)
oLiteReader.MoveToElement();
const int nDepth = oLiteReader.GetDepth();
unsigned int unCount = 0;
while (oLiteReader.ReadNextSiblingNode(nDepth) && unCount < oCGTransform.m_unGlyphCount)
while (oLiteReader.ReadNextSiblingNode(nDepth))
{
if ("ofd:Glyphs" == oLiteReader.GetNameA())
{
oCGTransform.m_arGlyphs.push_back(oLiteReader.GetUInteger());
++unCount;
}
if ("ofd:Glyphs" != oLiteReader.GetNameA())
continue;
const std::vector<unsigned int> arValues{oLiteReader.GetArrayUInteger()};
// oCGTransform.m_arGlyphs.insert(oCGTransform.m_arGlyphs.end(), arValues.begin(), arValues.end());
}
return oCGTransform;
@ -264,10 +263,10 @@ TCGTransform TCGTransform::Read(CXmlReader& oLiteReader)
bool TCGTransform::Draw(IRenderer* pRenderer, const LONG& lUnicode, unsigned int& unIndex, double dX, double dY) const
{
if (m_unCodePosition != unIndex || 0 == m_unCodeCount || 0 == m_unGlyphCount)
if (m_unCodePosition != unIndex || 0 == m_unCodeCount || m_arGlyphs.empty())
return false;
for (unsigned int unGlyphCount = 0; unGlyphCount < m_unGlyphCount; ++unGlyphCount)
for (unsigned int unGlyphCount = 0; unGlyphCount < m_arGlyphs.size(); ++unGlyphCount)
pRenderer->CommandDrawTextExCHAR(lUnicode, m_arGlyphs[unGlyphCount], dX, dY, 0, 0);
unIndex += m_unCodeCount;

View File

@ -47,7 +47,7 @@ bool CRes::Read(const std::wstring& wsFilePath, const std::wstring& wsRootPath)
if (!oLiteReader.FromFile(wsFullPath) || !oLiteReader.ReadNextNode() || L"ofd:Res" != oLiteReader.GetName() || oLiteReader.IsEmptyNode())
return false;
std::wstring wsResRootPath;
std::wstring wsResRootPath{wsRootPath};
if (0 != oLiteReader.GetAttributesCount() && oLiteReader.MoveToFirstAttribute())
{

View File

@ -65,4 +65,20 @@ std::vector<double> CXmlReader::GetArrayDoubles(bool bIsAttribute)
return arDoubleValues;
}
std::vector<unsigned int> CXmlReader::GetArrayUInteger(bool bIsAttribute)
{
const std::vector<std::string> arValues{Split(GetTextValueA(bIsAttribute), ' ')};
if(arValues.empty())
return std::vector<unsigned int>();
std::vector<unsigned int> arUIntValues(arValues.size());
for (unsigned int unIndex = 0; unIndex < arValues.size(); ++unIndex)
if (!StringToUInteger(arValues[unIndex], arUIntValues[unIndex]))
return std::vector<unsigned int>();
return arUIntValues;
}
}

View File

@ -20,6 +20,7 @@ public:
double GetDouble(bool bIsAttribute = false);
std::vector<std::string> GetArrayStrings(bool bIsAttribute = false);
std::vector<double> GetArrayDoubles(bool bIsAttribute = false);
std::vector<unsigned int> GetArrayUInteger(bool bIsAttribute = false);
};
}