Merge remote-tracking branch 'origin/feature/texture-fill' into release/v9.3.0

This commit is contained in:
Oleg Korshul
2025-12-23 19:34:09 +03:00
11 changed files with 294 additions and 11 deletions

View File

@ -419,6 +419,7 @@ namespace Aggplus
m_bReleaseImage = FALSE;
Alpha = 255;
m_bUseBounds = false;
m_bIsScale = false;
}
CBrushTexture::CBrushTexture(const std::wstring& strName, WrapMode wrapMode) : CBrush(BrushTypeTextureFill), m_wrapMode(wrapMode)
@ -427,6 +428,7 @@ namespace Aggplus
m_bReleaseImage = TRUE;
Alpha = 255;
m_bUseBounds = false;
m_bIsScale = false;
}
CBrushTexture::CBrushTexture(CImage *pImage, WrapMode wrapMode) : CBrush(BrushTypeTextureFill), m_wrapMode(wrapMode)
@ -435,6 +437,7 @@ namespace Aggplus
m_bReleaseImage = FALSE;
Alpha = 255;
m_bUseBounds = false;
m_bIsScale = false;
}
CBrushTexture::~CBrushTexture()

View File

@ -205,6 +205,10 @@ public:
bool m_bUseBounds;
CDoubleRect m_oBounds;
bool m_bIsScale;
double m_dScaleX;
double m_dScaleY;
BYTE Alpha;
};
}

View File

@ -847,6 +847,8 @@ namespace Aggplus
double dScaleY = m_dDpiY / m_dDpiTile;
brushMatrix.Scale(dScaleX, dScaleY, Aggplus::MatrixOrderAppend);
if (ptxBrush->m_bIsScale)
brushMatrix.Scale(ptxBrush->m_dScaleX, ptxBrush->m_dScaleY, Aggplus::MatrixOrderAppend);
}
brushMatrix.Translate(x, y, Aggplus::MatrixOrderAppend);

View File

@ -1549,3 +1549,31 @@ namespace Aggplus
return false;
}
}
HRESULT IRenderer::AddPath(const Aggplus::CGraphicsPath& path)
{
if (path.GetPointCount() == 0)
return S_FALSE;
size_t length = path.GetPointCount() + path.GetCloseCount();
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 if (path.IsLinePoint(i))
PathCommandLineTo(points[i].X, points[i].Y);
else
PathCommandClose();
}
return S_OK;
}

View File

@ -613,6 +613,32 @@ HRESULT CGraphicsRenderer::put_BrushTransform(const Aggplus::CMatrix& oMatrix)
m_oBrush.Transform = oMatrix;
return S_OK;
}
HRESULT CGraphicsRenderer::get_BrushOffset(double& offsetX, double& offsetY) const
{
offsetX = m_oBrush.OffsetX;
offsetY = m_oBrush.OffsetY;
return S_OK;
}
HRESULT CGraphicsRenderer::put_BrushOffset(const double& offsetX, const double& offsetY)
{
m_oBrush.OffsetX = offsetX;
m_oBrush.OffsetY = offsetY;
return S_OK;
}
HRESULT CGraphicsRenderer::get_BrushScale(bool& isScale, double& scaleX, double& scaleY) const
{
isScale = m_oBrush.IsScale;
scaleX = m_oBrush.ScaleX;
scaleY = m_oBrush.ScaleY;
return S_OK;
}
HRESULT CGraphicsRenderer::put_BrushScale(bool isScale, const double& scaleX, const double& scaleY)
{
m_oBrush.IsScale = isScale;
m_oBrush.ScaleX = scaleX;
m_oBrush.ScaleY = scaleY;
return S_OK;
}
HRESULT CGraphicsRenderer::BrushRect(const INT& val, const double& left, const double& top, const double& width, const double& height)
{
m_oBrush.Rectable = val;
@ -946,11 +972,18 @@ HRESULT CGraphicsRenderer::DrawPath(const LONG& nType)
switch (m_oBrush.TextureMode)
{
case c_BrushTextureModeTile:
oMode = Aggplus::WrapModeTile;
break;
case c_BrushTextureModeTileCenter:
oMode = Aggplus::WrapModeTile;
break;
case c_BrushTextureModeTileFlipX:
oMode = Aggplus::WrapModeTileFlipX;
break;
case c_BrushTextureModeTileFlipY:
oMode = Aggplus::WrapModeTileFlipY;
break;
case c_BrushTextureModeTileFlipXY:
oMode = Aggplus::WrapModeTileFlipXY;
break;
default:
break;
}
@ -1023,11 +1056,18 @@ HRESULT CGraphicsRenderer::DrawPath(const LONG& nType)
if (m_oBrush.Rectable == 1)
{
pTextureBrush->m_bUseBounds = true;
pTextureBrush->m_oBounds.left = m_oBrush.Rect.X;
pTextureBrush->m_oBounds.top = m_oBrush.Rect.Y;
pTextureBrush->m_oBounds.left = m_oBrush.Rect.X + m_oBrush.OffsetX;
pTextureBrush->m_oBounds.top = m_oBrush.Rect.Y + m_oBrush.OffsetY;
pTextureBrush->m_oBounds.right = pTextureBrush->m_oBounds.left + m_oBrush.Rect.Width;
pTextureBrush->m_oBounds.bottom = pTextureBrush->m_oBounds.top + m_oBrush.Rect.Height;
}
if (m_oBrush.IsScale == 1)
{
pTextureBrush->m_bIsScale = true;
pTextureBrush->m_dScaleX = m_oBrush.ScaleX;
pTextureBrush->m_dScaleY = m_oBrush.ScaleY;
}
}
pBrush = pTextureBrush;

View File

@ -189,6 +189,10 @@ public:
virtual HRESULT put_BrushLinearAngle(const double& dAngle);
virtual HRESULT get_BrushTransform(Aggplus::CMatrix& oMatrix);
virtual HRESULT put_BrushTransform(const Aggplus::CMatrix& oMatrix);
virtual HRESULT get_BrushOffset(double& offsetX, double& offsetY) const;
virtual HRESULT put_BrushOffset(const double& offsetX, const double& offsetY);
virtual HRESULT get_BrushScale(bool& isScale, double& scaleX, double& scaleY) const;
virtual HRESULT put_BrushScale(bool isScale, const double& scaleX, const double& scaleY);
virtual HRESULT BrushRect(const INT& val, const double& left, const double& top, const double& width, const double& height);
virtual HRESULT BrushBounds(const double& left, const double& top, const double& width, const double& height);
virtual HRESULT put_BrushGradientColors(LONG* lColors, double* pPositions, LONG nCount);

View File

@ -169,7 +169,10 @@ public:
AdvancedCommandType GetCommandType() { return m_nCommandType; }
};
namespace Aggplus { class CImage; }
namespace Aggplus {
class CImage;
class CGraphicsPath;
}
// IRenderer
class IRenderer : public IGrObject
@ -241,6 +244,32 @@ public:
virtual HRESULT put_BrushTransform(const Aggplus::CMatrix& oMatrix) = 0;
virtual HRESULT get_BrushLinearAngle(double* dAngle) = 0;
virtual HRESULT put_BrushLinearAngle(const double& dAngle) = 0;
virtual HRESULT get_BrushOffset(double& offsetX, double& offsetY) const
{
UNUSED_VARIABLE(offsetX);
UNUSED_VARIABLE(offsetY);
return S_OK;
}
virtual HRESULT put_BrushOffset(const double& offsetX, const double& offsetY)
{
UNUSED_VARIABLE(offsetX);
UNUSED_VARIABLE(offsetY);
return S_OK;
}
virtual HRESULT get_BrushScale(bool& isScale, double& scaleX, double& scaleY) const
{
UNUSED_VARIABLE(isScale);
UNUSED_VARIABLE(scaleX);
UNUSED_VARIABLE(scaleY);
return S_OK;
}
virtual HRESULT put_BrushScale(bool isScale, const double& scaleX, const double& scaleY)
{
UNUSED_VARIABLE(isScale);
UNUSED_VARIABLE(scaleX);
UNUSED_VARIABLE(scaleY);
return S_OK;
}
virtual HRESULT BrushRect(const INT& val, const double& left, const double& top, const double& width, const double& height) = 0;
virtual HRESULT BrushBounds(const double& left, const double& top, const double& width, const double& height) = 0;
@ -300,6 +329,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;
HRESULT AddPath(const Aggplus::CGraphicsPath& path);
//-------- Функции для вывода изображений ---------------------------------------------------
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
// а не просто на каждом символе переключаться, если нужно
@ -351,7 +352,13 @@ namespace NSOnlineOfficeBinToPdf
bool bIsPathOpened = false;
bool bIsEnableBrushRect = false;
double old_t1, old_t2, old_t3, old_t4, old_t5, old_t6;
CBufferReader oReader(pBuffer, lBufferLen);
Aggplus::CGraphicsPath path;
Aggplus::CMatrix transMatrRot;
Aggplus::RectF_T<double> clipRect;
bool isResetRot = false;
while (oReader.Check())
{
eCommand = (CommandType)(oReader.ReadByte());
@ -471,6 +478,16 @@ namespace NSOnlineOfficeBinToPdf
double m2 = oReader.ReadDouble();
double m3 = oReader.ReadDouble();
double m4 = oReader.ReadDouble();
long type;
pRenderer->get_BrushTextureMode(&type);
if (type != c_BrushTextureModeStretch)
{
m1 = 0.0;
m2 = 0.0;
}
clipRect = Aggplus::RectF_T<double>(m1, m2, m3, m4);
pRenderer->BrushRect(bIsEnableBrushRect ? 1 : 0, m1, m2, m3, m4);
break;
}
@ -590,6 +607,16 @@ namespace NSOnlineOfficeBinToPdf
pRenderer->put_BrushTextureAlpha(lAlpha);
break;
}
case ctBrushResetRotation:
{
pRenderer->GetTransform(&old_t1, &old_t2, &old_t3, &old_t4, &old_t5, &old_t6);
Aggplus::CMatrix mtr(old_t1, old_t2, old_t3, old_t4, old_t5, old_t6);
double rot = mtr.rotation();
transMatrRot.Rotate(agg::rad2deg(rot));
isResetRot = true;
break;
}
case ctSetTransform:
{
double m1 = oReader.ReadDouble();
@ -611,6 +638,8 @@ namespace NSOnlineOfficeBinToPdf
pRenderer->BeginCommand(c_nPathType);
pRenderer->PathCommandStart();
path.Reset();
path.StartFigure();
bIsPathOpened = true;
break;
@ -619,14 +648,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 +666,12 @@ 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();
break;
}
case ctPathCommandEnd:
@ -655,9 +684,101 @@ namespace NSOnlineOfficeBinToPdf
}
break;
}
case ctPathCommandOffset:
{
double m1 = oReader.ReadDouble();
double m2 = oReader.ReadDouble();
pRenderer->put_BrushOffset(m1, m2);
break;
}
case ctPathCommandScale:
{
double m1 = oReader.ReadDouble();
double m2 = oReader.ReadDouble();
pRenderer->put_BrushScale(true, m1, m2);
break;
}
case ctDrawPath:
{
pRenderer->DrawPath(oReader.ReadInt());
long fill = oReader.ReadInt();
long type;
pRenderer->get_BrushType(&type);
if (fill != c_nStroke && type == c_BrushTypeTexture)
{
Aggplus::CGraphicsPath clipPath;
Aggplus::CGraphicsPath drawPath(path);
if (isResetRot)
{
pRenderer->get_BrushTextureMode(&type);
bool isStretch = type == c_BrushTextureModeStretch;
double left, top, width, height;
drawPath.GetBounds(left, top, width, height);
double rot = transMatrRot.rotation();
double cX = left + width / 2.0;
double cY = top + height / 2.0;
bool isZeroPt = clipRect.X < 0.1 && clipRect.X > -0.1 && clipRect.Y < 0.1 && clipRect.Y > -0.1;
bool isZeroRot = rot < 1e-6 && rot > -1e-6;
transMatrRot.Reset();
transMatrRot.RotateAt(agg::rad2deg(rot), cX, cY, Aggplus::MatrixOrderAppend);
double offX = old_t5 - transMatrRot.tx();
double offY = old_t6 - transMatrRot.ty();
drawPath.Transform(&transMatrRot);
pRenderer->SetTransform(1.0, 0.0, 0.0, 1.0, offX, offY);
if (isZeroPt && !isZeroRot && isStretch)
drawPath.GetBounds(left, top, width, height);
else
{
Aggplus::CGraphicsPath tmpPath;
tmpPath.AddRectangle(left, top, width, height);
tmpPath.Transform(&transMatrRot);
tmpPath.GetBounds(left, top, width, height);
}
if (isZeroPt || !isStretch)
clipRect = Aggplus::RectF_T<double>(left, top, width, height);
if (isStretch)
{
if (!isZeroPt)
clipRect.Offset(-offX, -offY);
pRenderer->BrushRect(true, clipRect.X, clipRect.Y, clipRect.Width, clipRect.Height);
}
else
{
double tileOffX, tileOffY;
pRenderer->get_BrushOffset(tileOffX, tileOffY);
pRenderer->put_BrushOffset(tileOffX - offX, tileOffY - offY);
}
}
clipPath.AddRectangle(clipRect.X, clipRect.Y, clipRect.Width, clipRect.Height);
path = Aggplus::CalcBooleanOperation(drawPath, clipPath, Aggplus::Intersection);
clipRect = Aggplus::RectF_T<double>();
}
pRenderer->AddPath(path);
pRenderer->DrawPath(fill);
if (isResetRot)
{
pRenderer->SetTransform(old_t1, old_t2, old_t3, old_t4, old_t5, old_t6);
transMatrRot.Reset();
isResetRot = false;
}
pRenderer->put_BrushScale(false, 1.0, 1.0);
pRenderer->put_BrushOffset(0.0, 0.0);
break;
}
case ctDrawImageFromFile:
@ -1132,6 +1253,10 @@ namespace NSOnlineOfficeBinToPdf
oReader.Skip(1);
break;
}
case ctBrushResetRotation:
{
break;
}
case ctSetTransform:
{
oReader.SkipInt(6);
@ -1164,6 +1289,16 @@ namespace NSOnlineOfficeBinToPdf
{
break;
}
case ctPathCommandOffset:
{
oReader.SkipInt(2);
break;
}
case ctPathCommandScale:
{
oReader.SkipInt(2);
break;
}
case ctDrawPath:
{
oReader.SkipInt();

View File

@ -108,6 +108,7 @@ namespace NSOnlineOfficeBinToPdf
ctBrushRectableEnabled = 30,
ctBrushGradient = 31,
ctBrushTexturePath = 32,
ctBrushResetRotation = 33,
// font
ctFontXML = 40,
@ -153,6 +154,8 @@ namespace NSOnlineOfficeBinToPdf
ctPathCommandGetCurrentPoint = 101,
ctPathCommandText = 102,
ctPathCommandTextEx = 103,
ctPathCommandOffset = 104,
ctPathCommandScale = 105,
// image
ctDrawImage = 110,

View File

@ -214,6 +214,18 @@ public:
inline bool IsPositive() { return Width > 0 && Height > 0; }
RectF_T& operator=(const RectF_T& other)
{
if (this == &other)
return *this;
X = other.X;
Y = other.Y;
Width = other.Width;
Height = other.Height;
return *this;
};
public:
T X, Y, Width, Height;
};

View File

@ -113,7 +113,10 @@ const long c_BrushTypeTensorCurveGradient = 6007;
const long c_BrushTextureModeStretch = 0;
const long c_BrushTextureModeTile = 1;
const long c_BrushTextureModeTileCenter = 2;
const long c_BrushTextureModeTileFlipX = 2;
const long c_BrushTextureModeTileFlipY = 3;
const long c_BrushTextureModeTileFlipXY = 4;
const long c_BrushTextureModeTileCenter = 5;
// --------------------------------------------------------------
namespace Aggplus { class CImage; }
@ -284,6 +287,13 @@ namespace NSStructures
Aggplus::RectF Rect;
Aggplus::CDoubleRect Bounds;
int IsScale;
double ScaleX;
double ScaleY;
double OffsetX;
double OffsetY;
double LinearAngle;
std::vector<TSubColor> m_arrSubColors;
NSStructures::GradientInfo m_oGradientInfo;
@ -415,6 +425,13 @@ namespace NSStructures
Rect.Width = 0.0F;
Rect.Height = 0.0F;
IsScale = FALSE;
ScaleX = 1.0;
ScaleY = 1.0;
OffsetX = 0.0;
OffsetY = 0.0;
Bounds.left = 0;
Bounds.top = 0;
Bounds.right = 0;
@ -454,6 +471,10 @@ namespace NSStructures
Rect = other.Rect;
Bounds = other.Bounds;
IsScale = other.IsScale;
ScaleX = other.ScaleX;
ScaleY = other.ScaleY;
LinearAngle = other.LinearAngle;
m_arrSubColors = other.m_arrSubColors;
m_oGradientInfo = other.m_oGradientInfo;