diff options
Diffstat (limited to 'src/glibext/tokenstyle.c')
-rw-r--r-- | src/glibext/tokenstyle.c | 142 |
1 files changed, 113 insertions, 29 deletions
diff --git a/src/glibext/tokenstyle.c b/src/glibext/tokenstyle.c index e797856..df1d42a 100644 --- a/src/glibext/tokenstyle.c +++ b/src/glibext/tokenstyle.c @@ -25,6 +25,7 @@ #include "tokenstyle.h" +#include <math.h> #include <string.h> @@ -60,34 +61,35 @@ static void g_token_style_finalize(GTokenStyle *); static const char *_token_names[TRT_COUNT] = { - [TRT_NONE] = SEGMENT_NAME("none"), - [TRT_RAW] = SEGMENT_NAME("raw"), - [TRT_RAW_FULL] = SEGMENT_NAME("raw-full"), - [TRT_RAW_NULL] = SEGMENT_NAME("raw-null"), - [TRT_PRINTABLE] = SEGMENT_NAME("printable"), - [TRT_NOT_PRINTABLE] = SEGMENT_NAME("not-printable"), - [TRT_COMMENT] = SEGMENT_NAME("comment"), - [TRT_INDICATION] = SEGMENT_NAME("indication"), - [TRT_PHYS_ADDR_PAD] = SEGMENT_NAME("phys-addr-padding"), - [TRT_PHYS_ADDR] = SEGMENT_NAME("phys-addr"), - [TRT_VIRT_ADDR_PAD] = SEGMENT_NAME("virt-addr-padding"), - [TRT_VIRT_ADDR] = SEGMENT_NAME("virt-addr"), - [TRT_RAW_CODE] = SEGMENT_NAME("raw-code"), - [TRT_RAW_CODE_NULL] = SEGMENT_NAME("raw-code-null"), - [TRT_LABEL] = SEGMENT_NAME("label"), - [TRT_INSTRUCTION] = SEGMENT_NAME("instruction"), - [TRT_IMMEDIATE] = SEGMENT_NAME("immediate"), - [TRT_REGISTER] = SEGMENT_NAME("register"), - [TRT_PUNCT] = SEGMENT_NAME("punct"), - [TRT_HOOK] = SEGMENT_NAME("hooks"), - [TRT_SIGNS] = SEGMENT_NAME("signs"), - [TRT_LTGT] = SEGMENT_NAME("ltgt"), - [TRT_SECTION] = SEGMENT_NAME("section"), - [TRT_SEGMENT] = SEGMENT_NAME("segment"), - [TRT_STRING] = SEGMENT_NAME("string"), - [TRT_VAR_NAME] = SEGMENT_NAME("var-name"), - [TRT_KEY_WORD] = SEGMENT_NAME("keyword"), - [TRT_ERROR] = SEGMENT_NAME("error"), + [TRT_NONE] = SEGMENT_NAME("none"), + [TRT_RAW_PRINTABLE] = SEGMENT_NAME("raw-printable"), + [TRT_RAW_NOT_PRINTABLE] = SEGMENT_NAME("raw-not-printable"), + [TRT_RAW_FULL] = SEGMENT_NAME("raw-full"), + [TRT_RAW_NULL] = SEGMENT_NAME("raw-null"), + [TRT_CHR_PRINTABLE] = SEGMENT_NAME("chr-printable"), + [TRT_CHR_NOT_PRINTABLE] = SEGMENT_NAME("chr-not-printable"), + [TRT_COMMENT] = SEGMENT_NAME("comment"), + [TRT_INDICATION] = SEGMENT_NAME("indication"), + [TRT_PHYS_ADDR_PAD] = SEGMENT_NAME("phys-addr-padding"), + [TRT_PHYS_ADDR] = SEGMENT_NAME("phys-addr"), + [TRT_VIRT_ADDR_PAD] = SEGMENT_NAME("virt-addr-padding"), + [TRT_VIRT_ADDR] = SEGMENT_NAME("virt-addr"), + [TRT_RAW_CODE] = SEGMENT_NAME("raw-code"), + [TRT_RAW_CODE_NULL] = SEGMENT_NAME("raw-code-null"), + [TRT_LABEL] = SEGMENT_NAME("label"), + [TRT_INSTRUCTION] = SEGMENT_NAME("instruction"), + [TRT_IMMEDIATE] = SEGMENT_NAME("immediate"), + [TRT_REGISTER] = SEGMENT_NAME("register"), + [TRT_PUNCT] = SEGMENT_NAME("punct"), + [TRT_HOOK] = SEGMENT_NAME("hooks"), + [TRT_SIGNS] = SEGMENT_NAME("signs"), + [TRT_LTGT] = SEGMENT_NAME("ltgt"), + [TRT_SECTION] = SEGMENT_NAME("section"), + [TRT_SEGMENT] = SEGMENT_NAME("segment"), + [TRT_STRING] = SEGMENT_NAME("string"), + [TRT_VAR_NAME] = SEGMENT_NAME("var-name"), + [TRT_KEY_WORD] = SEGMENT_NAME("keyword"), + [TRT_ERROR] = SEGMENT_NAME("error"), }; @@ -272,12 +274,35 @@ bool g_token_style_create(GTokenStyle *style, GtkWidget *target) /****************************************************************************** * * * Paramètres : style = gestionnaire de paramètres de rendu à consulter. * +* * +* Description : Fournit la quantité de pixels requise pour une ligne. * +* * +* Retour : Hauteur de chaque ligne de rendu, en pixels. * +* * +* Remarques : - * +* * +******************************************************************************/ + +int g_token_style_get_line_height(const GTokenStyle *style) +{ + int result; /* Hauteur à retourner */ + + result = style->font_extents.height; + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : style = gestionnaire de paramètres de rendu à consulter. * * tag = type de rendu sollicité. * * length = nombre de caractères à mesurer. * * * * Description : Fournit la quantité de pixels requise pour l'impression. * * * -* Retour : Largeur requise par la colonne, en pixel. * +* Retour : Largeur requise par la colonne, en pixels. * * * * Remarques : - * * * @@ -325,6 +350,13 @@ void g_token_style_draw_text(const GTokenStyle *style, TokenRenderingTag tag, ca cairo_operator_t old; /* Sauvegarde avant changement */ const rendering_property_t *prop; /* Motif de rendu visé */ + /* Cas particulier d'une tabulation */ + if (length == 1 && (text[0] == '\t' || text[0] == ' ')) + { + width = g_token_style_measure_width(style, tag, text[0] == '\t' ? TAB_SIZE : 1); + goto small_sep; + } + selected = false;//selection_list_has_segment_content(list, segment); width = g_token_style_measure_width(style, tag, length); @@ -378,6 +410,8 @@ void g_token_style_draw_text(const GTokenStyle *style, TokenRenderingTag tag, ca cairo_show_text(cr, text); + small_sep: + *x += width; } @@ -467,6 +501,56 @@ char *g_token_style_append_markup(const GTokenStyle *style, char *base, TokenRen } +/****************************************************************************** +* * +* Paramètres : style = gestionnaire de paramètres de rendu à consulter. * +* max = valeur maximale atteignable. * +* virt = indique une position virtuelle et non physique. * +* * +* Description : Détermine une taille de localisation, physique ou virtuelle. * +* * +* Retour : Largeur minimale à observer en pixels. * +* * +* Remarques : - * +* * +******************************************************************************/ + +int g_token_style_compute_location_width(const GTokenStyle *style, uint64_t max, bool virt) +{ + int result; /* Taille à retourner */ + double n; /* Nombre de chiffres hexa */ + double c; /* Valeur ajustée */ + TokenRenderingTag tag; /* Type de représentation */ + + /** + * Les situations suivantes ont été évaluées : + * + * max | n | c + * ----------------------------------- + * 0 | 0 | 0 + * 1 | 0,25 | 1 + * f | 1 | 1 + * 10 | 1,02187 | 2 + * 11 | 1,04248 | 2 + * ff | 2 | 2 + * 100 | 2,00141 | 3 + * ffffffff | 8 | 8 + * ffffffffffffffff | 16 | 16 + */ + + n = log1p(max) / log(16); + + c = ceil(n); + + tag = virt ? TRT_VIRT_ADDR : TRT_PHYS_ADDR; + + result = g_token_style_measure_width(style, tag, c); + + return result; + +} + + /* ---------------------------------------------------------------------------------- */ /* RECEPTACLES DE SIGNAUX CONNECTES */ |