Commit 060eea09 authored by Ilya.Kirillov's avatar Ilya.Kirillov Committed by Alexander Trofimov

Написан полноценный парсер атрибутов Indices и UnicodeString у ноды Glyph.

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@63459 954022d7-b5bf-4e40-9824-e11837661b57
parent 22f9c18c
...@@ -218,14 +218,18 @@ namespace XPS ...@@ -218,14 +218,18 @@ namespace XPS
int nBgr = 0, nAlpha = 255; int nBgr = 0, nAlpha = 255;
double dFontSize = 10.0; double dFontSize = 10.0;
bool bTransform = false, bClip = false, bOpacity = false; bool bTransform = false, bClip = false, bOpacity = false;
int nTextLen = 0; unsigned int unTextLen = 0;
std::wstring wsText;
double dX = 0; double dX = 0;
double dY = 0; double dY = 0;
std::wstring wsFontPath; std::wstring wsFontPath;
std::wstring wsIndicies; std::wstring wsIndicies;
int nBidiLevel = 0; int nBidiLevel = 0;
CWString wsClip, wsTransform; CWString wsClip, wsTransform;
unsigned int* pUnicodes = NULL;
unsigned int* pUnicodesPtr = NULL;
CWString wsUnicodeString, wsIndices;
if (oReader.MoveToFirstAttribute()) if (oReader.MoveToFirstAttribute())
{ {
std::wstring wsAttrName = oReader.GetName(); std::wstring wsAttrName = oReader.GetName();
...@@ -282,14 +286,20 @@ namespace XPS ...@@ -282,14 +286,20 @@ namespace XPS
} }
else if (L"UnicodeString" == wsAttrName) else if (L"UnicodeString" == wsAttrName)
{ {
wsText = oReader.GetText(); wsUnicodeString.create(oReader.GetText(), true);
nTextLen = wsText.length();
pUnicodesPtr = NSStringExt::CConverter::GetUtf32FromUnicode(wsUnicodeString.c_str(), unTextLen);
if (nTextLen >= 2 && '{' == wsText.at(0) && '}' == wsText.at(1)) if (unTextLen >= 2 && '{' == pUnicodesPtr[0] && '}' == pUnicodesPtr[1])
{ {
wsText = wsText.substr(2); pUnicodes = pUnicodesPtr + 2;
nTextLen -= 2; unTextLen -= 2;
} }
else
{
pUnicodes = pUnicodesPtr;
}
} }
else if (L"OriginX" == wsAttrName) else if (L"OriginX" == wsAttrName)
{ {
...@@ -303,6 +313,7 @@ namespace XPS ...@@ -303,6 +313,7 @@ namespace XPS
} }
else if (L"Indices" == wsAttrName) else if (L"Indices" == wsAttrName)
{ {
wsIndices.create(oReader.GetText(), true);
wsIndicies = oReader.GetText(); wsIndicies = oReader.GetText();
} }
else if (L"BidiLevel" == wsAttrName) else if (L"BidiLevel" == wsAttrName)
...@@ -357,13 +368,23 @@ namespace XPS ...@@ -357,13 +368,23 @@ namespace XPS
pRenderer->put_BrushType(c_BrushTypeSolid); pRenderer->put_BrushType(c_BrushTypeSolid);
pRenderer->put_FontSize(dFontSize * 0.75); pRenderer->put_FontSize(dFontSize * 0.75);
std::wstring wsChar = wsText.substr(0, 1); TIndicesEntry oEntry;
std::vector<std::vector<std::wstring>> arrElements = Split(wsIndicies, L';', L','); int nIndicesPos = 0, nIndicesLen = wsIndices.size();
int nUtf16Pos = 0, nUtf16Len = wsUnicodeString.size();
while (GetNextGlyph(wsIndices.c_str(), nIndicesPos, nIndicesLen, (unsigned short*)wsUnicodeString.c_str(), nUtf16Pos, nUtf16Len, oEntry))
{
int k = 10;
k++;
}
std::vector<std::vector<std::wstring>> arrElements = Split(wsIndicies, L';', L',');
bool bRtoL = (nBidiLevel % 2 ? true : false); bool bRtoL = (nBidiLevel % 2 ? true : false);
m_pFontManager->LoadFontFromFile(wsFontPath, 0, (float)(dFontSize * 0.75), 96, 96); m_pFontManager->LoadFontFromFile(wsFontPath, 0, (float)(dFontSize * 0.75), 96, 96);
for (int nIndex = 0; nIndex < nTextLen; nIndex++) if (pUnicodesPtr)
{ {
for (int nIndex = 0; nIndex < unTextLen; nIndex++)
{
std::wstring wsChar = NSStringExt::CConverter::GetUnicodeFromUTF32((const unsigned int*)(pUnicodes + nIndex), 1);
if (nIndex >= arrElements.size()) if (nIndex >= arrElements.size())
arrElements.push_back(std::vector<std::wstring>()); arrElements.push_back(std::vector<std::wstring>());
...@@ -379,11 +400,13 @@ namespace XPS ...@@ -379,11 +400,13 @@ namespace XPS
TBBox oBox = m_pFontManager->MeasureString2(); TBBox oBox = m_pFontManager->MeasureString2();
dX -= (oBox.fMaxX - oBox.fMinX); dX -= (oBox.fMaxX - oBox.fMinX);
} }
pRenderer->CommandDrawText(wsChar, xpsUnitToMM(dX), xpsUnitToMM(dY), 0, 0, 0); pRenderer->CommandDrawTextEx(wsChar, L"", xpsUnitToMM(dX), xpsUnitToMM(dY), 0, 0, 0, 0);
} }
else else
{ {
pRenderer->CommandDrawText(wsChar, xpsUnitToMM(dX), xpsUnitToMM(dY), 0, 0, 0); pRenderer->CommandDrawTextEx(wsChar, L"", xpsUnitToMM(dX), xpsUnitToMM(dY), 0, 0, 0, 0);
if (nIndex < unTextLen - 1)
{
if (arrElements.at(nIndex).size() >= 2) if (arrElements.at(nIndex).size() >= 2)
{ {
dX += GetDouble(arrElements.at(nIndex).at(1)) * dFontSize / 100.0; dX += GetDouble(arrElements.at(nIndex).at(1)) * dFontSize / 100.0;
...@@ -395,8 +418,10 @@ namespace XPS ...@@ -395,8 +418,10 @@ namespace XPS
dX += (oBox.fMaxX - oBox.fMinX); dX += (oBox.fMaxX - oBox.fMinX);
} }
} }
}
}
wsChar = wsText.substr(nIndex + 1, 1); delete[] pUnicodesPtr;
} }
if (bClip) if (bClip)
......
...@@ -41,6 +41,7 @@ namespace XPS ...@@ -41,6 +41,7 @@ namespace XPS
CWString ReadMatrixTransform(XmlUtils::CXmlLiteReader& oReader); CWString ReadMatrixTransform(XmlUtils::CXmlLiteReader& oReader);
CWString ReadClip (XmlUtils::CXmlLiteReader& oReader); CWString ReadClip (XmlUtils::CXmlLiteReader& oReader);
private: private:
std::wstring m_wsPagePath; std::wstring m_wsPagePath;
......
This diff is collapsed.
...@@ -41,6 +41,31 @@ namespace XPS ...@@ -41,6 +41,31 @@ namespace XPS
unsigned int m_unLen; unsigned int m_unLen;
bool m_bOwnBuffer; bool m_bOwnBuffer;
}; };
struct TIndicesEntry
{
public:
TIndicesEntry() : nUnicode(0), nGid(0), dAdvance(0.0), dHorOffset(0.0), dVerOffset(0.0),
bUnicode(false), bGid(false), bAdvance(false), bHorOffset(false), bVerOffset(false)
{
}
public:
unsigned int nUnicode;
unsigned short nGid;
double dAdvance;
double dHorOffset;
double dVerOffset;
bool bUnicode;
bool bGid;
bool bAdvance;
bool bHorOffset;
bool bVerOffset;
std::vector<unsigned int> vRemainUnicodes;
};
bool IsAlpha(wchar_t wChar); bool IsAlpha(wchar_t wChar);
...@@ -62,6 +87,7 @@ namespace XPS ...@@ -62,6 +87,7 @@ namespace XPS
void ReadAttribute(XmlUtils::CXmlLiteReader& oReader, const wchar_t* wsAttrName, std::wstring& wsAttr); void ReadAttribute(XmlUtils::CXmlLiteReader& oReader, const wchar_t* wsAttrName, std::wstring& wsAttr);
void ReadAttribute(XmlUtils::CXmlLiteReader& oReader, const wchar_t* wsAttrName, CWString& wsAttr); void ReadAttribute(XmlUtils::CXmlLiteReader& oReader, const wchar_t* wsAttrName, CWString& wsAttr);
bool VmlToRenderer(const wchar_t* wsString, IRenderer* pRenderer); bool VmlToRenderer(const wchar_t* wsString, IRenderer* pRenderer);
bool GetNextGlyph(const wchar_t* wsIndices, int& nIndicesPos, const int& nIndicesLen, unsigned short* pUtf16, int& nUtf16Pos, const int& nUtf16Len, TIndicesEntry& oEntry);
} }
#endif // _XPS_XPSLIB_UTILS_H #endif // _XPS_XPSLIB_UTILS_H
\ 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