Aff offset metafile command

This commit is contained in:
Prokhorov Kirill
2025-09-25 13:58:55 +03:00
parent d50d1b04e5
commit 2931c4b53e
7 changed files with 97 additions and 5 deletions

View File

@ -462,6 +462,33 @@ namespace Aggplus
return Ok;
}
CGraphicsPath CGraphicsPath::Trsanslate(const double& offsetX, const double& offsetY)
{
CGraphicsPath result;
result.StartFigure();
unsigned length = GetPointCount();
std::vector<Aggplus::PointD> points = GetPoints(0, length);
for (unsigned i = 0; i < length; i++)
{
if (IsCurvePoint(i))
{
result.CurveTo(points[i].X + offsetX, points[i].Y + offsetY,
points[i + 1].X + offsetX, points[i + 1].Y + offsetY,
points[i + 2].X + offsetX, points[i + 2].Y + offsetY);
i += 2;
}
else if (IsMovePoint(i))
result.MoveTo(points[i].X + offsetX, points[i].Y + offsetY);
else if (IsLinePoint(i))
result.LineTo(points[i].X + offsetX, points[i].Y + offsetY);
}
result.CloseFigure();
return result;
}
bool CGraphicsPath::_MoveTo(double x, double y)
{
if (NULL != m_internal->m_pTransform)

View File

@ -84,6 +84,7 @@ namespace Aggplus
void GetBoundsAccurate(double& left, double& top, double& width, double& height) const;
Status Transform(const CMatrix* matrix);
CGraphicsPath Trsanslate(const double& offsetX, const double& offsetY);
virtual bool _MoveTo(double x, double y);
virtual bool _LineTo(double x, double y);
virtual bool _CurveTo(double x1, double y1, double x2, double y2, double x3, double y3);

View File

@ -1130,6 +1130,32 @@ HRESULT CGraphicsRenderer::PathCommandTextEx(const std::wstring& bsUnicodeText,
return PathCommandText(bsUnicodeText, x, y, w, h);
}
HRESULT CGraphicsRenderer::AddPath(const Aggplus::CGraphicsPath& path)
{
if (path.GetPointCount() == 0)
return S_FALSE;
size_t length = path.GetPointCount();
std::vector<Aggplus::PointD> points = path.GetPoints(0, length);
for (size_t i = 0; i < length; i++)
{
if (path.IsCurvePoint(i))
{
PathCommandCurveTo(points[i].X, points[i].Y,
points[i + 1].X, points[i + 1].Y,
points[i + 2].X, points[i + 2].Y);
i += 2;
}
else if (path.IsMovePoint(i))
PathCommandMoveTo(points[i].X, points[i].Y);
else
PathCommandLineTo(points[i].X, points[i].Y);
}
return S_OK;
}
//-------- Функции для вывода изображений ---------------------------------------------------
HRESULT CGraphicsRenderer::DrawImage(IGrObject* pImage, const double& x, const double& y, const double& w, const double& h)
{

View File

@ -239,6 +239,8 @@ public:
virtual HRESULT PathCommandTextExCHAR(const LONG& c, const LONG& gid, const double& x, const double& y, const double& w, const double& h);
virtual HRESULT PathCommandTextEx(const std::wstring& sText, const unsigned int* pGids, const unsigned int nGidsCount, const double& x, const double& y, const double& w, const double& h);
virtual HRESULT AddPath(const Aggplus::CGraphicsPath& path);
//-------- Функции для вывода изображений ---------------------------------------------------
virtual HRESULT DrawImage(IGrObject* pImage, const double& x, const double& y, const double& w, const double& h);
virtual HRESULT DrawImageFromFile(const std::wstring& sFile, const double& x, const double& y, const double& w, const double& h, const BYTE& lAlpha = 255);

View File

@ -167,7 +167,10 @@ public:
AdvancedCommandType GetCommandType() { return m_nCommandType; }
};
namespace Aggplus { class CImage; }
namespace Aggplus {
class CImage;
class CGraphicsPath;
}
// IRenderer
class IRenderer : public IGrObject
@ -298,6 +301,8 @@ public:
virtual HRESULT PathCommandTextExCHAR(const LONG& c, const LONG& gid, const double& x, const double& y, const double& w, const double& h) = 0;
virtual HRESULT PathCommandTextEx(const std::wstring& sText, const unsigned int* pGids, const unsigned int nGidsCount, const double& x, const double& y, const double& w, const double& h) = 0;
virtual HRESULT AddPath(const Aggplus::CGraphicsPath& path) = 0;
//-------- Функции для вывода изображений ---------------------------------------------------
virtual HRESULT DrawImage(IGrObject* pImage, const double& x, const double& y, const double& w, const double& h) = 0;
virtual HRESULT DrawImageFromFile(const std::wstring&, const double& x, const double& y, const double& w, const double& h, const BYTE& lAlpha = 255) = 0;

View File

@ -36,6 +36,7 @@
#include "../fontengine/FontManager.h"
#include "../raster/BgraFrame.h"
#include "../common/StringExt.h"
#include "../GraphicsPath.h"
// этот класс нужно переписать. должно работать как и в js
// а не просто на каждом символе переключаться, если нужно
@ -352,6 +353,10 @@ namespace NSOnlineOfficeBinToPdf
bool bIsEnableBrushRect = false;
CBufferReader oReader(pBuffer, lBufferLen);
Aggplus::CGraphicsPath path;
Aggplus::CGraphicsPath clipPath;
bool isClip = false;
bool isClose = false;
while (oReader.Check())
{
eCommand = (CommandType)(oReader.ReadByte());
@ -611,6 +616,7 @@ namespace NSOnlineOfficeBinToPdf
pRenderer->BeginCommand(c_nPathType);
pRenderer->PathCommandStart();
path.StartFigure();
bIsPathOpened = true;
break;
@ -619,14 +625,14 @@ namespace NSOnlineOfficeBinToPdf
{
double m1 = oReader.ReadDouble();
double m2 = oReader.ReadDouble();
pRenderer->PathCommandMoveTo(m1, m2);
path.MoveTo(m1, m2);
break;
}
case ctPathCommandLineTo:
{
double m1 = oReader.ReadDouble();
double m2 = oReader.ReadDouble();
pRenderer->PathCommandLineTo(m1, m2);
path.LineTo(m1, m2);
break;
}
case ctPathCommandCurveTo:
@ -637,12 +643,13 @@ namespace NSOnlineOfficeBinToPdf
double m4 = oReader.ReadDouble();
double m5 = oReader.ReadDouble();
double m6 = oReader.ReadDouble();
pRenderer->PathCommandCurveTo(m1, m2, m3, m4, m5, m6);
path.CurveTo(m1, m2, m3, m4, m5, m6);
break;
}
case ctPathCommandClose:
{
pRenderer->PathCommandClose();
path.CloseFigure();
isClose = true;
break;
}
case ctPathCommandEnd:
@ -655,9 +662,32 @@ namespace NSOnlineOfficeBinToPdf
}
break;
}
case ctPathCommandOffset:
{
double m1 = oReader.ReadDouble();
double m2 = oReader.ReadDouble();
isClip = true;
clipPath = path.Trsanslate(m1, m2);
}
case ctDrawPath:
{
if (isClip)
{
path = Aggplus::CalcBooleanOperation(path, clipPath, Aggplus::Intersection);
clipPath.Reset();
isClip = false;
}
pRenderer->AddPath(path);
if (isClose)
{
pRenderer->PathCommandClose();
isClose = false;
}
pRenderer->DrawPath(oReader.ReadInt());
path.Reset();
break;
}
case ctDrawImageFromFile:

View File

@ -153,6 +153,7 @@ namespace NSOnlineOfficeBinToPdf
ctPathCommandGetCurrentPoint = 101,
ctPathCommandText = 102,
ctPathCommandTextEx = 103,
ctPathCommandOffset = 104,
// image
ctDrawImage = 110,