直接导入 SVG path 字符串(如 "M10 80 C40 10, 65 10, 95 80"),或将 ShapeEx 路径导出为 SVG path data。
| 函数 | 说明 |
|---|---|
int xgeShapeExAppendSvgPath(xge_shape_ex pShape, const char* sPath) | 导入 SVG path data |
int xgeShapeExGetSvgPathData(xge_shape_ex pShape, char* sBuffer, int iBufferSize, int* pRequiredSize) | 导出 SVG path data |
int xgeShapeExGetPath(xge_shape_ex pShape, const uint8_t** ppCommands, int* pCommandCount, const xge_vec2_t** ppPoints, int* pPointCount) | 获取内部路径数据 |
int xgeShapeExAppendPath(xge_shape_ex pShape, const uint8_t* pCommands, int iCommandCount, const xge_vec2_t* pPoints, int iPointCount) | 从内部数据恢复路径 |
gcc -O2 -I. -o ch40.exe ch40_main.c build\xge.lib -lm -lws2_32 -liphlpapi -lgdi32 -luser32 -lshell32 -lopengl32 -lole32 -lwinmm -lavrt
.\ch40.exe
xge_shape_ex icon = NULL;
xgeShapeExCreate(&icon);
// 一个 SVG 心形路径
const char* svg =
"M400 480 C100 300 150 100 400 200 "
"C650 100 700 300 400 480 Z";
xgeShapeExAppendSvgPath(icon, svg);
xgeShapeExFillColor(icon, 0xFF6B5EFF);
xgeShapeExDraw(icon, 0.25f);// 构建一个路径
xge_shape_ex shape = NULL;
xgeShapeExCreate(&shape);
xgeShapeExAppendCircle(shape, 200, 200, 100, 100, 1);
// 导出为 SVG path data
char buffer[1024];
int required = 0;
xgeShapeExGetSvgPathData(shape, buffer, sizeof(buffer), &required);
xgeLogWrite(XGE_LOG_INFO, "SVG: %s", buffer);// 获取内部命令和点数组
const uint8_t* cmds; int cmdCount;
const xge_vec2_t* pts; int ptCount;
xgeShapeExGetPath(shape, &cmds, &cmdCount, &pts, &ptCount);
// 保存到文件 / 网络传输...
// 恢复到新对象
xge_shape_ex restored = NULL;
xgeShapeExCreate(&restored);
xgeShapeExAppendPath(restored, cmds, cmdCount, pts, ptCount);将以下代码保存为 ch40_main.c,编译后运行即可看到 SVG path 导入与导出效果:
#include "xge.h"
static int onFrame(void* pUser) {
(void)pUser;
xgeClear(0x081114FF);
// 导入 SVG 心形路径
xge_shape_ex icon = NULL;
xgeShapeExCreate(&icon);
const char* svg =
"M400 480 C100 300 150 100 400 200 "
"C650 100 700 300 400 480 Z";
xgeShapeExAppendSvgPath(icon, svg);
xgeShapeExFillColor(icon, 0xFF6B5EFF);
xgeShapeExDraw(icon, 0.25f);
// 导出为 SVG path data
char buffer[1024];
int required = 0;
xgeShapeExGetSvgPathData(icon, buffer, sizeof(buffer), &required);
xgeShapeExDestroy(icon);
// 用 API 构建圆形并导出
xge_shape_ex circle = NULL;
xgeShapeExCreate(&circle);
xgeShapeExAppendCircle(circle, 400, 500, 60, 60, 1);
xgeShapeExFillColor(circle, 0x4FD8C2FF);
xgeShapeExDraw(circle, 0.25f);
xgeShapeExDestroy(circle);
return XGE_OK;
}
int main(void) {
xge_desc_t d = {0};
d.iWidth = 800;
d.iHeight = 600;
d.sTitle = "ch40 - SVG Path";
d.iFlags = XGE_INIT_VSYNC;
xgeInit(&d);
xgeRun(onFrame, NULL);
xgeUnit();
return 0;
}