Minor refactoring of API to barcode structure.
{
gint validbits = BARCODE_NO_ASCII;
glBarcode *gbc;
- glBarcodeShapeLine *line;
- glBarcodeShapeAlpha *bchar;
gdouble scalef = 1.0;
gdouble x;
gint i, j, barlen;
yr -= (isdigit (*p) ? 20 : 10) * scalef;
}
}
- line = gl_barcode_shape_line_new ();
- line->x = x0;
- line->y = y0;
- line->length = yr;
- line->width = (j * scalef) - SHRINK_AMOUNT;
- gl_barcode_add_shape (gbc, (glBarcodeShape *)line);
+ gl_barcode_add_line (gbc, x0, y0, yr, (j * scalef) - SHRINK_AMOUNT);
}
x += j * scalef;
g_message ("impossible data: %s", p);
continue;
}
- bchar = gl_barcode_shape_alpha_new ();
- bchar->x = f1 * scalef + bci->margin;
+ x0 = f1 * scalef + bci->margin;
if (mode == '-') {
- bchar->y =
- bci->margin + bci->height - 8 * scalef;
+ y0 = bci->margin + bci->height - 8 * scalef;
} else {
- bchar->y = bci->margin;
+ y0 = bci->margin;
}
- bchar->fsize = f2 * FONT_SCALE * scalef;
- bchar->c = c;
- gl_barcode_add_shape (gbc, (glBarcodeShape *)bchar);
+ gl_barcode_add_char (gbc, x0, y0, (f2 * FONT_SCALE * scalef), c);
}
}
gdouble h)
{
glBarcode *gbc;
- glBarcodeShapeLine *line;
gint x, y;
gdouble aspect_ratio, pixel_size;
if (*grid++)
{
- line = gl_barcode_shape_line_new ();
- line->x = x*pixel_size + pixel_size/2.0;
- line->y = y*pixel_size;
- line->length = pixel_size;
- line->width = pixel_size;
- gl_barcode_add_shape (gbc, (glBarcodeShape *)line);
+ gl_barcode_add_box (gbc, x*pixel_size, y*pixel_size, pixel_size, pixel_size);
}
}
gdouble h)
{
glBarcode *gbc;
- glBarcodeShapeLine *line;
gint x, y;
gdouble aspect_ratio, pixel_size;
* bits are meaningless for us. */
if ((*grid++) & 1)
{
- line = gl_barcode_shape_line_new ();
- line->x = x*pixel_size + pixel_size/2.0;
- line->y = y*pixel_size;
- line->length = pixel_size;
- line->width = pixel_size;
- gl_barcode_add_shape (gbc, (glBarcodeShape *)line);
+ gl_barcode_add_box (gbc, x*pixel_size, y*pixel_size, pixel_size, pixel_size);
}
}
{
gchar *code, *p;
glBarcode *gbc;
- glBarcodeShapeLine *line;
- gdouble x;
+ gdouble x, y, length, width;
/* Validate code length for all subtypes. */
if ( (g_ascii_strcasecmp (id, "POSTNET") == 0) ) {
/* Now traverse the code string and create a list of lines */
x = POSTNET_HORIZ_MARGIN;
for (p = code; *p != 0; p++) {
- line = gl_barcode_shape_line_new ();
- line->x = x;
- line->y = POSTNET_VERT_MARGIN;
+ y = POSTNET_VERT_MARGIN;
if (*p == '0') {
- line->y +=
- POSTNET_FULLBAR_HEIGHT - POSTNET_HALFBAR_HEIGHT;
- line->length = POSTNET_HALFBAR_HEIGHT;
+ y += POSTNET_FULLBAR_HEIGHT - POSTNET_HALFBAR_HEIGHT;
+ length = POSTNET_HALFBAR_HEIGHT;
} else {
- line->length = POSTNET_FULLBAR_HEIGHT;
+ length = POSTNET_FULLBAR_HEIGHT;
}
- line->width = POSTNET_BAR_WIDTH;
+ width = POSTNET_BAR_WIDTH;
- gl_barcode_add_shape (gbc, (glBarcodeShape *)line);
+ gl_barcode_add_line (gbc, x, y, length, width);
x += POSTNET_BAR_PITCH;
}
{
glBarcode *gbc;
struct zint_symbol *symbol;
- gint type;
gint result;
symbol = ZBarcode_Create();
static glBarcode *render_zint(struct zint_symbol *symbol, gboolean text_flag)
{
glBarcode *gbc;
- glBarcodeShapeBox *box;
- glBarcodeShapeString *bstring;
-
+
struct zint_render *render;
struct zint_render_line *zline;
struct zint_render_string *zstring;
for ( zline = render->lines; zline != NULL; zline = zline->next )
{
- box = gl_barcode_shape_box_new ();
-
- box->x = (gdouble) zline->x;
- box->y = (gdouble) zline->y;
- box->width = (gdouble) zline->width;
- box->height = (gdouble) zline->length;
-
- gl_barcode_add_shape (gbc, (glBarcodeShape *)box);
+ gl_barcode_add_box (gbc, zline->x, zline->y, zline->width, zline->length);
}
/*
{
for ( zstring = render->strings; zstring != NULL; zstring = zstring->next )
{
- bstring = gl_barcode_shape_string_new();
- bstring->x = (double) zstring->x;
- bstring->y = (double) zstring->y;
- bstring->fsize = (double) zstring->fsize;
- bstring->str = g_strndup (zstring->text, zstring->length);
- gl_barcode_add_shape (gbc, (glBarcodeShape *)bstring);
+ gl_barcode_add_string (gbc,
+ zstring->x, zstring->y,
+ zstring->fsize, (gchar *)zstring->text, zstring->length);
}
}
/* Private function prototypes. */
/*========================================================*/
+static void gl_barcode_add_shape (glBarcode *bc,
+ glBarcodeShape *shape);
+
+static void gl_barcode_shape_free (glBarcodeShape *shape);
+
/*---------------------------------------------------------------------------*/
/* Convert id to index into above table. */
}
-/*****************************************************************************/
-/* Allocate new Line shape. */
-/*****************************************************************************/
-glBarcodeShapeLine *
-gl_barcode_shape_line_new (void)
-{
- glBarcodeShapeLine *line_shape = g_new0 (glBarcodeShapeLine, 1);
- line_shape->type = GL_BARCODE_SHAPE_LINE;
-
- return line_shape;
-}
-
-
-/*****************************************************************************/
-/* Allocate new Box shape. */
-/*****************************************************************************/
-glBarcodeShapeBox *
-gl_barcode_shape_box_new (void)
-{
- glBarcodeShapeBox *box_shape = g_new0 (glBarcodeShapeBox, 1);
- box_shape->type = GL_BARCODE_SHAPE_BOX;
-
- return box_shape;
-}
-
-
-/*****************************************************************************/
-/* Allocate new Alpha shape. */
-/*****************************************************************************/
-glBarcodeShapeAlpha *
-gl_barcode_shape_alpha_new (void)
-{
- glBarcodeShapeAlpha *alpha_shape = g_new0 (glBarcodeShapeAlpha, 1);
- alpha_shape->type = GL_BARCODE_SHAPE_ALPHA;
-
- return alpha_shape;
-}
-
-
-/*****************************************************************************/
-/* Allocate new String shape. */
-/*****************************************************************************/
-glBarcodeShapeString *
-gl_barcode_shape_string_new (void)
-{
- glBarcodeShapeString *string_shape = g_new0 (glBarcodeShapeString, 1);
- string_shape->type = GL_BARCODE_SHAPE_STRING;
-
- return string_shape;
-}
-
-
-/*****************************************************************************/
-/* Free a shape primitive. */
-/*****************************************************************************/
-void
-gl_barcode_shape_free (glBarcodeShape *shape)
-{
- switch (shape->type)
- {
-
- case GL_BARCODE_SHAPE_STRING:
- g_free (shape->string.str);
- break;
-
- default:
- break;
- }
-
- g_free (shape);
-}
-
-
/*****************************************************************************/
/* Call appropriate barcode backend to create barcode in intermediate format.*/
/*****************************************************************************/
/*****************************************************************************/
-/* Add shape to barcode. */
+/* Add a line. */
+/*****************************************************************************/
+void
+gl_barcode_add_line (glBarcode *bc,
+ gdouble x,
+ gdouble y,
+ gdouble length,
+ gdouble width)
+{
+ glBarcodeShapeLine *line_shape = g_new0 (glBarcodeShapeLine, 1);
+ line_shape->type = GL_BARCODE_SHAPE_LINE;
+
+ line_shape->x = x;
+ line_shape->y = y;
+ line_shape->length = length;
+ line_shape->width = width;
+
+ gl_barcode_add_shape (bc, (glBarcodeShape *)line_shape);
+}
+
+
+/*****************************************************************************/
+/* Add box. */
+/*****************************************************************************/
+void
+gl_barcode_add_box (glBarcode *bc,
+ gdouble x,
+ gdouble y,
+ gdouble width,
+ gdouble height)
+{
+ glBarcodeShapeBox *box_shape = g_new0 (glBarcodeShapeBox, 1);
+ box_shape->type = GL_BARCODE_SHAPE_BOX;
+
+ box_shape->x = x;
+ box_shape->y = y;
+ box_shape->width = width;
+ box_shape->height = height;
+
+ gl_barcode_add_shape (bc, (glBarcodeShape *)box_shape);
+}
+
+
+/*****************************************************************************/
+/* Add character. */
/*****************************************************************************/
void
+gl_barcode_add_char (glBarcode *bc,
+ gdouble x,
+ gdouble y,
+ gdouble fsize,
+ gchar c)
+{
+ glBarcodeShapeChar *char_shape = g_new0 (glBarcodeShapeChar, 1);
+ char_shape->type = GL_BARCODE_SHAPE_CHAR;
+
+ char_shape->x = x;
+ char_shape->y = y;
+ char_shape->fsize = fsize;
+ char_shape->c = c;
+
+ gl_barcode_add_shape (bc, (glBarcodeShape *)char_shape);
+}
+
+
+/*****************************************************************************/
+/* Add string. */
+/*****************************************************************************/
+void
+gl_barcode_add_string (glBarcode *bc,
+ gdouble x,
+ gdouble y,
+ gdouble fsize,
+ gchar *string,
+ gsize length)
+{
+ glBarcodeShapeString *string_shape = g_new0 (glBarcodeShapeString, 1);
+ string_shape->type = GL_BARCODE_SHAPE_STRING;
+
+ string_shape->x = x;
+ string_shape->y = y;
+ string_shape->fsize = fsize;
+ string_shape->string = g_strndup(string, length);
+
+ gl_barcode_add_shape (bc, (glBarcodeShape *)string_shape);
+}
+
+
+/*****************************************************************************/
+/* Add shape to barcode. */
+/*****************************************************************************/
+static void
gl_barcode_add_shape (glBarcode *bc,
glBarcodeShape *shape)
{
}
+/*****************************************************************************/
+/* Free a shape primitive. */
+/*****************************************************************************/
+static void
+gl_barcode_shape_free (glBarcodeShape *shape)
+{
+ switch (shape->type)
+ {
+
+ case GL_BARCODE_SHAPE_STRING:
+ g_free (shape->string.string);
+ break;
+
+ default:
+ break;
+ }
+
+ g_free (shape);
+}
+
+
/*****************************************************************************/
/* Get a list of names for valid barcode styles. */
/*****************************************************************************/
typedef enum {
GL_BARCODE_SHAPE_LINE,
GL_BARCODE_SHAPE_BOX,
- GL_BARCODE_SHAPE_ALPHA,
+ GL_BARCODE_SHAPE_CHAR,
GL_BARCODE_SHAPE_STRING,
} glBarcodeShapeType;
typedef struct {
/* Begin Common Fields */
- glBarcodeShapeType type; /* Always GL_BARCODE_SHAPE_LINE. */
+ glBarcodeShapeType type; /* Always GL_BARCODE_SHAPE_BOX. */
gdouble x;
gdouble y;
/* End Common Fields */
} glBarcodeShapeBox;
/*
- * glBarcodeShapeAlpha:
+ * glBarcodeShapeChar:
*
* @ = origin (x,y) from top left corner of barcode
*
typedef struct {
/* Begin Common Fields */
- glBarcodeShapeType type; /* Always GL_BARCODE_SHAPE_ALPHA. */
+ glBarcodeShapeType type; /* Always GL_BARCODE_SHAPE_CHAR. */
gdouble x;
gdouble y;
/* End Common Fields */
gdouble fsize;
gchar c;
-} glBarcodeShapeAlpha;
+} glBarcodeShapeChar;
/*
* glBarcodeShapeString:
typedef struct {
/* Begin Common Fields */
- glBarcodeShapeType type; /* Always GL_BARCODE_SHAPE_ALPHA. */
+ glBarcodeShapeType type; /* Always GL_BARCODE_SHAPE_STRING. */
gdouble x;
gdouble y;
/* End Common Fields */
gdouble fsize;
- gchar *str;
+ gchar *string;
} glBarcodeShapeString;
glBarcodeShapeLine line;
glBarcodeShapeBox box;
- glBarcodeShapeAlpha alpha;
+ glBarcodeShapeChar bchar;
glBarcodeShapeString string;
} glBarcodeShape;
-glBarcodeShapeLine *gl_barcode_shape_line_new (void);
-glBarcodeShapeBox *gl_barcode_shape_box_new (void);
-glBarcodeShapeAlpha *gl_barcode_shape_alpha_new (void);
-glBarcodeShapeString *gl_barcode_shape_string_new (void);
-
-void gl_barcode_shape_free (glBarcodeShape *shape);
-
/********************************/
/* Barcode Intermediate Format. */
void gl_barcode_free (glBarcode **bc);
-void gl_barcode_add_shape (glBarcode *bc,
- glBarcodeShape *shape);
+void gl_barcode_add_line (glBarcode *bc,
+ gdouble x,
+ gdouble y,
+ gdouble length,
+ gdouble width);
+
+void gl_barcode_add_box (glBarcode *bc,
+ gdouble x,
+ gdouble y,
+ gdouble width,
+ gdouble height);
+
+void gl_barcode_add_char (glBarcode *bc,
+ gdouble x,
+ gdouble y,
+ gdouble fsize,
+ gchar c);
+
+void gl_barcode_add_string (glBarcode *bc,
+ gdouble x,
+ gdouble y,
+ gdouble fsize,
+ gchar *string,
+ gsize length);
+
GList *gl_barcode_get_styles_list (void);
void gl_barcode_free_styles_list (GList *styles_list);
glBarcodeShape *shape;
glBarcodeShapeLine *line;
glBarcodeShapeBox *box;
- glBarcodeShapeAlpha *bchar;
+ glBarcodeShapeChar *bchar;
glBarcodeShapeString *bstring;
GList *p;
gdouble x_offset, y_offset;
break;
- case GL_BARCODE_SHAPE_ALPHA:
- bchar = (glBarcodeShapeAlpha *) shape;
+ case GL_BARCODE_SHAPE_CHAR:
+ bchar = (glBarcodeShapeChar *) shape;
layout = pango_cairo_create_layout (cr);
pango_layout_set_font_description (layout, desc);
pango_font_description_free (desc);
- pango_layout_set_text (layout, bstring->str, -1);
+ pango_layout_set_text (layout, bstring->string, -1);
pango_layout_get_size (layout, &iw, &ih);
layout_width = (gdouble)iw / (gdouble)PANGO_SCALE;