Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
Merge pull request #132 from MSOpenTech/windows_barcode_format_fix
Browse files Browse the repository at this point in the history
Correct scan result to expose format name instead of format code.
  • Loading branch information
Vladimir Kotikov committed Dec 22, 2015
2 parents b25d710 + dc84cac commit 8b5739f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
35 changes: 34 additions & 1 deletion src/windows/BarcodeScannerProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,35 @@

var urlutil = require('cordova/urlutil');

/**
* List of supported barcode formats from ZXing library. Used to return format
* name instead of number code as per plugin spec.
*
* @enum {String}
*/
var BARCODE_FORMAT = {
1: 'AZTEC',
2: 'CODABAR',
4: 'CODE_39',
8: 'CODE_93',
16: 'CODE_128',
32: 'DATA_MATRIX',
64: 'EAN_8',
128: 'EAN_13',
256: 'ITF',
512: 'MAXICODE',
1024: 'PDF_417',
2048: 'QR_CODE',
4096: 'RSS_14',
8192: 'RSS_EXPANDED',
16384: 'UPC_A',
32768: 'UPC_E',
61918: 'All_1D',
65536: 'UPC_EAN_EXTENSION',
131072: 'MSI',
262144: 'PLESSEY'
};

module.exports = {

/**
Expand Down Expand Up @@ -174,7 +203,11 @@ module.exports = {
})
.done(function (result) {
destroyPreview();
success({ text: result && result.text, format: result && result.barcodeFormat, cancelled: !result });
success({
text: result && result.text,
format: result && BARCODE_FORMAT[result.barcodeFormat],
cancelled: !result
});
}, function (error) {
destroyPreview();
fail(error);
Expand Down
4 changes: 2 additions & 2 deletions src/wp8/BarcodeScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public BarcodeResult(bool canceled = true)
public BarcodeResult(Result barcode)
{
this.Cancelled = false;
this.Format = (int)barcode.BarcodeFormat;
this.Format = barcode.BarcodeFormat.ToString();
this.Text = barcode.Text;
}

Expand All @@ -103,7 +103,7 @@ public BarcodeResult(Result barcode)
/// The barcode format.
/// </value>
[DataMember(Name = "format")]
public int Format { get; private set; }
public string Format { get; private set; }

/// <summary>
/// Gets the barcode text.
Expand Down

0 comments on commit 8b5739f

Please sign in to comment.