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

Реализованы трансформы заданные в ресурсках. Реализованы ситуации, когда нужно...

Реализованы трансформы заданные в ресурсках. Реализованы ситуации, когда нужно делать ручной италик и болд.

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@63577 954022d7-b5bf-4e40-9824-e11837661b57
parent 717aa6b2
...@@ -162,4 +162,24 @@ namespace XPS ...@@ -162,4 +162,24 @@ namespace XPS
return NULL; return NULL;
} }
void CContextState::GetTransform(const CWString& _wsKey, CWString& wsTransform)
{
if (_wsKey.size() < 17)
return;
CWString wsKey((wchar_t*)(_wsKey.c_str() + 16), false, _wsKey.size() - 17);
const wchar_t* pTransform;
CStaticResource* pResource;
for (int nIndex = m_vResourcesStack.size() - 1; nIndex >= 0; nIndex--)
{
pResource = m_vResourcesStack.at(nIndex).pResource;
pTransform = pResource->GetTransform(wsKey);
if (NULL != pTransform)
{
wsTransform.create(pTransform, true);
return;
}
}
}
} }
\ No newline at end of file
...@@ -48,6 +48,7 @@ namespace XPS ...@@ -48,6 +48,7 @@ namespace XPS
void GetPathGeometry(const CWString& wsKey, CWString& wsPathData, CWString& wsPathTransform); void GetPathGeometry(const CWString& wsKey, CWString& wsPathData, CWString& wsPathTransform);
CBrush* GetBrush(const CWString& wsKey); CBrush* GetBrush(const CWString& wsKey);
void GetTransform(const CWString& wsKey, CWString& wsTransform);
Aggplus::CMatrix GetCurrentTransform() Aggplus::CMatrix GetCurrentTransform()
{ {
return m_oCurrentTransform; return m_oCurrentTransform;
......
...@@ -7,10 +7,6 @@ ...@@ -7,10 +7,6 @@
#include "Document.h" #include "Document.h"
#include "StaticResources.h" #include "StaticResources.h"
#include <iostream>
#include <ctime>
#ifndef M_PI #ifndef M_PI
#define M_PI 3.14159265358979323846 #define M_PI 3.14159265358979323846
#endif #endif
...@@ -63,15 +59,10 @@ namespace XPS ...@@ -63,15 +59,10 @@ namespace XPS
void Page::GetSize(int& nW, int& nH) const void Page::GetSize(int& nW, int& nH) const
{ {
XmlUtils::CXmlLiteReader oReader; XmlUtils::CXmlLiteReader oReader;
clock_t oBeginTime = clock();
if (!oReader.FromFile(m_wsPagePath)) if (!oReader.FromFile(m_wsPagePath))
return; return;
clock_t oEndTime = clock();
double dElapsedSecs = double(oEndTime - oBeginTime) / CLOCKS_PER_SEC;
printf("%S %fseconds\n", m_wsPagePath.c_str(), dElapsedSecs);
if (!oReader.ReadNextNode()) if (!oReader.ReadNextNode())
return; return;
...@@ -364,12 +355,16 @@ namespace XPS ...@@ -364,12 +355,16 @@ namespace XPS
bool Page::TransformToRenderer(const wchar_t* wsString, CContextState* pState) bool Page::TransformToRenderer(const wchar_t* wsString, CContextState* pState)
{ {
CWString wsTransform = wsString; CWString wsTransform = wsString;
if (!wsTransform.empty()) if (!wsTransform.empty())
{ {
std::vector<std::wstring> arrElements = NSStringExt::Split(wsString, L','); if (IsFromResource(wsTransform))
pState->GetTransform(wsTransform, wsTransform);
std::vector<CWString> arrElements = wsTransform.split(',');
double arrRes[6] ={ 1.0, 0.0, 0.0, 1.0, 0.0, 0.0 }; double arrRes[6] ={ 1.0, 0.0, 0.0, 1.0, 0.0, 0.0 };
for (int nIndex = 0, nCount = min(6, arrElements.size()); nIndex < nCount; nIndex++) for (int nIndex = 0, nCount = min(6, arrElements.size()); nIndex < nCount; nIndex++)
arrRes[nIndex] = GetDouble(arrElements[nIndex]); arrRes[nIndex] = GetDouble(arrElements[nIndex].c_str());
pState->PushTransform(arrRes); pState->PushTransform(arrRes);
return true; return true;
...@@ -393,6 +388,9 @@ namespace XPS ...@@ -393,6 +388,9 @@ namespace XPS
CWString wsFill; CWString wsFill;
bool bIsSideways = false; bool bIsSideways = false;
bool bForceItalic = false;
bool bForceBold = false;
if (oReader.MoveToFirstAttribute()) if (oReader.MoveToFirstAttribute())
{ {
std::wstring wsAttrName = oReader.GetName(); std::wstring wsAttrName = oReader.GetName();
...@@ -430,18 +428,24 @@ namespace XPS ...@@ -430,18 +428,24 @@ namespace XPS
} }
else if (L"StyleSimulations" == wsAttrName) else if (L"StyleSimulations" == wsAttrName)
{ {
std::wstring wsFontStyle = oReader.GetText(); CWString wsFontStyle = oReader.GetText();
if (L"ItalicSimulation" == wsFontStyle) if (wsFontStyle == L"ItalicSimulation")
pRenderer->put_FontStyle(0x02); {
else if (L"BoldSimulation" == wsFontStyle) bForceItalic = true;
pRenderer->put_FontStyle(0x01); }
else if (L"BoldItalicSimulation" == wsFontStyle) else if (wsFontStyle == L"BoldSimulation")
pRenderer->put_FontStyle(0x03); {
bForceBold = true;
}
else if (wsFontStyle == L"BoldItalicSimulation")
{
bForceItalic = true;
bForceBold = true;
}
} }
else if (L"FontRenderingEmSize" == wsAttrName) else if (L"FontRenderingEmSize" == wsAttrName)
{ {
std::wstring wsFontSize = oReader.GetText(); dFontSize = GetDouble(oReader.GetText());
dFontSize = GetDouble(wsFontSize);
} }
else if (L"RenderTransform" == wsAttrName) else if (L"RenderTransform" == wsAttrName)
{ {
...@@ -467,13 +471,11 @@ namespace XPS ...@@ -467,13 +471,11 @@ namespace XPS
} }
else if (L"OriginX" == wsAttrName) else if (L"OriginX" == wsAttrName)
{ {
std::wstring wsTextX = oReader.GetText(); dX = GetDouble(oReader.GetText());
dX = GetDouble(wsTextX);
} }
else if (L"OriginY" == wsAttrName) else if (L"OriginY" == wsAttrName)
{ {
std::wstring wsTextY = oReader.GetText(); dY = GetDouble(oReader.GetText());
dY = GetDouble(wsTextY);
} }
else if (L"Indices" == wsAttrName) else if (L"Indices" == wsAttrName)
{ {
...@@ -575,6 +577,25 @@ namespace XPS ...@@ -575,6 +577,25 @@ namespace XPS
m_pFontManager->LoadFontFromFile(wsFontPath, 0, (float)(dFontSize * 0.75), 96, 96); m_pFontManager->LoadFontFromFile(wsFontPath, 0, (float)(dFontSize * 0.75), 96, 96);
double dFontKoef = dFontSize / 100.0; double dFontKoef = dFontSize / 100.0;
bool bNeedItalic = false, bNeedBold = false;
if (m_pFontManager->m_pFont && m_pFontManager->m_pFont->m_pFace)
{
FT_Face pFace = m_pFontManager->m_pFont->m_pFace;
if (!(pFace->style_flags & FT_STYLE_FLAG_ITALIC) && bForceItalic)
bNeedItalic = true;
if (!(pFace->style_flags & FT_STYLE_FLAG_BOLD) && bForceBold)
{
LONG lTextColor, lTextAlpha;
pRenderer->get_BrushColor1(&lTextColor);
pRenderer->get_BrushAlpha1(&lTextAlpha);
pRenderer->put_PenColor(lTextColor);
pRenderer->put_PenAlpha(lTextAlpha);
pRenderer->put_PenSize(xpsUnitToMM(1));
bNeedBold = true;
}
}
if (!bIsSideways) if (!bIsSideways)
{ {
while (GetNextGlyph(wsIndices.c_str(), nIndicesPos, nIndicesLen, pUtf16, nUtf16Pos, unUtf16Len, oEntry)) while (GetNextGlyph(wsIndices.c_str(), nIndicesPos, nIndicesLen, pUtf16, nUtf16Pos, unUtf16Len, oEntry))
...@@ -600,10 +621,36 @@ namespace XPS ...@@ -600,10 +621,36 @@ namespace XPS
double dXorigin = (oEntry.bHorOffset || oEntry.bVerOffset) ? dX + (bRtoL ? -oEntry.dHorOffset * dFontKoef : oEntry.dHorOffset * dFontKoef) : dX; double dXorigin = (oEntry.bHorOffset || oEntry.bVerOffset) ? dX + (bRtoL ? -oEntry.dHorOffset * dFontKoef : oEntry.dHorOffset * dFontKoef) : dX;
double dYorigin = (oEntry.bHorOffset || oEntry.bVerOffset) ? dY - oEntry.dVerOffset * dFontKoef : dY; double dYorigin = (oEntry.bHorOffset || oEntry.bVerOffset) ? dY - oEntry.dVerOffset * dFontKoef : dY;
if (bNeedItalic)
{
double dAlpha = sin(-15 * M_PI / 180);
double pTransform[] ={ 1, 0, dAlpha, 1, -dAlpha * dYorigin, 0 };
pState->PushTransform(pTransform);
}
if (oEntry.bGid) if (oEntry.bGid)
pRenderer->CommandDrawTextExCHAR(oEntry.nUnicode, oEntry.nGid, xpsUnitToMM(dXorigin), xpsUnitToMM(dYorigin), 0, 0, 0, 0); pRenderer->CommandDrawTextExCHAR(oEntry.nUnicode, oEntry.nGid, xpsUnitToMM(dXorigin), xpsUnitToMM(dYorigin), 0, 0);
else else
pRenderer->CommandDrawTextCHAR(oEntry.nUnicode, xpsUnitToMM(dXorigin), xpsUnitToMM(dYorigin), 0, 0, 0); pRenderer->CommandDrawTextCHAR(oEntry.nUnicode, xpsUnitToMM(dXorigin), xpsUnitToMM(dYorigin), 0, 0);
if (bNeedBold)
{
pRenderer->BeginCommand(c_nPathType);
pRenderer->PathCommandStart();
if (oEntry.bGid)
pRenderer->PathCommandTextExCHAR(oEntry.nUnicode, oEntry.nGid, xpsUnitToMM(dXorigin), xpsUnitToMM(dYorigin), 0, 0);
else
pRenderer->PathCommandTextCHAR(oEntry.nUnicode, xpsUnitToMM(dXorigin), xpsUnitToMM(dYorigin), 0, 0);
pRenderer->DrawPath(c_nStroke);
pRenderer->EndCommand(c_nPathType);
pRenderer->PathCommandEnd();
}
if (bNeedItalic)
pState->PopTransform();
if (!bRtoL) if (!bRtoL)
dX += dAdvance; dX += dAdvance;
...@@ -626,15 +673,40 @@ namespace XPS ...@@ -626,15 +673,40 @@ namespace XPS
double dXorigin = (oEntry.bHorOffset || oEntry.bVerOffset) ? dX + oEntry.dHorOffset * dFontKoef : dX; double dXorigin = (oEntry.bHorOffset || oEntry.bVerOffset) ? dX + oEntry.dHorOffset * dFontKoef : dX;
double dYorigin = (oEntry.bHorOffset || oEntry.bVerOffset) ? dY - oEntry.dVerOffset * dFontKoef : dY; double dYorigin = (oEntry.bHorOffset || oEntry.bVerOffset) ? dY - oEntry.dVerOffset * dFontKoef : dY;
if (bNeedItalic)
{
double dAlpha = sin(15 * M_PI / 180);
double pTransform[] ={ 1, dAlpha, 0, 1, 0, -dAlpha * dXorigin };
pState->PushTransform(pTransform);
}
double pTransform[] ={ 0, -1, 1, 0, dXorigin + dAdvanceY, dYorigin + dAdvanceX / 2 }; double pTransform[] ={ 0, -1, 1, 0, dXorigin + dAdvanceY, dYorigin + dAdvanceX / 2 };
pState->PushTransform(pTransform); pState->PushTransform(pTransform);
if (oEntry.bGid) if (oEntry.bGid)
pRenderer->CommandDrawTextExCHAR(oEntry.nUnicode, oEntry.nGid, 0, 0, 0, 0, 0, 0); pRenderer->CommandDrawTextExCHAR(oEntry.nUnicode, oEntry.nGid, 0, 0, 0, 0);
else else
pRenderer->CommandDrawTextCHAR(oEntry.nUnicode, 0, 0, 0, 0, 0); pRenderer->CommandDrawTextCHAR(oEntry.nUnicode, 0, 0, 0, 0);
if (bNeedBold)
{
pRenderer->BeginCommand(c_nPathType);
pRenderer->PathCommandStart();
if (oEntry.bGid)
pRenderer->PathCommandTextExCHAR(oEntry.nUnicode, oEntry.nGid, 0, 0, 0, 0);
else
pRenderer->PathCommandTextCHAR(oEntry.nUnicode, 0, 0, 0, 0);
pRenderer->DrawPath(c_nStroke);
pRenderer->EndCommand(c_nPathType);
pRenderer->PathCommandEnd();
}
pState->PopTransform(); pState->PopTransform();
if (bNeedItalic)
pState->PopTransform();
dX += dAdvance; dX += dAdvance;
} }
} }
...@@ -865,7 +937,7 @@ namespace XPS ...@@ -865,7 +937,7 @@ namespace XPS
pRenderer->put_PenDashStyle(Aggplus::DashStyleCustom); pRenderer->put_PenDashStyle(Aggplus::DashStyleCustom);
pRenderer->PenDashPattern(pDashPattern, lDashPatternSize); pRenderer->PenDashPattern(pDashPattern, lDashPatternSize);
pRenderer->put_PenDashOffset(dDashOffset); pRenderer->put_PenDashOffset(xpsUnitToMM(dDashOffset * dPenSize));
pRenderer->put_PenLineStartCap(nDashCap); pRenderer->put_PenLineStartCap(nDashCap);
pRenderer->put_PenLineEndCap(nDashCap); pRenderer->put_PenLineEndCap(nDashCap);
delete[] pDashPattern; delete[] pDashPattern;
......
...@@ -51,6 +51,14 @@ namespace XPS ...@@ -51,6 +51,14 @@ namespace XPS
return NULL; return NULL;
} }
const wchar_t* CStaticResource::GetTransform(CWString& wsKey)
{
std::map<CWString, CWString>::iterator oIter = m_mTransforms.find(wsKey);
if (oIter != m_mTransforms.end())
return oIter->second.c_str();
return NULL;
}
void CStaticResource::Parse(XmlUtils::CXmlLiteReader& oReader) void CStaticResource::Parse(XmlUtils::CXmlLiteReader& oReader)
{ {
CWString wsNodeName; CWString wsNodeName;
...@@ -95,6 +103,13 @@ namespace XPS ...@@ -95,6 +103,13 @@ namespace XPS
if (pBrush) if (pBrush)
AddBrush(wsKey, pBrush); AddBrush(wsKey, pBrush);
} }
else if (wsNodeName == L"MatrixTransform")
{
CWString wsKey, wsValue;
ReadMatrixTransform(oReader, wsValue, &wsKey);
if (!wsKey.empty() && !wsValue.empty())
AddTransform(wsKey, wsValue);
}
} }
} }
void CStaticResource::AddFigure(const CWString& wsKey, const CWString& wsValue) void CStaticResource::AddFigure(const CWString& wsKey, const CWString& wsValue)
...@@ -105,7 +120,10 @@ namespace XPS ...@@ -105,7 +120,10 @@ namespace XPS
{ {
m_mBrushes.insert(std::pair<CWString, CBrush*>(wsKey, pBrush)); m_mBrushes.insert(std::pair<CWString, CBrush*>(wsKey, pBrush));
} }
void CStaticResource::AddTransform(const CWString& wsKey, const CWString& wsValue)
{
m_mTransforms.insert(std::pair<CWString, CWString>(wsKey, wsValue));
}
bool CSolidBrush::SetToRenderer(IRenderer* pRenderer) bool CSolidBrush::SetToRenderer(IRenderer* pRenderer)
{ {
pRenderer->put_BrushType(c_BrushTypeSolid); pRenderer->put_BrushType(c_BrushTypeSolid);
......
...@@ -19,17 +19,20 @@ namespace XPS ...@@ -19,17 +19,20 @@ namespace XPS
~CStaticResource(); ~CStaticResource();
const wchar_t* GetFigure(CWString& wsKey); const wchar_t* GetFigure(CWString& wsKey);
CBrush* GetBrush(CWString& wsKey); CBrush* GetBrush(CWString& wsKey);
const wchar_t* GetTransform(CWString& wsKey);
private: private:
void Parse(XmlUtils::CXmlLiteReader& oReader); void Parse(XmlUtils::CXmlLiteReader& oReader);
void AddFigure(const CWString& wsKey, const CWString& wsValue); void AddFigure(const CWString& wsKey, const CWString& wsValue);
void AddBrush(const CWString& wsKey, CBrush* pBrush); void AddBrush(const CWString& wsKey, CBrush* pBrush);
void AddTransform(const CWString& wsKey, const CWString& wsValue);
private: private:
std::map<CWString, CWString> m_mFigures; std::map<CWString, CWString> m_mFigures;
std::map<CWString, CBrush*> m_mBrushes; std::map<CWString, CBrush*> m_mBrushes;
std::map<CWString, CWString> m_mTransforms;
}; };
class CBrush class CBrush
......
...@@ -310,6 +310,7 @@ namespace XPSEllipse ...@@ -310,6 +310,7 @@ namespace XPSEllipse
dCy1 = SQRT(dRoot); dCy1 = SQRT(dRoot);
dCy2 = -dCy1; dCy2 = -dCy1;
} }
return true;
} }
inline bool GetEllipses (const double& dX1, const double& dY1, double& dRadX, double& dRadY, double& dCx1, double& dCy1, double& dCx2, double& dCy2) inline bool GetEllipses (const double& dX1, const double& dY1, double& dRadX, double& dRadY, double& dCx1, double& dCy1, double& dCx2, double& dCy2)
{ {
...@@ -1376,7 +1377,31 @@ namespace XPS ...@@ -1376,7 +1377,31 @@ namespace XPS
else else
return false; // Такого не должно быть return false; // Такого не должно быть
} }
void ReadTransform (XmlUtils::CXmlLiteReader& oReader, CWString& wsTransform, CWString* pwsKey) void ReadMatrixTransform(XmlUtils::CXmlLiteReader& oReader, CWString& wsTransform, CWString* pwsKey)
{
if (oReader.GetAttributesCount() <= 0)
return;
if (!oReader.MoveToFirstAttribute())
return;
CWString wsAttrName = oReader.GetName();
while (!wsAttrName.empty())
{
if (wsAttrName == L"Matrix")
wsTransform.create(oReader.GetText(), true);
else if (wsAttrName == L"x:Key" && pwsKey)
pwsKey->create(oReader.GetText(), true);
if (!oReader.MoveToNextAttribute())
break;
wsAttrName = oReader.GetName();
}
oReader.MoveToElement();
}
void ReadTransform (XmlUtils::CXmlLiteReader& oReader, CWString& wsTransform, CWString* pwsKey)
{ {
CWString wsNodeName; CWString wsNodeName;
int nCurDepth = oReader.GetDepth(); int nCurDepth = oReader.GetDepth();
...@@ -1385,27 +1410,7 @@ namespace XPS ...@@ -1385,27 +1410,7 @@ namespace XPS
wsNodeName = oReader.GetName(); wsNodeName = oReader.GetName();
if (wsNodeName == L"MatrixTransform") if (wsNodeName == L"MatrixTransform")
{ {
if (oReader.GetAttributesCount() <= 0) ReadMatrixTransform(oReader, wsTransform, pwsKey);
return;
if (!oReader.MoveToFirstAttribute())
return;
CWString wsAttrName = oReader.GetName();
while (!wsAttrName.empty())
{
if (wsAttrName == L"Matrix")
wsTransform.create(oReader.GetText(), true);
else if (wsAttrName == L"x:Key" && pwsKey)
pwsKey->create(oReader.GetText(), true);
if (!oReader.MoveToNextAttribute())
break;
wsAttrName = oReader.GetName();
}
oReader.MoveToElement();
} }
} }
} }
......
...@@ -83,9 +83,10 @@ namespace XPS ...@@ -83,9 +83,10 @@ namespace XPS
void ReadSTColor(const CWString& wsString, LONG& lColor); void ReadSTColor(const CWString& wsString, LONG& lColor);
void ReadSTDouble(const CWString& wsString, double& dValue); void ReadSTDouble(const CWString& wsString, double& dValue);
void ReadTransform (XmlUtils::CXmlLiteReader& oReader, CWString& wsTransform, CWString* pwsKey = NULL); void ReadMatrixTransform(XmlUtils::CXmlLiteReader& oReader, CWString& wsTransform, CWString* pwsKey = NULL);
void ReadPathGeometry(XmlUtils::CXmlLiteReader& oReader, CWString& wsData, CWString& wsTransform, CWString* pwsKey = NULL); void ReadTransform (XmlUtils::CXmlLiteReader& oReader, CWString& wsTransform, CWString* pwsKey = NULL);
void ReadPathFigure (XmlUtils::CXmlLiteReader& oReader, std::wstring&, bool bEvenOdd); void ReadPathGeometry (XmlUtils::CXmlLiteReader& oReader, CWString& wsData, CWString& wsTransform, CWString* pwsKey = NULL);
void ReadPathFigure (XmlUtils::CXmlLiteReader& oReader, std::wstring&, bool bEvenOdd);
void ReadGradientStops(XmlUtils::CXmlLiteReader& oReader, std::vector<LONG>& vColors, std::vector<double>& vPositions, const double& dOpacity); void ReadGradientStops(XmlUtils::CXmlLiteReader& oReader, std::vector<LONG>& vColors, std::vector<double>& vPositions, const double& dOpacity);
} }
......
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