summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kicad/pl-common.h1
-rw-r--r--kicad/pl-parse.c53
-rw-r--r--kicad/pl-render.c7
3 files changed, 50 insertions, 11 deletions
diff --git a/kicad/pl-common.h b/kicad/pl-common.h
index 4680efd..8b52bf4 100644
--- a/kicad/pl-common.h
+++ b/kicad/pl-common.h
@@ -49,6 +49,7 @@ struct pl_obj {
struct pl_ctx {
struct sexpr_ctx *sexpr_ctx;
float l, r, t, b; /* margins */
+ float tx, ty; /* text size */
struct pl_obj *objs;
};
diff --git a/kicad/pl-parse.c b/kicad/pl-parse.c
index 467ceca..6d7b2ce 100644
--- a/kicad/pl-parse.c
+++ b/kicad/pl-parse.c
@@ -73,6 +73,42 @@ static bool get_coord(const struct expr *e,
}
+static bool get_size(const struct expr *e, float *x, float *y)
+{
+ unsigned n = 0;
+
+ for (; e; e = e->next) {
+ char *end;
+ float f;
+
+ if (e->e)
+ continue;
+
+ f = strtof(e->s, &end);
+ if (*end) {
+ error("no a number \"%s\"\n", e->s);
+ return 0;
+ }
+ if (n++)
+ *y = f;
+ else
+ *x = f;
+ }
+
+ switch (n) {
+ case 0:
+ case 1:
+ error("no enough coordinates\n");
+ return 0;
+ case 2:
+ return 1;
+ default:
+ error("too many coordinates\n");
+ return 0;
+ }
+}
+
+
static bool get_float(const struct expr *e, float *f)
{
for (; e; e = e->next)
@@ -98,7 +134,7 @@ static bool get_int(const struct expr *e, int *n)
}
-static bool process_setup(struct pl_ctx *p, const struct expr *e)
+static bool process_setup(struct pl_ctx *pl, const struct expr *e)
{
const char *s;
const struct expr *next;
@@ -116,22 +152,23 @@ static bool process_setup(struct pl_ctx *p, const struct expr *e)
continue;
if (!strcmp(s, "textsize")) {
- // meh
+ if (!get_size(next, &pl->tx, &pl->ty))
+ return 0;
} else if (!strcmp(s, "linewidth")) {
// meh
} else if (!strcmp(s, "textlinewidth")) {
// meh
} else if (!strcmp(s, "left_margin")) {
- if (!get_float(next, &p->l))
+ if (!get_float(next, &pl->l))
return 0;
} else if (!strcmp(s, "right_margin")) {
- if (!get_float(next, &p->r))
+ if (!get_float(next, &pl->r))
return 0;
} else if (!strcmp(s, "top_margin")) {
- if (!get_float(next, &p->t))
+ if (!get_float(next, &pl->t))
return 0;
} else if (!strcmp(s, "bottom_margin")) {
- if (!get_float(next, &p->b))
+ if (!get_float(next, &pl->b))
return 0;
} else {
warning("ignoring \"%s\"\n", s);
@@ -168,8 +205,7 @@ static bool process_font(struct pl_obj *obj, const struct expr *e)
continue;
if (!strcmp(s, "size")) {
- if (!get_coord(next, &obj->ex, &obj->ey,
- &obj->edx, &obj->edy))
+ if (!get_size(next, &obj->ex, &obj->ey))
return 0;
} else {
warning("ignoring \"%s\"\n", s);
@@ -351,6 +387,7 @@ struct pl_ctx *pl_parse(struct file *file)
pl = alloc_type(struct pl_ctx);
pl->sexpr_ctx = sexpr_new();
pl->l = pl->r = pl->t = pl->b = 0;
+ pl->tx = pl->ty = 0;
pl->objs = NULL;
if (!file_read(file, pl_parse_line, pl)) {
diff --git a/kicad/pl-render.c b/kicad/pl-render.c
index 6be02e4..311a0f5 100644
--- a/kicad/pl-render.c
+++ b/kicad/pl-render.c
@@ -42,11 +42,12 @@ static int coord(int v, int d, int o, int e)
}
-static void render_text(const struct pl_obj *obj, int x, int y)
+static void render_text(const struct pl_ctx *pl, const struct pl_obj *obj,
+ int x, int y)
{
struct text txt = {
.s = obj->s,
- .size = mil(obj->ey),
+ .size = mil(obj->ey ? obj->ey : pl->ty),
.x = x,
.y = y,
.rot = 0,
@@ -96,7 +97,7 @@ static void render_obj(const struct pl_ctx *pl, const struct pl_obj *obj,
}
break;
case pl_obj_text:
- render_text(obj, x, y);
+ render_text(pl, obj, x, y);
break;
default:
break;