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
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
void GetPathGeometry(const CWString& wsKey, CWString& wsPathData, CWString& wsPathTransform);
CBrush* GetBrush(const CWString& wsKey);
void GetTransform(const CWString& wsKey, CWString& wsTransform);
Aggplus::CMatrix GetCurrentTransform()
{
return m_oCurrentTransform;
......
......@@ -7,10 +7,6 @@
#include "Document.h"
#include "StaticResources.h"
#include <iostream>
#include <ctime>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
......@@ -63,15 +59,10 @@ namespace XPS
void Page::GetSize(int& nW, int& nH) const
{
XmlUtils::CXmlLiteReader oReader;
clock_t oBeginTime = clock();
if (!oReader.FromFile(m_wsPagePath))
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())
return;
......@@ -364,12 +355,16 @@ namespace XPS
bool Page::TransformToRenderer(const wchar_t* wsString, CContextState* pState)
{
CWString wsTransform = wsString;
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 };
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);
return true;
......@@ -393,6 +388,9 @@ namespace XPS
CWString wsFill;
bool bIsSideways = false;
bool bForceItalic = false;
bool bForceBold = false;
if (oReader.MoveToFirstAttribute())
{
std::wstring wsAttrName = oReader.GetName();
......@@ -430,18 +428,24 @@ namespace XPS
}
else if (L"StyleSimulations" == wsAttrName)
{
std::wstring wsFontStyle = oReader.GetText();
if (L"ItalicSimulation" == wsFontStyle)
pRenderer->put_FontStyle(0x02);
else if (L"BoldSimulation" == wsFontStyle)
pRenderer->put_FontStyle(0x01);
else if (L"BoldItalicSimulation" == wsFontStyle)
pRenderer->put_FontStyle(0x03);
CWString wsFontStyle = oReader.GetText();
if (wsFontStyle == L"ItalicSimulation")
{
bForceItalic = true;
}
else if (wsFontStyle == L"BoldSimulation")
{
bForceBold = true;
}
else if (wsFontStyle == L"BoldItalicSimulation")
{
bForceItalic = true;
bForceBold = true;
}
}
else if (L"FontRenderingEmSize" == wsAttrName)
{
std::wstring wsFontSize = oReader.GetText();
dFontSize = GetDouble(wsFontSize);
dFontSize = GetDouble(oReader.GetText());
}
else if (L"RenderTransform" == wsAttrName)
{
......@@ -467,13 +471,11 @@ namespace XPS
}
else if (L"OriginX" == wsAttrName)
{
std::wstring wsTextX = oReader.GetText();
dX = GetDouble(wsTextX);
dX = GetDouble(oReader.GetText());
}
else if (L"OriginY" == wsAttrName)
{
std::wstring wsTextY = oReader.GetText();
dY = GetDouble(wsTextY);
dY = GetDouble(oReader.GetText());
}
else if (L"Indices" == wsAttrName)
{
......@@ -575,6 +577,25 @@ namespace XPS
m_pFontManager->LoadFontFromFile(wsFontPath, 0, (float)(dFontSize * 0.75), 96, 96);
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)
{
while (GetNextGlyph(wsIndices.c_str(), nIndicesPos, nIndicesLen, pUtf16, nUtf16Pos, unUtf16Len, oEntry))
......@@ -600,10 +621,36 @@ namespace XPS
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;
if (bNeedItalic)
{
double dAlpha = sin(-15 * M_PI / 180);
double pTransform[] ={ 1, 0, dAlpha, 1, -dAlpha * dYorigin, 0 };
pState->PushTransform(pTransform);
}
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
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)
dX += dAdvance;
......@@ -626,15 +673,40 @@ namespace XPS
double dXorigin = (oEntry.bHorOffset || oEntry.bVerOffset) ? dX + oEntry.dHorOffset * dFontKoef : dX;
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 };
pState->PushTransform(pTransform);
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
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();
if (bNeedItalic)
pState->PopTransform();
dX += dAdvance;
}
}
......@@ -865,7 +937,7 @@ namespace XPS
pRenderer->put_PenDashStyle(Aggplus::DashStyleCustom);
pRenderer->PenDashPattern(pDashPattern, lDashPatternSize);
pRenderer->put_PenDashOffset(dDashOffset);
pRenderer->put_PenDashOffset(xpsUnitToMM(dDashOffset * dPenSize));
pRenderer->put_PenLineStartCap(nDashCap);
pRenderer->put_PenLineEndCap(nDashCap);
delete[] pDashPattern;
......
......@@ -51,6 +51,14 @@ namespace XPS
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)
{
CWString wsNodeName;
......@@ -95,6 +103,13 @@ namespace XPS
if (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)
......@@ -105,7 +120,10 @@ namespace XPS
{
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)
{
pRenderer->put_BrushType(c_BrushTypeSolid);
......
......@@ -19,17 +19,20 @@ namespace XPS
~CStaticResource();
const wchar_t* GetFigure(CWString& wsKey);
CBrush* GetBrush(CWString& wsKey);
const wchar_t* GetTransform(CWString& wsKey);
private:
void Parse(XmlUtils::CXmlLiteReader& oReader);
void AddFigure(const CWString& wsKey, const CWString& wsValue);
void AddBrush(const CWString& wsKey, CBrush* pBrush);
void AddTransform(const CWString& wsKey, const CWString& wsValue);
private:
std::map<CWString, CWString> m_mFigures;
std::map<CWString, CBrush*> m_mBrushes;
std::map<CWString, CWString> m_mTransforms;
};
class CBrush
......
......@@ -310,6 +310,7 @@ namespace XPSEllipse
dCy1 = SQRT(dRoot);
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)
{
......@@ -1376,7 +1377,31 @@ namespace XPS
else
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;
int nCurDepth = oReader.GetDepth();
......@@ -1385,27 +1410,7 @@ namespace XPS
wsNodeName = oReader.GetName();
if (wsNodeName == L"MatrixTransform")
{
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();
ReadMatrixTransform(oReader, wsTransform, pwsKey);
}
}
}
......
......@@ -83,9 +83,10 @@ namespace XPS
void ReadSTColor(const CWString& wsString, LONG& lColor);
void ReadSTDouble(const CWString& wsString, double& dValue);
void ReadTransform (XmlUtils::CXmlLiteReader& oReader, CWString& wsTransform, CWString* pwsKey = NULL);
void ReadPathGeometry(XmlUtils::CXmlLiteReader& oReader, CWString& wsData, CWString& wsTransform, CWString* pwsKey = NULL);
void ReadPathFigure (XmlUtils::CXmlLiteReader& oReader, std::wstring&, bool bEvenOdd);
void ReadMatrixTransform(XmlUtils::CXmlLiteReader& oReader, CWString& wsTransform, CWString* pwsKey = NULL);
void ReadTransform (XmlUtils::CXmlLiteReader& oReader, CWString& wsTransform, CWString* pwsKey = NULL);
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);
}
......
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