diff --git a/sch2fig/fig.c b/sch2fig/fig.c index 03de122..bf88a0c 100644 --- a/sch2fig/fig.c +++ b/sch2fig/fig.c @@ -76,6 +76,40 @@ static enum box_type flip_box(enum box_type box) } +void fig_label(int x, int y, const char *s, int dir, int dim, + enum fig_shape shape) +{ + struct text txt = { + .s = s, + .size = dim, + .x = x, + .y = y, + .rot = 0, + .hor = 0, + .vert = text_min, + }; + int dy; + + switch (dir) { + case 0: + txt.rot = 0; + txt.hor = text_min; + dy = 1; + break; + case 2: + txt.rot = 0; + txt.hor = text_max; + dy = 1; + break; + default: + assert(0); + } + + txt.y -= dy * LABEL_OFFSET; + text_fig(&txt, COLOR_LABEL, LAYER_LABEL); +} + + void fig_glabel(int x, int y, const char *s, int dir, int dim, enum fig_shape shape) { diff --git a/sch2fig/fig.h b/sch2fig/fig.h index 897be18..ed77aaf 100644 --- a/sch2fig/fig.h +++ b/sch2fig/fig.h @@ -28,6 +28,8 @@ enum fig_shape { /* schematics */ +void fig_label(int x, int y, const char *s, int dir, int dim, + enum fig_shape shape); void fig_glabel(int x, int y, const char *s, int dir, int dim, enum fig_shape shape); diff --git a/sch2fig/misc.c b/sch2fig/misc.c index 1a15c04..7a8fb44 100644 --- a/sch2fig/misc.c +++ b/sch2fig/misc.c @@ -36,3 +36,13 @@ unsigned matrix_to_angle(int m[6]) m[1], m[2], m[4], m[5]); exit(1); } + + +int angle_add(int a, int b) +{ + a += b; + while (a < 0) + a += 360; + return a % 360; +} + diff --git a/sch2fig/misc.h b/sch2fig/misc.h index e1007fc..e17e7ec 100644 --- a/sch2fig/misc.h +++ b/sch2fig/misc.h @@ -42,5 +42,6 @@ static inline int my(int x, int y, int m[6]) unsigned matrix_to_angle(int m[6]); +int angle_add(int a, int b); #endif /* !MISC_H */ diff --git a/sch2fig/sch.c b/sch2fig/sch.c index b491a7e..cd0ec0a 100644 --- a/sch2fig/sch.c +++ b/sch2fig/sch.c @@ -238,10 +238,10 @@ bool sch_parse(struct sch_ctx *ctx, const char *line) ctx->text = NULL; return 1; } - if (sscanf(line, "Text Label%n", &n) == 0 && n) { + if (sscanf(line, "Text Label %d %d %d %d", + &ctx->x, &ctx->y, &ctx->dir, &ctx->dim) == 4) { ctx->state = sch_text; - unsupported("Text Label"); - ctx->text = NULL; + ctx->text = fig_label; return 1; } diff --git a/sch2fig/style.h b/sch2fig/style.h index b92e4a8..dd4457a 100644 --- a/sch2fig/style.h +++ b/sch2fig/style.h @@ -29,6 +29,7 @@ #define COLOR_WIRE COLOR_GREEN4 #define COLOR_NOCONN COLOR_BLUE #define COLOR_GLABEL COLOR_RED4 +#define COLOR_LABEL COLOR_BLACK #define COLOR_FIELD COLOR_CYAN3 #define COLOR_PIN_NAME COLOR_FIELD #define COLOR_PIN_NUMBER COLOR_RED4 @@ -36,6 +37,7 @@ #define FONT_HELVETICA_BOLD 18 #define LAYER_GLABEL 20 +#define LAYER_LABEL LAYER_GLABEL #define LAYER_TEXT 30 #define LAYER_NOCONN 40 #define LAYER_WIRES 50 @@ -54,7 +56,8 @@ #define NOCONN_LEN 25 +#define LABEL_OFFSET 15 // eeschema has more like 10 #define GLABEL_OFFSET 20 -#define PIN_NUM_OFFSET 15 +#define PIN_NUM_OFFSET 15 // eeschema has more like 10 #endif /* !STYLE_H */ diff --git a/sch2fig/text.c b/sch2fig/text.c index a898674..eb2baee 100644 --- a/sch2fig/text.c +++ b/sch2fig/text.c @@ -18,6 +18,7 @@ #include #include "util.h" +#include "misc.h" #include "fig.h" #include "text.h" @@ -49,10 +50,7 @@ void text_set(struct text *txt, const char *s) void text_rot(struct text *txt, int deg) { - txt->rot += deg; - while (txt->rot < 0) - txt->rot += 360; - txt->rot %= 360; + txt->rot = angle_add(txt->rot, deg); }