diff options
author | Jim Evins <evins@snaught.com> | 2010-07-10 01:38:48 -0400 |
---|---|---|
committer | Jim Evins <evins@snaught.com> | 2010-07-10 01:38:48 -0400 |
commit | b012b9c74def1a87e21e678486eeb4debeaf23be (patch) | |
tree | 87b43c603e323e694389f7af2af9c36d2c00038e | |
parent | 61aa9b8dce8e6143eba39b368897a5f1a39a8e29 (diff) |
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.
-rw-r--r-- | src/bc-zint.c | 2 | ||||
-rw-r--r-- | src/bc.h | 3 | ||||
-rw-r--r-- | src/label-barcode.c | 10 |
3 files changed, 11 insertions, 4 deletions
diff --git a/src/bc-zint.c b/src/bc-zint.c index fb02b51..ca83f61 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); @@ -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 6f53818..7f3cf8f 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); |