summaryrefslogtreecommitdiff
path: root/kicad
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-08-26 01:03:23 -0300
committerWerner Almesberger <werner@almesberger.net>2016-08-26 01:40:30 -0300
commitce09b77d3be3cf2f61142dbdf22b05afe881f59c (patch)
tree84ec067aa1235f863ba595454a9f1605ca54c27a /kicad
parentf99f39fd163f8b84b11dbfd576f5d010b09c790f (diff)
downloadeeshow-ce09b77d3be3cf2f61142dbdf22b05afe881f59c.tar.gz
eeshow-ce09b77d3be3cf2f61142dbdf22b05afe881f59c.tar.bz2
eeshow-ce09b77d3be3cf2f61142dbdf22b05afe881f59c.zip
fully decode text attributes in sch-parse.c and lib-parse.c
Diffstat (limited to 'kicad')
-rw-r--r--kicad/lib-parse.c36
-rw-r--r--kicad/sch-parse.c61
-rw-r--r--kicad/sch.h1
3 files changed, 73 insertions, 25 deletions
diff --git a/kicad/lib-parse.c b/kicad/lib-parse.c
index 122c389..e24e37a 100644
--- a/kicad/lib-parse.c
+++ b/kicad/lib-parse.c
@@ -25,13 +25,21 @@
/* ----- Text -------------------------------------------------------------- */
-static enum text_style decode_style(const char *s)
+static enum text_style decode_style(const char *s, unsigned bold)
{
+ enum text_style res;
+
if (!strcmp(s, "Normal"))
- return text_normal;
- if (!strcmp(s, "Italic"))
- return text_italic;
- assert(0);
+ res = text_normal;
+ else if (!strcmp(s, "Italic"))
+ res = text_italic;
+ else
+ error("unrecognized text attribute \"%s\"", s);
+
+ if (bold)
+ res |= text_bold;
+
+ return res;
}
@@ -197,7 +205,7 @@ static bool lib_parse_line(const struct file *file,
unsigned points;
struct lib_obj *obj;
char *s, *style;
- unsigned zero1, zero2;
+ unsigned zero, bold;
char vis;
switch (lib->state) {
@@ -265,15 +273,15 @@ static bool lib_parse_line(const struct file *file,
n = sscanf(line,
"T %d %d %d %d %u %u %u \"%m[^\"]\" %ms %u %c %c",
&obj->u.text.orient, &obj->u.text.x, &obj->u.text.y,
- &obj->u.text.dim, &zero1, &obj->unit, &obj->convert,
- &obj->u.text.s, &style, &zero2,
+ &obj->u.text.dim, &zero, &obj->unit, &obj->convert,
+ &obj->u.text.s, &style, &bold,
&obj->u.text.hor_align, &obj->u.text.vert_align);
if (n != 12) {
n = sscanf(line,
"T %d %d %d %d %u %u %u %ms %ms %u %c %c",
&obj->u.text.orient, &obj->u.text.x, &obj->u.text.y,
- &obj->u.text.dim, &zero1, &obj->unit, &obj->convert,
- &obj->u.text.s, &style, &zero2,
+ &obj->u.text.dim, &zero, &obj->unit, &obj->convert,
+ &obj->u.text.s, &style, &bold,
&obj->u.text.hor_align, &obj->u.text.vert_align);
while (n == 12) {
char *tilde;
@@ -284,15 +292,13 @@ static bool lib_parse_line(const struct file *file,
*tilde = ' ';
}
}
- /*
- * zero2 seems to be the font style: 0 = normal, 1 = bold ?
- */
if (n == 12) {
- if (zero1)
+ if (zero)
fatal("%u: only understand 0 x x\n"
"\"%s\"", file->lineno, line);
- obj->u.text.style = decode_style(style);
+ obj->u.text.style = decode_style(style, bold);
obj->type = lib_obj_text;
+ free(style);
return 1;
}
s = NULL;
diff --git a/kicad/sch-parse.c b/kicad/sch-parse.c
index 9f98d0f..0049241 100644
--- a/kicad/sch-parse.c
+++ b/kicad/sch-parse.c
@@ -56,6 +56,26 @@ static enum dwg_shape decode_shape(const char *s)
}
+static enum text_style decode_style(const char *italic, int bold)
+{
+ enum text_style res;
+
+ if (!strcmp(italic, "~"))
+ res = text_normal;
+ else if (!strcmp(italic, "Italic"))
+ res = text_italic;
+ else {
+ error ("unrecognized text attribute \"%s\"", italic);
+ res = text_normal;
+ }
+
+ if (bold)
+ res |= text_bold;
+
+ return res;
+}
+
+
/* ----- Component fields -------------------------------------------------- */
@@ -175,7 +195,15 @@ static bool parse_field(struct sch_ctx *ctx, const char *line)
decode_alignment(txt, hor, vert);
- // @@@ decode font
+ txt->style = text_normal;
+ if (italic == 'I')
+ txt->style |= text_italic;
+ else if (italic != 'N')
+ error("unknown italic value \"%c\"", italic);
+ if (bold == 'B')
+ txt->style |= text_bold;
+ else if (bold != 'N')
+ error("unknown bold value \"%c\"", italic);
return 1;
}
@@ -376,7 +404,8 @@ static bool parse_line(const struct file *file, void *user, const char *line)
struct sch_ctx *ctx = user;
struct sch_obj *obj = &ctx->obj;
int n = 0;
- char *s;
+ char *s, *italic;
+ int bold;
switch (ctx->state) {
case sch_basic:
@@ -399,33 +428,45 @@ static bool parse_line(const struct file *file, void *user, const char *line)
struct sch_text *text = &obj->u.text;
- if (sscanf(line, "Text Notes %d %d %d %d",
- &obj->x, &obj->y, &text->dir, &text->dim) == 4) {
+ if (sscanf(line, "Text Notes %d %d %d %d %ms %d",
+ &obj->x, &obj->y, &text->dir, &text->dim, &italic, &bold)
+ == 6) {
ctx->state = sch_text;
obj->u.text.fn = dwg_text;
obj->u.text.shape = dwg_unspec; /* not used for text */
+ obj->u.text.style = decode_style(italic, bold);
+ free(italic);
return 1;
}
- if (sscanf(line, "Text GLabel %d %d %d %d %ms",
- &obj->x, &obj->y, &text->dir, &text->dim, &s) == 5) {
+ if (sscanf(line, "Text GLabel %d %d %d %d %ms %ms %d",
+ &obj->x, &obj->y, &text->dir, &text->dim, &s,
+ &italic, &bold) == 7) {
ctx->state = sch_text;
obj->u.text.fn = dwg_glabel;
obj->u.text.shape = decode_shape(s);
+ obj->u.text.style = decode_style(italic, bold);
+ free(italic);
return 1;
}
- if (sscanf(line, "Text HLabel %d %d %d %d %ms",
- &obj->x, &obj->y, &text->dir, &text->dim, &s) == 5) {
+ if (sscanf(line, "Text HLabel %d %d %d %d %ms %ms %d",
+ &obj->x, &obj->y, &text->dir, &text->dim, &s,
+ &italic, &bold) == 7) {
ctx->state = sch_text;
obj->u.text.fn = dwg_hlabel;
obj->u.text.shape = decode_shape(s);
+ obj->u.text.style = decode_style(italic, bold);
+ free(italic);
return 1;
}
- if (sscanf(line, "Text Label %d %d %d %d",
- &obj->x, &obj->y, &text->dir, &text->dim) == 4) {
+ if (sscanf(line, "Text Label %d %d %d %d %ms %d",
+ &obj->x, &obj->y, &text->dir, &text->dim,
+ &italic, &bold) == 6) {
ctx->state = sch_text;
obj->u.text.fn = dwg_label;
obj->u.text.shape = dwg_unspec;
/* not used for (local) labels */
+ obj->u.text.style = decode_style(italic, bold);
+ free(italic);
return 1;
}
diff --git a/kicad/sch.h b/kicad/sch.h
index 48c2ee5..1ccb3fd 100644
--- a/kicad/sch.h
+++ b/kicad/sch.h
@@ -63,6 +63,7 @@ struct sch_obj {
int dir; /* orientation */
int dim; /* dimension */
enum dwg_shape shape;
+ enum text_style style;
struct dwg_bbox bbox; /* set when rendering; glabel */
} text;
struct sch_comp {