From b3b68fa8e1d6093069b07953c98bd99f6f6655d9 Mon Sep 17 00:00:00 2001
From: ciaochaos <1272777550@qq.com>
Date: Wed, 6 May 2020 18:42:14 +0800
Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=9B=BE=E7=89=87=E8=83=8C?=
=?UTF-8?q?=E6=99=AF=E6=A0=B7=E5=BC=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/components/QrRendererImage.js | 136 ++++++++++++++++++++++++++++++
src/components/Qrcode.js | 3 +-
src/utils/qrcodeHandler.js | 9 +-
3 files changed, 143 insertions(+), 5 deletions(-)
create mode 100644 src/components/QrRendererImage.js
diff --git a/src/components/QrRendererImage.js b/src/components/QrRendererImage.js
new file mode 100644
index 0000000..2a6c599
--- /dev/null
+++ b/src/components/QrRendererImage.js
@@ -0,0 +1,136 @@
+import React from "react";
+import './Qrcode.css'
+import {getTypeTable, QRPointType} from "../utils/qrcodeHandler";
+import {defaultRenderer, rand} from "../utils/util";
+
+function listPoint(props) {
+ if (!props.qrcode) return []
+
+ const qrcode = props.qrcode;
+ const nCount = qrcode.getModuleCount();
+ const typeTable = getTypeTable(qrcode);
+ const pointList = new Array(nCount);
+
+ let type = props.params[0];
+ let size = props.params[1] / 100 / 3;
+ let opacity = props.params[2] / 100;
+ let posType = props.params[3];
+ let id = 0;
+
+ const vw = [3, -3];
+ const vh = [3, -3];
+
+ if (size <= 0) size = 1.0
+
+ pointList.push();
+
+ for (let x = 0; x < nCount; x++) {
+ for (let y = 0; y < nCount; y++) {
+
+ if (typeTable[x][y] == QRPointType.ALIGN_CENTER || typeTable[x][y] == QRPointType.ALIGN_OTHER || typeTable[x][y] == QRPointType.TIMING) {
+ if (qrcode.isDark(x, y)) {
+ if (type == 0)
+ pointList.push()
+ else if (type == 1)
+ pointList.push()
+ } else {
+ if (type == 0)
+ pointList.push()
+ else if (type == 1)
+ pointList.push()
+ }
+ }
+ else if (typeTable[x][y] == QRPointType.POS_CENTER) {
+ if (qrcode.isDark(x, y)) {
+ if (posType == 0) {
+ pointList.push();
+ } else if (posType == 1) {
+ pointList.push()
+ pointList.push()
+ pointList.push()
+ } else if (posType == 2) {
+ pointList.push()
+ pointList.push()
+ pointList.push()
+ for (let w = 0; w < vw.length; w++) {
+ pointList.push()
+ }
+ for (let h = 0; h < vh.length; h++) {
+ pointList.push()
+ }
+ }
+ }
+
+ }
+ else if (typeTable[x][y] == QRPointType.POS_OTHER) {
+ if (qrcode.isDark(x, y)) {
+ if (posType == 0) {
+ pointList.push();
+ }
+ } else {
+ if (posType == 0) {
+ pointList.push();
+ }
+ }
+
+ }
+ else {
+ if (qrcode.isDark(x, y)) {
+ if (type == 0)
+ pointList.push()
+ else if (type == 1)
+ pointList.push()
+ } else {
+ if (type == 0)
+ pointList.push()
+ else if (type == 1)
+ pointList.push()
+ }
+
+ }
+ }
+ }
+
+ return pointList;
+}
+
+export default class QrRendererImage extends React.Component {
+ constructor(props) {
+ super(props);
+ if (this.props.setParamInfo) {
+ this.props.setParamInfo([
+ {
+ key: '信息点样式',
+ default: 0,
+ choices: [
+ "矩形",
+ "圆形",
+ ]
+ },
+ {
+ key: '信息点缩放',
+ default: 100
+ },
+ {
+ key: '信息点不透明度',
+ default: 100,
+ },
+ {
+ key: '定位点样式',
+ default: 2,
+ choices: [
+ "矩形",
+ "圆形",
+ "行星",
+ ]
+ },
+ ]
+ );
+ }
+ }
+
+ render() {
+ return defaultRenderer(this.props.qrcode, listPoint(this.props));
+ }
+}
+
diff --git a/src/components/Qrcode.js b/src/components/Qrcode.js
index 37b263c..f6b8e0a 100644
--- a/src/components/Qrcode.js
+++ b/src/components/Qrcode.js
@@ -16,6 +16,7 @@ import QrRendererRandRound from "./QrRendererRandRound";
import QrRendererBlank from "./QrRendererBlank";
import QrRendererRandRect from "./QrRendererRandRect";
import QrRendererDSJ from "./QrRendererDSJ";
+import QrRendererImage from "./QrRendererImage";
const logoStyle = {
background: `url(${logo})`,
@@ -29,7 +30,7 @@ const styleList = [
{value: "A3", renderer: QrRendererRandRound},
{value: "SP — 1", renderer: QrRendererDSJ},
{value: "SP — 2", renderer: QrRendererRandRect},
- {value: "C2", renderer: QrRendererBlank},
+ {value: "C1", renderer: QrRendererImage},
{value: "D1", renderer: QrRendererBlank},
{value: "D2", renderer: QrRendererBlank},
];
diff --git a/src/utils/qrcodeHandler.js b/src/utils/qrcodeHandler.js
index 724924e..3a947b7 100644
--- a/src/utils/qrcodeHandler.js
+++ b/src/utils/qrcodeHandler.js
@@ -62,10 +62,11 @@ export function getTypeTable(qrcode) {
for (let i = 0; i < PD.length; i++) {
typeTable[PD[i][0]][PD[i][1]] = QRPointType.POS_CENTER
- for (let r = -3; r <= 3; r++) {
- for (let c = -3; c <= 3; c++) {
- if (!(r == 0 && c == 0))
- typeTable[PD[i][0] + r][PD[i][1] + c] = QRPointType.POS_OTHER;
+ for (let r = -4; r <= 4; r++) {
+ for (let c = -4; c <= 4; c++) {
+ if (PD[i][0] + r >= 0 && PD[i][0] + r < nCount && PD[i][1] + c >=0 && PD[i][1] + c < nCount)
+ if (!(r == 0 && c == 0))
+ typeTable[PD[i][0] + r][PD[i][1] + c] = QRPointType.POS_OTHER;
}
}
}