chore: remove legacy PDF417 generation implementation
Delete custom PDF417 generator and renderer now that all components use zxing-wasm/writer. Removes Pdf417Barcode component, generateBarcode, and renderBarcode utilities. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,51 +0,0 @@
|
|||||||
import { BarcodeArray } from './pdf417';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Renders a PDF417 barcode matrix to a canvas and returns it as a data URL.
|
|
||||||
*
|
|
||||||
* This function creates an HTML canvas element, draws the barcode by iterating through
|
|
||||||
* the barcode matrix, and converts the canvas to a base64-encoded PNG data URL that
|
|
||||||
* can be used as an image source.
|
|
||||||
*
|
|
||||||
* @param barcodeMatrix - The barcode array generated by the PDF417 encoder containing
|
|
||||||
* the barcode matrix data with dimensions and binary code values
|
|
||||||
* @param blockWidth - The width in pixels of each individual barcode module (bar/space unit)
|
|
||||||
* @param blockHeight - The height in pixels of each individual barcode module (bar/space unit)
|
|
||||||
*
|
|
||||||
* @returns A data URL string (base64-encoded PNG) representing the rendered barcode image,
|
|
||||||
* suitable for use in an HTML img src attribute
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* ```typescript
|
|
||||||
* const pdf417 = createPDF417();
|
|
||||||
* pdf417.init("Hello World", 2, 2);
|
|
||||||
* const barcodeArray = pdf417.getBarcodeArray();
|
|
||||||
* const dataUrl = renderBarcode(barcodeArray, 2, 4);
|
|
||||||
* // dataUrl can now be used: <img src={dataUrl} />
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
export function renderBarcode(barcodeMatrix: BarcodeArray, blockWidth: number, blockHeight: number) {
|
|
||||||
|
|
||||||
const canvas = document.createElement('canvas');
|
|
||||||
canvas.width = barcodeMatrix.num_cols * blockWidth;
|
|
||||||
canvas.height = barcodeMatrix.num_rows * blockHeight;
|
|
||||||
const ctx = canvas.getContext('2d') as CanvasRenderingContext2D;
|
|
||||||
|
|
||||||
let positionY = 0;
|
|
||||||
for (let row = 0; row < barcodeMatrix.num_rows; row += 1) {
|
|
||||||
let positionX = 0;
|
|
||||||
|
|
||||||
for (let col = 0; col < barcodeMatrix.num_cols; col += 1) {
|
|
||||||
if (barcodeMatrix.bcode[row][col] === 1) {
|
|
||||||
ctx.fillStyle = '#000';
|
|
||||||
} else {
|
|
||||||
ctx.fillStyle = '#FFF';
|
|
||||||
}
|
|
||||||
ctx.fillRect(positionX, positionY, blockWidth, blockHeight);
|
|
||||||
positionX += blockWidth;
|
|
||||||
}
|
|
||||||
positionY += blockHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
return canvas.toDataURL();
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import { useState, useEffect, FC } from 'react';
|
|
||||||
import { generateBarcode } from '../lib/pdf/pdf417';
|
|
||||||
import { renderBarcode } from '../lib/pdf/renderBarcode';
|
|
||||||
|
|
||||||
export const Pdf417Barcode:FC<{hub3aText:string, className?: string}> = ({hub3aText: hub3a_text, className}) => {
|
|
||||||
const [bitmapData, setBitmapData] = useState<string | undefined>(undefined);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const barcodeMatrix = generateBarcode(hub3a_text);
|
|
||||||
const bitmap = renderBarcode(barcodeMatrix, 2, 2);
|
|
||||||
setBitmapData(bitmap);
|
|
||||||
}, [hub3a_text]);
|
|
||||||
|
|
||||||
// Don't render until bitmap is generated (prevents hydration mismatch)
|
|
||||||
if (!bitmapData) {
|
|
||||||
return (
|
|
||||||
<div style={{ width: "350px", height: "92px" }} className="flex items-center justify-center">
|
|
||||||
<span className="loading loading-spinner loading-lg"></span>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
// eslint-disable-next-line @next/next/no-img-element
|
|
||||||
<img src={bitmapData} alt="PDF417 Barcode" className={className} style={className ? undefined : { width: "350px", height: "92px" }} />
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user