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); g_regex_match(regex, line, 0, &mi);
if (g_match_info_matches(mi) && color_idx < lines) { if (g_match_info_matches(mi) && color_idx < lines) {
match = g_match_info_fetch_named(mi, "red"); 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); g_free(match);
match = g_match_info_fetch_named(mi, "green"); 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); g_free(match);
match = g_match_info_fetch_named(mi, "blue"); 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); g_free(match);
/* Only RGB supported so far. Fix alpha channel to 1.0 */ /* Only RGB supported so far. Fix alpha channel to 1.0 */
@ -233,8 +236,7 @@ static void color_palette_dispose(GObject *gobj)
ColorPalette *palette; ColorPalette *palette;
palette = GDS_RENDER_COLOR_PALETTE(gobj); palette = GDS_RENDER_COLOR_PALETTE(gobj);
if (palette->color_array) if (palette->color_array) {
{
palette->color_array_length = 0; palette->color_array_length = 0;
free(palette->color_array); free(palette->color_array);
} }

View File

@ -54,7 +54,8 @@ struct _LayerSelector {
G_DEFINE_TYPE(LayerSelector, layer_selector, G_TYPE_OBJECT) 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/ * Original code from https://blog.gtk.org/2017/06/01/drag-and-drop-in-lists-revisited/
*/ */
@ -72,16 +73,16 @@ static void sel_layer_element_drag_begin(GtkWidget *widget, GdkDragContext *cont
surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, alloc.width, alloc.height); surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, alloc.width, alloc.height);
cr = cairo_create(surface); cr = cairo_create(surface);
gtk_style_context_add_class (gtk_widget_get_style_context(row), "drag-icon"); gtk_style_context_add_class(gtk_widget_get_style_context(row), "drag-icon");
gtk_widget_draw (row, cr); gtk_widget_draw(row, cr);
gtk_style_context_remove_class(gtk_widget_get_style_context(row), "drag-icon"); gtk_style_context_remove_class(gtk_widget_get_style_context(row), "drag-icon");
gtk_widget_translate_coordinates (widget, row, 0, 0, &x, &y); gtk_widget_translate_coordinates(widget, row, 0, 0, &x, &y);
cairo_surface_set_device_offset (surface, -x, -y); cairo_surface_set_device_offset(surface, -x, -y);
gtk_drag_set_icon_surface (context, surface); gtk_drag_set_icon_surface(context, surface);
cairo_destroy (cr); cairo_destroy(cr);
cairo_surface_destroy (surface); cairo_surface_destroy(surface);
g_object_set_data(G_OBJECT(gtk_widget_get_parent(row)), "drag-row", row); g_object_set_data(G_OBJECT(gtk_widget_get_parent(row)), "drag-row", row);
gtk_style_context_add_class(gtk_widget_get_style_context(row), "drag-row"); gtk_style_context_add_class(gtk_widget_get_style_context(row), "drag-row");
@ -115,14 +116,14 @@ static void sel_layer_element_drag_data_get(GtkWidget *widget, GdkDragContext *c
32, (const guchar *)&widget, sizeof(gpointer)); 32, (const guchar *)&widget, sizeof(gpointer));
} }
static GtkListBoxRow *layer_selector_get_last_row (GtkListBox *list) static GtkListBoxRow *layer_selector_get_last_row(GtkListBox *list)
{ {
int i; int i;
GtkListBoxRow *row; GtkListBoxRow *row;
GtkListBoxRow *tmp;
row = NULL; row = NULL;
for (i = 0; ; i++) { for (i = 0; ; i++) {
GtkListBoxRow *tmp;
tmp = gtk_list_box_get_row_at_index(list, i); tmp = gtk_list_box_get_row_at_index(list, i);
if (tmp == NULL) if (tmp == NULL)
break; break;
@ -132,15 +133,15 @@ static GtkListBoxRow *layer_selector_get_last_row (GtkListBox *list)
return row; return row;
} }
static GtkListBoxRow *layer_selector_get_row_before (GtkListBox *list, GtkListBoxRow *row) static GtkListBoxRow *layer_selector_get_row_before(GtkListBox *list, GtkListBoxRow *row)
{ {
int pos; int pos;
pos = gtk_list_box_row_get_index (row); pos = gtk_list_box_row_get_index(row);
return gtk_list_box_get_row_at_index (list, pos - 1); return gtk_list_box_get_row_at_index(list, pos - 1);
} }
static GtkListBoxRow *layer_selector_get_row_after (GtkListBox *list, GtkListBoxRow *row) static GtkListBoxRow *layer_selector_get_row_after(GtkListBox *list, GtkListBoxRow *row)
{ {
int pos; int pos;
@ -348,7 +349,8 @@ static void layer_selector_class_init(LayerSelectorClass *klass)
static void layer_selector_setup_dnd(LayerSelector *self) 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-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-motion", G_CALLBACK(layer_selector_drag_motion), NULL);
g_signal_connect(self->list_box, "drag-leave", G_CALLBACK(layer_selector_drag_leave), NULL); g_signal_connect(self->list_box, "drag-leave", G_CALLBACK(layer_selector_drag_leave), NULL);
@ -398,11 +400,11 @@ LayerSettings *layer_selector_export_rendered_layer_info(LayerSelector *selector
row_list = gtk_container_get_children(GTK_CONTAINER(selector->list_box)); row_list = gtk_container_get_children(GTK_CONTAINER(selector->list_box));
for (i = 0,iterator = row_list; iterator != NULL; iterator = g_list_next(iterator), i++) { for (i = 0, iterator = row_list; iterator != NULL; iterator = g_list_next(iterator), i++) {
le = LAYER_ELEMENT(iterator->data); le = LAYER_ELEMENT(iterator->data);
/* Get name from layer element. This must not be freed */ /* Get name from layer element. This must not be freed */
linfo.name =(char *)layer_element_get_name(le); linfo.name = (char *)layer_element_get_name(le);
layer_element_get_color(le, &linfo.color); layer_element_get_color(le, &linfo.color);
linfo.render = (layer_element_get_export(le) ? 1 : 0); linfo.render = (layer_element_get_export(le) ? 1 : 0);
@ -424,9 +426,9 @@ static void layer_selector_clear_widgets(LayerSelector *self)
GList *temp; GList *temp;
list = gtk_container_get_children(GTK_CONTAINER(self->list_box)); 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)); 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 */ /* Widgets are already destroyed when removed from box because they are only referenced inside the container */
g_list_free(list); g_list_free(list);
@ -444,7 +446,8 @@ static void layer_selector_clear_widgets(LayerSelector *self)
* @param layer Layer number to check for * @param layer Layer number to check for
* @return TRUE if layer is present, else FALSE * @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 *list;
GList *temp; GList *temp;
LayerElement *widget; LayerElement *widget;
@ -552,9 +555,8 @@ void layer_selector_generate_layer_widgets(LayerSelector *selector, GList *libs)
for (; libs != NULL; libs = libs->next) { for (; libs != NULL; libs = libs->next) {
lib = (struct gds_library *)libs->data; 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); layer_selector_analyze_cell_layers(selector, (struct gds_cell *)cell_list->data);
} /* For Cell List */
} /* For libs */ } /* For libs */
/* Sort the layers */ /* Sort the layers */
@ -690,7 +692,8 @@ static void layer_selector_load_mapping_clicked(GtkWidget *button, gpointer user
sel = LAYER_SELECTOR(user_data); 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); "Cancel", GTK_RESPONSE_CANCEL, "Load Mapping", GTK_RESPONSE_ACCEPT, NULL);
res = gtk_dialog_run(GTK_DIALOG(dialog)); res = gtk_dialog_run(GTK_DIALOG(dialog));
if (res == GTK_RESPONSE_ACCEPT) { 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); 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); "Cancel", GTK_RESPONSE_CANCEL, "Save Mapping", GTK_RESPONSE_ACCEPT, NULL);
gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE); 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)) { for (iter = le_list; iter != NULL; iter = g_list_next(iter)) {
le = LAYER_ELEMENT(iter->data); le = LAYER_ELEMENT(iter->data);
if (LAYER_IS_ELEMENT(le)) { if (LAYER_IS_ELEMENT(le))
layer_element_set_export(le, select); layer_element_set_export(le, select);
} }
}
g_list_free(le_list); 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 */ /* Render child cells */
for (instance_list = cell->child_cells; instance_list != NULL; instance_list = instance_list->next) { for (instance_list = cell->child_cells; instance_list != NULL; instance_list = instance_list->next) {
cell_instance = (struct gds_cell_instance *)instance_list->data; 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, apply_inherited_transform_to_all_layers(layers,
&cell_instance->origin, &cell_instance->origin,
cell_instance->magnification, 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 * @param scale Scale the output image down by \p scale
* @return Error * @return Error
*/ */
static int cairo_renderer_render_cell_to_vector_file(GdsOutputRenderer *renderer, struct gds_cell *cell, GList *layer_infos, const char *pdf_file, static int cairo_renderer_render_cell_to_vector_file(GdsOutputRenderer *renderer,
const char *svg_file, double scale) 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_surface_t *pdf_surface = NULL, *svg_surface = NULL;
cairo_t *pdf_cr = NULL, *svg_cr = NULL; cairo_t *pdf_cr = NULL, *svg_cr = NULL;
@ -393,7 +398,7 @@ static int cairo_renderer_render_cell_to_vector_file(GdsOutputRenderer *renderer
ret_clear_layers: ret_clear_layers:
for (i = 0; i < MAX_LAYERS; i++) { for (i = 0; i < MAX_LAYERS; i++) {
lay = &layers[i]; lay = &layers[i];
if(lay->cr) { if (lay->cr) {
cairo_destroy(lay->cr); cairo_destroy(lay->cr);
cairo_surface_destroy(lay->rec); cairo_surface_destroy(lay->rec);
} }

View File

@ -79,7 +79,8 @@ static int external_renderer_render_cell(struct gds_cell *toplevel_cell, GList *
} }
/* Load symbol from library */ /* 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(); error_msg = dlerror();
if (error_msg != NULL) { if (error_msg != NULL) {
fprintf(stderr, "Rendering function not found in library:\n%s\n", error_msg); fprintf(stderr, "Rendering function not found in library:\n%s\n", error_msg);
@ -133,7 +134,7 @@ static void external_renderer_get_property(GObject *obj, guint property_id, GVal
g_value_set_string(value, self->shared_object_path); g_value_set_string(value, self->shared_object_path);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, property_id, pspec);
break; break;
} }
} }

View File

@ -213,8 +213,6 @@ void gds_output_renderer_init(GdsOutputRenderer *self)
priv->idle_function_parameters.status_message = NULL; priv->idle_function_parameters.status_message = NULL;
g_mutex_init(&priv->settings_lock); g_mutex_init(&priv->settings_lock);
g_mutex_init(&priv->idle_function_parameters.message_lock); g_mutex_init(&priv->idle_function_parameters.message_lock);
return;
} }
GdsOutputRenderer *gds_output_renderer_new() GdsOutputRenderer *gds_output_renderer_new()
@ -328,7 +326,7 @@ static void gds_output_renderer_async_wrapper(GTask *task,
ret = -1000; ret = -1000;
goto ret_from_task; goto ret_from_task;
} }
if(!priv->mutex_init_status) { if (!priv->mutex_init_status) {
ret = -1001; ret = -1001;
goto ret_from_task; goto ret_from_task;
} }

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->red = inf->color.red;
color->green = inf->color.green; color->green = inf->color.green;
color->blue = inf->color.blue; 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); layer, layer, inf->name);
WRITEOUT_BUFFER(buffer); WRITEOUT_BUFFER(buffer);
return TRUE; return TRUE;
@ -167,21 +168,26 @@ static void generate_graphics(FILE *tex_file, GList *graphics, GList *linfo, GSt
struct gds_graphics *gfx; struct gds_graphics *gfx;
struct gds_point *pt; struct gds_point *pt;
GdkRGBA color; 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) { for (temp = graphics; temp != NULL; temp = temp->next) {
gfx = (struct gds_graphics *)temp->data; gfx = (struct gds_graphics *)temp->data;
if (write_layer_env(tex_file, &color, (int)gfx->layer, linfo, buffer) == TRUE) { if (write_layer_env(tex_file, &color, (int)gfx->layer, linfo, buffer) == TRUE) {
/* Layer is defined => create graphics */ /* Layer is defined => create graphics */
if (gfx->gfx_type == GRAPHIC_POLYGON || gfx->gfx_type == GRAPHIC_BOX ) { 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); gfx->layer, gfx->layer, color.alpha);
WRITEOUT_BUFFER(buffer); WRITEOUT_BUFFER(buffer);
/* Append vertices */ /* 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; 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); WRITEOUT_BUFFER(buffer);
} }
g_string_printf(buffer, "cycle;\n"); 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); WRITEOUT_BUFFER(buffer);
/* Append vertices */ /* 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; pt = (struct gds_point *)temp_vertex->data;
g_string_printf(buffer, "(%lf pt, %lf pt)%s", g_string_printf(buffer, "(%lf pt, %lf pt)%s",
((double)pt->x)/scale, ((double)pt->x)/scale,
@ -257,13 +265,14 @@ static void render_cell(struct gds_cell *cell, GList *layer_infos, FILE *tex_fil
/* generate translation scope */ /* generate translation scope */
g_string_printf(buffer, "\\begin{scope}[shift={(%lf pt,%lf pt)}]\n", g_string_printf(buffer, "\\begin{scope}[shift={(%lf pt,%lf pt)}]\n",
((double)inst->origin.x)/scale,((double)inst->origin.y)/scale); ((double)inst->origin.x) / scale, ((double)inst->origin.y) / scale);
WRITEOUT_BUFFER(buffer); WRITEOUT_BUFFER(buffer);
g_string_printf(buffer, "\\begin{scope}[rotate=%lf]\n", inst->angle); g_string_printf(buffer, "\\begin{scope}[rotate=%lf]\n", inst->angle);
WRITEOUT_BUFFER(buffer); 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); inst->magnification);
WRITEOUT_BUFFER(buffer); 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); WRITEOUT_BUFFER(working_line);
g_string_printf(working_line, "\\iftestmode\n"); g_string_printf(working_line, "\\iftestmode\n");
WRITEOUT_BUFFER(working_line); 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); WRITEOUT_BUFFER(working_line);
g_string_printf(working_line, "\\fi\n"); g_string_printf(working_line, "\\fi\n");
WRITEOUT_BUFFER(working_line); WRITEOUT_BUFFER(working_line);
@ -361,9 +371,8 @@ static int latex_renderer_render_output(GdsOutputRenderer *renderer,
g_error("Could not open LaTeX output file"); g_error("Could not open LaTeX output file");
} }
if (settings) { if (settings)
g_object_unref(settings); g_object_unref(settings);
}
return ret; return ret;
} }