[download svg/jpg]

This commit is contained in:
CPunisher 2020-05-03 15:43:26 +08:00
parent 37e33724ce
commit 2f651c4a3f
9 changed files with 311 additions and 193 deletions

View File

@ -1,6 +0,0 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
</profile>
</component>

View File

@ -11,8 +11,15 @@
</component>
<component name="ChangeListManager">
<list default="true" id="78c692f3-8e9f-49c7-86c1-0c5e9d711b1f" name="Default Changelist" comment="静态参数调节组件初步完成">
<change beforePath="$PROJECT_DIR$/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/components/QrRendererBlank.js" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/utils/downloader.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/inspectionProfiles/Project_Default.xml" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/components/QrItem.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/QrItem.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/components/QrRendererBase.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/QrRendererBase.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/components/QrRendererRound.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/QrRendererRound.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/components/Qrcode.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/Qrcode.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/utils/qrcode.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/utils/qrcode.js" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -22,14 +29,20 @@
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="JavaScript File" />
<option value="CSS File" />
<option value="JavaScript File" />
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="JsFlowSettings">
<service-enabled>true</service-enabled>
<exe-path />
<other-services-enabled>true</other-services-enabled>
<auto-save>true</auto-save>
</component>
<component name="ProjectId" id="1bFvrHaftMN3n3JxJkjIZayPhN8" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true">
<ConfirmationsSetting value="2" id="Add" />
@ -44,17 +57,22 @@
<property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="dart.analysis.tool.window.visible" value="false" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/src" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/src/components" />
<property name="list.type.of.created.stylesheet" value="CSS" />
<property name="node.js.detected.package.eslint" value="true" />
<property name="node.js.detected.package.standard" value="true" />
<property name="node.js.path.for.package.eslint" value="project" />
<property name="node.js.path.for.package.standard" value="project" />
<property name="node.js.selected.package.eslint" value="(autodetect)" />
<property name="node.js.selected.package.standard" value="" />
<property name="nodejs_interpreter_path" value="node" />
<property name="nodejs_package_manager_path" value="yarn" />
<property name="settings.editor.selected.configurable" value="settings.javascript.linters.eslint" />
<property name="ts.external.directory.path" value="$APPLICATION_HOME_DIR$/plugins/JavaScriptLanguage/jsLanguageServicesImpl/external" />
</component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="D:\github\qrbtf\src\components" />
<recent name="$PROJECT_DIR$/src" />
</key>
</component>
@ -438,6 +456,10 @@
<screen x="0" y="23" width="2541" height="1057" />
</state>
<state x="1161" y="421" key="#Notifications/428.1103.1680.1027/0.23.2541.1057/-1600.203.1600.877@0.23.2541.1057" timestamp="1588307553058" />
<state x="270" y="57" key="SettingsEditor" timestamp="1588491676810">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="270" y="57" key="SettingsEditor/0.0.1536.824@0.0.1536.824" timestamp="1588491676810" />
<state x="877" y="274" key="Vcs.Push.Dialog.v2" timestamp="1588438354037">
<screen x="0" y="0" width="2560" height="1080" />
</state>
@ -447,6 +469,14 @@
<screen x="0" y="0" width="2560" height="1080" />
</state>
<state x="99" y="100" width="2343" height="880" key="com.intellij.history.integration.ui.views.FileHistoryDialog/428.1080.1680.1050/0.0.2560.1080/-1600.180.1600.900@0.0.2560.1080" timestamp="1588438456208" />
<state x="380" y="14" key="com.intellij.openapi.editor.actions.MultiplePasteAction$ClipboardContentChooser" timestamp="1588479183892">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="380" y="14" key="com.intellij.openapi.editor.actions.MultiplePasteAction$ClipboardContentChooser/0.0.1536.824@0.0.1536.824" timestamp="1588479183892" />
<state x="793" y="181" width="613" height="584" key="find.popup" timestamp="1588490972232">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="793" y="181" width="613" height="584" key="find.popup/0.0.1536.824@0.0.1536.824" timestamp="1588490972232" />
<state x="1004" y="331" key="git4idea.merge.GitPullDialog" timestamp="1588436573499">
<screen x="0" y="0" width="2560" height="1080" />
</state>

View File

@ -1,13 +1,6 @@
import React from "react";
import './Qrcode.css'
function calViewBox(props) {
if (!props.qrcode) return '0 0 0 0';
const nCount = props.qrcode.getModuleCount();
return '0 0 ' + String(nCount) + ' ' + String(nCount);
}
function calClassName(props) {
if (props.selected == true) return 'Qr-item Qr-item-selected';
return 'Qr-item';
@ -19,12 +12,12 @@ class QrItem extends React.Component {
super(props);
this.handleClick = this.handleClick.bind(this);
this.state = {
value: props.value
}
params: new Array(16)
};
}
handleClick(e) {
this.props.onSelected(this.state.value);
this.props.onSelected(this.props.index);
}
render() {
@ -32,13 +25,11 @@ class QrItem extends React.Component {
<div className={calClassName(this.props)} onClick={this.handleClick}>
<div className="Qr-item-image">
<div className="Qr-item-image-inner">
<svg className="Qr-item-svg" width="100%" height="100%" viewBox={calViewBox(this.props)} fill="white">
{this.props.renderer}
</svg>
</div>
</div>
<div className="Qr-item-detail">
{this.state.value}
{this.props.value}
</div>
</div>
);

View File

@ -17,15 +17,18 @@ function listPoint(props) {
return pointList;
}
function calViewBox(props) {
if (!props.qrcode) return '0 0 0 0';
const nCount = props.qrcode.getModuleCount();
return '0 0 ' + String(nCount) + ' ' + String(nCount);
}
class QrRendererBase extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<svg>
<svg className="Qr-item-svg" width="100%" height="100%" viewBox={calViewBox(this.props)} fill="white"
xmlns="http://www.w3.org/2000/svg" xmlnsXlink="http://www.w3.org/1999/xlink">
<rect fill="black" width={1} height={1} id="simpleRect"/>
{listPoint(this.props)}
</svg>

View File

@ -0,0 +1,14 @@
import React from "react";
import './Qrcode.css'
class QrRendererBlank extends React.Component {
render() {
return (
<svg className="Qr-item-svg" width="100%" height="100%" viewBox="0 0 0 0" fill="white"
xmlns="http://www.w3.org/2000/svg" xmlnsXlink="http://www.w3.org/1999/xlink">
</svg>
);
}
}
export default QrRendererBlank

View File

@ -17,15 +17,18 @@ function listPoint(props) {
return pointList;
}
function calViewBox(props) {
if (!props.qrcode) return '0 0 0 0';
const nCount = props.qrcode.getModuleCount();
return '0 0 ' + String(nCount) + ' ' + String(nCount);
}
class QrRendererRound extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<svg>
<svg className="Qr-item-svg" width="100%" height="100%" viewBox={calViewBox(this.props)} fill="white"
xmlns="http://www.w3.org/2000/svg" xmlnsXlink="http://www.w3.org/1999/xlink">
<circle fill="black" r={0.6} id="simpleRound"/>
{listPoint(this.props)}
</svg>

View File

@ -1,42 +1,47 @@
import React from "react";
import ReactDOMServer from 'react-dom/server'
import {getQrcodeData} from "../utils/qrcodeHandler";
import {saveImg, saveSvg} from "../utils/downloader";
import './Qrcode.css';
import QrRendererBase from "./QrRendererBase";
import QrRendererRound from "./QrRendererRound";
import QrRendererBlank from "./QrRendererBlank";
import QrItem from "./QrItem";
function getStyleList(qrcode) {
const styleList = [
{value: "A1", renderer: <QrRendererBase qrcode={qrcode}/> },
{value: "A2", renderer: <QrRendererRound qrcode={qrcode}/>},
{value: "B1"},
{value: "B2"},
{value: "C1"},
{value: "C2"},
{value: "D1"},
{value: "D2"},
];
return styleList;
}
const styleList = [
{value: "A1", renderer: QrRendererBase},
{value: "A2", renderer: QrRendererRound},
{value: "B1", renderer: QrRendererBlank},
{value: "B2", renderer: QrRendererBlank},
{value: "C1", renderer: QrRendererBlank},
{value: "C2", renderer: QrRendererBlank},
{value: "D1", renderer: QrRendererBlank},
{value: "D2", renderer: QrRendererBlank},
];
class Qrcode extends React.Component {
constructor(props) {
super(props);
this.handleChange = this.handleChange.bind(this)
this.handleCreate = this.handleCreate.bind(this)
this.handleSelected = this.handleSelected.bind(this)
this.downloadSvg = this.downloadSvg.bind(this)
this.downloadImg = this.downloadImg.bind(this)
this.state = {
text: '',
selected: 'A1',
selectedIndex: 0,
options: {text: ''},
qrcode: null
};
}
handleSelected(value) {
this.setState({selected: value});
componentDidMount() {
this.handleCreate()
}
handleSelected(index) {
this.setState({selectedIndex: index});
}
handleChange(e) {
@ -52,7 +57,19 @@ class Qrcode extends React.Component {
text = 'https://qrbtf.com/';
this.setState({text: text, options: {text: text}, qrcode: getQrcodeData({text: text})});
}
e.target.blur();
if (e) e.target.blur();
}
downloadSvg(e) {
const style = styleList[this.state.selectedIndex]
const el = React.createElement(style.renderer, {qrcode: this.state.qrcode})
saveSvg(style.value, ReactDOMServer.renderToString(el))
}
downloadImg(e) {
const style = styleList[this.state.selectedIndex]
const el = React.createElement(style.renderer, {qrcode: this.state.qrcode})
saveImg(style.value, ReactDOMServer.renderToString(el), 512, 512)
}
render() {
@ -64,7 +81,6 @@ class Qrcode extends React.Component {
<input
className="Qr-input big-input"
placeholder="Input your URL here"
value={this.state.text}
onChange={this.handleChange}
onBlur={this.handleCreate}
onKeyPress={(e) => {if(e.key == 'Enter') this.handleCreate(e)}}
@ -78,13 +94,16 @@ class Qrcode extends React.Component {
<div className="Qr-s">
<div className="Qr-box">
{
getStyleList(this.state.qrcode).map((style) => {
styleList.map((style, index) => {
return <QrItem
value={style.value}
key={style.value}
value={style.value}
index={index}
qrcode={this.state.qrcode}
renderer={style.renderer}
selected={style.value == this.state.selected}
renderer={React.createElement(style.renderer, {
qrcode: this.state.qrcode,
})}
selected={index == this.state.selectedIndex}
onSelected={this.handleSelected}
/>
})
@ -124,8 +143,8 @@ class Qrcode extends React.Component {
</div>
<div className="Qr-Centered">
<div className="div-btn">
<button className="dl-btn">SVG</button>
<button className="dl-btn">JPG</button>
<button className="dl-btn" onClick={this.downloadSvg}>SVG</button>
<button className="dl-btn" onClick={this.downloadImg}>JPG</button>
</div>
</div>

64
src/utils/downloader.js Normal file
View File

@ -0,0 +1,64 @@
const svgHead = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n " +
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 20010904//EN\" \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n"
export function isChrome() {
return navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
}
export function saveSvg(filename, content) {
let htmlContent = [svgHead + content]
let bl = new Blob(htmlContent, {type: "text/html"})
let a = document.createElement("a")
filename = "QRcode_" + filename + ".svg"
a.href = URL.createObjectURL(bl)
a.download = filename
a.hidden = true
a.click()
}
export function saveImg(filename, content, width, height) {
// Finish creating downloadable data
filename = "QRcode_" + filename + ".jpg";
const wrap = document.createElement('div');
wrap.innerHTML = content;
const $svg = wrap.firstChild
const $clone = $svg.cloneNode(true);
$clone.setAttribute('width', width);
$clone.setAttribute('height', height);
const svgData = new XMLSerializer().serializeToString($clone);
let canvas = document.createElement('canvas');
// Image will be scaled to the requested size.
// var size = data.requestedSize;
canvas.setAttribute('width', width);
canvas.setAttribute('height', height);
let ctx = canvas.getContext('2d');
let img = document.createElement('img');
// New window for the image when it's loaded
if(!isChrome()) window.open('', 'download');
img.onload = () => {
ctx.fillStyle = 'white'
ctx.fillRect(0, 0, width, height)
ctx.drawImage(img, 0, 0, width, height);
// `download` attr is not well supported
// Will result in a download popup for chrome and the
// image opening in a new tab for others.
let a = document.createElement('a');
a.setAttribute('href', canvas.toDataURL('image/jpeg', 0.8))
a.setAttribute('target', 'download')
a.setAttribute('download', filename);
a.click();
};
img.setAttribute('src', 'data:image/svg+xml;base64,' + btoa(svgData));
}

View File

@ -30,7 +30,7 @@ QR8bitByte.prototype = {
},
write : function(buffer) {
for (var i = 0; i < this.data.length; i++) {
for (let i = 0; i < this.data.length; i++) {
// not JIS ...
buffer.put(this.data.charCodeAt(i), 8);
}
@ -47,13 +47,13 @@ function QRCode(typeNumber, errorCorrectLevel) {
this.modules = null;
this.moduleCount = 0;
this.dataCache = null;
this.dataList = new Array();
this.dataList = [];
}
QRCode.prototype = {
addData : function(data) {
var newData = new QR8bitByte(data);
let newData = new QR8bitByte(data);
this.dataList.push(newData);
this.dataCache = null;
},
@ -72,18 +72,18 @@ QRCode.prototype = {
make : function() {
// Calculate automatically typeNumber if provided is < 1
if (this.typeNumber < 1 ){
var typeNumber = 1;
let typeNumber = 1;
for (typeNumber = 1; typeNumber < 40; typeNumber++) {
var rsBlocks = QRRSBlock.getRSBlocks(typeNumber, this.errorCorrectLevel);
let rsBlocks = QRRSBlock.getRSBlocks(typeNumber, this.errorCorrectLevel);
var buffer = new QRBitBuffer();
var totalDataCount = 0;
for (var i = 0; i < rsBlocks.length; i++) {
let buffer = new QRBitBuffer();
let totalDataCount = 0;
for (let i = 0; i < rsBlocks.length; i++) {
totalDataCount += rsBlocks[i].dataCount;
}
for (var i = 0; i < this.dataList.length; i++) {
var data = this.dataList[i];
for (let i = 0; i < this.dataList.length; i++) {
let data = this.dataList[i];
buffer.put(data.mode, 4);
buffer.put(data.getLength(), QRUtil.getLengthInBits(data.mode, typeNumber) );
data.write(buffer);
@ -101,11 +101,11 @@ QRCode.prototype = {
this.moduleCount = this.typeNumber * 4 + 17;
this.modules = new Array(this.moduleCount);
for (var row = 0; row < this.moduleCount; row++) {
for (let row = 0; row < this.moduleCount; row++) {
this.modules[row] = new Array(this.moduleCount);
for (var col = 0; col < this.moduleCount; col++) {
for (let col = 0; col < this.moduleCount; col++) {
this.modules[row][col] = null;//(col + row) % 3;
}
}
@ -130,11 +130,11 @@ QRCode.prototype = {
setupPositionProbePattern : function(row, col) {
for (var r = -1; r <= 7; r++) {
for (let r = -1; r <= 7; r++) {
if (row + r <= -1 || this.moduleCount <= row + r) continue;
for (var c = -1; c <= 7; c++) {
for (let c = -1; c <= 7; c++) {
if (col + c <= -1 || this.moduleCount <= col + c) continue;
@ -151,14 +151,14 @@ QRCode.prototype = {
getBestMaskPattern : function() {
var minLostPoint = 0;
var pattern = 0;
let minLostPoint = 0;
let pattern = 0;
for (var i = 0; i < 8; i++) {
for (let i = 0; i < 8; i++) {
this.makeImpl(true, i);
var lostPoint = QRUtil.getLostPoint(this);
let lostPoint = QRUtil.getLostPoint(this);
if (i == 0 || minLostPoint > lostPoint) {
minLostPoint = lostPoint;
@ -171,19 +171,19 @@ QRCode.prototype = {
createMovieClip : function(target_mc, instance_name, depth) {
var qr_mc = target_mc.createEmptyMovieClip(instance_name, depth);
var cs = 1;
let qr_mc = target_mc.createEmptyMovieClip(instance_name, depth);
let cs = 1;
this.make();
for (var row = 0; row < this.modules.length; row++) {
for (let row = 0; row < this.modules.length; row++) {
var y = row * cs;
let y = row * cs;
for (var col = 0; col < this.modules[row].length; col++) {
for (let col = 0; col < this.modules[row].length; col++) {
var x = col * cs;
var dark = this.modules[row][col];
let x = col * cs;
let dark = this.modules[row][col];
if (dark) {
qr_mc.beginFill(0, 100);
@ -201,14 +201,14 @@ QRCode.prototype = {
setupTimingPattern : function() {
for (var r = 8; r < this.moduleCount - 8; r++) {
for (let r = 8; r < this.moduleCount - 8; r++) {
if (this.modules[r][6] != null) {
continue;
}
this.modules[r][6] = (r % 2 == 0);
}
for (var c = 8; c < this.moduleCount - 8; c++) {
for (let c = 8; c < this.moduleCount - 8; c++) {
if (this.modules[6][c] != null) {
continue;
}
@ -218,22 +218,22 @@ QRCode.prototype = {
setupPositionAdjustPattern : function() {
var pos = QRUtil.getPatternPosition(this.typeNumber);
let pos = QRUtil.getPatternPosition(this.typeNumber);
for (var i = 0; i < pos.length; i++) {
for (let i = 0; i < pos.length; i++) {
for (var j = 0; j < pos.length; j++) {
for (let j = 0; j < pos.length; j++) {
var row = pos[i];
var col = pos[j];
let row = pos[i];
let col = pos[j];
if (this.modules[row][col] != null) {
continue;
}
for (var r = -2; r <= 2; r++) {
for (let r = -2; r <= 2; r++) {
for (var c = -2; c <= 2; c++) {
for (let c = -2; c <= 2; c++) {
if (r == -2 || r == 2 || c == -2 || c == 2
|| (r == 0 && c == 0) ) {
@ -249,28 +249,28 @@ QRCode.prototype = {
setupTypeNumber : function(test) {
var bits = QRUtil.getBCHTypeNumber(this.typeNumber);
let bits = QRUtil.getBCHTypeNumber(this.typeNumber);
for (var i = 0; i < 18; i++) {
var mod = (!test && ( (bits >> i) & 1) == 1);
for (let i = 0; i < 18; i++) {
let mod = (!test && ( (bits >> i) & 1) == 1);
this.modules[Math.floor(i / 3)][i % 3 + this.moduleCount - 8 - 3] = mod;
}
for (var i = 0; i < 18; i++) {
var mod = (!test && ( (bits >> i) & 1) == 1);
for (let i = 0; i < 18; i++) {
let mod = (!test && ( (bits >> i) & 1) == 1);
this.modules[i % 3 + this.moduleCount - 8 - 3][Math.floor(i / 3)] = mod;
}
},
setupTypeInfo : function(test, maskPattern) {
var data = (this.errorCorrectLevel << 3) | maskPattern;
var bits = QRUtil.getBCHTypeInfo(data);
let data = (this.errorCorrectLevel << 3) | maskPattern;
let bits = QRUtil.getBCHTypeInfo(data);
// vertical
for (var i = 0; i < 15; i++) {
for (let i = 0; i < 15; i++) {
var mod = (!test && ( (bits >> i) & 1) == 1);
let mod = (!test && ( (bits >> i) & 1) == 1);
if (i < 6) {
this.modules[i][8] = mod;
@ -282,9 +282,9 @@ QRCode.prototype = {
}
// horizontal
for (var i = 0; i < 15; i++) {
for (let i = 0; i < 15; i++) {
var mod = (!test && ( (bits >> i) & 1) == 1);
let mod = (!test && ( (bits >> i) & 1) == 1);
if (i < 8) {
this.modules[8][this.moduleCount - i - 1] = mod;
@ -302,28 +302,28 @@ QRCode.prototype = {
mapData : function(data, maskPattern) {
var inc = -1;
var row = this.moduleCount - 1;
var bitIndex = 7;
var byteIndex = 0;
let inc = -1;
let row = this.moduleCount - 1;
let bitIndex = 7;
let byteIndex = 0;
for (var col = this.moduleCount - 1; col > 0; col -= 2) {
for (let col = this.moduleCount - 1; col > 0; col -= 2) {
if (col == 6) col--;
while (true) {
for (var c = 0; c < 2; c++) {
for (let c = 0; c < 2; c++) {
if (this.modules[row][col - c] == null) {
var dark = false;
let dark = false;
if (byteIndex < data.length) {
dark = ( ( (data[byteIndex] >>> bitIndex) & 1) == 1);
}
var mask = QRUtil.getMask(maskPattern, row, col - c);
let mask = QRUtil.getMask(maskPattern, row, col - c);
if (mask) {
dark = !dark;
@ -358,20 +358,20 @@ QRCode.PAD1 = 0x11;
QRCode.createData = function(typeNumber, errorCorrectLevel, dataList) {
var rsBlocks = QRRSBlock.getRSBlocks(typeNumber, errorCorrectLevel);
let rsBlocks = QRRSBlock.getRSBlocks(typeNumber, errorCorrectLevel);
var buffer = new QRBitBuffer();
let buffer = new QRBitBuffer();
for (var i = 0; i < dataList.length; i++) {
var data = dataList[i];
for (let i = 0; i < dataList.length; i++) {
let data = dataList[i];
buffer.put(data.mode, 4);
buffer.put(data.getLength(), QRUtil.getLengthInBits(data.mode, typeNumber) );
data.write(buffer);
}
// calc num max data.
var totalDataCount = 0;
for (var i = 0; i < rsBlocks.length; i++) {
let totalDataCount = 0;
for (let i = 0; i < rsBlocks.length; i++) {
totalDataCount += rsBlocks[i].dataCount;
}
@ -412,59 +412,59 @@ QRCode.createData = function(typeNumber, errorCorrectLevel, dataList) {
QRCode.createBytes = function(buffer, rsBlocks) {
var offset = 0;
let offset = 0;
var maxDcCount = 0;
var maxEcCount = 0;
let maxDcCount = 0;
let maxEcCount = 0;
var dcdata = new Array(rsBlocks.length);
var ecdata = new Array(rsBlocks.length);
let dcdata = new Array(rsBlocks.length);
let ecdata = new Array(rsBlocks.length);
for (var r = 0; r < rsBlocks.length; r++) {
for (let r = 0; r < rsBlocks.length; r++) {
var dcCount = rsBlocks[r].dataCount;
var ecCount = rsBlocks[r].totalCount - dcCount;
let dcCount = rsBlocks[r].dataCount;
let ecCount = rsBlocks[r].totalCount - dcCount;
maxDcCount = Math.max(maxDcCount, dcCount);
maxEcCount = Math.max(maxEcCount, ecCount);
dcdata[r] = new Array(dcCount);
for (var i = 0; i < dcdata[r].length; i++) {
for (let i = 0; i < dcdata[r].length; i++) {
dcdata[r][i] = 0xff & buffer.buffer[i + offset];
}
offset += dcCount;
var rsPoly = QRUtil.getErrorCorrectPolynomial(ecCount);
var rawPoly = new QRPolynomial(dcdata[r], rsPoly.getLength() - 1);
let rsPoly = QRUtil.getErrorCorrectPolynomial(ecCount);
let rawPoly = new QRPolynomial(dcdata[r], rsPoly.getLength() - 1);
var modPoly = rawPoly.mod(rsPoly);
let modPoly = rawPoly.mod(rsPoly);
ecdata[r] = new Array(rsPoly.getLength() - 1);
for (var i = 0; i < ecdata[r].length; i++) {
var modIndex = i + modPoly.getLength() - ecdata[r].length;
for (let i = 0; i < ecdata[r].length; i++) {
let modIndex = i + modPoly.getLength() - ecdata[r].length;
ecdata[r][i] = (modIndex >= 0)? modPoly.get(modIndex) : 0;
}
}
var totalCodeCount = 0;
for (var i = 0; i < rsBlocks.length; i++) {
let totalCodeCount = 0;
for (let i = 0; i < rsBlocks.length; i++) {
totalCodeCount += rsBlocks[i].totalCount;
}
var data = new Array(totalCodeCount);
var index = 0;
let data = new Array(totalCodeCount);
let index = 0;
for (var i = 0; i < maxDcCount; i++) {
for (var r = 0; r < rsBlocks.length; r++) {
for (let i = 0; i < maxDcCount; i++) {
for (let r = 0; r < rsBlocks.length; r++) {
if (i < dcdata[r].length) {
data[index++] = dcdata[r][i];
}
}
}
for (var i = 0; i < maxEcCount; i++) {
for (var r = 0; r < rsBlocks.length; r++) {
for (let i = 0; i < maxEcCount; i++) {
for (let r = 0; r < rsBlocks.length; r++) {
if (i < ecdata[r].length) {
data[index++] = ecdata[r][i];
}
@ -479,7 +479,7 @@ QRCode.createBytes = function(buffer, rsBlocks) {
// QRMode
//---------------------------------------------------------------------
var QRMode = {
let QRMode = {
MODE_NUMBER : 1 << 0,
MODE_ALPHA_NUM : 1 << 1,
MODE_8BIT_BYTE : 1 << 2,
@ -490,7 +490,7 @@ var QRMode = {
// QRErrorCorrectLevel
//---------------------------------------------------------------------
var QRErrorCorrectLevel = {
let QRErrorCorrectLevel = {
L : 1,
M : 0,
Q : 3,
@ -501,7 +501,7 @@ var QRErrorCorrectLevel = {
// QRMaskPattern
//---------------------------------------------------------------------
var QRMaskPattern = {
let QRMaskPattern = {
PATTERN000 : 0,
PATTERN001 : 1,
PATTERN010 : 2,
@ -516,7 +516,7 @@ var QRMaskPattern = {
// QRUtil
//---------------------------------------------------------------------
var QRUtil = {
let QRUtil = {
PATTERN_POSITION_TABLE : [
[],
@ -566,7 +566,7 @@ var QRUtil = {
G15_MASK : (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1),
getBCHTypeInfo : function(data) {
var d = data << 10;
let d = data << 10;
while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15) >= 0) {
d ^= (QRUtil.G15 << (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15) ) );
}
@ -574,7 +574,7 @@ var QRUtil = {
},
getBCHTypeNumber : function(data) {
var d = data << 12;
let d = data << 12;
while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18) >= 0) {
d ^= (QRUtil.G18 << (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18) ) );
}
@ -583,7 +583,7 @@ var QRUtil = {
getBCHDigit : function(data) {
var digit = 0;
let digit = 0;
while (data != 0) {
digit++;
@ -617,9 +617,9 @@ var QRUtil = {
getErrorCorrectPolynomial : function(errorCorrectLength) {
var a = new QRPolynomial([1], 0);
let a = new QRPolynomial([1], 0);
for (var i = 0; i < errorCorrectLength; i++) {
for (let i = 0; i < errorCorrectLength; i++) {
a = a.multiply(new QRPolynomial([1, QRMath.gexp(i)], 0) );
}
@ -674,26 +674,26 @@ var QRUtil = {
getLostPoint : function(qrCode) {
var moduleCount = qrCode.getModuleCount();
let moduleCount = qrCode.getModuleCount();
var lostPoint = 0;
let lostPoint = 0;
// LEVEL1
for (var row = 0; row < moduleCount; row++) {
for (let row = 0; row < moduleCount; row++) {
for (var col = 0; col < moduleCount; col++) {
for (let col = 0; col < moduleCount; col++) {
var sameCount = 0;
var dark = qrCode.isDark(row, col);
let sameCount = 0;
let dark = qrCode.isDark(row, col);
for (var r = -1; r <= 1; r++) {
for (let r = -1; r <= 1; r++) {
if (row + r < 0 || moduleCount <= row + r) {
continue;
}
for (var c = -1; c <= 1; c++) {
for (let c = -1; c <= 1; c++) {
if (col + c < 0 || moduleCount <= col + c) {
continue;
@ -717,9 +717,9 @@ var QRUtil = {
// LEVEL2
for (var row = 0; row < moduleCount - 1; row++) {
for (var col = 0; col < moduleCount - 1; col++) {
var count = 0;
for (let row = 0; row < moduleCount - 1; row++) {
for (let col = 0; col < moduleCount - 1; col++) {
let count = 0;
if (qrCode.isDark(row, col ) ) count++;
if (qrCode.isDark(row + 1, col ) ) count++;
if (qrCode.isDark(row, col + 1) ) count++;
@ -732,8 +732,8 @@ var QRUtil = {
// LEVEL3
for (var row = 0; row < moduleCount; row++) {
for (var col = 0; col < moduleCount - 6; col++) {
for (let row = 0; row < moduleCount; row++) {
for (let col = 0; col < moduleCount - 6; col++) {
if (qrCode.isDark(row, col)
&& !qrCode.isDark(row, col + 1)
&& qrCode.isDark(row, col + 2)
@ -746,8 +746,8 @@ var QRUtil = {
}
}
for (var col = 0; col < moduleCount; col++) {
for (var row = 0; row < moduleCount - 6; row++) {
for (let col = 0; col < moduleCount; col++) {
for (let row = 0; row < moduleCount - 6; row++) {
if (qrCode.isDark(row, col)
&& !qrCode.isDark(row + 1, col)
&& qrCode.isDark(row + 2, col)
@ -762,17 +762,17 @@ var QRUtil = {
// LEVEL4
var darkCount = 0;
let darkCount = 0;
for (var col = 0; col < moduleCount; col++) {
for (var row = 0; row < moduleCount; row++) {
for (let col = 0; col < moduleCount; col++) {
for (let row = 0; row < moduleCount; row++) {
if (qrCode.isDark(row, col) ) {
darkCount++;
}
}
}
var ratio = Math.abs(100 * darkCount / moduleCount / moduleCount - 50) / 5;
let ratio = Math.abs(100 * darkCount / moduleCount / moduleCount - 50) / 5;
lostPoint += ratio * 10;
return lostPoint;
@ -785,7 +785,7 @@ var QRUtil = {
// QRMath
//---------------------------------------------------------------------
var QRMath = {
let QRMath = {
glog : function(n) {
@ -815,16 +815,16 @@ var QRMath = {
};
for (var i = 0; i < 8; i++) {
for (let i = 0; i < 8; i++) {
QRMath.EXP_TABLE[i] = 1 << i;
}
for (var i = 8; i < 256; i++) {
for (let i = 8; i < 256; i++) {
QRMath.EXP_TABLE[i] = QRMath.EXP_TABLE[i - 4]
^ QRMath.EXP_TABLE[i - 5]
^ QRMath.EXP_TABLE[i - 6]
^ QRMath.EXP_TABLE[i - 8];
}
for (var i = 0; i < 255; i++) {
for (let i = 0; i < 255; i++) {
QRMath.LOG_TABLE[QRMath.EXP_TABLE[i] ] = i;
}
@ -838,14 +838,14 @@ function QRPolynomial(num, shift) {
throw new Error(num.length + "/" + shift);
}
var offset = 0;
let offset = 0;
while (offset < num.length && num[offset] == 0) {
offset++;
}
this.num = new Array(num.length - offset + shift);
for (var i = 0; i < num.length - offset; i++) {
for (let i = 0; i < num.length - offset; i++) {
this.num[i] = num[i + offset];
}
}
@ -862,10 +862,10 @@ QRPolynomial.prototype = {
multiply : function(e) {
var num = new Array(this.getLength() + e.getLength() - 1);
let num = new Array(this.getLength() + e.getLength() - 1);
for (var i = 0; i < this.getLength(); i++) {
for (var j = 0; j < e.getLength(); j++) {
for (let i = 0; i < this.getLength(); i++) {
for (let j = 0; j < e.getLength(); j++) {
num[i + j] ^= QRMath.gexp(QRMath.glog(this.get(i) ) + QRMath.glog(e.get(j) ) );
}
}
@ -879,15 +879,15 @@ QRPolynomial.prototype = {
return this;
}
var ratio = QRMath.glog(this.get(0) ) - QRMath.glog(e.get(0) );
let ratio = QRMath.glog(this.get(0) ) - QRMath.glog(e.get(0) );
var num = new Array(this.getLength() );
let num = new Array(this.getLength() );
for (var i = 0; i < this.getLength(); i++) {
for (let i = 0; i < this.getLength(); i++) {
num[i] = this.get(i);
}
for (var i = 0; i < e.getLength(); i++) {
for (let i = 0; i < e.getLength(); i++) {
num[i] ^= QRMath.gexp(QRMath.glog(e.get(i) ) + ratio);
}
@ -1155,23 +1155,23 @@ QRRSBlock.RS_BLOCK_TABLE = [
QRRSBlock.getRSBlocks = function(typeNumber, errorCorrectLevel) {
var rsBlock = QRRSBlock.getRsBlockTable(typeNumber, errorCorrectLevel);
let rsBlock = QRRSBlock.getRsBlockTable(typeNumber, errorCorrectLevel);
if (rsBlock == undefined) {
throw new Error("bad rs block @ typeNumber:" + typeNumber + "/errorCorrectLevel:" + errorCorrectLevel);
}
var length = rsBlock.length / 3;
let length = rsBlock.length / 3;
var list = new Array();
let list = [];
for (var i = 0; i < length; i++) {
for (let i = 0; i < length; i++) {
var count = rsBlock[i * 3 + 0];
var totalCount = rsBlock[i * 3 + 1];
var dataCount = rsBlock[i * 3 + 2];
let count = rsBlock[i * 3 + 0];
let totalCount = rsBlock[i * 3 + 1];
let dataCount = rsBlock[i * 3 + 2];
for (var j = 0; j < count; j++) {
for (let j = 0; j < count; j++) {
list.push(new QRRSBlock(totalCount, dataCount) );
}
}
@ -1200,19 +1200,19 @@ QRRSBlock.getRsBlockTable = function(typeNumber, errorCorrectLevel) {
//---------------------------------------------------------------------
function QRBitBuffer() {
this.buffer = new Array();
this.buffer = [];
this.length = 0;
}
QRBitBuffer.prototype = {
get : function(index) {
var bufIndex = Math.floor(index / 8);
let bufIndex = Math.floor(index / 8);
return ( (this.buffer[bufIndex] >>> (7 - index % 8) ) & 1) == 1;
},
put : function(num, length) {
for (var i = 0; i < length; i++) {
for (let i = 0; i < length; i++) {
this.putBit( ( (num >>> (length - i - 1) ) & 1) == 1);
}
},
@ -1223,7 +1223,7 @@ QRBitBuffer.prototype = {
putBit : function(bit) {
var bufIndex = Math.floor(this.length / 8);
let bufIndex = Math.floor(this.length / 8);
if (this.buffer.length <= bufIndex) {
this.buffer.push(0);
}