diff --git a/src/components/renderer/RendererLine.js b/src/components/renderer/RendererLine.js new file mode 100644 index 0000000..7336c5e --- /dev/null +++ b/src/components/renderer/RendererLine.js @@ -0,0 +1,226 @@ +import React from "react"; +import {ParamTypes} from "../../constant/ParamTypes"; +import {getTypeTable, QRPointType} from "../../utils/qrcodeHandler"; +import {createRenderer} from "../style/Renderer"; +import {rand} from "../../utils/util"; + +function listPoints(qrcode, params) { + if (!qrcode) return [] + + const nCount = qrcode.getModuleCount(); + const typeTable = getTypeTable(qrcode); + const pointList = new Array(nCount); + + let type = params[0]; + let size = params[1] / 100; + let opacity = params[2] / 100; + let posType = params[3]; + let id = 0; + let otherColor = params[4]; + let posColor = params[5]; + + const vw = [3, -3]; + const vh = [3, -3]; + + const sq25 = "M32.048565,-1.29480038e-15 L67.951435,1.29480038e-15 C79.0954192,-7.52316311e-16 83.1364972,1.16032014 87.2105713,3.3391588 C91.2846454,5.51799746 94.4820025,8.71535463 96.6608412,12.7894287 C98.8396799,16.8635028 100,20.9045808 100,32.048565 L100,67.951435 C100,79.0954192 98.8396799,83.1364972 96.6608412,87.2105713 C94.4820025,91.2846454 91.2846454,94.4820025 87.2105713,96.6608412 C83.1364972,98.8396799 79.0954192,100 67.951435,100 L32.048565,100 C20.9045808,100 16.8635028,98.8396799 12.7894287,96.6608412 C8.71535463,94.4820025 5.51799746,91.2846454 3.3391588,87.2105713 C1.16032014,83.1364972 5.01544207e-16,79.0954192 -8.63200256e-16,67.951435 L8.63200256e-16,32.048565 C-5.01544207e-16,20.9045808 1.16032014,16.8635028 3.3391588,12.7894287 C5.51799746,8.71535463 8.71535463,5.51799746 12.7894287,3.3391588 C16.8635028,1.16032014 20.9045808,7.52316311e-16 32.048565,-1.29480038e-15 Z"; + + if (size <= 0) size = 1.0 + + let available = []; + let ava2 = []; + for (let x = 0; x < nCount; x++) { + available[x] = []; + ava2[x] = []; + for (let y = 0; y < nCount; y++) { + available[x][y] = true; + ava2[x][y] = true; + } + } + + for (let x = 0; x < nCount; x++) { + for (let y = 0; y < nCount; y++) { + if (!available[x][y] || !ava2[x][y] || qrcode.isDark(x, y) === false) continue; + + if (typeTable[x][y] === QRPointType.POS_CENTER) { + if (posType === 0) { + pointList.push(); + } else if (posType === 1) { + pointList.push() + pointList.push() + } else if (posType === 2) { + 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 (posType === 3) { + pointList.push() + pointList.push() + } + } + else if (typeTable[x][y] === QRPointType.POS_OTHER) { + if (posType === 0) { + pointList.push(); + } + } + else { + if (type === 0) { + if (x === 0 || (x > 0 && (!qrcode.isDark(x - 1, y) || !ava2[x - 1][y]))) { + let start = 0; + let end = 0; + let ctn = true; + while (ctn && x + end < nCount) { + if (qrcode.isDark(x + end, y) && ava2[x + end][y]) { + end++; + } else { + ctn = false; + } + } + if (end - start > 1) { + for (let i = start; i < end; i++) { + ava2[x + i][y] = false; + available[x + i][y] = false; + } + pointList.push() + } + } + if (available[x][y]) { + pointList.push() + } + } + + if (type === 1) { + if (y === 0 || (y > 0 && (!qrcode.isDark(x, y - 1) || !ava2[x][y - 1]))) { + let start = 0; + let end = 0; + let ctn = true; + while (ctn && y + end < nCount) { + if (qrcode.isDark(x, y + end) && ava2[x][y + end]) { + end++; + } else { + ctn = false; + } + } + if (end - start > 1) { + for (let i = start; i < end; i++) { + ava2[x][y + i] = false; + available[x][y + i] = false; + } + pointList.push() + } + } + if (available[x][y]) { + pointList.push() + } + } + + if (type === 2) { + if (y === 0 || x === 0 || ((y > 0 && x > 0) && (!qrcode.isDark(x - 1, y - 1) || !ava2[x - 1][y - 1]))) { + let start = 0; + let end = 0; + let ctn = true; + while (ctn && y + end < nCount && x + end < nCount) { + if (qrcode.isDark(x + end, y + end) && ava2[x + end][y + end]) { + end++; + } else { + ctn = false; + } + } + if (end - start > 1) { + for (let i = start; i < end; i++) { + ava2[x + i][y + i] = false; + available[x + i][y + i] = false; + } + pointList.push() + } + } + if (available[x][y]) { + pointList.push() + } + } + + if (type === 3) { + if (y === 0 || x === nCount - 1 || ((y > 0 && x < nCount - 1) && (!qrcode.isDark(x + 1, y - 1) || !ava2[x + 1][y - 1]))) { + let start = 0; + let end = 0; + let ctn = true; + while (ctn && y + end < nCount && x - end >= 0) { + if (qrcode.isDark(x - end, y + end) && ava2[x - end][y + end]) { + end++; + } else { + ctn = false; + } + } + if (end - start > 1) { + for (let i = start; i < end; i++) { + ava2[x - i][y + i] = false; + available[x - i][y + i] = false; + } + pointList.push() + } + } + if (available[x][y]) { + pointList.push() + } + } + } + } + } + + return pointList; +} + +function getParamInfoLine() { + return [ + { + type: ParamTypes.SELECTOR, + key: '连线方向', + default: 1, + choices: [ + "左右", + "上下", + "左上 — 右下", + "右上 — 左下" + ] + }, + { + type: ParamTypes.TEXT_EDITOR, + key: '连线粗细', + default: 50 + }, + { + type: ParamTypes.TEXT_EDITOR, + key: '连线不透明度', + default: 100, + }, + { + type: ParamTypes.SELECTOR, + key: '定位点样式', + default: 3, + choices: [ + "矩形", + "圆形", + "行星", + "圆角矩形", + ] + }, + { + type: ParamTypes.COLOR_EDITOR, + key: '连线颜色', + default: '#000000' + }, + { + type: ParamTypes.COLOR_EDITOR, + key: '定位点点颜色', + default: '#000000' + } + ]; +} + +export const RendererLine= createRenderer({ + listPoints: listPoints, + getParamInfo: getParamInfoLine, +}); diff --git a/src/containers/style/StyleListViewer.js b/src/containers/style/StyleListViewer.js index da99b82..6d167bc 100644 --- a/src/containers/style/StyleListViewer.js +++ b/src/containers/style/StyleListViewer.js @@ -8,12 +8,14 @@ import Renderer25D from "../../components/renderer/Renderer25D"; import RendererImage from "../../components/renderer/RendererImage"; import RendererResImage from "../../components/renderer/RendererResImage"; import {RendererRandRound, RendererRect, RendererRound} from "../../components/renderer/RendererBase"; +import {RendererLine} from "../../components/renderer/RendererLine"; import * as React from "react"; const styles = [ {value: "A1", renderer: RendererRect}, {value: "A2", renderer: RendererRound}, {value: "A3", renderer: RendererRandRound}, + {value: "A — 4", renderer: RendererLine}, {value: "SP — 1", renderer: RendererDSJ}, {value: "SP — 2", renderer: RendererRandRect}, {value: "B1", renderer: Renderer25D},