glbarcode++
 All Classes Namespaces Files Functions Variables Typedefs Macros Pages
Implementing Renderers

The internal structure of a glbarcode::Barcode contains a simple vectorized representation of the barcode. This representation is simply a list of device-independent and barcode-type-independent drawing primitives. New renderers can be created by simply extending the glbarcode::Renderer base class. The glbarcode::Renderer baseclass simply traverses this list of drawing primitives and calls the appropriate virtual method (or callback) to translate into native drawing commands for the target format or drawing context.

The renderer must implement the following virtual methods:

Example

The following is a simple example of a renderer for a fictitious drawing library called "xxx":

#include "Renderer.h"
#include <cstdio>
#include <xxx.h>
class RendererXxx : public Renderer
{
public:
RendererXxx( XxxContext & xc )
{
m_xc = xc;
}
private:
void drawBegin( double w, double h )
{
xxx_open( m_xc, w, h );
}
void drawEnd( void )
{
xxx_close( m_xc );
}
void drawLine( const DrawingPrimitiveLine *line )
{
/* Note: offset x by w/2 so that x1 and x2 refer to center of line. */
xxx_draw_line( m_xc,
line->x + line->w/2, line->y,
line->x + line->w/2, line->y + line->h,
line->w );
}
void drawBox( const DrawingPrimitiveBox *box )
{
xxx_draw_rect( m_xc, box->x, box->y, box->w, box->h );
}
void drawText( const DrawingPrimitiveText *text )
{
xxx_draw_text( m_xc, text->x, text->y, text->fsize, text->s.c_str() );
}
void drawRing( const DrawingPrimitiveRing *ring )
{
xxx_draw_circle( m_xc, ring->x, ring->y, ring->r, ring->lwidth );
}
void drawHexagon( const DrawingPrimitiveHexagon *hexagon )
{
xxx_draw_hexagon( m_xc, hexagon->x, hexagon->y, hexagon->h );
}
XxxContext & m_xc;
};