From 356df44952df3a9d7ca445913e41a60739ee646b Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Mon, 22 Aug 2016 04:52:18 -0300 Subject: [PATCH] eeshow/kicad/: support text justification in page layout --- eeshow/kicad/pl-common.h | 3 +++ eeshow/kicad/pl-parse.c | 34 +++++++++++++++++++++++++++++++++- eeshow/kicad/pl-render.c | 19 +++++++++++++++++-- 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/eeshow/kicad/pl-common.h b/eeshow/kicad/pl-common.h index 72ce0f3..4680efd 100644 --- a/eeshow/kicad/pl-common.h +++ b/eeshow/kicad/pl-common.h @@ -14,6 +14,7 @@ #ifndef KICAD_PL_COMMON_H #define KICAD_PL_COMMON_H +#include "gfx/text.h" #include "kicad/sexpr.h" @@ -39,6 +40,8 @@ struct pl_obj { float incrx, incry; int incrlabel; /* tbtext */ int font; /* tbtext (flags) */ + enum text_align hor; /* tbtext */ + enum text_align vert; /* tbtext */ struct pl_obj *next; }; diff --git a/eeshow/kicad/pl-parse.c b/eeshow/kicad/pl-parse.c index 5b75f64..467ceca 100644 --- a/eeshow/kicad/pl-parse.c +++ b/eeshow/kicad/pl-parse.c @@ -17,6 +17,7 @@ #include "misc/util.h" #include "misc/diag.h" +#include "gfx/text.h" #include "file/file.h" #include "kicad/sexpr.h" #include "kicad/pl-common.h" @@ -170,8 +171,34 @@ static bool process_font(struct pl_obj *obj, const struct expr *e) if (!get_coord(next, &obj->ex, &obj->ey, &obj->edx, &obj->edy)) return 0; - } else + } else { warning("ignoring \"%s\"\n", s); + } + } + return 1; +} + + +static bool process_justify(struct pl_obj *obj, const struct expr *e) +{ + for (; e; e = e->next) { + if (e->e) { + warning("ignoring list\n"); + continue; + } + + if (!strcmp(e->s, "center")) + obj->hor = obj->vert = text_mid; + else if (!strcmp(e->s, "left")) + obj->hor = text_min; + else if (!strcmp(e->s, "right")) + obj->hor = text_max; + else if (!strcmp(e->s, "top")) + obj->vert = text_max; + else if (!strcmp(e->s, "bottom")) + obj->vert = text_min; + else + warning("ignoring \"%s\"\n", e->s); } return 1; } @@ -194,6 +221,8 @@ static bool process_obj(struct pl_ctx *pl, const struct expr *e, obj->incry = 0; obj->incrlabel = 0; obj->font = 0; + obj->hor = text_min; + obj->vert = text_mid; for (; e; e = e->next) { if (e->s) { @@ -242,6 +271,9 @@ static bool process_obj(struct pl_ctx *pl, const struct expr *e, } else if (!strcmp(s, "font")) { if (!process_font(obj, next)) return 0; + } else if (!strcmp(s, "justify")) { + if (!process_justify(obj, next)) + return 0; } else warning("ignoring \"%s\"\n", s); } diff --git a/eeshow/kicad/pl-render.c b/eeshow/kicad/pl-render.c index b682a82..6be02e4 100644 --- a/eeshow/kicad/pl-render.c +++ b/eeshow/kicad/pl-render.c @@ -42,6 +42,22 @@ static int coord(int v, int d, int o, int e) } +static void render_text(const struct pl_obj *obj, int x, int y) +{ + struct text txt = { + .s = obj->s, + .size = mil(obj->ey), + .x = x, + .y = y, + .rot = 0, + .hor = obj->hor, + .vert = obj->vert, + }; + + text_fig(&txt, COLOR_COMP_DWG, LAYER_COMP_DWG); +} + + static void render_obj(const struct pl_ctx *pl, const struct pl_obj *obj, unsigned i, int w, int h) { @@ -80,8 +96,7 @@ static void render_obj(const struct pl_ctx *pl, const struct pl_obj *obj, } break; case pl_obj_text: - gfx_text(x, y, obj->s, mil(obj->ey), text_min, 0, - COLOR_COMP_DWG, LAYER_COMP_DWG); + render_text(obj, x, y); break; default: break;