Style improvements

This commit is contained in:
Mario Hüttel 2019-10-25 21:16:31 +02:00
parent 547b002e57
commit 2e8e258b49
6 changed files with 121 additions and 103 deletions

View File

@ -141,13 +141,16 @@ static int color_palette_fill_with_resource(ColorPalette *palette, char *resourc
g_regex_match(regex, line, 0, &mi);
if (g_match_info_matches(mi) && color_idx < lines) {
match = g_match_info_fetch_named(mi, "red");
palette->color_array[color_idx].red = (double)g_ascii_strtoll(match, NULL, 16) / 255.0;
palette->color_array[color_idx].red =
(double)g_ascii_strtoll(match, NULL, 16) / 255.0;
g_free(match);
match = g_match_info_fetch_named(mi, "green");
palette->color_array[color_idx].green = (double)g_ascii_strtoll(match, NULL, 16) / 255.0;
palette->color_array[color_idx].green =
(double)g_ascii_strtoll(match, NULL, 16) / 255.0;
g_free(match);
match = g_match_info_fetch_named(mi, "blue");
palette->color_array[color_idx].blue = (double)g_ascii_strtoll(match, NULL, 16) / 255.0;
palette->color_array[color_idx].blue =
(double)g_ascii_strtoll(match, NULL, 16) / 255.0;
g_free(match);
/* Only RGB supported so far. Fix alpha channel to 1.0 */
@ -233,8 +236,7 @@ static void color_palette_dispose(GObject *gobj)
ColorPalette *palette;
palette = GDS_RENDER_COLOR_PALETTE(gobj);
if (palette->color_array)
{
if (palette->color_array) {
palette->color_array_length = 0;
free(palette->color_array);
}

View File

@ -54,7 +54,8 @@ struct _LayerSelector {
G_DEFINE_TYPE(LayerSelector, layer_selector, G_TYPE_OBJECT)
/* Drag and drop code
/*
* Drag and drop code
* Original code from https://blog.gtk.org/2017/06/01/drag-and-drop-in-lists-revisited/
*/
@ -119,10 +120,10 @@ static GtkListBoxRow *layer_selector_get_last_row (GtkListBox *list)
{
int i;
GtkListBoxRow *row;
GtkListBoxRow *tmp;
row = NULL;
for (i = 0; ; i++) {
GtkListBoxRow *tmp;
tmp = gtk_list_box_get_row_at_index(list, i);
if (tmp == NULL)
break;
@ -348,7 +349,8 @@ static void layer_selector_class_init(LayerSelectorClass *klass)
static void layer_selector_setup_dnd(LayerSelector *self)
{
gtk_drag_dest_set(GTK_WIDGET(self->list_box), GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP, &self->dnd_target, 1, GDK_ACTION_MOVE);
gtk_drag_dest_set(GTK_WIDGET(self->list_box), GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP,
&self->dnd_target, 1, GDK_ACTION_MOVE);
g_signal_connect(self->list_box, "drag-data-received", G_CALLBACK(layer_selector_drag_data_received), NULL);
g_signal_connect(self->list_box, "drag-motion", G_CALLBACK(layer_selector_drag_motion), NULL);
g_signal_connect(self->list_box, "drag-leave", G_CALLBACK(layer_selector_drag_leave), NULL);
@ -424,9 +426,9 @@ static void layer_selector_clear_widgets(LayerSelector *self)
GList *temp;
list = gtk_container_get_children(GTK_CONTAINER(self->list_box));
for (temp = list; temp != NULL; temp = temp->next) {
for (temp = list; temp != NULL; temp = temp->next)
gtk_container_remove(GTK_CONTAINER(self->list_box), GTK_WIDGET(temp->data));
}
/* Widgets are already destroyed when removed from box because they are only referenced inside the container */
g_list_free(list);
@ -444,7 +446,8 @@ static void layer_selector_clear_widgets(LayerSelector *self)
* @param layer Layer number to check for
* @return TRUE if layer is present, else FALSE
*/
static gboolean layer_selector_check_if_layer_widget_exists(LayerSelector *self, int layer) {
static gboolean layer_selector_check_if_layer_widget_exists(LayerSelector *self, int layer)
{
GList *list;
GList *temp;
LayerElement *widget;
@ -552,9 +555,8 @@ void layer_selector_generate_layer_widgets(LayerSelector *selector, GList *libs)
for (; libs != NULL; libs = libs->next) {
lib = (struct gds_library *)libs->data;
for (cell_list = lib->cells; cell_list != NULL; cell_list = cell_list->next) {
for (cell_list = lib->cells; cell_list != NULL; cell_list = cell_list->next)
layer_selector_analyze_cell_layers(selector, (struct gds_cell *)cell_list->data);
} /* For Cell List */
} /* For libs */
/* Sort the layers */
@ -690,7 +692,8 @@ static void layer_selector_load_mapping_clicked(GtkWidget *button, gpointer user
sel = LAYER_SELECTOR(user_data);
dialog = gtk_file_chooser_dialog_new("Load Mapping File", GTK_WINDOW(sel->load_parent_window), GTK_FILE_CHOOSER_ACTION_OPEN,
dialog = gtk_file_chooser_dialog_new("Load Mapping File", GTK_WINDOW(sel->load_parent_window),
GTK_FILE_CHOOSER_ACTION_OPEN,
"Cancel", GTK_RESPONSE_CANCEL, "Load Mapping", GTK_RESPONSE_ACCEPT, NULL);
res = gtk_dialog_run(GTK_DIALOG(dialog));
if (res == GTK_RESPONSE_ACCEPT) {
@ -735,7 +738,8 @@ static void layer_selector_save_mapping_clicked(GtkWidget *button, gpointer user
sel = LAYER_SELECTOR(user_data);
dialog = gtk_file_chooser_dialog_new("Save Mapping File", GTK_WINDOW(sel->save_parent_window), GTK_FILE_CHOOSER_ACTION_SAVE,
dialog = gtk_file_chooser_dialog_new("Save Mapping File", GTK_WINDOW(sel->save_parent_window),
GTK_FILE_CHOOSER_ACTION_SAVE,
"Cancel", GTK_RESPONSE_CANCEL, "Save Mapping", GTK_RESPONSE_ACCEPT, NULL);
gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);
@ -802,10 +806,9 @@ void layer_selector_select_all_layers(LayerSelector *layer_selector, gboolean se
for (iter = le_list; iter != NULL; iter = g_list_next(iter)) {
le = LAYER_ELEMENT(iter->data);
if (LAYER_IS_ELEMENT(le)) {
if (LAYER_IS_ELEMENT(le))
layer_element_set_export(le, select);
}
}
g_list_free(le_list);
}

View File

@ -121,7 +121,8 @@ static void render_cell(struct gds_cell *cell, struct cairo_layer *layers, doubl
/* Render child cells */
for (instance_list = cell->child_cells; instance_list != NULL; instance_list = instance_list->next) {
cell_instance = (struct gds_cell_instance *)instance_list->data;
if ((temp_cell = cell_instance->cell_ref) != NULL) {
temp_cell = cell_instance->cell_ref;
if (temp_cell != NULL) {
apply_inherited_transform_to_all_layers(layers,
&cell_instance->origin,
cell_instance->magnification,
@ -228,8 +229,12 @@ static int read_line_from_fd(int fd, char *buff, size_t buff_size)
* @param scale Scale the output image down by \p scale
* @return Error
*/
static int cairo_renderer_render_cell_to_vector_file(GdsOutputRenderer *renderer, struct gds_cell *cell, GList *layer_infos, const char *pdf_file,
const char *svg_file, double scale)
static int cairo_renderer_render_cell_to_vector_file(GdsOutputRenderer *renderer,
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;

View File

@ -79,7 +79,8 @@ static int external_renderer_render_cell(struct gds_cell *toplevel_cell, GList *
}
/* Load symbol from library */
so_render_func = (int (*)(struct gds_cell *, GList *, const char *, double))dlsym(so_handle, EXTERNAL_LIBRARY_FUNCTION);
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);

View File

@ -213,8 +213,6 @@ void gds_output_renderer_init(GdsOutputRenderer *self)
priv->idle_function_parameters.status_message = NULL;
g_mutex_init(&priv->settings_lock);
g_mutex_init(&priv->idle_function_parameters.message_lock);
return;
}
GdsOutputRenderer *gds_output_renderer_new()

View File

@ -140,7 +140,8 @@ static gboolean write_layer_env(FILE *tex_file, GdkRGBA *color, int layer, GList
color->red = inf->color.red;
color->green = inf->color.green;
color->blue = inf->color.blue;
g_string_printf(buffer, "\\begin{pgfonlayer}{l%d}\n\\ifcreatepdflayers\n\\begin{scope}[ocg={ref=%d, status=visible,name={%s}}]\n\\fi\n",
g_string_printf(buffer,
"\\begin{pgfonlayer}{l%d}\n\\ifcreatepdflayers\n\\begin{scope}[ocg={ref=%d, status=visible,name={%s}}]\n\\fi\n",
layer, layer, inf->name);
WRITEOUT_BUFFER(buffer);
return TRUE;
@ -167,7 +168,7 @@ static void generate_graphics(FILE *tex_file, GList *graphics, GList *linfo, GSt
struct gds_graphics *gfx;
struct gds_point *pt;
GdkRGBA color;
static const char *line_caps[] = {"butt", "round", "rect"};
static const char * const line_caps[] = {"butt", "round", "rect"};
for (temp = graphics; temp != NULL; temp = temp->next) {
gfx = (struct gds_graphics *)temp->data;
@ -175,13 +176,18 @@ static void generate_graphics(FILE *tex_file, GList *graphics, GList *linfo, GSt
/* Layer is defined => create graphics */
if (gfx->gfx_type == GRAPHIC_POLYGON || gfx->gfx_type == GRAPHIC_BOX) {
g_string_printf(buffer, "\\draw[line width=0.00001 pt, draw={c%d}, fill={c%d}, fill opacity={%lf}] ",
g_string_printf(buffer,
"\\draw[line width=0.00001 pt, draw={c%d}, fill={c%d}, fill opacity={%lf}] ",
gfx->layer, gfx->layer, color.alpha);
WRITEOUT_BUFFER(buffer);
/* Append vertices */
for (temp_vertex = gfx->vertices; temp_vertex != NULL; temp_vertex = temp_vertex->next) {
for (temp_vertex = gfx->vertices;
temp_vertex != NULL;
temp_vertex = temp_vertex->next) {
pt = (struct gds_point *)temp_vertex->data;
g_string_printf(buffer, "(%lf pt, %lf pt) -- ", ((double)pt->x)/scale, ((double)pt->y)/scale);
g_string_printf(buffer, "(%lf pt, %lf pt) -- ",
((double)pt->x)/scale,
((double)pt->y)/scale);
WRITEOUT_BUFFER(buffer);
}
g_string_printf(buffer, "cycle;\n");
@ -204,7 +210,9 @@ static void generate_graphics(FILE *tex_file, GList *graphics, GList *linfo, GSt
WRITEOUT_BUFFER(buffer);
/* Append vertices */
for (temp_vertex = gfx->vertices; temp_vertex != NULL; temp_vertex = temp_vertex->next) {
for (temp_vertex = gfx->vertices;
temp_vertex != NULL;
temp_vertex = temp_vertex->next) {
pt = (struct gds_point *)temp_vertex->data;
g_string_printf(buffer, "(%lf pt, %lf pt)%s",
((double)pt->x)/scale,
@ -263,7 +271,8 @@ static void render_cell(struct gds_cell *cell, GList *layer_infos, FILE *tex_fil
g_string_printf(buffer, "\\begin{scope}[rotate=%lf]\n", inst->angle);
WRITEOUT_BUFFER(buffer);
g_string_printf(buffer, "\\begin{scope}[yscale=%lf, xscale=%lf]\n", (inst->flipped ? -1*inst->magnification : inst->magnification),
g_string_printf(buffer, "\\begin{scope}[yscale=%lf, xscale=%lf]\n",
(inst->flipped ? -1*inst->magnification : inst->magnification),
inst->magnification);
WRITEOUT_BUFFER(buffer);
@ -302,7 +311,8 @@ static int latex_render_cell_to_code(struct gds_cell *cell, GList *layer_infos,
WRITEOUT_BUFFER(working_line);
g_string_printf(working_line, "\\iftestmode\n");
WRITEOUT_BUFFER(working_line);
g_string_printf(working_line, "\\documentclass[tikz]{standalone}\n\\usepackage{xcolor}\n\\usetikzlibrary{ocgx}\n\\begin{document}\n");
g_string_printf(working_line,
"\\documentclass[tikz]{standalone}\n\\usepackage{xcolor}\n\\usetikzlibrary{ocgx}\n\\begin{document}\n");
WRITEOUT_BUFFER(working_line);
g_string_printf(working_line, "\\fi\n");
WRITEOUT_BUFFER(working_line);
@ -361,9 +371,8 @@ static int latex_renderer_render_output(GdsOutputRenderer *renderer,
g_error("Could not open LaTeX output file");
}
if (settings) {
if (settings)
g_object_unref(settings);
}
return ret;
}