Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/first release #3

Merged
merged 22 commits into from
Dec 4, 2020
Merged

Feature/first release #3

merged 22 commits into from
Dec 4, 2020

Conversation

wh1t3h47
Copy link
Owner

@wh1t3h47 wh1t3h47 commented Nov 19, 2020

Release v0.0.1

Planned features:

2. Setup barebones BarCode file generator (to support creating files onto the disk in the future)
2. Create 2 ways to generate PDF, strict or best

Done:

  1. Generate a PDF stream that replicates This (only for packages)
  2. Implement manual test to QR code and barcode (dump file into disk)
  3. Create correctly formated QR code and barcode out of data;
  4. Store these codes into a PDF file with approximate size;
  5. Create manual test for PDF generation into disk
  6. Create the place holder for labels and add text on it

This will be for our internal use in a freelance project, but we have plans to publish it as a package

@wh1t3h47
Copy link
Owner Author

wh1t3h47 commented Nov 21, 2020

PDF info:

Font: Helvetica (/ Bold)
Size: 595 x 842 pts (A4)

PDF corners

// create a document and pipe to a blob
const doc = new PDFDocument();
const stream = doc.pipe(blobStream());

const marginLeft = 10;
const marginTop = 10;
const cornerSize = 15;
const pageSize = 612;
const halfPage = Math.round(pageSize / 2);
const marginBetweenLabels = marginLeft;
const widthBetweenCorners = halfPage - marginLeft * 2 - cornerSize * 2;
const heightBetweenCorners = Math.round((halfPage - marginTop * 2 - cornerSize * 2) / 2);
// Seguimos a mesma ordem que CSS
const topLeftCorner = [marginLeft, marginTop + cornerSize]
const topRightCorner = [marginLeft + cornerSize + widthBetweenCorners, marginTop];
const bottomRightCorner = [topRightCorner[0] + cornerSize, marginTop + cornerSize + heightBetweenCorners];
const bottomLeftCorner = [marginLeft + cornerSize, marginTop + bottomRightCorner[1]];

// <3
doc
  .moveTo(...topLeftCorner)
  topLeftCorner[1] -= cornerSize;
doc
  .lineTo(...topLeftCorner)
  .lineTo(topLeftCorner[0] + cornerSize, topLeftCorner[1])
  .stroke();
doc
  .moveTo(...topRightCorner)
  topRightCorner[0] += cornerSize
doc
  .lineTo(...topRightCorner)
  .lineTo(topRightCorner[0], topRightCorner[1] + cornerSize)
  .stroke();
doc
  .moveTo(...bottomRightCorner)
  bottomRightCorner[1] += cornerSize
doc
  .lineTo(...bottomRightCorner)
  .lineTo(bottomRightCorner[0]  - cornerSize, bottomRightCorner[1])
  .stroke()
doc
  .moveTo(...bottomLeftCorner)
  bottomLeftCorner[0] -= cornerSize;
doc
  .lineTo(...bottomLeftCorner)
  .lineTo(bottomLeftCorner[0], bottomLeftCorner[1] - cornerSize)
  .stroke()

// end and display the document in the iframe to the right
doc.end();
stream.on('finish', function() {
  iframe.src = stream.toBlobURL('application/pdf');
});

Teste Aqui

@wh1t3h47
Copy link
Owner Author

wh1t3h47 commented Nov 23, 2020

Next changes

  • Refactor secondHalfPage, it's ugly, instead use "labelInPage" and an enum (first, second, third...) [DONE]
  1. Offset for y and x, test it (that applies for text on labels too) [PENDING]
    3. Add strict or best

@wh1t3h47
Copy link
Owner Author

wh1t3h47 commented Nov 28, 2020

Proximos passos:

Checkout no commit 943c125
La tem o src/index.ts, nele geramos um barcode com Stream, utilizar esse mesmo codigo para gerar um barcode no pdf
Setar o lastY no caixa de Entrega ao vizinho
Colocar que nao queremos entrega ao vizinho por padrao

implement drawShipToNeighbor

implrment drawRecepientBox

Implement dataMatrix into the pdf
@wh1t3h47 wh1t3h47 force-pushed the feature/first-release branch from ec1a187 to e2ec14f Compare November 29, 2020 21:26
@wh1t3h47
Copy link
Owner Author

wh1t3h47 commented Dec 1, 2020

O que falta?

getter pra offsetX e offsetY src/labels/correiosPackage/drawStream.ts
Etiquetas 3 e 4 na pagina
Documentar
Padronizar comentarios (@lucaashoff pode ajudar nisso)
Criar testes + e2e (a gente pode usar uma lib js pra ler barcode e converter o pdf pra jpg)

@wh1t3h47
Copy link
Owner Author

wh1t3h47 commented Dec 1, 2020

Preparacao para inaugurar!

@lucaashoff Finalmente gerando 4 etiquetas por pagina, quero te pedir algumas coisas

  1. Code review dessa PR.
  2. As configuracoes de compilacao, o comando serve do yarn
  3. Traduzir e acentuar os comentarios adequadamente
  4. Sugestao de como diminuir o correiosPackage/drawStream.ts

Copy link
Owner Author

@wh1t3h47 wh1t3h47 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Algumas consideracoes

.eslintrc.json Outdated Show resolved Hide resolved
src/barCode/barcodeModel.ts Show resolved Hide resolved
src/barCode/barcodeModel.ts Show resolved Hide resolved
numeroRuaRemetente,
checkSumCepDestino,
};
const data: string = `${datamatrix.cepDestino}${datamatrix.numeroRuaDestino}${datamatrix.cepRemetente}${datamatrix.numeroRuaRemetente}${datamatrix.checkSumCepDestino}`.padEnd(
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adicionar mao propria ao objeto de geracao do QR code

Copy link
Owner Author

@wh1t3h47 wh1t3h47 Dec 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acho que o correios nao usa isso no encomendas.

  • Verificar, instalar leitor de qr code e ler de outros pdfs

src/barCode/barcodeModel.ts Show resolved Hide resolved
src/barCode/file.ts Show resolved Hide resolved
src/barCode/file.ts Show resolved Hide resolved
} // else
reject(err);
}
// `png` is a Buffer
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment

src/label/labelModel.ts Show resolved Hide resolved
src/label/pageTypes.ts Show resolved Hide resolved
@wh1t3h47 wh1t3h47 requested a review from lucaashoff December 2, 2020 00:44
@wh1t3h47 wh1t3h47 added treat before publishing Do not publish on NPM before solving it WIP Working on it labels Dec 2, 2020
}

public createDatamatrix(
CepDestino: string,
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lucaashoff Ta afim de adicioner suporte a string | number?

Copy link
Owner Author

@wh1t3h47 wh1t3h47 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consideracoes

numeroRuaRemetente,
checkSumCepDestino,
};
const data: string = `${datamatrix.cepDestino}${datamatrix.numeroRuaDestino}${datamatrix.cepRemetente}${datamatrix.numeroRuaRemetente}${datamatrix.checkSumCepDestino}`.padEnd(
Copy link
Owner Author

@wh1t3h47 wh1t3h47 Dec 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acho que o correios nao usa isso no encomendas.

  • Verificar, instalar leitor de qr code e ler de outros pdfs

@wh1t3h47
Copy link
Owner Author

wh1t3h47 commented Dec 2, 2020

Tem diversos problemas que eu seto a doc.font() para a mesma doc.font() que a chamada anterior, isso precisa ser otimizado
Preciso verificar se isso se aplica para stroke() e para outros metodos do pdfkit, no drawStream da etiquetaCorreios.
Isso iria simplificar o codigo e manter no principio DRY (Dont Repeat Yourself)

  • Resolver?

@wh1t3h47 wh1t3h47 merged commit 0f691dc into main Dec 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
treat before publishing Do not publish on NPM before solving it WIP Working on it
Projects
None yet
2 participants