From 7ca724b0a41d1fca87247d5463f26c9cb736ba0b Mon Sep 17 00:00:00 2001 From: Stephen Last Date: Fri, 2 Sep 2016 11:29:03 +0100 Subject: [PATCH] tidy up --- README.md | 3 ++- barcodes.pdf | Bin 1943 -> 0 bytes dist/srtps.js | 4 ++-- gruntfile.js | 23 ----------------------- gulpfile.js | 12 ++++++++++++ package.json | 9 ++++----- src/srtps.js | 2 +- test/barcodes.pdf | Bin 0 -> 1669 bytes test-basic.js => test/test-basic.js | 2 +- test.js => test/test.js | 19 +++++++------------ 10 files changed, 29 insertions(+), 45 deletions(-) delete mode 100644 barcodes.pdf delete mode 100644 gruntfile.js create mode 100644 gulpfile.js create mode 100644 test/barcodes.pdf rename test-basic.js => test/test-basic.js (84%) rename test.js => test/test.js (70%) diff --git a/README.md b/README.md index 112b463..118c390 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Convert SVG `rects` to a single path string. ## Motivation -I needed to generate PDF documents for printing onto labels media. Some of the labels need barcodes, and I wanted everything to be vector, no bitmaps. I decided to use [PDF Kit](http://pdfkit.org/docs/vector.html#svg_paths) which can use SVG path strings to draw vector shapes. So I needed a way to generate an SVG barcode and get an SVG path string to feed to `.path()`. +I needed to generate PDF documents for printing onto labels media. Some of the labels need barcodes, and I wanted everything to be vector, no bitmaps. I decided to use [PDF Kit](http://pdfkit.org/docs/vector.html#svg_paths) which can use SVG path strings to draw vector shapes. So I needed a way to generate an SVG barcode and get an SVG path string to feed to PDF Kit's `.path()` method. Only one dependency: [xmldom](https://github.com/jindw/xmldom). @@ -33,6 +33,7 @@ console.log(path) // M 10.000 10.000 L 14.000 10.000 L 14.000 38.000 L 10.000 ### With Bardcode & PDFKit ```javascript +import fs from 'fs' import bardcode from 'bardcode' import PDFKit from 'pdfkit' import srtps from 'srtps' diff --git a/barcodes.pdf b/barcodes.pdf deleted file mode 100644 index b9323afa5e53b3bf57d8409353cef5050b751dcf..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1943 zcmZWqc{EjP6fZ?Og}m2f_3}nHlVxi%kBbt2weCzvtzrB9Hz4uys8+x!gOA!l8!0$rSr~uw68EE;1$3tb(5ZoV?f%H+}n-29J_vC>~ z{XJ0v^o2;@AmoLH5g^1Ble*4hx69bgB{jZ!2dR8qWe7;+$D?w9IHdk4%t1ibIQmW0 z>PJyQh(C&hCZy;Jj4&nL<0zkyPCziJgiV$TG+{5J!3Yz!h7p9$utwkwrr#Bgk{eIx zOOYuv0OZV88!}lCqSDZ z;KC>PBB_vSj*u+zm)?BKmU{o_Xp~2FDTHbz0Ik3TGSHW5Id9Wua416QIFArS~7 zu%$IwUQ9%g6@xe;vL0-d^o&wrGJ-6e7zoSgNv-&M0c&RL>;BpOYVYH7*j&d0E_a!Z z(xp3=MBt$v^+XK%WPGd-)4_0>|$9Jg%$ zxb6C)M6UWRTzqR_Ysat*}*@ijLni)QF%h9sorNF{xoB|&dq;Dc2k9ikTY zMkxkE?QF#lgI_&peU1di&^sSKcAA~mCdd|eBsZJN z(pPF=(GjkC^?}++4Fm7D9d^>x`#rE2?4;b68NJ;9c-&>m~imy!+`({#RfC;?C)f>i$>bs)3@hnEelu5 z_0UG??lAd&7+c8RslcZh{iS6U_tLypW9sI(b9*O;92zLhR9Pjd_PsR}CwO)E?08bp z!>!8<2-nO{t*B|J&Am-aH0@*+4PnXdS;tR0)voJy3KTxfiqmGEg`eikO1CL)F`9eB zcQ(DI$cJ+nJ>$c%@B^!7mNvt8^H6S)L_Vny@eC@9d1RL@s%}x)E?PAC$;jZlBNkT8 z!+*qX`1Qh;GOWO_AvwaRyz~WLRayGMZA8z#*=9}DH zhwGdVNJH252cCNzx~FgOeN|QA9{u_E3|7i(%YZoDHfp1cO@^`E5{9Dz01R3K@Ye$} z84ODX7yyoA41^rg)Bz=5F*?(F0>)sGW9ug#!XzixPZ-RY7z-m4V=Y", "scripts": { - "test": "node test.js", - "testbasic": "node test-basic.js" + "test": "node test/test.js", + "testbasic": "node test/test-basic.js" }, "contributors": [ { @@ -26,9 +26,8 @@ "devDependencies": { "babel-preset-es2015": "^6.14.0", "bardcode": "^1.0.0", - "grunt": "^1.0.1", - "grunt-babel": "^6.0.0", - "load-grunt-tasks": "^3.5.2", + "gulp": "^3.9.1", + "gulp-babel": "^6.1.2", "pdfkit": "^0.8.0" }, "dependencies": { diff --git a/src/srtps.js b/src/srtps.js index abd1682..a1759f3 100644 --- a/src/srtps.js +++ b/src/srtps.js @@ -68,7 +68,7 @@ function getRectPaths (rects) { } /** - * rects converted to string paths (exported/public) + * rects converted to string paths (public) */ export function rectsToPath (svgString) { const doc = new dom.DOMParser().parseFromString(svgString, 'text/xml') diff --git a/test/barcodes.pdf b/test/barcodes.pdf new file mode 100644 index 0000000000000000000000000000000000000000..a6a18d7c17b84e208cd5aae9c1f53feff2c8174a GIT binary patch literal 1669 zcmZWqYfuwc6rKWAT+tQ_Dz(zIWP2z#H5yWvIAi%gl=*v|isD!2%NYewKS3EhPrwuw4p$9xG@J5F{ z+dRp1v?_{VKpYBv12md2G5`%tg1Ui2yJTn&g&MED12&%!JqFnP;sF`>fit-`T# zwuD|4nKgr;fw-Qq+Cmo)+GK(uRXBo18J08FMzBl_=0vGzHA!gzx|pN_C_QNd-V)#r z6OiBxuBA0>b2PBTuX^()TlV~}BP);Xl7Vd{f`*Z5J&0plE?2&##5T_sC?zNjvjPYO z0$5#A%fN!6!CF|3AOcz@*eE>%>z0HV3-9MQQ7)KMeRr=*uU*yZd!p>`MbYy-sNJzVXH^N@dtFiY4o=4Wl!!p zWM`+9pQ~wZ%xrzK=15M(4~MdtaXDEVv&`pnmxyoV3@9=Kv{P0o$L3DFxVO4N@^C;_ z;C=GfKG7w<^T8U2MYLOyvBX_n{5S@gTJ~lBvgoI(^EnG<7V*eAmP>BmDytzS*0F0# z=jOc2K4uf~xtph%Xy~+bT7t>dk59W+_pM0mXmMY8e^ido$-ULysfMofeXBycW4+tU zo^HqGX)DRJgsV*rFghtRes;?wbIKk`Qe;8g?44%ku!sPK>$NpO>0iAIe!Hc*a?5+#e*65Re~c-RX6&V@=62Hvj-{ra=eE>Ns_=Bqjxe35E6*4? zr9G@NBO^k6HE)z_p2)By`}Tudcb1{{xcxz(vp?~+aC9Kd#H zai0IwqOP%xNu!G&I!Bgrt7fh@=W2frxHjQ;d_$Xd;tF}GT1(BI(;MUUciPQCsVMeg z_apJtY4-7hqmSK4^?p9)j{IdOJ3ogW!q6l&>WBn{1AGzA>jeaSz7HQH02{`~;7DQ@ zpk8A' var path = srtps.rectsToPath(svg) diff --git a/test.js b/test/test.js similarity index 70% rename from test.js rename to test/test.js index 3d62eef..ad1aaf1 100644 --- a/test.js +++ b/test/test.js @@ -3,15 +3,14 @@ var fs = require('fs') var bardcode = require('bardcode') var PDFKit = require('pdfkit') -var srtps = require('./dist/srtps') +var srtps = require('../dist/srtps') /** * multiplier for converting mm to 72 ppi (72 / 25.4) (1 inch = 25.4 mm) * pdf kit creates pdf docs at 72 ppi */ function mm (num) { - var multiplier = 2.834645669291339 - return num * multiplier + return num * 2.834645669291339 } /** @@ -25,8 +24,7 @@ function svgPath (str, h) { quietZoneSize: 0 // number of moduleWidths in quiet zone on either side. defaults to 10. } var svg = bardcode.drawBarcode('svg', str, options) - var path = srtps.rectsToPath(svg) - return path + return srtps.rectsToPath(svg) } /** @@ -34,18 +32,15 @@ function svgPath (str, h) { */ function barcode (pdf, barcode, h, x, y) { pdf.save() - pdf.translate(mm(x), mm(y)) - pdf.path(svgPath(barcode, h)).fill('#000') + pdf.translate(mm(x), mm(y)).path(svgPath(barcode, h)).fill('#000') pdf.text(barcode, mm(0), (mm(h) + mm(2)), { align: 'left' }) pdf.restore() } // generate pdf var pdf = new PDFKit() -pdf.pipe(fs.createWriteStream('./barcodes.pdf')) +pdf.pipe(fs.createWriteStream('./test/barcodes.pdf')) barcode(pdf, '12345', 10, 10, 10) -barcode(pdf, '3946', 10, 10, 30) -barcode(pdf, 'hello', 10, 10, 50) -barcode(pdf, 'scan-me', 10, 10, 70) -barcode(pdf, '.PL46521', 10, 10, 90) +barcode(pdf, 'hello', 10, 10, 30) +barcode(pdf, 'scan-me', 10, 10, 50) pdf.end()