[glabels/zint] Improved centering of barcode text.
- From: Jim Evins <jimevins src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glabels/zint] Improved centering of barcode text.
- Date: Sat, 10 Jul 2010 05:42:06 +0000 (UTC)
commit b012b9c74def1a87e21e678486eeb4debeaf23be
Author: Jim Evins <evins snaught com>
Date: Sat Jul 10 01:38:48 2010 -0400
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.
src/bc-zint.c | 2 +-
src/bc.h | 3 ++-
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);
diff --git a/src/bc.h b/src/bc.h
index 5a0374f..6c7cbcb 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 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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]