void fz_curveto(fz_context *ctx, fz_path *path, float x1, float y1, float x2, float y2, float x3, float y3) { float x0 = path->current.x; float y0 = path->current.y; if (path->cmd_len == 0) { fz_warn(ctx, "curveto with no current point"); return; } /* Check for degenerate cases: */ if (x0 == x1 && y0 == y1) { if (x2 == x3 && y2 == y3) { /* If (x1,y1)==(x2,y2) and prev wasn't a moveto, then skip */ if (x1 == x2 && y1 == y2 && path->last_cmd != FZ_MOVETO) return; /* Otherwise a line will suffice */ fz_lineto(ctx, path, x3, y3); return; } if (x1 == x2 && y1 == y2) { /* A line will suffice */ fz_lineto(ctx, path, x3, y3); return; } } else if (x1 == x2 && y1 == y2 && x2 == x3 && y2 == y3) { /* A line will suffice */ fz_lineto(ctx, path, x3, y3); return; } push_cmd(ctx, path, FZ_CURVETO); push_coord(ctx, path, x1, y1); push_coord(ctx, path, x2, y2); push_coord(ctx, path, x3, y3); }
void fz_closepath(fz_context *ctx, fz_path *path) { if (path->cmd_len == 0) { fz_warn(ctx, "closepath with no current point"); return; } /* CLOSE following a CLOSE is a NOP */ if (path->last_cmd == FZ_CLOSE_PATH) return; push_cmd(ctx, path, FZ_CLOSE_PATH); path->current = path->begin; }
void fz_moveto(fz_context *ctx, fz_path *path, float x, float y) { if (path->cmd_len > 0 && path->last_cmd == FZ_MOVETO) { /* Collapse moveto followed by moveto. */ path->coords[path->coord_len-2] = x; path->coords[path->coord_len-1] = y; path->current.x = x; path->current.y = y; path->begin = path->current; return; } push_cmd(ctx, path, FZ_MOVETO); push_coord(ctx, path, x, y); path->begin = path->current; }
void fz_lineto(fz_context *ctx, fz_path *path, float x, float y) { float x0 = path->current.x; float y0 = path->current.y; if (path->cmd_len == 0) { fz_warn(ctx, "lineto with no current point"); return; } /* Anything other than MoveTo followed by LineTo the same place is a nop */ if (path->last_cmd != FZ_MOVETO && x0 == x && y0 == y) return; push_cmd(ctx, path, FZ_LINETO); push_coord(ctx, path, x, y); }
void CosmosQueue::cmd_thread() { unsigned char buffer[128]; uint32_t length; uint8_t id; int received = 0; Packet* cmd; while (true) { connection_mutex.lock(); if (!connected.load()) connect(); connection_mutex.unlock(); while (connected.load()) { // receive the first four bytes (the length of the packet); if (cosmos.recvPacket(buffer, 4) < 0) { connected.store(false); break; } else { memcpy(&length, buffer, sizeof(length)); //printf("received packet of length %u\n", length); if (length < 5) { connected.store(false); break; } // receive the rest of the packet if ((received = cosmos.recvPacket(buffer+4, length-4)) < (int)(length-4)) { printf("failed to fetch entire packet (%d/%d)\n", received+4, length); connected.store(false); break; } // get the id to know what command it is memcpy(&id, buffer+4, sizeof(id)); //printf("id is %d\n", id); cmd = new Packet(length, id, true); memcpy(cmd->buffer, buffer, length); push_cmd(cmd); } } printf("command connection with COSMOS lost\n"); } }