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 a38e7d7 commit 69720a0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
16 changes: 8 additions & 8 deletions src/egegapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2391,7 +2391,7 @@ void ege_path_widen(ege_path* path, float lineWidth, const ege_transform_matrix*

if (matrix != NULL) {
Gdiplus::Matrix mat;
matrixConvert(matrix, mat);
matrixConvert(*matrix, mat);
graphicsPath->Widen(&pen, &mat, flatness);
} else {
graphicsPath->Widen(&pen, NULL, flatness);
Expand All @@ -2413,7 +2413,7 @@ void ege_path_flatten(ege_path* path, const ege_transform_matrix* matrix, float
if (graphicsPath != NULL) {
if (matrix != NULL) {
Gdiplus::Matrix mat;
matrixConvert(matrix, mat);
matrixConvert(*matrix, mat);
graphicsPath->Flatten(&mat, flatness);
} else {
graphicsPath->Flatten(NULL, flatness);
Expand All @@ -2439,7 +2439,7 @@ void ege_path_warp(ege_path* path, const ege_point* points, int count, const ege

if (matrix != NULL) {
Gdiplus::Matrix mat;
matrixConvert(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 @@ -2460,7 +2460,7 @@ void ege_path_outline(ege_path* path, const ege_transform_matrix* matrix, float
if (graphicsPath != NULL) {
if (matrix != NULL) {
Gdiplus::Matrix mat;
matrixConvert(matrix, mat);
matrixConvert(*matrix, mat);
graphicsPath->Outline(&mat, flatness);
} else {
graphicsPath->Outline(NULL, flatness);
Expand Down Expand Up @@ -2552,7 +2552,7 @@ ege_rect ege_path_getbounds(const ege_path* path, const ege_transform_matrix* ma
if (graphicsPath != NULL) {
if (matrix != NULL) {
Gdiplus::Matrix mat;
matrixConvert(matrix, mat);
matrixConvert(*matrix, mat);
graphicsPath->GetBounds((Gdiplus::RectF*)&bounds, &mat);
} else {
graphicsPath->GetBounds((Gdiplus::RectF*)&bounds, NULL);
Expand All @@ -2572,7 +2572,7 @@ ege_rect ege_path_getbounds(const ege_path* path, const ege_transform_matrix* ma
PIMAGE img = CONVERT_IMAGE_CONST((PIMAGE)pimg);
if (matrix != NULL) {
Gdiplus::Matrix mat;
matrixConvert(matrix, mat);
matrixConvert(*matrix, mat);
graphicsPath->GetBounds((Gdiplus::RectF*)&bounds, &mat, img->getPen());
} else {
graphicsPath->GetBounds((Gdiplus::RectF*)&bounds, NULL, img->getPen());
Expand Down Expand Up @@ -2633,7 +2633,7 @@ void ege_path_transform(ege_path* path, const ege_transform_matrix *matrix)
Gdiplus::GraphicsPath* graphicsPath = (Gdiplus::GraphicsPath*)path->data();
if (graphicsPath != NULL) {
Gdiplus::Matrix mat;
matrixConvert(matrix, mat);
matrixConvert(*matrix, mat);
graphicsPath->Transform(&mat);
}
}
Expand Down Expand Up @@ -2890,7 +2890,7 @@ void EGEAPI ege_set_transform(const ege_transform_matrix* matrix, PIMAGE pimg)
if (img && matrix) {
Gdiplus::Graphics* graphics = img->getGraphics();
Gdiplus::Matrix mat;
matrixConvert(matrix, mat);
matrixConvert(*matrix, mat);
graphics->SetTransform(&mat);
}
CONVERT_IMAGE_END;
Expand Down
9 changes: 2 additions & 7 deletions src/gdi_conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,10 @@ namespace ege
* 将 ege_transform_matrix 类型转换为 Gdiplus::Matrix 类型
* @param[in] from 输入的矩阵
* @param[out] to 保存转换结果
* @note 如果 from 参数为 NULL,输出结果为单位矩阵。
*/
void matrixConvert(const ege_transform_matrix* from, Gdiplus::Matrix& to)
void matrixConvert(const ege_transform_matrix& from, Gdiplus::Matrix& to)
{
if (from) {
to.SetElements(from->m11, from->m12, from->m21, from->m22, from->m31, from->m32);
} else {
to.Reset();
}
to.SetElements(from.m11, from.m12, from.m21, from.m22, from.m31, from.m32);
}

}
2 changes: 1 addition & 1 deletion src/gdi_conv.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
namespace ege
{
/* 矩阵类型转换 */
void matrixConvert(const ege_transform_matrix* from, Gdiplus::Matrix& to);
void matrixConvert(const ege_transform_matrix& from, Gdiplus::Matrix& to);
}

0 comments on commit 69720a0

Please sign in to comment.