Allow adjustment of dot size when in dotty mode

This commit is contained in:
Robin Stuart 2016-09-18 14:09:58 +01:00
parent b13efe334a
commit 9eff5cc63a
10 changed files with 46 additions and 14 deletions

View File

@ -74,6 +74,7 @@ struct zint_symbol *ZBarcode_Create() {
symbol->bitmap_width = 0;
symbol->bitmap_height = 0;
symbol->eci = 3;
symbol->dot_size = 4.0 / 5.0;
return symbol;
}
@ -1016,6 +1017,11 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source, int lengt
memcpy(local_source, source, length);
local_source[length] = '\0';
}
if ((symbol->dot_size < 0.01) || (symbol->dot_size > 20.0)) {
strcpy(symbol->errtxt, "Invalid dot size");
return ZINT_ERROR_INVALID_OPTION;
}
switch (symbol->symbology) {
case BARCODE_QRCODE:

View File

@ -430,7 +430,7 @@ int ps_plot(struct zint_symbol *symbol) {
/* Use dots instead of squares */
for (i = 0; i < symbol->width; i++) {
if (module_is_set(symbol, this_row, i)) {
fprintf(feps, "%.2f %.2f %.2f TD\n", ((i + xoffset) * scaler) + (scaler / 2.0), (row_posn * scaler) + (scaler / 2.0), (2.0 / 5.0) * scaler);
fprintf(feps, "%.2f %.2f %.2f TD\n", ((i + xoffset) * scaler) + (scaler / 2.0), (row_posn * scaler) + (scaler / 2.0), (symbol->dot_size / 2.0) * scaler);
}
}
} else {

View File

@ -171,12 +171,13 @@ void draw_bar(char *pixelbuf, int xpos, int xlen, int ypos, int ylen, int image_
}
}
void draw_circle(char *pixelbuf, int image_width, int image_height, int x0, int y0, int radius, char fill) {
void draw_circle(char *pixelbuf, int image_width, int image_height, int x0, int y0, float radius, char fill) {
int x, y;
for (y = -radius; y <= radius; y++) {
for (x = -radius; x <= radius; x++) {
if ((x * x) + (y * y) <= (radius * radius)) {
int radius_i = (int) radius;
for (y = -radius_i; y <= radius_i; y++) {
for (x = -radius_i; x <= radius_i; x++) {
if ((x * x) + (y * y) <= (radius_i * radius_i)) {
if ((y + y0 >= 0) && (y + y0 < image_height)
&& (x + x0 >= 0) && (x + x0 < image_width)) {
*(pixelbuf + ((y + y0) * image_width) + (x + x0)) = fill;
@ -544,7 +545,7 @@ int plot_raster_dotty(struct zint_symbol *symbol, int rotate_angle, int data_typ
draw_circle(scaled_pixelbuf, scale_width, scale_height,
(int) ((i + xoffset) * scaler) + (scaler / 2.0),
(int) ((r + yoffset) * scaler) + (scaler / 2.0),
(int) (scaler / 2.0),
(symbol->dot_size / 2.0) * scaler,
'1');
}
}

View File

@ -316,7 +316,7 @@ int svg_plot(struct zint_symbol *symbol) {
/* Use (currently undocumented) dot mode - see SF ticket #29 */
for (i = 0; i < symbol->width; i++) {
if (module_is_set(symbol, this_row, i)) {
fprintf(fsvg, " <circle cx=\"%.2f\" cy=\"%.2f\" r=\"%.2f\" fill=\"#%s\" />\n", ((i + xoffset) * scaler) + (scaler / 2.0), (row_posn * scaler) + (scaler / 2.0), (2.0 / 5.0) * scaler, symbol->fgcolour);
fprintf(fsvg, " <circle cx=\"%.2f\" cy=\"%.2f\" r=\"%.2f\" fill=\"#%s\" />\n", ((i + xoffset) * scaler) + (scaler / 2.0), (row_posn * scaler) + (scaler / 2.0), (symbol->dot_size / 2.0) * scaler, symbol->fgcolour);
}
}
} else {

View File

@ -94,6 +94,7 @@ extern "C" {
int bitmap_width;
int bitmap_height;
unsigned int bitmap_byte_length;
float dot_size;
struct zint_render *rendered;
};

View File

@ -41,6 +41,7 @@ namespace Zint {
m_scale = 1.0;
m_option_3 = 0;
m_hidetext = FALSE;
m_dot_size = 4.0 / 5.0;
}
QZint::~QZint() {
@ -62,6 +63,7 @@ namespace Zint {
m_zintSymbol->option_1 = m_securityLevel;
m_zintSymbol->input_mode = m_input_mode;
m_zintSymbol->option_2 = m_width;
m_zintSymbol->dot_size = m_dot_size;
if (m_hidetext) {
m_zintSymbol->show_hrt = 0;
} else {
@ -151,6 +153,10 @@ namespace Zint {
void QZint::setScale(float scale) {
m_scale = scale;
}
void QZint::setDotSize(float dot_size) {
m_dot_size = dot_size;
}
QColor QZint::fgColor() {
return m_fgColor;
@ -239,6 +245,7 @@ namespace Zint {
m_zintSymbol->option_1 = m_securityLevel;
m_zintSymbol->input_mode = m_input_mode;
m_zintSymbol->option_2 = m_width;
m_zintSymbol->dot_size = m_dot_size;
if (m_hidetext) {
m_zintSymbol->show_hrt = 0;
} else {
@ -493,7 +500,7 @@ namespace Zint {
for (int c = 0; c < m_zintSymbol->width; c++) {
if (module_set(r, c)) {
painter.drawEllipse(QPointF((c + 1.0), (r + 1.0)), 0.5, 0.5);
painter.drawEllipse(QPointF((c + 1.0), (r + 1.0)), m_dot_size / 2.0, m_dot_size / 2.0);
}
}
}

View File

@ -73,6 +73,8 @@ public:
float scale();
void setScale(float scale);
void setDotSize(float dot_size);
int mode();
void setMode(int securityLevel);
@ -116,6 +118,7 @@ private:
float m_scale;
int m_option_3;
bool m_hidetext;
float m_dot_size;
};
}
#endif

View File

@ -106,7 +106,7 @@ void usage(void) {
" --notext Remove human readable text\n"
" --square Force Data Matrix symbols to be square\n"
" --dmre Allow Data Matrix Rectangular Extended\n"
" --init Create reader initialisation symbol (Code 128)\n"
" --init Create reader initialisation/programming symbol\n"
" --smalltext Use half-size text in PNG images\n"
" --boldtext Use bold text in PNG images\n"
" --batch Treat each line of input as a separate data set\n"
@ -114,6 +114,8 @@ void usage(void) {
" --mirroreps Use batch data to determine filename (EPS output)\n"
" --mirrorsvg Use batch data to determine filename (SVG output)\n"
" --eci=NUMBER Set the ECI mode for raw data\n"
" --dotty Use dots instead of squares for matrix symbols\n"
" --dotsize=NUMBER Set radius of dots in dotty mode\n"
, ZINT_VERSION);
}
@ -508,6 +510,7 @@ int main(int argc, char **argv) {
{"mirroreps", 0, 0, 0},
{"mirrorsvg", 0, 0, 0},
{"dotty", 0, 0, 0},
{"dotsize", 1, 0, 0},
{"eci", 1, 0, 'e'},
{0, 0, 0, 0}
};
@ -591,6 +594,15 @@ int main(int argc, char **argv) {
my_symbol->scale = 1.0;
}
}
if (!strcmp(long_options[option_index].name, "dotsize")) {
my_symbol->dot_size = (float) (atof(optarg));
if (my_symbol->dot_size < 0.01) {
/* Zero and negative values are not permitted */
fprintf(stderr, "Invalid dot radius value\n");
fflush(stderr);
my_symbol->dot_size = 4.0 / 5.0;
}
}
if (!strcmp(long_options[option_index].name, "border")) {
error_number = validator(NESET, optarg);
if (error_number == ZINT_ERROR_INVALID_DATA) {
@ -630,7 +642,7 @@ int main(int argc, char **argv) {
if ((atoi(optarg) >= 1) && (atoi(optarg) <= 44)) {
my_symbol->option_1 = atoi(optarg);
} else {
fprintf(stderr, "Number of columns out of range\n");
fprintf(stderr, "Number of rows out of range\n");
fflush(stderr);
}
}

View File

@ -281,7 +281,7 @@
<item row="1" column="0">
<widget class="QLabel" name="lblDotSize">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="text">
<string>Dot Size:</string>
@ -307,10 +307,10 @@
<item row="1" column="1">
<widget class="QLineEdit" name="txtDotSize">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="text">
<string>1.0</string>
<string>0.8</string>
</property>
</widget>
</item>

View File

@ -298,6 +298,7 @@ void MainWindow::change_options()
connect(m_optionWidget->findChild<QObject*>("cmbDotCols"), SIGNAL(currentIndexChanged( int )), SLOT(update_preview()));
connect(m_optionWidget->findChild<QObject*>("radDotStan"), SIGNAL(clicked( bool )), SLOT(update_preview()));
connect(m_optionWidget->findChild<QObject*>("radDotGs1"), SIGNAL(clicked( bool )), SLOT(update_preview()));
connect(m_optionWidget->findChild<QObject*>("txtDotSize"), SIGNAL(textChanged( QString )), SLOT(update_preview()));
}
if(metaObject()->enumerator(0).value(bstyle->currentIndex()) == BARCODE_AZTEC)
@ -713,6 +714,7 @@ void MainWindow::update_preview()
m_bc.bc.setWidth(m_optionWidget->findChild<QComboBox*>("cmbDotCols")->currentIndex());
if(m_optionWidget->findChild<QRadioButton*>("radDotGs1")->isChecked())
m_bc.bc.setInputMode(GS1_MODE);
m_bc.bc.setDotSize(m_optionWidget->findChild<QLineEdit*>("txtDotSize")->text().toFloat());
break;
case BARCODE_AZTEC: