]> git.sur5r.net Git - glabels/commitdiff
Improved centering of barcode text.
authorJim Evins <evins@snaught.com>
Sat, 10 Jul 2010 05:38:48 +0000 (01:38 -0400)
committerJim Evins <evins@snaught.com>
Sat, 10 Jul 2010 05:38:48 +0000 (01:38 -0400)
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.

src/bc-zint.c
src/bc.h
src/label-barcode.c

index fb02b51450f7ebbb170e561eb60007c97c8a49fa..ca83f619ae81aa7a30e69c107d035e5eb9dc67c3 100644 (file)
@@ -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);
index 5a0374f0ad1ce0db4ef85c930c72396572e4ec15..6c7cbcb5aedeaa9c98ddae9d570cf695ccf7c8f8 100644 (file)
--- a/src/bc.h
+++ b/src/bc.h
@@ -151,7 +151,8 @@ typedef struct {
  *         /  /      \  \  | |_)  | |  (__      |
  *        /__/        \__\ |_.___/   \____|     |
  *                                              v
- *       @ --------------------------------------
+ *                           @ ------------------
+ *                           x = horizontal center
  */
 typedef struct {
 
index 6f538189e454e7e72d6165354c355685e4a7df4c..7f3cf8f3a593dc92acfd04c154bf239577bfeef1 100644 (file)
@@ -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);