cairo output started

This commit is contained in:
Mario Hüttel 2018-07-19 18:45:37 +02:00
parent b72466957c
commit 3167da4648
3 changed files with 48 additions and 3 deletions

View File

@ -19,15 +19,58 @@
#include "cairo-output.h" #include "cairo-output.h"
#include <math.h> #include <math.h>
#include <stdlib.h>
#include <cairo.h> #include <cairo.h>
#include <cairo-pdf.h> #include <cairo-pdf.h>
void cairo_render_cell_to_pdf(struct gds_cell *cell, GList *layer_infos, char *pdf_file) struct cairo_layer {
cairo_t *cr;
cairo_surface_t *rec;
struct layer_info *linfo;
};
void cairo_render_cell_to_pdf(struct gds_cell *cell, GList *layer_infos, char *pdf_file, double scale)
{ {
cairo_surface_t *surface; cairo_surface_t *surface;
cairo_t *cr; cairo_t *cr;
struct layer_info *linfo;
struct cairo_layer *layers;
struct cairo_layer *lay;
GList *info_list;
int i;
layers = (struct cairo_layer *)calloc(MAX_LAYERS, sizeof(struct cairo_layer));
/* Clear layers */
for (i = 0; i < MAX_LAYERS; i++) {
layers[i].cr = NULL;
layers[i].rec = NULL;
}
/* Create recording surface for each layer */
for (info_list = layer_infos; info_list != NULL; info_list = g_list_next(info_list)) {
linfo = (struct layer_info *)info_list->data;
if (linfo->layer < MAX_LAYERS) {
lay = &(layers[(unsigned int)linfo->layer]);
lay->linfo = linfo;
lay->rec = cairo_recording_surface_create(CAIRO_CONTENT_COLOR_ALPHA,
NULL);
lay->cr = cairo_create(layers[(unsigned int)linfo->layer].rec);
cairo_scale(lay->cr, 1/scale, 1/scale);
} else {
printf("Layer number (%d) too high!\n", linfo->layer);
goto ret_clear_layers;
}
}
ret_clear_layers:
for (i = 0; i < MAX_LAYERS; i++) {
lay = &layers[i];
cairo_destroy(lay->cr);
cairo_surface_destroy(lay->rec);
}
free(layers);
printf("cairo export not yet implemented!\n"); printf("cairo export not yet implemented!\n");
} }

View File

@ -23,6 +23,8 @@
#include "../layer-selector.h" #include "../layer-selector.h"
#include "../gds-parser/gds-types.h" #include "../gds-parser/gds-types.h"
void cairo_render_cell_to_pdf(struct gds_cell *cell, GList *layer_infos, char *pdf_file); #define MAX_LAYERS (2048)
void cairo_render_cell_to_pdf(struct gds_cell *cell, GList *layer_infos, char *pdf_file, double scale);
#endif /* __CAIRO_OUTPUT_H__ */ #endif /* __CAIRO_OUTPUT_H__ */

2
main.c
View File

@ -233,7 +233,7 @@ static void on_convert_clicked(gpointer button, gpointer user)
fclose(output_file); fclose(output_file);
break; break;
case RENDERER_CAIROGRAPHICS: case RENDERER_CAIROGRAPHICS:
cairo_render_cell_to_pdf(cell_to_render, layer_list, file_name); cairo_render_cell_to_pdf(cell_to_render, layer_list, file_name, sett.scale);
break; break;
} }
g_free(file_name); g_free(file_name);