Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修正纯数字长度为奇数位时最后一位无法生成,为下划线的问题 #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added demo/imgs/timg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions demo/pages/index/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ Page({
code: '1234567890123456789'
},

onLoad: function() {
onLoad: function () {
wxbarcode.barcode('barcode', '1234567890123456789', 680, 200);
wxbarcode.qrcode('qrcode', '1234567890123456789', 420, 420);
wxbarcode.qrcode('qrcode', '1234567890123456789', 420, 420, '../../imgs/timg.jpg', 80);//img path & img size rpx
}
})
32 changes: 32 additions & 0 deletions demo/project.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"description": "项目配置文件。",
"setting": {
"urlCheck": true,
"es6": true,
"postcss": true,
"minified": true,
"newFeature": true
},
"compileType": "miniprogram",
"libVersion": "1.9.1",
"appid": "touristappid",
"projectname": "wxbarcode",
"condition": {
"search": {
"current": -1,
"list": []
},
"conversation": {
"current": -1,
"list": []
},
"game": {
"currentL": -1,
"list": []
},
"miniprogram": {
"current": -1,
"list": []
}
}
}
27 changes: 15 additions & 12 deletions demo/utils/barcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ exports.code128 = function (ctx, text, width, height) {
height = parseInt(height);

var codes = stringToCode128(text);
console.debug('codes', codes)

var g = new Graphics(ctx, width, height);

Expand Down Expand Up @@ -67,7 +68,6 @@ exports.code128 = function (ctx, text, width, height) {


function stringToCode128(text) {

var barc = {
currcs: CODESET.C
};
Expand Down Expand Up @@ -145,7 +145,10 @@ function stringToCode128(text) {
if ((b < 48 || b > 57) && b != CHAR_TILDE)
return codeset;
}
return CODESET.C;
if (bytes.length % 2 == 0)
return CODESET.C;
else
return CODESET.A;
}

//chr1 is current byte
Expand Down Expand Up @@ -249,44 +252,44 @@ function codeSetAllowedFor(chr) {
}
}

var Graphics = function(ctx, width, height) {
var Graphics = function (ctx, width, height) {

this.width = width;
this.height = height;
this.quiet = Math.round(this.width / 40);
this.border_size = 0;

this.border_size = 0;
this.padding_width = 0;

this.area = {
width : width - this.padding_width * 2 - this.quiet * 2,
width: width - this.padding_width * 2 - this.quiet * 2,
height: height - this.border_size * 2,
top : this.border_size - 4,
left : this.padding_width + this.quiet
top: this.border_size - 4,
left: this.padding_width + this.quiet
};

this.ctx = ctx;
this.fg = "#000000";
this.bg = "#ffffff";

// fill background
this.fillBgRect(0,0, width, height);
this.fillBgRect(0, 0, width, height);

// fill center to create border
this.fillBgRect(0, this.border_size, width, height - this.border_size * 2);
}

//use native color
Graphics.prototype._fillRect = function(x, y, width, height, color) {
Graphics.prototype._fillRect = function (x, y, width, height, color) {
this.ctx.setFillStyle(color)
this.ctx.fillRect(x, y, width, height)
}

Graphics.prototype.fillFgRect = function(x,y, width, height) {
Graphics.prototype.fillFgRect = function (x, y, width, height) {
this._fillRect(x, y, width, height, this.fg);
}

Graphics.prototype.fillBgRect = function(x,y, width, height) {
Graphics.prototype.fillBgRect = function (x, y, width, height) {
this._fillRect(x, y, width, height, this.bg);
}

Expand Down
22 changes: 12 additions & 10 deletions demo/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@ var barcode = require('./barcode');
var qrcode = require('./qrcode');

function convert_length(length) {
return Math.round(wx.getSystemInfoSync().windowWidth * length / 750);
return Math.round(wx.getSystemInfoSync().windowWidth * length / 750);
}

function barc(id, code, width, height) {
barcode.code128(wx.createCanvasContext(id), code, convert_length(width), convert_length(height))
barcode.code128(wx.createCanvasContext(id), code, convert_length(width), convert_length(height))
}

function qrc(id, code, width, height) {
qrcode.api.draw(code, {
ctx: wx.createCanvasContext(id),
width: convert_length(width),
height: convert_length(height)
})
function qrc(id, code, width, height, icoPath, icoSize) {
qrcode.api.draw(code, {
ctx: wx.createCanvasContext(id),
width: convert_length(width),
height: convert_length(height),
},
null, null,
icoPath, convert_length(icoSize))
}

module.exports = {
barcode: barc,
qrcode: qrc
barcode: barc,
qrcode: qrc
}
Loading