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:
+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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user