summaryrefslogtreecommitdiff
path: root/kicad
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-08-22 04:40:40 -0300
committerWerner Almesberger <werner@almesberger.net>2016-08-22 04:40:40 -0300
commitf4e780e0101b81d373a6fec3fc41bd8e382f9c21 (patch)
tree7a04e437be2ca642758e6bfb012777e3fa4eaeb2 /kicad
parent01e563c537c8503b86c833d351207396ec6c9fc2 (diff)
downloadeeshow-f4e780e0101b81d373a6fec3fc41bd8e382f9c21.tar.gz
eeshow-f4e780e0101b81d373a6fec3fc41bd8e382f9c21.tar.bz2
eeshow-f4e780e0101b81d373a6fec3fc41bd8e382f9c21.zip
eeshow/kicad/: begin text support for page layout (WIP); add missing pl-common.h
Diffstat (limited to 'kicad')
-rw-r--r--kicad/pl-common.h52
-rw-r--r--kicad/pl-parse.c51
-rw-r--r--kicad/pl-render.c34
3 files changed, 117 insertions, 20 deletions
diff --git a/kicad/pl-common.h b/kicad/pl-common.h
new file mode 100644
index 0000000..72ce0f3
--- /dev/null
+++ b/kicad/pl-common.h
@@ -0,0 +1,52 @@
+/*
+ * kicad/pl-common.h - Shared definitions for KiCad page layout handling
+ *
+ * Written 2016 by Werner Almesberger
+ * Copyright 2016 by Werner Almesberger
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+
+#ifndef KICAD_PL_COMMON_H
+#define KICAD_PL_COMMON_H
+
+#include "kicad/sexpr.h"
+
+
+enum font_flag {
+ font_bold = 1 << 0,
+ font_italic = 1 << 1,
+};
+
+
+struct pl_obj {
+ enum pl_obj_type {
+ pl_obj_rect,
+ pl_obj_line,
+ pl_obj_text,
+ } type;
+
+ const char *s; /* tbtext */
+ int repeat; /* line, rect, tbtext */
+ float x, y; /* line, rect, tbtext */
+ int dx, dy;
+ float ex, ey; /* line, rect; font size for tbtext */
+ int edx, edy;
+ float incrx, incry;
+ int incrlabel; /* tbtext */
+ int font; /* tbtext (flags) */
+
+ struct pl_obj *next;
+};
+
+struct pl_ctx {
+ struct sexpr_ctx *sexpr_ctx;
+ float l, r, t, b; /* margins */
+ struct pl_obj *objs;
+};
+
+#endif /* !KICAD_PL_COMMON_H */
diff --git a/kicad/pl-parse.c b/kicad/pl-parse.c
index b8376f5..5b75f64 100644
--- a/kicad/pl-parse.c
+++ b/kicad/pl-parse.c
@@ -140,6 +140,43 @@ static bool process_setup(struct pl_ctx *p, const struct expr *e)
}
+static bool process_font(struct pl_obj *obj, const struct expr *e)
+{
+ const char *s;
+ const struct expr *next;
+
+ for (; e; e = e->next) {
+ if (e->s) {
+ if (!strcmp(e->s, "bold"))
+ obj->font |= font_bold;
+ else if (!strcmp(e->s, "italic"))
+ obj->font |= font_italic;
+ else
+ warning("ignoring \"%s\"\n", e->s);
+ continue;
+ }
+
+ if (!e->e) {
+ warning("ignoring empty list\n");
+ continue;
+ }
+ s = e->e->s;
+ next = e->e->next;
+
+ if (!strcmp(s, "comment"))
+ continue;
+
+ if (!strcmp(s, "size")) {
+ if (!get_coord(next, &obj->ex, &obj->ey,
+ &obj->edx, &obj->edy))
+ return 0;
+ } else
+ warning("ignoring \"%s\"\n", s);
+ }
+ return 1;
+}
+
+
static bool process_obj(struct pl_ctx *pl, const struct expr *e,
enum pl_obj_type type)
{
@@ -156,10 +193,19 @@ static bool process_obj(struct pl_ctx *pl, const struct expr *e,
obj->incrx = 0;
obj->incry = 0;
obj->incrlabel = 0;
+ obj->font = 0;
for (; e; e = e->next) {
+ if (e->s) {
+ if (obj->s) {
+ error("multiple strings\n");
+ return 0;
+ }
+ obj->s = stralloc(e->s);
+ continue;
+ }
if (!e->e) {
- warning("ignoring non-list\n");
+ warning("ignoring empty list\n");
continue;
}
@@ -193,6 +239,9 @@ static bool process_obj(struct pl_ctx *pl, const struct expr *e,
} else if (!strcmp(s, "incrlabel")) {
if (!get_int(next, &obj->incrlabel))
return 0;
+ } else if (!strcmp(s, "font")) {
+ if (!process_font(obj, next))
+ return 0;
} else
warning("ignoring \"%s\"\n", s);
}
diff --git a/kicad/pl-render.c b/kicad/pl-render.c
index a6723cd..b682a82 100644
--- a/kicad/pl-render.c
+++ b/kicad/pl-render.c
@@ -18,6 +18,7 @@
#include "misc/util.h"
#include "misc/diag.h"
#include "gfx/style.h"
+#include "gfx/text.h"
#include "gfx/gfx.h"
#include "kicad/pl-common.h"
#include "kicad/pl.h"
@@ -35,15 +36,9 @@ static int mil(float mm)
}
-static int cx(int x, int dx, int xo, int xe)
+static int coord(int v, int d, int o, int e)
{
- return dx >= 0 ? xo + x : xe - x;
-}
-
-
-static int cy(int y, int dy, int yo, int ye)
-{
- return dy >= 0 ? yo + y : ye - y;
+ return d >= 0 ? o + v : e - v;
}
@@ -66,27 +61,28 @@ static void render_obj(const struct pl_ctx *pl, const struct pl_obj *obj,
if (x > ww || y > hh || ex > ww || ey > hh)
return;
+ x = coord(x, obj->dx, xo, xe);
+ y = coord(y, obj->dy, yo, ye);
+ ex = coord(ex, obj->edx, xo, xe);
+ ey = coord(ey, obj->edy, yo, ye);
+
switch (obj->type) {
case pl_obj_rect:
- gfx_rect(
- cx(x, obj->dx, xo, xe), cy(y, obj->dy, yo, ye),
- cx(ex, obj->edx, xo, xe), cy(ey, obj->edy, yo, ye),
+ gfx_rect(x, y, ex, ey,
COLOR_COMP_DWG, COLOR_NONE, LAYER_COMP_DWG);
break;
case pl_obj_line: {
- int vx[] = {
- cx(x, obj->dx, xo, xe),
- cx(ex, obj->edx, xo, xe)
- };
- int vy[] = {
- cy(y, obj->dy, yo, ye),
- cy(ey, obj->edy, yo, ye)
- };
+ int vx[] = { x, ex };
+ int vy[] = { y, ey };
gfx_poly(2, vx, vy,
COLOR_COMP_DWG, COLOR_NONE, LAYER_COMP_DWG);
}
break;
+ case pl_obj_text:
+ gfx_text(x, y, obj->s, mil(obj->ey), text_min, 0,
+ COLOR_COMP_DWG, LAYER_COMP_DWG);
+ break;
default:
break;
}