WIP: Uncouples barcode dimensions from label dimensions

This commit is contained in:
Aaron Louie 2020-11-13 22:06:53 -05:00
parent c2e4c85769
commit 57c8f9c14d
11 changed files with 77 additions and 69 deletions

View File

@ -3,7 +3,7 @@ import {formatDate} from '@angular/common';
export const createQrCodeValue = (barCode: string, initials: string, dateCreated: Date, locationId: string): string => {
const valArray = [
barCode,
initials,
initials.toUpperCase(),
formatDate(dateCreated, 'yyyyMMddHHmm', 'en-us'),
locationId,
];

View File

@ -1,2 +1,2 @@
<canvas id="barcodeCanvas"></canvas>
<canvas id="barcodeCanvas" [ngStyle]="{width: settings.labelLayout.dimensions.barcodeWidth, height: settings.labelLayout.dimensions.barcodeHeight}"></canvas>
<div id="err"></div>

View File

@ -1,4 +1,4 @@
#barcodeCanvas {
width: 100%;
height: 100%;
//width: 100%;
//height: 100%;
}

View File

@ -20,7 +20,7 @@ describe('BarcodeDataMatrixComponent', () => {
beforeEach(() => {
fixture = TestBed.createComponent(BarcodeDataMatrixComponent);
component = fixture.componentInstance;
// settings.labelLayout = labelLayouts.rectangular_lg;
settings.labelLayout = labelLayouts.rectangular_54x32;
component.settings = settings;
component.format = settings.labelLayout.barcodeType;
component.value = '987654321-202101231122-ABCDE-0123';

View File

@ -1,4 +1,4 @@
import {Component, Input, OnInit} from '@angular/core';
import {AfterViewInit, Component, Input, OnInit} from '@angular/core';
import bwipjs from 'bwip-js';
import {AppDefaults} from '../models/appDefaults.interface';
@ -20,17 +20,17 @@ export class BarcodeDataMatrixComponent implements OnInit {
}
renderBarcode(): void {
if (bwipjs && bwipjs.toCanvas && this.settings && this.format) {
if (!!(bwipjs && bwipjs.toCanvas && this.settings && this.format)) {
bwipjs.toCanvas('barcodeCanvas', {
bcid: this.format,
text: this.value,
scale: 2,
width: this.settings.labelLayout.labelWidth,
height: this.settings.labelLayout.labelHeight,
includetext: false,
textalign: 'center',
scale: 1,
width: this.settings.labelLayout.barcodeWidth,
height: this.settings.labelLayout.barcodeHeight,
// includetext: false,
// textalign: 'center',
// version: '12x64',
padding: this.settings.labelLayout.marginSize,
// padding: this.settings.labelLayout.marginSize,
});
}
}

View File

@ -8,8 +8,8 @@ export const labelLayouts = {
type: 'round_32mm_1up',
numCols: 1,
columnGap: 0,
labelWidth: 28.6,
labelHeight: 28.6,
barcodeWidth: 28.6,
barcodeHeight: 28.6,
sideTextMargin: 0,
topTextMargin: 0,
bottomTextMargin: 0,
@ -20,37 +20,39 @@ export const labelLayouts = {
type: 'round_32mm_2up',
numCols: 2,
columnGap: 3.4,
labelWidth: 28.6,
labelHeight: 28.6,
barcodeWidth: 28.6,
barcodeHeight: 28.6,
sideTextMargin: 0,
topTextMargin: 0,
bottomTextMargin: 0,
}),
// rectangular_lg: new LabelLayout({
// name: '2in x 1.25in Rectangular Label',
// barcodeType: 'qrcode',
// type: 'rectangular_lg',
// numCols: 1,
// columnGap: 0,
// labelWidth: 28.6,
// labelHeight: 28.6,
// sideTextMargin: 10,
// topTextMargin: 1,
// bottomTextMargin: 1,
// }),
// rectangular_sm: new LabelLayout({
// name: '96mm x 15mm Rectangular Label',
// barcodeType: 'datamatrix',
// type: 'rectangular_sm',
// numCols: 1,
// columnGap: 0,
// labelWidth: 32,
// labelHeight: 16,
// marginSize: 6,
// sideTextMargin: 2,
// topTextMargin: 3,
// bottomTextMargin: 3,
// }),
rectangular_54x32: new LabelLayout({
name: '2in x 1.25in Rectangular Label',
barcodeType: 'datamatrix',
type: 'rectangular_54x32',
numCols: 1,
columnGap: 0,
columnWidth: 54,
columnHeight: 34,
barcodeWidth: 10,
barcodeHeight: 10,
sideTextMargin: 0,
topTextMargin: 0,
bottomTextMargin: 0,
}),
rectangular_sm: new LabelLayout({
name: '96mm x 15mm Rectangular Label',
barcodeType: 'datamatrix',
type: 'rectangular_sm',
numCols: 1,
columnGap: 0,
barcodeWidth: 32,
barcodeHeight: 16,
marginSize: 6,
sideTextMargin: 2,
topTextMargin: 3,
bottomTextMargin: 3,
}),
};
export const defaultOptions: AppDefaultsOptions = {

View File

@ -18,13 +18,13 @@
*ngIf="settings.labelLayout.barcodeType === 'qrcode'"
[value]="qrCodeValue"
errorCorrectionLevel="H"
[ngStyle]="labelStyle"
[ngStyle]="barcodeStyle"
></qrcode-svg>
<app-barcode-data-matrix
*ngIf="settings.labelLayout.barcodeType !== 'qrcode'"
[value]="qrCodeValue"
[format]="settings.labelLayout.barcodeType"
[ngStyle]="labelStyle"
[ngStyle]="barcodeStyle"
[settings]="settings"
></app-barcode-data-matrix>
<div

View File

@ -14,7 +14,7 @@
width: 24.6mm;
height: 24.6mm;
border: 2mm solid transparent;
border-radius: 100%;
border-radius: 2mm;
background-color: white;
padding: 0;
margin: 0;

View File

@ -15,30 +15,30 @@ export class LabelLayoutComponent implements OnInit {
@Input() initials: string;
settings: AppDefaults;
pageStyle: CssStyle;
labelStyle: CssStyle;
barcodeStyle: CssStyle;
constructor(private settingsService: SettingsService) {
this.settings = this.settingsService.getSettings();
const d = this.settings.labelLayout.dimensions;
this.pageStyle = {
width: d.labelWidth,
height: d.labelHeight,
width: d.columnWidth,
height: d.columnHeight,
padding: d.marginWidth,
};
this.labelStyle = {
width: d.labelWidth,
height: d.labelHeight,
marginTop: `-${this.settings.labelLayout.labelHeight / 2}mm`,
marginLeft: `-${this.settings.labelLayout.labelWidth / 2}mm`,
this.barcodeStyle = {
width: d.barcodeWidth,
height: d.barcodeHeight,
marginTop: `-${this.settings.labelLayout.barcodeHeight / 2}mm`,
marginLeft: `-${this.settings.labelLayout.barcodeWidth / 2}mm`,
};
}
get qrCodeValue(): string {
return createQrCodeValue(
this.barCode,
this.initials.toUpperCase(),
this.initials,
this.dateCreated,
this.settings.locationId
);

View File

@ -4,8 +4,10 @@ export interface LayoutOptions {
name?: string;
units?: string;
pointsPerUnit?: number;
labelWidth?: number;
labelHeight?: number;
barcodeWidth?: number;
barcodeHeight?: number;
columnHeight?: number;
columnWidth?: number;
marginSize?: number;
numCols?: number;
columnGap?: number;
@ -24,8 +26,10 @@ export class LabelLayout {
name = '32mm Round Label - 1up';
units = 'mm';
pointsPerUnit = 0.3528;
labelHeight = 28.6;
labelWidth = 28.6;
barcodeHeight = 28.6;
barcodeWidth = 28.6;
columnHeight = 32;
columnWidth = 32;
marginSize = 1.7;
numCols = 1;
columnGap = 0;
@ -49,10 +53,12 @@ export class LabelLayout {
bottomTextMargin: this._toUnits(this.bottomTextMargin),
columnGap: this._toUnits(this.columnGap),
fontSize: this._toUnits(this.fontSize),
labelWidth: this._toUnits(this.labelWidth),
labelWidthWithMargins: this._toUnits(this.labelWidthWithMargins),
labelHeight: this._toUnits(this.labelHeight),
labelHeightWithMargins: this._toUnits(this.labelHeightWithMargins),
columnWidth: this._toUnits(this.columnWidth),
columnHeight: this._toUnits(this.columnHeight),
barcodeWidth: this._toUnits(this.barcodeWidth),
barcodeWidthWithMargins: this._toUnits(this.barcodeWidthWithMargins),
barcodeHeight: this._toUnits(this.barcodeHeight),
barcodeHeightWithMargins: this._toUnits(this.barcodeHeightWithMargins),
marginWidth: this._toUnits(this.marginSize),
pageHeight: this._toUnits(this.pageHeight),
pageWidth: this._toUnits(this.pageWidth),
@ -63,17 +69,17 @@ export class LabelLayout {
};
}
get labelWidthWithMargins(): number {
get barcodeWidthWithMargins(): number {
return (
this.labelWidth +
this.barcodeWidth +
(this.marginSize * 2) +
(this.sideTextMargin * 2)
);
}
get labelHeightWithMargins(): number {
get barcodeHeightWithMargins(): number {
return (
this.labelHeight +
this.barcodeHeight +
(this.marginSize * 2) +
this.topTextMargin +
this.bottomTextMargin
@ -81,11 +87,11 @@ export class LabelLayout {
}
get pageWidth(): number {
return (this.labelWidthWithMargins * this.numCols);
return (this.barcodeWidthWithMargins * this.numCols);
}
get pageHeight(): number {
return (this.labelHeightWithMargins * this.numCopies);
return (this.barcodeHeightWithMargins * this.numCopies);
}
get fontSize(): number {

View File

@ -75,7 +75,7 @@ export class PrintComponent implements AfterViewInit {
save(callback: (s: Sample) => void) {
const id = createQrCodeValue(
this.barCode,
this.initials.toUpperCase(),
this.initials,
this.dateCreated,
this.settings.locationId
);