diff options
Diffstat (limited to 'src/glibext')
-rw-r--r-- | src/glibext/Makefile.am | 6 | ||||
-rw-r--r-- | src/glibext/_signal.h (renamed from src/glibext/signal.h) | 0 | ||||
-rw-r--r-- | src/glibext/displayoptions.c (renamed from src/glibext/gdisplayoptions.c) | 0 | ||||
-rw-r--r-- | src/glibext/displayoptions.h (renamed from src/glibext/gdisplayoptions.h) | 0 | ||||
-rw-r--r-- | src/glibext/linetoken.c (renamed from src/glibext/linesegment.c) | 0 | ||||
-rw-r--r-- | src/glibext/linetoken.h (renamed from src/glibext/linesegment.h) | 0 | ||||
-rw-r--r-- | src/glibext/tokenstyle.c | 205 | ||||
-rw-r--r-- | src/glibext/tokenstyle.h | 65 |
8 files changed, 273 insertions, 3 deletions
diff --git a/src/glibext/Makefile.am b/src/glibext/Makefile.am index 860f3b9..ac8668c 100644 --- a/src/glibext/Makefile.am +++ b/src/glibext/Makefile.am @@ -17,7 +17,7 @@ libglibext_la_SOURCES = \ gbinarycursor.h gbinarycursor.c \ gbinportion-int.h \ gbinportion.h gbinportion.c \ - gdisplayoptions.h gdisplayoptions.c \ + displayoptions.h displayoptions.c \ glinecursor-int.h \ glinecursor.h glinecursor.c \ gnhash.h gnhash.c \ @@ -28,9 +28,9 @@ libglibext_la_SOURCES = \ objhole.h \ proto.h \ seq.h seq.c \ - signal.h signal.c \ + _signal.h signal.c \ singleton.h singleton.c \ - linesegment.h linesegment.c \ + linetoken.h linetoken.c \ umemslice-int.h \ umemslice.h umemslice.c diff --git a/src/glibext/signal.h b/src/glibext/_signal.h index 4f0ab4b..4f0ab4b 100644 --- a/src/glibext/signal.h +++ b/src/glibext/_signal.h diff --git a/src/glibext/gdisplayoptions.c b/src/glibext/displayoptions.c index a8f835b..a8f835b 100644 --- a/src/glibext/gdisplayoptions.c +++ b/src/glibext/displayoptions.c diff --git a/src/glibext/gdisplayoptions.h b/src/glibext/displayoptions.h index 1a30e81..1a30e81 100644 --- a/src/glibext/gdisplayoptions.h +++ b/src/glibext/displayoptions.h diff --git a/src/glibext/linesegment.c b/src/glibext/linetoken.c index 192e030..192e030 100644 --- a/src/glibext/linesegment.c +++ b/src/glibext/linetoken.c diff --git a/src/glibext/linesegment.h b/src/glibext/linetoken.h index 4859fbb..4859fbb 100644 --- a/src/glibext/linesegment.h +++ b/src/glibext/linetoken.h diff --git a/src/glibext/tokenstyle.c b/src/glibext/tokenstyle.c new file mode 100644 index 0000000..8badf21 --- /dev/null +++ b/src/glibext/tokenstyle.c @@ -0,0 +1,205 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * rendering.h - prototypes pour la transformation de paramètres du thème GTK courant + * + * Copyright (C) 2018 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include "rendering.h" + + +#include <malloc.h> +#include <stdio.h> +#include <string.h> +#include <gtk/gtk.h> + + +#include "../common/extstr.h" + + + +/****************************************************************************** +* * +* Paramètres : name = désignation d'un élément dans une feuille de style.* +* pattern = paramètres restitués en interne. |OUT] * +* * +* Description : Récupère les informations de rendus d'un élément de thème. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void load_rendering_pattern(const char *name, rendering_pattern_t *pattern) +{ + GtkStyleContext *context; /* Contexte pour les styles */ + GtkWidgetPath *path; /* Chemin d'accès aux thèmes */ + GdkRGBA *tmp_color; /* Description d'une couleur */ + PangoFontDescription *font_desc; /* Description d'une police */ + + /* Création d'un contexte d'accès */ + + path = gtk_widget_path_new(); + gtk_widget_path_append_type(path, G_TYPE_OBJECT); + + context = gtk_style_context_new(); + gtk_style_context_set_path(context, path); + gtk_style_context_set_screen(context, gdk_screen_get_default()); + + gtk_style_context_add_class(context, name); + + gtk_style_context_get(context, GTK_STATE_FLAG_NORMAL, GTK_STYLE_PROPERTY_COLOR, &tmp_color, NULL); + + pattern->foreground.has_color = true; + pattern->foreground.color = *tmp_color; + + pattern->inverted.has_color = true; + pattern->inverted.color.red = 1.0 - tmp_color->red; + pattern->inverted.color.green = 1.0 - tmp_color->green; + pattern->inverted.color.blue = 1.0 - tmp_color->blue; + pattern->inverted.color.alpha = tmp_color->alpha; + + gdk_rgba_free(tmp_color); + + gtk_style_context_get(context, GTK_STATE_FLAG_NORMAL, GTK_STYLE_PROPERTY_FONT, &font_desc, NULL); + + switch (pango_font_description_get_style(font_desc)) + { + case PANGO_STYLE_NORMAL: + pattern->slant = CAIRO_FONT_SLANT_NORMAL; + break; + case PANGO_STYLE_ITALIC: + pattern->slant = CAIRO_FONT_SLANT_ITALIC; + break; + case PANGO_STYLE_OBLIQUE: + pattern->slant = CAIRO_FONT_SLANT_OBLIQUE; + break; + } + + switch (pango_font_description_get_weight(font_desc)) + { + case PANGO_WEIGHT_THIN: + case PANGO_WEIGHT_ULTRALIGHT: + case PANGO_WEIGHT_LIGHT: + case PANGO_WEIGHT_SEMILIGHT: + case PANGO_WEIGHT_BOOK: + case PANGO_WEIGHT_NORMAL: + case PANGO_WEIGHT_MEDIUM: + pattern->weight = CAIRO_FONT_WEIGHT_NORMAL; + break; + case PANGO_WEIGHT_SEMIBOLD: + case PANGO_WEIGHT_BOLD: + case PANGO_WEIGHT_ULTRABOLD: + case PANGO_WEIGHT_HEAVY: + case PANGO_WEIGHT_ULTRAHEAVY: + pattern->weight = CAIRO_FONT_WEIGHT_BOLD; + break; + } + + pango_font_description_free(font_desc); + + gtk_widget_path_free(path); + g_object_unref(context); + +} + + +/****************************************************************************** +* * +* Paramètres : text = texte à encadrer par des balises Pango. * +* pattern = paramètres restitués en interne. * +* * +* Description : Enjolive du texte selon les paramètres d'un élément de thème.* +* * +* Retour : Chaîne de caractère à libérer après usage. * +* * +* Remarques : - * +* * +******************************************************************************/ + +char *build_pango_markup_for(const char *text, const rendering_pattern_t *pattern) +{ + char *result; /* Construction à retourner */ + char color[10]; /* Définition hexa de couleur */ + + result = strdup(text); + + if (pattern->foreground.has_color) + { + snprintf(color, sizeof(color), "#%02hhx%02hhx%02hhx%02hhx", + (unsigned char)(255 * pattern->foreground.color.red), + (unsigned char)(255 * pattern->foreground.color.green), + (unsigned char)(255 * pattern->foreground.color.blue), + (unsigned char)(255 * pattern->foreground.color.alpha)); + + result = strprep(result, "\">"); + result = strprep(result, color); + result = strprep(result, "<span color=\""); + + result = stradd(result, "</span>"); + + } + + if (pattern->slant == CAIRO_FONT_SLANT_ITALIC || pattern->slant == CAIRO_FONT_SLANT_OBLIQUE) + { + result = strprep(result, "<i>"); + result = stradd(result, "</i>"); + } + + if (pattern->weight == CAIRO_FONT_WEIGHT_BOLD) + { + result = strprep(result, "<b>"); + result = stradd(result, "</b>"); + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : base = base de texte à compléter. * +* text = texte à encadrer par des balises Pango. * +* pattern = paramètres restitués en interne. * +* * +* Description : Ajoute du texte enjolivé selon un élément de thème. * +* * +* Retour : Chaîne de caractère à libérer après usage. * +* * +* Remarques : - * +* * +******************************************************************************/ + +char *append_pango_markup_with(char *base, const char *text, const rendering_pattern_t *pattern) +{ + char *result; /* Construction à retourner */ + char *tmp; /* Stockage temporaire */ + + tmp = build_pango_markup_for(text, pattern); + + result = stradd(base, tmp); + + free(tmp); + + return result; + +} diff --git a/src/glibext/tokenstyle.h b/src/glibext/tokenstyle.h new file mode 100644 index 0000000..9adfe1a --- /dev/null +++ b/src/glibext/tokenstyle.h @@ -0,0 +1,65 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * rendering.h - prototypes pour la transformation de paramètres du thème GTK courant + * + * Copyright (C) 2018 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef _GTKEXT_RENDERING_H +#define _GTKEXT_RENDERING_H + + +#include <stdbool.h> +#include <gdk/gdk.h> + + + +/* Restitution d'une couleur */ +typedef struct _rendering_color_t +{ + GdkRGBA color; /* Couleur de rendu */ + bool has_color; /* Définition en place ? */ + +} rendering_color_t; + +/* Restitution d'un élément de thème */ +typedef struct _rendering_pattern_t +{ + rendering_color_t foreground; /* Couleur d'impression */ + rendering_color_t inverted; /* Couleur inversée pour sél. */ + + cairo_font_slant_t slant; /* Style d'impression */ + cairo_font_weight_t weight; /* Poids de la police */ + +} rendering_pattern_t; + + +/* Récupère les informations de rendus d'un élément de thème. */ +void load_rendering_pattern(const char *, rendering_pattern_t *); + +/* Enjolive du texte selon les paramètres d'un élément de thème. */ +char *build_pango_markup_for(const char *, const rendering_pattern_t *); + +/* Ajoute du texte enjolivé selon un élément de thème. */ +char *append_pango_markup_with(char *, const char *, const rendering_pattern_t *); + + + +#endif /* _GTKEXT_RENDERING_H */ |