Merge branch 'multithread-dev' into dev
Current progess: Changed output renderers to GObjects derived from a base class. Furthermore, added base structure for future multithreading
This commit is contained in:
commit
1b62427770
@ -17,19 +17,17 @@ add_definitions(${GLIB2_CFLAGS_OTHER})
|
||||
aux_source_directory("widgets" LAYER_SOURCES)
|
||||
aux_source_directory("cell-selector" CELL_SELECTOR_SOURCES)
|
||||
aux_source_directory("gds-utils" GDS_SOURCES)
|
||||
aux_source_directory("latex-renderer" LATEX_SOURCES)
|
||||
aux_source_directory("cairo-renderer" CAIRO_SOURCES)
|
||||
aux_source_directory("output-renderers" OUTPUT_RENDERER_SOURCES)
|
||||
aux_source_directory("geometric" GEOMETRIC_SOURCES)
|
||||
aux_source_directory("layer" LAYER_SELECTOR_SOURCES)
|
||||
set(SOURCE "main.c" "command-line.c" "gds-render-gui.c" "external-renderer.c")
|
||||
set(SOURCE "main.c" "command-line.c" "gds-render-gui.c")
|
||||
|
||||
set(SOURCE
|
||||
${SOURCE}
|
||||
${LAYER_SOURCES}
|
||||
${CELL_SELECTOR_SOURCES}
|
||||
${GDS_SOURCES}
|
||||
${LATEX_SOURCES}
|
||||
${CAIRO_SOURCES}
|
||||
${OUTPUT_RENDERER_SOURCES}
|
||||
${GEOMETRIC_SOURCES}
|
||||
${LAYER_SELECTOR_SOURCES}
|
||||
)
|
||||
|
252
command-line.c
252
command-line.c
@ -34,127 +34,178 @@
|
||||
#include <gds-render/gds-utils/gds-parser.h>
|
||||
#include <gds-render/layer/mapping-parser.h>
|
||||
#include <gds-render/layer/layer-info.h>
|
||||
#include <gds-render/cairo-renderer/cairo-output.h>
|
||||
#include <gds-render/latex-renderer/latex-output.h>
|
||||
#include <gds-render/external-renderer.h>
|
||||
#include <gds-render/output-renderers/cairo-renderer.h>
|
||||
#include <gds-render/output-renderers/latex-renderer.h>
|
||||
#include <gds-render/output-renderers/external-renderer.h>
|
||||
#include <gds-render/gds-utils/gds-tree-checker.h>
|
||||
|
||||
/**
|
||||
* @brief Delete layer_info and free nem element.
|
||||
*
|
||||
* Like delete_layer_info_struct() but also frees layer_info::name
|
||||
* @param info
|
||||
* @warning This function must not be used if the layer_info::name field references the internal storage strings if e.g. an entry field
|
||||
*/
|
||||
static void delete_layer_info_with_name(struct layer_info *info)
|
||||
static int string_array_count(char **string_array)
|
||||
{
|
||||
if (info) {
|
||||
if (info->name)
|
||||
g_free(info->name);
|
||||
free(info);
|
||||
}
|
||||
int count;
|
||||
|
||||
if (!string_array)
|
||||
return 0;
|
||||
|
||||
for (count = 0; *string_array; string_array++)
|
||||
count++;
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
void command_line_convert_gds(char *gds_name, char *pdf_name, char *tex_name, gboolean pdf, gboolean tex,
|
||||
char *layer_file, char *cell_name, double scale, gboolean pdf_layers,
|
||||
gboolean pdf_standalone, gboolean svg, char *svg_name, char *so_name, char *so_out_file)
|
||||
static int create_renderers(char **renderers,
|
||||
char **output_file_names,
|
||||
gboolean tex_layers,
|
||||
gboolean tex_standalone,
|
||||
const char *so_path,
|
||||
GList **renderer_list,
|
||||
LayerSettings *layer_settings)
|
||||
{
|
||||
GList *libs = NULL;
|
||||
FILE *tex_file;
|
||||
int res;
|
||||
GFile *file;
|
||||
int i;
|
||||
GFileInputStream *stream;
|
||||
GDataInputStream *dstream;
|
||||
gboolean layer_export;
|
||||
GdkRGBA layer_color;
|
||||
int layer;
|
||||
char *layer_name;
|
||||
GList *layer_info_list = NULL;
|
||||
GList *cell_list;
|
||||
struct layer_info *linfo_temp;
|
||||
struct gds_library *first_lib;
|
||||
struct gds_cell *toplevel_cell = NULL, *temp_cell;
|
||||
char **renderer_iter;
|
||||
char *current_renderer;
|
||||
int idx;
|
||||
char *current_out_file;
|
||||
int count_render, count_out;
|
||||
GdsOutputRenderer *output_renderer;
|
||||
|
||||
if (!renderer_list)
|
||||
return -1;
|
||||
|
||||
if (!renderers || !output_file_names) {
|
||||
fprintf(stderr, "Please specify renderers and file names\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
count_render = string_array_count(renderers);
|
||||
count_out = string_array_count(output_file_names);
|
||||
if (count_render != count_out) {
|
||||
fprintf(stderr, "Count of renderers %d does not match count of output file names %d\n",
|
||||
count_render, count_out);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Parse cmd line parameters */
|
||||
for (renderer_iter = renderers, idx = 0; *renderer_iter; renderer_iter++, idx++) {
|
||||
current_renderer = *renderer_iter;
|
||||
current_out_file = output_file_names[idx];
|
||||
|
||||
/* File valid ? */
|
||||
if (!current_out_file || !current_out_file[0])
|
||||
continue;
|
||||
|
||||
if (!strcmp(current_renderer, "tikz")) {
|
||||
output_renderer = GDS_RENDER_OUTPUT_RENDERER(latex_renderer_new_with_options(tex_layers,
|
||||
tex_standalone));
|
||||
} else if (!strcmp(current_renderer, "pdf")) {
|
||||
output_renderer = GDS_RENDER_OUTPUT_RENDERER(cairo_renderer_new_pdf());
|
||||
} else if (!strcmp(current_renderer, "svg")) {
|
||||
output_renderer = GDS_RENDER_OUTPUT_RENDERER(cairo_renderer_new_svg());
|
||||
} else if (!strcmp(current_renderer, "ext")) {
|
||||
if (!so_path) {
|
||||
fprintf(stderr, "Please specify shared object for external renderer. Will ignore this renderer.\n");
|
||||
continue;
|
||||
}
|
||||
output_renderer = GDS_RENDER_OUTPUT_RENDERER(external_renderer_new_with_so(so_path));
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
gds_output_renderer_set_output_file(output_renderer, current_out_file);
|
||||
gds_output_renderer_set_layer_settings(output_renderer, layer_settings);
|
||||
*renderer_list = g_list_append(*renderer_list, output_renderer);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct gds_cell *find_gds_cell_in_lib(struct gds_library *lib, const char *cell_name)
|
||||
{
|
||||
GList *cell_list;
|
||||
struct gds_cell *return_cell = NULL;
|
||||
struct gds_cell *temp_cell;
|
||||
|
||||
for (cell_list = lib->cells; cell_list; cell_list = g_list_next(cell_list)) {
|
||||
temp_cell = (struct gds_cell *)cell_list->data;
|
||||
if (!strncmp(temp_cell->name, cell_name, CELL_NAME_MAX)) {
|
||||
return_cell = temp_cell;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return return_cell;
|
||||
}
|
||||
|
||||
int command_line_convert_gds(const char *gds_name,
|
||||
const char *cell_name,
|
||||
char **renderers,
|
||||
char **output_file_names,
|
||||
const char *layer_file,
|
||||
const char *so_path,
|
||||
gboolean tex_standalone,
|
||||
gboolean tex_layers,
|
||||
double scale)
|
||||
{
|
||||
int ret = -1;
|
||||
GList *libs = NULL;
|
||||
int res;
|
||||
GList *renderer_list = NULL;
|
||||
GList *list_iter;
|
||||
struct gds_library *first_lib;
|
||||
struct gds_cell *toplevel_cell = NULL;
|
||||
LayerSettings *layer_sett;
|
||||
GdsOutputRenderer *current_renderer;
|
||||
|
||||
/* Check if parameters are valid */
|
||||
if (!gds_name || (!pdf_name && pdf) || (!tex_name && tex) || !layer_file || !cell_name) {
|
||||
if (!gds_name || !cell_name || !output_file_names || !layer_file || !renderers) {
|
||||
printf("Probably missing argument. Check --help option\n");
|
||||
return;
|
||||
return -2;
|
||||
}
|
||||
|
||||
/* Load layer_settings */
|
||||
layer_sett = layer_settings_new();
|
||||
layer_settings_load_from_csv(layer_sett, layer_file);
|
||||
|
||||
/* Create renderers */
|
||||
if (create_renderers(renderers, output_file_names, tex_layers, tex_standalone,
|
||||
so_path, &renderer_list, layer_sett))
|
||||
goto ret_destroy_layer_mapping;
|
||||
|
||||
|
||||
/* Load GDS */
|
||||
clear_lib_list(&libs);
|
||||
res = parse_gds_from_file(gds_name, &libs);
|
||||
if (res)
|
||||
goto ret_destroy_library_list;
|
||||
|
||||
file = g_file_new_for_path(layer_file);
|
||||
stream = g_file_read(file, NULL, NULL);
|
||||
|
||||
if (!stream) {
|
||||
printf("Layer mapping not readable!\n");
|
||||
goto ret_destroy_file;
|
||||
}
|
||||
dstream = g_data_input_stream_new(G_INPUT_STREAM(stream));
|
||||
i = 0;
|
||||
do {
|
||||
res = mapping_parser_load_line(dstream, &layer_export, &layer_name, &layer, &layer_color);
|
||||
if (res == 0) {
|
||||
if (!layer_export)
|
||||
continue;
|
||||
linfo_temp = (struct layer_info *)malloc(sizeof(struct layer_info));
|
||||
if (!linfo_temp) {
|
||||
printf("Out of memory\n");
|
||||
goto ret_clear_layer_list;
|
||||
}
|
||||
linfo_temp->color.alpha = layer_color.alpha;
|
||||
linfo_temp->color.red = layer_color.red;
|
||||
linfo_temp->color.green = layer_color.green;
|
||||
linfo_temp->color.blue = layer_color.blue;
|
||||
linfo_temp->name = layer_name;
|
||||
linfo_temp->stacked_position = i++;
|
||||
linfo_temp->layer = layer;
|
||||
layer_info_list = g_list_append(layer_info_list, (gpointer)linfo_temp);
|
||||
}
|
||||
} while(res >= 0);
|
||||
|
||||
|
||||
/* find_cell in first library. */
|
||||
if (!libs)
|
||||
goto ret_clear_layer_list;
|
||||
goto ret_clear_renderers;
|
||||
|
||||
first_lib = (struct gds_library *)libs->data;
|
||||
if (!first_lib) {
|
||||
fprintf(stderr, "No library in library list. This should not happen.\n");
|
||||
goto ret_clear_layer_list;
|
||||
/* This is safe. Library destruction can handle an empty list element */
|
||||
goto ret_destroy_library_list;
|
||||
}
|
||||
|
||||
for (cell_list = first_lib->cells; cell_list != NULL; cell_list = g_list_next(cell_list)) {
|
||||
temp_cell = (struct gds_cell *)cell_list->data;
|
||||
if (!strcmp(temp_cell->name, cell_name)) {
|
||||
toplevel_cell = temp_cell;
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* Find cell in first library */
|
||||
toplevel_cell = find_gds_cell_in_lib(first_lib, cell_name);
|
||||
|
||||
if (!toplevel_cell) {
|
||||
printf("Couldn't find cell in first library!\n");
|
||||
goto ret_clear_layer_list;
|
||||
goto ret_destroy_library_list;
|
||||
}
|
||||
|
||||
/* Check if cell passes vital checks */
|
||||
res = gds_tree_check_reference_loops(toplevel_cell->parent_library);
|
||||
if (res < 0) {
|
||||
fprintf(stderr, "Checking library %s failed.\n", first_lib->name);
|
||||
goto ret_clear_layer_list;
|
||||
goto ret_destroy_library_list;
|
||||
} else if (res > 0) {
|
||||
fprintf(stderr, "%d reference loops found.\n", res);
|
||||
|
||||
/* do further checking if the specified cell and/or its subcells are affected */
|
||||
if (toplevel_cell->checks.affected_by_reference_loop == 1) {
|
||||
fprintf(stderr, "Cell is affected by reference loop. Abort!\n");
|
||||
goto ret_clear_layer_list;
|
||||
goto ret_destroy_library_list;
|
||||
}
|
||||
}
|
||||
|
||||
@ -165,40 +216,21 @@ void command_line_convert_gds(char *gds_name, char *pdf_name, char *tex_name, gb
|
||||
* Deal with it.
|
||||
*/
|
||||
|
||||
/* Render outputs */
|
||||
if (pdf == TRUE || svg == TRUE) {
|
||||
cairo_render_cell_to_vector_file(toplevel_cell, layer_info_list, (pdf == TRUE ? pdf_name : NULL),
|
||||
(svg == TRUE ? svg_name : NULL), scale);
|
||||
/* Execute all rendererer instances */
|
||||
for (list_iter = renderer_list; list_iter; list_iter = list_iter->next) {
|
||||
current_renderer = GDS_RENDER_OUTPUT_RENDERER(list_iter->data);
|
||||
gds_output_renderer_render_output(current_renderer, toplevel_cell, scale);
|
||||
}
|
||||
|
||||
if (tex == TRUE) {
|
||||
tex_file = fopen(tex_name, "w");
|
||||
if (!tex_file)
|
||||
goto ret_clear_layer_list;
|
||||
latex_render_cell_to_code(toplevel_cell, layer_info_list, tex_file, scale, pdf_layers, pdf_standalone);
|
||||
fclose(tex_file);
|
||||
}
|
||||
|
||||
if (so_name && so_out_file) {
|
||||
if (strlen(so_name) == 0 || strlen(so_out_file) == 0)
|
||||
goto ret_clear_layer_list;
|
||||
|
||||
/* Render output using external renderer */
|
||||
printf("Invoking external renderer!\n");
|
||||
external_renderer_render_cell(toplevel_cell, layer_info_list, so_out_file, so_name);
|
||||
printf("External renderer finished!\n");
|
||||
}
|
||||
|
||||
ret_clear_layer_list:
|
||||
g_list_free_full(layer_info_list, (GDestroyNotify)delete_layer_info_with_name);
|
||||
|
||||
g_object_unref(dstream);
|
||||
g_object_unref(stream);
|
||||
ret_destroy_file:
|
||||
g_object_unref(file);
|
||||
/* Delete all allocated libraries */
|
||||
ret_destroy_library_list:
|
||||
clear_lib_list(&libs);
|
||||
ret_clear_renderers:
|
||||
for (list_iter = renderer_list; list_iter; list_iter = list_iter->next) {
|
||||
g_object_unref(list_iter->data);
|
||||
}
|
||||
ret_destroy_layer_mapping:
|
||||
g_object_unref(layer_sett);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
@ -3,19 +3,25 @@
|
||||
@section cmd Command Line Interface
|
||||
To use the application on the command line check 'gds-render `--`help'.
|
||||
|
||||
Usage:
|
||||
gds-render [OPTION…] FILE - Convert GDS file <FILE> to graphic
|
||||
|
||||
Help Options:
|
||||
-h, '--'help Show help options
|
||||
'--'help-all Show all help options
|
||||
'--'help-gtk Show GTK+ Options
|
||||
|
||||
Application Options:
|
||||
- -t, `--`tikz Output TikZ code
|
||||
- -p, `--`pdf Output PDF document
|
||||
- -s, `--`scale=SCALE Divide output coordinates by SCALE
|
||||
- -o, `--`tex-output=PATH Optional path for TeX file
|
||||
- -O, `--`pdf-output=PATH Optional path for PDF file
|
||||
- -m, `--`mapping=PATH Path for Layer Mapping File
|
||||
- -c, `--`cell=NAME Cell to render
|
||||
- -a, `--`tex-standalone Create standalone PDF
|
||||
- -l, `--`tex-layers Create PDF Layers (OCG)
|
||||
- -P, `--`custom-render-lib=PATH Path to a custom shared object, that implements the render_cell_to_file function
|
||||
- -e, `--`external-lib-output=PATH Output path for external render library
|
||||
- `--`display=DISPLAY X display to use
|
||||
-v, '--'version Print version
|
||||
-r, '--'renderer=pdf|svg|tikz|ext Renderer to use
|
||||
-s, '--'scale=<SCALE> Divide output coordinates by <SCALE>
|
||||
-o, '--'output-file=PATH Output file path
|
||||
-m, '--'mapping=PATH Path for Layer Mapping File
|
||||
-c, '--'cell=NAME Cell to render
|
||||
-a, '--'tex-standalone Create standalone PDF
|
||||
-l, '--'tex-layers Create PDF Layers (OCG)
|
||||
-P, '--'custom-render-lib=PATH Path to a custom shared object, that implements the render_cell_to_file function
|
||||
'--'display=DISPLAY X display to use
|
||||
|
||||
|
||||
@section gui Graphical User Interface
|
||||
@ -27,7 +33,7 @@ It is possible to export the layer configurations so they can be used later on.
|
||||
@image html gui.png
|
||||
@image latex gui.png
|
||||
|
||||
The cell selector on the left shows the GDS Libraries and Cells. The cells are marked green if all references inside the cell could be found. If not all references could be found, the cell is marked orange. This doens't show if child cells have missing childs. Only one level of the hierarchy is checked in order to make it easier to spot an errorneous cell. Cells with missing child cells are still renderable but -- obviously -- faulty. If a cell or any sub-cell contains a reference loop, the cell is marked red. In this case it can't be selected for rendering.
|
||||
The cell selector on the left shows the GDS Libraries and Cells. The cells are marked green if all references inside the cell could be found. If not all references could be found, the cell is marked orange. This doens't show if child cells have missing childs. Only one level of the hierarchy is checked in order to make it easier to spot an errorneous cell. Cells with missing child cells are still renderable but '--' obviously '--' faulty. If a cell or any sub-cell contains a reference loop, the cell is marked red. In this case it can't be selected for rendering.
|
||||
|
||||
In the above image the cell is green; so everything is okay.
|
||||
|
||||
|
@ -1,72 +0,0 @@
|
||||
/*
|
||||
* GDSII-Converter
|
||||
* Copyright (C) 2018 Mario Hüttel <mario.huettel@gmx.net>
|
||||
*
|
||||
* This file is part of GDSII-Converter.
|
||||
*
|
||||
* GDSII-Converter is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* GDSII-Converter is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GDSII-Converter. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file external-renderer.c
|
||||
* @brief This file implements the dynamic library loading for the external rendering feature
|
||||
* @author Mario Hüttel <mario.huettel@gmx.net>
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup external-renderer
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <gds-render/external-renderer.h>
|
||||
|
||||
int external_renderer_render_cell(struct gds_cell *toplevel_cell, GList *layer_info_list,
|
||||
char *output_file, char *so_path)
|
||||
{
|
||||
int (*so_render_func)(struct gds_cell *, GList *, char *) = NULL;
|
||||
void *so_handle = NULL;
|
||||
char *error_msg;
|
||||
int ret = 0;
|
||||
|
||||
/* Check parameter sanity */
|
||||
if (!output_file || !so_path || !toplevel_cell || !layer_info_list)
|
||||
return -3000;
|
||||
|
||||
/* Load shared object */
|
||||
so_handle = dlopen(so_path, RTLD_LAZY);
|
||||
if (!so_handle) {
|
||||
printf("Could not load external library '%s'\nDetailed error is:\n%s\n", so_path, dlerror());
|
||||
return -2000;
|
||||
}
|
||||
|
||||
/* Load symbol from library */
|
||||
so_render_func = (int (*)(struct gds_cell *, GList *, char *))dlsym(so_handle, EXTERNAL_LIBRARY_FUNCTION);
|
||||
error_msg = dlerror();
|
||||
if (error_msg != NULL) {
|
||||
printf("Rendering function not found in library:\n%s\n", error_msg);
|
||||
goto ret_close_so_handle;
|
||||
}
|
||||
|
||||
/* Execute */
|
||||
if (so_render_func)
|
||||
so_render_func(toplevel_cell, layer_info_list, output_file);
|
||||
|
||||
ret_close_so_handle:
|
||||
dlclose(so_handle);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/** @} */
|
@ -37,8 +37,8 @@
|
||||
#include <gds-render/widgets/activity-bar.h>
|
||||
#include <gds-render/cell-selector/tree-store.h>
|
||||
#include <gds-render/cell-selector/lib-cell-renderer.h>
|
||||
#include <gds-render/latex-renderer/latex-output.h>
|
||||
#include <gds-render/cairo-renderer/cairo-output.h>
|
||||
#include <gds-render/output-renderers/latex-renderer.h>
|
||||
#include <gds-render/output-renderers/cairo-renderer.h>
|
||||
#include <gds-render/widgets/conv-settings-dialog.h>
|
||||
#include <gds-render/geometric/cell-geometrics.h>
|
||||
#include <gds-render/version.h>
|
||||
@ -266,9 +266,7 @@ static void on_convert_clicked(gpointer button, gpointer user)
|
||||
GtkTreeSelection *selection;
|
||||
GtkTreeIter iter;
|
||||
GtkTreeModel *model;
|
||||
GList *layer_list;
|
||||
struct gds_cell *cell_to_render;
|
||||
FILE *output_file;
|
||||
GtkWidget *dialog;
|
||||
RendererSettingsDialog *settings;
|
||||
GtkFileFilter *filter;
|
||||
@ -277,6 +275,8 @@ static void on_convert_clicked(gpointer button, gpointer user)
|
||||
union bounding_box cell_box;
|
||||
unsigned int height, width;
|
||||
struct render_settings *sett;
|
||||
LayerSettings *layer_settings;
|
||||
GdsOutputRenderer *render_engine;
|
||||
|
||||
self = RENDERER_GUI(user);
|
||||
|
||||
@ -296,7 +296,7 @@ static void on_convert_clicked(gpointer button, gpointer user)
|
||||
return;
|
||||
|
||||
/* Get layers that are rendered */
|
||||
layer_list = layer_selector_export_rendered_layer_info(self->layer_selector);
|
||||
layer_settings = layer_selector_export_rendered_layer_info(self->layer_selector);
|
||||
|
||||
/* Calculate cell size in DB units */
|
||||
bounding_box_prepare_empty(&cell_box);
|
||||
@ -359,30 +359,35 @@ static void on_convert_clicked(gpointer button, gpointer user)
|
||||
|
||||
switch (sett->renderer) {
|
||||
case RENDERER_LATEX_TIKZ:
|
||||
output_file = fopen(file_name, "w");
|
||||
latex_render_cell_to_code(cell_to_render, layer_list, output_file, sett->scale,
|
||||
sett->tex_pdf_layers, sett->tex_standalone);
|
||||
fclose(output_file);
|
||||
render_engine =
|
||||
GDS_RENDER_OUTPUT_RENDERER(latex_renderer_new_with_options(sett->tex_pdf_layers,
|
||||
sett->tex_standalone));
|
||||
break;
|
||||
case RENDERER_CAIROGRAPHICS_SVG:
|
||||
render_engine = GDS_RENDER_OUTPUT_RENDERER(cairo_renderer_new_svg());
|
||||
break;
|
||||
case RENDERER_CAIROGRAPHICS_PDF:
|
||||
cairo_render_cell_to_vector_file(cell_to_render, layer_list,
|
||||
(sett->renderer == RENDERER_CAIROGRAPHICS_PDF
|
||||
? file_name
|
||||
: NULL),
|
||||
(sett->renderer == RENDERER_CAIROGRAPHICS_SVG
|
||||
? file_name
|
||||
: NULL),
|
||||
sett->scale);
|
||||
render_engine = GDS_RENDER_OUTPUT_RENDERER(cairo_renderer_new_pdf());
|
||||
break;
|
||||
}
|
||||
|
||||
if (render_engine) {
|
||||
gds_output_renderer_set_output_file(render_engine, file_name);
|
||||
gds_output_renderer_set_layer_settings(render_engine, layer_settings);
|
||||
|
||||
/* TODO: Replace this with asynchronous rendering. However, this fixes issue #19 */
|
||||
gds_output_renderer_render_output(render_engine, cell_to_render, sett->scale);
|
||||
|
||||
g_object_unref(render_engine);
|
||||
}
|
||||
|
||||
g_free(file_name);
|
||||
|
||||
} else {
|
||||
gtk_widget_destroy(dialog);
|
||||
}
|
||||
ret_layer_destroy:
|
||||
g_list_free_full(layer_list, (GDestroyNotify)layer_info_delete_struct);
|
||||
g_object_unref(layer_settings);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -21,7 +21,7 @@
|
||||
* @file gds-tree-checker.c
|
||||
* @brief Checking functions of a cell tree
|
||||
*
|
||||
* This file contains cehcking functions for the GDS cell tree.
|
||||
* This file contains checking functions for the GDS cell tree.
|
||||
* These functions include checks if all child references could be resolved,
|
||||
* and if the cell tree contains loops.
|
||||
*
|
||||
|
@ -34,27 +34,27 @@
|
||||
#include <glib.h>
|
||||
|
||||
/**
|
||||
* @brief Convert GDS according to supplied parameters
|
||||
* @param gds_name GDS File path
|
||||
* @param pdf_name Cairo-PDF path
|
||||
* @param tex_name TeX/TikZ path
|
||||
* @param pdf Render Cairo
|
||||
* @param tex Render LaTeX
|
||||
* @brief Convert GDS according to command line parameters
|
||||
* @param gds_name Path to GDS File
|
||||
* @param cell_name Cell name
|
||||
* @param renderers Renderer ids
|
||||
* @param output_file_names Output file names
|
||||
* @param layer_file Layer mapping file
|
||||
* @param cell_name Cell name to render
|
||||
* @param scale Scale image down by this value
|
||||
* @param pdf_layers TikZ creates OCG layers
|
||||
* @param pdf_standalone LaTeX document is standalone7
|
||||
* @param svg Render to SVG file
|
||||
* @param so_name Path to shared object of custom renderer
|
||||
* @param so_out_file Output file path for custom renderer
|
||||
* @param svg_name SVG file name
|
||||
*
|
||||
* @note This function is pretty damn retarded (Lots of parameters). Will be reworked when generating GObjects for renderers.
|
||||
* @param so_path Shared object
|
||||
* @param tex_standalone Standalone TeX
|
||||
* @param tec_layers TeX OCR layers
|
||||
* @param scale Scale value
|
||||
* @return Error code, 0 if successful
|
||||
*/
|
||||
void command_line_convert_gds(char *gds_name, char *pdf_name, char *tex_name, gboolean pdf, gboolean tex,
|
||||
char *layer_file, char *cell_name, double scale, gboolean pdf_layers,
|
||||
gboolean pdf_standalone, gboolean svg, char *svg_name, char *so_name, char *so_out_file);
|
||||
int command_line_convert_gds(const char *gds_name,
|
||||
const char *cell_name,
|
||||
char **renderers,
|
||||
char **output_file_names,
|
||||
const char *layer_file,
|
||||
const char *so_path,
|
||||
gboolean tex_standalone,
|
||||
gboolean tex_layers,
|
||||
double scale);
|
||||
|
||||
#endif /* _COMMAND_LINE_H_ */
|
||||
|
||||
|
@ -23,14 +23,14 @@
|
||||
* @author Mario Hüttel <mario.huettel@gmx.net>
|
||||
*/
|
||||
|
||||
#ifndef _GDSPARSER_H_
|
||||
#define _GDSPARSER_H_
|
||||
|
||||
/**
|
||||
* @addtogroup GDS-Utilities
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _GDSPARSER_H_
|
||||
#define _GDSPARSER_H_
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include <gds-render/gds-utils/gds-types.h>
|
||||
@ -61,4 +61,4 @@ int clear_lib_list(GList **library_list);
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* _GDSPARSE_H_ */
|
||||
#endif /* _GDSPARSER_H_ */
|
||||
|
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* GDSII-Converter
|
||||
* Copyright (C) 2018 Mario Hüttel <mario.huettel@gmx.net>
|
||||
*
|
||||
* This file is part of GDSII-Converter.
|
||||
*
|
||||
* GDSII-Converter is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* GDSII-Converter is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GDSII-Converter. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file latex-output.h
|
||||
* @brief LaTeX output renderer
|
||||
* @author Mario Hüttel <mario.huettel@gmx.net>
|
||||
*/
|
||||
|
||||
#ifndef __LATEX_OUTPUT_H__
|
||||
#define __LATEX_OUTPUT_H__
|
||||
|
||||
/**
|
||||
* @addtogroup LaTeX-Renderer
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include <glib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "gds-render/layer/layer-info.h"
|
||||
#include <gds-render/gds-utils/gds-types.h>
|
||||
|
||||
#define LATEX_LINE_BUFFER_KB (10) /**< @brief Buffer for LaTeX Code line in KiB */
|
||||
|
||||
/**
|
||||
* @brief Render \p cell to LateX/TikZ code
|
||||
* @param cell Cell to render
|
||||
* @param layer_infos Layer information
|
||||
* @param tex_file Already opened file to write data in
|
||||
* @param scale Scale image down by this value
|
||||
* @param create_pdf_layers Optional content groups used
|
||||
* @param standalone_document document can be compiled standalone
|
||||
*/
|
||||
void latex_render_cell_to_code(struct gds_cell *cell, GList *layer_infos, FILE *tex_file, double scale,
|
||||
gboolean create_pdf_layers, gboolean standalone_document);
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* __LATEX_OUTPUT_H__ */
|
@ -19,7 +19,7 @@
|
||||
|
||||
/**
|
||||
* @file layer-info.h
|
||||
* @brief Helper functions and definition of layer info struct
|
||||
* @brief LayerSettings class heade file
|
||||
* @author Mario Hüttel <mario.huettel@gmx.net>
|
||||
*/
|
||||
|
||||
@ -28,24 +28,92 @@
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* @brief Layer information.
|
||||
*
|
||||
* This structs contains information on how to render a layer
|
||||
* @note You probably don't want to use this struct standalone but in combination
|
||||
* with a LayerSettings object.
|
||||
*/
|
||||
struct layer_info
|
||||
{
|
||||
int layer; /**< @brief Layer number */
|
||||
char *name; /**< @brief Layer name */
|
||||
char *name; /**< @brief Layer name. */
|
||||
int stacked_position; ///< @brief Position of layer in output @warning This parameter is not used by any renderer so far @note Lower is bottom, higher is top
|
||||
GdkRGBA color; /**< @brief RGBA color used to render this layer */
|
||||
int render; /**< @brief true: Render to output */
|
||||
};
|
||||
|
||||
G_DECLARE_FINAL_TYPE(LayerSettings, layer_settings, GDS_RENDER, LAYER_SETTINGS, GObject)
|
||||
|
||||
#define GDS_RENDER_TYPE_LAYER_SETTINGS (layer_settings_get_type())
|
||||
|
||||
/**
|
||||
* @brief Delete a layer_info struct
|
||||
* @param info Struct to be deleted.
|
||||
* @note The layer_info::name Element has to be freed manually
|
||||
* @brief Maximum length of a layer mapping CSV line
|
||||
*/
|
||||
void layer_info_delete_struct(struct layer_info *info);
|
||||
#define CSV_LINE_MAX_LEN (1024)
|
||||
|
||||
/**
|
||||
* @brief New LayerSettings object
|
||||
* @return New object
|
||||
*/
|
||||
LayerSettings *layer_settings_new();
|
||||
|
||||
/**
|
||||
* @brief layer_settings_append_layer_info
|
||||
* @param settings LayerSettings object.
|
||||
* @param info Info to append
|
||||
* @return Error code. 0 if successful
|
||||
* @note \p info is copied internally. You can free this struct afterwards.
|
||||
*/
|
||||
int layer_settings_append_layer_info(LayerSettings *settings, struct layer_info *info);
|
||||
|
||||
/**
|
||||
* @brief Clear all layers in this settings object
|
||||
* @param settings LayerSettings object
|
||||
*/
|
||||
void layer_settings_clear(LayerSettings *settings);
|
||||
|
||||
/**
|
||||
* @brief Remove a specific layer number from the layer settings.
|
||||
* @param settings LayerSettings object
|
||||
* @param layer Layer number
|
||||
* @return Error code. 0 if successful
|
||||
*/
|
||||
int layer_settings_remove_layer(LayerSettings *settings, int layer);
|
||||
|
||||
/**
|
||||
* @brief Get a GList with layer_info structs
|
||||
*
|
||||
* This function returns a GList with all layer_info structs in rendering order
|
||||
* (bottom to top) that shall be rendered.
|
||||
*
|
||||
* @param settings LayerSettings object
|
||||
* @return GList with struct layer_info elements.
|
||||
*/
|
||||
GList *layer_settings_get_layer_info_list(LayerSettings *settings);
|
||||
|
||||
/**
|
||||
* @brief Write layer settings to a CSV file
|
||||
* @param path
|
||||
* @return 0 if successful
|
||||
*/
|
||||
int layer_settings_to_csv(LayerSettings *settings, const char *path);
|
||||
|
||||
/**
|
||||
* @brief Load new layer Settings from CSV
|
||||
*
|
||||
* This function loads the layer information from a CSV file.
|
||||
* All data inside the \p settings is cleared beforehand.
|
||||
*
|
||||
* @param settings Settings to write to.
|
||||
* @param path CSV file path
|
||||
* @return 0 if successful
|
||||
*/
|
||||
int layer_settings_load_from_csv(LayerSettings *settings, const char *path);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif // _LAYER_INFO_H_
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include <gtk/gtk.h>
|
||||
#include <glib.h>
|
||||
#include <gds-render/layer/color-palette.h>
|
||||
#include <gds-render/layer/layer-info.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@ -80,9 +81,9 @@ void layer_selector_set_save_mapping_button(LayerSelector *selector, GtkWidget *
|
||||
/**
|
||||
* @brief Get a list of all layers that shall be exported when rendering the cells
|
||||
* @param selector Layer selector instance
|
||||
* @return List of layer_info structures containing the layer information
|
||||
* @return LayerSettings containing the layer information
|
||||
*/
|
||||
GList *layer_selector_export_rendered_layer_info(LayerSelector *selector);
|
||||
LayerSettings *layer_selector_export_rendered_layer_info(LayerSelector *selector);
|
||||
|
||||
/**
|
||||
* @brief Force the layer selector list to be sorted according to \p sort_function
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include <glib.h>
|
||||
|
||||
#include <gds-render/widgets/layer-element.h>
|
||||
#include <gds-render/layer/layer-info.h>
|
||||
|
||||
/**
|
||||
* @brief Load a line from \p stream and parse try to parse it as layer information
|
||||
|
@ -26,23 +26,36 @@
|
||||
|
||||
#include <gds-render/gds-utils/gds-types.h>
|
||||
#include <gds-render/layer/layer-info.h>
|
||||
#include <gds-render/output-renderers/gds-output-renderer.h>
|
||||
#include <glib-object.h>
|
||||
|
||||
/** @addtogroup Cairo-Renderer
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/** @addtogroup CairoRenderer
|
||||
* @{
|
||||
*/
|
||||
|
||||
G_DECLARE_FINAL_TYPE(CairoRenderer, cairo_renderer, GDS_RENDER, CAIRO_RENDERER, GdsOutputRenderer)
|
||||
|
||||
#define GDS_RENDER_TYPE_CAIRO_RENDERER (cairo_renderer_get_type())
|
||||
|
||||
#define MAX_LAYERS (300) /**< \brief Maximum layer count the output renderer can process. Typically GDS only specifies up to 255 layers.*/
|
||||
|
||||
/**
|
||||
* @brief Render \p cell to a PDF file specified by \p pdf_file
|
||||
* @param cell Toplevel cell to @ref Cairo-Renderer
|
||||
* @param layer_infos List of layer information. Specifies color and layer stacking
|
||||
* @param pdf_file PDF output file. Set to NULL if no PDF file has to be generated
|
||||
* @param svg_file SVG output file. Set to NULL if no SVG file has to be generated
|
||||
* @param scale Scale the output image down by \p scale
|
||||
* @brief Create new CairoRenderer for SVG output
|
||||
* @return New object
|
||||
*/
|
||||
void cairo_render_cell_to_vector_file(struct gds_cell *cell, GList *layer_infos, char *pdf_file, char *svg_file, double scale);
|
||||
CairoRenderer *cairo_renderer_new_svg();
|
||||
|
||||
|
||||
/**
|
||||
* @brief Create new CairoRenderer for PDF output
|
||||
* @return New object
|
||||
*/
|
||||
CairoRenderer *cairo_renderer_new_pdf();
|
||||
|
||||
/** @} */
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* _CAIRO_OUTPUT_H_ */
|
@ -24,35 +24,46 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup external-renderer
|
||||
* @addtogroup ExternalRenderer
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _EXTERNAL_RENDERER_H_
|
||||
#define _EXTERNAL_RENDERER_H_
|
||||
|
||||
#include <gds-render/output-renderers/gds-output-renderer.h>
|
||||
#include <gds-render/gds-utils/gds-types.h>
|
||||
#include <glib.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GDS_RENDER_TYPE_EXTERNAL_RENDERER (external_renderer_get_type())
|
||||
|
||||
G_DECLARE_FINAL_TYPE(ExternalRenderer, external_renderer, GDS_RENDER, EXTERNAL_RENDERER, GdsOutputRenderer)
|
||||
|
||||
/**
|
||||
* @brief function name expected to be found in external library.
|
||||
*
|
||||
* The function has to be defined as follows:
|
||||
* @code
|
||||
* int function_name(gds_cell *toplevel, GList *layer_info_list, char *output_file_name)
|
||||
* int EXTERNAL_LIBRARY_FUNCTION(struct gds_cell *toplevel, GList *layer_info_list, const char *output_file_name, double scale)
|
||||
* @endcode
|
||||
*/
|
||||
#define EXTERNAL_LIBRARY_FUNCTION "render_cell_to_file"
|
||||
|
||||
/**
|
||||
* @brief external_renderer_render_cell
|
||||
* @param toplevel_cell The toplevel cell to render
|
||||
* @param layer_info_list The layer information. Contains #layer_info elements
|
||||
* @param output_file Output file
|
||||
* @param so_path Path to the shared object file containing #EXTERNAL_LIBRARY_FUNCTION
|
||||
* @return 0 on success
|
||||
* @brief Create new ExternalRenderer object
|
||||
* @return New object
|
||||
*/
|
||||
int external_renderer_render_cell(struct gds_cell *toplevel_cell, GList *layer_info_list, char *output_file, char *so_path);
|
||||
ExternalRenderer *external_renderer_new();
|
||||
|
||||
/**
|
||||
* @brief Create new ExternalRenderer object with specified shared object path
|
||||
* @param so_path Path to shared object, the rendering function is searched in
|
||||
* @return New object.
|
||||
*/
|
||||
ExternalRenderer *external_renderer_new_with_so(const char *so_path);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* _EXTERNAL_RENDERER_H_ */
|
||||
|
151
include/gds-render/output-renderers/gds-output-renderer.h
Normal file
151
include/gds-render/output-renderers/gds-output-renderer.h
Normal file
@ -0,0 +1,151 @@
|
||||
/*
|
||||
* GDSII-Converter
|
||||
* Copyright (C) 2018 Mario Hüttel <mario.huettel@gmx.net>
|
||||
*
|
||||
* This file is part of GDSII-Converter.
|
||||
*
|
||||
* GDSII-Converter is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* GDSII-Converter is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GDSII-Converter. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file gds-output-renderer.h
|
||||
* @brief Header for output renderer base class
|
||||
* @author Mario Hüttel <mario.huettel@gmx.net>
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup GdsOutputRenderer
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _GDS_OUTPUT_RENDERER_H_
|
||||
#define _GDS_OUTPUT_RENDERER_H_
|
||||
|
||||
#include <gds-render/gds-utils/gds-types.h>
|
||||
#include <glib-object.h>
|
||||
#include <glib.h>
|
||||
#include <gds-render/layer/layer-info.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GDS_RENDER_TYPE_OUTPUT_RENDERER (gds_output_renderer_get_type())
|
||||
|
||||
G_DECLARE_DERIVABLE_TYPE(GdsOutputRenderer, gds_output_renderer, GDS_RENDER, OUTPUT_RENDERER, GObject);
|
||||
|
||||
/**
|
||||
* @brief Base output renderer class structure.
|
||||
* @note This structure is only used for internal inheritance of GObjects. Do not use in code outside of these classes.
|
||||
*/
|
||||
struct _GdsOutputRendererClass {
|
||||
GObjectClass parent_class;
|
||||
|
||||
/**
|
||||
* @brief Virtual render output function. Overwritten by final class implementation
|
||||
*/
|
||||
int (*render_output)(GdsOutputRenderer *renderer,
|
||||
struct gds_cell *cell,
|
||||
double scale);
|
||||
gpointer padding[4];
|
||||
};
|
||||
|
||||
enum {
|
||||
GDS_OUTPUT_RENDERER_GEN_ERR = -100, /**< @brief Error set by the _GdsOutputRendererClass::render_output virtual function, if renderer is invalid. */
|
||||
GDS_OUTPUT_RENDERER_PARAM_ERR = -200 /**< @brief Error set by the _GdsOutputRendererClass::render_output virtual function, if parameters are faulty. */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Create a new GdsOutputRenderer GObject.
|
||||
* @return New object
|
||||
*/
|
||||
GdsOutputRenderer *gds_output_renderer_new();
|
||||
|
||||
/**
|
||||
* @brief Create a new GdsOutputRenderer GObject with its properties
|
||||
* @param output_file Output file of the renderer
|
||||
* @param layer_settings Layer settings object
|
||||
* @return New object
|
||||
*/
|
||||
GdsOutputRenderer *gds_output_renderer_new_with_props(const char *output_file, LayerSettings *layer_settings);
|
||||
|
||||
/**
|
||||
* @brief gds_output_renderer_render_output
|
||||
* @param renderer Renderer object
|
||||
* @param cell Cell to render
|
||||
* @param scale scale value. The output is scaled *down* by this value
|
||||
* @return 0 if successful
|
||||
*/
|
||||
int gds_output_renderer_render_output(GdsOutputRenderer *renderer,
|
||||
struct gds_cell *cell,
|
||||
double scale);
|
||||
|
||||
/**
|
||||
* @brief Convenience function for setting the "output-file" property
|
||||
* @param renderer Renderer object
|
||||
* @param file_name Output file path
|
||||
*/
|
||||
void gds_output_renderer_set_output_file(GdsOutputRenderer *renderer, const gchar *file_name);
|
||||
|
||||
/**
|
||||
* @brief Convenience function for getting the "output-file" property
|
||||
* @param renderer
|
||||
* @return Output file path. This must not be freed
|
||||
*/
|
||||
const char *gds_output_renderer_get_output_file(GdsOutputRenderer *renderer);
|
||||
|
||||
/**
|
||||
* @brief Get layer settings
|
||||
*
|
||||
* This is a convenience function for getting the
|
||||
* "layer-settings" property. This also references it.
|
||||
* This is to prevent race conditions with another thread that might
|
||||
* alter the layer settings before they are read out.
|
||||
*
|
||||
* @param renderer Renderer
|
||||
* @return Layer settings object
|
||||
*/
|
||||
LayerSettings *gds_output_renderer_get_and_ref_layer_settings(GdsOutputRenderer *renderer);
|
||||
|
||||
/**
|
||||
* @brief Set layer settings
|
||||
*
|
||||
* This is a convenience function for setting the
|
||||
* "layer-settings" property.
|
||||
*
|
||||
* If another Layer settings has previously been supplied,
|
||||
* it is unref'd.
|
||||
*
|
||||
* @param renderer Renderer
|
||||
* @param settings LayerSettings object
|
||||
*/
|
||||
void gds_output_renderer_set_layer_settings(GdsOutputRenderer *renderer, LayerSettings *settings);
|
||||
|
||||
/**
|
||||
* @brief Render output asynchronously
|
||||
*
|
||||
* This function will render in a separate thread.
|
||||
* To wait for the completion of the rendering process.
|
||||
*
|
||||
* @note A second async thread cannot be spawned.
|
||||
*
|
||||
* @param renderer Output renderer
|
||||
* @param cell Cell to render
|
||||
* @param scale Scale
|
||||
* @return 0 if successful. In case no thread can be spawned < 0
|
||||
*/
|
||||
int gds_output_renderer_render_output_async(GdsOutputRenderer *renderer, struct gds_cell *cell, double scale);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* _GDS_OUTPUT_RENDERER_H_ */
|
||||
|
||||
/** @} */
|
74
include/gds-render/output-renderers/latex-renderer.h
Normal file
74
include/gds-render/output-renderers/latex-renderer.h
Normal file
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* GDSII-Converter
|
||||
* Copyright (C) 2018 Mario Hüttel <mario.huettel@gmx.net>
|
||||
*
|
||||
* This file is part of GDSII-Converter.
|
||||
*
|
||||
* GDSII-Converter is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* GDSII-Converter is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GDSII-Converter. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file latex-output.h
|
||||
* @brief LaTeX output renderer
|
||||
* @author Mario Hüttel <mario.huettel@gmx.net>
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup LaTeX-Renderer
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _LATEX_OUTPUT_H_
|
||||
#define _LATEX_OUTPUT_H_
|
||||
|
||||
#include <gds-render/output-renderers/gds-output-renderer.h>
|
||||
#include <gds-render/gds-utils/gds-types.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
G_DECLARE_FINAL_TYPE(LatexRenderer, latex_renderer, GDS_RENDER, LATEX_RENDERER, GdsOutputRenderer)
|
||||
|
||||
#define GDS_RENDER_TYPE_LATEX_RENDERER (latex_renderer_get_type())
|
||||
|
||||
/**
|
||||
* @brief Buffer for LaTeX Code line in KiB
|
||||
*/
|
||||
#define LATEX_LINE_BUFFER_KB (10)
|
||||
|
||||
/**
|
||||
* @brief Create new LatexRenderer object
|
||||
* @return New object
|
||||
*/
|
||||
LatexRenderer *latex_renderer_new();
|
||||
|
||||
/**
|
||||
* @brief Create new LatexRenderer object
|
||||
*
|
||||
* This function sets the 'pdf-layers' and 'standalone'
|
||||
* properties for the newly created object.
|
||||
*
|
||||
* They can later be changes by modifying the properties again.
|
||||
* On top of that, The options can be changed in the resulting
|
||||
* LaTeX output file if needed.
|
||||
*
|
||||
* @param pdf_layers If PDF OCR layers should be enabled
|
||||
* @param standalone If output TeX file should be standalone compilable
|
||||
* @return New object
|
||||
*/
|
||||
LatexRenderer *latex_renderer_new_with_options(gboolean pdf_layers, gboolean standalone);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* _LATEX_OUTPUT_H_ */
|
||||
|
||||
/** @} */
|
@ -35,6 +35,7 @@ struct _ColorPalette {
|
||||
/** @brief The length of the _ColorPalette::color_array array */
|
||||
unsigned int color_array_length;
|
||||
|
||||
/* Dummy bytes to ensure ABI compatibility in future versions */
|
||||
gpointer dummy[4];
|
||||
};
|
||||
|
||||
@ -116,8 +117,8 @@ static int color_palette_fill_with_resource(ColorPalette *palette, char *resourc
|
||||
palette->color_array = (GdkRGBA *)malloc(sizeof(GdkRGBA) * (unsigned int)lines);
|
||||
|
||||
/* Setup regex for hexadecimal RGB colors like 'A0CB3F' */
|
||||
regex = g_regex_new("^(?<red>[0-9A-Fa-f][0-9A-Fa-f])(?<green>[0-9A-Fa-f][0-9A-Fa-f])(?<blue>[0-9A-Fa-f][0-9A-Fa-f])$", 0, 0, NULL);
|
||||
|
||||
regex = g_regex_new("^(?<red>[0-9A-Fa-f][0-9A-Fa-f])(?<green>[0-9A-Fa-f][0-9A-Fa-f])(?<blue>[0-9A-Fa-f][0-9A-Fa-f])$",
|
||||
0, 0, NULL);
|
||||
|
||||
/* Reset line */
|
||||
line_idx = 0;
|
||||
@ -227,11 +228,27 @@ unsigned int color_palette_get_color_count(ColorPalette *palette)
|
||||
return return_val;
|
||||
}
|
||||
|
||||
static void color_palette_dispose(GObject *gobj)
|
||||
{
|
||||
ColorPalette *palette;
|
||||
|
||||
palette = GDS_RENDER_COLOR_PALETTE(gobj);
|
||||
if (palette->color_array)
|
||||
{
|
||||
palette->color_array_length = 0;
|
||||
free(palette->color_array);
|
||||
}
|
||||
|
||||
/* Chain up to parent class */
|
||||
G_OBJECT_CLASS(color_palette_parent_class)->dispose(gobj);
|
||||
}
|
||||
|
||||
static void color_palette_class_init(ColorPaletteClass *klass)
|
||||
{
|
||||
(void)klass;
|
||||
/* Nothing to do for now */
|
||||
return;
|
||||
GObjectClass *gclass;
|
||||
|
||||
gclass = G_OBJECT_CLASS(klass);
|
||||
gclass->dispose = color_palette_dispose;
|
||||
}
|
||||
|
||||
static void color_palette_init(ColorPalette *self)
|
||||
|
@ -19,15 +19,312 @@
|
||||
|
||||
/**
|
||||
* @file layer-info.c
|
||||
* @brief Helper functions for layer info struct
|
||||
* @brief Implementation of the LayerSettings class
|
||||
* @author Mario Hüttel <mario.huettel@gmx.net>
|
||||
*/
|
||||
|
||||
#include <gds-render/layer/layer-info.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void layer_info_delete_struct(struct layer_info *info)
|
||||
struct _LayerSettings {
|
||||
GObject parent;
|
||||
GList *layer_infos;
|
||||
gpointer padding[12];
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE(LayerSettings, layer_settings, G_TYPE_OBJECT)
|
||||
|
||||
static void layer_settings_init(LayerSettings *self)
|
||||
{
|
||||
if (info)
|
||||
free(info);
|
||||
self->layer_infos = NULL;
|
||||
}
|
||||
|
||||
static void layer_settings_class_init(LayerSettingsClass *klass)
|
||||
{
|
||||
(void)klass;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Copy layer_info struct
|
||||
*
|
||||
* This function copies a layer info struct.
|
||||
* Be aware, that it does not only copy the pointer to the
|
||||
* layer name, but instead duplicates the string.
|
||||
*
|
||||
* @param info Info to copy
|
||||
* @return new layer_info struct
|
||||
*/
|
||||
static struct layer_info *layer_info_copy(const struct layer_info * const info)
|
||||
{
|
||||
struct layer_info *copy;
|
||||
|
||||
if (!info)
|
||||
return 0;
|
||||
|
||||
copy = (struct layer_info *)malloc(sizeof(struct layer_info));
|
||||
if (!copy)
|
||||
return 0;
|
||||
|
||||
/* Copy data */
|
||||
memcpy(copy, info, sizeof(struct layer_info));
|
||||
/* Duplicate string */
|
||||
if (info->name)
|
||||
copy->name = strdup(info->name);
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
static void layer_info_delete_with_name(struct layer_info *const info)
|
||||
{
|
||||
if (!info)
|
||||
return;
|
||||
|
||||
if (info->name)
|
||||
free(info->name);
|
||||
free(info);
|
||||
}
|
||||
|
||||
LayerSettings *layer_settings_new()
|
||||
{
|
||||
return g_object_new(GDS_RENDER_TYPE_LAYER_SETTINGS, NULL);
|
||||
}
|
||||
|
||||
int layer_settings_append_layer_info(LayerSettings *settings, struct layer_info *info)
|
||||
{
|
||||
struct layer_info *info_copy;
|
||||
|
||||
g_return_val_if_fail(GDS_RENDER_IS_LAYER_SETTINGS(settings), -1);
|
||||
if (!info)
|
||||
return -2;
|
||||
|
||||
/* Copy layer info */
|
||||
info_copy = layer_info_copy(info);
|
||||
|
||||
/* Append to list */
|
||||
settings->layer_infos = g_list_append(settings->layer_infos, info_copy);
|
||||
|
||||
return (settings->layer_infos ? 0 : -3);
|
||||
}
|
||||
|
||||
void layer_settings_clear(LayerSettings *settings)
|
||||
{
|
||||
g_return_if_fail(GDS_RENDER_IS_LAYER_SETTINGS(settings));
|
||||
|
||||
/* Clear list and delete layer_info structs including the name field */
|
||||
g_list_free_full(settings->layer_infos, (GDestroyNotify)layer_info_delete_with_name);
|
||||
settings->layer_infos = NULL;
|
||||
}
|
||||
|
||||
int layer_settings_remove_layer(LayerSettings *settings, int layer)
|
||||
{
|
||||
GList *list_iter;
|
||||
GList *found = NULL;
|
||||
struct layer_info *inf;
|
||||
|
||||
g_return_val_if_fail(GDS_RENDER_IS_LAYER_SETTINGS(settings), -1);
|
||||
|
||||
/* Find in list */
|
||||
for (list_iter = settings->layer_infos; list_iter; list_iter = list_iter->next) {
|
||||
inf = (struct layer_info *)list_iter->data;
|
||||
|
||||
if (!inf)
|
||||
continue;
|
||||
if (inf->layer == layer)
|
||||
found = list_iter;
|
||||
}
|
||||
|
||||
if (found) {
|
||||
/* Free the layer_info struct */
|
||||
layer_info_delete_with_name((struct layer_info *)found->data);
|
||||
/* Delete the list element */
|
||||
settings->layer_infos = g_list_delete_link(settings->layer_infos, found);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -2;
|
||||
}
|
||||
|
||||
GList *layer_settings_get_layer_info_list(LayerSettings *settings)
|
||||
{
|
||||
g_return_val_if_fail(GDS_RENDER_IS_LAYER_SETTINGS(settings), NULL);
|
||||
return settings->layer_infos;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Generate a layer mapping CSV line for a given layer_info struct
|
||||
* @param string Buffer to write to
|
||||
* @param linfo Layer information
|
||||
*/
|
||||
static void layer_settings_gen_csv_line(GString *string, struct layer_info *linfo)
|
||||
{
|
||||
int i;
|
||||
|
||||
g_string_printf(string, "%d:%lf:%lf:%lf:%lf:%d:%s\n",
|
||||
linfo->layer, linfo->color.red, linfo->color.green,
|
||||
linfo->color.blue, linfo->color.alpha, (linfo->render ? 1 : 0), linfo->name);
|
||||
/* Fix broken locale settings */
|
||||
for (i = 0; string->str[i]; i++) {
|
||||
if (string->str[i] == ',')
|
||||
string->str[i] = '.';
|
||||
}
|
||||
|
||||
for (i = 0; string->str[i]; i++) {
|
||||
if (string->str[i] == ':')
|
||||
string->str[i] = ',';
|
||||
}
|
||||
}
|
||||
|
||||
int layer_settings_to_csv(LayerSettings *settings, const char *path)
|
||||
{
|
||||
GFile *file;
|
||||
GOutputStream *w_fstream;
|
||||
GString *string;
|
||||
GList *info_iter;
|
||||
struct layer_info *linfo;
|
||||
int ret = 0;
|
||||
|
||||
file = g_file_new_for_path(path);
|
||||
w_fstream = G_OUTPUT_STREAM(g_file_replace(file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, NULL));
|
||||
if (!w_fstream) {
|
||||
ret = -1;
|
||||
goto ret_unref_file;
|
||||
}
|
||||
|
||||
/* Allocate new working buffer string. A size bigger than 200 is unexpected, but possible
|
||||
* 200 is a tradeoff between memory usage and preventing the necessity of realloc'ing the string
|
||||
*/
|
||||
string = g_string_new_len(NULL, 200);
|
||||
if (!string) {
|
||||
ret = -2;
|
||||
goto ret_close_file;
|
||||
}
|
||||
|
||||
/* Loop over layers and write CSV lines */
|
||||
for (info_iter = settings->layer_infos; info_iter; info_iter = info_iter->next) {
|
||||
linfo = (struct layer_info *)info_iter->data;
|
||||
|
||||
layer_settings_gen_csv_line(string, linfo);
|
||||
g_output_stream_write(w_fstream, string->str, sizeof(gchar), NULL, NULL);
|
||||
}
|
||||
|
||||
/* Delete string */
|
||||
g_string_free(string, TRUE);
|
||||
ret_close_file:
|
||||
g_output_stream_flush(w_fstream, NULL, NULL);
|
||||
g_output_stream_close(w_fstream, NULL, NULL);
|
||||
g_object_unref(w_fstream);
|
||||
ret_unref_file:
|
||||
g_object_unref(file);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Load a line from \p stream and parse try to parse it as layer information
|
||||
* @param stream Input data stream
|
||||
* @param linfo Layer info struct to fill
|
||||
* @return 1 if malformatted line, 0 if parsing was successful and parameters are valid, -1 if file end
|
||||
*/
|
||||
static int layer_settings_load_csv_line_from_stream(GDataInputStream *stream, struct layer_info *linfo)
|
||||
{
|
||||
int ret;
|
||||
gsize len;
|
||||
gchar *line;
|
||||
GRegex *regex;
|
||||
GMatchInfo *mi;
|
||||
char *match;
|
||||
|
||||
if (!linfo) {
|
||||
ret = 1;
|
||||
goto ret_direct;
|
||||
}
|
||||
|
||||
regex = g_regex_new("^(?<layer>[0-9]+),(?<r>[0-9\\.]+),(?<g>[0-9\\.]+),(?<b>[0-9\\.]+),(?<a>[0-9\\.]+),(?<export>[01]),(?<name>.*)$", 0, 0, NULL);
|
||||
|
||||
line = g_data_input_stream_read_line(stream, &len, NULL, NULL);
|
||||
if (!line) {
|
||||
ret = -1;
|
||||
goto destroy_regex;
|
||||
}
|
||||
|
||||
/* Match line in CSV */
|
||||
g_regex_match(regex, line, 0, &mi);
|
||||
if (g_match_info_matches(mi)) {
|
||||
/* Line is valid */
|
||||
match = g_match_info_fetch_named(mi, "layer");
|
||||
linfo->layer = (int)g_ascii_strtoll(match, NULL, 10);
|
||||
g_free(match);
|
||||
match = g_match_info_fetch_named(mi, "r");
|
||||
linfo->color.red = g_ascii_strtod(match, NULL);
|
||||
g_free(match);
|
||||
match = g_match_info_fetch_named(mi, "g");
|
||||
linfo->color.green = g_ascii_strtod(match, NULL);
|
||||
g_free(match);
|
||||
match = g_match_info_fetch_named(mi, "b");
|
||||
linfo->color.blue = g_ascii_strtod(match, NULL);
|
||||
g_free(match);
|
||||
match = g_match_info_fetch_named(mi, "a");
|
||||
linfo->color.alpha = g_ascii_strtod(match, NULL);
|
||||
g_free(match);
|
||||
match = g_match_info_fetch_named(mi, "export");
|
||||
linfo->render = ((!strcmp(match, "1")) ? 1 : 0);
|
||||
g_free(match);
|
||||
match = g_match_info_fetch_named(mi, "name");
|
||||
linfo->name = match;
|
||||
|
||||
ret = 0;
|
||||
} else {
|
||||
/* Line is malformatted */
|
||||
printf("Could not recognize line in CSV as valid entry: %s\n", line);
|
||||
ret = 1;
|
||||
}
|
||||
|
||||
g_match_info_free(mi);
|
||||
g_free(line);
|
||||
destroy_regex:
|
||||
g_regex_unref(regex);
|
||||
ret_direct:
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
int layer_settings_load_from_csv(LayerSettings *settings, const char *path)
|
||||
{
|
||||
GFile *file;
|
||||
int ret = 0;
|
||||
GInputStream *in_stream;
|
||||
GDataInputStream *data_stream;
|
||||
int parser_ret;
|
||||
struct layer_info linfo;
|
||||
|
||||
file = g_file_new_for_path(path);
|
||||
in_stream = G_INPUT_STREAM(g_file_read(file, NULL, NULL));
|
||||
if (!in_stream) {
|
||||
ret = -1;
|
||||
goto ret_destroy_file;
|
||||
}
|
||||
/* Delete old settings */
|
||||
layer_settings_clear(settings);
|
||||
|
||||
data_stream = g_data_input_stream_new(in_stream);
|
||||
|
||||
while ((parser_ret = layer_settings_load_csv_line_from_stream(data_stream, &linfo)) >= 0) {
|
||||
/* Line broken */
|
||||
if (parser_ret == 1)
|
||||
continue;
|
||||
|
||||
layer_settings_append_layer_info(settings, &linfo);
|
||||
/* Clear name to prevent memory leak */
|
||||
if (linfo.name)
|
||||
g_free(linfo.name);
|
||||
}
|
||||
|
||||
g_object_unref(data_stream);
|
||||
g_object_unref(in_stream);
|
||||
ret_destroy_file:
|
||||
g_object_unref(file);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -371,39 +371,39 @@ LayerSelector *layer_selector_new(GtkListBox *list_box)
|
||||
return selector;
|
||||
}
|
||||
|
||||
GList *layer_selector_export_rendered_layer_info(LayerSelector *selector)
|
||||
LayerSettings *layer_selector_export_rendered_layer_info(LayerSelector *selector)
|
||||
{
|
||||
GList *info_list = NULL;
|
||||
LayerElement *le;
|
||||
struct layer_info *linfo;
|
||||
LayerSettings *layer_settings;
|
||||
struct layer_info linfo;
|
||||
GList *row_list;
|
||||
GList *temp;
|
||||
GList *iterator;
|
||||
LayerElement *le;
|
||||
int i;
|
||||
|
||||
if (!selector)
|
||||
layer_settings = layer_settings_new();
|
||||
if (!layer_settings)
|
||||
return NULL;
|
||||
|
||||
row_list = gtk_container_get_children(GTK_CONTAINER(selector->list_box));
|
||||
|
||||
/* Iterate through widgets and add layers that shall be exported */
|
||||
for (i = 0, temp = row_list; temp != NULL; temp = temp->next, i++) {
|
||||
for (i = 0,iterator = row_list; iterator != NULL; iterator = g_list_next(iterator), i++) {
|
||||
le = LAYER_ELEMENT(iterator->data);
|
||||
|
||||
le = LAYER_ELEMENT(temp->data);
|
||||
/* Get name from layer element. This must not be freed */
|
||||
linfo.name =(char *)layer_element_get_name(le);
|
||||
|
||||
if (layer_element_get_export(le) == TRUE) {
|
||||
/* Allocate new info and fill with info */
|
||||
linfo = (struct layer_info *)malloc(sizeof(struct layer_info));
|
||||
layer_element_get_color(le, &linfo->color);
|
||||
linfo->layer = layer_element_get_layer(le);
|
||||
linfo->stacked_position = i;
|
||||
linfo->name = (char *)layer_element_get_name(le);
|
||||
layer_element_get_color(le, &linfo.color);
|
||||
linfo.render = (layer_element_get_export(le) ? 1 : 0);
|
||||
linfo.stacked_position = i;
|
||||
linfo.layer = layer_element_get_layer(le);
|
||||
|
||||
/* Append to list */
|
||||
info_list = g_list_append(info_list, (gpointer)linfo);
|
||||
}
|
||||
/* This function copies the entire layer info struct including the name string.
|
||||
* Therefore, using the same layer_info struct over and over is safe.
|
||||
*/
|
||||
layer_settings_append_layer_info(layer_settings, &linfo);
|
||||
}
|
||||
|
||||
return info_list;
|
||||
return layer_settings;
|
||||
}
|
||||
|
||||
static void layer_selector_clear_widgets(LayerSelector *self)
|
||||
|
64
main.c
64
main.c
@ -29,7 +29,7 @@
|
||||
|
||||
#include <gds-render/gds-render-gui.h>
|
||||
#include <gds-render/command-line.h>
|
||||
#include <gds-render/external-renderer.h>
|
||||
#include <gds-render/output-renderers/external-renderer.h>
|
||||
#include <gds-render/version.h>
|
||||
|
||||
/**
|
||||
@ -240,30 +240,25 @@ int main(int argc, char **argv)
|
||||
GError *error = NULL;
|
||||
GOptionContext *context;
|
||||
gchar *gds_name;
|
||||
gchar *basename;
|
||||
gchar *pdfname = NULL, *texname = NULL, *mappingname = NULL, *cellname = NULL, *svgname = NULL;
|
||||
gboolean tikz = FALSE, pdf = FALSE, pdf_layers = FALSE, pdf_standalone = FALSE, svg = FALSE;
|
||||
gboolean version = FALSE;
|
||||
gchar **output_paths = NULL;
|
||||
gchar *mappingname = NULL;
|
||||
gchar *cellname = NULL;
|
||||
gchar **renderer_args = NULL;
|
||||
gboolean version = FALSE, pdf_standalone = FALSE, pdf_layers = FALSE;
|
||||
gchar *custom_library_path = NULL;
|
||||
gchar *custom_library_file_name = NULL;
|
||||
int scale = 1000;
|
||||
int app_status = 0;
|
||||
|
||||
GOptionEntry entries[] = {
|
||||
{"version", 'v', 0, G_OPTION_ARG_NONE, &version, "Print version", NULL},
|
||||
{"tikz", 't', 0, G_OPTION_ARG_NONE, &tikz, "Output TikZ code", NULL },
|
||||
{"pdf", 'p', 0, G_OPTION_ARG_NONE, &pdf, "Output PDF document", NULL },
|
||||
//{"svg", 'S', 0, G_OPTION_ARG_NONE, &svg, "Output SVG image", NULL },
|
||||
{"renderer", 'r', 0, G_OPTION_ARG_STRING_ARRAY, &renderer_args, "Renderer to use. Can be used multiple times.", "pdf|svg|tikz|ext"},
|
||||
{"scale", 's', 0, G_OPTION_ARG_INT, &scale, "Divide output coordinates by <SCALE>", "<SCALE>" },
|
||||
{"tex-output", 'o', 0, G_OPTION_ARG_FILENAME, &texname, "Optional path for TeX file", "PATH" },
|
||||
{"pdf-output", 'O', 0, G_OPTION_ARG_FILENAME, &pdfname, "Optional path for PDF file", "PATH" },
|
||||
//{"svg-output", 0, 0, G_OPTION_ARG_FILENAME, &svgname, "Optional path for PDF file", "PATH"},
|
||||
{"output-file", 'o', 0, G_OPTION_ARG_FILENAME_ARRAY, &output_paths, "Output file path. Can be used multiple times.", "PATH" },
|
||||
{"mapping", 'm', 0, G_OPTION_ARG_FILENAME, &mappingname, "Path for Layer Mapping File", "PATH" },
|
||||
{"cell", 'c', 0, G_OPTION_ARG_STRING, &cellname, "Cell to render", "NAME" },
|
||||
{"tex-standalone", 'a', 0, G_OPTION_ARG_NONE, &pdf_standalone, "Create standalone PDF", NULL },
|
||||
{"tex-layers", 'l', 0, G_OPTION_ARG_NONE, &pdf_layers, "Create PDF Layers (OCG)", NULL },
|
||||
{"custom-render-lib", 'P', 0, G_OPTION_ARG_FILENAME, &custom_library_path, "Path to a custom shared object, that implements the " EXTERNAL_LIBRARY_FUNCTION " function", "PATH"},
|
||||
{"external-lib-output", 'e', 0, G_OPTION_ARG_FILENAME, &custom_library_file_name, "Output path for external render library", "PATH"},
|
||||
{NULL}
|
||||
};
|
||||
|
||||
@ -287,9 +282,6 @@ int main(int argc, char **argv)
|
||||
scale = 1;
|
||||
}
|
||||
|
||||
/* No format selected */
|
||||
if (!(tikz || pdf || svg))
|
||||
tikz = TRUE;
|
||||
|
||||
/* Get gds name */
|
||||
gds_name = argv[1];
|
||||
@ -299,36 +291,26 @@ int main(int argc, char **argv)
|
||||
printf("Ignored argument: %s", argv[i]);
|
||||
}
|
||||
|
||||
/* Check if PDF/TeX names are supplied. if not generate */
|
||||
basename = g_path_get_basename(gds_name);
|
||||
app_status =
|
||||
command_line_convert_gds(gds_name, cellname, renderer_args, output_paths, mappingname,
|
||||
custom_library_path, pdf_standalone, pdf_layers, scale);
|
||||
|
||||
if (!texname)
|
||||
texname = g_strdup_printf("./%s.tex", basename);
|
||||
|
||||
if (!pdfname)
|
||||
pdfname = g_strdup_printf("./%s.pdf", basename);
|
||||
|
||||
if (!svgname)
|
||||
svgname = g_strdup_printf("./%s.svg", basename);
|
||||
|
||||
command_line_convert_gds(gds_name, pdfname, texname, pdf, tikz,
|
||||
mappingname, cellname, (double)scale,
|
||||
pdf_layers, pdf_standalone, svg, svgname,
|
||||
custom_library_path, custom_library_file_name);
|
||||
/* Clean up */
|
||||
g_free(pdfname);
|
||||
g_free(texname);
|
||||
g_free(svgname);
|
||||
g_free(basename);
|
||||
if (mappingname)
|
||||
g_free(mappingname);
|
||||
if (cellname)
|
||||
g_free(cellname);
|
||||
app_status = 0;
|
||||
} else {
|
||||
app_status = start_gui(argc, argv);
|
||||
}
|
||||
|
||||
ret_status:
|
||||
/* If necessary, free command line parameters */
|
||||
if (output_paths)
|
||||
g_strfreev(output_paths);
|
||||
if (renderer_args)
|
||||
g_strfreev(renderer_args);
|
||||
if (mappingname)
|
||||
g_free(mappingname);
|
||||
if (cellname)
|
||||
free(cellname);
|
||||
if (custom_library_path)
|
||||
free(custom_library_path);
|
||||
|
||||
return app_status;
|
||||
}
|
||||
|
@ -22,7 +22,7 @@
|
||||
* @author Mario Hüttel <mario.huettel@gmx.net>
|
||||
*/
|
||||
|
||||
/** @addtogroup Cairo-Renderer
|
||||
/** @addtogroup CairoRenderer
|
||||
* @{
|
||||
*/
|
||||
|
||||
@ -32,10 +32,17 @@
|
||||
#include <cairo-pdf.h>
|
||||
#include <cairo-svg.h>
|
||||
|
||||
#include <gds-render/cairo-renderer/cairo-output.h>
|
||||
#include <gds-render/output-renderers/cairo-renderer.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
struct _CairoRenderer {
|
||||
GdsOutputRenderer parent;
|
||||
gboolean svg; /**< @brief TRUE: SVG output, FALSE: PDF output */
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE(CairoRenderer, cairo_renderer, GDS_RENDER_TYPE_OUTPUT_RENDERER)
|
||||
|
||||
/**
|
||||
* @brief The cairo_layer struct
|
||||
* Each rendered layer is represented by this struct.
|
||||
@ -67,7 +74,7 @@ static void revert_inherited_transform(struct cairo_layer *layers)
|
||||
* @param origin Origin translation
|
||||
* @param magnification Scaling
|
||||
* @param flipping Mirror image on x-axis before rotating
|
||||
* @param rotation Rotattion in degrees
|
||||
* @param rotation Rotation in degrees
|
||||
* @param scale Scale the image down by. Only used for sclaing origin coordinates. Not applied to layer.
|
||||
*/
|
||||
static void apply_inherited_transform_to_all_layers(struct cairo_layer *layers,
|
||||
@ -133,7 +140,9 @@ static void render_cell(struct gds_cell *cell, struct cairo_layer *layers, doubl
|
||||
/* Get layer renderer */
|
||||
if (gfx->layer >= MAX_LAYERS)
|
||||
continue;
|
||||
if ((cr = layers[gfx->layer].cr) == NULL)
|
||||
|
||||
cr = layers[gfx->layer].cr;
|
||||
if (cr == NULL)
|
||||
continue;
|
||||
|
||||
/* Apply settings */
|
||||
@ -160,7 +169,6 @@ static void render_cell(struct gds_cell *cell, struct cairo_layer *layers, doubl
|
||||
cairo_move_to(cr, vertex->x/scale, vertex->y/scale);
|
||||
else
|
||||
cairo_line_to(cr, vertex->x/scale, vertex->y/scale);
|
||||
|
||||
}
|
||||
|
||||
/* Create graphics object */
|
||||
@ -176,12 +184,20 @@ static void render_cell(struct gds_cell *cell, struct cairo_layer *layers, doubl
|
||||
cairo_fill(cr);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} /* for gfx list */
|
||||
}
|
||||
|
||||
void cairo_render_cell_to_vector_file(struct gds_cell *cell, GList *layer_infos, char *pdf_file, char *svg_file, double scale)
|
||||
/**
|
||||
* @brief Render \p cell to a PDF file specified by \p pdf_file
|
||||
* @param cell Toplevel cell to @ref Cairo-Renderer
|
||||
* @param layer_infos List of layer information. Specifies color and layer stacking
|
||||
* @param pdf_file PDF output file. Set to NULL if no PDF file has to be generated
|
||||
* @param svg_file SVG output file. Set to NULL if no SVG file has to be generated
|
||||
* @param scale Scale the output image down by \p scale
|
||||
* @return Error
|
||||
*/
|
||||
static int cairo_renderer_render_cell_to_vector_file(struct gds_cell *cell, GList *layer_infos, const char *pdf_file,
|
||||
const char *svg_file, double scale)
|
||||
{
|
||||
cairo_surface_t *pdf_surface = NULL, *svg_surface = NULL;
|
||||
cairo_t *pdf_cr = NULL, *svg_cr = NULL;
|
||||
@ -196,7 +212,7 @@ void cairo_render_cell_to_vector_file(struct gds_cell *cell, GList *layer_infos,
|
||||
|
||||
if (pdf_file == NULL && svg_file == NULL) {
|
||||
/* No output specified */
|
||||
return;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Fork to a new child process. This ensures the memory leaks (see issue #16) in Cairo don't
|
||||
@ -204,7 +220,10 @@ void cairo_render_cell_to_vector_file(struct gds_cell *cell, GList *layer_infos,
|
||||
*
|
||||
* And by the way: This now bricks all Windows compatibility. Deal with it.
|
||||
*/
|
||||
|
||||
/* Use fork for production code and -1 as value for debugging */
|
||||
process_id = fork();
|
||||
//process_id = -1;
|
||||
if (process_id < 0) {
|
||||
/* Well... shit... We have to run it in our process. */
|
||||
} else if (process_id > 0) {
|
||||
@ -224,6 +243,10 @@ void cairo_render_cell_to_vector_file(struct gds_cell *cell, GList *layer_infos,
|
||||
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) {
|
||||
/* Layer shall not be rendered */
|
||||
if (!linfo->render)
|
||||
continue;
|
||||
|
||||
lay = &(layers[(unsigned int)linfo->layer]);
|
||||
lay->linfo = linfo;
|
||||
lay->rec = cairo_recording_surface_create(CAIRO_CONTENT_COLOR_ALPHA,
|
||||
@ -249,6 +272,9 @@ void cairo_render_cell_to_vector_file(struct gds_cell *cell, GList *layer_infos,
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!linfo->render)
|
||||
continue;
|
||||
|
||||
/* Print size */
|
||||
cairo_recording_surface_ink_extents(layers[linfo->layer].rec, &rec_x0, &rec_y0,
|
||||
&rec_width, &rec_height);
|
||||
@ -292,6 +318,9 @@ void cairo_render_cell_to_vector_file(struct gds_cell *cell, GList *layer_infos,
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!linfo->render)
|
||||
continue;
|
||||
|
||||
if (pdf_file && pdf_cr) {
|
||||
cairo_set_source_surface(pdf_cr, layers[linfo->layer].rec, -xmin, -ymin);
|
||||
cairo_paint_with_alpha(pdf_cr, linfo->color.alpha);
|
||||
@ -332,10 +361,78 @@ ret_clear_layers:
|
||||
exit(0);
|
||||
|
||||
/* Fork didn't work. Just return here */
|
||||
return;
|
||||
return 0;
|
||||
ret_parent:
|
||||
waitpid(process_id, NULL, 0);
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void cairo_renderer_init(CairoRenderer *self)
|
||||
{
|
||||
/* PDF default */
|
||||
self->svg = FALSE;
|
||||
}
|
||||
|
||||
static int cairo_renderer_render_output(GdsOutputRenderer *renderer,
|
||||
struct gds_cell *cell,
|
||||
double scale)
|
||||
{
|
||||
CairoRenderer *c_renderer = GDS_RENDER_CAIRO_RENDERER(renderer);
|
||||
const char *pdf_file = NULL;
|
||||
const char *svg_file = NULL;
|
||||
LayerSettings *settings;
|
||||
GList *layer_infos = NULL;
|
||||
const char *output_file;
|
||||
int ret;
|
||||
|
||||
if (!c_renderer)
|
||||
return -2000;
|
||||
|
||||
output_file = gds_output_renderer_get_output_file(renderer);
|
||||
settings = gds_output_renderer_get_and_ref_layer_settings(renderer);
|
||||
|
||||
/* Set layer info list. In case of failure it remains NULL */
|
||||
if (settings)
|
||||
layer_infos = layer_settings_get_layer_info_list(settings);
|
||||
|
||||
if (c_renderer->svg == TRUE)
|
||||
svg_file = output_file;
|
||||
else
|
||||
pdf_file = output_file;
|
||||
|
||||
ret = cairo_renderer_render_cell_to_vector_file(cell, layer_infos, pdf_file, svg_file, scale);
|
||||
|
||||
if (settings)
|
||||
g_object_unref(settings);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void cairo_renderer_class_init(CairoRendererClass *klass)
|
||||
{
|
||||
GdsOutputRendererClass *renderer_class = GDS_RENDER_OUTPUT_RENDERER_CLASS(klass);
|
||||
|
||||
renderer_class->render_output = cairo_renderer_render_output;
|
||||
}
|
||||
|
||||
CairoRenderer *cairo_renderer_new_pdf()
|
||||
{
|
||||
CairoRenderer *renderer;
|
||||
|
||||
renderer = GDS_RENDER_CAIRO_RENDERER(g_object_new(GDS_RENDER_TYPE_CAIRO_RENDERER, NULL));
|
||||
renderer->svg = FALSE;
|
||||
|
||||
return renderer;
|
||||
}
|
||||
|
||||
CairoRenderer *cairo_renderer_new_svg()
|
||||
{
|
||||
CairoRenderer *renderer;
|
||||
|
||||
renderer = GDS_RENDER_CAIRO_RENDERER(g_object_new(GDS_RENDER_TYPE_CAIRO_RENDERER, NULL));
|
||||
renderer->svg = TRUE;
|
||||
|
||||
return renderer;
|
||||
}
|
||||
|
||||
/** @} */
|
213
output-renderers/external-renderer.c
Normal file
213
output-renderers/external-renderer.c
Normal file
@ -0,0 +1,213 @@
|
||||
/*
|
||||
* GDSII-Converter
|
||||
* Copyright (C) 2018 Mario Hüttel <mario.huettel@gmx.net>
|
||||
*
|
||||
* This file is part of GDSII-Converter.
|
||||
*
|
||||
* GDSII-Converter is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* GDSII-Converter is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GDSII-Converter. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file external-renderer.c
|
||||
* @brief This file implements the dynamic library loading for the external rendering feature
|
||||
* @author Mario Hüttel <mario.huettel@gmx.net>
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup ExternalRenderer
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <gds-render/output-renderers/external-renderer.h>
|
||||
|
||||
struct _ExternalRenderer {
|
||||
GdsOutputRenderer parent;
|
||||
char *shared_object_path;
|
||||
};
|
||||
|
||||
enum {
|
||||
PROP_SO_PATH = 1, /**< @brief Shared object path property */
|
||||
N_PROPERTIES /**< @brief Used to get property count */
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE(ExternalRenderer, external_renderer, GDS_RENDER_TYPE_OUTPUT_RENDERER)
|
||||
|
||||
/**
|
||||
* @brief Execute render function in shared object to render the supplied cell
|
||||
* @param toplevel_cell Cell to render
|
||||
* @param layer_info_list Layer information (Color etc.)
|
||||
* @param output_file Destination file
|
||||
* @param so_path Path to shared object
|
||||
* @return 0 if successful
|
||||
*/
|
||||
static int external_renderer_render_cell(struct gds_cell *toplevel_cell, GList *layer_info_list,
|
||||
const char *output_file, double scale, const char *so_path)
|
||||
{
|
||||
int (*so_render_func)(struct gds_cell *, GList *, const char *, double) = NULL;
|
||||
void *so_handle = NULL;
|
||||
char *error_msg;
|
||||
int ret = 0;
|
||||
|
||||
if (!so_path) {
|
||||
fprintf(stderr, "Path to shared object not set!\n");
|
||||
return -3000;
|
||||
}
|
||||
|
||||
/* Check parameter sanity */
|
||||
if (!output_file || !toplevel_cell || !layer_info_list)
|
||||
return -3000;
|
||||
|
||||
/* Load shared object */
|
||||
so_handle = dlopen(so_path, RTLD_LAZY);
|
||||
if (!so_handle) {
|
||||
fprintf(stderr, "Could not load external library '%s'\nDetailed error is:\n%s\n", so_path, dlerror());
|
||||
return -2000;
|
||||
}
|
||||
|
||||
/* Load symbol from library */
|
||||
so_render_func = (int (*)(struct gds_cell *, GList *, const char *, double))dlsym(so_handle, EXTERNAL_LIBRARY_FUNCTION);
|
||||
error_msg = dlerror();
|
||||
if (error_msg != NULL) {
|
||||
fprintf(stderr, "Rendering function not found in library:\n%s\n", error_msg);
|
||||
goto ret_close_so_handle;
|
||||
}
|
||||
|
||||
/* Execute */
|
||||
if (so_render_func) {
|
||||
g_message("Calling external renderer.");
|
||||
ret = so_render_func(toplevel_cell, layer_info_list, output_file, scale);
|
||||
g_message("External renderer finished.");
|
||||
}
|
||||
|
||||
ret_close_so_handle:
|
||||
dlclose(so_handle);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int external_renderer_render_output(GdsOutputRenderer *renderer,
|
||||
struct gds_cell *cell,
|
||||
double scale)
|
||||
{
|
||||
ExternalRenderer *ext_renderer = GDS_RENDER_EXTERNAL_RENDERER(renderer);
|
||||
LayerSettings *settings;
|
||||
GList *layer_infos = NULL;
|
||||
const char *output_file;
|
||||
int ret;
|
||||
|
||||
output_file = gds_output_renderer_get_output_file(renderer);
|
||||
settings = gds_output_renderer_get_and_ref_layer_settings(renderer);
|
||||
|
||||
/* Set layer info list. In case of failure it remains NULL */
|
||||
if (settings)
|
||||
layer_infos = layer_settings_get_layer_info_list(settings);
|
||||
|
||||
ret = external_renderer_render_cell(cell, layer_infos, output_file, scale, ext_renderer->shared_object_path);
|
||||
if (settings)
|
||||
g_object_unref(settings);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void external_renderer_get_property(GObject *obj, guint property_id, GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
ExternalRenderer *self;
|
||||
|
||||
self = GDS_RENDER_EXTERNAL_RENDERER(obj);
|
||||
|
||||
switch (property_id) {
|
||||
case PROP_SO_PATH:
|
||||
g_value_set_string(value, self->shared_object_path);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void external_renderer_set_property(GObject *obj, guint property_id, const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
ExternalRenderer *self;
|
||||
|
||||
self = GDS_RENDER_EXTERNAL_RENDERER(obj);
|
||||
|
||||
switch (property_id) {
|
||||
case PROP_SO_PATH:
|
||||
if (self->shared_object_path)
|
||||
g_free(self->shared_object_path);
|
||||
self->shared_object_path = g_value_dup_string(value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void external_renderer_dispose(GObject *self_obj)
|
||||
{
|
||||
ExternalRenderer *self = GDS_RENDER_EXTERNAL_RENDERER(self_obj);
|
||||
|
||||
if (self->shared_object_path) {
|
||||
g_free(self->shared_object_path);
|
||||
self->shared_object_path = NULL;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS(external_renderer_parent_class)->dispose(self_obj);
|
||||
}
|
||||
|
||||
static GParamSpec *external_renderer_properties[N_PROPERTIES] = {NULL};
|
||||
|
||||
static void external_renderer_class_init(ExternalRendererClass *klass)
|
||||
{
|
||||
GdsOutputRendererClass *inherited_parent_class;
|
||||
GObjectClass *oclass;
|
||||
|
||||
inherited_parent_class = GDS_RENDER_OUTPUT_RENDERER_CLASS(klass);
|
||||
oclass = G_OBJECT_CLASS(klass);
|
||||
|
||||
/* Override virtual function */
|
||||
inherited_parent_class->render_output = external_renderer_render_output;
|
||||
|
||||
/* Setup Gobject callbacks */
|
||||
oclass->set_property = external_renderer_set_property;
|
||||
oclass->get_property = external_renderer_get_property;
|
||||
oclass->dispose = external_renderer_dispose;
|
||||
|
||||
/* Setup properties */
|
||||
external_renderer_properties[PROP_SO_PATH] =
|
||||
g_param_spec_string("shared-object-path",
|
||||
"Shared object file path",
|
||||
"Path to the shared object to search rendering function in.",
|
||||
NULL,
|
||||
G_PARAM_READWRITE);
|
||||
g_object_class_install_properties(oclass, N_PROPERTIES, external_renderer_properties);
|
||||
}
|
||||
|
||||
static void external_renderer_init(ExternalRenderer *self)
|
||||
{
|
||||
self->shared_object_path = NULL;
|
||||
}
|
||||
|
||||
ExternalRenderer *external_renderer_new()
|
||||
{
|
||||
return g_object_new(GDS_RENDER_TYPE_EXTERNAL_RENDERER, NULL);
|
||||
}
|
||||
|
||||
ExternalRenderer *external_renderer_new_with_so(const char *so_path)
|
||||
{
|
||||
return g_object_new(GDS_RENDER_TYPE_EXTERNAL_RENDERER, "shared-object-path", so_path, NULL);
|
||||
}
|
||||
|
||||
/** @} */
|
365
output-renderers/gds-output-renderer.c
Normal file
365
output-renderers/gds-output-renderer.c
Normal file
@ -0,0 +1,365 @@
|
||||
/*
|
||||
* GDSII-Converter
|
||||
* Copyright (C) 2019 Mario Hüttel <mario.huettel@gmx.net>
|
||||
*
|
||||
* This file is part of GDSII-Converter.
|
||||
*
|
||||
* GDSII-Converter is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* GDSII-Converter is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GDSII-Converter. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file gds-output-renderer.c
|
||||
* @brief Base GObject class for output renderers
|
||||
*
|
||||
* All output renderers are derived from this class
|
||||
*
|
||||
* @author Mario Hüttel <mario.huettel@gmx.net>
|
||||
*/
|
||||
|
||||
/** @addtogroup GdsOutputRenderer
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include <gds-render/output-renderers/gds-output-renderer.h>
|
||||
#include <gds-render/layer/layer-info.h>
|
||||
|
||||
struct renderer_params {
|
||||
struct gds_cell *cell;
|
||||
double scale;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
gchar *output_file;
|
||||
LayerSettings *layer_settings;
|
||||
GMutex settings_lock;
|
||||
gboolean mutex_init_status;
|
||||
GTask *task;
|
||||
struct renderer_params async_params;
|
||||
gpointer padding[11];
|
||||
} GdsOutputRendererPrivate;
|
||||
|
||||
enum {
|
||||
PROP_OUTPUT_FILE = 1,
|
||||
PROP_LAYER_SETTINGS,
|
||||
N_PROPERTIES
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE(GdsOutputRenderer, gds_output_renderer, G_TYPE_OBJECT)
|
||||
|
||||
enum gds_output_renderer_signal_ids {ASYNC_FINISHED = 0, ASYNC_PROGRESS_UPDATE, GDS_OUTPUT_RENDERER_SIGNAL_COUNT};
|
||||
static guint gds_output_renderer_signals[GDS_OUTPUT_RENDERER_SIGNAL_COUNT];
|
||||
|
||||
static int gds_output_renderer_render_dummy(GdsOutputRenderer *renderer,
|
||||
struct gds_cell *cell,
|
||||
double scale)
|
||||
{
|
||||
(void)renderer;
|
||||
(void)cell;
|
||||
(void)scale;
|
||||
|
||||
g_warning("Output renderer does not define a render_output function!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void gds_output_renderer_dispose(GObject *self_obj)
|
||||
{
|
||||
GdsOutputRenderer *renderer = GDS_RENDER_OUTPUT_RENDERER(self_obj);
|
||||
GdsOutputRendererPrivate *priv;
|
||||
|
||||
priv = gds_output_renderer_get_instance_private(renderer);
|
||||
|
||||
if (priv->mutex_init_status) {
|
||||
/* Try locking the mutex, to test if it's free */
|
||||
g_mutex_lock(&priv->settings_lock);
|
||||
g_mutex_unlock(&priv->settings_lock);
|
||||
g_mutex_clear(&priv->settings_lock);
|
||||
priv->mutex_init_status = FALSE;
|
||||
}
|
||||
|
||||
g_clear_object(&priv->task);
|
||||
|
||||
if (priv->output_file)
|
||||
g_free(priv->output_file);
|
||||
|
||||
g_clear_object(&priv->layer_settings);
|
||||
|
||||
/* Chain up to parent class */
|
||||
G_OBJECT_CLASS(gds_output_renderer_parent_class)->dispose(self_obj);
|
||||
}
|
||||
|
||||
static void gds_output_renderer_get_property(GObject *obj, guint property_id, GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
GdsOutputRenderer *self = GDS_RENDER_OUTPUT_RENDERER(obj);
|
||||
GdsOutputRendererPrivate *priv;
|
||||
|
||||
priv = gds_output_renderer_get_instance_private(self);
|
||||
|
||||
switch (property_id) {
|
||||
case PROP_OUTPUT_FILE:
|
||||
g_value_set_string(value, priv->output_file);
|
||||
break;
|
||||
case PROP_LAYER_SETTINGS:
|
||||
g_value_set_object(value, priv->layer_settings);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void gds_output_renderer_set_property(GObject *obj, guint property_id, const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
GdsOutputRenderer *self = GDS_RENDER_OUTPUT_RENDERER(obj);
|
||||
GdsOutputRendererPrivate *priv;
|
||||
|
||||
priv = gds_output_renderer_get_instance_private(self);
|
||||
|
||||
switch (property_id) {
|
||||
case PROP_OUTPUT_FILE:
|
||||
g_mutex_lock(&priv->settings_lock);
|
||||
if (priv->output_file)
|
||||
g_free(priv->output_file);
|
||||
priv->output_file = g_strdup(g_value_get_string(value));
|
||||
g_mutex_unlock(&priv->settings_lock);
|
||||
break;
|
||||
case PROP_LAYER_SETTINGS:
|
||||
g_mutex_lock(&priv->settings_lock);
|
||||
g_clear_object(&priv->layer_settings);
|
||||
priv->layer_settings = g_value_get_object(value);
|
||||
g_object_ref(priv->layer_settings);
|
||||
g_mutex_unlock(&priv->settings_lock);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static GParamSpec *gds_output_renderer_properties[N_PROPERTIES] = {NULL};
|
||||
|
||||
static void gds_output_renderer_class_init(GdsOutputRendererClass *klass)
|
||||
{
|
||||
GObjectClass *oclass = G_OBJECT_CLASS(klass);
|
||||
|
||||
klass->render_output = gds_output_renderer_render_dummy;
|
||||
|
||||
oclass->dispose = gds_output_renderer_dispose;
|
||||
oclass->set_property = gds_output_renderer_set_property;
|
||||
oclass->get_property = gds_output_renderer_get_property;
|
||||
|
||||
/* Setup properties */
|
||||
gds_output_renderer_properties[PROP_OUTPUT_FILE] =
|
||||
g_param_spec_string("output-file", "output file", "Output file for renderer",
|
||||
NULL, G_PARAM_READWRITE);
|
||||
gds_output_renderer_properties[PROP_LAYER_SETTINGS] =
|
||||
g_param_spec_object("layer-settings", "Layer Settings object",
|
||||
"Object containing the layer rendering information",
|
||||
GDS_RENDER_TYPE_LAYER_SETTINGS, G_PARAM_READWRITE);
|
||||
g_object_class_install_properties(oclass, N_PROPERTIES, gds_output_renderer_properties);
|
||||
|
||||
/* Setup output signals */
|
||||
gds_output_renderer_signals[ASYNC_FINISHED] =
|
||||
g_signal_newv("async-finished", GDS_RENDER_TYPE_OUTPUT_RENDERER,
|
||||
G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
G_TYPE_NONE,
|
||||
0,
|
||||
NULL);
|
||||
gds_output_renderer_signals[ASYNC_PROGRESS_UPDATE] =
|
||||
g_signal_newv("progress-update", GDS_RENDER_TYPE_OUTPUT_RENDERER,
|
||||
G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
G_TYPE_NONE,
|
||||
0,
|
||||
NULL);
|
||||
}
|
||||
|
||||
void gds_output_renderer_init(GdsOutputRenderer *self)
|
||||
{
|
||||
GdsOutputRendererPrivate *priv;
|
||||
|
||||
priv = gds_output_renderer_get_instance_private(self);
|
||||
|
||||
priv->layer_settings = NULL;
|
||||
priv->output_file = NULL;
|
||||
priv->task = NULL;
|
||||
priv->mutex_init_status = TRUE;
|
||||
g_mutex_init(&priv->settings_lock);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
GdsOutputRenderer *gds_output_renderer_new()
|
||||
{
|
||||
return GDS_RENDER_OUTPUT_RENDERER(g_object_new(GDS_RENDER_TYPE_OUTPUT_RENDERER, NULL));
|
||||
}
|
||||
|
||||
GdsOutputRenderer *gds_output_renderer_new_with_props(const char *output_file, LayerSettings *layer_settings)
|
||||
{
|
||||
return GDS_RENDER_OUTPUT_RENDERER(g_object_new(GDS_RENDER_TYPE_OUTPUT_RENDERER,
|
||||
"layer-settings", layer_settings,
|
||||
"output-file", output_file,
|
||||
NULL));
|
||||
}
|
||||
|
||||
void gds_output_renderer_set_output_file(GdsOutputRenderer *renderer, const gchar *file_name)
|
||||
{
|
||||
g_return_if_fail(GDS_RENDER_IS_OUTPUT_RENDERER(renderer));
|
||||
|
||||
/* Check if the filename is actually filled */
|
||||
if (!file_name || !file_name[0])
|
||||
return;
|
||||
g_object_set(renderer, "output-file", file_name, NULL);
|
||||
}
|
||||
|
||||
const char *gds_output_renderer_get_output_file(GdsOutputRenderer *renderer)
|
||||
{
|
||||
const char *file = NULL;
|
||||
|
||||
g_object_get(renderer, "output-file", &file, NULL);
|
||||
return file;
|
||||
}
|
||||
|
||||
LayerSettings *gds_output_renderer_get_and_ref_layer_settings(GdsOutputRenderer *renderer)
|
||||
{
|
||||
LayerSettings *ret = NULL;
|
||||
GdsOutputRendererPrivate *priv;
|
||||
|
||||
priv = gds_output_renderer_get_instance_private(renderer);
|
||||
|
||||
/* Acquire settings lock */
|
||||
g_mutex_lock(&priv->settings_lock);
|
||||
|
||||
g_object_get(renderer, "layer-settings", &ret, NULL);
|
||||
/* Reference it, so it is not cleared by another thread overwriting the property */
|
||||
g_object_ref(ret);
|
||||
|
||||
/* It is now safe to clear the lock */
|
||||
g_mutex_unlock(&priv->settings_lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void gds_output_renderer_set_layer_settings(GdsOutputRenderer *renderer, LayerSettings *settings)
|
||||
{
|
||||
g_return_if_fail(GDS_RENDER_IS_LAYER_SETTINGS(settings));
|
||||
|
||||
g_object_set(renderer, "layer-settings", settings, NULL);
|
||||
}
|
||||
|
||||
int gds_output_renderer_render_output(GdsOutputRenderer *renderer, struct gds_cell *cell, double scale)
|
||||
{
|
||||
int ret;
|
||||
GdsOutputRendererClass *klass;
|
||||
GdsOutputRendererPrivate *priv = gds_output_renderer_get_instance_private(renderer);
|
||||
|
||||
if (GDS_RENDER_IS_OUTPUT_RENDERER(renderer) == FALSE) {
|
||||
g_error("Output Renderer not valid.");
|
||||
return GDS_OUTPUT_RENDERER_GEN_ERR;
|
||||
}
|
||||
|
||||
if (!priv->output_file || !priv->output_file[0]) {
|
||||
g_error("No/invalid output file set.");
|
||||
return GDS_OUTPUT_RENDERER_GEN_ERR;
|
||||
}
|
||||
|
||||
if (!priv->layer_settings) {
|
||||
g_error("No layer specification supplied.");
|
||||
return GDS_OUTPUT_RENDERER_GEN_ERR;
|
||||
}
|
||||
|
||||
if (!cell) {
|
||||
g_error("Output renderer called without cell to render.");
|
||||
return GDS_OUTPUT_RENDERER_PARAM_ERR;
|
||||
}
|
||||
|
||||
klass = GDS_RENDER_OUTPUT_RENDERER_GET_CLASS(renderer);
|
||||
if (klass->render_output == NULL) {
|
||||
g_critical("Output Renderer: Rendering function broken. This is a bug.");
|
||||
return GDS_OUTPUT_RENDERER_GEN_ERR;
|
||||
}
|
||||
|
||||
ret = klass->render_output(renderer, cell, scale);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void gds_output_renderer_async_wrapper(GTask *task,
|
||||
gpointer source_object,
|
||||
gpointer task_data,
|
||||
GCancellable *cancellable)
|
||||
{
|
||||
GdsOutputRenderer *renderer;
|
||||
GdsOutputRendererPrivate *priv;
|
||||
int ret;
|
||||
|
||||
renderer = GDS_RENDER_OUTPUT_RENDERER(source_object);
|
||||
priv = gds_output_renderer_get_instance_private(renderer);
|
||||
if (!priv) {
|
||||
ret = -1000;
|
||||
goto ret_from_task;
|
||||
}
|
||||
if(!priv->mutex_init_status) {
|
||||
ret = -1001;
|
||||
goto ret_from_task;
|
||||
}
|
||||
|
||||
g_mutex_lock(&priv->settings_lock);
|
||||
ret = gds_output_renderer_render_output(renderer, priv->async_params.cell, priv->async_params.scale);
|
||||
g_mutex_unlock(&priv->settings_lock);
|
||||
|
||||
ret_from_task:
|
||||
g_task_return_int(task, ret);
|
||||
}
|
||||
|
||||
static void gds_output_renderer_async_finished(GObject *src_obj, GAsyncResult *res, gpointer user_data)
|
||||
{
|
||||
GdsOutputRendererPrivate *priv;
|
||||
(void)user_data;
|
||||
(void)res; /* Will hopefully be destroyed later */
|
||||
|
||||
priv = gds_output_renderer_get_instance_private(GDS_RENDER_OUTPUT_RENDERER(src_obj));
|
||||
|
||||
g_signal_emit(src_obj, gds_output_renderer_signals[ASYNC_FINISHED], 0);
|
||||
g_clear_object(&priv->task);
|
||||
}
|
||||
|
||||
int gds_output_renderer_render_output_async(GdsOutputRenderer *renderer, struct gds_cell *cell, double scale)
|
||||
{
|
||||
GdsOutputRendererPrivate *priv;
|
||||
int ret = -1;
|
||||
|
||||
priv = gds_output_renderer_get_instance_private(renderer);
|
||||
if (priv->task) {
|
||||
g_warning("renderer already started asynchronously");
|
||||
return -2000;
|
||||
}
|
||||
|
||||
priv->task = g_task_new(renderer, NULL, gds_output_renderer_async_finished, NULL);
|
||||
g_mutex_lock(&priv->settings_lock);
|
||||
priv->async_params.cell = cell;
|
||||
priv->async_params.scale = scale;
|
||||
g_mutex_unlock(&priv->settings_lock);
|
||||
|
||||
g_task_run_in_thread(priv->task, gds_output_renderer_async_wrapper);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/** @} */
|
@ -24,15 +24,33 @@
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include <gds-render/latex-renderer/latex-output.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <gds-render/output-renderers/latex-renderer.h>
|
||||
#include <gdk/gdk.h>
|
||||
#include <gds-render/layer/layer-info.h>
|
||||
/**
|
||||
* @addtogroup LaTeX-Renderer
|
||||
* @addtogroup LatexRenderer
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @brief Writes a GString \p buffer to the fixed file tex_file */
|
||||
struct _LatexRenderer {
|
||||
GdsOutputRenderer parent;
|
||||
gboolean tex_standalone;
|
||||
gboolean pdf_layers;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE(LatexRenderer, latex_renderer, GDS_RENDER_TYPE_OUTPUT_RENDERER)
|
||||
|
||||
enum {
|
||||
PROP_STANDALONE = 1,
|
||||
PROP_PDF_LAYERS,
|
||||
N_PROPERTIES
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Writes a GString \p buffer to the fixed file tex_file
|
||||
* @note This is a convinience macro. Do not use this anywhere else. It might change behavior in futurtre releases
|
||||
*/
|
||||
#define WRITEOUT_BUFFER(buff) fwrite((buff)->str, sizeof(char), (buff)->len, tex_file)
|
||||
|
||||
/**
|
||||
@ -51,10 +69,13 @@ static void write_layer_definitions(FILE *tex_file, GList *layer_infos, GString
|
||||
{
|
||||
GList *list;
|
||||
struct layer_info *lifo;
|
||||
char *end_str;
|
||||
|
||||
for (list = layer_infos; list != NULL; list = list->next) {
|
||||
lifo = (struct layer_info *)list->data;
|
||||
|
||||
if (!lifo->render)
|
||||
continue;
|
||||
|
||||
g_string_printf(buffer, "\\pgfdeclarelayer{l%d}\n\\definecolor{c%d}{rgb}{%lf,%lf,%lf}\n",
|
||||
lifo->layer, lifo->layer,
|
||||
lifo->color.red, lifo->color.green, lifo->color.blue);
|
||||
@ -67,14 +88,14 @@ static void write_layer_definitions(FILE *tex_file, GList *layer_infos, GString
|
||||
for (list = layer_infos; list != NULL; list = list->next) {
|
||||
lifo = (struct layer_info *)list->data;
|
||||
|
||||
if (list->next == NULL)
|
||||
end_str = ",main}";
|
||||
else
|
||||
end_str = ",";
|
||||
g_string_printf(buffer, "l%d%s", lifo->layer, end_str);
|
||||
if (!lifo->render)
|
||||
continue;
|
||||
|
||||
g_string_printf(buffer, "l%d,", lifo->layer);
|
||||
WRITEOUT_BUFFER(buffer);
|
||||
}
|
||||
fwrite("\n", sizeof(char), 1, tex_file);
|
||||
g_string_printf(buffer, "main}\n");
|
||||
WRITEOUT_BUFFER(buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -110,7 +131,7 @@ static gboolean write_layer_env(FILE *tex_file, GdkRGBA *color, int layer, GList
|
||||
|
||||
for (temp = linfo; temp != NULL; temp = temp->next) {
|
||||
inf = (struct layer_info *)temp->data;
|
||||
if (inf->layer == layer) {
|
||||
if (inf->layer == layer && inf->render) {
|
||||
color->alpha = inf->color.alpha;
|
||||
color->red = inf->color.red;
|
||||
color->green = inf->color.green;
|
||||
@ -249,14 +270,14 @@ static void render_cell(struct gds_cell *cell, GList *layer_infos, FILE *tex_fil
|
||||
|
||||
}
|
||||
|
||||
void latex_render_cell_to_code(struct gds_cell *cell, GList *layer_infos, FILE *tex_file, double scale,
|
||||
static int latex_render_cell_to_code(struct gds_cell *cell, GList *layer_infos, FILE *tex_file, double scale,
|
||||
gboolean create_pdf_layers, gboolean standalone_document)
|
||||
{
|
||||
GString *working_line;
|
||||
|
||||
|
||||
if (!tex_file || !layer_infos || !cell)
|
||||
return;
|
||||
return -1;
|
||||
|
||||
/* 10 kB Line working buffer should be enough */
|
||||
working_line = g_string_new_len(NULL, LATEX_LINE_BUFFER_KB*1024);
|
||||
@ -298,6 +319,125 @@ void latex_render_cell_to_code(struct gds_cell *cell, GList *layer_infos, FILE *
|
||||
|
||||
fflush(tex_file);
|
||||
g_string_free(working_line, TRUE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int latex_renderer_render_output(GdsOutputRenderer *renderer,
|
||||
struct gds_cell *cell,
|
||||
double scale)
|
||||
{
|
||||
LatexRenderer *l_renderer = GDS_RENDER_LATEX_RENDERER(renderer);
|
||||
FILE *tex_file;
|
||||
int ret = -2;
|
||||
LayerSettings *settings;
|
||||
GList *layer_infos = NULL;
|
||||
const char *output_file;
|
||||
|
||||
output_file = gds_output_renderer_get_output_file(renderer);
|
||||
settings = gds_output_renderer_get_and_ref_layer_settings(renderer);
|
||||
|
||||
/* Set layer info list. In case of failure it remains NULL */
|
||||
if (settings)
|
||||
layer_infos = layer_settings_get_layer_info_list(settings);
|
||||
|
||||
tex_file = fopen(output_file, "w");
|
||||
if (tex_file) {
|
||||
ret = latex_render_cell_to_code(cell, layer_infos, tex_file, scale,
|
||||
l_renderer->pdf_layers, l_renderer->tex_standalone);
|
||||
fclose(tex_file);
|
||||
} else {
|
||||
g_error("Could not open LaTeX output file");
|
||||
}
|
||||
|
||||
if (settings) {
|
||||
g_object_unref(settings);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void latex_renderer_init(LatexRenderer *self)
|
||||
{
|
||||
self->pdf_layers = FALSE;
|
||||
self->tex_standalone = FALSE;
|
||||
}
|
||||
|
||||
static void latex_renderer_get_property(GObject *obj, guint property_id, GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
LatexRenderer *self = GDS_RENDER_LATEX_RENDERER(obj);
|
||||
|
||||
switch (property_id) {
|
||||
case PROP_STANDALONE:
|
||||
g_value_set_boolean(value, self->tex_standalone);
|
||||
break;
|
||||
case PROP_PDF_LAYERS:
|
||||
g_value_set_boolean(value, self->pdf_layers);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void latex_renderer_set_property(GObject *obj, guint property_id, const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
LatexRenderer *self = GDS_RENDER_LATEX_RENDERER(obj);
|
||||
|
||||
switch (property_id) {
|
||||
case PROP_STANDALONE:
|
||||
self->tex_standalone = g_value_get_boolean(value);
|
||||
break;
|
||||
case PROP_PDF_LAYERS:
|
||||
self->pdf_layers = g_value_get_boolean(value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static GParamSpec *latex_renderer_properties[N_PROPERTIES] = {NULL};
|
||||
|
||||
static void latex_renderer_class_init(LatexRendererClass *klass)
|
||||
{
|
||||
GdsOutputRendererClass *render_class = GDS_RENDER_OUTPUT_RENDERER_CLASS(klass);
|
||||
GObjectClass *oclass = G_OBJECT_CLASS(klass);
|
||||
|
||||
/* Overwrite virtual function */
|
||||
render_class->render_output = latex_renderer_render_output;
|
||||
|
||||
/* Property stuff */
|
||||
oclass->get_property = latex_renderer_get_property;
|
||||
oclass->set_property = latex_renderer_set_property;
|
||||
|
||||
latex_renderer_properties[PROP_STANDALONE] =
|
||||
g_param_spec_boolean("standalone",
|
||||
"Standalone TeX file",
|
||||
"Generate a standalone LaTeX file.",
|
||||
FALSE,
|
||||
G_PARAM_READWRITE);
|
||||
latex_renderer_properties[PROP_PDF_LAYERS] =
|
||||
g_param_spec_boolean("pdf-layers",
|
||||
"PDF OCR layers",
|
||||
"Generate OCR layers",
|
||||
FALSE,
|
||||
G_PARAM_READWRITE);
|
||||
|
||||
g_object_class_install_properties(oclass, N_PROPERTIES, latex_renderer_properties);
|
||||
}
|
||||
|
||||
LatexRenderer *latex_renderer_new()
|
||||
{
|
||||
return GDS_RENDER_LATEX_RENDERER(g_object_new(GDS_RENDER_TYPE_LATEX_RENDERER, NULL));
|
||||
}
|
||||
|
||||
LatexRenderer *latex_renderer_new_with_options(gboolean pdf_layers, gboolean standalone)
|
||||
{
|
||||
GObject *obj;
|
||||
|
||||
obj = g_object_new(GDS_RENDER_TYPE_LATEX_RENDERER, "standalone", standalone, "pdf-layers", pdf_layers, NULL);
|
||||
return GDS_RENDER_LATEX_RENDERER(obj);
|
||||
}
|
||||
|
||||
/** @} */
|
Loading…
Reference in New Issue
Block a user