mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-26 20:51:33 +02:00
sch2fig/: support multi-page PDF
This commit is contained in:
parent
97ac2297e1
commit
55f10b8769
@ -14,7 +14,6 @@
|
|||||||
- PDF TOC
|
- PDF TOC
|
||||||
- let user set PNG size or zoom level
|
- let user set PNG size or zoom level
|
||||||
- implement dashed lines in cairo.c
|
- implement dashed lines in cairo.c
|
||||||
- implement multi-page PDF output in cairo.o
|
|
||||||
- use correct color for hierarchical items, 0x848400 (or close) instead of
|
- use correct color for hierarchical items, 0x848400 (or close) instead of
|
||||||
COLOR_BROWN2
|
COLOR_BROWN2
|
||||||
- directly pick versions out of git, without requiring checkout to file
|
- directly pick versions out of git, without requiring checkout to file
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@ -47,6 +48,9 @@ struct cairo_ctx {
|
|||||||
cairo_t *cr;
|
cairo_t *cr;
|
||||||
cairo_surface_t *s;
|
cairo_surface_t *s;
|
||||||
|
|
||||||
|
struct layer *sheets; /* for PDF */
|
||||||
|
unsigned n_sheets;
|
||||||
|
|
||||||
const char *output_name;
|
const char *output_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -230,6 +234,9 @@ static struct cairo_ctx *init_common(int argc, char *const *argv)
|
|||||||
cc->xo = cc->yo = 0;
|
cc->xo = cc->yo = 0;
|
||||||
cc->scale = DEFAULT_SCALE;
|
cc->scale = DEFAULT_SCALE;
|
||||||
|
|
||||||
|
cc->sheets = NULL;
|
||||||
|
cc->n_sheets = 0;
|
||||||
|
|
||||||
cc->output_name = NULL;
|
cc->output_name = NULL;
|
||||||
while ((c = getopt(argc, argv, "o:s:")) != EOF)
|
while ((c = getopt(argc, argv, "o:s:")) != EOF)
|
||||||
switch (c) {
|
switch (c) {
|
||||||
@ -322,23 +329,46 @@ static void cr_png_end(void *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void cr_pdf_new_sheet(void *ctx)
|
||||||
|
{
|
||||||
|
struct cairo_ctx *cc = ctx;
|
||||||
|
|
||||||
|
cc->n_sheets++;
|
||||||
|
cc->sheets = realloc(cc->sheets, sizeof(struct layer) * cc->n_sheets);
|
||||||
|
if (!cc->sheets) {
|
||||||
|
perror("realloc");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
cc->sheets[cc->n_sheets - 1] = cc->layer;
|
||||||
|
layer_wipe(&cc->layer);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void cr_pdf_end(void *ctx)
|
static void cr_pdf_end(void *ctx)
|
||||||
{
|
{
|
||||||
struct cairo_ctx *cc = ctx;
|
struct cairo_ctx *cc = ctx;
|
||||||
int w, h;
|
int w, h;
|
||||||
|
unsigned i;
|
||||||
|
|
||||||
end_common(cc, &w, &h);
|
end_common(cc, &w, &h);
|
||||||
|
|
||||||
cc->s = cairo_pdf_surface_create(cc->output_name, w, h);
|
cc->s = cairo_pdf_surface_create(cc->output_name, w, h);
|
||||||
cc->cr = cairo_create(cc->s);
|
cc->cr = cairo_create(cc->s);
|
||||||
|
|
||||||
set_color(cc->cr, COLOR_WHITE);
|
|
||||||
cairo_paint(cc->cr);
|
|
||||||
|
|
||||||
cairo_select_font_face(cc->cr, "Helvetica", CAIRO_FONT_SLANT_NORMAL,
|
cairo_select_font_face(cc->cr, "Helvetica", CAIRO_FONT_SLANT_NORMAL,
|
||||||
CAIRO_FONT_WEIGHT_BOLD);
|
CAIRO_FONT_WEIGHT_BOLD);
|
||||||
cairo_set_line_width(cc->cr, 3);
|
cairo_set_line_width(cc->cr, 3);
|
||||||
|
|
||||||
|
for (i = 0; i != cc->n_sheets; i++) {
|
||||||
|
set_color(cc->cr, COLOR_WHITE);
|
||||||
|
cairo_paint(cc->cr);
|
||||||
|
|
||||||
|
layer_replay(cc->sheets + i);
|
||||||
|
layer_destroy(cc->sheets + i);
|
||||||
|
|
||||||
|
cairo_show_page(cc->cr);
|
||||||
|
}
|
||||||
|
|
||||||
layer_replay(&cc->layer);
|
layer_replay(&cc->layer);
|
||||||
layer_destroy(&cc->layer);
|
layer_destroy(&cc->layer);
|
||||||
|
|
||||||
@ -373,5 +403,6 @@ const struct gfx_ops cairo_pdf_ops = {
|
|||||||
.text = layer_text,
|
.text = layer_text,
|
||||||
.text_width = cr_text_width,
|
.text_width = cr_text_width,
|
||||||
.init = cr_pdf_init,
|
.init = cr_pdf_init,
|
||||||
|
.new_sheet = cr_pdf_new_sheet,
|
||||||
.end = cr_pdf_end,
|
.end = cr_pdf_end,
|
||||||
};
|
};
|
||||||
|
@ -234,6 +234,12 @@ void layer_init(struct layer *layer, const struct gfx_ops *ops, void *user)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void layer_wipe(struct layer *layer)
|
||||||
|
{
|
||||||
|
layer->objs = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void layer_replay(const struct layer *layer)
|
void layer_replay(const struct layer *layer)
|
||||||
{
|
{
|
||||||
const struct gfx_ops *ops = layer->ops;
|
const struct gfx_ops *ops = layer->ops;
|
||||||
|
@ -49,6 +49,7 @@ void layer_text(void *ctx, int x, int y, const char *s, unsigned size,
|
|||||||
enum text_align align, int rot, unsigned color, unsigned layer);
|
enum text_align align, int rot, unsigned color, unsigned layer);
|
||||||
|
|
||||||
void layer_init(struct layer *layer, const struct gfx_ops *ops, void *user);
|
void layer_init(struct layer *layer, const struct gfx_ops *ops, void *user);
|
||||||
|
void layer_wipe(struct layer *layer);
|
||||||
void layer_replay(const struct layer *layer);
|
void layer_replay(const struct layer *layer);
|
||||||
void layer_bbox(const struct layer *layer, int *x, int *y, int *w, int *h);
|
void layer_bbox(const struct layer *layer, int *x, int *y, int *w, int *h);
|
||||||
void layer_destroy(struct layer *layer);
|
void layer_destroy(struct layer *layer);
|
||||||
|
Loading…
Reference in New Issue
Block a user