Support libzint >= 2.15 (#225,#222,#186))
- Update libzint support for 2.15 as new baseline version, removing support for earlier versions, avoiding '#ifdef'-hell - Based on #186 --------- Co-authored-by: gitlost <burmartke@gmail.com>
This commit is contained in:
@@ -174,9 +174,9 @@ namespace glbarcode
|
||||
}
|
||||
|
||||
|
||||
void Barcode::addText( double x, double y, double size, const std::string& text )
|
||||
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 ) );
|
||||
d->mPrimitives.push_back( new DrawingPrimitiveText( x, y, size, text, halign ) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
+7
-5
@@ -24,6 +24,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Enums.h"
|
||||
#include "Renderer.h"
|
||||
|
||||
|
||||
@@ -215,12 +216,13 @@ namespace glbarcode
|
||||
*
|
||||
* @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] 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 );
|
||||
void addText( double x, double y, double size, const std::string& text, HAlign halign = H_ALIGN_CENTER );
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -81,8 +81,8 @@ namespace glbarcode
|
||||
|
||||
|
||||
|
||||
DrawingPrimitiveText::DrawingPrimitiveText( double x, double y, double size, const std::string& text )
|
||||
: DrawingPrimitive( x, y ), mSize(size), mText(text)
|
||||
DrawingPrimitiveText::DrawingPrimitiveText( double x, double y, double size, const std::string& text, HAlign halign )
|
||||
: DrawingPrimitive( x, y ), mSize(size), mText(text), mHalign(halign)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -99,6 +99,12 @@ namespace glbarcode
|
||||
}
|
||||
|
||||
|
||||
HAlign DrawingPrimitiveText::halign() const
|
||||
{
|
||||
return mHalign;
|
||||
}
|
||||
|
||||
|
||||
|
||||
DrawingPrimitiveRing::DrawingPrimitiveRing( double x, double y, double r, double w )
|
||||
: DrawingPrimitive( x, y ), mR(r), mW(w)
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
#define glbarcode_DrawingPrimitives_h
|
||||
|
||||
|
||||
#include "Enums.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
@@ -163,12 +165,13 @@ namespace glbarcode
|
||||
/**
|
||||
* 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] 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 );
|
||||
DrawingPrimitiveText( double x, double y, double size, const std::string& text, HAlign halign = H_ALIGN_CENTER );
|
||||
|
||||
/**
|
||||
* Get font size (points).
|
||||
@@ -180,9 +183,15 @@ namespace glbarcode
|
||||
*/
|
||||
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. */
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/* 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
|
||||
@@ -30,6 +30,7 @@
|
||||
namespace
|
||||
{
|
||||
const double FONT_SCALE = 0.75;
|
||||
const double MIN_POINT_SIZE = 0.4; // Less than ~0.37 causes issues for QFontMetricsF
|
||||
}
|
||||
|
||||
|
||||
@@ -122,7 +123,7 @@ namespace glbarcode
|
||||
}
|
||||
|
||||
|
||||
void QtRenderer::drawText( double x, double y, double size, const std::string& text )
|
||||
void QtRenderer::drawText( double x, double y, double size, const std::string& text, HAlign halign )
|
||||
{
|
||||
if ( d->painter )
|
||||
{
|
||||
@@ -131,10 +132,18 @@ namespace glbarcode
|
||||
QFont font;
|
||||
font.setStyleHint( QFont::Monospace );
|
||||
font.setFamily( "monospace" );
|
||||
font.setPointSizeF( FONT_SCALE*size );
|
||||
font.setPointSizeF( std::max( FONT_SCALE*size, MIN_POINT_SIZE ) );
|
||||
|
||||
QFontMetricsF fm( font );
|
||||
double xCorner = x - fm.horizontalAdvance( QString::fromStdString(text) )/2.0;
|
||||
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 );
|
||||
@@ -151,7 +160,7 @@ namespace glbarcode
|
||||
if ( d->painter )
|
||||
{
|
||||
d->painter->setPen( QPen( d->color, w ) );
|
||||
d->painter->setBrush( Qt::NoBrush );
|
||||
d->painter->setBrush( w ? Qt::NoBrush : QBrush( d->color ) );
|
||||
|
||||
d->painter->drawEllipse( QPointF(x, y), r, r );
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace glbarcode
|
||||
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 ) 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;
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ void glbarcode::Renderer::render( double w, double h, const std::list<DrawingPri
|
||||
}
|
||||
else if ( auto* text = dynamic_cast<DrawingPrimitiveText*>(*primitive) )
|
||||
{
|
||||
drawText( text->x(), text->y(), text->size(), text->text() );
|
||||
drawText( text->x(), text->y(), text->size(), text->text(), text->halign() );
|
||||
}
|
||||
else if ( auto* ring = dynamic_cast<DrawingPrimitiveRing*>(*primitive) )
|
||||
{
|
||||
|
||||
@@ -132,7 +132,7 @@ namespace glbarcode
|
||||
* @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 ) = 0;
|
||||
virtual void drawText( double x, double y, double size, const std::string& text, HAlign halign = H_ALIGN_CENTER ) = 0;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user