Skip to content

Commit

Permalink
refactor: 变换矩阵类型转换改为由引用返回结果
Browse files Browse the repository at this point in the history
  • Loading branch information
yixy-only committed Oct 4, 2024
1 parent dd5afd7 commit a38e7d7
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 35 deletions.
71 changes: 49 additions & 22 deletions src/egegapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2388,9 +2388,14 @@ void ege_path_widen(ege_path* path, float lineWidth, const ege_transform_matrix*
Gdiplus::GraphicsPath* graphicsPath = (Gdiplus::GraphicsPath*)path->data();
if (graphicsPath != NULL) {
const Gdiplus::Pen pen(Gdiplus::Color(), lineWidth);
const Gdiplus::Matrix* mat = matrixConvert(matrix);
graphicsPath->Widen(&pen, mat, flatness);
delete mat;

if (matrix != NULL) {
Gdiplus::Matrix mat;
matrixConvert(matrix, mat);
graphicsPath->Widen(&pen, &mat, flatness);
} else {
graphicsPath->Widen(&pen, NULL, flatness);
}
}
}
}
Expand All @@ -2406,9 +2411,13 @@ void ege_path_flatten(ege_path* path, const ege_transform_matrix* matrix, float
Gdiplus::GraphicsPath* graphicsPath = (Gdiplus::GraphicsPath*)path->data();

if (graphicsPath != NULL) {
const Gdiplus::Matrix* mat = matrixConvert(matrix);
graphicsPath->Flatten(mat, flatness);
delete mat;
if (matrix != NULL) {
Gdiplus::Matrix mat;
matrixConvert(matrix, mat);
graphicsPath->Flatten(&mat, flatness);
} else {
graphicsPath->Flatten(NULL, flatness);
}
}
}
}
Expand All @@ -2427,9 +2436,14 @@ void ege_path_warp(ege_path* path, const ege_point* points, int count, const ege
if (graphicsPath != NULL) {
const Gdiplus::PointF* p = (const Gdiplus::PointF*)points;
const Gdiplus::RectF r(rect->x, rect->y, rect->w, rect->h);
const Gdiplus::Matrix* mat = matrixConvert(matrix);
graphicsPath->Warp(p, count, r, mat, Gdiplus::WarpModePerspective, flatness);
delete mat;

if (matrix != NULL) {
Gdiplus::Matrix mat;
matrixConvert(matrix, mat);
graphicsPath->Warp(p, count, r, &mat, Gdiplus::WarpModePerspective, flatness);
} else {
graphicsPath->Warp(p, count, r, NULL, Gdiplus::WarpModePerspective, flatness);
}
}
}
}
Expand All @@ -2444,9 +2458,13 @@ void ege_path_outline(ege_path* path, const ege_transform_matrix* matrix, float
if (path != NULL) {
Gdiplus::GraphicsPath* graphicsPath = (Gdiplus::GraphicsPath*)path->data();
if (graphicsPath != NULL) {
const Gdiplus::Matrix* mat = matrixConvert(matrix);
graphicsPath->Outline(mat, flatness);
delete mat;
if (matrix != NULL) {
Gdiplus::Matrix mat;
matrixConvert(matrix, mat);
graphicsPath->Outline(&mat, flatness);
} else {
graphicsPath->Outline(NULL, flatness);
}
}
}
}
Expand Down Expand Up @@ -2532,9 +2550,13 @@ ege_rect ege_path_getbounds(const ege_path* path, const ege_transform_matrix* ma
if (path != NULL) {
const Gdiplus::GraphicsPath* graphicsPath = (const Gdiplus::GraphicsPath*)path->data();
if (graphicsPath != NULL) {
const Gdiplus::Matrix* mat = matrixConvert(matrix);
graphicsPath->GetBounds((Gdiplus::RectF*)&bounds, mat);
delete mat;
if (matrix != NULL) {
Gdiplus::Matrix mat;
matrixConvert(matrix, mat);
graphicsPath->GetBounds((Gdiplus::RectF*)&bounds, &mat);
} else {
graphicsPath->GetBounds((Gdiplus::RectF*)&bounds, NULL);
}
}
}

Expand All @@ -2548,9 +2570,13 @@ ege_rect ege_path_getbounds(const ege_path* path, const ege_transform_matrix* ma
const Gdiplus::GraphicsPath* graphicsPath = (const Gdiplus::GraphicsPath*)path->data();
if (graphicsPath != NULL) {
PIMAGE img = CONVERT_IMAGE_CONST((PIMAGE)pimg);
const Gdiplus::Matrix* mat = matrixConvert(matrix);
graphicsPath->GetBounds((Gdiplus::RectF*)&bounds, mat, img->getPen());
delete mat;
if (matrix != NULL) {
Gdiplus::Matrix mat;
matrixConvert(matrix, mat);
graphicsPath->GetBounds((Gdiplus::RectF*)&bounds, &mat, img->getPen());
} else {
graphicsPath->GetBounds((Gdiplus::RectF*)&bounds, NULL, img->getPen());
}
CONVERT_IMAGE_END
}
}
Expand Down Expand Up @@ -2606,9 +2632,9 @@ void ege_path_transform(ege_path* path, const ege_transform_matrix *matrix)
if ((path != NULL) && (matrix != NULL)) {
Gdiplus::GraphicsPath* graphicsPath = (Gdiplus::GraphicsPath*)path->data();
if (graphicsPath != NULL) {
const Gdiplus::Matrix* mat = matrixConvert(matrix);
graphicsPath->Transform(mat);
delete mat;
Gdiplus::Matrix mat;
matrixConvert(matrix, mat);
graphicsPath->Transform(&mat);
}
}
}
Expand Down Expand Up @@ -2863,7 +2889,8 @@ void EGEAPI ege_set_transform(const ege_transform_matrix* matrix, PIMAGE pimg)
PIMAGE img = CONVERT_IMAGE(pimg);
if (img && matrix) {
Gdiplus::Graphics* graphics = img->getGraphics();
const Gdiplus::Matrix mat(matrix->m11, matrix->m12, matrix->m21, matrix->m22, matrix->m31, matrix->m32);
Gdiplus::Matrix mat;
matrixConvert(matrix, mat);
graphics->SetTransform(&mat);
}
CONVERT_IMAGE_END;
Expand Down
20 changes: 9 additions & 11 deletions src/gdi_conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@ namespace ege
{

/**
* 将ege_transform_matrix 转换为 Gdiplus::Matrix
* matrix 参数不为 NULL 时返回 Matrix 对象指针,否则返回 NULL
* 将 ege_transform_matrix 类型转换为 Gdiplus::Matrix 类型
* @param[in] from 输入的矩阵
* @param[out] to 保存转换结果
* @note 如果 from 参数为 NULL,输出结果为单位矩阵。
*/
Gdiplus::Matrix* matrixConvert(const ege_transform_matrix* matrix)
void matrixConvert(const ege_transform_matrix* from, Gdiplus::Matrix& to)
{
if (matrix != NULL) {
return new Gdiplus::Matrix(
matrix->m11, matrix->m12,
matrix->m21, matrix->m22,
matrix->m31, matrix->m32
);
if (from) {
to.SetElements(from->m11, from->m12, from->m21, from->m22, from->m31, from->m32);
} else {
to.Reset();
}

return NULL;
}

}
4 changes: 2 additions & 2 deletions src/gdi_conv.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

namespace ege
{
/* 矩阵类型转换*/
Gdiplus::Matrix* matrixConvert(const ege_transform_matrix* matrix);
/* 矩阵类型转换 */
void matrixConvert(const ege_transform_matrix* from, Gdiplus::Matrix& to);
}

0 comments on commit a38e7d7

Please sign in to comment.