Big-Ugly Style Update (#278)
* Bulk replaced tabs with spaces * Bulk removed trailing whitespace from lines * Replaced c-style comments with c++-style comments in file banners * Replace nested namespace definitions with single concise definitions (C++17), this keeps the indentation more manageable * Cleanup ordering and spacing of include directives * Bulk renaming of header file extensions from '.h' to '.hpp'. * Update CODING-STYLE.md * Update target_compile_features from cxx_std_11 to cxx_std_20. * Refresh .clang-format file. Still needs a lot of tweaking.
This commit is contained in:
+132
-131
@@ -1,195 +1,196 @@
|
||||
/* Barcode.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// Barcode.cpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#include "Barcode.h"
|
||||
|
||||
#include "Barcode.hpp"
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "DrawingPrimitives.h"
|
||||
#include "DrawingPrimitives.hpp"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/*
|
||||
* Barcode private data
|
||||
*/
|
||||
struct Barcode::PrivateData {
|
||||
/*
|
||||
* Barcode private data
|
||||
*/
|
||||
struct Barcode::PrivateData {
|
||||
|
||||
bool mShowTextFlag; /**< Display text flag */
|
||||
bool mChecksumFlag; /**< Add checksum flag */
|
||||
bool mShowTextFlag; /**< Display text flag */
|
||||
bool mChecksumFlag; /**< Add checksum flag */
|
||||
|
||||
double mW; /**< Width of barcode (points) */
|
||||
double mH; /**< Height of barcode (points) */
|
||||
double mW; /**< Width of barcode (points) */
|
||||
double mH; /**< Height of barcode (points) */
|
||||
|
||||
bool mIsEmpty; /**< Empty data flag */
|
||||
bool mIsDataValid; /**< Valid data flag */
|
||||
bool mIsEmpty; /**< Empty data flag */
|
||||
bool mIsDataValid; /**< Valid data flag */
|
||||
|
||||
std::list<DrawingPrimitive *> mPrimitives; /**< List of drawing primitives */
|
||||
std::list<DrawingPrimitive *> mPrimitives; /**< List of drawing primitives */
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Barcode::Barcode()
|
||||
{
|
||||
d = new Barcode::PrivateData;
|
||||
Barcode::Barcode()
|
||||
{
|
||||
d = new Barcode::PrivateData;
|
||||
|
||||
d->mShowTextFlag = false;
|
||||
d->mChecksumFlag = false;
|
||||
d->mShowTextFlag = false;
|
||||
d->mChecksumFlag = false;
|
||||
|
||||
d->mW = 0;
|
||||
d->mH = 0;
|
||||
d->mW = 0;
|
||||
d->mH = 0;
|
||||
|
||||
d->mIsEmpty = true;
|
||||
d->mIsDataValid = false;
|
||||
}
|
||||
d->mIsEmpty = true;
|
||||
d->mIsDataValid = false;
|
||||
}
|
||||
|
||||
|
||||
Barcode::~Barcode()
|
||||
{
|
||||
clear(); /* Clear drawing primitives. */
|
||||
delete d;
|
||||
}
|
||||
Barcode::~Barcode()
|
||||
{
|
||||
clear(); /* Clear drawing primitives. */
|
||||
delete d;
|
||||
}
|
||||
|
||||
|
||||
Barcode& Barcode::setShowText( bool value )
|
||||
{
|
||||
d->mShowTextFlag = value;
|
||||
return *this;
|
||||
}
|
||||
Barcode& Barcode::setShowText( bool value )
|
||||
{
|
||||
d->mShowTextFlag = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
bool Barcode::showText( ) const
|
||||
{
|
||||
return d->mShowTextFlag;
|
||||
}
|
||||
bool Barcode::showText( ) const
|
||||
{
|
||||
return d->mShowTextFlag;
|
||||
}
|
||||
|
||||
|
||||
Barcode& Barcode::setChecksum( bool value )
|
||||
{
|
||||
d->mChecksumFlag = value;
|
||||
return *this;
|
||||
}
|
||||
Barcode& Barcode::setChecksum( bool value )
|
||||
{
|
||||
d->mChecksumFlag = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
bool Barcode::checksum( ) const
|
||||
{
|
||||
return d->mChecksumFlag;
|
||||
}
|
||||
bool Barcode::checksum( ) const
|
||||
{
|
||||
return d->mChecksumFlag;
|
||||
}
|
||||
|
||||
|
||||
void Barcode::render( Renderer& renderer )
|
||||
{
|
||||
renderer.render( d->mW, d->mH, d->mPrimitives );
|
||||
}
|
||||
void Barcode::render( Renderer& renderer )
|
||||
{
|
||||
renderer.render( d->mW, d->mH, d->mPrimitives );
|
||||
}
|
||||
|
||||
|
||||
bool Barcode::isEmpty( ) const
|
||||
{
|
||||
return d->mIsEmpty;
|
||||
}
|
||||
bool Barcode::isEmpty( ) const
|
||||
{
|
||||
return d->mIsEmpty;
|
||||
}
|
||||
|
||||
|
||||
void Barcode::setIsEmpty( bool value )
|
||||
{
|
||||
d->mIsEmpty = value;
|
||||
}
|
||||
void Barcode::setIsEmpty( bool value )
|
||||
{
|
||||
d->mIsEmpty = value;
|
||||
}
|
||||
|
||||
|
||||
bool Barcode::isDataValid( ) const
|
||||
{
|
||||
return d->mIsDataValid;
|
||||
}
|
||||
bool Barcode::isDataValid( ) const
|
||||
{
|
||||
return d->mIsDataValid;
|
||||
}
|
||||
|
||||
|
||||
void Barcode::setIsDataValid( bool value )
|
||||
{
|
||||
d->mIsDataValid = value;
|
||||
}
|
||||
void Barcode::setIsDataValid( bool value )
|
||||
{
|
||||
d->mIsDataValid = value;
|
||||
}
|
||||
|
||||
|
||||
double Barcode::width( ) const
|
||||
{
|
||||
return d->mW;
|
||||
}
|
||||
double Barcode::width( ) const
|
||||
{
|
||||
return d->mW;
|
||||
}
|
||||
|
||||
|
||||
double Barcode::height( ) const
|
||||
{
|
||||
return d->mH;
|
||||
}
|
||||
double Barcode::height( ) const
|
||||
{
|
||||
return d->mH;
|
||||
}
|
||||
|
||||
|
||||
void Barcode::setWidth( double w )
|
||||
{
|
||||
d->mW = w;
|
||||
}
|
||||
void Barcode::setWidth( double w )
|
||||
{
|
||||
d->mW = w;
|
||||
}
|
||||
|
||||
|
||||
void Barcode::setHeight( double h )
|
||||
{
|
||||
d->mH = h;
|
||||
}
|
||||
void Barcode::setHeight( double h )
|
||||
{
|
||||
d->mH = h;
|
||||
}
|
||||
|
||||
|
||||
void Barcode::clear( )
|
||||
{
|
||||
std::list<DrawingPrimitive*>::iterator primitive;
|
||||
void Barcode::clear( )
|
||||
{
|
||||
std::list<DrawingPrimitive*>::iterator primitive;
|
||||
|
||||
for ( primitive = d->mPrimitives.begin(); primitive != d->mPrimitives.end(); primitive++ )
|
||||
{
|
||||
delete *primitive;
|
||||
}
|
||||
for ( primitive = d->mPrimitives.begin(); primitive != d->mPrimitives.end(); primitive++ )
|
||||
{
|
||||
delete *primitive;
|
||||
}
|
||||
|
||||
d->mPrimitives.clear();
|
||||
}
|
||||
d->mPrimitives.clear();
|
||||
}
|
||||
|
||||
|
||||
void Barcode::addLine( double x, double y, double w, double h )
|
||||
{
|
||||
d->mPrimitives.push_back( new DrawingPrimitiveLine( x, y, w, h ) );
|
||||
}
|
||||
void Barcode::addLine( double x, double y, double w, double h )
|
||||
{
|
||||
d->mPrimitives.push_back( new DrawingPrimitiveLine( x, y, w, h ) );
|
||||
}
|
||||
|
||||
|
||||
void Barcode::addBox( double x, double y, double w, double h )
|
||||
{
|
||||
d->mPrimitives.push_back( new DrawingPrimitiveBox( x, y, w, h ) );
|
||||
}
|
||||
void Barcode::addBox( double x, double y, double w, double h )
|
||||
{
|
||||
d->mPrimitives.push_back( new DrawingPrimitiveBox( x, y, w, h ) );
|
||||
}
|
||||
|
||||
|
||||
void Barcode::addText( double x, double y, double size, const std::string& text, HAlign halign )
|
||||
{
|
||||
d->mPrimitives.push_back( new DrawingPrimitiveText( x, y, size, text, halign ) );
|
||||
}
|
||||
void Barcode::addText( double x, double y, double size, const std::string& text, HAlign halign )
|
||||
{
|
||||
d->mPrimitives.push_back( new DrawingPrimitiveText( x, y, size, text, halign ) );
|
||||
}
|
||||
|
||||
|
||||
void Barcode::addRing( double x, double y, double r, double w )
|
||||
{
|
||||
d->mPrimitives.push_back( new DrawingPrimitiveRing( x, y, r, w ) );
|
||||
}
|
||||
void Barcode::addRing( double x, double y, double r, double w )
|
||||
{
|
||||
d->mPrimitives.push_back( new DrawingPrimitiveRing( x, y, r, w ) );
|
||||
}
|
||||
|
||||
|
||||
void Barcode::addHexagon( double x, double y, double h )
|
||||
{
|
||||
d->mPrimitives.push_back( new DrawingPrimitiveHexagon( x, y, h ) );
|
||||
}
|
||||
void Barcode::addHexagon( double x, double y, double h )
|
||||
{
|
||||
d->mPrimitives.push_back( new DrawingPrimitiveHexagon( x, y, h ) );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,317 +0,0 @@
|
||||
/* Barcode.h
|
||||
*
|
||||
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glbarcode_Barcode_h
|
||||
#define glbarcode_Barcode_h
|
||||
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Enums.h"
|
||||
#include "Renderer.h"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/**
|
||||
* @class Barcode Barcode.h glbarcode/Barcode.h
|
||||
*
|
||||
* The Barcode class is the base class for all barcode implementations. This class
|
||||
* provides the public interfaces and basic infrastructure for all barcode implementations.
|
||||
* Implementations would not typically directly implement this class, but instead would implement
|
||||
* either Barcode1dBase (for 1D symbologies) or Barcode2dBase (for 2D symbologies).
|
||||
*
|
||||
* See Barcode1dBase or Barcode2dBase.
|
||||
*
|
||||
*/
|
||||
class Barcode
|
||||
{
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
Barcode();
|
||||
|
||||
|
||||
public:
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
virtual ~Barcode();
|
||||
|
||||
/*
|
||||
* Non-copyable
|
||||
*/
|
||||
Barcode( const Barcode & ) = delete;
|
||||
void operator=( const Barcode & ) = delete;
|
||||
|
||||
/**
|
||||
* Set accessor for "showText" property.
|
||||
*
|
||||
* @param[in] value Boolean value
|
||||
*
|
||||
* @returns A reference to this Barcode object for property chaining
|
||||
*
|
||||
* @sa showText()
|
||||
*/
|
||||
Barcode& setShowText( bool value );
|
||||
|
||||
|
||||
/**
|
||||
* Get accessor for "showText" property.
|
||||
*
|
||||
* @returns Value of boolean "showText" property
|
||||
*
|
||||
* @sa setShowText()
|
||||
*/
|
||||
bool showText() const;
|
||||
|
||||
|
||||
/**
|
||||
* Set accessor for "checksum" property.
|
||||
*
|
||||
* @param[in] value Boolean value
|
||||
*
|
||||
* @returns A reference to this Barcode object for property chaining
|
||||
*
|
||||
* @sa checksum()
|
||||
*/
|
||||
Barcode& setChecksum( bool value );
|
||||
|
||||
|
||||
/**
|
||||
* Get accessor for "checksum" property.
|
||||
*
|
||||
* @returns Value of boolean "checksum" property
|
||||
*
|
||||
* @sa setChecksum()
|
||||
*/
|
||||
bool checksum() const;
|
||||
|
||||
|
||||
/**
|
||||
* Build barcode from data.
|
||||
*
|
||||
* @param[in] data Data to encode in barcode
|
||||
* @param[in] w Requested width of barcode (0 = auto size)
|
||||
* @param[in] h Requested height of barcode (0 = auto size)
|
||||
*
|
||||
* @returns A reference to this Barcode object for chaining methods
|
||||
*/
|
||||
virtual Barcode& build( const std::string& data,
|
||||
double w = 0,
|
||||
double h = 0 ) = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Render barcode using given Renderer object.
|
||||
*
|
||||
* @param[in] renderer A Renderer object
|
||||
*/
|
||||
void render( Renderer& renderer );
|
||||
|
||||
|
||||
/**
|
||||
* Is barcode data empty?
|
||||
*
|
||||
* @return True if barcode data is empty
|
||||
* @return False if barcode data is not empty
|
||||
*
|
||||
* @sa setIsEmpty()
|
||||
*/
|
||||
bool isEmpty() const;
|
||||
|
||||
|
||||
/**
|
||||
* Is barcode data valid?
|
||||
*
|
||||
* @return True if barcode data is valid
|
||||
* @return False if barcode data is not valid for implemented barcode type
|
||||
*
|
||||
* @sa setIsDataValid()
|
||||
*/
|
||||
bool isDataValid() const;
|
||||
|
||||
|
||||
/**
|
||||
* Get actual width of barcode (may differ from requested width).
|
||||
*
|
||||
* @return Actual width of barcode (points)
|
||||
*
|
||||
* @sa setWidth()
|
||||
*/
|
||||
double width() const;
|
||||
|
||||
|
||||
/**
|
||||
* Get actual height of barcode (may differ from requested height).
|
||||
*
|
||||
* @return Actual height of barcode (points)
|
||||
*
|
||||
* @sa setHeight()
|
||||
*/
|
||||
double height() const;
|
||||
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Clear drawing primitives.
|
||||
*/
|
||||
void clear();
|
||||
|
||||
|
||||
/**
|
||||
* Add line drawing primitive
|
||||
*
|
||||
* To be used by build() implementations during vectorization.
|
||||
*
|
||||
* @image html figure-primitive-line.svg "Line primitive properties"
|
||||
*
|
||||
* @param[in] x X coordinate of line's origin (points)
|
||||
* @param[in] y Y coordinate of line's origin (points)
|
||||
* @param[in] w Bar width (points)
|
||||
* @param[in] h Bar height (points)
|
||||
*/
|
||||
void addLine( double x, double y, double w, double h );
|
||||
|
||||
|
||||
/**
|
||||
* Add box drawing primitive
|
||||
*
|
||||
* To be used by build() implementations during vectorization.
|
||||
*
|
||||
* @image html figure-primitive-box.svg "Box primitive properties"
|
||||
*
|
||||
* @param[in] x X coordinate of box's origin (points)
|
||||
* @param[in] y Y coordinate of box's origin (points)
|
||||
* @param[in] w Width of box (points)
|
||||
* @param[in] h Height of box (points)
|
||||
*/
|
||||
void addBox( double x, double y, double w, double h );
|
||||
|
||||
|
||||
/**
|
||||
* Add text drawing primitive
|
||||
*
|
||||
* To be used by build() implementations during vectorization.
|
||||
*
|
||||
* @image html figure-primitive-text.svg "Text primitive properties"
|
||||
*
|
||||
* @param[in] x X coordinate of text's origin (points)
|
||||
* @param[in] y Y coordinate of text's origin (points)
|
||||
* @param[in] size Font size of text (points)
|
||||
* @param[in] text Text
|
||||
* @param[in] halign Horizontal text alignment
|
||||
*/
|
||||
void addText( double x, double y, double size, const std::string& text, HAlign halign = H_ALIGN_CENTER );
|
||||
|
||||
|
||||
/**
|
||||
* Add ring drawing primitive
|
||||
*
|
||||
* To be used by build() implementations during vectorization.
|
||||
*
|
||||
* @image html figure-primitive-ring.svg "Ring primitive properties"
|
||||
*
|
||||
* @param[in] x X coordinate of ring's origin (points)
|
||||
* @param[in] y Y coordinate of ring's origin (points)
|
||||
* @param[in] r Radius of ring (points)
|
||||
* @param[in] w Line width of ring (points)
|
||||
*/
|
||||
void addRing( double x, double y, double r, double w );
|
||||
|
||||
|
||||
/**
|
||||
* Add hexagon drawing primitive
|
||||
*
|
||||
* To be used by build() implementations during vectorization.
|
||||
*
|
||||
* @image html figure-primitive-hexagon.svg "Hexagon primitive properties"
|
||||
*
|
||||
* @param[in] x X coordinate of hexagon's origin (points)
|
||||
* @param[in] y Y coordinate of hexagon's origin (points)
|
||||
* @param[in] h Height of hexagon (points)
|
||||
*/
|
||||
void addHexagon( double x, double y, double h );
|
||||
|
||||
|
||||
/**
|
||||
* Set is empty property.
|
||||
*
|
||||
* To be used by build() implementations to indicate if input data is empty.
|
||||
*
|
||||
* @param[in] value Boolean value of flag
|
||||
*
|
||||
* @sa isEmpty()
|
||||
*/
|
||||
void setIsEmpty( bool value );
|
||||
|
||||
|
||||
/**
|
||||
* Set is data valid property.
|
||||
*
|
||||
* To be used by build() implementations to indicate if input data is valid or not.
|
||||
*
|
||||
* @param[in] value Boolean value of flag
|
||||
*
|
||||
* @sa isDataValid()
|
||||
*/
|
||||
void setIsDataValid( bool value );
|
||||
|
||||
|
||||
/**
|
||||
* Set new width of barcode.
|
||||
*
|
||||
* To be used by build() implementations to override requested width of barcode.
|
||||
*
|
||||
* @param[in] w Actual width of barcode (points)
|
||||
*
|
||||
* @sa width()
|
||||
*/
|
||||
void setWidth( double w );
|
||||
|
||||
|
||||
/**
|
||||
* Set new height of barcode.
|
||||
*
|
||||
* To be used by build() implementations to override requested height of barcode.
|
||||
*
|
||||
* @param[in] h Actual height of barcode (points)
|
||||
*
|
||||
* @sa height()
|
||||
*/
|
||||
void setHeight( double h );
|
||||
|
||||
|
||||
private:
|
||||
/**
|
||||
* Barcode Private data
|
||||
*/
|
||||
struct PrivateData;
|
||||
PrivateData *d;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_Barcode_h
|
||||
@@ -0,0 +1,317 @@
|
||||
// Barcode.hpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#ifndef glbarcode_Barcode_hpp
|
||||
#define glbarcode_Barcode_hpp
|
||||
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Enums.hpp"
|
||||
#include "Renderer.hpp"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/**
|
||||
* @class Barcode Barcode.h glbarcode/Barcode.h
|
||||
*
|
||||
* The Barcode class is the base class for all barcode implementations. This class
|
||||
* provides the public interfaces and basic infrastructure for all barcode implementations.
|
||||
* Implementations would not typically directly implement this class, but instead would implement
|
||||
* either Barcode1dBase (for 1D symbologies) or Barcode2dBase (for 2D symbologies).
|
||||
*
|
||||
* See Barcode1dBase or Barcode2dBase.
|
||||
*
|
||||
*/
|
||||
class Barcode
|
||||
{
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
Barcode();
|
||||
|
||||
|
||||
public:
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
virtual ~Barcode();
|
||||
|
||||
/*
|
||||
* Non-copyable
|
||||
*/
|
||||
Barcode( const Barcode & ) = delete;
|
||||
void operator=( const Barcode & ) = delete;
|
||||
|
||||
/**
|
||||
* Set accessor for "showText" property.
|
||||
*
|
||||
* @param[in] value Boolean value
|
||||
*
|
||||
* @returns A reference to this Barcode object for property chaining
|
||||
*
|
||||
* @sa showText()
|
||||
*/
|
||||
Barcode& setShowText( bool value );
|
||||
|
||||
|
||||
/**
|
||||
* Get accessor for "showText" property.
|
||||
*
|
||||
* @returns Value of boolean "showText" property
|
||||
*
|
||||
* @sa setShowText()
|
||||
*/
|
||||
bool showText() const;
|
||||
|
||||
|
||||
/**
|
||||
* Set accessor for "checksum" property.
|
||||
*
|
||||
* @param[in] value Boolean value
|
||||
*
|
||||
* @returns A reference to this Barcode object for property chaining
|
||||
*
|
||||
* @sa checksum()
|
||||
*/
|
||||
Barcode& setChecksum( bool value );
|
||||
|
||||
|
||||
/**
|
||||
* Get accessor for "checksum" property.
|
||||
*
|
||||
* @returns Value of boolean "checksum" property
|
||||
*
|
||||
* @sa setChecksum()
|
||||
*/
|
||||
bool checksum() const;
|
||||
|
||||
|
||||
/**
|
||||
* Build barcode from data.
|
||||
*
|
||||
* @param[in] data Data to encode in barcode
|
||||
* @param[in] w Requested width of barcode (0 = auto size)
|
||||
* @param[in] h Requested height of barcode (0 = auto size)
|
||||
*
|
||||
* @returns A reference to this Barcode object for chaining methods
|
||||
*/
|
||||
virtual Barcode& build( const std::string& data,
|
||||
double w = 0,
|
||||
double h = 0 ) = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Render barcode using given Renderer object.
|
||||
*
|
||||
* @param[in] renderer A Renderer object
|
||||
*/
|
||||
void render( Renderer& renderer );
|
||||
|
||||
|
||||
/**
|
||||
* Is barcode data empty?
|
||||
*
|
||||
* @return True if barcode data is empty
|
||||
* @return False if barcode data is not empty
|
||||
*
|
||||
* @sa setIsEmpty()
|
||||
*/
|
||||
bool isEmpty() const;
|
||||
|
||||
|
||||
/**
|
||||
* Is barcode data valid?
|
||||
*
|
||||
* @return True if barcode data is valid
|
||||
* @return False if barcode data is not valid for implemented barcode type
|
||||
*
|
||||
* @sa setIsDataValid()
|
||||
*/
|
||||
bool isDataValid() const;
|
||||
|
||||
|
||||
/**
|
||||
* Get actual width of barcode (may differ from requested width).
|
||||
*
|
||||
* @return Actual width of barcode (points)
|
||||
*
|
||||
* @sa setWidth()
|
||||
*/
|
||||
double width() const;
|
||||
|
||||
|
||||
/**
|
||||
* Get actual height of barcode (may differ from requested height).
|
||||
*
|
||||
* @return Actual height of barcode (points)
|
||||
*
|
||||
* @sa setHeight()
|
||||
*/
|
||||
double height() const;
|
||||
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Clear drawing primitives.
|
||||
*/
|
||||
void clear();
|
||||
|
||||
|
||||
/**
|
||||
* Add line drawing primitive
|
||||
*
|
||||
* To be used by build() implementations during vectorization.
|
||||
*
|
||||
* @image html figure-primitive-line.svg "Line primitive properties"
|
||||
*
|
||||
* @param[in] x X coordinate of line's origin (points)
|
||||
* @param[in] y Y coordinate of line's origin (points)
|
||||
* @param[in] w Bar width (points)
|
||||
* @param[in] h Bar height (points)
|
||||
*/
|
||||
void addLine( double x, double y, double w, double h );
|
||||
|
||||
|
||||
/**
|
||||
* Add box drawing primitive
|
||||
*
|
||||
* To be used by build() implementations during vectorization.
|
||||
*
|
||||
* @image html figure-primitive-box.svg "Box primitive properties"
|
||||
*
|
||||
* @param[in] x X coordinate of box's origin (points)
|
||||
* @param[in] y Y coordinate of box's origin (points)
|
||||
* @param[in] w Width of box (points)
|
||||
* @param[in] h Height of box (points)
|
||||
*/
|
||||
void addBox( double x, double y, double w, double h );
|
||||
|
||||
|
||||
/**
|
||||
* Add text drawing primitive
|
||||
*
|
||||
* To be used by build() implementations during vectorization.
|
||||
*
|
||||
* @image html figure-primitive-text.svg "Text primitive properties"
|
||||
*
|
||||
* @param[in] x X coordinate of text's origin (points)
|
||||
* @param[in] y Y coordinate of text's origin (points)
|
||||
* @param[in] size Font size of text (points)
|
||||
* @param[in] text Text
|
||||
* @param[in] halign Horizontal text alignment
|
||||
*/
|
||||
void addText( double x, double y, double size, const std::string& text, HAlign halign = H_ALIGN_CENTER );
|
||||
|
||||
|
||||
/**
|
||||
* Add ring drawing primitive
|
||||
*
|
||||
* To be used by build() implementations during vectorization.
|
||||
*
|
||||
* @image html figure-primitive-ring.svg "Ring primitive properties"
|
||||
*
|
||||
* @param[in] x X coordinate of ring's origin (points)
|
||||
* @param[in] y Y coordinate of ring's origin (points)
|
||||
* @param[in] r Radius of ring (points)
|
||||
* @param[in] w Line width of ring (points)
|
||||
*/
|
||||
void addRing( double x, double y, double r, double w );
|
||||
|
||||
|
||||
/**
|
||||
* Add hexagon drawing primitive
|
||||
*
|
||||
* To be used by build() implementations during vectorization.
|
||||
*
|
||||
* @image html figure-primitive-hexagon.svg "Hexagon primitive properties"
|
||||
*
|
||||
* @param[in] x X coordinate of hexagon's origin (points)
|
||||
* @param[in] y Y coordinate of hexagon's origin (points)
|
||||
* @param[in] h Height of hexagon (points)
|
||||
*/
|
||||
void addHexagon( double x, double y, double h );
|
||||
|
||||
|
||||
/**
|
||||
* Set is empty property.
|
||||
*
|
||||
* To be used by build() implementations to indicate if input data is empty.
|
||||
*
|
||||
* @param[in] value Boolean value of flag
|
||||
*
|
||||
* @sa isEmpty()
|
||||
*/
|
||||
void setIsEmpty( bool value );
|
||||
|
||||
|
||||
/**
|
||||
* Set is data valid property.
|
||||
*
|
||||
* To be used by build() implementations to indicate if input data is valid or not.
|
||||
*
|
||||
* @param[in] value Boolean value of flag
|
||||
*
|
||||
* @sa isDataValid()
|
||||
*/
|
||||
void setIsDataValid( bool value );
|
||||
|
||||
|
||||
/**
|
||||
* Set new width of barcode.
|
||||
*
|
||||
* To be used by build() implementations to override requested width of barcode.
|
||||
*
|
||||
* @param[in] w Actual width of barcode (points)
|
||||
*
|
||||
* @sa width()
|
||||
*/
|
||||
void setWidth( double w );
|
||||
|
||||
|
||||
/**
|
||||
* Set new height of barcode.
|
||||
*
|
||||
* To be used by build() implementations to override requested height of barcode.
|
||||
*
|
||||
* @param[in] h Actual height of barcode (points)
|
||||
*
|
||||
* @sa height()
|
||||
*/
|
||||
void setHeight( double h );
|
||||
|
||||
|
||||
private:
|
||||
/**
|
||||
* Barcode Private data
|
||||
*/
|
||||
struct PrivateData;
|
||||
PrivateData *d;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_Barcode_hpp
|
||||
+88
-87
@@ -1,117 +1,118 @@
|
||||
/* Barcode1dBase.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// Barcode1dBase.cpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#include "Barcode1dBase.h"
|
||||
|
||||
#include "Barcode1dBase.hpp"
|
||||
|
||||
#include "DrawingPrimitives.hpp"
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "DrawingPrimitives.h"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/*
|
||||
* Barcode1dBase private data
|
||||
*/
|
||||
struct Barcode1dBase::PrivateData {
|
||||
int dummy;
|
||||
};
|
||||
/*
|
||||
* Barcode1dBase private data
|
||||
*/
|
||||
struct Barcode1dBase::PrivateData {
|
||||
int dummy;
|
||||
};
|
||||
|
||||
|
||||
Barcode1dBase::Barcode1dBase()
|
||||
{
|
||||
d = new Barcode1dBase::PrivateData;
|
||||
}
|
||||
Barcode1dBase::Barcode1dBase()
|
||||
{
|
||||
d = new Barcode1dBase::PrivateData;
|
||||
}
|
||||
|
||||
|
||||
Barcode1dBase::~Barcode1dBase()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
Barcode1dBase::~Barcode1dBase()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
|
||||
Barcode& Barcode1dBase::build( const std::string& rawData,
|
||||
double w,
|
||||
double h )
|
||||
{
|
||||
std::string cookedData; /* Preprocessed data */
|
||||
std::string displayText; /* Text data to be displayed */
|
||||
std::string codedData; /* Encoded data */
|
||||
Barcode& Barcode1dBase::build( const std::string& rawData,
|
||||
double w,
|
||||
double h )
|
||||
{
|
||||
std::string cookedData; /* Preprocessed data */
|
||||
std::string displayText; /* Text data to be displayed */
|
||||
std::string codedData; /* Encoded data */
|
||||
|
||||
clear();
|
||||
clear();
|
||||
|
||||
if ( rawData.empty() )
|
||||
{
|
||||
setIsEmpty( true );
|
||||
setIsDataValid( false );
|
||||
if ( rawData.empty() )
|
||||
{
|
||||
setIsEmpty( true );
|
||||
setIsDataValid( false );
|
||||
|
||||
setWidth( 0 );
|
||||
setHeight( 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
setIsEmpty( false );
|
||||
setWidth( 0 );
|
||||
setHeight( 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
setIsEmpty( false );
|
||||
|
||||
if ( !validate( rawData ) )
|
||||
{
|
||||
setIsDataValid( false );
|
||||
if ( !validate( rawData ) )
|
||||
{
|
||||
setIsDataValid( false );
|
||||
|
||||
setWidth( 0 );
|
||||
setHeight( 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
setIsDataValid( true );
|
||||
setWidth( 0 );
|
||||
setHeight( 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
setIsDataValid( true );
|
||||
|
||||
cookedData = preprocess( rawData );
|
||||
codedData = encode( cookedData );
|
||||
displayText = prepareText( rawData );
|
||||
cookedData = preprocess( rawData );
|
||||
codedData = encode( cookedData );
|
||||
displayText = prepareText( rawData );
|
||||
|
||||
vectorize( codedData, displayText, cookedData, w, h );
|
||||
vectorize( codedData, displayText, cookedData, w, h );
|
||||
|
||||
setWidth( w );
|
||||
setHeight( h );
|
||||
}
|
||||
}
|
||||
setWidth( w );
|
||||
setHeight( h );
|
||||
}
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Default preprocess method
|
||||
*/
|
||||
std::string Barcode1dBase::preprocess( const std::string& rawData )
|
||||
{
|
||||
return rawData;
|
||||
}
|
||||
/*
|
||||
* Default preprocess method
|
||||
*/
|
||||
std::string Barcode1dBase::preprocess( const std::string& rawData )
|
||||
{
|
||||
return rawData;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Default prepareText method
|
||||
*/
|
||||
std::string Barcode1dBase::prepareText( const std::string& rawData )
|
||||
{
|
||||
return rawData;
|
||||
}
|
||||
/*
|
||||
* Default prepareText method
|
||||
*/
|
||||
std::string Barcode1dBase::prepareText( const std::string& rawData )
|
||||
{
|
||||
return rawData;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,164 +0,0 @@
|
||||
/* Barcode1dBase.h
|
||||
*
|
||||
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glbarcode_Barcode1dBase_h
|
||||
#define glbarcode_Barcode1dBase_h
|
||||
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Barcode.h"
|
||||
#include "Renderer.h"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/**
|
||||
* @class Barcode1dBase Barcode1dBase.h glbarcode/Barcode1dBase.h
|
||||
*
|
||||
* The Barcode1dBase class is the base class for all 1D barcode implementations.
|
||||
* This class provides a common framework for the implementation of 1D barcodes.
|
||||
* Creating 1D barcode types (or symbologies) would be typically accomplished by
|
||||
* implementing this class rather than directly implementing the Barcode class.
|
||||
*
|
||||
*/
|
||||
class Barcode1dBase : public Barcode
|
||||
{
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
Barcode1dBase();
|
||||
|
||||
|
||||
public:
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~Barcode1dBase() override;
|
||||
|
||||
|
||||
/**
|
||||
* Build 1D barcode from data.
|
||||
*
|
||||
* Implements glbarcode::Barcode::build(). Calls the validate(), preprocess(),
|
||||
* encode(), prepareText(), and vectorize() virtual methods, as shown:
|
||||
*
|
||||
* @dotfile figure-1d-build.dot "1D build() data flow"
|
||||
*
|
||||
* @param[in] data Data to encode in barcode
|
||||
* @param[in] w Requested width of barcode (0 = auto size)
|
||||
* @param[in] h Requested height of barcode (0 = auto size)
|
||||
*
|
||||
* @returns A reference to this Barcode object for chaining methods
|
||||
*/
|
||||
Barcode& build( const std::string& data,
|
||||
double w = 0,
|
||||
double h = 0 ) override;
|
||||
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Data validator.
|
||||
*
|
||||
* Required virtual method to test if data is valid for encoding with
|
||||
* barcode type.
|
||||
*
|
||||
* @param[in] rawData Data to validate
|
||||
*
|
||||
* @return True if data is valid data for barcode type
|
||||
* @return False if data is not valid data for barcode type
|
||||
*/
|
||||
virtual bool validate( const std::string& rawData ) = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Data preprocessor.
|
||||
*
|
||||
* Optional virtual method to perform any transformation of the data needed
|
||||
* before encoding. (E.g. encoding an extended alphabet into a simpler one).
|
||||
*
|
||||
* @param[in] rawData Data to preprocess
|
||||
*
|
||||
* @return Preprocessed data
|
||||
*/
|
||||
virtual std::string preprocess( const std::string& rawData );
|
||||
|
||||
|
||||
/**
|
||||
* Data encoder.
|
||||
*
|
||||
* Required virtual method to encode data such that it can be later vectorized.
|
||||
* The encoded data is usually a list of characters that represent an atomic
|
||||
* barcode element (e.g. 'w' = a wide line & 'n' = a narrow line).
|
||||
*
|
||||
* @param[in] cookedData Data to encode
|
||||
*
|
||||
* @return Encoded data
|
||||
*/
|
||||
virtual std::string encode( const std::string& cookedData ) = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Prepare text.
|
||||
*
|
||||
* Optional virtual method to prepare text to be displayed as part of barcode.
|
||||
*
|
||||
* @param[in] rawData Data to prepare
|
||||
*
|
||||
* @return text in display form
|
||||
*/
|
||||
virtual std::string prepareText( const std::string& rawData );
|
||||
|
||||
|
||||
/**
|
||||
* Vectorize encoded data.
|
||||
*
|
||||
* Required virtual method to convert encoded data into a list of drawing
|
||||
* primitives which can later be rendered.
|
||||
*
|
||||
* @param[in] encodedData Data to vectorize
|
||||
* @param[in] displayText Text to display
|
||||
* @param[in] cookedData Original data prior to encoding (may be needed for sizing)
|
||||
* @param[in,out] w Requested width of barcode (0 = auto size), vectorize will overwrite with actual width
|
||||
* @param[in,out] h Requested height of barcode (0 = auto size), vectorize will overwrite with actual width
|
||||
*/
|
||||
virtual void vectorize( const std::string& encodedData,
|
||||
const std::string& displayText,
|
||||
const std::string& cookedData,
|
||||
double& w,
|
||||
double& h ) = 0;
|
||||
|
||||
|
||||
private:
|
||||
/**
|
||||
* Barcode1dBase Private data
|
||||
*/
|
||||
struct PrivateData;
|
||||
PrivateData *d;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_Barcode1dBase_h
|
||||
@@ -0,0 +1,164 @@
|
||||
// Barcode1dBase.hpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#ifndef glbarcode_Barcode1dBase_hpp
|
||||
#define glbarcode_Barcode1dBase_hpp
|
||||
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Barcode.hpp"
|
||||
#include "Renderer.hpp"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/**
|
||||
* @class Barcode1dBase Barcode1dBase.h glbarcode/Barcode1dBase.h
|
||||
*
|
||||
* The Barcode1dBase class is the base class for all 1D barcode implementations.
|
||||
* This class provides a common framework for the implementation of 1D barcodes.
|
||||
* Creating 1D barcode types (or symbologies) would be typically accomplished by
|
||||
* implementing this class rather than directly implementing the Barcode class.
|
||||
*
|
||||
*/
|
||||
class Barcode1dBase : public Barcode
|
||||
{
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
Barcode1dBase();
|
||||
|
||||
|
||||
public:
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~Barcode1dBase() override;
|
||||
|
||||
|
||||
/**
|
||||
* Build 1D barcode from data.
|
||||
*
|
||||
* Implements glbarcode::Barcode::build(). Calls the validate(), preprocess(),
|
||||
* encode(), prepareText(), and vectorize() virtual methods, as shown:
|
||||
*
|
||||
* @dotfile figure-1d-build.dot "1D build() data flow"
|
||||
*
|
||||
* @param[in] data Data to encode in barcode
|
||||
* @param[in] w Requested width of barcode (0 = auto size)
|
||||
* @param[in] h Requested height of barcode (0 = auto size)
|
||||
*
|
||||
* @returns A reference to this Barcode object for chaining methods
|
||||
*/
|
||||
Barcode& build( const std::string& data,
|
||||
double w = 0,
|
||||
double h = 0 ) override;
|
||||
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Data validator.
|
||||
*
|
||||
* Required virtual method to test if data is valid for encoding with
|
||||
* barcode type.
|
||||
*
|
||||
* @param[in] rawData Data to validate
|
||||
*
|
||||
* @return True if data is valid data for barcode type
|
||||
* @return False if data is not valid data for barcode type
|
||||
*/
|
||||
virtual bool validate( const std::string& rawData ) = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Data preprocessor.
|
||||
*
|
||||
* Optional virtual method to perform any transformation of the data needed
|
||||
* before encoding. (E.g. encoding an extended alphabet into a simpler one).
|
||||
*
|
||||
* @param[in] rawData Data to preprocess
|
||||
*
|
||||
* @return Preprocessed data
|
||||
*/
|
||||
virtual std::string preprocess( const std::string& rawData );
|
||||
|
||||
|
||||
/**
|
||||
* Data encoder.
|
||||
*
|
||||
* Required virtual method to encode data such that it can be later vectorized.
|
||||
* The encoded data is usually a list of characters that represent an atomic
|
||||
* barcode element (e.g. 'w' = a wide line & 'n' = a narrow line).
|
||||
*
|
||||
* @param[in] cookedData Data to encode
|
||||
*
|
||||
* @return Encoded data
|
||||
*/
|
||||
virtual std::string encode( const std::string& cookedData ) = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Prepare text.
|
||||
*
|
||||
* Optional virtual method to prepare text to be displayed as part of barcode.
|
||||
*
|
||||
* @param[in] rawData Data to prepare
|
||||
*
|
||||
* @return text in display form
|
||||
*/
|
||||
virtual std::string prepareText( const std::string& rawData );
|
||||
|
||||
|
||||
/**
|
||||
* Vectorize encoded data.
|
||||
*
|
||||
* Required virtual method to convert encoded data into a list of drawing
|
||||
* primitives which can later be rendered.
|
||||
*
|
||||
* @param[in] encodedData Data to vectorize
|
||||
* @param[in] displayText Text to display
|
||||
* @param[in] cookedData Original data prior to encoding (may be needed for sizing)
|
||||
* @param[in,out] w Requested width of barcode (0 = auto size), vectorize will overwrite with actual width
|
||||
* @param[in,out] h Requested height of barcode (0 = auto size), vectorize will overwrite with actual width
|
||||
*/
|
||||
virtual void vectorize( const std::string& encodedData,
|
||||
const std::string& displayText,
|
||||
const std::string& cookedData,
|
||||
double& w,
|
||||
double& h ) = 0;
|
||||
|
||||
|
||||
private:
|
||||
/**
|
||||
* Barcode1dBase Private data
|
||||
*/
|
||||
struct PrivateData;
|
||||
PrivateData *d;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_Barcode1dBase_hpp
|
||||
+121
-120
@@ -1,27 +1,28 @@
|
||||
/* Barcode2dBase.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// Barcode2dBase.cpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#include "Barcode2dBase.h"
|
||||
|
||||
#include "Constants.h"
|
||||
#include "DrawingPrimitives.h"
|
||||
#include "Barcode2dBase.hpp"
|
||||
|
||||
#include "Constants.hpp"
|
||||
#include "DrawingPrimitives.hpp"
|
||||
|
||||
#include <list>
|
||||
#include <algorithm>
|
||||
@@ -33,7 +34,7 @@ using namespace glbarcode::Constants;
|
||||
namespace
|
||||
{
|
||||
|
||||
const double MIN_CELL_SIZE = ( 1.0/64.0 * PTS_PER_INCH );
|
||||
const double MIN_CELL_SIZE = ( 1.0/64.0 * PTS_PER_INCH );
|
||||
|
||||
}
|
||||
|
||||
@@ -41,125 +42,125 @@ namespace
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/*
|
||||
* Barcode2dBase private data
|
||||
*/
|
||||
struct Barcode2dBase::PrivateData {
|
||||
int dummy;
|
||||
};
|
||||
/*
|
||||
* Barcode2dBase private data
|
||||
*/
|
||||
struct Barcode2dBase::PrivateData {
|
||||
int dummy;
|
||||
};
|
||||
|
||||
|
||||
Barcode2dBase::Barcode2dBase()
|
||||
{
|
||||
d = new Barcode2dBase::PrivateData;
|
||||
}
|
||||
Barcode2dBase::Barcode2dBase()
|
||||
{
|
||||
d = new Barcode2dBase::PrivateData;
|
||||
}
|
||||
|
||||
|
||||
Barcode2dBase::~Barcode2dBase()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
Barcode2dBase::~Barcode2dBase()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
|
||||
Barcode& Barcode2dBase::build( const std::string& rawData,
|
||||
double w,
|
||||
double h )
|
||||
{
|
||||
std::string cookedData; /* Preprocessed data */
|
||||
Matrix<bool> encodedData; /* Encoded data matrix */
|
||||
Barcode& Barcode2dBase::build( const std::string& rawData,
|
||||
double w,
|
||||
double h )
|
||||
{
|
||||
std::string cookedData; /* Preprocessed data */
|
||||
Matrix<bool> encodedData; /* Encoded data matrix */
|
||||
|
||||
clear();
|
||||
clear();
|
||||
|
||||
if ( rawData.empty() )
|
||||
{
|
||||
setIsEmpty( true );
|
||||
setIsDataValid( false );
|
||||
if ( rawData.empty() )
|
||||
{
|
||||
setIsEmpty( true );
|
||||
setIsDataValid( false );
|
||||
|
||||
setWidth( 0 );
|
||||
setHeight( 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
setIsEmpty( false );
|
||||
setWidth( 0 );
|
||||
setHeight( 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
setIsEmpty( false );
|
||||
|
||||
if ( !validate( rawData ) )
|
||||
{
|
||||
setIsDataValid( false );
|
||||
if ( !validate( rawData ) )
|
||||
{
|
||||
setIsDataValid( false );
|
||||
|
||||
setWidth( 0 );
|
||||
setHeight( 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
setIsDataValid( true );
|
||||
setWidth( 0 );
|
||||
setHeight( 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
setIsDataValid( true );
|
||||
|
||||
cookedData = preprocess( rawData );
|
||||
encode( cookedData, encodedData );
|
||||
cookedData = preprocess( rawData );
|
||||
encode( cookedData, encodedData );
|
||||
|
||||
vectorize( encodedData, w, h );
|
||||
vectorize( encodedData, w, h );
|
||||
|
||||
setWidth( w );
|
||||
setHeight( h );
|
||||
}
|
||||
}
|
||||
setWidth( w );
|
||||
setHeight( h );
|
||||
}
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Default preprocess method
|
||||
*/
|
||||
std::string Barcode2dBase::preprocess( const std::string& rawData )
|
||||
{
|
||||
return rawData;
|
||||
}
|
||||
/*
|
||||
* Default preprocess method
|
||||
*/
|
||||
std::string Barcode2dBase::preprocess( const std::string& rawData )
|
||||
{
|
||||
return rawData;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Default 2D vectorization method
|
||||
*/
|
||||
void Barcode2dBase::vectorize( const Matrix<bool>& encodedData,
|
||||
double& w,
|
||||
double& h )
|
||||
{
|
||||
/*
|
||||
* Default 2D vectorization method
|
||||
*/
|
||||
void Barcode2dBase::vectorize( const Matrix<bool>& encodedData,
|
||||
double& w,
|
||||
double& h )
|
||||
{
|
||||
|
||||
/* determine size and establish scale */
|
||||
double scale;
|
||||
double minW = MIN_CELL_SIZE*encodedData.nx() + 2*MIN_CELL_SIZE;
|
||||
double minH = MIN_CELL_SIZE*encodedData.ny() + 2*MIN_CELL_SIZE;
|
||||
/* determine size and establish scale */
|
||||
double scale;
|
||||
double minW = MIN_CELL_SIZE*encodedData.nx() + 2*MIN_CELL_SIZE;
|
||||
double minH = MIN_CELL_SIZE*encodedData.ny() + 2*MIN_CELL_SIZE;
|
||||
|
||||
if ( (w <= minW) || (h <= minH) )
|
||||
{
|
||||
scale = 1;
|
||||
w = minW;
|
||||
h = minH;
|
||||
}
|
||||
else
|
||||
{
|
||||
scale = std::min( w / minW, h / minH );
|
||||
w = scale * minW;
|
||||
h = scale * minH;
|
||||
}
|
||||
double cellSize = scale * MIN_CELL_SIZE;
|
||||
double quietSize = scale * MIN_CELL_SIZE;
|
||||
|
||||
|
||||
for ( int iy = 0; iy < encodedData.ny(); iy++ )
|
||||
{
|
||||
for ( int ix = 0; ix < encodedData.nx(); ix++ )
|
||||
{
|
||||
if ( encodedData[iy][ix] )
|
||||
{
|
||||
addBox( quietSize + ix*cellSize,
|
||||
quietSize + iy*cellSize,
|
||||
cellSize,
|
||||
cellSize );
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( (w <= minW) || (h <= minH) )
|
||||
{
|
||||
scale = 1;
|
||||
w = minW;
|
||||
h = minH;
|
||||
}
|
||||
else
|
||||
{
|
||||
scale = std::min( w / minW, h / minH );
|
||||
w = scale * minW;
|
||||
h = scale * minH;
|
||||
}
|
||||
double cellSize = scale * MIN_CELL_SIZE;
|
||||
double quietSize = scale * MIN_CELL_SIZE;
|
||||
|
||||
}
|
||||
|
||||
for ( int iy = 0; iy < encodedData.ny(); iy++ )
|
||||
{
|
||||
for ( int ix = 0; ix < encodedData.nx(); ix++ )
|
||||
{
|
||||
if ( encodedData[iy][ix] )
|
||||
{
|
||||
addBox( quietSize + ix*cellSize,
|
||||
quietSize + iy*cellSize,
|
||||
cellSize,
|
||||
cellSize );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,151 +0,0 @@
|
||||
/* Barcode2dBase.h
|
||||
*
|
||||
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glbarcode_Barcode2dBase_h
|
||||
#define glbarcode_Barcode2dBase_h
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Barcode.h"
|
||||
#include "Renderer.h"
|
||||
#include "Matrix.h"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/**
|
||||
* @class Barcode2dBase Barcode2dBase.h glbarcode/Barcode2dBase.h
|
||||
*
|
||||
* The Barcode2dBase class is the base class for all 2D barcode implementations.
|
||||
* This class provides a common framework for the implementation of 2D barcodes.
|
||||
* Creating 2D barcode types (or symbologies) would be typically accomplished by
|
||||
* implementing this class rather than directly implementing the Barcode class.
|
||||
*
|
||||
*/
|
||||
class Barcode2dBase : public Barcode
|
||||
{
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
Barcode2dBase();
|
||||
|
||||
|
||||
public:
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~Barcode2dBase() override;
|
||||
|
||||
|
||||
/**
|
||||
* Build 2D barcode from data.
|
||||
*
|
||||
* Implements glbarcode::Barcode::build(). Calls the validate(), preprocess(),
|
||||
* encode(), and vectorize() virtual methods, as shown:
|
||||
*
|
||||
* @dotfile figure-2d-build.dot "2D build() data flow"
|
||||
*
|
||||
* @param[in] data Data to encode in barcode
|
||||
* @param[in] w Requested width of barcode (0 = auto size)
|
||||
* @param[in] h Requested height of barcode (0 = auto size)
|
||||
*
|
||||
* @returns A reference to this Barcode object for chaining methods
|
||||
*/
|
||||
Barcode& build( const std::string& data,
|
||||
double w = 0,
|
||||
double h = 0 ) override;
|
||||
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Validate barcode data.
|
||||
*
|
||||
* Required virtual method to test if data is valid for encoding with
|
||||
* barcode type.
|
||||
*
|
||||
* @param[in] rawData Data to validate
|
||||
*
|
||||
* @return True if data is valid data for barcode type
|
||||
* @return False if data is not valid data for barcode type
|
||||
*/
|
||||
virtual bool validate( const std::string& rawData ) = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Preprocess barcode data.
|
||||
*
|
||||
* Optional virtual method to perform any transformation of the data needed
|
||||
* before encoding. (E.g. encoding an extended alphabet into a simpler one).
|
||||
*
|
||||
* @param[in] rawData Data to preprocess
|
||||
*
|
||||
* @return Preprocessed data
|
||||
*/
|
||||
virtual std::string preprocess( const std::string& rawData );
|
||||
|
||||
|
||||
/**
|
||||
* Encode barcode data
|
||||
*
|
||||
* Required virtual method to encode data such that it can be later vectorized.
|
||||
*
|
||||
* @param[in] cookedData Data to encode
|
||||
* @param[out] encodedData Encoded data in the form of a matrix
|
||||
*
|
||||
* @return True if data was encoded successfully
|
||||
* @return False if data could not be encoded (condition not discoverable by validate())
|
||||
*/
|
||||
virtual bool encode( const std::string& cookedData,
|
||||
Matrix<bool>& encodedData ) = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Vectorize encoded data
|
||||
*
|
||||
* Optional virtual method to convert encoded data into a list of drawing
|
||||
* primitives which can later be rendered.
|
||||
*
|
||||
* @param[in] encodedData Data to vectorize
|
||||
* @param[in,out] w Requested width of barcode (0 = auto size), vectorize will overwrite with actual width
|
||||
* @param[in,out] h Requested height of barcode (0 = auto size), vectorize will overwrite with actual width
|
||||
*/
|
||||
virtual void vectorize( const Matrix<bool>& encodedData,
|
||||
double& w,
|
||||
double& h );
|
||||
|
||||
|
||||
private:
|
||||
/**
|
||||
* Barcode2dBase Private data
|
||||
*/
|
||||
struct PrivateData;
|
||||
PrivateData *d;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_Barcode2dBase_h
|
||||
@@ -0,0 +1,151 @@
|
||||
// Barcode2dBase.hpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#ifndef glbarcode_Barcode2dBase_hpp
|
||||
#define glbarcode_Barcode2dBase_hpp
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Barcode.hpp"
|
||||
#include "Renderer.hpp"
|
||||
#include "Matrix.hpp"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/**
|
||||
* @class Barcode2dBase Barcode2dBase.h glbarcode/Barcode2dBase.h
|
||||
*
|
||||
* The Barcode2dBase class is the base class for all 2D barcode implementations.
|
||||
* This class provides a common framework for the implementation of 2D barcodes.
|
||||
* Creating 2D barcode types (or symbologies) would be typically accomplished by
|
||||
* implementing this class rather than directly implementing the Barcode class.
|
||||
*
|
||||
*/
|
||||
class Barcode2dBase : public Barcode
|
||||
{
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
Barcode2dBase();
|
||||
|
||||
|
||||
public:
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~Barcode2dBase() override;
|
||||
|
||||
|
||||
/**
|
||||
* Build 2D barcode from data.
|
||||
*
|
||||
* Implements glbarcode::Barcode::build(). Calls the validate(), preprocess(),
|
||||
* encode(), and vectorize() virtual methods, as shown:
|
||||
*
|
||||
* @dotfile figure-2d-build.dot "2D build() data flow"
|
||||
*
|
||||
* @param[in] data Data to encode in barcode
|
||||
* @param[in] w Requested width of barcode (0 = auto size)
|
||||
* @param[in] h Requested height of barcode (0 = auto size)
|
||||
*
|
||||
* @returns A reference to this Barcode object for chaining methods
|
||||
*/
|
||||
Barcode& build( const std::string& data,
|
||||
double w = 0,
|
||||
double h = 0 ) override;
|
||||
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Validate barcode data.
|
||||
*
|
||||
* Required virtual method to test if data is valid for encoding with
|
||||
* barcode type.
|
||||
*
|
||||
* @param[in] rawData Data to validate
|
||||
*
|
||||
* @return True if data is valid data for barcode type
|
||||
* @return False if data is not valid data for barcode type
|
||||
*/
|
||||
virtual bool validate( const std::string& rawData ) = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Preprocess barcode data.
|
||||
*
|
||||
* Optional virtual method to perform any transformation of the data needed
|
||||
* before encoding. (E.g. encoding an extended alphabet into a simpler one).
|
||||
*
|
||||
* @param[in] rawData Data to preprocess
|
||||
*
|
||||
* @return Preprocessed data
|
||||
*/
|
||||
virtual std::string preprocess( const std::string& rawData );
|
||||
|
||||
|
||||
/**
|
||||
* Encode barcode data
|
||||
*
|
||||
* Required virtual method to encode data such that it can be later vectorized.
|
||||
*
|
||||
* @param[in] cookedData Data to encode
|
||||
* @param[out] encodedData Encoded data in the form of a matrix
|
||||
*
|
||||
* @return True if data was encoded successfully
|
||||
* @return False if data could not be encoded (condition not discoverable by validate())
|
||||
*/
|
||||
virtual bool encode( const std::string& cookedData,
|
||||
Matrix<bool>& encodedData ) = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Vectorize encoded data
|
||||
*
|
||||
* Optional virtual method to convert encoded data into a list of drawing
|
||||
* primitives which can later be rendered.
|
||||
*
|
||||
* @param[in] encodedData Data to vectorize
|
||||
* @param[in,out] w Requested width of barcode (0 = auto size), vectorize will overwrite with actual width
|
||||
* @param[in,out] h Requested height of barcode (0 = auto size), vectorize will overwrite with actual width
|
||||
*/
|
||||
virtual void vectorize( const Matrix<bool>& encodedData,
|
||||
double& w,
|
||||
double& h );
|
||||
|
||||
|
||||
private:
|
||||
/**
|
||||
* Barcode2dBase Private data
|
||||
*/
|
||||
struct PrivateData;
|
||||
PrivateData *d;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_Barcode2dBase_hpp
|
||||
+35
-34
@@ -1,44 +1,45 @@
|
||||
/* BarcodeCepnet.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// BarcodeCepnet.cpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#include "BarcodeCepnet.h"
|
||||
|
||||
#include "BarcodeCepnet.hpp"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/*
|
||||
* Static CEPNET barcode creation method
|
||||
*/
|
||||
Barcode* BarcodeCepnet::create( )
|
||||
{
|
||||
return new BarcodeCepnet();
|
||||
}
|
||||
/*
|
||||
* Static CEPNET barcode creation method
|
||||
*/
|
||||
Barcode* BarcodeCepnet::create( )
|
||||
{
|
||||
return new BarcodeCepnet();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* CEPNET validation of number of digits, overrides BarcodePostnet::validateDigits()
|
||||
*/
|
||||
bool BarcodeCepnet::validateDigits( int nDigits )
|
||||
{
|
||||
return nDigits == 8;
|
||||
}
|
||||
/*
|
||||
* CEPNET validation of number of digits, overrides BarcodePostnet::validateDigits()
|
||||
*/
|
||||
bool BarcodeCepnet::validateDigits( int nDigits )
|
||||
{
|
||||
return nDigits == 8;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
/* BarcodeCepnet.h
|
||||
*
|
||||
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glbarcode_BarcodeCepnet_h
|
||||
#define glbarcode_BarcodeCepnet_h
|
||||
|
||||
|
||||
#include "BarcodePostnet.h"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/**
|
||||
* @class BarcodeCepnet BarcodeCepnet.h glbarcode/BarcodeCepnet.h
|
||||
*
|
||||
* 8 digit *CEPNET* barcode (Brazilian Post, based on POSTNET), extends BarcodePostnet
|
||||
*
|
||||
* @image html sample-cepnet.svg "Sample Brazilian Post CEPNET Barcode"
|
||||
*
|
||||
*
|
||||
* ### Input Data Format ###
|
||||
*
|
||||
* Input data requirements are identical to BarcodePostnet, except the
|
||||
* validator only accepts 8 digits of input.
|
||||
*
|
||||
* See BarcodePostnet.
|
||||
*
|
||||
*/
|
||||
class BarcodeCepnet : public BarcodePostnet
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Static CEPNET barcode creation method
|
||||
*
|
||||
* Used by glbarcode::BarcodeFactory
|
||||
*/
|
||||
static Barcode* create();
|
||||
|
||||
|
||||
private:
|
||||
bool validateDigits( int nDigits ) override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_BarcodeCepnet_h
|
||||
@@ -0,0 +1,66 @@
|
||||
// BarcodeCepnet.hpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#ifndef glbarcode_BarcodeCepnet_hpp
|
||||
#define glbarcode_BarcodeCepnet_hpp
|
||||
|
||||
|
||||
#include "BarcodePostnet.hpp"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/**
|
||||
* @class BarcodeCepnet BarcodeCepnet.h glbarcode/BarcodeCepnet.h
|
||||
*
|
||||
* 8 digit *CEPNET* barcode (Brazilian Post, based on POSTNET), extends BarcodePostnet
|
||||
*
|
||||
* @image html sample-cepnet.svg "Sample Brazilian Post CEPNET Barcode"
|
||||
*
|
||||
*
|
||||
* ### Input Data Format ###
|
||||
*
|
||||
* Input data requirements are identical to BarcodePostnet, except the
|
||||
* validator only accepts 8 digits of input.
|
||||
*
|
||||
* See BarcodePostnet.
|
||||
*
|
||||
*/
|
||||
class BarcodeCepnet : public BarcodePostnet
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Static CEPNET barcode creation method
|
||||
*
|
||||
* Used by glbarcode::BarcodeFactory
|
||||
*/
|
||||
static Barcode* create();
|
||||
|
||||
|
||||
private:
|
||||
bool validateDigits( int nDigits ) override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_BarcodeCepnet_hpp
|
||||
+229
-228
@@ -1,26 +1,27 @@
|
||||
/* BarcodeCode39.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// BarcodeCode39.cpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#include "BarcodeCode39.h"
|
||||
|
||||
#include "Constants.h"
|
||||
#include "BarcodeCode39.hpp"
|
||||
|
||||
#include "Constants.hpp"
|
||||
|
||||
#include <cctype>
|
||||
#include <algorithm>
|
||||
@@ -31,68 +32,68 @@ using namespace glbarcode::Constants;
|
||||
|
||||
namespace
|
||||
{
|
||||
/* Code 39 alphabet. Position indicates value. */
|
||||
const std::string alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%";
|
||||
/* Code 39 alphabet. Position indicates value. */
|
||||
const std::string alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%";
|
||||
|
||||
/* Code 39 symbols. Position must match position in alphabet. */
|
||||
const std::string symbols[] = {
|
||||
/* BsBsBsBsB */
|
||||
/* 0 */ "NnNwWnWnN",
|
||||
/* 1 */ "WnNwNnNnW",
|
||||
/* 2 */ "NnWwNnNnW",
|
||||
/* 3 */ "WnWwNnNnN",
|
||||
/* 4 */ "NnNwWnNnW",
|
||||
/* 5 */ "WnNwWnNnN",
|
||||
/* 6 */ "NnWwWnNnN",
|
||||
/* 7 */ "NnNwNnWnW",
|
||||
/* 8 */ "WnNwNnWnN",
|
||||
/* 9 */ "NnWwNnWnN",
|
||||
/* A */ "WnNnNwNnW",
|
||||
/* B */ "NnWnNwNnW",
|
||||
/* C */ "WnWnNwNnN",
|
||||
/* D */ "NnNnWwNnW",
|
||||
/* E */ "WnNnWwNnN",
|
||||
/* F */ "NnWnWwNnN",
|
||||
/* G */ "NnNnNwWnW",
|
||||
/* H */ "WnNnNwWnN",
|
||||
/* I */ "NnWnNwWnN",
|
||||
/* J */ "NnNnWwWnN",
|
||||
/* K */ "WnNnNnNwW",
|
||||
/* L */ "NnWnNnNwW",
|
||||
/* M */ "WnWnNnNwN",
|
||||
/* N */ "NnNnWnNwW",
|
||||
/* O */ "WnNnWnNwN",
|
||||
/* P */ "NnWnWnNwN",
|
||||
/* Q */ "NnNnNnWwW",
|
||||
/* R */ "WnNnNnWwN",
|
||||
/* S */ "NnWnNnWwN",
|
||||
/* T */ "NnNnWnWwN",
|
||||
/* U */ "WwNnNnNnW",
|
||||
/* V */ "NwWnNnNnW",
|
||||
/* W */ "WwWnNnNnN",
|
||||
/* X */ "NwNnWnNnW",
|
||||
/* Y */ "WwNnWnNnN",
|
||||
/* Z */ "NwWnWnNnN",
|
||||
/* - */ "NwNnNnWnW",
|
||||
/* . */ "WwNnNnWnN",
|
||||
/* */ "NwWnNnWnN",
|
||||
/* $ */ "NwNwNwNnN",
|
||||
/* / */ "NwNwNnNwN",
|
||||
/* + */ "NwNnNwNwN",
|
||||
/* % */ "NnNwNwNwN"
|
||||
};
|
||||
/* Code 39 symbols. Position must match position in alphabet. */
|
||||
const std::string symbols[] = {
|
||||
/* BsBsBsBsB */
|
||||
/* 0 */ "NnNwWnWnN",
|
||||
/* 1 */ "WnNwNnNnW",
|
||||
/* 2 */ "NnWwNnNnW",
|
||||
/* 3 */ "WnWwNnNnN",
|
||||
/* 4 */ "NnNwWnNnW",
|
||||
/* 5 */ "WnNwWnNnN",
|
||||
/* 6 */ "NnWwWnNnN",
|
||||
/* 7 */ "NnNwNnWnW",
|
||||
/* 8 */ "WnNwNnWnN",
|
||||
/* 9 */ "NnWwNnWnN",
|
||||
/* A */ "WnNnNwNnW",
|
||||
/* B */ "NnWnNwNnW",
|
||||
/* C */ "WnWnNwNnN",
|
||||
/* D */ "NnNnWwNnW",
|
||||
/* E */ "WnNnWwNnN",
|
||||
/* F */ "NnWnWwNnN",
|
||||
/* G */ "NnNnNwWnW",
|
||||
/* H */ "WnNnNwWnN",
|
||||
/* I */ "NnWnNwWnN",
|
||||
/* J */ "NnNnWwWnN",
|
||||
/* K */ "WnNnNnNwW",
|
||||
/* L */ "NnWnNnNwW",
|
||||
/* M */ "WnWnNnNwN",
|
||||
/* N */ "NnNnWnNwW",
|
||||
/* O */ "WnNnWnNwN",
|
||||
/* P */ "NnWnWnNwN",
|
||||
/* Q */ "NnNnNnWwW",
|
||||
/* R */ "WnNnNnWwN",
|
||||
/* S */ "NnWnNnWwN",
|
||||
/* T */ "NnNnWnWwN",
|
||||
/* U */ "WwNnNnNnW",
|
||||
/* V */ "NwWnNnNnW",
|
||||
/* W */ "WwWnNnNnN",
|
||||
/* X */ "NwNnWnNnW",
|
||||
/* Y */ "WwNnWnNnN",
|
||||
/* Z */ "NwWnWnNnN",
|
||||
/* - */ "NwNnNnWnW",
|
||||
/* . */ "WwNnNnWnN",
|
||||
/* */ "NwWnNnWnN",
|
||||
/* $ */ "NwNwNwNnN",
|
||||
/* / */ "NwNwNnNwN",
|
||||
/* + */ "NwNnNwNwN",
|
||||
/* % */ "NnNwNwNwN"
|
||||
};
|
||||
|
||||
const std::string frameSymbol = "NwNnWnWnN";
|
||||
const std::string frameSymbol = "NwNnWnWnN";
|
||||
|
||||
/* Vectorization constants */
|
||||
const double MIN_X = ( 0.0075 * PTS_PER_INCH );
|
||||
const double N = 2.5;
|
||||
const double MIN_I = MIN_X;
|
||||
const double MIN_HEIGHT = ( 0.19685 * PTS_PER_INCH );
|
||||
const double MIN_QUIET = ( 10 * MIN_X );
|
||||
/* Vectorization constants */
|
||||
const double MIN_X = ( 0.0075 * PTS_PER_INCH );
|
||||
const double N = 2.5;
|
||||
const double MIN_I = MIN_X;
|
||||
const double MIN_HEIGHT = ( 0.19685 * PTS_PER_INCH );
|
||||
const double MIN_QUIET = ( 10 * MIN_X );
|
||||
|
||||
const double MIN_TEXT_AREA_HEIGHT = 12.0;
|
||||
const double MIN_TEXT_SIZE = 8.0;
|
||||
const double MIN_TEXT_AREA_HEIGHT = 12.0;
|
||||
const double MIN_TEXT_SIZE = 8.0;
|
||||
|
||||
}
|
||||
|
||||
@@ -100,188 +101,188 @@ namespace
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/*
|
||||
* Static Code39 barcode creation method
|
||||
*/
|
||||
Barcode* BarcodeCode39::create( )
|
||||
{
|
||||
return new BarcodeCode39();
|
||||
}
|
||||
/*
|
||||
* Static Code39 barcode creation method
|
||||
*/
|
||||
Barcode* BarcodeCode39::create( )
|
||||
{
|
||||
return new BarcodeCode39();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Code39 data validation, implements Barcode1dBase::validate()
|
||||
*/
|
||||
bool BarcodeCode39::validate( const std::string& rawData )
|
||||
{
|
||||
for (char r : rawData)
|
||||
{
|
||||
char c = toupper( r );
|
||||
/*
|
||||
* Code39 data validation, implements Barcode1dBase::validate()
|
||||
*/
|
||||
bool BarcodeCode39::validate( const std::string& rawData )
|
||||
{
|
||||
for (char r : rawData)
|
||||
{
|
||||
char c = toupper( r );
|
||||
|
||||
if ( alphabet.find(c) == std::string::npos )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ( alphabet.find(c) == std::string::npos )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Code39 data encoding, implements Barcode1dBase::encode()
|
||||
*/
|
||||
std::string BarcodeCode39::encode( const std::string& cookedData )
|
||||
{
|
||||
std::string code;
|
||||
/*
|
||||
* Code39 data encoding, implements Barcode1dBase::encode()
|
||||
*/
|
||||
std::string BarcodeCode39::encode( const std::string& cookedData )
|
||||
{
|
||||
std::string code;
|
||||
|
||||
/* Left frame symbol */
|
||||
code += frameSymbol;
|
||||
code += "i";
|
||||
/* Left frame symbol */
|
||||
code += frameSymbol;
|
||||
code += "i";
|
||||
|
||||
int sum = 0;
|
||||
for (char c : cookedData)
|
||||
{
|
||||
size_t cValue = alphabet.find( toupper( c ) );
|
||||
int sum = 0;
|
||||
for (char c : cookedData)
|
||||
{
|
||||
size_t cValue = alphabet.find( toupper( c ) );
|
||||
|
||||
code += symbols[cValue];
|
||||
code += "i";
|
||||
code += symbols[cValue];
|
||||
code += "i";
|
||||
|
||||
sum += int(cValue);
|
||||
}
|
||||
sum += int(cValue);
|
||||
}
|
||||
|
||||
if ( checksum() )
|
||||
{
|
||||
code += symbols[sum % 43];
|
||||
code += "i";
|
||||
}
|
||||
if ( checksum() )
|
||||
{
|
||||
code += symbols[sum % 43];
|
||||
code += "i";
|
||||
}
|
||||
|
||||
/* Right frame bar */
|
||||
code += frameSymbol;
|
||||
/* Right frame bar */
|
||||
code += frameSymbol;
|
||||
|
||||
return code;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Code39 prepare text for display, implements Barcode1dBase::prepareText()
|
||||
*/
|
||||
std::string BarcodeCode39::prepareText( const std::string& rawData )
|
||||
{
|
||||
std::string displayText;
|
||||
/*
|
||||
* Code39 prepare text for display, implements Barcode1dBase::prepareText()
|
||||
*/
|
||||
std::string BarcodeCode39::prepareText( const std::string& rawData )
|
||||
{
|
||||
std::string displayText;
|
||||
|
||||
for (char c : rawData)
|
||||
{
|
||||
displayText += toupper( c );
|
||||
}
|
||||
for (char c : rawData)
|
||||
{
|
||||
displayText += toupper( c );
|
||||
}
|
||||
|
||||
return displayText;
|
||||
}
|
||||
return displayText;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Code39 vectorization, implements Barcode1dBase::vectorize()
|
||||
*/
|
||||
void BarcodeCode39::vectorize( const std::string& codedData,
|
||||
const std::string& displayText,
|
||||
const std::string& cookedData,
|
||||
double& w,
|
||||
double& h )
|
||||
{
|
||||
/*
|
||||
* Code39 vectorization, implements Barcode1dBase::vectorize()
|
||||
*/
|
||||
void BarcodeCode39::vectorize( const std::string& codedData,
|
||||
const std::string& displayText,
|
||||
const std::string& cookedData,
|
||||
double& w,
|
||||
double& h )
|
||||
{
|
||||
|
||||
/* determine width and establish horizontal scale, based on original cooked data */
|
||||
auto dataSize = double( cookedData.size() );
|
||||
double minL;
|
||||
if ( !checksum() )
|
||||
{
|
||||
minL = (dataSize + 2)*(3*N + 6)*MIN_X + (dataSize + 1)*MIN_I;
|
||||
}
|
||||
else
|
||||
{
|
||||
minL = (dataSize + 3)*(3*N + 6)*MIN_X + (dataSize + 2)*MIN_I;
|
||||
}
|
||||
|
||||
double scale;
|
||||
if ( w == 0 )
|
||||
{
|
||||
scale = 1.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
scale = w / (minL + 2*MIN_QUIET);
|
||||
/* determine width and establish horizontal scale, based on original cooked data */
|
||||
auto dataSize = double( cookedData.size() );
|
||||
double minL;
|
||||
if ( !checksum() )
|
||||
{
|
||||
minL = (dataSize + 2)*(3*N + 6)*MIN_X + (dataSize + 1)*MIN_I;
|
||||
}
|
||||
else
|
||||
{
|
||||
minL = (dataSize + 3)*(3*N + 6)*MIN_X + (dataSize + 2)*MIN_I;
|
||||
}
|
||||
|
||||
if ( scale < 1.0 )
|
||||
{
|
||||
scale = 1.0;
|
||||
}
|
||||
}
|
||||
double width = minL * scale;
|
||||
double scale;
|
||||
if ( w == 0 )
|
||||
{
|
||||
scale = 1.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
scale = w / (minL + 2*MIN_QUIET);
|
||||
|
||||
/* determine text parameters */
|
||||
double hTextArea = scale * MIN_TEXT_AREA_HEIGHT;
|
||||
double textSize = scale * MIN_TEXT_SIZE;
|
||||
if ( scale < 1.0 )
|
||||
{
|
||||
scale = 1.0;
|
||||
}
|
||||
}
|
||||
double width = minL * scale;
|
||||
|
||||
/* determine height of barcode */
|
||||
double height = showText() ? h - hTextArea : h;
|
||||
height = std::max( height, std::max( 0.15*width, MIN_HEIGHT ) );
|
||||
/* determine text parameters */
|
||||
double hTextArea = scale * MIN_TEXT_AREA_HEIGHT;
|
||||
double textSize = scale * MIN_TEXT_SIZE;
|
||||
|
||||
/* determine horizontal quiet zone */
|
||||
double xQuiet = std::max( (10 * scale * MIN_X), MIN_QUIET );
|
||||
/* determine height of barcode */
|
||||
double height = showText() ? h - hTextArea : h;
|
||||
height = std::max( height, std::max( 0.15*width, MIN_HEIGHT ) );
|
||||
|
||||
/* Now traverse the code string and draw each bar */
|
||||
double x1 = xQuiet;
|
||||
for (char c : codedData)
|
||||
{
|
||||
double lwidth;
|
||||
|
||||
switch ( c )
|
||||
{
|
||||
/* determine horizontal quiet zone */
|
||||
double xQuiet = std::max( (10 * scale * MIN_X), MIN_QUIET );
|
||||
|
||||
case 'i':
|
||||
/* Inter-character gap */
|
||||
x1 += scale * MIN_I;
|
||||
break;
|
||||
/* Now traverse the code string and draw each bar */
|
||||
double x1 = xQuiet;
|
||||
for (char c : codedData)
|
||||
{
|
||||
double lwidth;
|
||||
|
||||
case 'N':
|
||||
/* Narrow bar */
|
||||
lwidth = scale*MIN_X;
|
||||
addLine( x1, 0.0, lwidth, height );
|
||||
x1 += scale * MIN_X;
|
||||
break;
|
||||
switch ( c )
|
||||
{
|
||||
|
||||
case 'W':
|
||||
/* Wide bar */
|
||||
lwidth = scale*N*MIN_X;
|
||||
addLine( x1, 0.0, lwidth, height );
|
||||
x1 += scale * N * MIN_X;
|
||||
break;
|
||||
case 'i':
|
||||
/* Inter-character gap */
|
||||
x1 += scale * MIN_I;
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
/* Narrow space */
|
||||
x1 += scale * MIN_X;
|
||||
break;
|
||||
case 'N':
|
||||
/* Narrow bar */
|
||||
lwidth = scale*MIN_X;
|
||||
addLine( x1, 0.0, lwidth, height );
|
||||
x1 += scale * MIN_X;
|
||||
break;
|
||||
|
||||
case 'w':
|
||||
/* Wide space */
|
||||
x1 += scale * N * MIN_X;
|
||||
break;
|
||||
case 'W':
|
||||
/* Wide bar */
|
||||
lwidth = scale*N*MIN_X;
|
||||
addLine( x1, 0.0, lwidth, height );
|
||||
x1 += scale * N * MIN_X;
|
||||
break;
|
||||
|
||||
default:
|
||||
// NOT REACHED
|
||||
break;
|
||||
}
|
||||
}
|
||||
case 'n':
|
||||
/* Narrow space */
|
||||
x1 += scale * MIN_X;
|
||||
break;
|
||||
|
||||
if ( showText() )
|
||||
{
|
||||
std::string starredText = "*" + displayText + "*";
|
||||
addText( xQuiet + width/2, height + (hTextArea+0.7*textSize)/2, textSize, starredText );
|
||||
}
|
||||
case 'w':
|
||||
/* Wide space */
|
||||
x1 += scale * N * MIN_X;
|
||||
break;
|
||||
|
||||
/* Overwrite requested size with actual size. */
|
||||
w = width + 2*xQuiet;
|
||||
h = showText() ? height + hTextArea : height;
|
||||
default:
|
||||
// NOT REACHED
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if ( showText() )
|
||||
{
|
||||
std::string starredText = "*" + displayText + "*";
|
||||
addText( xQuiet + width/2, height + (hTextArea+0.7*textSize)/2, textSize, starredText );
|
||||
}
|
||||
|
||||
/* Overwrite requested size with actual size. */
|
||||
w = width + 2*xQuiet;
|
||||
h = showText() ? height + hTextArea : height;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,100 +0,0 @@
|
||||
/* BarcodeCode39.h
|
||||
*
|
||||
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glbarcode_BarcodeCode39_h
|
||||
#define glbarcode_BarcodeCode39_h
|
||||
|
||||
|
||||
#include "Barcode1dBase.h"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/**
|
||||
* @class BarcodeCode39 BarcodeCode39.h glbarcode/BarcodeCode39.h
|
||||
*
|
||||
* *Code 39* 1D barcode symbology.
|
||||
*
|
||||
* @image html sample-code39.svg "Sample Code 39 Barcode"
|
||||
*
|
||||
*
|
||||
* ### Input Data Format ###
|
||||
*
|
||||
* The *Code 39* specification defines 43 characters, consisting of upper
|
||||
* case letters (A-Z), decimal digits (0-9), space, and several special
|
||||
* characters (-.$/+%). The BarcodeCode39 validator will also accept
|
||||
* lower case letters (a-z). The encoder will automatically upshift
|
||||
* any lower case letters prior to encoding.
|
||||
*
|
||||
* For full ASCII support see BarcodeCode39Ext.
|
||||
*
|
||||
*
|
||||
* ### Checksum Property ###
|
||||
*
|
||||
* If the *checksum* property is *true*, a modulo 43 check digit will be
|
||||
* automatically generated and appended to input data before encoding.
|
||||
* By default, the check digit will not be generated.
|
||||
*
|
||||
* See setChecksum().
|
||||
*
|
||||
*
|
||||
* ### Show Text Property ###
|
||||
*
|
||||
* If the *Show Text* property is *true*, the input data will be printed
|
||||
* below the barcode. By default, the data will not be printed.
|
||||
*
|
||||
* See setShowText().
|
||||
*
|
||||
*
|
||||
* ### References ###
|
||||
*
|
||||
* - http://en.wikipedia.org/wiki/Code_39
|
||||
*
|
||||
*/
|
||||
class BarcodeCode39 : public Barcode1dBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Static Code39 barcode creation method
|
||||
*
|
||||
* Used by glbarcode::BarcodeFactory
|
||||
*/
|
||||
static Barcode* create();
|
||||
|
||||
|
||||
private:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
|
||||
std::string prepareText( const std::string& rawData ) override;
|
||||
|
||||
void vectorize( const std::string& codedData,
|
||||
const std::string& displayText,
|
||||
const std::string& cookedData,
|
||||
double& w,
|
||||
double& h ) override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_BarcodeCode39_h
|
||||
@@ -0,0 +1,100 @@
|
||||
// BarcodeCode39.hpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#ifndef glbarcode_BarcodeCode39_hpp
|
||||
#define glbarcode_BarcodeCode39_hpp
|
||||
|
||||
|
||||
#include "Barcode1dBase.hpp"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/**
|
||||
* @class BarcodeCode39 BarcodeCode39.h glbarcode/BarcodeCode39.h
|
||||
*
|
||||
* *Code 39* 1D barcode symbology.
|
||||
*
|
||||
* @image html sample-code39.svg "Sample Code 39 Barcode"
|
||||
*
|
||||
*
|
||||
* ### Input Data Format ###
|
||||
*
|
||||
* The *Code 39* specification defines 43 characters, consisting of upper
|
||||
* case letters (A-Z), decimal digits (0-9), space, and several special
|
||||
* characters (-.$/+%). The BarcodeCode39 validator will also accept
|
||||
* lower case letters (a-z). The encoder will automatically upshift
|
||||
* any lower case letters prior to encoding.
|
||||
*
|
||||
* For full ASCII support see BarcodeCode39Ext.
|
||||
*
|
||||
*
|
||||
* ### Checksum Property ###
|
||||
*
|
||||
* If the *checksum* property is *true*, a modulo 43 check digit will be
|
||||
* automatically generated and appended to input data before encoding.
|
||||
* By default, the check digit will not be generated.
|
||||
*
|
||||
* See setChecksum().
|
||||
*
|
||||
*
|
||||
* ### Show Text Property ###
|
||||
*
|
||||
* If the *Show Text* property is *true*, the input data will be printed
|
||||
* below the barcode. By default, the data will not be printed.
|
||||
*
|
||||
* See setShowText().
|
||||
*
|
||||
*
|
||||
* ### References ###
|
||||
*
|
||||
* - http://en.wikipedia.org/wiki/Code_39
|
||||
*
|
||||
*/
|
||||
class BarcodeCode39 : public Barcode1dBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Static Code39 barcode creation method
|
||||
*
|
||||
* Used by glbarcode::BarcodeFactory
|
||||
*/
|
||||
static Barcode* create();
|
||||
|
||||
|
||||
private:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
|
||||
std::string prepareText( const std::string& rawData ) override;
|
||||
|
||||
void vectorize( const std::string& codedData,
|
||||
const std::string& displayText,
|
||||
const std::string& cookedData,
|
||||
double& w,
|
||||
double& h ) override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_BarcodeCode39_hpp
|
||||
@@ -1,118 +1,119 @@
|
||||
/* BarcodeCode39Ext.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// BarcodeCode39Ext.cpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#include "BarcodeCode39Ext.h"
|
||||
|
||||
#include "BarcodeCode39Ext.hpp"
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
/* Code 39Ext ASCII map. */
|
||||
const std::string asciiMap[] = {
|
||||
/* NUL */ "%U", /* SOH */ "$A", /* STX */ "$B", /* ETX */ "$C",
|
||||
/* EOT */ "$D", /* ENQ */ "$E", /* ACK */ "$F", /* BEL */ "$G",
|
||||
/* BS */ "$H", /* HT */ "$I", /* LF */ "$J", /* VT */ "$K",
|
||||
/* FF */ "$L", /* CR */ "$M", /* SO */ "$N", /* SI */ "$O",
|
||||
/* DLE */ "$P", /* DC1 */ "$Q", /* DC2 */ "$R", /* DC3 */ "$S",
|
||||
/* DC4 */ "$T", /* NAK */ "$U", /* SYN */ "$V", /* ETB */ "$W",
|
||||
/* CAN */ "$X", /* EM */ "$Y", /* SUB */ "$Z", /* ESC */ "%A",
|
||||
/* FS */ "%B", /* GS */ "%C", /* RS */ "%D", /* US */ "%E",
|
||||
/* " " */ " ", /* ! */ "/A", /* " */ "/B", /* # */ "/C",
|
||||
/* $ */ "/D", /* % */ "/E", /* & */ "/F", /* ' */ "/G",
|
||||
/* ( */ "/H", /* ) */ "/I", /* * */ "/J", /* + */ "/K",
|
||||
/* , */ "/L", /* - */ "-", /* . */ ".", /* / */ "/O",
|
||||
/* 0 */ "0", /* 1 */ "1", /* 2 */ "2", /* 3 */ "3",
|
||||
/* 4 */ "4", /* 5 */ "5", /* 6 */ "6", /* 7 */ "7",
|
||||
/* 8 */ "8", /* 9 */ "9", /* : */ "/Z", /* ; */ "%F",
|
||||
/* < */ "%G", /* = */ "%H", /* > */ "%I", /* ? */ "%J",
|
||||
/* @ */ "%V", /* A */ "A", /* B */ "B", /* C */ "C",
|
||||
/* D */ "D", /* E */ "E", /* F */ "F", /* G */ "G",
|
||||
/* H */ "H", /* I */ "I", /* J */ "J", /* K */ "K",
|
||||
/* L */ "L", /* M */ "M", /* N */ "N", /* O */ "O",
|
||||
/* P */ "P", /* Q */ "Q", /* R */ "R", /* S */ "S",
|
||||
/* T */ "T", /* U */ "U", /* V */ "V", /* W */ "W",
|
||||
/* X */ "X", /* Y */ "Y", /* Z */ "Z", /* [ */ "%K",
|
||||
/* \ */ "%L", /* ] */ "%M", /* ^ */ "%N", /* _ */ "%O",
|
||||
/* ` */ "%W", /* a */ "+A", /* b */ "+B", /* c */ "+C",
|
||||
/* d */ "+D", /* e */ "+E", /* f */ "+F", /* g */ "+G",
|
||||
/* h */ "+H", /* i */ "+I", /* j */ "+J", /* k */ "+K",
|
||||
/* l */ "+L", /* m */ "+M", /* n */ "+N", /* o */ "+O",
|
||||
/* p */ "+P", /* q */ "+Q", /* r */ "+R", /* s */ "+S",
|
||||
/* t */ "+T", /* u */ "+U", /* v */ "+V", /* w */ "+W",
|
||||
/* x */ "+X", /* y */ "+Y", /* z */ "+Z", /* { */ "%P",
|
||||
/* | */ "%Q", /* } */ "%R", /* ~ */ "%S", /* DEL */ "%T"
|
||||
};
|
||||
/* Code 39Ext ASCII map. */
|
||||
const std::string asciiMap[] = {
|
||||
/* NUL */ "%U", /* SOH */ "$A", /* STX */ "$B", /* ETX */ "$C",
|
||||
/* EOT */ "$D", /* ENQ */ "$E", /* ACK */ "$F", /* BEL */ "$G",
|
||||
/* BS */ "$H", /* HT */ "$I", /* LF */ "$J", /* VT */ "$K",
|
||||
/* FF */ "$L", /* CR */ "$M", /* SO */ "$N", /* SI */ "$O",
|
||||
/* DLE */ "$P", /* DC1 */ "$Q", /* DC2 */ "$R", /* DC3 */ "$S",
|
||||
/* DC4 */ "$T", /* NAK */ "$U", /* SYN */ "$V", /* ETB */ "$W",
|
||||
/* CAN */ "$X", /* EM */ "$Y", /* SUB */ "$Z", /* ESC */ "%A",
|
||||
/* FS */ "%B", /* GS */ "%C", /* RS */ "%D", /* US */ "%E",
|
||||
/* " " */ " ", /* ! */ "/A", /* " */ "/B", /* # */ "/C",
|
||||
/* $ */ "/D", /* % */ "/E", /* & */ "/F", /* ' */ "/G",
|
||||
/* ( */ "/H", /* ) */ "/I", /* * */ "/J", /* + */ "/K",
|
||||
/* , */ "/L", /* - */ "-", /* . */ ".", /* / */ "/O",
|
||||
/* 0 */ "0", /* 1 */ "1", /* 2 */ "2", /* 3 */ "3",
|
||||
/* 4 */ "4", /* 5 */ "5", /* 6 */ "6", /* 7 */ "7",
|
||||
/* 8 */ "8", /* 9 */ "9", /* : */ "/Z", /* ; */ "%F",
|
||||
/* < */ "%G", /* = */ "%H", /* > */ "%I", /* ? */ "%J",
|
||||
/* @ */ "%V", /* A */ "A", /* B */ "B", /* C */ "C",
|
||||
/* D */ "D", /* E */ "E", /* F */ "F", /* G */ "G",
|
||||
/* H */ "H", /* I */ "I", /* J */ "J", /* K */ "K",
|
||||
/* L */ "L", /* M */ "M", /* N */ "N", /* O */ "O",
|
||||
/* P */ "P", /* Q */ "Q", /* R */ "R", /* S */ "S",
|
||||
/* T */ "T", /* U */ "U", /* V */ "V", /* W */ "W",
|
||||
/* X */ "X", /* Y */ "Y", /* Z */ "Z", /* [ */ "%K",
|
||||
/* \ */ "%L", /* ] */ "%M", /* ^ */ "%N", /* _ */ "%O",
|
||||
/* ` */ "%W", /* a */ "+A", /* b */ "+B", /* c */ "+C",
|
||||
/* d */ "+D", /* e */ "+E", /* f */ "+F", /* g */ "+G",
|
||||
/* h */ "+H", /* i */ "+I", /* j */ "+J", /* k */ "+K",
|
||||
/* l */ "+L", /* m */ "+M", /* n */ "+N", /* o */ "+O",
|
||||
/* p */ "+P", /* q */ "+Q", /* r */ "+R", /* s */ "+S",
|
||||
/* t */ "+T", /* u */ "+U", /* v */ "+V", /* w */ "+W",
|
||||
/* x */ "+X", /* y */ "+Y", /* z */ "+Z", /* { */ "%P",
|
||||
/* | */ "%Q", /* } */ "%R", /* ~ */ "%S", /* DEL */ "%T"
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/*
|
||||
* Static Extended Code39 barcode creation method
|
||||
*/
|
||||
Barcode* BarcodeCode39Ext::create( )
|
||||
{
|
||||
return new BarcodeCode39Ext();
|
||||
}
|
||||
/*
|
||||
* Static Extended Code39 barcode creation method
|
||||
*/
|
||||
Barcode* BarcodeCode39Ext::create( )
|
||||
{
|
||||
return new BarcodeCode39Ext();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Extended Code39 data validation, overrides BarcodeCode39::validate() implementation
|
||||
*/
|
||||
bool BarcodeCode39Ext::validate( const std::string& rawData )
|
||||
{
|
||||
for (char c : rawData)
|
||||
{
|
||||
if ( c < 0 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Extended Code39 data validation, overrides BarcodeCode39::validate() implementation
|
||||
*/
|
||||
bool BarcodeCode39Ext::validate( const std::string& rawData )
|
||||
{
|
||||
for (char c : rawData)
|
||||
{
|
||||
if ( c < 0 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Extened Code39 preprocessing of data, implements Barcode1dBase::preprocess()
|
||||
*/
|
||||
std::string BarcodeCode39Ext::preprocess( const std::string& rawData )
|
||||
{
|
||||
std::string cookedData;
|
||||
/*
|
||||
* Extened Code39 preprocessing of data, implements Barcode1dBase::preprocess()
|
||||
*/
|
||||
std::string BarcodeCode39Ext::preprocess( const std::string& rawData )
|
||||
{
|
||||
std::string cookedData;
|
||||
|
||||
for (char c : rawData)
|
||||
{
|
||||
cookedData += asciiMap[ int(c) ];
|
||||
}
|
||||
for (char c : rawData)
|
||||
{
|
||||
cookedData += asciiMap[ int(c) ];
|
||||
}
|
||||
|
||||
return cookedData;
|
||||
}
|
||||
return cookedData;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Extended Code39 prepare text for display, overrides BarcodeCode39::prepareText()
|
||||
*/
|
||||
std::string BarcodeCode39Ext::prepareText( const std::string& rawData )
|
||||
{
|
||||
return rawData;
|
||||
}
|
||||
/*
|
||||
* Extended Code39 prepare text for display, overrides BarcodeCode39::prepareText()
|
||||
*/
|
||||
std::string BarcodeCode39Ext::prepareText( const std::string& rawData )
|
||||
{
|
||||
return rawData;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,132 +0,0 @@
|
||||
/* BarcodeCode39Ext.h
|
||||
*
|
||||
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glbarcode_BarcodeCode39Ext_h
|
||||
#define glbarcode_BarcodeCode39Ext_h
|
||||
|
||||
|
||||
#include "BarcodeCode39.h"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/**
|
||||
* @class BarcodeCode39Ext BarcodeCode39Ext.h glbarcode/BarcodeCode39Ext.h
|
||||
*
|
||||
* Extended *Code 39* 1D barcode symbology.
|
||||
*
|
||||
* @image html sample-code39ext.svg "Sample Extended Code 39 Barcode"
|
||||
*
|
||||
*
|
||||
* ### Input Data Format ###
|
||||
*
|
||||
* The extended *Code 39* barcode type supports the full 7-bit ASCII
|
||||
* character set (0-127). This support is accomplished by encoding
|
||||
* lower case letters, constrol characters, and special characters
|
||||
* other than "-" and "." as two character sequences as illustrated
|
||||
* in the following table:
|
||||
*
|
||||
* | Dec | Char | Enc || Dec | Char | Enc || Dec | Char | Enc || Dec | Char | Enc |
|
||||
* |----:|:----:|:---:||----:|:----:|:---:||----:|:----:|:---:||----:|:----:|:---:|
|
||||
* | 0 | NUL | %%U || 32 | \" \"|\" \"|| 64 | @ | %%V || 96 | ` | %%W |
|
||||
* | 1 | SOH | $A || 33 | ! | /A || 65 | A | A || 97 | a | +A |
|
||||
* | 2 | STX | $B || 34 | \" | /B || 66 | B | B || 98 | b | +B |
|
||||
* | 3 | ETX | $C || 35 | # | /C || 67 | C | C || 99 | c | +C |
|
||||
* | 4 | EOT | $D || 36 | $ | /D || 68 | D | D || 100 | d | +D |
|
||||
* | 5 | ENQ | $E || 37 | % | /E || 69 | E | E || 101 | e | +E |
|
||||
* | 6 | ACK | $F || 38 | & | /F || 70 | F | F || 102 | f | +F |
|
||||
* | 7 | BEL | $G || 39 | ' | /G || 71 | G | G || 103 | g | +G |
|
||||
* | 8 | BS | $H || 40 | ( | /H || 72 | H | H || 104 | h | +H |
|
||||
* | 9 | HT | $I || 41 | ) | /I || 73 | I | I || 105 | i | +I |
|
||||
* | 10 | LF | $J || 42 | * | /J || 74 | J | J || 106 | j | +J |
|
||||
* | 11 | VT | $K || 43 | + | /K || 75 | K | K || 107 | k | +K |
|
||||
* | 12 | FF | $L || 44 | , | /L || 76 | L | L || 108 | l | +L |
|
||||
* | 13 | CR | $M || 45 | - | - || 77 | M | M || 109 | m | +M |
|
||||
* | 14 | SO | $N || 46 | . | . || 78 | N | N || 110 | n | +N |
|
||||
* | 15 | SI | $O || 47 | / | /O || 79 | O | O || 111 | o | +O |
|
||||
* | 16 | DLE | $P || 48 | 0 | 0 || 80 | P | P || 112 | p | +P |
|
||||
* | 17 | DC1 | $Q || 49 | 1 | 1 || 81 | Q | Q || 113 | q | +Q |
|
||||
* | 18 | DC2 | $R || 50 | 2 | 2 || 82 | R | R || 114 | r | +R |
|
||||
* | 19 | DC3 | $S || 51 | 3 | 3 || 83 | S | S || 115 | s | +S |
|
||||
* | 20 | DC4 | $T || 52 | 4 | 4 || 84 | T | T || 116 | t | +T |
|
||||
* | 21 | NAK | $U || 53 | 5 | 5 || 85 | U | U || 117 | u | +U |
|
||||
* | 22 | SYN | $V || 54 | 6 | 6 || 86 | V | V || 118 | v | +V |
|
||||
* | 23 | ETB | $W || 55 | 7 | 7 || 87 | W | W || 119 | w | +W |
|
||||
* | 24 | CAN | $X || 56 | 8 | 8 || 88 | X | X || 120 | x | +X |
|
||||
* | 25 | EM | $Y || 57 | 9 | 9 || 89 | Y | Y || 121 | y | +Y |
|
||||
* | 26 | SUB | $Z || 58 | : | /Z || 90 | Z | Z || 122 | z | +Z |
|
||||
* | 27 | ESC | %%A || 59 | ; | %%F || 91 | [ | %%K || 123 | { | %%P |
|
||||
* | 28 | FS | %%B || 60 | < | %%G || 92 | \\ | %%L || 124 | \| | %%Q |
|
||||
* | 29 | GS | %%C || 61 | = | %%H || 93 | ] | %%M || 125 | } | %%R |
|
||||
* | 30 | RS | %%D || 62 | > | %%I || 94 | ^ | %%N || 126 | ~ | %%S |
|
||||
* | 31 | US | %%E || 63 | ? | %%J || 95 | _ | %%O || 127 | DEL | %%T |
|
||||
*
|
||||
* This pre-encoded data is now encoded using the standard *Code 39* symbology.
|
||||
*
|
||||
*
|
||||
* ### Checksum Property ###
|
||||
*
|
||||
* If the *checksum* property is *true*, a modulo 43 check digit will be
|
||||
* automatically generated and appended to the 1st pass encoded data
|
||||
* prior to the 2nd pass *Code 39* encoding. By default, the check digit
|
||||
* will not be generated.
|
||||
*
|
||||
* See setChecksum().
|
||||
*
|
||||
*
|
||||
* ### Show Text Property ###
|
||||
*
|
||||
* If the *Show Text* property is *true*, the original ASCII input data will
|
||||
* be printed below the barcode. By default, the data will not be printed.
|
||||
*
|
||||
* See setShowText().
|
||||
*
|
||||
*
|
||||
* ### References ###
|
||||
*
|
||||
* - http://en.wikipedia.org/wiki/Code_39
|
||||
*
|
||||
*
|
||||
*/
|
||||
class BarcodeCode39Ext : public BarcodeCode39
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Static Extended Code39 barcode creation method
|
||||
*
|
||||
* Used by glbarcode::BarcodeFactory
|
||||
*/
|
||||
static Barcode* create();
|
||||
|
||||
|
||||
private:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
|
||||
std::string preprocess( const std::string& rawData ) override;
|
||||
|
||||
std::string prepareText( const std::string& rawData ) override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_BarcodeCode39Ext_h
|
||||
@@ -0,0 +1,132 @@
|
||||
// BarcodeCode39Ext.hpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#ifndef glbarcode_BarcodeCode39Ext_hpp
|
||||
#define glbarcode_BarcodeCode39Ext_hpp
|
||||
|
||||
|
||||
#include "BarcodeCode39.hpp"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/**
|
||||
* @class BarcodeCode39Ext BarcodeCode39Ext.h glbarcode/BarcodeCode39Ext.h
|
||||
*
|
||||
* Extended *Code 39* 1D barcode symbology.
|
||||
*
|
||||
* @image html sample-code39ext.svg "Sample Extended Code 39 Barcode"
|
||||
*
|
||||
*
|
||||
* ### Input Data Format ###
|
||||
*
|
||||
* The extended *Code 39* barcode type supports the full 7-bit ASCII
|
||||
* character set (0-127). This support is accomplished by encoding
|
||||
* lower case letters, constrol characters, and special characters
|
||||
* other than "-" and "." as two character sequences as illustrated
|
||||
* in the following table:
|
||||
*
|
||||
* | Dec | Char | Enc || Dec | Char | Enc || Dec | Char | Enc || Dec | Char | Enc |
|
||||
* |----:|:----:|:---:||----:|:----:|:---:||----:|:----:|:---:||----:|:----:|:---:|
|
||||
* | 0 | NUL | %%U || 32 | \" \"|\" \"|| 64 | @ | %%V || 96 | ` | %%W |
|
||||
* | 1 | SOH | $A || 33 | ! | /A || 65 | A | A || 97 | a | +A |
|
||||
* | 2 | STX | $B || 34 | \" | /B || 66 | B | B || 98 | b | +B |
|
||||
* | 3 | ETX | $C || 35 | # | /C || 67 | C | C || 99 | c | +C |
|
||||
* | 4 | EOT | $D || 36 | $ | /D || 68 | D | D || 100 | d | +D |
|
||||
* | 5 | ENQ | $E || 37 | % | /E || 69 | E | E || 101 | e | +E |
|
||||
* | 6 | ACK | $F || 38 | & | /F || 70 | F | F || 102 | f | +F |
|
||||
* | 7 | BEL | $G || 39 | ' | /G || 71 | G | G || 103 | g | +G |
|
||||
* | 8 | BS | $H || 40 | ( | /H || 72 | H | H || 104 | h | +H |
|
||||
* | 9 | HT | $I || 41 | ) | /I || 73 | I | I || 105 | i | +I |
|
||||
* | 10 | LF | $J || 42 | * | /J || 74 | J | J || 106 | j | +J |
|
||||
* | 11 | VT | $K || 43 | + | /K || 75 | K | K || 107 | k | +K |
|
||||
* | 12 | FF | $L || 44 | , | /L || 76 | L | L || 108 | l | +L |
|
||||
* | 13 | CR | $M || 45 | - | - || 77 | M | M || 109 | m | +M |
|
||||
* | 14 | SO | $N || 46 | . | . || 78 | N | N || 110 | n | +N |
|
||||
* | 15 | SI | $O || 47 | / | /O || 79 | O | O || 111 | o | +O |
|
||||
* | 16 | DLE | $P || 48 | 0 | 0 || 80 | P | P || 112 | p | +P |
|
||||
* | 17 | DC1 | $Q || 49 | 1 | 1 || 81 | Q | Q || 113 | q | +Q |
|
||||
* | 18 | DC2 | $R || 50 | 2 | 2 || 82 | R | R || 114 | r | +R |
|
||||
* | 19 | DC3 | $S || 51 | 3 | 3 || 83 | S | S || 115 | s | +S |
|
||||
* | 20 | DC4 | $T || 52 | 4 | 4 || 84 | T | T || 116 | t | +T |
|
||||
* | 21 | NAK | $U || 53 | 5 | 5 || 85 | U | U || 117 | u | +U |
|
||||
* | 22 | SYN | $V || 54 | 6 | 6 || 86 | V | V || 118 | v | +V |
|
||||
* | 23 | ETB | $W || 55 | 7 | 7 || 87 | W | W || 119 | w | +W |
|
||||
* | 24 | CAN | $X || 56 | 8 | 8 || 88 | X | X || 120 | x | +X |
|
||||
* | 25 | EM | $Y || 57 | 9 | 9 || 89 | Y | Y || 121 | y | +Y |
|
||||
* | 26 | SUB | $Z || 58 | : | /Z || 90 | Z | Z || 122 | z | +Z |
|
||||
* | 27 | ESC | %%A || 59 | ; | %%F || 91 | [ | %%K || 123 | { | %%P |
|
||||
* | 28 | FS | %%B || 60 | < | %%G || 92 | \\ | %%L || 124 | \| | %%Q |
|
||||
* | 29 | GS | %%C || 61 | = | %%H || 93 | ] | %%M || 125 | } | %%R |
|
||||
* | 30 | RS | %%D || 62 | > | %%I || 94 | ^ | %%N || 126 | ~ | %%S |
|
||||
* | 31 | US | %%E || 63 | ? | %%J || 95 | _ | %%O || 127 | DEL | %%T |
|
||||
*
|
||||
* This pre-encoded data is now encoded using the standard *Code 39* symbology.
|
||||
*
|
||||
*
|
||||
* ### Checksum Property ###
|
||||
*
|
||||
* If the *checksum* property is *true*, a modulo 43 check digit will be
|
||||
* automatically generated and appended to the 1st pass encoded data
|
||||
* prior to the 2nd pass *Code 39* encoding. By default, the check digit
|
||||
* will not be generated.
|
||||
*
|
||||
* See setChecksum().
|
||||
*
|
||||
*
|
||||
* ### Show Text Property ###
|
||||
*
|
||||
* If the *Show Text* property is *true*, the original ASCII input data will
|
||||
* be printed below the barcode. By default, the data will not be printed.
|
||||
*
|
||||
* See setShowText().
|
||||
*
|
||||
*
|
||||
* ### References ###
|
||||
*
|
||||
* - http://en.wikipedia.org/wiki/Code_39
|
||||
*
|
||||
*
|
||||
*/
|
||||
class BarcodeCode39Ext : public BarcodeCode39
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Static Extended Code39 barcode creation method
|
||||
*
|
||||
* Used by glbarcode::BarcodeFactory
|
||||
*/
|
||||
static Barcode* create();
|
||||
|
||||
|
||||
private:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
|
||||
std::string preprocess( const std::string& rawData ) override;
|
||||
|
||||
std::string prepareText( const std::string& rawData ) override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_BarcodeCode39Ext_hpp
|
||||
+628
-627
File diff suppressed because it is too large
Load Diff
@@ -1,61 +0,0 @@
|
||||
/* BarcodeDataMatrix.h
|
||||
*
|
||||
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glbarcode_BarcodeDataMatrix_h
|
||||
#define glbarcode_BarcodeDataMatrix_h
|
||||
|
||||
|
||||
#include "Barcode2dBase.h"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/**
|
||||
* @class BarcodeDataMatrix BarcodeDataMatrix.h glbarcode/BarcodeDataMatrix.h
|
||||
*
|
||||
* DataMatrix barcode, implements Barcode2dBase
|
||||
*
|
||||
* @image html sample-datamatrix.svg "Sample Data Matrix Barcode"
|
||||
*
|
||||
*/
|
||||
class BarcodeDataMatrix : public Barcode2dBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Static DataMatrix barcode creation method
|
||||
*
|
||||
* Used by glbarcode::BarcodeFactory
|
||||
*/
|
||||
static Barcode* create();
|
||||
|
||||
|
||||
private:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
|
||||
bool encode( const std::string& cookedData,
|
||||
Matrix<bool>& encodedData ) override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_BarcodeDataMatrix_h
|
||||
@@ -0,0 +1,61 @@
|
||||
// BarcodeDataMatrix.hpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#ifndef glbarcode_BarcodeDataMatrix_hpp
|
||||
#define glbarcode_BarcodeDataMatrix_hpp
|
||||
|
||||
|
||||
#include "Barcode2dBase.hpp"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/**
|
||||
* @class BarcodeDataMatrix BarcodeDataMatrix.h glbarcode/BarcodeDataMatrix.h
|
||||
*
|
||||
* DataMatrix barcode, implements Barcode2dBase
|
||||
*
|
||||
* @image html sample-datamatrix.svg "Sample Data Matrix Barcode"
|
||||
*
|
||||
*/
|
||||
class BarcodeDataMatrix : public Barcode2dBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Static DataMatrix barcode creation method
|
||||
*
|
||||
* Used by glbarcode::BarcodeFactory
|
||||
*/
|
||||
static Barcode* create();
|
||||
|
||||
|
||||
private:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
|
||||
bool encode( const std::string& cookedData,
|
||||
Matrix<bool>& encodedData ) override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_BarcodeDataMatrix_hpp
|
||||
+75
-74
@@ -1,24 +1,25 @@
|
||||
/* BarcodeEan13.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// BarcodeEan13.cpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#include "BarcodeEan13.h"
|
||||
|
||||
#include "BarcodeEan13.hpp"
|
||||
|
||||
#include <cctype>
|
||||
#include <string>
|
||||
@@ -27,69 +28,69 @@
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/*
|
||||
* Static EAN-13 barcode creation method
|
||||
*/
|
||||
Barcode* BarcodeEan13::create( )
|
||||
{
|
||||
return new BarcodeEan13();
|
||||
}
|
||||
/*
|
||||
* Static EAN-13 barcode creation method
|
||||
*/
|
||||
Barcode* BarcodeEan13::create( )
|
||||
{
|
||||
return new BarcodeEan13();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* EAN-13 barcode constructor
|
||||
*/
|
||||
BarcodeEan13::BarcodeEan13()
|
||||
{
|
||||
mEndBarsModules = 3;
|
||||
}
|
||||
/*
|
||||
* EAN-13 barcode constructor
|
||||
*/
|
||||
BarcodeEan13::BarcodeEan13()
|
||||
{
|
||||
mEndBarsModules = 3;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* EAN-13 validate number of digits, implements BarcodeUpcBase::validateDigits()
|
||||
*/
|
||||
bool BarcodeEan13::validateDigits( int nDigits )
|
||||
{
|
||||
return (nDigits == 12);
|
||||
}
|
||||
/*
|
||||
* EAN-13 validate number of digits, implements BarcodeUpcBase::validateDigits()
|
||||
*/
|
||||
bool BarcodeEan13::validateDigits( int nDigits )
|
||||
{
|
||||
return (nDigits == 12);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* EAN-13 Pre-process data before encoding, implements Barcode1dBase::preprocess()
|
||||
*/
|
||||
std::string BarcodeEan13::preprocess( const std::string& rawData )
|
||||
{
|
||||
std::string cookedData;
|
||||
/*
|
||||
* EAN-13 Pre-process data before encoding, implements Barcode1dBase::preprocess()
|
||||
*/
|
||||
std::string BarcodeEan13::preprocess( const std::string& rawData )
|
||||
{
|
||||
std::string cookedData;
|
||||
|
||||
for (char c : rawData)
|
||||
{
|
||||
if ( isdigit( c ) )
|
||||
{
|
||||
cookedData += c;
|
||||
}
|
||||
}
|
||||
for (char c : rawData)
|
||||
{
|
||||
if ( isdigit( c ) )
|
||||
{
|
||||
cookedData += c;
|
||||
}
|
||||
}
|
||||
|
||||
mFirstDigitVal = (cookedData[0] - '0');
|
||||
return cookedData.substr( 1, cookedData.size()-1 );
|
||||
}
|
||||
mFirstDigitVal = (cookedData[0] - '0');
|
||||
return cookedData.substr( 1, cookedData.size()-1 );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* EAN-13 vectorize text, implements BarcodeUpcBase::vectorizeText()
|
||||
*/
|
||||
void BarcodeEan13::vectorizeText( const std::string& displayText,
|
||||
double size1,
|
||||
double size2,
|
||||
double x1Left,
|
||||
double x1Right,
|
||||
double y1,
|
||||
double x2Left,
|
||||
double x2Right,
|
||||
double y2 )
|
||||
{
|
||||
addText( x2Left, y2, size2, displayText.substr( 0, 1 ) );
|
||||
addText( x1Left, y1, size1, displayText.substr( 1, 6 ) );
|
||||
addText( x1Right, y1, size1, displayText.substr( 7, 6 ) );
|
||||
}
|
||||
/*
|
||||
* EAN-13 vectorize text, implements BarcodeUpcBase::vectorizeText()
|
||||
*/
|
||||
void BarcodeEan13::vectorizeText( const std::string& displayText,
|
||||
double size1,
|
||||
double size2,
|
||||
double x1Left,
|
||||
double x1Right,
|
||||
double y1,
|
||||
double x2Left,
|
||||
double x2Right,
|
||||
double y2 )
|
||||
{
|
||||
addText( x2Left, y2, size2, displayText.substr( 0, 1 ) );
|
||||
addText( x1Left, y1, size1, displayText.substr( 1, 6 ) );
|
||||
addText( x1Right, y1, size1, displayText.substr( 7, 6 ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
/* BarcodeEan13.h
|
||||
*
|
||||
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glbarcode_BarcodeEan13_h
|
||||
#define glbarcode_BarcodeEan13_h
|
||||
|
||||
|
||||
#include "BarcodeUpcBase.h"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/**
|
||||
* @class BarcodeEan13 BarcodeEan13.h glbarcode/BarcodeEan13.h
|
||||
*
|
||||
* EAN-13 barcode, implements BarcodeUpcBase
|
||||
*
|
||||
* @image html sample-ean-13.svg "Sample EAN-13 Barcode"
|
||||
*
|
||||
*/
|
||||
class BarcodeEan13 : public BarcodeUpcBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Static EAN-13 barcode creation method
|
||||
*
|
||||
* Used by glbarcode::BarcodeFactory
|
||||
*/
|
||||
static Barcode* create();
|
||||
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
BarcodeEan13();
|
||||
|
||||
|
||||
private:
|
||||
bool validateDigits( int nDigits ) override;
|
||||
|
||||
std::string preprocess( const std::string& rawData ) override;
|
||||
|
||||
void vectorizeText( const std::string& displayText,
|
||||
double size1,
|
||||
double size2,
|
||||
double x1Left,
|
||||
double x1Right,
|
||||
double y1,
|
||||
double x2Left,
|
||||
double x2Right,
|
||||
double y2 ) override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_BarcodeEan13_h
|
||||
@@ -0,0 +1,76 @@
|
||||
// BarcodeEan13.hpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#ifndef glbarcode_BarcodeEan13_hpp
|
||||
#define glbarcode_BarcodeEan13_hpp
|
||||
|
||||
|
||||
#include "BarcodeUpcBase.hpp"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/**
|
||||
* @class BarcodeEan13 BarcodeEan13.h glbarcode/BarcodeEan13.h
|
||||
*
|
||||
* EAN-13 barcode, implements BarcodeUpcBase
|
||||
*
|
||||
* @image html sample-ean-13.svg "Sample EAN-13 Barcode"
|
||||
*
|
||||
*/
|
||||
class BarcodeEan13 : public BarcodeUpcBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Static EAN-13 barcode creation method
|
||||
*
|
||||
* Used by glbarcode::BarcodeFactory
|
||||
*/
|
||||
static Barcode* create();
|
||||
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
BarcodeEan13();
|
||||
|
||||
|
||||
private:
|
||||
bool validateDigits( int nDigits ) override;
|
||||
|
||||
std::string preprocess( const std::string& rawData ) override;
|
||||
|
||||
void vectorizeText( const std::string& displayText,
|
||||
double size1,
|
||||
double size2,
|
||||
double x1Left,
|
||||
double x1Right,
|
||||
double y1,
|
||||
double x2Left,
|
||||
double x2Right,
|
||||
double y2 ) override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_BarcodeEan13_hpp
|
||||
+541
-540
File diff suppressed because it is too large
Load Diff
@@ -1,72 +0,0 @@
|
||||
/* BarcodeOnecode.h
|
||||
*
|
||||
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glbarcode_BarcodeOnecode_h
|
||||
#define glbarcode_BarcodeOnecode_h
|
||||
|
||||
|
||||
#include "Barcode1dBase.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/**
|
||||
* @class BarcodeOnecode BarcodeOnecode.h glbarcode/BarcodeOnecode.h
|
||||
*
|
||||
* Onecode barcode, implements Barcode1dBase
|
||||
*
|
||||
* @image html sample-onecode.svg "Sample USPS Onecode Barcode"
|
||||
*
|
||||
*/
|
||||
class BarcodeOnecode : public Barcode1dBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Static Onecode barcode creation method
|
||||
*
|
||||
* Used by glbarcode::BarcodeFactory
|
||||
*/
|
||||
static Barcode* create();
|
||||
|
||||
|
||||
private:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
|
||||
void vectorize( const std::string& codedData,
|
||||
const std::string& displayText,
|
||||
const std::string& cookedData,
|
||||
double& w,
|
||||
double& h ) override;
|
||||
|
||||
|
||||
private:
|
||||
uint32_t USPS_MSB_Math_CRC11GenerateFrameCheckSequence( const uint8_t* ByteArrayPtr );
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_BarcodeOnecode_h
|
||||
@@ -0,0 +1,72 @@
|
||||
// BarcodeOnecode.hpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#ifndef glbarcode_BarcodeOnecode_hpp
|
||||
#define glbarcode_BarcodeOnecode_hpp
|
||||
|
||||
|
||||
#include "Barcode1dBase.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/**
|
||||
* @class BarcodeOnecode BarcodeOnecode.h glbarcode/BarcodeOnecode.h
|
||||
*
|
||||
* Onecode barcode, implements Barcode1dBase
|
||||
*
|
||||
* @image html sample-onecode.svg "Sample USPS Onecode Barcode"
|
||||
*
|
||||
*/
|
||||
class BarcodeOnecode : public Barcode1dBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Static Onecode barcode creation method
|
||||
*
|
||||
* Used by glbarcode::BarcodeFactory
|
||||
*/
|
||||
static Barcode* create();
|
||||
|
||||
|
||||
private:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
|
||||
void vectorize( const std::string& codedData,
|
||||
const std::string& displayText,
|
||||
const std::string& cookedData,
|
||||
double& w,
|
||||
double& h ) override;
|
||||
|
||||
|
||||
private:
|
||||
uint32_t USPS_MSB_Math_CRC11GenerateFrameCheckSequence( const uint8_t* ByteArrayPtr );
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_BarcodeOnecode_hpp
|
||||
+144
-143
@@ -1,26 +1,27 @@
|
||||
/* BarcodePostnet.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// BarcodePostnet.cpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#include "BarcodePostnet.h"
|
||||
|
||||
#include "Constants.h"
|
||||
#include "BarcodePostnet.hpp"
|
||||
|
||||
#include "Constants.hpp"
|
||||
|
||||
#include <cctype>
|
||||
#include <algorithm>
|
||||
@@ -31,34 +32,34 @@ using namespace glbarcode::Constants;
|
||||
|
||||
namespace
|
||||
{
|
||||
/*
|
||||
* Encoding symbology
|
||||
*/
|
||||
const std::string symbols[] = {
|
||||
/* 0 */ "11000",
|
||||
/* 1 */ "00011",
|
||||
/* 2 */ "00101",
|
||||
/* 3 */ "00110",
|
||||
/* 4 */ "01001",
|
||||
/* 5 */ "01010",
|
||||
/* 6 */ "01100",
|
||||
/* 7 */ "10001",
|
||||
/* 8 */ "10010",
|
||||
/* 9 */ "10100"
|
||||
};
|
||||
/*
|
||||
* Encoding symbology
|
||||
*/
|
||||
const std::string symbols[] = {
|
||||
/* 0 */ "11000",
|
||||
/* 1 */ "00011",
|
||||
/* 2 */ "00101",
|
||||
/* 3 */ "00110",
|
||||
/* 4 */ "01001",
|
||||
/* 5 */ "01010",
|
||||
/* 6 */ "01100",
|
||||
/* 7 */ "10001",
|
||||
/* 8 */ "10010",
|
||||
/* 9 */ "10100"
|
||||
};
|
||||
|
||||
const std::string frameSymbol = "1";
|
||||
const std::string frameSymbol = "1";
|
||||
|
||||
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
const double POSTNET_BAR_WIDTH = ( 0.02 * PTS_PER_INCH );
|
||||
const double POSTNET_FULLBAR_HEIGHT = ( 0.125 * PTS_PER_INCH );
|
||||
const double POSTNET_HALFBAR_HEIGHT = ( 0.05 * PTS_PER_INCH );
|
||||
const double POSTNET_BAR_PITCH = ( 0.04545 * PTS_PER_INCH );
|
||||
const double POSTNET_HORIZ_MARGIN = ( 0.125 * PTS_PER_INCH );
|
||||
const double POSTNET_VERT_MARGIN = ( 0.04 * PTS_PER_INCH );
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
const double POSTNET_BAR_WIDTH = ( 0.02 * PTS_PER_INCH );
|
||||
const double POSTNET_FULLBAR_HEIGHT = ( 0.125 * PTS_PER_INCH );
|
||||
const double POSTNET_HALFBAR_HEIGHT = ( 0.05 * PTS_PER_INCH );
|
||||
const double POSTNET_BAR_PITCH = ( 0.04545 * PTS_PER_INCH );
|
||||
const double POSTNET_HORIZ_MARGIN = ( 0.125 * PTS_PER_INCH );
|
||||
const double POSTNET_VERT_MARGIN = ( 0.04 * PTS_PER_INCH );
|
||||
|
||||
}
|
||||
|
||||
@@ -66,120 +67,120 @@ namespace
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/*
|
||||
* Static Postnet barcode creation method
|
||||
*/
|
||||
Barcode* BarcodePostnet::create( )
|
||||
{
|
||||
return new BarcodePostnet();
|
||||
}
|
||||
/*
|
||||
* Static Postnet barcode creation method
|
||||
*/
|
||||
Barcode* BarcodePostnet::create( )
|
||||
{
|
||||
return new BarcodePostnet();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Postnet validate number of digits
|
||||
*/
|
||||
bool BarcodePostnet::validateDigits( int nDigits )
|
||||
{
|
||||
/* Accept any valid USPS POSTNET length. */
|
||||
return (nDigits == 5) || (nDigits == 9) || (nDigits == 11);
|
||||
}
|
||||
/*
|
||||
* Postnet validate number of digits
|
||||
*/
|
||||
bool BarcodePostnet::validateDigits( int nDigits )
|
||||
{
|
||||
/* Accept any valid USPS POSTNET length. */
|
||||
return (nDigits == 5) || (nDigits == 9) || (nDigits == 11);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Postnet data validation, implements Barcode1dBase::validate()
|
||||
*/
|
||||
bool BarcodePostnet::validate( const std::string& rawData )
|
||||
{
|
||||
int nDigits = 0;
|
||||
for (char c : rawData)
|
||||
{
|
||||
if ( isdigit( c ) )
|
||||
{
|
||||
nDigits++;
|
||||
}
|
||||
else if ( (c != '-') && (c != ' ') )
|
||||
{
|
||||
/* Only allow digits, dashes, and spaces. */
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Postnet data validation, implements Barcode1dBase::validate()
|
||||
*/
|
||||
bool BarcodePostnet::validate( const std::string& rawData )
|
||||
{
|
||||
int nDigits = 0;
|
||||
for (char c : rawData)
|
||||
{
|
||||
if ( isdigit( c ) )
|
||||
{
|
||||
nDigits++;
|
||||
}
|
||||
else if ( (c != '-') && (c != ' ') )
|
||||
{
|
||||
/* Only allow digits, dashes, and spaces. */
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return validateDigits( nDigits );
|
||||
}
|
||||
return validateDigits( nDigits );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Postnet data encoding, implements Barcode1dBase::encode()
|
||||
*/
|
||||
std::string BarcodePostnet::encode( const std::string& cookedData )
|
||||
{
|
||||
std::string code;
|
||||
/*
|
||||
* Postnet data encoding, implements Barcode1dBase::encode()
|
||||
*/
|
||||
std::string BarcodePostnet::encode( const std::string& cookedData )
|
||||
{
|
||||
std::string code;
|
||||
|
||||
/* Left frame bar */
|
||||
code += frameSymbol;
|
||||
/* Left frame bar */
|
||||
code += frameSymbol;
|
||||
|
||||
/* process each digit, adding appropriate symbol */
|
||||
int sum = 0;
|
||||
for (char c : cookedData)
|
||||
{
|
||||
if ( isdigit( c ) )
|
||||
{
|
||||
/* Only translate the digits (0-9) */
|
||||
int d = c - '0';
|
||||
code += symbols[d];
|
||||
sum += d;
|
||||
}
|
||||
}
|
||||
/* process each digit, adding appropriate symbol */
|
||||
int sum = 0;
|
||||
for (char c : cookedData)
|
||||
{
|
||||
if ( isdigit( c ) )
|
||||
{
|
||||
/* Only translate the digits (0-9) */
|
||||
int d = c - '0';
|
||||
code += symbols[d];
|
||||
sum += d;
|
||||
}
|
||||
}
|
||||
|
||||
/* Create mandatory correction character */
|
||||
code += symbols[ (10 - (sum % 10)) % 10 ];
|
||||
/* Create mandatory correction character */
|
||||
code += symbols[ (10 - (sum % 10)) % 10 ];
|
||||
|
||||
/* Right frame bar */
|
||||
code += frameSymbol;
|
||||
/* Right frame bar */
|
||||
code += frameSymbol;
|
||||
|
||||
return code;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Postnet vectorization, implements Barcode1dBase::vectorize()
|
||||
*/
|
||||
void BarcodePostnet::vectorize( const std::string& codedData,
|
||||
const std::string& displayText,
|
||||
const std::string& cookedData,
|
||||
double& w,
|
||||
double& h )
|
||||
{
|
||||
double x = POSTNET_HORIZ_MARGIN;
|
||||
for (char c : codedData)
|
||||
{
|
||||
double y = POSTNET_VERT_MARGIN;
|
||||
/*
|
||||
* Postnet vectorization, implements Barcode1dBase::vectorize()
|
||||
*/
|
||||
void BarcodePostnet::vectorize( const std::string& codedData,
|
||||
const std::string& displayText,
|
||||
const std::string& cookedData,
|
||||
double& w,
|
||||
double& h )
|
||||
{
|
||||
double x = POSTNET_HORIZ_MARGIN;
|
||||
for (char c : codedData)
|
||||
{
|
||||
double y = POSTNET_VERT_MARGIN;
|
||||
|
||||
double length = 0;
|
||||
switch ( c )
|
||||
{
|
||||
case '0':
|
||||
y += POSTNET_FULLBAR_HEIGHT - POSTNET_HALFBAR_HEIGHT;
|
||||
length = POSTNET_HALFBAR_HEIGHT;
|
||||
break;
|
||||
case '1':
|
||||
length = POSTNET_FULLBAR_HEIGHT;
|
||||
break;
|
||||
default:
|
||||
// Not reached
|
||||
break;
|
||||
}
|
||||
|
||||
double width = POSTNET_BAR_WIDTH;
|
||||
double length = 0;
|
||||
switch ( c )
|
||||
{
|
||||
case '0':
|
||||
y += POSTNET_FULLBAR_HEIGHT - POSTNET_HALFBAR_HEIGHT;
|
||||
length = POSTNET_HALFBAR_HEIGHT;
|
||||
break;
|
||||
case '1':
|
||||
length = POSTNET_FULLBAR_HEIGHT;
|
||||
break;
|
||||
default:
|
||||
// Not reached
|
||||
break;
|
||||
}
|
||||
|
||||
addLine( x, y, width, length );
|
||||
double width = POSTNET_BAR_WIDTH;
|
||||
|
||||
x += POSTNET_BAR_PITCH;
|
||||
}
|
||||
addLine( x, y, width, length );
|
||||
|
||||
/* Overwrite requested size with actual size. */
|
||||
w = x + POSTNET_HORIZ_MARGIN;
|
||||
h = POSTNET_FULLBAR_HEIGHT + 2 * POSTNET_VERT_MARGIN;
|
||||
}
|
||||
x += POSTNET_BAR_PITCH;
|
||||
}
|
||||
|
||||
/* Overwrite requested size with actual size. */
|
||||
w = x + POSTNET_HORIZ_MARGIN;
|
||||
h = POSTNET_FULLBAR_HEIGHT + 2 * POSTNET_VERT_MARGIN;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
/* BarcodePostnet.h
|
||||
*
|
||||
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glbarcode_BarcodePostnet_h
|
||||
#define glbarcode_BarcodePostnet_h
|
||||
|
||||
|
||||
#include "Barcode1dBase.h"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/**
|
||||
* @class BarcodePostnet BarcodePostnet.h glbarcode/BarcodePostnet.h
|
||||
*
|
||||
* *POSTNET* barcode (All USPS sizes: ZIP, ZIP+4, ZIP+4+DC).
|
||||
*
|
||||
* @image html sample-postnet.svg "Sample USPS POSTNET Barcode"
|
||||
*
|
||||
*
|
||||
* ### Input Data Format ###
|
||||
*
|
||||
* The *POSTNET* specification defines 10 characters, consisting solely
|
||||
* of decimal digits (0-9). The BarcodePostnet validator and encoder will
|
||||
* ignore spaces and dashes (-). The validator will only accept input
|
||||
* data with 5 digits (ZIP), 9 digits (ZIP+4) or 11 digits (ZIP+4+DC).
|
||||
*
|
||||
*
|
||||
* ### Checksum Property ###
|
||||
*
|
||||
* The *checksum* property is ignored. A mandatory check digit will
|
||||
* always be automatically generated and appended to the input data
|
||||
* prior to encoding.
|
||||
*
|
||||
*
|
||||
* ### Show Text Property ###
|
||||
*
|
||||
* The *Show Text* property is ignored.
|
||||
*
|
||||
*
|
||||
* ### References ###
|
||||
*
|
||||
* - http://en.wikipedia.org/wiki/POSTNET
|
||||
*
|
||||
*/
|
||||
class BarcodePostnet : public Barcode1dBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Static Postnet barcode creation method
|
||||
*
|
||||
* Used by glbarcode::BarcodeFactory
|
||||
*/
|
||||
static Barcode* create();
|
||||
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Validate number of digits
|
||||
*/
|
||||
virtual bool validateDigits( int nDigits );
|
||||
|
||||
|
||||
private:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
|
||||
void vectorize( const std::string& codedData,
|
||||
const std::string& displayText,
|
||||
const std::string& cookedData,
|
||||
double& w,
|
||||
double& h ) override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_BarcodePostnet_h
|
||||
@@ -0,0 +1,98 @@
|
||||
// BarcodePostnet.hpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#ifndef glbarcode_BarcodePostnet_hpp
|
||||
#define glbarcode_BarcodePostnet_hpp
|
||||
|
||||
|
||||
#include "Barcode1dBase.hpp"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/**
|
||||
* @class BarcodePostnet BarcodePostnet.h glbarcode/BarcodePostnet.h
|
||||
*
|
||||
* *POSTNET* barcode (All USPS sizes: ZIP, ZIP+4, ZIP+4+DC).
|
||||
*
|
||||
* @image html sample-postnet.svg "Sample USPS POSTNET Barcode"
|
||||
*
|
||||
*
|
||||
* ### Input Data Format ###
|
||||
*
|
||||
* The *POSTNET* specification defines 10 characters, consisting solely
|
||||
* of decimal digits (0-9). The BarcodePostnet validator and encoder will
|
||||
* ignore spaces and dashes (-). The validator will only accept input
|
||||
* data with 5 digits (ZIP), 9 digits (ZIP+4) or 11 digits (ZIP+4+DC).
|
||||
*
|
||||
*
|
||||
* ### Checksum Property ###
|
||||
*
|
||||
* The *checksum* property is ignored. A mandatory check digit will
|
||||
* always be automatically generated and appended to the input data
|
||||
* prior to encoding.
|
||||
*
|
||||
*
|
||||
* ### Show Text Property ###
|
||||
*
|
||||
* The *Show Text* property is ignored.
|
||||
*
|
||||
*
|
||||
* ### References ###
|
||||
*
|
||||
* - http://en.wikipedia.org/wiki/POSTNET
|
||||
*
|
||||
*/
|
||||
class BarcodePostnet : public Barcode1dBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Static Postnet barcode creation method
|
||||
*
|
||||
* Used by glbarcode::BarcodeFactory
|
||||
*/
|
||||
static Barcode* create();
|
||||
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Validate number of digits
|
||||
*/
|
||||
virtual bool validateDigits( int nDigits );
|
||||
|
||||
|
||||
private:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
|
||||
void vectorize( const std::string& codedData,
|
||||
const std::string& displayText,
|
||||
const std::string& cookedData,
|
||||
double& w,
|
||||
double& h ) override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_BarcodePostnet_hpp
|
||||
@@ -1,44 +1,45 @@
|
||||
/* BarcodePostnet11.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// BarcodePostnet11.cpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#include "BarcodePostnet11.h"
|
||||
|
||||
#include "BarcodePostnet11.hpp"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/*
|
||||
* Static Postnet-11 barcode creation method
|
||||
*/
|
||||
Barcode* BarcodePostnet11::create( )
|
||||
{
|
||||
return new BarcodePostnet11();
|
||||
}
|
||||
/*
|
||||
* Static Postnet-11 barcode creation method
|
||||
*/
|
||||
Barcode* BarcodePostnet11::create( )
|
||||
{
|
||||
return new BarcodePostnet11();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Postnet-11 validation of number of digits, overrides BarcodePostnet::validateDigits()
|
||||
*/
|
||||
bool BarcodePostnet11::validateDigits( int nDigits )
|
||||
{
|
||||
return nDigits == 11; /* Zip + 4 + Delivery Code */
|
||||
}
|
||||
/*
|
||||
* Postnet-11 validation of number of digits, overrides BarcodePostnet::validateDigits()
|
||||
*/
|
||||
bool BarcodePostnet11::validateDigits( int nDigits )
|
||||
{
|
||||
return nDigits == 11; /* Zip + 4 + Delivery Code */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
/* BarcodePostnet11.h
|
||||
*
|
||||
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glbarcode_BarcodePostnet11_h
|
||||
#define glbarcode_BarcodePostnet11_h
|
||||
|
||||
|
||||
#include "BarcodePostnet.h"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/**
|
||||
* @class BarcodePostnet11 BarcodePostnet11.h glbarcode/BarcodePostnet11.h
|
||||
*
|
||||
* *POSTNET-11* barcode (ZIP only), extends BarcodePostnet
|
||||
*
|
||||
* @image html sample-postnet-11.svg "Sample 11 digit USPS POSTNET Barcode"
|
||||
*
|
||||
*
|
||||
* ### Input Data Format ###
|
||||
*
|
||||
* Input data requirements are identical to BarcodePostnet, except the
|
||||
* validator only accepts 11 digits (ZIP+4+DC) of input.
|
||||
*
|
||||
* See BarcodePostnet.
|
||||
*
|
||||
*/
|
||||
class BarcodePostnet11 : public BarcodePostnet
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Static POSTNET-11 barcode creation method
|
||||
*
|
||||
* Used by glbarcode::BarcodeFactory
|
||||
*/
|
||||
static Barcode* create();
|
||||
|
||||
|
||||
private:
|
||||
bool validateDigits( int nDigits ) override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_BarcodePostnet11_h
|
||||
@@ -0,0 +1,66 @@
|
||||
// BarcodePostnet11.hpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#ifndef glbarcode_BarcodePostnet11_hpp
|
||||
#define glbarcode_BarcodePostnet11_hpp
|
||||
|
||||
|
||||
#include "BarcodePostnet.hpp"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/**
|
||||
* @class BarcodePostnet11 BarcodePostnet11.h glbarcode/BarcodePostnet11.h
|
||||
*
|
||||
* *POSTNET-11* barcode (ZIP only), extends BarcodePostnet
|
||||
*
|
||||
* @image html sample-postnet-11.svg "Sample 11 digit USPS POSTNET Barcode"
|
||||
*
|
||||
*
|
||||
* ### Input Data Format ###
|
||||
*
|
||||
* Input data requirements are identical to BarcodePostnet, except the
|
||||
* validator only accepts 11 digits (ZIP+4+DC) of input.
|
||||
*
|
||||
* See BarcodePostnet.
|
||||
*
|
||||
*/
|
||||
class BarcodePostnet11 : public BarcodePostnet
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Static POSTNET-11 barcode creation method
|
||||
*
|
||||
* Used by glbarcode::BarcodeFactory
|
||||
*/
|
||||
static Barcode* create();
|
||||
|
||||
|
||||
private:
|
||||
bool validateDigits( int nDigits ) override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_BarcodePostnet11_hpp
|
||||
@@ -1,44 +1,45 @@
|
||||
/* BarcodePostnet5.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// BarcodePostnet5.cpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#include "BarcodePostnet5.h"
|
||||
|
||||
#include "BarcodePostnet5.hpp"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/*
|
||||
* Static Postnet-5 barcode creation method
|
||||
*/
|
||||
Barcode* BarcodePostnet5::create( )
|
||||
{
|
||||
return new BarcodePostnet5();
|
||||
}
|
||||
/*
|
||||
* Static Postnet-5 barcode creation method
|
||||
*/
|
||||
Barcode* BarcodePostnet5::create( )
|
||||
{
|
||||
return new BarcodePostnet5();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Postnet-5 validation of number of digits, overrides BarcodePostnet::validateDigits()
|
||||
*/
|
||||
bool BarcodePostnet5::validateDigits( int nDigits )
|
||||
{
|
||||
return nDigits == 5; /* Zip only */
|
||||
}
|
||||
/*
|
||||
* Postnet-5 validation of number of digits, overrides BarcodePostnet::validateDigits()
|
||||
*/
|
||||
bool BarcodePostnet5::validateDigits( int nDigits )
|
||||
{
|
||||
return nDigits == 5; /* Zip only */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
/* BarcodePostnet5.h
|
||||
*
|
||||
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glbarcode_BarcodePostnet5_h
|
||||
#define glbarcode_BarcodePostnet5_h
|
||||
|
||||
|
||||
#include "BarcodePostnet.h"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/**
|
||||
* @class BarcodePostnet5 BarcodePostnet5.h glbarcode/BarcodePostnet5.h
|
||||
*
|
||||
* *POSTNET-5* barcode (ZIP only), extends BarcodePostnet
|
||||
*
|
||||
* @image html sample-postnet-5.svg "Sample 5 digit USPS POSTNET Barcode"
|
||||
*
|
||||
*
|
||||
* ### Input Data Format ###
|
||||
*
|
||||
* Input data requirements are identical to BarcodePostnet, except the
|
||||
* validator only accepts 5 digits (ZIP) of input.
|
||||
*
|
||||
* See BarcodePostnet.
|
||||
*
|
||||
*/
|
||||
class BarcodePostnet5 : public BarcodePostnet
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Static POSTNET-5 barcode creation method
|
||||
*
|
||||
* Used by glbarcode::BarcodeFactory
|
||||
*/
|
||||
static Barcode* create();
|
||||
|
||||
|
||||
private:
|
||||
bool validateDigits( int nDigits ) override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_BarcodePostnet5_h
|
||||
@@ -0,0 +1,66 @@
|
||||
// BarcodePostnet5.hpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#ifndef glbarcode_BarcodePostnet5_hpp
|
||||
#define glbarcode_BarcodePostnet5_hpp
|
||||
|
||||
|
||||
#include "BarcodePostnet.hpp"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/**
|
||||
* @class BarcodePostnet5 BarcodePostnet5.h glbarcode/BarcodePostnet5.h
|
||||
*
|
||||
* *POSTNET-5* barcode (ZIP only), extends BarcodePostnet
|
||||
*
|
||||
* @image html sample-postnet-5.svg "Sample 5 digit USPS POSTNET Barcode"
|
||||
*
|
||||
*
|
||||
* ### Input Data Format ###
|
||||
*
|
||||
* Input data requirements are identical to BarcodePostnet, except the
|
||||
* validator only accepts 5 digits (ZIP) of input.
|
||||
*
|
||||
* See BarcodePostnet.
|
||||
*
|
||||
*/
|
||||
class BarcodePostnet5 : public BarcodePostnet
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Static POSTNET-5 barcode creation method
|
||||
*
|
||||
* Used by glbarcode::BarcodeFactory
|
||||
*/
|
||||
static Barcode* create();
|
||||
|
||||
|
||||
private:
|
||||
bool validateDigits( int nDigits ) override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_BarcodePostnet5_hpp
|
||||
@@ -1,44 +1,45 @@
|
||||
/* BarcodePostnet9.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// BarcodePostnet9.cpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#include "BarcodePostnet9.h"
|
||||
|
||||
#include "BarcodePostnet9.hpp"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/*
|
||||
* Static Postnet-9 barcode creation method
|
||||
*/
|
||||
Barcode* BarcodePostnet9::create( )
|
||||
{
|
||||
return new BarcodePostnet9();
|
||||
}
|
||||
/*
|
||||
* Static Postnet-9 barcode creation method
|
||||
*/
|
||||
Barcode* BarcodePostnet9::create( )
|
||||
{
|
||||
return new BarcodePostnet9();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Postnet-9 validation of number of digits, overrides BarcodePostnet::validateDigits()
|
||||
*/
|
||||
bool BarcodePostnet9::validateDigits( int nDigits )
|
||||
{
|
||||
return nDigits == 9; /* Zip + 4 */
|
||||
}
|
||||
/*
|
||||
* Postnet-9 validation of number of digits, overrides BarcodePostnet::validateDigits()
|
||||
*/
|
||||
bool BarcodePostnet9::validateDigits( int nDigits )
|
||||
{
|
||||
return nDigits == 9; /* Zip + 4 */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
/* BarcodePostnet9.h
|
||||
*
|
||||
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glbarcode_BarcodePostnet9_h
|
||||
#define glbarcode_BarcodePostnet9_h
|
||||
|
||||
|
||||
#include "BarcodePostnet.h"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/**
|
||||
* @class BarcodePostnet9 BarcodePostnet9.h glbarcode/BarcodePostnet9.h
|
||||
*
|
||||
* *POSTNET-9* barcode (ZIP+4 only), extends BarcodePostnet
|
||||
*
|
||||
* @image html sample-postnet-9.svg "Sample 9 digit USPS POSTNET Barcode"
|
||||
*
|
||||
*
|
||||
* ### Input Data Format ###
|
||||
*
|
||||
* Input data requirements are identical to BarcodePostnet, except the
|
||||
* validator only accepts 9 digits (ZIP+4) of input.
|
||||
*
|
||||
* See BarcodePostnet.
|
||||
*
|
||||
*/
|
||||
class BarcodePostnet9 : public BarcodePostnet
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Static POSTNET-9 barcode creation method
|
||||
*
|
||||
* Used by glbarcode::BarcodeFactory
|
||||
*/
|
||||
static Barcode* create();
|
||||
|
||||
|
||||
private:
|
||||
bool validateDigits( int nDigits ) override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_BarcodePostnet9_h
|
||||
@@ -0,0 +1,66 @@
|
||||
// BarcodePostnet9.hpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#ifndef glbarcode_BarcodePostnet9_hpp
|
||||
#define glbarcode_BarcodePostnet9_hpp
|
||||
|
||||
|
||||
#include "BarcodePostnet.hpp"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/**
|
||||
* @class BarcodePostnet9 BarcodePostnet9.h glbarcode/BarcodePostnet9.h
|
||||
*
|
||||
* *POSTNET-9* barcode (ZIP+4 only), extends BarcodePostnet
|
||||
*
|
||||
* @image html sample-postnet-9.svg "Sample 9 digit USPS POSTNET Barcode"
|
||||
*
|
||||
*
|
||||
* ### Input Data Format ###
|
||||
*
|
||||
* Input data requirements are identical to BarcodePostnet, except the
|
||||
* validator only accepts 9 digits (ZIP+4) of input.
|
||||
*
|
||||
* See BarcodePostnet.
|
||||
*
|
||||
*/
|
||||
class BarcodePostnet9 : public BarcodePostnet
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Static POSTNET-9 barcode creation method
|
||||
*
|
||||
* Used by glbarcode::BarcodeFactory
|
||||
*/
|
||||
static Barcode* create();
|
||||
|
||||
|
||||
private:
|
||||
bool validateDigits( int nDigits ) override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_BarcodePostnet9_hpp
|
||||
+65
-64
@@ -1,85 +1,86 @@
|
||||
/* BarcodeQrcode.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// BarcodeQrcode.cpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#if HAVE_QRENCODE
|
||||
|
||||
#include "BarcodeQrcode.h"
|
||||
|
||||
#include "qrencode.h"
|
||||
#include "BarcodeQrcode.hpp"
|
||||
|
||||
#include "qrencode.hpp"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/*
|
||||
* Static Qrcode barcode creation method
|
||||
*/
|
||||
Barcode* BarcodeQrcode::create( void )
|
||||
{
|
||||
return new BarcodeQrcode();
|
||||
}
|
||||
/*
|
||||
* Static Qrcode barcode creation method
|
||||
*/
|
||||
Barcode* BarcodeQrcode::create( void )
|
||||
{
|
||||
return new BarcodeQrcode();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Qrcode data validation, implements Barcode2dBase::validate()
|
||||
*/
|
||||
bool BarcodeQrcode::validate( const std::string& rawData )
|
||||
{
|
||||
if ( rawData.size() == 0 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/*
|
||||
* Qrcode data validation, implements Barcode2dBase::validate()
|
||||
*/
|
||||
bool BarcodeQrcode::validate( const std::string& rawData )
|
||||
{
|
||||
if ( rawData.size() == 0 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Qrcode data encoding, implements Barcode2dBase::encode()
|
||||
*/
|
||||
bool BarcodeQrcode::encode( const std::string& cookedData, Matrix<bool>& encodedData )
|
||||
{
|
||||
QRcode *qrcode = QRcode_encodeString( cookedData.c_str(), 0, QR_ECLEVEL_M, QR_MODE_8, 1 );
|
||||
if ( qrcode == NULL )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
/*
|
||||
* Qrcode data encoding, implements Barcode2dBase::encode()
|
||||
*/
|
||||
bool BarcodeQrcode::encode( const std::string& cookedData, Matrix<bool>& encodedData )
|
||||
{
|
||||
QRcode *qrcode = QRcode_encodeString( cookedData.c_str(), 0, QR_ECLEVEL_M, QR_MODE_8, 1 );
|
||||
if ( qrcode == NULL )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
int w = qrcode->width;
|
||||
encodedData.resize( w, w );
|
||||
|
||||
|
||||
for ( int iy = 0; iy < w; iy++ )
|
||||
{
|
||||
for ( int ix = 0; ix < w; ix++ )
|
||||
{
|
||||
encodedData[iy][ix] = qrcode->data[ iy*w + ix ] & 0x01;
|
||||
}
|
||||
}
|
||||
int w = qrcode->width;
|
||||
encodedData.resize( w, w );
|
||||
|
||||
|
||||
QRcode_free( qrcode );
|
||||
QRcode_clearCache();
|
||||
for ( int iy = 0; iy < w; iy++ )
|
||||
{
|
||||
for ( int ix = 0; ix < w; ix++ )
|
||||
{
|
||||
encodedData[iy][ix] = qrcode->data[ iy*w + ix ] & 0x01;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QRcode_free( qrcode );
|
||||
QRcode_clearCache();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
/* BarcodeQrcode.h
|
||||
*
|
||||
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glbarcode_BarcodeQrcode_h
|
||||
#define glbarcode_BarcodeQrcode_h
|
||||
|
||||
|
||||
#include "Barcode2dBase.h"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/**
|
||||
* @class BarcodeQrcode BarcodeQrcode.h glbarcode/BarcodeQrcode.h
|
||||
*
|
||||
* QRCode barcode, implements Barcode2dBase.
|
||||
*
|
||||
* @image html sample-qrcode.svg "Sample QRCode Barcode"
|
||||
*/
|
||||
class BarcodeQrcode : public Barcode2dBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Static QRCode barcode creation method
|
||||
*
|
||||
* Used by glbarcode::BarcodeFactory
|
||||
*/
|
||||
static Barcode* create();
|
||||
|
||||
|
||||
private:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
|
||||
bool encode( const std::string& cookedData,
|
||||
Matrix<bool>& encodedData ) override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // glbarcode_BarcodeQrcode_h
|
||||
@@ -0,0 +1,59 @@
|
||||
// BarcodeQrcode.hpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#ifndef glbarcode_BarcodeQrcode_hpp
|
||||
#define glbarcode_BarcodeQrcode_hpp
|
||||
|
||||
|
||||
#include "Barcode2dBase.hpp"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/**
|
||||
* @class BarcodeQrcode BarcodeQrcode.h glbarcode/BarcodeQrcode.h
|
||||
*
|
||||
* QRCode barcode, implements Barcode2dBase.
|
||||
*
|
||||
* @image html sample-qrcode.svg "Sample QRCode Barcode"
|
||||
*/
|
||||
class BarcodeQrcode : public Barcode2dBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Static QRCode barcode creation method
|
||||
*
|
||||
* Used by glbarcode::BarcodeFactory
|
||||
*/
|
||||
static Barcode* create();
|
||||
|
||||
|
||||
private:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
|
||||
bool encode( const std::string& cookedData,
|
||||
Matrix<bool>& encodedData ) override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // glbarcode_BarcodeQrcode_hpp
|
||||
+76
-75
@@ -1,24 +1,25 @@
|
||||
/* BarcodeUpcA.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// BarcodeUpcA.cpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#include "BarcodeUpcA.h"
|
||||
|
||||
#include "BarcodeUpcA.hpp"
|
||||
|
||||
#include <cctype>
|
||||
#include <string>
|
||||
@@ -27,70 +28,70 @@
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/*
|
||||
* Static UPC-A barcode creation method
|
||||
*/
|
||||
Barcode* BarcodeUpcA::create( )
|
||||
{
|
||||
return new BarcodeUpcA();
|
||||
}
|
||||
/*
|
||||
* Static UPC-A barcode creation method
|
||||
*/
|
||||
Barcode* BarcodeUpcA::create( )
|
||||
{
|
||||
return new BarcodeUpcA();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* UPC-A barcode constructor
|
||||
*/
|
||||
BarcodeUpcA::BarcodeUpcA()
|
||||
{
|
||||
mEndBarsModules = 7;
|
||||
}
|
||||
/*
|
||||
* UPC-A barcode constructor
|
||||
*/
|
||||
BarcodeUpcA::BarcodeUpcA()
|
||||
{
|
||||
mEndBarsModules = 7;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* UPC-A validate number of digits, implements BarcodeUpcBase::validateDigits()
|
||||
*/
|
||||
bool BarcodeUpcA::validateDigits( int nDigits )
|
||||
{
|
||||
return (nDigits == 11);
|
||||
}
|
||||
/*
|
||||
* UPC-A validate number of digits, implements BarcodeUpcBase::validateDigits()
|
||||
*/
|
||||
bool BarcodeUpcA::validateDigits( int nDigits )
|
||||
{
|
||||
return (nDigits == 11);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* UPC-A Pre-process data before encoding, implements Barcode1dBase::preprocess()
|
||||
*/
|
||||
std::string BarcodeUpcA::preprocess( const std::string& rawData )
|
||||
{
|
||||
std::string cookedData;
|
||||
/*
|
||||
* UPC-A Pre-process data before encoding, implements Barcode1dBase::preprocess()
|
||||
*/
|
||||
std::string BarcodeUpcA::preprocess( const std::string& rawData )
|
||||
{
|
||||
std::string cookedData;
|
||||
|
||||
for (char c : rawData)
|
||||
{
|
||||
if ( isdigit( c ) )
|
||||
{
|
||||
cookedData += c;
|
||||
}
|
||||
}
|
||||
for (char c : rawData)
|
||||
{
|
||||
if ( isdigit( c ) )
|
||||
{
|
||||
cookedData += c;
|
||||
}
|
||||
}
|
||||
|
||||
mFirstDigitVal = 0;
|
||||
return cookedData;
|
||||
}
|
||||
mFirstDigitVal = 0;
|
||||
return cookedData;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* UPC-A vectorize text, implements BarcodeUpcBase::vectorizeText()
|
||||
*/
|
||||
void BarcodeUpcA::vectorizeText( const std::string& displayText,
|
||||
double size1,
|
||||
double size2,
|
||||
double x1Left,
|
||||
double x1Right,
|
||||
double y1,
|
||||
double x2Left,
|
||||
double x2Right,
|
||||
double y2 )
|
||||
{
|
||||
addText( x2Left, y2, size2, displayText.substr( 0, 1 ) );
|
||||
addText( x1Left, y1, size1, displayText.substr( 1, 5 ) );
|
||||
addText( x1Right, y1, size1, displayText.substr( 6, 5 ) );
|
||||
addText( x2Right, y2, size2, displayText.substr( 11, 1 ) );
|
||||
}
|
||||
/*
|
||||
* UPC-A vectorize text, implements BarcodeUpcBase::vectorizeText()
|
||||
*/
|
||||
void BarcodeUpcA::vectorizeText( const std::string& displayText,
|
||||
double size1,
|
||||
double size2,
|
||||
double x1Left,
|
||||
double x1Right,
|
||||
double y1,
|
||||
double x2Left,
|
||||
double x2Right,
|
||||
double y2 )
|
||||
{
|
||||
addText( x2Left, y2, size2, displayText.substr( 0, 1 ) );
|
||||
addText( x1Left, y1, size1, displayText.substr( 1, 5 ) );
|
||||
addText( x1Right, y1, size1, displayText.substr( 6, 5 ) );
|
||||
addText( x2Right, y2, size2, displayText.substr( 11, 1 ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
/* BarcodeUpcA.h
|
||||
*
|
||||
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glbarcode_BarcodeUpcA_h
|
||||
#define glbarcode_BarcodeUpcA_h
|
||||
|
||||
|
||||
#include "BarcodeUpcBase.h"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/**
|
||||
* @class BarcodeUpcA BarcodeUpcA.h glbarcode/BarcodeUpcA.h
|
||||
*
|
||||
* UPC-A barcode, implements BarcodeUpcBase
|
||||
*
|
||||
* @image html sample-upc-a.svg "Sample UPC-A Barcode"
|
||||
*
|
||||
*/
|
||||
class BarcodeUpcA : public BarcodeUpcBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Static UPC-A barcode creation method
|
||||
*
|
||||
* Used by glbarcode::BarcodeFactory
|
||||
*/
|
||||
static Barcode* create();
|
||||
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
BarcodeUpcA();
|
||||
|
||||
|
||||
private:
|
||||
bool validateDigits( int nDigits ) override;
|
||||
|
||||
std::string preprocess( const std::string& rawData ) override;
|
||||
|
||||
void vectorizeText( const std::string& displayText,
|
||||
double size1,
|
||||
double size2,
|
||||
double x1Left,
|
||||
double x1Right,
|
||||
double y1,
|
||||
double x2Left,
|
||||
double x2Right,
|
||||
double y2 ) override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_BarcodeUpcA_h
|
||||
@@ -0,0 +1,76 @@
|
||||
// BarcodeUpcA.hpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#ifndef glbarcode_BarcodeUpcA_hpp
|
||||
#define glbarcode_BarcodeUpcA_hpp
|
||||
|
||||
|
||||
#include "BarcodeUpcBase.hpp"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/**
|
||||
* @class BarcodeUpcA BarcodeUpcA.h glbarcode/BarcodeUpcA.h
|
||||
*
|
||||
* UPC-A barcode, implements BarcodeUpcBase
|
||||
*
|
||||
* @image html sample-upc-a.svg "Sample UPC-A Barcode"
|
||||
*
|
||||
*/
|
||||
class BarcodeUpcA : public BarcodeUpcBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Static UPC-A barcode creation method
|
||||
*
|
||||
* Used by glbarcode::BarcodeFactory
|
||||
*/
|
||||
static Barcode* create();
|
||||
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
BarcodeUpcA();
|
||||
|
||||
|
||||
private:
|
||||
bool validateDigits( int nDigits ) override;
|
||||
|
||||
std::string preprocess( const std::string& rawData ) override;
|
||||
|
||||
void vectorizeText( const std::string& displayText,
|
||||
double size1,
|
||||
double size2,
|
||||
double x1Left,
|
||||
double x1Right,
|
||||
double y1,
|
||||
double x2Left,
|
||||
double x2Right,
|
||||
double y2 ) override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_BarcodeUpcA_hpp
|
||||
+241
-240
@@ -1,31 +1,32 @@
|
||||
/* BarcodeUpcBase.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// BarcodeUpcBase.cpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#include "BarcodeUpcBase.h"
|
||||
|
||||
#include "Constants.h"
|
||||
#include "BarcodeUpcBase.hpp"
|
||||
|
||||
#include "Constants.hpp"
|
||||
|
||||
#include <cctype>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
|
||||
using namespace glbarcode::Constants;
|
||||
@@ -33,273 +34,273 @@ using namespace glbarcode::Constants;
|
||||
|
||||
namespace
|
||||
{
|
||||
/*
|
||||
* Symbology
|
||||
*/
|
||||
const std::string symbols[10][2] = {
|
||||
/* Odd Even */
|
||||
/* Left: sBsB sBsB */
|
||||
/* Right: BsBs ---- */
|
||||
/* */
|
||||
/* 0 */ { "3211", "1123" },
|
||||
/* 1 */ { "2221", "1222" },
|
||||
/* 2 */ { "2122", "2212" },
|
||||
/* 3 */ { "1411", "1141" },
|
||||
/* 4 */ { "1132", "2311" },
|
||||
/* 5 */ { "1231", "1321" },
|
||||
/* 6 */ { "1114", "4111" },
|
||||
/* 7 */ { "1312", "2131" },
|
||||
/* 8 */ { "1213", "3121" },
|
||||
/* 9 */ { "3112", "2113" }
|
||||
};
|
||||
/*
|
||||
* Symbology
|
||||
*/
|
||||
const std::string symbols[10][2] = {
|
||||
/* Odd Even */
|
||||
/* Left: sBsB sBsB */
|
||||
/* Right: BsBs ---- */
|
||||
/* */
|
||||
/* 0 */ { "3211", "1123" },
|
||||
/* 1 */ { "2221", "1222" },
|
||||
/* 2 */ { "2122", "2212" },
|
||||
/* 3 */ { "1411", "1141" },
|
||||
/* 4 */ { "1132", "2311" },
|
||||
/* 5 */ { "1231", "1321" },
|
||||
/* 6 */ { "1114", "4111" },
|
||||
/* 7 */ { "1312", "2131" },
|
||||
/* 8 */ { "1213", "3121" },
|
||||
/* 9 */ { "3112", "2113" }
|
||||
};
|
||||
|
||||
const std::string sSymbol = "111"; /* BsB */
|
||||
const std::string eSymbol = "111"; /* BsB */
|
||||
const std::string mSymbol = "11111"; /* sBsBs */
|
||||
const std::string sSymbol = "111"; /* BsB */
|
||||
const std::string eSymbol = "111"; /* BsB */
|
||||
const std::string mSymbol = "11111"; /* sBsBs */
|
||||
|
||||
|
||||
/*
|
||||
* Parity selection
|
||||
*/
|
||||
enum Parity { P_ODD, P_EVEN };
|
||||
/*
|
||||
* Parity selection
|
||||
*/
|
||||
enum Parity { P_ODD, P_EVEN };
|
||||
|
||||
const Parity parity[10][6] = {
|
||||
/* Pos 1, Pos 2, Pos 3, Pos 4, Pos 5, Pos 6 */
|
||||
/* 0 (UPC-A) */ { P_ODD, P_ODD, P_ODD, P_ODD, P_ODD, P_ODD },
|
||||
/* 1 */ { P_ODD, P_ODD, P_EVEN, P_ODD, P_EVEN, P_EVEN },
|
||||
/* 2 */ { P_ODD, P_ODD, P_EVEN, P_EVEN, P_ODD, P_EVEN },
|
||||
/* 3 */ { P_ODD, P_ODD, P_EVEN, P_EVEN, P_EVEN, P_ODD },
|
||||
/* 4 */ { P_ODD, P_EVEN, P_ODD, P_ODD, P_EVEN, P_EVEN },
|
||||
/* 5 */ { P_ODD, P_EVEN, P_EVEN, P_ODD, P_ODD, P_EVEN },
|
||||
/* 6 */ { P_ODD, P_EVEN, P_EVEN, P_EVEN, P_ODD, P_ODD },
|
||||
/* 7 */ { P_ODD, P_EVEN, P_ODD, P_EVEN, P_ODD, P_EVEN },
|
||||
/* 8 */ { P_ODD, P_EVEN, P_ODD, P_EVEN, P_EVEN, P_ODD },
|
||||
/* 9 */ { P_ODD, P_EVEN, P_EVEN, P_ODD, P_EVEN, P_ODD }
|
||||
};
|
||||
const Parity parity[10][6] = {
|
||||
/* Pos 1, Pos 2, Pos 3, Pos 4, Pos 5, Pos 6 */
|
||||
/* 0 (UPC-A) */ { P_ODD, P_ODD, P_ODD, P_ODD, P_ODD, P_ODD },
|
||||
/* 1 */ { P_ODD, P_ODD, P_EVEN, P_ODD, P_EVEN, P_EVEN },
|
||||
/* 2 */ { P_ODD, P_ODD, P_EVEN, P_EVEN, P_ODD, P_EVEN },
|
||||
/* 3 */ { P_ODD, P_ODD, P_EVEN, P_EVEN, P_EVEN, P_ODD },
|
||||
/* 4 */ { P_ODD, P_EVEN, P_ODD, P_ODD, P_EVEN, P_EVEN },
|
||||
/* 5 */ { P_ODD, P_EVEN, P_EVEN, P_ODD, P_ODD, P_EVEN },
|
||||
/* 6 */ { P_ODD, P_EVEN, P_EVEN, P_EVEN, P_ODD, P_ODD },
|
||||
/* 7 */ { P_ODD, P_EVEN, P_ODD, P_EVEN, P_ODD, P_EVEN },
|
||||
/* 8 */ { P_ODD, P_EVEN, P_ODD, P_EVEN, P_EVEN, P_ODD },
|
||||
/* 9 */ { P_ODD, P_EVEN, P_EVEN, P_ODD, P_EVEN, P_ODD }
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
const int QUIET_MODULES = 9;
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
const int QUIET_MODULES = 9;
|
||||
|
||||
const double BASE_MODULE_SIZE = ( 0.01 * PTS_PER_INCH );
|
||||
const double BASE_FONT_SIZE = 7;
|
||||
const double BASE_TEXT_AREA_HEIGHT = 11;
|
||||
const double BASE_MODULE_SIZE = ( 0.01 * PTS_PER_INCH );
|
||||
const double BASE_FONT_SIZE = 7;
|
||||
const double BASE_TEXT_AREA_HEIGHT = 11;
|
||||
}
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/*
|
||||
* UPC data validation, implements Barcode1dBase::validate()
|
||||
*/
|
||||
bool BarcodeUpcBase::validate( const std::string& rawData )
|
||||
{
|
||||
int nDigits = 0;
|
||||
/*
|
||||
* UPC data validation, implements Barcode1dBase::validate()
|
||||
*/
|
||||
bool BarcodeUpcBase::validate( const std::string& rawData )
|
||||
{
|
||||
int nDigits = 0;
|
||||
|
||||
for (char c : rawData)
|
||||
{
|
||||
if ( isdigit( c ) )
|
||||
{
|
||||
nDigits++;
|
||||
}
|
||||
else if ( c != ' ')
|
||||
{
|
||||
/* Only allow digits and spaces -- ignoring spaces. */
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (char c : rawData)
|
||||
{
|
||||
if ( isdigit( c ) )
|
||||
{
|
||||
nDigits++;
|
||||
}
|
||||
else if ( c != ' ')
|
||||
{
|
||||
/* Only allow digits and spaces -- ignoring spaces. */
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* validate nDigits (call implementation from concrete class) */
|
||||
return validateDigits( nDigits );
|
||||
}
|
||||
/* validate nDigits (call implementation from concrete class) */
|
||||
return validateDigits( nDigits );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* UPC data encoding, implements Barcode1dBase::encode()
|
||||
*/
|
||||
std::string BarcodeUpcBase::encode( const std::string& cookedData )
|
||||
{
|
||||
int sumOdd = 0;
|
||||
int sumEven = mFirstDigitVal;
|
||||
/*
|
||||
* UPC data encoding, implements Barcode1dBase::encode()
|
||||
*/
|
||||
std::string BarcodeUpcBase::encode( const std::string& cookedData )
|
||||
{
|
||||
int sumOdd = 0;
|
||||
int sumEven = mFirstDigitVal;
|
||||
|
||||
std::string code;
|
||||
std::string code;
|
||||
|
||||
/* Left frame symbol */
|
||||
code += sSymbol;
|
||||
/* Left frame symbol */
|
||||
code += sSymbol;
|
||||
|
||||
/* Left 6 digits */
|
||||
for ( int i = 0; i < 6; i++ )
|
||||
{
|
||||
int cValue = cookedData[i] - '0';
|
||||
code += symbols[ cValue ][ parity[ mFirstDigitVal ][ i ] ];
|
||||
/* Left 6 digits */
|
||||
for ( int i = 0; i < 6; i++ )
|
||||
{
|
||||
int cValue = cookedData[i] - '0';
|
||||
code += symbols[ cValue ][ parity[ mFirstDigitVal ][ i ] ];
|
||||
|
||||
if ( (i & 1) == 0 )
|
||||
{
|
||||
sumOdd += cValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
sumEven += cValue;
|
||||
}
|
||||
}
|
||||
if ( (i & 1) == 0 )
|
||||
{
|
||||
sumOdd += cValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
sumEven += cValue;
|
||||
}
|
||||
}
|
||||
|
||||
/* Middle frame symbol */
|
||||
code += mSymbol;
|
||||
/* Middle frame symbol */
|
||||
code += mSymbol;
|
||||
|
||||
/* Right 5 digits */
|
||||
for ( int i = 6; i < 11; i++ )
|
||||
{
|
||||
int cValue = cookedData[i] - '0';
|
||||
code += symbols[cValue][P_ODD];
|
||||
/* Right 5 digits */
|
||||
for ( int i = 6; i < 11; i++ )
|
||||
{
|
||||
int cValue = cookedData[i] - '0';
|
||||
code += symbols[cValue][P_ODD];
|
||||
|
||||
if ( (i & 1) == 0 )
|
||||
{
|
||||
sumOdd += cValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
sumEven += cValue;
|
||||
}
|
||||
}
|
||||
if ( (i & 1) == 0 )
|
||||
{
|
||||
sumOdd += cValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
sumEven += cValue;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check digit */
|
||||
mCheckDigitVal = (3*sumOdd + sumEven) % 10;
|
||||
if ( mCheckDigitVal != 0 )
|
||||
{
|
||||
mCheckDigitVal = 10 - mCheckDigitVal;
|
||||
}
|
||||
code += symbols[mCheckDigitVal][P_ODD];
|
||||
/* Check digit */
|
||||
mCheckDigitVal = (3*sumOdd + sumEven) % 10;
|
||||
if ( mCheckDigitVal != 0 )
|
||||
{
|
||||
mCheckDigitVal = 10 - mCheckDigitVal;
|
||||
}
|
||||
code += symbols[mCheckDigitVal][P_ODD];
|
||||
|
||||
/* Right frame symbol */
|
||||
code += eSymbol;
|
||||
/* Right frame symbol */
|
||||
code += eSymbol;
|
||||
|
||||
/* Append a final zero length space to make the length of the encoded string even. */
|
||||
/* This is because vectorize() handles bars and spaces in pairs. */
|
||||
code += "0";
|
||||
/* Append a final zero length space to make the length of the encoded string even. */
|
||||
/* This is because vectorize() handles bars and spaces in pairs. */
|
||||
code += "0";
|
||||
|
||||
return code;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* UPC prepare text for display, implements Barcode1dBase::prepareText()
|
||||
*/
|
||||
std::string BarcodeUpcBase::prepareText( const std::string& rawData )
|
||||
{
|
||||
std::string displayText;
|
||||
/*
|
||||
* UPC prepare text for display, implements Barcode1dBase::prepareText()
|
||||
*/
|
||||
std::string BarcodeUpcBase::prepareText( const std::string& rawData )
|
||||
{
|
||||
std::string displayText;
|
||||
|
||||
if ( showText() )
|
||||
{
|
||||
for (char c : rawData)
|
||||
{
|
||||
if ( isdigit( c ) )
|
||||
{
|
||||
displayText += c;
|
||||
}
|
||||
}
|
||||
if ( showText() )
|
||||
{
|
||||
for (char c : rawData)
|
||||
{
|
||||
if ( isdigit( c ) )
|
||||
{
|
||||
displayText += c;
|
||||
}
|
||||
}
|
||||
|
||||
displayText += (mCheckDigitVal + '0');
|
||||
}
|
||||
displayText += (mCheckDigitVal + '0');
|
||||
}
|
||||
|
||||
return displayText;
|
||||
}
|
||||
return displayText;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* UPC vectorization, implements Barcode1dBase::vectorize()
|
||||
*/
|
||||
void BarcodeUpcBase::vectorize( const std::string& codedData,
|
||||
const std::string& displayText,
|
||||
const std::string& cookedData,
|
||||
double& w,
|
||||
double& h )
|
||||
{
|
||||
/* determine width and establish horizontal scale */
|
||||
int nModules = 7*int(cookedData.size()+1) + 11;
|
||||
/*
|
||||
* UPC vectorization, implements Barcode1dBase::vectorize()
|
||||
*/
|
||||
void BarcodeUpcBase::vectorize( const std::string& codedData,
|
||||
const std::string& displayText,
|
||||
const std::string& cookedData,
|
||||
double& w,
|
||||
double& h )
|
||||
{
|
||||
/* determine width and establish horizontal scale */
|
||||
int nModules = 7*int(cookedData.size()+1) + 11;
|
||||
|
||||
double scale;
|
||||
if ( w == 0 )
|
||||
{
|
||||
scale = 1.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
scale = w / ((nModules + 2*QUIET_MODULES) * BASE_MODULE_SIZE);
|
||||
double scale;
|
||||
if ( w == 0 )
|
||||
{
|
||||
scale = 1.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
scale = w / ((nModules + 2*QUIET_MODULES) * BASE_MODULE_SIZE);
|
||||
|
||||
if ( scale < 1.0 )
|
||||
{
|
||||
scale = 1.0;
|
||||
}
|
||||
}
|
||||
double mscale = scale * BASE_MODULE_SIZE;
|
||||
if ( scale < 1.0 )
|
||||
{
|
||||
scale = 1.0;
|
||||
}
|
||||
}
|
||||
double mscale = scale * BASE_MODULE_SIZE;
|
||||
|
||||
double width = mscale * (nModules + 2*QUIET_MODULES);
|
||||
double xQuiet = mscale * QUIET_MODULES;
|
||||
double width = mscale * (nModules + 2*QUIET_MODULES);
|
||||
double xQuiet = mscale * QUIET_MODULES;
|
||||
|
||||
/* determine bar height */
|
||||
double hTextArea = showText() ? scale * BASE_TEXT_AREA_HEIGHT : 0;
|
||||
double hBar1 = std::max( (h - hTextArea), width/2 );
|
||||
double hBar2 = hBar1 + hTextArea/2;
|
||||
/* determine bar height */
|
||||
double hTextArea = showText() ? scale * BASE_TEXT_AREA_HEIGHT : 0;
|
||||
double hBar1 = std::max( (h - hTextArea), width/2 );
|
||||
double hBar2 = hBar1 + hTextArea/2;
|
||||
|
||||
/* now traverse the code string and draw each bar */
|
||||
auto nBarsSpaces = int( codedData.size() - 1 ); /* coded data has dummy "0" on end. */
|
||||
/* now traverse the code string and draw each bar */
|
||||
auto nBarsSpaces = int( codedData.size() - 1 ); /* coded data has dummy "0" on end. */
|
||||
|
||||
double xModules = 0;
|
||||
for ( int i = 0; i < nBarsSpaces; i += 2 )
|
||||
{
|
||||
double hBar;
|
||||
double xModules = 0;
|
||||
for ( int i = 0; i < nBarsSpaces; i += 2 )
|
||||
{
|
||||
double hBar;
|
||||
|
||||
if ( ( (xModules > mEndBarsModules) && (xModules < (nModules/2-1)) ) ||
|
||||
( (xModules > (nModules/2+1)) && (xModules < (nModules-mEndBarsModules)) ) )
|
||||
{
|
||||
hBar = hBar1;
|
||||
}
|
||||
else
|
||||
{
|
||||
hBar = hBar2;
|
||||
}
|
||||
if ( ( (xModules > mEndBarsModules) && (xModules < (nModules/2-1)) ) ||
|
||||
( (xModules > (nModules/2+1)) && (xModules < (nModules-mEndBarsModules)) ) )
|
||||
{
|
||||
hBar = hBar1;
|
||||
}
|
||||
else
|
||||
{
|
||||
hBar = hBar2;
|
||||
}
|
||||
|
||||
/* Bar */
|
||||
int wBar = codedData[i] - '0';
|
||||
addLine( xQuiet + mscale*xModules, 0.0, mscale*wBar, hBar );
|
||||
xModules += wBar;
|
||||
/* Bar */
|
||||
int wBar = codedData[i] - '0';
|
||||
addLine( xQuiet + mscale*xModules, 0.0, mscale*wBar, hBar );
|
||||
xModules += wBar;
|
||||
|
||||
/* Space */
|
||||
int wSpace = codedData[i+1] - '0';
|
||||
xModules += wSpace;
|
||||
}
|
||||
/* Space */
|
||||
int wSpace = codedData[i+1] - '0';
|
||||
xModules += wSpace;
|
||||
}
|
||||
|
||||
|
||||
/* draw text */
|
||||
if ( showText() )
|
||||
{
|
||||
/* determine text parameters */
|
||||
double textSize1 = scale * BASE_FONT_SIZE;
|
||||
double textSize2 = 0.75*textSize1;
|
||||
/* draw text */
|
||||
if ( showText() )
|
||||
{
|
||||
/* determine text parameters */
|
||||
double textSize1 = scale * BASE_FONT_SIZE;
|
||||
double textSize2 = 0.75*textSize1;
|
||||
|
||||
double textX1Left = xQuiet + mscale*(0.25*nModules + 0.5*mEndBarsModules - 0.75);
|
||||
double textX1Right = xQuiet + mscale*(0.75*nModules - 0.5*mEndBarsModules + 0.75);
|
||||
double textX2Left = 0.5*xQuiet;
|
||||
double textX2Right = 1.5*xQuiet + mscale*nModules;
|
||||
double textX1Left = xQuiet + mscale*(0.25*nModules + 0.5*mEndBarsModules - 0.75);
|
||||
double textX1Right = xQuiet + mscale*(0.75*nModules - 0.5*mEndBarsModules + 0.75);
|
||||
double textX2Left = 0.5*xQuiet;
|
||||
double textX2Right = 1.5*xQuiet + mscale*nModules;
|
||||
|
||||
double textY1 = hBar2 + textSize1/4;
|
||||
double textY2 = hBar2 + textSize2/4;
|
||||
double textY1 = hBar2 + textSize1/4;
|
||||
double textY2 = hBar2 + textSize2/4;
|
||||
|
||||
/* draw text (call implementation from concrete class) */
|
||||
vectorizeText( displayText,
|
||||
textSize1, textSize2,
|
||||
textX1Left, textX1Right, textY1,
|
||||
textX2Left, textX2Right, textY2 );
|
||||
}
|
||||
|
||||
/* draw text (call implementation from concrete class) */
|
||||
vectorizeText( displayText,
|
||||
textSize1, textSize2,
|
||||
textX1Left, textX1Right, textY1,
|
||||
textX2Left, textX2Right, textY2 );
|
||||
}
|
||||
|
||||
/* Overwrite requested size with actual size. */
|
||||
w = width;
|
||||
h = hBar1 + hTextArea;
|
||||
}
|
||||
|
||||
/* Overwrite requested size with actual size. */
|
||||
w = width;
|
||||
h = hBar1 + hTextArea;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
/* BarcodeUpcBase.h
|
||||
*
|
||||
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glbarcode_BarcodeUpcBase_h
|
||||
#define glbarcode_BarcodeUpcBase_h
|
||||
|
||||
|
||||
#include "Barcode1dBase.h"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/**
|
||||
* @class BarcodeUpcBase BarcodeUpcBase.h glbarcode/BarcodeUpcBase.h
|
||||
*
|
||||
* UpcBase barcode, base class for UPC-A and EAN-13 barcode types, implements Barcode1dBase
|
||||
*/
|
||||
class BarcodeUpcBase : public Barcode1dBase
|
||||
{
|
||||
protected:
|
||||
virtual bool validateDigits( int nDigits ) = 0;
|
||||
|
||||
virtual void vectorizeText( const std::string& displayText,
|
||||
double size1,
|
||||
double size2,
|
||||
double x1Left,
|
||||
double x1Right,
|
||||
double y1,
|
||||
double x2Left,
|
||||
double x2Right,
|
||||
double y2 ) = 0;
|
||||
|
||||
private:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
|
||||
std::string prepareText( const std::string& rawData ) override;
|
||||
|
||||
void vectorize( const std::string& codedData,
|
||||
const std::string& displayText,
|
||||
const std::string& cookedData,
|
||||
double& w,
|
||||
double& h ) override;
|
||||
|
||||
|
||||
protected:
|
||||
int mEndBarsModules;
|
||||
int mFirstDigitVal;
|
||||
|
||||
|
||||
private:
|
||||
int mCheckDigitVal;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_BarcodeUpcBase_h
|
||||
@@ -0,0 +1,78 @@
|
||||
// BarcodeUpcBase.hpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#ifndef glbarcode_BarcodeUpcBase_hpp
|
||||
#define glbarcode_BarcodeUpcBase_hpp
|
||||
|
||||
|
||||
#include "Barcode1dBase.hpp"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/**
|
||||
* @class BarcodeUpcBase BarcodeUpcBase.h glbarcode/BarcodeUpcBase.h
|
||||
*
|
||||
* UpcBase barcode, base class for UPC-A and EAN-13 barcode types, implements Barcode1dBase
|
||||
*/
|
||||
class BarcodeUpcBase : public Barcode1dBase
|
||||
{
|
||||
protected:
|
||||
virtual bool validateDigits( int nDigits ) = 0;
|
||||
|
||||
virtual void vectorizeText( const std::string& displayText,
|
||||
double size1,
|
||||
double size2,
|
||||
double x1Left,
|
||||
double x1Right,
|
||||
double y1,
|
||||
double x2Left,
|
||||
double x2Right,
|
||||
double y2 ) = 0;
|
||||
|
||||
private:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
|
||||
std::string encode( const std::string& cookedData ) override;
|
||||
|
||||
std::string prepareText( const std::string& rawData ) override;
|
||||
|
||||
void vectorize( const std::string& codedData,
|
||||
const std::string& displayText,
|
||||
const std::string& cookedData,
|
||||
double& w,
|
||||
double& h ) override;
|
||||
|
||||
|
||||
protected:
|
||||
int mEndBarsModules;
|
||||
int mFirstDigitVal;
|
||||
|
||||
|
||||
private:
|
||||
int mCheckDigitVal;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_BarcodeUpcBase_hpp
|
||||
@@ -34,7 +34,7 @@ add_library (glbarcode STATIC
|
||||
)
|
||||
|
||||
target_compile_features (glbarcode
|
||||
PUBLIC cxx_std_11
|
||||
PUBLIC cxx_std_20
|
||||
)
|
||||
|
||||
target_include_directories (glbarcode
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
/* Constants.h
|
||||
*
|
||||
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glbarcode_Constants_h
|
||||
#define glbarcode_Constants_h
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
namespace Constants
|
||||
{
|
||||
const double PTS_PER_INCH = 72.0; /**< Points per inch. */
|
||||
const double PTS_PER_MM = 2.83464566929; /**< Points per millimeter. */
|
||||
const double PTS_PER_CM = 10*PTS_PER_MM; /**< Points per centimeter. */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_Constants_h
|
||||
@@ -0,0 +1,38 @@
|
||||
// Constants.hpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#ifndef glbarcode_Constants_hpp
|
||||
#define glbarcode_Constants_hpp
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
namespace Constants
|
||||
{
|
||||
const double PTS_PER_INCH = 72.0; /**< Points per inch. */
|
||||
const double PTS_PER_MM = 2.83464566929; /**< Points per millimeter. */
|
||||
const double PTS_PER_CM = 10*PTS_PER_MM; /**< Points per centimeter. */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_Constants_hpp
|
||||
@@ -1,139 +1,140 @@
|
||||
/* DrawingPrimitives.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// DrawingPrimitives.cpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#include "DrawingPrimitives.h"
|
||||
|
||||
#include "DrawingPrimitives.hpp"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
DrawingPrimitive::DrawingPrimitive( double x, double y )
|
||||
: mX(x), mY(y)
|
||||
{
|
||||
}
|
||||
DrawingPrimitive::DrawingPrimitive( double x, double y )
|
||||
: mX(x), mY(y)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
double DrawingPrimitive::x() const
|
||||
{
|
||||
return mX;
|
||||
}
|
||||
double DrawingPrimitive::x() const
|
||||
{
|
||||
return mX;
|
||||
}
|
||||
|
||||
|
||||
double DrawingPrimitive::y() const
|
||||
{
|
||||
return mY;
|
||||
}
|
||||
double DrawingPrimitive::y() const
|
||||
{
|
||||
return mY;
|
||||
}
|
||||
|
||||
|
||||
|
||||
DrawingPrimitiveLine::DrawingPrimitiveLine( double x, double y, double w, double h )
|
||||
: DrawingPrimitive( x, y ), mW(w), mH(h)
|
||||
{
|
||||
}
|
||||
DrawingPrimitiveLine::DrawingPrimitiveLine( double x, double y, double w, double h )
|
||||
: DrawingPrimitive( x, y ), mW(w), mH(h)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
double DrawingPrimitiveLine::w() const
|
||||
{
|
||||
return mW;
|
||||
}
|
||||
double DrawingPrimitiveLine::w() const
|
||||
{
|
||||
return mW;
|
||||
}
|
||||
|
||||
|
||||
double DrawingPrimitiveLine::h() const
|
||||
{
|
||||
return mH;
|
||||
}
|
||||
double DrawingPrimitiveLine::h() const
|
||||
{
|
||||
return mH;
|
||||
}
|
||||
|
||||
|
||||
|
||||
DrawingPrimitiveBox::DrawingPrimitiveBox( double x, double y, double w, double h )
|
||||
: DrawingPrimitive( x, y ), mW(w), mH(h)
|
||||
{
|
||||
}
|
||||
DrawingPrimitiveBox::DrawingPrimitiveBox( double x, double y, double w, double h )
|
||||
: DrawingPrimitive( x, y ), mW(w), mH(h)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
double DrawingPrimitiveBox::w() const
|
||||
{
|
||||
return mW;
|
||||
}
|
||||
double DrawingPrimitiveBox::w() const
|
||||
{
|
||||
return mW;
|
||||
}
|
||||
|
||||
|
||||
double DrawingPrimitiveBox::h() const
|
||||
{
|
||||
return mH;
|
||||
}
|
||||
double DrawingPrimitiveBox::h() const
|
||||
{
|
||||
return mH;
|
||||
}
|
||||
|
||||
|
||||
|
||||
DrawingPrimitiveText::DrawingPrimitiveText( double x, double y, double size, const std::string& text, HAlign halign )
|
||||
: DrawingPrimitive( x, y ), mSize(size), mText(text), mHalign(halign)
|
||||
{
|
||||
}
|
||||
DrawingPrimitiveText::DrawingPrimitiveText( double x, double y, double size, const std::string& text, HAlign halign )
|
||||
: DrawingPrimitive( x, y ), mSize(size), mText(text), mHalign(halign)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
double DrawingPrimitiveText::size() const
|
||||
{
|
||||
return mSize;
|
||||
}
|
||||
double DrawingPrimitiveText::size() const
|
||||
{
|
||||
return mSize;
|
||||
}
|
||||
|
||||
|
||||
const std::string& DrawingPrimitiveText::text() const
|
||||
{
|
||||
return mText;
|
||||
}
|
||||
const std::string& DrawingPrimitiveText::text() const
|
||||
{
|
||||
return mText;
|
||||
}
|
||||
|
||||
|
||||
HAlign DrawingPrimitiveText::halign() const
|
||||
{
|
||||
return mHalign;
|
||||
}
|
||||
HAlign DrawingPrimitiveText::halign() const
|
||||
{
|
||||
return mHalign;
|
||||
}
|
||||
|
||||
|
||||
|
||||
DrawingPrimitiveRing::DrawingPrimitiveRing( double x, double y, double r, double w )
|
||||
: DrawingPrimitive( x, y ), mR(r), mW(w)
|
||||
{
|
||||
}
|
||||
DrawingPrimitiveRing::DrawingPrimitiveRing( double x, double y, double r, double w )
|
||||
: DrawingPrimitive( x, y ), mR(r), mW(w)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
double DrawingPrimitiveRing::r() const
|
||||
{
|
||||
return mR;
|
||||
}
|
||||
double DrawingPrimitiveRing::r() const
|
||||
{
|
||||
return mR;
|
||||
}
|
||||
|
||||
|
||||
double DrawingPrimitiveRing::w() const
|
||||
{
|
||||
return mW;
|
||||
}
|
||||
double DrawingPrimitiveRing::w() const
|
||||
{
|
||||
return mW;
|
||||
}
|
||||
|
||||
|
||||
|
||||
DrawingPrimitiveHexagon::DrawingPrimitiveHexagon( double x, double y, double h )
|
||||
: DrawingPrimitive( x, y ), mH(h)
|
||||
{
|
||||
}
|
||||
DrawingPrimitiveHexagon::DrawingPrimitiveHexagon( double x, double y, double h )
|
||||
: DrawingPrimitive( x, y ), mH(h)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
double DrawingPrimitiveHexagon::h() const
|
||||
{
|
||||
return mH;
|
||||
}
|
||||
double DrawingPrimitiveHexagon::h() const
|
||||
{
|
||||
return mH;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,269 +0,0 @@
|
||||
/* DrawingPrimitives.h
|
||||
*
|
||||
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glbarcode_DrawingPrimitives_h
|
||||
#define glbarcode_DrawingPrimitives_h
|
||||
|
||||
|
||||
#include "Enums.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/**
|
||||
* @class DrawingPrimitive DrawingPrimitives.h glbarcode/DrawingPrimitives.h
|
||||
*
|
||||
* Base class for all drawing primitives
|
||||
*/
|
||||
class DrawingPrimitive
|
||||
{
|
||||
protected:
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param[in] x X coordinate of primitive's origin (points)
|
||||
* @param[in] y Y coordinate of primitive's origin (points)
|
||||
*/
|
||||
DrawingPrimitive( double x, double y );
|
||||
|
||||
public:
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
virtual ~DrawingPrimitive() = default;
|
||||
|
||||
/*
|
||||
* Non-copyable
|
||||
*/
|
||||
DrawingPrimitive( const DrawingPrimitive & ) = delete;
|
||||
void operator=( const DrawingPrimitive & ) = delete;
|
||||
|
||||
/**
|
||||
* Get X coordinate of primitive's origin (points).
|
||||
*/
|
||||
double x() const;
|
||||
|
||||
/**
|
||||
* Get Y coordinate of primitive's origin (points).
|
||||
*/
|
||||
double y() const;
|
||||
|
||||
private:
|
||||
double mX; /**< X coordinate of primitive's origin (points). */
|
||||
double mY; /**< Y coordinate of primitive's origin (points). */
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @class DrawingPrimitiveLine DrawingPrimitives.h glbarcode/DrawingPrimitives.h
|
||||
*
|
||||
* A solid vertical line drawing primitive.
|
||||
*
|
||||
* @image html figure-primitive-line.svg "Line primitive properties"
|
||||
*
|
||||
*/
|
||||
class DrawingPrimitiveLine : public DrawingPrimitive
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Line constructor
|
||||
*
|
||||
* @param[in] x X coordinate of line's origin (points)
|
||||
* @param[in] y Y coordinate of line's origin (points)
|
||||
* @param[in] w Line width (points)
|
||||
* @param[in] h Line height (points)
|
||||
*/
|
||||
DrawingPrimitiveLine( double x, double y, double w, double h );
|
||||
|
||||
/**
|
||||
* Get line width (points).
|
||||
*/
|
||||
double w() const;
|
||||
|
||||
/**
|
||||
* Get line height (points).
|
||||
*/
|
||||
double h() const;
|
||||
|
||||
private:
|
||||
double mW; /**< Line width (points). */
|
||||
double mH; /**< Line length (points). */
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @class DrawingPrimitiveBox DrawingPrimitives.h glbarcode/DrawingPrimitives.h
|
||||
*
|
||||
* A solid box drawing primitive.
|
||||
*
|
||||
* @image html figure-primitive-box.svg "Box primitive properties"
|
||||
*
|
||||
*/
|
||||
class DrawingPrimitiveBox : public DrawingPrimitive
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Box constructor
|
||||
*
|
||||
* @param[in] x X coordinate of box's origin (points)
|
||||
* @param[in] y Y coordinate of box's origin (points)
|
||||
* @param[in] w Width of box (points)
|
||||
* @param[in] h Height of box (points)
|
||||
*/
|
||||
DrawingPrimitiveBox( double x, double y, double w, double h );
|
||||
|
||||
/**
|
||||
* Get box width (points).
|
||||
*/
|
||||
double w() const;
|
||||
|
||||
/**
|
||||
* Get box height (points).
|
||||
*/
|
||||
double h() const;
|
||||
|
||||
private:
|
||||
double mW; /**< Width of box (points). */
|
||||
double mH; /**< Height of box (points). */
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @class DrawingPrimitiveText DrawingPrimitives.h glbarcode/DrawingPrimitives.h
|
||||
*
|
||||
* A character string drawing primitive.
|
||||
*
|
||||
* @image html figure-primitive-text.svg "Text primitive properties"
|
||||
*
|
||||
*/
|
||||
class DrawingPrimitiveText : public DrawingPrimitive
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Text constructor
|
||||
*
|
||||
* @param[in] x X coordinate of text's origin (points)
|
||||
* @param[in] y Y coordinate of text's origin (points)
|
||||
* @param[in] size Font size of text (points)
|
||||
* @param[in] text Text
|
||||
* @param[in] halign Horizontal text alignment
|
||||
*/
|
||||
DrawingPrimitiveText( double x, double y, double size, const std::string& text, HAlign halign = H_ALIGN_CENTER );
|
||||
|
||||
/**
|
||||
* Get font size (points).
|
||||
*/
|
||||
double size() const;
|
||||
|
||||
/**
|
||||
* Get text.
|
||||
*/
|
||||
const std::string& text() const;
|
||||
|
||||
/**
|
||||
* Get horizontal alignment.
|
||||
*/
|
||||
HAlign halign() const;
|
||||
|
||||
private:
|
||||
double mSize; /**< Font size of text (points). */
|
||||
std::string mText; /**< Text. */
|
||||
HAlign mHalign; /**< Horizontal alignment. */
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @class DrawingPrimitiveRing DrawingPrimitives.h glbarcode/DrawingPrimitives.h
|
||||
*
|
||||
* A ring (an open circle) drawing primitive.
|
||||
*
|
||||
* @image html figure-primitive-ring.svg "Ring primitive properties"
|
||||
*
|
||||
*/
|
||||
class DrawingPrimitiveRing : public DrawingPrimitive
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Ring constructor
|
||||
*
|
||||
* @param[in] x X coordinate of ring's origin (points)
|
||||
* @param[in] y Y coordinate of ring's origin (points)
|
||||
* @param[in] r Radius of ring (points)
|
||||
* @param[in] w Line width of ring (points)
|
||||
*/
|
||||
DrawingPrimitiveRing( double x, double y, double r, double w );
|
||||
|
||||
/**
|
||||
* Get radius of ring (points).
|
||||
*/
|
||||
double r() const;
|
||||
|
||||
/**
|
||||
* Get line width (points).
|
||||
*/
|
||||
double w() const;
|
||||
|
||||
private:
|
||||
double mR; /**< Radius of ring (points). */
|
||||
double mW; /**< Line width of ring (points). */
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @class DrawingPrimitiveHexagon DrawingPrimitives.h glbarcode/DrawingPrimitives.h
|
||||
*
|
||||
* A solid regular hexagon (oriented with vertexes at top and bottom) drawing primitive.
|
||||
*
|
||||
* @image html figure-primitive-hexagon.svg "Hexagon primitive properties"
|
||||
*
|
||||
*/
|
||||
class DrawingPrimitiveHexagon : public DrawingPrimitive
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Hexagon constructor
|
||||
*
|
||||
* @param[in] x X coordinate of hexagon's origin (points)
|
||||
* @param[in] y Y coordinate of hexagon's origin (points)
|
||||
* @param[in] h Height of hexagon (points)
|
||||
*/
|
||||
DrawingPrimitiveHexagon( double x, double y, double h );
|
||||
|
||||
/**
|
||||
* Get Hexagon height (points).
|
||||
*/
|
||||
double h() const;
|
||||
|
||||
private:
|
||||
double mH; /**< Height of hexagon (points). */
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_DrawingPrimitives_h
|
||||
@@ -0,0 +1,269 @@
|
||||
// DrawingPrimitives.hpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#ifndef glbarcode_DrawingPrimitives_hpp
|
||||
#define glbarcode_DrawingPrimitives_hpp
|
||||
|
||||
|
||||
#include "Enums.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/**
|
||||
* @class DrawingPrimitive DrawingPrimitives.h glbarcode/DrawingPrimitives.h
|
||||
*
|
||||
* Base class for all drawing primitives
|
||||
*/
|
||||
class DrawingPrimitive
|
||||
{
|
||||
protected:
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param[in] x X coordinate of primitive's origin (points)
|
||||
* @param[in] y Y coordinate of primitive's origin (points)
|
||||
*/
|
||||
DrawingPrimitive( double x, double y );
|
||||
|
||||
public:
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
virtual ~DrawingPrimitive() = default;
|
||||
|
||||
/*
|
||||
* Non-copyable
|
||||
*/
|
||||
DrawingPrimitive( const DrawingPrimitive & ) = delete;
|
||||
void operator=( const DrawingPrimitive & ) = delete;
|
||||
|
||||
/**
|
||||
* Get X coordinate of primitive's origin (points).
|
||||
*/
|
||||
double x() const;
|
||||
|
||||
/**
|
||||
* Get Y coordinate of primitive's origin (points).
|
||||
*/
|
||||
double y() const;
|
||||
|
||||
private:
|
||||
double mX; /**< X coordinate of primitive's origin (points). */
|
||||
double mY; /**< Y coordinate of primitive's origin (points). */
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @class DrawingPrimitiveLine DrawingPrimitives.h glbarcode/DrawingPrimitives.h
|
||||
*
|
||||
* A solid vertical line drawing primitive.
|
||||
*
|
||||
* @image html figure-primitive-line.svg "Line primitive properties"
|
||||
*
|
||||
*/
|
||||
class DrawingPrimitiveLine : public DrawingPrimitive
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Line constructor
|
||||
*
|
||||
* @param[in] x X coordinate of line's origin (points)
|
||||
* @param[in] y Y coordinate of line's origin (points)
|
||||
* @param[in] w Line width (points)
|
||||
* @param[in] h Line height (points)
|
||||
*/
|
||||
DrawingPrimitiveLine( double x, double y, double w, double h );
|
||||
|
||||
/**
|
||||
* Get line width (points).
|
||||
*/
|
||||
double w() const;
|
||||
|
||||
/**
|
||||
* Get line height (points).
|
||||
*/
|
||||
double h() const;
|
||||
|
||||
private:
|
||||
double mW; /**< Line width (points). */
|
||||
double mH; /**< Line length (points). */
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @class DrawingPrimitiveBox DrawingPrimitives.h glbarcode/DrawingPrimitives.h
|
||||
*
|
||||
* A solid box drawing primitive.
|
||||
*
|
||||
* @image html figure-primitive-box.svg "Box primitive properties"
|
||||
*
|
||||
*/
|
||||
class DrawingPrimitiveBox : public DrawingPrimitive
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Box constructor
|
||||
*
|
||||
* @param[in] x X coordinate of box's origin (points)
|
||||
* @param[in] y Y coordinate of box's origin (points)
|
||||
* @param[in] w Width of box (points)
|
||||
* @param[in] h Height of box (points)
|
||||
*/
|
||||
DrawingPrimitiveBox( double x, double y, double w, double h );
|
||||
|
||||
/**
|
||||
* Get box width (points).
|
||||
*/
|
||||
double w() const;
|
||||
|
||||
/**
|
||||
* Get box height (points).
|
||||
*/
|
||||
double h() const;
|
||||
|
||||
private:
|
||||
double mW; /**< Width of box (points). */
|
||||
double mH; /**< Height of box (points). */
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @class DrawingPrimitiveText DrawingPrimitives.h glbarcode/DrawingPrimitives.h
|
||||
*
|
||||
* A character string drawing primitive.
|
||||
*
|
||||
* @image html figure-primitive-text.svg "Text primitive properties"
|
||||
*
|
||||
*/
|
||||
class DrawingPrimitiveText : public DrawingPrimitive
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Text constructor
|
||||
*
|
||||
* @param[in] x X coordinate of text's origin (points)
|
||||
* @param[in] y Y coordinate of text's origin (points)
|
||||
* @param[in] size Font size of text (points)
|
||||
* @param[in] text Text
|
||||
* @param[in] halign Horizontal text alignment
|
||||
*/
|
||||
DrawingPrimitiveText( double x, double y, double size, const std::string& text, HAlign halign = H_ALIGN_CENTER );
|
||||
|
||||
/**
|
||||
* Get font size (points).
|
||||
*/
|
||||
double size() const;
|
||||
|
||||
/**
|
||||
* Get text.
|
||||
*/
|
||||
const std::string& text() const;
|
||||
|
||||
/**
|
||||
* Get horizontal alignment.
|
||||
*/
|
||||
HAlign halign() const;
|
||||
|
||||
private:
|
||||
double mSize; /**< Font size of text (points). */
|
||||
std::string mText; /**< Text. */
|
||||
HAlign mHalign; /**< Horizontal alignment. */
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @class DrawingPrimitiveRing DrawingPrimitives.h glbarcode/DrawingPrimitives.h
|
||||
*
|
||||
* A ring (an open circle) drawing primitive.
|
||||
*
|
||||
* @image html figure-primitive-ring.svg "Ring primitive properties"
|
||||
*
|
||||
*/
|
||||
class DrawingPrimitiveRing : public DrawingPrimitive
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Ring constructor
|
||||
*
|
||||
* @param[in] x X coordinate of ring's origin (points)
|
||||
* @param[in] y Y coordinate of ring's origin (points)
|
||||
* @param[in] r Radius of ring (points)
|
||||
* @param[in] w Line width of ring (points)
|
||||
*/
|
||||
DrawingPrimitiveRing( double x, double y, double r, double w );
|
||||
|
||||
/**
|
||||
* Get radius of ring (points).
|
||||
*/
|
||||
double r() const;
|
||||
|
||||
/**
|
||||
* Get line width (points).
|
||||
*/
|
||||
double w() const;
|
||||
|
||||
private:
|
||||
double mR; /**< Radius of ring (points). */
|
||||
double mW; /**< Line width of ring (points). */
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @class DrawingPrimitiveHexagon DrawingPrimitives.h glbarcode/DrawingPrimitives.h
|
||||
*
|
||||
* A solid regular hexagon (oriented with vertexes at top and bottom) drawing primitive.
|
||||
*
|
||||
* @image html figure-primitive-hexagon.svg "Hexagon primitive properties"
|
||||
*
|
||||
*/
|
||||
class DrawingPrimitiveHexagon : public DrawingPrimitive
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Hexagon constructor
|
||||
*
|
||||
* @param[in] x X coordinate of hexagon's origin (points)
|
||||
* @param[in] y Y coordinate of hexagon's origin (points)
|
||||
* @param[in] h Height of hexagon (points)
|
||||
*/
|
||||
DrawingPrimitiveHexagon( double x, double y, double h );
|
||||
|
||||
/**
|
||||
* Get Hexagon height (points).
|
||||
*/
|
||||
double h() const;
|
||||
|
||||
private:
|
||||
double mH; /**< Height of hexagon (points). */
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_DrawingPrimitives_hpp
|
||||
@@ -1,38 +0,0 @@
|
||||
/* Enums.h
|
||||
*
|
||||
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glbarcode_Enums_h
|
||||
#define glbarcode_Enums_h
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
enum HAlign
|
||||
{
|
||||
H_ALIGN_CENTER = 0,
|
||||
H_ALIGN_LEFT = 1,
|
||||
H_ALIGN_RIGHT = 2
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_Enums_h
|
||||
@@ -0,0 +1,38 @@
|
||||
// Enums.hpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#ifndef glbarcode_Enums_hpp
|
||||
#define glbarcode_Enums_hpp
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
enum HAlign
|
||||
{
|
||||
H_ALIGN_CENTER = 0,
|
||||
H_ALIGN_LEFT = 1,
|
||||
H_ALIGN_RIGHT = 2
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_Enums_hpp
|
||||
+93
-92
@@ -1,125 +1,126 @@
|
||||
/* Factory.cpp
|
||||
*
|
||||
* Copyright (C) 2013-2014 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// Factory.cpp
|
||||
//
|
||||
// Copyright (C) 2013-2014 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#include "Factory.h"
|
||||
|
||||
#include "BarcodeCode39.h"
|
||||
#include "BarcodeCode39Ext.h"
|
||||
#include "BarcodeUpcA.h"
|
||||
#include "BarcodeEan13.h"
|
||||
#include "BarcodePostnet.h"
|
||||
#include "BarcodePostnet5.h"
|
||||
#include "BarcodePostnet9.h"
|
||||
#include "BarcodePostnet11.h"
|
||||
#include "BarcodeCepnet.h"
|
||||
#include "BarcodeOnecode.h"
|
||||
#include "BarcodeDataMatrix.h"
|
||||
#include "BarcodeQrcode.h"
|
||||
#include "Factory.hpp"
|
||||
|
||||
#include "BarcodeCepnet.hpp"
|
||||
#include "BarcodeCode39.hpp"
|
||||
#include "BarcodeCode39Ext.hpp"
|
||||
#include "BarcodeDataMatrix.hpp"
|
||||
#include "BarcodeEan13.hpp"
|
||||
#include "BarcodeOnecode.hpp"
|
||||
#include "BarcodePostnet.hpp"
|
||||
#include "BarcodePostnet5.hpp"
|
||||
#include "BarcodePostnet9.hpp"
|
||||
#include "BarcodePostnet11.hpp"
|
||||
#include "BarcodeQrcode.hpp"
|
||||
#include "BarcodeUpcA.hpp"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
Factory::BarcodeTypeMap Factory::mBarcodeTypeMap;
|
||||
TypeIdList Factory::mSupportedTypes;
|
||||
Factory::BarcodeTypeMap Factory::mBarcodeTypeMap;
|
||||
TypeIdList Factory::mSupportedTypes;
|
||||
|
||||
|
||||
Factory::Factory()
|
||||
{
|
||||
/*
|
||||
* Register built-in types.
|
||||
*/
|
||||
internalRegisterType( "code39", &BarcodeCode39::create );
|
||||
internalRegisterType( "code39ext", &BarcodeCode39Ext::create );
|
||||
internalRegisterType( "upc-a", &BarcodeUpcA::create );
|
||||
internalRegisterType( "ean-13", &BarcodeEan13::create );
|
||||
internalRegisterType( "postnet", &BarcodePostnet::create );
|
||||
internalRegisterType( "postnet-5", &BarcodePostnet5::create );
|
||||
internalRegisterType( "postnet-9", &BarcodePostnet9::create );
|
||||
internalRegisterType( "postnet-11", &BarcodePostnet11::create );
|
||||
internalRegisterType( "cepnet", &BarcodeCepnet::create );
|
||||
internalRegisterType( "onecode", &BarcodeOnecode::create );
|
||||
internalRegisterType( "datamatrix", &BarcodeDataMatrix::create );
|
||||
Factory::Factory()
|
||||
{
|
||||
/*
|
||||
* Register built-in types.
|
||||
*/
|
||||
internalRegisterType( "code39", &BarcodeCode39::create );
|
||||
internalRegisterType( "code39ext", &BarcodeCode39Ext::create );
|
||||
internalRegisterType( "upc-a", &BarcodeUpcA::create );
|
||||
internalRegisterType( "ean-13", &BarcodeEan13::create );
|
||||
internalRegisterType( "postnet", &BarcodePostnet::create );
|
||||
internalRegisterType( "postnet-5", &BarcodePostnet5::create );
|
||||
internalRegisterType( "postnet-9", &BarcodePostnet9::create );
|
||||
internalRegisterType( "postnet-11", &BarcodePostnet11::create );
|
||||
internalRegisterType( "cepnet", &BarcodeCepnet::create );
|
||||
internalRegisterType( "onecode", &BarcodeOnecode::create );
|
||||
internalRegisterType( "datamatrix", &BarcodeDataMatrix::create );
|
||||
#if HAVE_QRENCODE
|
||||
internalRegisterType( "qrcode", &BarcodeQrcode::create );
|
||||
internalRegisterType( "qrcode", &BarcodeQrcode::create );
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Factory::init( )
|
||||
{
|
||||
static Factory* singletonInstance = nullptr;
|
||||
|
||||
if ( singletonInstance == nullptr )
|
||||
{
|
||||
singletonInstance = new Factory();
|
||||
}
|
||||
}
|
||||
void Factory::init( )
|
||||
{
|
||||
static Factory* singletonInstance = nullptr;
|
||||
|
||||
if ( singletonInstance == nullptr )
|
||||
{
|
||||
singletonInstance = new Factory();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Factory::registerType( const std::string& typeId, Factory::BarcodeCreateFct fct )
|
||||
{
|
||||
init();
|
||||
void Factory::registerType( const std::string& typeId, Factory::BarcodeCreateFct fct )
|
||||
{
|
||||
init();
|
||||
|
||||
internalRegisterType( typeId, fct );
|
||||
}
|
||||
internalRegisterType( typeId, fct );
|
||||
}
|
||||
|
||||
|
||||
bool Factory::isTypeSupported( const std::string& typeId )
|
||||
{
|
||||
init();
|
||||
bool Factory::isTypeSupported( const std::string& typeId )
|
||||
{
|
||||
init();
|
||||
|
||||
auto i = mBarcodeTypeMap.find( typeId );
|
||||
auto i = mBarcodeTypeMap.find( typeId );
|
||||
|
||||
return ( i != mBarcodeTypeMap.end() );
|
||||
}
|
||||
return ( i != mBarcodeTypeMap.end() );
|
||||
}
|
||||
|
||||
|
||||
TypeIdList Factory::getSupportedTypes( )
|
||||
{
|
||||
init();
|
||||
TypeIdList Factory::getSupportedTypes( )
|
||||
{
|
||||
init();
|
||||
|
||||
return mSupportedTypes;
|
||||
}
|
||||
return mSupportedTypes;
|
||||
}
|
||||
|
||||
|
||||
Barcode* Factory::createBarcode( const std::string& typeId )
|
||||
{
|
||||
init();
|
||||
Barcode* Factory::createBarcode( const std::string& typeId )
|
||||
{
|
||||
init();
|
||||
|
||||
auto i = mBarcodeTypeMap.find( typeId );
|
||||
auto i = mBarcodeTypeMap.find( typeId );
|
||||
|
||||
if( i != mBarcodeTypeMap.end() )
|
||||
{
|
||||
return i->second();
|
||||
}
|
||||
if( i != mBarcodeTypeMap.end() )
|
||||
{
|
||||
return i->second();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
void Factory::internalRegisterType( const std::string& typeId, Factory::BarcodeCreateFct fct )
|
||||
{
|
||||
mBarcodeTypeMap[ typeId ] = fct;
|
||||
mSupportedTypes.push_back( typeId );
|
||||
}
|
||||
void Factory::internalRegisterType( const std::string& typeId, Factory::BarcodeCreateFct fct )
|
||||
{
|
||||
mBarcodeTypeMap[ typeId ] = fct;
|
||||
mSupportedTypes.push_back( typeId );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,124 +0,0 @@
|
||||
/* Factory.h
|
||||
*
|
||||
* Copyright (C) 2013-2014 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glbarcode_Factory_h
|
||||
#define glbarcode_Factory_h
|
||||
|
||||
#include "Barcode.h"
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "TypeIdList.h"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
/**
|
||||
* @class Factory Factory.h glbarcode/Factory.h
|
||||
*
|
||||
* Singleton Barcode factory class.
|
||||
*/
|
||||
class Factory
|
||||
{
|
||||
|
||||
public:
|
||||
/**
|
||||
* Barcode creation function signature.
|
||||
*/
|
||||
using BarcodeCreateFct = Barcode* (*)();
|
||||
|
||||
|
||||
private:
|
||||
/**
|
||||
* Barcode factory constructor
|
||||
*/
|
||||
Factory();
|
||||
|
||||
|
||||
public:
|
||||
/**
|
||||
* Initialize barcode factory.
|
||||
*
|
||||
* Initializes the barcode factory and registers all built-in Barcode types. It
|
||||
* is optional for an application to call init(), because glbarcode++ will automatically
|
||||
* initialize the factory on demand.
|
||||
*/
|
||||
static void init();
|
||||
|
||||
|
||||
/**
|
||||
* Create barcode based on type ID string.
|
||||
*
|
||||
* @param[in] typeId Barcode type ID string
|
||||
*/
|
||||
static Barcode* createBarcode( const std::string& typeId );
|
||||
|
||||
|
||||
/**
|
||||
* Register barcode type ID.
|
||||
*
|
||||
* @param[in] typeId Barcode type ID string
|
||||
* @param[in] fct Function to create barcode object of concrete Barcode class
|
||||
*/
|
||||
static void registerType( const std::string& typeId, BarcodeCreateFct fct );
|
||||
|
||||
|
||||
/**
|
||||
* Is barcode type supported?
|
||||
*
|
||||
* @param[in] typeId Barcode type ID string
|
||||
*/
|
||||
static bool isTypeSupported( const std::string& typeId );
|
||||
|
||||
|
||||
/**
|
||||
* Get list of supported types.
|
||||
*/
|
||||
static TypeIdList getSupportedTypes();
|
||||
|
||||
|
||||
private:
|
||||
/**
|
||||
* Internal register barcode type ID.
|
||||
*
|
||||
* @param[in] typeId Barcode type ID string
|
||||
* @param[in] fct Function to create barcode object of concrete Barcode class
|
||||
*/
|
||||
static void internalRegisterType( const std::string& typeId, BarcodeCreateFct fct );
|
||||
|
||||
|
||||
/**
|
||||
* Map barcode type strings to creation functions.
|
||||
*/
|
||||
using BarcodeTypeMap = std::map<std::string,BarcodeCreateFct>;
|
||||
static BarcodeTypeMap mBarcodeTypeMap;
|
||||
|
||||
|
||||
/**
|
||||
* Supported barcode types.
|
||||
*/
|
||||
static TypeIdList mSupportedTypes;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_Factory_h
|
||||
@@ -0,0 +1,126 @@
|
||||
// Factory.hpp
|
||||
//
|
||||
// Copyright (C) 2013-2014 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#ifndef glbarcode_Factory_hpp
|
||||
#define glbarcode_Factory_hpp
|
||||
|
||||
|
||||
#include "Barcode.hpp"
|
||||
|
||||
#include "TypeIdList.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
/**
|
||||
* @class Factory Factory.h glbarcode/Factory.h
|
||||
*
|
||||
* Singleton Barcode factory class.
|
||||
*/
|
||||
class Factory
|
||||
{
|
||||
|
||||
public:
|
||||
/**
|
||||
* Barcode creation function signature.
|
||||
*/
|
||||
using BarcodeCreateFct = Barcode* (*)();
|
||||
|
||||
|
||||
private:
|
||||
/**
|
||||
* Barcode factory constructor
|
||||
*/
|
||||
Factory();
|
||||
|
||||
|
||||
public:
|
||||
/**
|
||||
* Initialize barcode factory.
|
||||
*
|
||||
* Initializes the barcode factory and registers all built-in Barcode types. It
|
||||
* is optional for an application to call init(), because glbarcode++ will automatically
|
||||
* initialize the factory on demand.
|
||||
*/
|
||||
static void init();
|
||||
|
||||
|
||||
/**
|
||||
* Create barcode based on type ID string.
|
||||
*
|
||||
* @param[in] typeId Barcode type ID string
|
||||
*/
|
||||
static Barcode* createBarcode( const std::string& typeId );
|
||||
|
||||
|
||||
/**
|
||||
* Register barcode type ID.
|
||||
*
|
||||
* @param[in] typeId Barcode type ID string
|
||||
* @param[in] fct Function to create barcode object of concrete Barcode class
|
||||
*/
|
||||
static void registerType( const std::string& typeId, BarcodeCreateFct fct );
|
||||
|
||||
|
||||
/**
|
||||
* Is barcode type supported?
|
||||
*
|
||||
* @param[in] typeId Barcode type ID string
|
||||
*/
|
||||
static bool isTypeSupported( const std::string& typeId );
|
||||
|
||||
|
||||
/**
|
||||
* Get list of supported types.
|
||||
*/
|
||||
static TypeIdList getSupportedTypes();
|
||||
|
||||
|
||||
private:
|
||||
/**
|
||||
* Internal register barcode type ID.
|
||||
*
|
||||
* @param[in] typeId Barcode type ID string
|
||||
* @param[in] fct Function to create barcode object of concrete Barcode class
|
||||
*/
|
||||
static void internalRegisterType( const std::string& typeId, BarcodeCreateFct fct );
|
||||
|
||||
|
||||
/**
|
||||
* Map barcode type strings to creation functions.
|
||||
*/
|
||||
using BarcodeTypeMap = std::map<std::string,BarcodeCreateFct>;
|
||||
static BarcodeTypeMap mBarcodeTypeMap;
|
||||
|
||||
|
||||
/**
|
||||
* Supported barcode types.
|
||||
*/
|
||||
static TypeIdList mSupportedTypes;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_Factory_hpp
|
||||
@@ -1,220 +0,0 @@
|
||||
/* Matrix.h
|
||||
*
|
||||
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glbarcode_Matrix_h
|
||||
#define glbarcode_Matrix_h
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/**
|
||||
* @class Matrix Matrix.h glbarcode/Matrix.h
|
||||
*
|
||||
* Simple 2D Matrix implementation
|
||||
*/
|
||||
template <class T> class Matrix
|
||||
{
|
||||
|
||||
public:
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
Matrix() : mNx(0), mNy(0), mData(nullptr) { }
|
||||
|
||||
|
||||
/**
|
||||
* Sized constructor.
|
||||
*/
|
||||
Matrix( int nx, int ny ) : mNx(nx),
|
||||
mNy(ny),
|
||||
mData((nx > 0 && ny > 0) ? new T[nx * ny] : nullptr) { }
|
||||
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*/
|
||||
Matrix( const Matrix<T>& src ) : mNx(src.mNx),
|
||||
mNy(src.mNy),
|
||||
mData((src.mNx > 0 && src.mNy > 0) ? new T[src.mNx * src.mNy] : nullptr)
|
||||
{
|
||||
for ( int iy = 0; iy < mNy; iy++ )
|
||||
{
|
||||
for ( int ix = 0; ix < mNx; ix++ )
|
||||
{
|
||||
(*this)[iy][ix] = src[iy][ix];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Submatrix copy constructor.
|
||||
*/
|
||||
Matrix( const Matrix<T>& src,
|
||||
int x0,
|
||||
int y0,
|
||||
int nx,
|
||||
int ny ) : mNx(nx),
|
||||
mNy(ny),
|
||||
mData((nx > 0 && ny > 0) ? new T[nx * ny] : nullptr)
|
||||
{
|
||||
for ( int iy = 0; iy < mNy; iy++ )
|
||||
{
|
||||
if ( (y0+iy) < src.ny() )
|
||||
{
|
||||
for ( int ix = 0; ix < mNx; ix++ )
|
||||
{
|
||||
if ( (x0+ix) < src.nx() )
|
||||
{
|
||||
(*this)[iy][ix] = src[y0+iy][x0+ix];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~Matrix()
|
||||
{
|
||||
if ( mData != nullptr )
|
||||
{
|
||||
delete[] mData;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy assignment "=" operator
|
||||
*/
|
||||
inline Matrix & operator=( const Matrix & src )
|
||||
{
|
||||
return Matrix( src );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Indirection "[]" operator
|
||||
*/
|
||||
inline T* operator[]( int i ) const
|
||||
{
|
||||
return (mData + (mNx * i));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Resize (destroys old content)
|
||||
*/
|
||||
inline void resize( int nx, int ny )
|
||||
{
|
||||
if ( mData != nullptr )
|
||||
{
|
||||
delete[] mData;
|
||||
}
|
||||
mNx = nx;
|
||||
mNy = ny;
|
||||
mData = (nx > 0 && ny > 0) ? new T[nx * ny] : nullptr;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get accessor for "nx" parameter.
|
||||
*
|
||||
* @returns Value of "nx" parameter
|
||||
*/
|
||||
inline int nx() const
|
||||
{
|
||||
return mNx;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get accessor for "ny" parameter.
|
||||
*
|
||||
* @returns Value of "ny" parameter
|
||||
*/
|
||||
inline int ny() const
|
||||
{
|
||||
return mNy;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract sub-matrix from this matrix
|
||||
*/
|
||||
inline Matrix<T> subMatrix( int x0, int y0, int nx, int ny )
|
||||
{
|
||||
return Matrix<T>( *this, x0, y0, nx, ny );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set sub-matrix
|
||||
*/
|
||||
inline void setSubMatrix( int x0, int y0, Matrix<T> & a )
|
||||
{
|
||||
for ( int iy = 0; iy < a.ny(); iy++ )
|
||||
{
|
||||
if ( (y0 + iy) < mNy )
|
||||
{
|
||||
for ( int ix = 0; ix < a.nx(); ix++ )
|
||||
{
|
||||
if ( (x0 + ix) < mNx )
|
||||
{
|
||||
(*this)[y0+iy][x0+ix] = a[iy][ix];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fill matrix with single value
|
||||
*/
|
||||
inline void fill( T val )
|
||||
{
|
||||
for ( int iy = 0; iy < mNy; iy++ )
|
||||
{
|
||||
for ( int ix = 0; ix < mNx; ix++ )
|
||||
{
|
||||
(*this)[iy][ix] = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
/**
|
||||
* Matrix Private data
|
||||
*/
|
||||
int mNx;
|
||||
int mNy;
|
||||
T* mData;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_Matrix_h
|
||||
@@ -0,0 +1,220 @@
|
||||
// Matrix.hpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#ifndef glbarcode_Matrix_hpp
|
||||
#define glbarcode_Matrix_hpp
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/**
|
||||
* @class Matrix Matrix.h glbarcode/Matrix.h
|
||||
*
|
||||
* Simple 2D Matrix implementation
|
||||
*/
|
||||
template <class T> class Matrix
|
||||
{
|
||||
|
||||
public:
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
Matrix() : mNx(0), mNy(0), mData(nullptr) { }
|
||||
|
||||
|
||||
/**
|
||||
* Sized constructor.
|
||||
*/
|
||||
Matrix( int nx, int ny ) : mNx(nx),
|
||||
mNy(ny),
|
||||
mData((nx > 0 && ny > 0) ? new T[nx * ny] : nullptr) { }
|
||||
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*/
|
||||
Matrix( const Matrix<T>& src ) : mNx(src.mNx),
|
||||
mNy(src.mNy),
|
||||
mData((src.mNx > 0 && src.mNy > 0) ? new T[src.mNx * src.mNy] : nullptr)
|
||||
{
|
||||
for ( int iy = 0; iy < mNy; iy++ )
|
||||
{
|
||||
for ( int ix = 0; ix < mNx; ix++ )
|
||||
{
|
||||
(*this)[iy][ix] = src[iy][ix];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Submatrix copy constructor.
|
||||
*/
|
||||
Matrix( const Matrix<T>& src,
|
||||
int x0,
|
||||
int y0,
|
||||
int nx,
|
||||
int ny ) : mNx(nx),
|
||||
mNy(ny),
|
||||
mData((nx > 0 && ny > 0) ? new T[nx * ny] : nullptr)
|
||||
{
|
||||
for ( int iy = 0; iy < mNy; iy++ )
|
||||
{
|
||||
if ( (y0+iy) < src.ny() )
|
||||
{
|
||||
for ( int ix = 0; ix < mNx; ix++ )
|
||||
{
|
||||
if ( (x0+ix) < src.nx() )
|
||||
{
|
||||
(*this)[iy][ix] = src[y0+iy][x0+ix];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~Matrix()
|
||||
{
|
||||
if ( mData != nullptr )
|
||||
{
|
||||
delete[] mData;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy assignment "=" operator
|
||||
*/
|
||||
inline Matrix & operator=( const Matrix & src )
|
||||
{
|
||||
return Matrix( src );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Indirection "[]" operator
|
||||
*/
|
||||
inline T* operator[]( int i ) const
|
||||
{
|
||||
return (mData + (mNx * i));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Resize (destroys old content)
|
||||
*/
|
||||
inline void resize( int nx, int ny )
|
||||
{
|
||||
if ( mData != nullptr )
|
||||
{
|
||||
delete[] mData;
|
||||
}
|
||||
mNx = nx;
|
||||
mNy = ny;
|
||||
mData = (nx > 0 && ny > 0) ? new T[nx * ny] : nullptr;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get accessor for "nx" parameter.
|
||||
*
|
||||
* @returns Value of "nx" parameter
|
||||
*/
|
||||
inline int nx() const
|
||||
{
|
||||
return mNx;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get accessor for "ny" parameter.
|
||||
*
|
||||
* @returns Value of "ny" parameter
|
||||
*/
|
||||
inline int ny() const
|
||||
{
|
||||
return mNy;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract sub-matrix from this matrix
|
||||
*/
|
||||
inline Matrix<T> subMatrix( int x0, int y0, int nx, int ny )
|
||||
{
|
||||
return Matrix<T>( *this, x0, y0, nx, ny );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set sub-matrix
|
||||
*/
|
||||
inline void setSubMatrix( int x0, int y0, Matrix<T> & a )
|
||||
{
|
||||
for ( int iy = 0; iy < a.ny(); iy++ )
|
||||
{
|
||||
if ( (y0 + iy) < mNy )
|
||||
{
|
||||
for ( int ix = 0; ix < a.nx(); ix++ )
|
||||
{
|
||||
if ( (x0 + ix) < mNx )
|
||||
{
|
||||
(*this)[y0+iy][x0+ix] = a[iy][ix];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fill matrix with single value
|
||||
*/
|
||||
inline void fill( T val )
|
||||
{
|
||||
for ( int iy = 0; iy < mNy; iy++ )
|
||||
{
|
||||
for ( int ix = 0; ix < mNx; ix++ )
|
||||
{
|
||||
(*this)[iy][ix] = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
/**
|
||||
* Matrix Private data
|
||||
*/
|
||||
int mNx;
|
||||
int mNy;
|
||||
T* mData;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_Matrix_hpp
|
||||
+141
-140
@@ -1,190 +1,191 @@
|
||||
/* QtRenderer.cpp
|
||||
*
|
||||
* Copyright (C) 2017 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// QtRenderer.cpp
|
||||
//
|
||||
// Copyright (C) 2017 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#include "QtRenderer.h"
|
||||
|
||||
#include "QtRenderer.hpp"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QFont>
|
||||
#include <QFontMetrics>
|
||||
#include <QString>
|
||||
#include <QTextLayout>
|
||||
#include <QtDebug>
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
const double FONT_SCALE = 0.75;
|
||||
const double MIN_POINT_SIZE = 0.4; // Less than ~0.37 causes issues for QFontMetricsF
|
||||
const double FONT_SCALE = 0.75;
|
||||
const double MIN_POINT_SIZE = 0.4; // Less than ~0.37 causes issues for QFontMetricsF
|
||||
}
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
struct QtRenderer::PrivateData
|
||||
{
|
||||
QPainter* painter;
|
||||
QColor color;
|
||||
};
|
||||
struct QtRenderer::PrivateData
|
||||
{
|
||||
QPainter* painter;
|
||||
QColor color;
|
||||
};
|
||||
|
||||
|
||||
QtRenderer::QtRenderer()
|
||||
{
|
||||
d = new QtRenderer::PrivateData;
|
||||
QtRenderer::QtRenderer()
|
||||
{
|
||||
d = new QtRenderer::PrivateData;
|
||||
|
||||
d->painter = nullptr;
|
||||
}
|
||||
d->painter = nullptr;
|
||||
}
|
||||
|
||||
|
||||
QtRenderer::QtRenderer( QPainter* painter )
|
||||
{
|
||||
d = new QtRenderer::PrivateData;
|
||||
QtRenderer::QtRenderer( QPainter* painter )
|
||||
{
|
||||
d = new QtRenderer::PrivateData;
|
||||
|
||||
setPainter( painter );
|
||||
}
|
||||
setPainter( painter );
|
||||
}
|
||||
|
||||
|
||||
QtRenderer::~QtRenderer()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
QtRenderer::~QtRenderer()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
|
||||
QPainter* QtRenderer::painter( ) const
|
||||
{
|
||||
return d->painter;
|
||||
}
|
||||
QPainter* QtRenderer::painter( ) const
|
||||
{
|
||||
return d->painter;
|
||||
}
|
||||
|
||||
|
||||
QtRenderer& QtRenderer::setPainter( QPainter* painter )
|
||||
{
|
||||
d->painter = painter;
|
||||
QtRenderer& QtRenderer::setPainter( QPainter* painter )
|
||||
{
|
||||
d->painter = painter;
|
||||
|
||||
return *this;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void QtRenderer::drawBegin( double w, double h )
|
||||
{
|
||||
if ( d->painter )
|
||||
{
|
||||
d->painter->save();
|
||||
d->color = d->painter->pen().color(); // Get current pen color
|
||||
}
|
||||
}
|
||||
void QtRenderer::drawBegin( double w, double h )
|
||||
{
|
||||
if ( d->painter )
|
||||
{
|
||||
d->painter->save();
|
||||
d->color = d->painter->pen().color(); // Get current pen color
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void QtRenderer::drawEnd( )
|
||||
{
|
||||
if ( d->painter )
|
||||
{
|
||||
d->painter->restore();
|
||||
}
|
||||
}
|
||||
void QtRenderer::drawEnd( )
|
||||
{
|
||||
if ( d->painter )
|
||||
{
|
||||
d->painter->restore();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void QtRenderer::drawLine( double x, double y, double w, double h )
|
||||
{
|
||||
if ( d->painter )
|
||||
{
|
||||
double x1 = x + w/2; // Offset line origin by 1/2 line width.
|
||||
void QtRenderer::drawLine( double x, double y, double w, double h )
|
||||
{
|
||||
if ( d->painter )
|
||||
{
|
||||
double x1 = x + w/2; // Offset line origin by 1/2 line width.
|
||||
|
||||
d->painter->setPen( QPen( d->color, w, Qt::SolidLine, Qt::FlatCap ) );
|
||||
d->painter->drawLine( QPointF(x1, y), QPointF(x1, y+h) );
|
||||
}
|
||||
}
|
||||
d->painter->setPen( QPen( d->color, w, Qt::SolidLine, Qt::FlatCap ) );
|
||||
d->painter->drawLine( QPointF(x1, y), QPointF(x1, y+h) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void QtRenderer::drawBox( double x, double y, double w, double h )
|
||||
{
|
||||
if ( d->painter )
|
||||
{
|
||||
d->painter->setPen( QPen( Qt::NoPen ) );
|
||||
d->painter->setBrush( QBrush( d->color ) );
|
||||
|
||||
d->painter->drawRect( QRectF(x, y, w, h) );
|
||||
}
|
||||
}
|
||||
void QtRenderer::drawBox( double x, double y, double w, double h )
|
||||
{
|
||||
if ( d->painter )
|
||||
{
|
||||
d->painter->setPen( QPen( Qt::NoPen ) );
|
||||
d->painter->setBrush( QBrush( d->color ) );
|
||||
|
||||
d->painter->drawRect( QRectF(x, y, w, h) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void QtRenderer::drawText( double x, double y, double size, const std::string& text, HAlign halign )
|
||||
{
|
||||
if ( d->painter )
|
||||
{
|
||||
d->painter->setPen( QPen( d->color ) );
|
||||
void QtRenderer::drawText( double x, double y, double size, const std::string& text, HAlign halign )
|
||||
{
|
||||
if ( d->painter )
|
||||
{
|
||||
d->painter->setPen( QPen( d->color ) );
|
||||
|
||||
QFont font;
|
||||
font.setStyleHint( QFont::Monospace );
|
||||
font.setFamily( "monospace" );
|
||||
font.setPointSizeF( std::max( FONT_SCALE*size, MIN_POINT_SIZE ) );
|
||||
QFont font;
|
||||
font.setStyleHint( QFont::Monospace );
|
||||
font.setFamily( "monospace" );
|
||||
font.setPointSizeF( std::max( FONT_SCALE*size, MIN_POINT_SIZE ) );
|
||||
|
||||
QFontMetricsF fm( font );
|
||||
double xCorner = x;
|
||||
if ( halign == H_ALIGN_CENTER )
|
||||
{
|
||||
xCorner -= fm.horizontalAdvance( QString::fromStdString(text) )/2.0;
|
||||
}
|
||||
else if ( halign == H_ALIGN_RIGHT )
|
||||
{
|
||||
xCorner -= fm.horizontalAdvance( QString::fromStdString(text) );
|
||||
}
|
||||
double yCorner = y - fm.ascent();
|
||||
|
||||
QTextLayout layout( QString::fromStdString(text), font );
|
||||
layout.beginLayout();
|
||||
layout.createLine();
|
||||
layout.endLayout();
|
||||
layout.draw( d->painter, QPointF(xCorner, yCorner) );
|
||||
}
|
||||
}
|
||||
QFontMetricsF fm( font );
|
||||
double xCorner = x;
|
||||
if ( halign == H_ALIGN_CENTER )
|
||||
{
|
||||
xCorner -= fm.horizontalAdvance( QString::fromStdString(text) )/2.0;
|
||||
}
|
||||
else if ( halign == H_ALIGN_RIGHT )
|
||||
{
|
||||
xCorner -= fm.horizontalAdvance( QString::fromStdString(text) );
|
||||
}
|
||||
double yCorner = y - fm.ascent();
|
||||
|
||||
QTextLayout layout( QString::fromStdString(text), font );
|
||||
layout.beginLayout();
|
||||
layout.createLine();
|
||||
layout.endLayout();
|
||||
layout.draw( d->painter, QPointF(xCorner, yCorner) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void QtRenderer::drawRing( double x, double y, double r, double w )
|
||||
{
|
||||
if ( d->painter )
|
||||
{
|
||||
d->painter->setPen( QPen( d->color, w ) );
|
||||
d->painter->setBrush( w ? Qt::NoBrush : QBrush( d->color ) );
|
||||
|
||||
d->painter->drawEllipse( QPointF(x, y), r, r );
|
||||
}
|
||||
}
|
||||
void QtRenderer::drawRing( double x, double y, double r, double w )
|
||||
{
|
||||
if ( d->painter )
|
||||
{
|
||||
d->painter->setPen( QPen( d->color, w ) );
|
||||
d->painter->setBrush( w ? Qt::NoBrush : QBrush( d->color ) );
|
||||
|
||||
d->painter->drawEllipse( QPointF(x, y), r, r );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void QtRenderer::drawHexagon( double x, double y, double h )
|
||||
{
|
||||
if ( d->painter )
|
||||
{
|
||||
d->painter->setPen( QPen( Qt::NoPen ) );
|
||||
d->painter->setBrush( QBrush( d->color ) );
|
||||
|
||||
QPolygonF hexagon;
|
||||
hexagon << QPointF( x, y )
|
||||
<< QPointF( x + 0.433*h, y + 0.25*h )
|
||||
<< QPointF( x + 0.433*h, y + 0.75*h )
|
||||
<< QPointF( x, y + h )
|
||||
<< QPointF( x - 0.433*h, y + 0.75*h )
|
||||
<< QPointF( x - 0.433*h, y + 0.25*h );
|
||||
void QtRenderer::drawHexagon( double x, double y, double h )
|
||||
{
|
||||
if ( d->painter )
|
||||
{
|
||||
d->painter->setPen( QPen( Qt::NoPen ) );
|
||||
d->painter->setBrush( QBrush( d->color ) );
|
||||
|
||||
d->painter->drawPolygon( hexagon );
|
||||
}
|
||||
}
|
||||
QPolygonF hexagon;
|
||||
hexagon << QPointF( x, y )
|
||||
<< QPointF( x + 0.433*h, y + 0.25*h )
|
||||
<< QPointF( x + 0.433*h, y + 0.75*h )
|
||||
<< QPointF( x, y + h )
|
||||
<< QPointF( x - 0.433*h, y + 0.75*h )
|
||||
<< QPointF( x - 0.433*h, y + 0.25*h );
|
||||
|
||||
d->painter->drawPolygon( hexagon );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
/* QtRenderer.h
|
||||
*
|
||||
* Copyright (C) 2017 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glbarcode_QtRenderer_h
|
||||
#define glbarcode_QtRenderer_h
|
||||
|
||||
|
||||
#include "Renderer.h"
|
||||
|
||||
#include <QPainter>
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/**
|
||||
* @class QtRenderer QtRenderer.h glbarcode/QtRenderer.h
|
||||
*
|
||||
* Render to QPainter context
|
||||
*/
|
||||
class QtRenderer : public Renderer
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
QtRenderer();
|
||||
|
||||
/**
|
||||
* Constructor with QPainter
|
||||
*/
|
||||
QtRenderer( QPainter* painter );
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
~QtRenderer() override;
|
||||
|
||||
/** Get "painter" parameter
|
||||
*
|
||||
* @returns painter parameter
|
||||
*/
|
||||
QPainter* painter() const;
|
||||
|
||||
/** Set "painter" parameter
|
||||
*
|
||||
* @param[in] painter pointer to QPainter
|
||||
*
|
||||
* @returns reference to this QtRenderer object for parameter chaining
|
||||
*/
|
||||
QtRenderer& setPainter( QPainter* painter );
|
||||
|
||||
|
||||
private:
|
||||
/*
|
||||
* Virtual methods implemented by QtRenderer.
|
||||
*/
|
||||
void drawBegin( double w, double h ) override;
|
||||
void drawEnd() override;
|
||||
void drawLine( double x, double y, double w, double h ) override;
|
||||
void drawBox( double x, double y, double w, double h ) override;
|
||||
void drawText( double x, double y, double size, const std::string& text, HAlign halign = H_ALIGN_CENTER ) override;
|
||||
void drawRing( double x, double y, double r, double w ) override;
|
||||
void drawHexagon( double x, double y, double h ) override;
|
||||
|
||||
/**
|
||||
* Private data
|
||||
*/
|
||||
struct PrivateData;
|
||||
PrivateData *d;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // glbarcode_QtRenderer_h
|
||||
@@ -0,0 +1,92 @@
|
||||
// QtRenderer.hpp
|
||||
//
|
||||
// Copyright (C) 2017 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#ifndef glbarcode_QtRenderer_hpp
|
||||
#define glbarcode_QtRenderer_hpp
|
||||
|
||||
|
||||
#include "Renderer.hpp"
|
||||
|
||||
#include <QPainter>
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
/**
|
||||
* @class QtRenderer QtRenderer.h glbarcode/QtRenderer.h
|
||||
*
|
||||
* Render to QPainter context
|
||||
*/
|
||||
class QtRenderer : public Renderer
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
QtRenderer();
|
||||
|
||||
/**
|
||||
* Constructor with QPainter
|
||||
*/
|
||||
QtRenderer( QPainter* painter );
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
~QtRenderer() override;
|
||||
|
||||
/** Get "painter" parameter
|
||||
*
|
||||
* @returns painter parameter
|
||||
*/
|
||||
QPainter* painter() const;
|
||||
|
||||
/** Set "painter" parameter
|
||||
*
|
||||
* @param[in] painter pointer to QPainter
|
||||
*
|
||||
* @returns reference to this QtRenderer object for parameter chaining
|
||||
*/
|
||||
QtRenderer& setPainter( QPainter* painter );
|
||||
|
||||
|
||||
private:
|
||||
/*
|
||||
* Virtual methods implemented by QtRenderer.
|
||||
*/
|
||||
void drawBegin( double w, double h ) override;
|
||||
void drawEnd() override;
|
||||
void drawLine( double x, double y, double w, double h ) override;
|
||||
void drawBox( double x, double y, double w, double h ) override;
|
||||
void drawText( double x, double y, double size, const std::string& text, HAlign halign = H_ALIGN_CENTER ) override;
|
||||
void drawRing( double x, double y, double r, double w ) override;
|
||||
void drawHexagon( double x, double y, double h ) override;
|
||||
|
||||
/**
|
||||
* Private data
|
||||
*/
|
||||
struct PrivateData;
|
||||
PrivateData *d;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // glbarcode_QtRenderer_hpp
|
||||
+52
-51
@@ -1,61 +1,62 @@
|
||||
/* Renderer.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// Renderer.cpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#include "Renderer.h"
|
||||
|
||||
#include "DrawingPrimitives.h"
|
||||
#include "Renderer.hpp"
|
||||
|
||||
#include "DrawingPrimitives.hpp"
|
||||
|
||||
|
||||
void glbarcode::Renderer::render( double w, double h, const std::list<DrawingPrimitive*>& primitives )
|
||||
{
|
||||
drawBegin( w, h );
|
||||
drawBegin( w, h );
|
||||
|
||||
std::list<DrawingPrimitive*>::const_iterator primitive;
|
||||
std::list<DrawingPrimitive*>::const_iterator primitive;
|
||||
|
||||
for ( primitive = primitives.begin(); primitive != primitives.end(); primitive++ )
|
||||
{
|
||||
if ( auto* line = dynamic_cast<DrawingPrimitiveLine*>(*primitive) )
|
||||
{
|
||||
drawLine( line->x(), line->y(), line->w(), line->h() );
|
||||
}
|
||||
else if ( auto* box = dynamic_cast<DrawingPrimitiveBox*>(*primitive) )
|
||||
{
|
||||
drawBox( box->x(), box->y(), box->w(), box->h() );
|
||||
}
|
||||
else if ( auto* text = dynamic_cast<DrawingPrimitiveText*>(*primitive) )
|
||||
{
|
||||
drawText( text->x(), text->y(), text->size(), text->text(), text->halign() );
|
||||
}
|
||||
else if ( auto* ring = dynamic_cast<DrawingPrimitiveRing*>(*primitive) )
|
||||
{
|
||||
drawRing( ring->x(), ring->y(), ring->r(), ring->w() );
|
||||
}
|
||||
else if ( auto* hex = dynamic_cast<DrawingPrimitiveHexagon*>(*primitive) )
|
||||
{
|
||||
drawHexagon( hex->x(), hex->y(), hex->h() );
|
||||
}
|
||||
else
|
||||
{
|
||||
// NOT REACHED
|
||||
}
|
||||
}
|
||||
for ( primitive = primitives.begin(); primitive != primitives.end(); primitive++ )
|
||||
{
|
||||
if ( auto* line = dynamic_cast<DrawingPrimitiveLine*>(*primitive) )
|
||||
{
|
||||
drawLine( line->x(), line->y(), line->w(), line->h() );
|
||||
}
|
||||
else if ( auto* box = dynamic_cast<DrawingPrimitiveBox*>(*primitive) )
|
||||
{
|
||||
drawBox( box->x(), box->y(), box->w(), box->h() );
|
||||
}
|
||||
else if ( auto* text = dynamic_cast<DrawingPrimitiveText*>(*primitive) )
|
||||
{
|
||||
drawText( text->x(), text->y(), text->size(), text->text(), text->halign() );
|
||||
}
|
||||
else if ( auto* ring = dynamic_cast<DrawingPrimitiveRing*>(*primitive) )
|
||||
{
|
||||
drawRing( ring->x(), ring->y(), ring->r(), ring->w() );
|
||||
}
|
||||
else if ( auto* hex = dynamic_cast<DrawingPrimitiveHexagon*>(*primitive) )
|
||||
{
|
||||
drawHexagon( hex->x(), hex->y(), hex->h() );
|
||||
}
|
||||
else
|
||||
{
|
||||
// NOT REACHED
|
||||
}
|
||||
}
|
||||
|
||||
drawEnd();
|
||||
drawEnd();
|
||||
}
|
||||
|
||||
@@ -1,170 +0,0 @@
|
||||
/* Renderer.h
|
||||
*
|
||||
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glbarcode_Renderer_h
|
||||
#define glbarcode_Renderer_h
|
||||
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "DrawingPrimitives.h"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
class DrawingPrimitive; /* Forward reference to private drawing primitive class. */
|
||||
|
||||
|
||||
/**
|
||||
* @class Renderer Renderer.h glbarcode/Renderer.h
|
||||
*
|
||||
* Base class for all renderers.
|
||||
*/
|
||||
class Renderer
|
||||
{
|
||||
protected:
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
Renderer() = default;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
virtual ~Renderer() = default;
|
||||
|
||||
/*
|
||||
* Non-copyable
|
||||
*/
|
||||
Renderer( const Renderer & ) = delete;
|
||||
void operator=( const Renderer & ) = delete;
|
||||
|
||||
/**
|
||||
* Render list of primitives.
|
||||
*
|
||||
* @param[in] w Width of barcode bounding box (points)
|
||||
* @param[in] h Height of barcode bounding box (points)
|
||||
* @param[in] primitives List of drawing primitives
|
||||
*/
|
||||
void render( double w, double h, const std::list<DrawingPrimitive*>& primitives );
|
||||
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Draw begin.
|
||||
*
|
||||
* Required virtual method to perform rendering setup, such as opening devices and/or
|
||||
* initializing drawing contexts.
|
||||
*
|
||||
* @param[in] w Width of barcode bounding box (points)
|
||||
* @param[in] h Height of barcode bounding box (points)
|
||||
*/
|
||||
virtual void drawBegin( double w, double h ) = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Draw end.
|
||||
*
|
||||
* Required virtual method to perform rendering cleanup, such as closing devices
|
||||
* and/or drawing contexts.
|
||||
*/
|
||||
virtual void drawEnd() = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Draw line primitive.
|
||||
*
|
||||
* Required virtual method to draw or render line drawing primitive.
|
||||
*
|
||||
* @image html figure-primitive-line.svg "Line primitive properties"
|
||||
*
|
||||
* @param[in] x X coordinate of line's origin (points)
|
||||
* @param[in] y Y coordinate of line's origin (points)
|
||||
* @param[in] w Line width (points)
|
||||
* @param[in] h Line height (points)
|
||||
*/
|
||||
virtual void drawLine( double x, double y, double w, double h ) = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Draw box primitive.
|
||||
*
|
||||
* Required virtual method to draw or render box drawing primitive.
|
||||
*
|
||||
* @image html figure-primitive-box.svg "Box primitive properties"
|
||||
*
|
||||
* @param[in] x X coordinate of box's origin (points)
|
||||
* @param[in] y Y coordinate of box's origin (points)
|
||||
* @param[in] w Width of box (points)
|
||||
* @param[in] h Height of box (points)
|
||||
*/
|
||||
virtual void drawBox( double x, double y, double w, double h ) = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Draw text primitive.
|
||||
*
|
||||
* Required virtual method to draw or render text drawing primitive.
|
||||
*
|
||||
* @image html figure-primitive-text.svg "Text primitive properties"
|
||||
*
|
||||
* @param[in] x X coordinate of text's origin (points)
|
||||
* @param[in] y Y coordinate of text's origin (points)
|
||||
* @param[in] size Font size of text (points)
|
||||
* @param[in] text Text
|
||||
*/
|
||||
virtual void drawText( double x, double y, double size, const std::string& text, HAlign halign = H_ALIGN_CENTER ) = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Draw ring primitive.
|
||||
*
|
||||
* Required virtual method to draw or render ring drawing primitive.
|
||||
*
|
||||
* @image html figure-primitive-ring.svg "Ring primitive properties"
|
||||
*
|
||||
* @param[in] x X coordinate of ring's origin (points)
|
||||
* @param[in] y Y coordinate of ring's origin (points)
|
||||
* @param[in] r Radius of ring (points)
|
||||
* @param[in] w Line width of ring (points)
|
||||
*/
|
||||
virtual void drawRing( double x, double y, double r, double w ) = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Draw hexagon primitive.
|
||||
*
|
||||
* Required virtual method to draw or render hexagon drawing primitive.
|
||||
*
|
||||
* @image html figure-primitive-hexagon.svg "Hexagon primitive properties"
|
||||
*
|
||||
* @param[in] x X coordinate of hexagon's origin (points)
|
||||
* @param[in] y Y coordinate of hexagon's origin (points)
|
||||
* @param[in] h Height of hexagon (points)
|
||||
*/
|
||||
virtual void drawHexagon( double x, double y, double h ) = 0;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // glbarcode_Renderer_h
|
||||
@@ -0,0 +1,170 @@
|
||||
// Renderer.hpp
|
||||
//
|
||||
// Copyright (C) 2013 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#ifndef glbarcode_Renderer_hpp
|
||||
#define glbarcode_Renderer_hpp
|
||||
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "DrawingPrimitives.hpp"
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
|
||||
class DrawingPrimitive; /* Forward reference to private drawing primitive class. */
|
||||
|
||||
|
||||
/**
|
||||
* @class Renderer Renderer.h glbarcode/Renderer.h
|
||||
*
|
||||
* Base class for all renderers.
|
||||
*/
|
||||
class Renderer
|
||||
{
|
||||
protected:
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
Renderer() = default;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
virtual ~Renderer() = default;
|
||||
|
||||
/*
|
||||
* Non-copyable
|
||||
*/
|
||||
Renderer( const Renderer & ) = delete;
|
||||
void operator=( const Renderer & ) = delete;
|
||||
|
||||
/**
|
||||
* Render list of primitives.
|
||||
*
|
||||
* @param[in] w Width of barcode bounding box (points)
|
||||
* @param[in] h Height of barcode bounding box (points)
|
||||
* @param[in] primitives List of drawing primitives
|
||||
*/
|
||||
void render( double w, double h, const std::list<DrawingPrimitive*>& primitives );
|
||||
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Draw begin.
|
||||
*
|
||||
* Required virtual method to perform rendering setup, such as opening devices and/or
|
||||
* initializing drawing contexts.
|
||||
*
|
||||
* @param[in] w Width of barcode bounding box (points)
|
||||
* @param[in] h Height of barcode bounding box (points)
|
||||
*/
|
||||
virtual void drawBegin( double w, double h ) = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Draw end.
|
||||
*
|
||||
* Required virtual method to perform rendering cleanup, such as closing devices
|
||||
* and/or drawing contexts.
|
||||
*/
|
||||
virtual void drawEnd() = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Draw line primitive.
|
||||
*
|
||||
* Required virtual method to draw or render line drawing primitive.
|
||||
*
|
||||
* @image html figure-primitive-line.svg "Line primitive properties"
|
||||
*
|
||||
* @param[in] x X coordinate of line's origin (points)
|
||||
* @param[in] y Y coordinate of line's origin (points)
|
||||
* @param[in] w Line width (points)
|
||||
* @param[in] h Line height (points)
|
||||
*/
|
||||
virtual void drawLine( double x, double y, double w, double h ) = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Draw box primitive.
|
||||
*
|
||||
* Required virtual method to draw or render box drawing primitive.
|
||||
*
|
||||
* @image html figure-primitive-box.svg "Box primitive properties"
|
||||
*
|
||||
* @param[in] x X coordinate of box's origin (points)
|
||||
* @param[in] y Y coordinate of box's origin (points)
|
||||
* @param[in] w Width of box (points)
|
||||
* @param[in] h Height of box (points)
|
||||
*/
|
||||
virtual void drawBox( double x, double y, double w, double h ) = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Draw text primitive.
|
||||
*
|
||||
* Required virtual method to draw or render text drawing primitive.
|
||||
*
|
||||
* @image html figure-primitive-text.svg "Text primitive properties"
|
||||
*
|
||||
* @param[in] x X coordinate of text's origin (points)
|
||||
* @param[in] y Y coordinate of text's origin (points)
|
||||
* @param[in] size Font size of text (points)
|
||||
* @param[in] text Text
|
||||
*/
|
||||
virtual void drawText( double x, double y, double size, const std::string& text, HAlign halign = H_ALIGN_CENTER ) = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Draw ring primitive.
|
||||
*
|
||||
* Required virtual method to draw or render ring drawing primitive.
|
||||
*
|
||||
* @image html figure-primitive-ring.svg "Ring primitive properties"
|
||||
*
|
||||
* @param[in] x X coordinate of ring's origin (points)
|
||||
* @param[in] y Y coordinate of ring's origin (points)
|
||||
* @param[in] r Radius of ring (points)
|
||||
* @param[in] w Line width of ring (points)
|
||||
*/
|
||||
virtual void drawRing( double x, double y, double r, double w ) = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Draw hexagon primitive.
|
||||
*
|
||||
* Required virtual method to draw or render hexagon drawing primitive.
|
||||
*
|
||||
* @image html figure-primitive-hexagon.svg "Hexagon primitive properties"
|
||||
*
|
||||
* @param[in] x X coordinate of hexagon's origin (points)
|
||||
* @param[in] y Y coordinate of hexagon's origin (points)
|
||||
* @param[in] h Height of hexagon (points)
|
||||
*/
|
||||
virtual void drawHexagon( double x, double y, double h ) = 0;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // glbarcode_Renderer_hpp
|
||||
@@ -1,44 +0,0 @@
|
||||
/* TypeIdList.h
|
||||
*
|
||||
* Copyright (C) 2013-2014 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of glbarcode++.
|
||||
*
|
||||
* glbarcode++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* glbarcode++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glbarcode_TypeIdList_h
|
||||
#define glbarcode_TypeIdList_h
|
||||
|
||||
#include "Barcode.h"
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
/**
|
||||
* @class TypeIdList TypeIdList.h glbarcode/TypeIdList.h
|
||||
*
|
||||
* List of barcode type ID strings.
|
||||
*/
|
||||
class TypeIdList : public std::list<std::string>
|
||||
{
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_TypeIdList_h
|
||||
@@ -0,0 +1,45 @@
|
||||
// TypeIdList.hpp
|
||||
//
|
||||
// Copyright (C) 2013-2014 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of glbarcode++.
|
||||
//
|
||||
// glbarcode++ is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// glbarcode++ is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with glbarcode++. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#ifndef glbarcode_TypeIdList_hpp
|
||||
#define glbarcode_TypeIdList_hpp
|
||||
|
||||
|
||||
#include "Barcode.hpp"
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace glbarcode
|
||||
{
|
||||
/**
|
||||
* @class TypeIdList TypeIdList.h glbarcode/TypeIdList.h
|
||||
*
|
||||
* List of barcode type ID strings.
|
||||
*/
|
||||
class TypeIdList : public std::list<std::string>
|
||||
{
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glbarcode_TypeIdList_hpp
|
||||
Reference in New Issue
Block a user