summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gfx/diff.c31
-rw-r--r--gfx/gfx.c95
-rw-r--r--gfx/gfx.h36
-rw-r--r--gfx/text.c29
-rw-r--r--gfx/text.h17
-rw-r--r--gui/common.h7
-rw-r--r--gui/gui.c2
-rw-r--r--gui/index.c18
-rw-r--r--gui/render.c63
-rw-r--r--kicad/dwg.c94
-rw-r--r--kicad/dwg.h21
-rw-r--r--kicad/lib-render.c171
-rw-r--r--kicad/lib.h9
-rw-r--r--kicad/pl-render.c16
-rw-r--r--kicad/pl.h5
-rw-r--r--kicad/sch-render.c41
-rw-r--r--kicad/sch.h11
-rw-r--r--main.c23
18 files changed, 378 insertions, 311 deletions
diff --git a/gfx/diff.c b/gfx/diff.c
index cf7c80e..24b2540 100644
--- a/gfx/diff.c
+++ b/gfx/diff.c
@@ -27,6 +27,7 @@
#include "kicad/sch.h"
#include "kicad/lib.h"
#include "gfx/record.h"
+#include "gfx/gfx.h"
#include "gfx/diff.h"
@@ -48,7 +49,7 @@
struct diff {
- void *cr_ctx;
+ struct gfx *gfx;
uint32_t *new_img;
int w, h, stride;
const char *output_name;
@@ -65,7 +66,7 @@ static void diff_line(void *ctx, int sx, int sy, int ex, int ey,
{
const struct diff *diff = ctx;
- cro_img_ops.line(diff->cr_ctx, sx, sy, ex, ey, color, layer);
+ gfx_line(diff->gfx, sx, sy, ex, ey, color, layer);
}
@@ -75,7 +76,7 @@ static void diff_poly(void *ctx,
{
const struct diff *diff = ctx;
- cro_img_ops.poly(diff->cr_ctx, points, x, y, color, fill_color, layer);
+ gfx_poly(diff->gfx, points, x, y, color, fill_color, layer);
}
@@ -84,7 +85,7 @@ static void diff_circ(void *ctx, int x, int y, int r,
{
const struct diff *diff = ctx;
- cro_img_ops.circ(diff->cr_ctx, x, y, r, color, fill_color, layer);
+ gfx_circ(diff->gfx, x, y, r, color, fill_color, layer);
}
@@ -93,8 +94,7 @@ static void diff_arc(void *ctx, int x, int y, int r, int sa, int ea,
{
const struct diff *diff = ctx;
- cro_img_ops.arc(diff->cr_ctx, x, y, r, sa, ea,
- color, fill_color, layer);
+ gfx_arc(diff->gfx, x, y, r, sa, ea, color, fill_color, layer);
}
@@ -103,8 +103,7 @@ static void diff_text(void *ctx, int x, int y, const char *s, unsigned size,
{
const struct diff *diff = ctx;
- cro_img_ops.text(diff->cr_ctx, x, y, s, size, align, rot,
- color, layer);
+ gfx_text(diff->gfx, x, y, s, size, align, rot, color, layer);
}
@@ -112,7 +111,7 @@ static unsigned diff_text_width(void *ctx, const char *s, unsigned size)
{
const struct diff *diff = ctx;
- return cro_img_ops.text_width(diff->cr_ctx, s, size);
+ return gfx_text_width(diff->gfx, s, size);
}
@@ -161,14 +160,14 @@ static void *diff_init(int argc, char *const *argv)
file_close(&sch_file);
optind = 0;
- gfx_init(&cro_img_ops, argc, argv);
- diff->cr_ctx = gfx_ctx;
- sch_render(new_sch.sheets);
- diff->new_img = cro_img_end(gfx_ctx,
+ diff->gfx = gfx_init(&cro_img_ops, argc, argv);
+ sch_render(new_sch.sheets, diff->gfx);
+ diff->new_img = cro_img_end(gfx_user(diff->gfx),
&diff->w, &diff->h, &diff->stride);
optind = 0;
- diff->cr_ctx = cro_img_ops.init(argc, argv);
+ diff->gfx = gfx_init(&cro_img_ops, argc, argv);
+ //diff->gfx = cro_img_ops.init(argc, argv);
return diff;
@@ -308,7 +307,7 @@ static void diff_end(void *ctx)
uint32_t *old_img;
int w, h, stride;
- old_img = cro_img_end(diff->cr_ctx, &w, &h, &stride);
+ old_img = cro_img_end(gfx_user(diff->gfx), &w, &h, &stride);
if (diff->w != w || diff->h != h)
fatal("%d x %d vs. %d x %d image\n", w, h, diff->w, diff->h);
@@ -316,7 +315,7 @@ static void diff_end(void *ctx)
show_areas(diff, old_img);
free_areas(&diff->areas);
- cro_img_write(diff->cr_ctx, diff->output_name);
+ cro_img_write(gfx_user(diff->gfx), diff->output_name);
}
diff --git a/gfx/gfx.c b/gfx/gfx.c
index 6236888..0324cfd 100644
--- a/gfx/gfx.c
+++ b/gfx/gfx.c
@@ -12,36 +12,40 @@
#include <stdbool.h>
+#include <stdlib.h>
+#include "misc/util.h"
#include "gfx/style.h"
#include "gfx/text.h"
#include "gfx/gfx.h"
-void *gfx_ctx;
+struct gfx {
+ const struct gfx_ops *ops;
+ void *user;
+};
-static const struct gfx_ops *gfx_ops;
-
-void gfx_line(int sx, int sy, int ex, int ey, int color, unsigned layer)
+void gfx_line(struct gfx *gfx,
+ int sx, int sy, int ex, int ey, int color, unsigned layer)
{
- if (gfx_ops->line) {
- gfx_ops->line(gfx_ctx, sx, sy, ex, ey, color, layer);
+ if (gfx->ops->line) {
+ gfx->ops->line(gfx->user, sx, sy, ex, ey, color, layer);
return;
}
int vx[] = { sx, ex };
int vy[] = { sy, ey };
- gfx_poly(2, vx, vy, color, COLOR_NONE, layer);
+ gfx_poly(gfx, 2, vx, vy, color, COLOR_NONE, layer);
}
-void gfx_rect(int sx, int sy, int ex, int ey,
+void gfx_rect(struct gfx *gfx, int sx, int sy, int ex, int ey,
int color, int fill_color, unsigned layer)
{
- if (gfx_ops->rect) {
- gfx_ops->rect(gfx_ctx, sx, sy, ex, ey,
+ if (gfx->ops->rect) {
+ gfx->ops->rect(gfx->user, sx, sy, ex, ey,
color, fill_color, layer);
return;
}
@@ -49,79 +53,94 @@ void gfx_rect(int sx, int sy, int ex, int ey,
int vx[] = { sx, ex, ex, sx, sx };
int vy[] = { sy, sy, ey, ey, sy };
- gfx_poly(5, vx, vy, color, fill_color, layer);
+ gfx_poly(gfx, 5, vx, vy, color, fill_color, layer);
}
-void gfx_poly(int points, const int x[points], const int y[points],
+void gfx_poly(struct gfx *gfx,
+ int points, const int x[points], const int y[points],
int color, int fill_color, unsigned layer)
{
- gfx_ops->poly(gfx_ctx, points, x, y, color, fill_color, layer);
+ gfx->ops->poly(gfx->user, points, x, y, color, fill_color, layer);
}
-void gfx_circ(int x, int y, int r, int color, int fill_color, unsigned layer)
+void gfx_circ(struct gfx *gfx,
+ int x, int y, int r, int color, int fill_color, unsigned layer)
{
- gfx_ops->circ(gfx_ctx, x, y, r, color, fill_color, layer);
+ gfx->ops->circ(gfx->user, x, y, r, color, fill_color, layer);
}
-void gfx_arc(int x, int y, int r, int sa, int ea,
+void gfx_arc(struct gfx *gfx, int x, int y, int r, int sa, int ea,
int color, int fill_color, unsigned layer)
{
- gfx_ops->arc(gfx_ctx, x, y, r, sa, ea, color, fill_color, layer);
+ gfx->ops->arc(gfx->user, x, y, r, sa, ea, color, fill_color, layer);
}
-void gfx_text(int x, int y, const char *s, unsigned size,
+void gfx_text(struct gfx *gfx, int x, int y, const char *s, unsigned size,
enum text_align align, int rot, unsigned color, unsigned layer)
{
- gfx_ops->text(gfx_ctx, x, y, s, size, align, rot, color, layer);
+ gfx->ops->text(gfx->user, x, y, s, size, align, rot, color, layer);
}
-void gfx_tag(const char *s,
+void gfx_tag(struct gfx *gfx, const char *s,
unsigned points, const int x[points], int const y[points])
{
- if (gfx_ops->tag)
- gfx_ops->tag(gfx_ctx, s, points, x, y);
+ if (gfx->ops->tag)
+ gfx->ops->tag(gfx->user, s, points, x, y);
}
-unsigned gfx_text_width(const char *s, unsigned size)
+unsigned gfx_text_width(struct gfx *gfx, const char *s, unsigned size)
{
- return gfx_ops->text_width(gfx_ctx, s, size);
+ return gfx->ops->text_width(gfx->user, s, size);
}
-void gfx_init(const struct gfx_ops *ops, int argc, char *const *argv)
+struct gfx *gfx_init(const struct gfx_ops *ops,
+ int argc, char *const *argv)
{
- gfx_ctx = ops->init(argc, argv);
- gfx_ops = ops;
+ struct gfx *new;
+
+ new = alloc_type(struct gfx);
+ new->user = ops->init(argc, argv);
+ new->ops = ops;
+ return new;
}
-void gfx_sheet_name(const char *name)
+void gfx_sheet_name(struct gfx *gfx, const char *name)
{
- if (gfx_ops->sheet_name)
- gfx_ops->sheet_name(gfx_ctx, name);
+ if (gfx->ops->sheet_name)
+ gfx->ops->sheet_name(gfx->user, name);
}
-void gfx_new_sheet(void)
+void gfx_new_sheet(struct gfx *gfx)
{
- if (gfx_ops->new_sheet)
- gfx_ops->new_sheet(gfx_ctx);
+ if (gfx->ops->new_sheet)
+ gfx->ops->new_sheet(gfx->user);
}
-bool gfx_multi_sheet(void)
+bool gfx_multi_sheet(struct gfx *gfx)
{
- return !!gfx_ops->new_sheet;
+ return !!gfx->ops->new_sheet;
}
-void gfx_end(void)
+
+void *gfx_user(struct gfx *gfx)
+{
+ return gfx->user;
+}
+
+
+void gfx_end(struct gfx *gfx)
{
- if (gfx_ops->end)
- gfx_ops->end(gfx_ctx);
+ if (gfx->ops->end)
+ gfx->ops->end(gfx->user);
+ free(gfx);
}
diff --git a/gfx/gfx.h b/gfx/gfx.h
index bdd5225..c31495b 100644
--- a/gfx/gfx.h
+++ b/gfx/gfx.h
@@ -19,6 +19,8 @@
#include "gfx/text.h"
+struct gfx;
+
struct gfx_ops {
const char *name;
void (*line)(void *ctx, int sx, int sy, int ex, int ey,
@@ -44,31 +46,33 @@ struct gfx_ops {
};
-extern void *gfx_ctx;
-
-
/* wrappers */
-void gfx_line(int sx, int sy, int ex, int ey, int color, unsigned layer);
-void gfx_rect(int sx, int sy, int ex, int ey,
+void gfx_line(struct gfx *gfx,
+ int sx, int sy, int ex, int ey, int color, unsigned layer);
+void gfx_rect(struct gfx *gfx, int sx, int sy, int ex, int ey,
int color, int fill_color, unsigned layer);
-void gfx_poly(int points, const int x[points], const int y[points],
+void gfx_poly(struct gfx *gfx,
+ int points, const int x[points], const int y[points],
int color, int fill_color, unsigned layer);
-void gfx_circ(int x, int y, int r, int color, int fill_color, unsigned layer);
-void gfx_arc(int x, int y, int r, int sa, int ea,
+void gfx_circ(struct gfx *gfx,
+ int x, int y, int r, int color, int fill_color, unsigned layer);
+void gfx_arc(struct gfx *gfx, int x, int y, int r, int sa, int ea,
int color, int fill_color, unsigned layer);
-void gfx_text(int x, int y, const char *s, unsigned size,
+void gfx_text(struct gfx *gfx, int x, int y, const char *s, unsigned size,
enum text_align align, int rot, unsigned color, unsigned layer);
-void gfx_tag(const char *s,
+void gfx_tag(struct gfx *gfx, const char *s,
unsigned points, const int x[points], int const y[points]);
-unsigned gfx_text_width(const char *s, unsigned size);
+unsigned gfx_text_width(struct gfx *gfx, const char *s, unsigned size);
/* inititalization and termination */
-void gfx_init(const struct gfx_ops *ops, int argc, char *const *argv);
-void gfx_sheet_name(const char *name);
-void gfx_new_sheet(void);
-bool gfx_multi_sheet(void);
-void gfx_end(void);
+struct gfx *gfx_init(const struct gfx_ops