From: Jim Evins Date: Sat, 10 Jul 2010 05:38:48 +0000 (-0400) Subject: Improved centering of barcode text. X-Git-Tag: glabels-2_3_1~213^2~7 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=b012b9c74def1a87e21e678486eeb4debeaf23be;p=glabels Improved centering of barcode text. Don't try to calculate x offset using hardcoded fixed character width, which does not work properly for proportional fonts. Use the origin provided by zint (wich is at the horizontal center) and use pango to calculate the offset at render time. --- diff --git a/src/bc-zint.c b/src/bc-zint.c index fb02b514..ca83f619 100644 --- a/src/bc-zint.c +++ b/src/bc-zint.c @@ -213,7 +213,7 @@ static glBarcode *render_zint(struct zint_symbol *symbol, gboolean text_flag) for ( zstring = render->strings; zstring != NULL; zstring = zstring->next ) { bstring = gl_barcode_shape_string_new(); - bstring->x = (double) zstring->x - (((6.0 / 9.0) * zstring->length * zstring->fsize) / 2); + bstring->x = (double) zstring->x; bstring->y = (double) zstring->y; bstring->fsize = (double) zstring->fsize; bstring->str = g_strndup (zstring->text, zstring->length); diff --git a/src/bc.h b/src/bc.h index 5a0374f0..6c7cbcb5 100644 --- a/src/bc.h +++ b/src/bc.h @@ -151,7 +151,8 @@ typedef struct { * / / \ \ | |_) | | (__ | * /__/ \__\ |_.___/ \____| | * v - * @ -------------------------------------- + * @ ------------------ + * x = horizontal center */ typedef struct { diff --git a/src/label-barcode.c b/src/label-barcode.c index 6f538189..7f3cf8f3 100644 --- a/src/label-barcode.c +++ b/src/label-barcode.c @@ -428,7 +428,7 @@ draw_object (glLabelObject *object, glBarcodeShapeAlpha *bchar; glBarcodeShapeString *bstring; GList *p; - gdouble y_offset; + gdouble x_offset, y_offset; PangoLayout *layout; PangoFontDescription *desc; gchar *text, *cstring; @@ -440,6 +440,8 @@ draw_object (glLabelObject *object, glColorNode *color_node; guint format_digits; gdouble w, h; + gint iw, ih; + gdouble layout_width; gl_debug (DEBUG_LABEL, "START"); @@ -556,9 +558,13 @@ draw_object (glLabelObject *object, pango_layout_set_text (layout, bstring->str, -1); + pango_layout_get_size (layout, &iw, &ih); + layout_width = (gdouble)iw / (gdouble)PANGO_SCALE; + + x_offset = layout_width / 2.0; y_offset = 0.2 * bstring->fsize; - cairo_move_to (cr, bstring->x, bstring->y-y_offset); + cairo_move_to (cr, (bstring->x - x_offset), (bstring->y - y_offset)); pango_cairo_show_layout (cr, layout); g_object_unref (layout);