static bool _parseShapePath(const char *ptr, const char *end, Shape *shape)
{
- //Shape Path
uint32_t cmdCnt, ptsCnt;
+
READ_UI32(&cmdCnt, ptr);
- ptr += SIZE(uint32_t);
+ ptr += SIZE(cmdCnt);
+
READ_UI32(&ptsCnt, ptr);
- ptr += SIZE(uint32_t);
+ ptr += SIZE(ptsCnt);
- const PathCommand* cmds = (PathCommand*) ptr;
- ptr += SIZE(PathCommand) * cmdCnt;
- const Point* pts = (Point*) ptr;
+ auto cmds = (TvgBinFlag*) ptr;
+ ptr += SIZE(TvgBinFlag) * cmdCnt;
+
+ auto pts = (Point*) ptr;
ptr += SIZE(Point) * ptsCnt;
if (ptr > end) return false;
- shape->appendPath(cmds, cmdCnt, pts, ptsCnt);
+ /* Recover to PathCommand(4 bytes) from TvgBinFlag(1 byte) */
+ PathCommand inCmds[cmdCnt];
+ for (uint32_t i = 0; i < cmdCnt; ++i) {
+ inCmds[i] = static_cast<PathCommand>(cmds[i]);
+ }
+
+ shape->appendPath(inCmds, cmdCnt, pts, ptsCnt);
+
return true;
}
writeTag(TVG_TAG_SHAPE_PATH);
reserveCount();
+ /* Reduce the binary size.
+ Convert PathCommand(4 bytes) to TvgBinFlag(1 byte) */
+ TvgBinFlag outCmds[cmdCnt];
+ for (uint32_t i = 0; i < cmdCnt; ++i) {
+ outCmds[i] = static_cast<TvgBinFlag>(cmds[i]);
+ }
+
auto cnt = writeData(&cmdCnt, SIZE(cmdCnt));
cnt += writeData(&ptsCnt, SIZE(ptsCnt));
- cnt += writeData(cmds, cmdCnt * SIZE(cmds[0]));
+ cnt += writeData(outCmds, SIZE(outCmds));
cnt += writeData(pts, ptsCnt * SIZE(pts[0]));
writeReservedCount(cnt);