1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-25 21:55:20 +02:00

eeshow/kicad/: begin text support for page layout (WIP); add missing pl-common.h

This commit is contained in:
Werner Almesberger 2016-08-22 04:40:40 -03:00
parent 5cfbf666f4
commit 8ac35d9192
3 changed files with 117 additions and 20 deletions

52
eeshow/kicad/pl-common.h Normal file
View File

@ -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 */

View File

@ -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);
}

View File

@ -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;
}