qrbtf/src/components/renderer/RendererBase.js

31 lines
721 B
JavaScript
Raw Normal View History

2020-05-06 15:59:56 +00:00
import React from "react";
import PropTypes from 'prop-types';
import {defaultRenderer} from "../../utils/util";
function listPoints(qrcode) {
if (!qrcode) return[]
const nCount = qrcode.getModuleCount();
const pointList = []
let id = 0
for (let x = 0; x < nCount; x++) {
for (let y = 0; y < nCount; y++) {
if (qrcode.isDark(x, y)) {
pointList.push(<rect key={id++} width={1} height={1} fill={"black"} x={x} y={y}/>)
}
}
}
return pointList;
}
const RendererBase = ({ qrcode }) => (
defaultRenderer(qrcode, listPoints(qrcode))
);
RendererBase.prototype = {
qrcode: PropTypes.object.isRequired
}
export default RendererBase;