From 52f67e2690e52af857dfb04299075644ae106d49 Mon Sep 17 00:00:00 2001 From: Andrew Lisowski Date: Sun, 16 Sep 2018 23:09:25 -0700 Subject: [PATCH 1/5] faster lint --- packages/plugin-print/src/index.js | 21 +++++++++--------- .../test/images/SANS_16_BLACK-positioned.png | Bin 1969 -> 1966 bytes .../plugin-print/test/images/print-number.png | Bin 1652 -> 1643 bytes .../test/images/unknown-char-test.png | Bin 869 -> 870 bytes packages/plugin-print/test/print.test.js | 3 ++- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/plugin-print/src/index.js b/packages/plugin-print/src/index.js index c47e1fa44..a9890553f 100644 --- a/packages/plugin-print/src/index.js +++ b/packages/plugin-print/src/index.js @@ -17,16 +17,17 @@ function xOffsetBasedOnAlignment(constants, font, line, maxWidth, alignment) { function drawCharacter(image, font, x, y, char) { if (char.width > 0 && char.height > 0) { - let imageChar = char.image; - - if (!imageChar) { - imageChar = font.pages[char.page] - .cloneQuiet() - .crop(char.x, char.y, char.width, char.height); - char.image = imageChar; - } - - return image.composite(imageChar, x + char.xoffset, y + char.yoffset); + const characterPage = font.pages[char.page]; + + image.blit( + characterPage, + x + char.xoffset, + y + char.yoffset, + char.x, + char.y, + char.width, + char.height + ); } return image; diff --git a/packages/plugin-print/test/images/SANS_16_BLACK-positioned.png b/packages/plugin-print/test/images/SANS_16_BLACK-positioned.png index e66e278a0964795406e599694a8baec6cdda7d1b..be11559a73596b02341a5d98e5f18e5ef02d1ce7 100644 GIT binary patch literal 1966 zcmds2ZB)`}7XR}SD1w5LAPO=#DwZL#W09jd0*;${%$M{yDz5lKZMhSgj+$hm@>090 zC8o4k(w?Nu8mHQ3Jf;b1!C=PDOf{~ikW95U2Bj6_8nb`To-=#q?6>{6U!MEid+z-` z_ul9C+~;UoY9a6YZ7zQX>7_{{r{1AbDDw z+!M}&{H@Ij)MC>s*=gi(7`cUmD5v*8w*^pnN`COwcX{*6_^GXIE^i!)z~PdKJYKi} zi~FKEo;U9O|71w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#*+V0Mh`w;>q`T&H`bO&f*k$e#i`^0arZn z2pOT)XQEUoLbjHuoqiXjyb1GG*P{SeTd9#Xhc@BnV!W#7fwPnvsI4P)j|DHkhx-4O zoblda!^_}z2?j~*?K^4G$v5s6d6;lN3#^^6O)}&r85|E5a76m$7OuVX_rQdg2;!Vu zZjc?71lm#`@XsuTBc1UFdAA6Ac)C7%O~WjnDP#{NdVBAC+p%?X5q_3MfKSnqGk z6YWZ78HVD zeutspyxZRzEN)t3>ZVhVt=3Qb$OtDhK{dMJw!ld8k#I_W<%%s%YHjK%5Z2+r>jO2} zd4+P!`atK9de)x{>Rlx%7!Pu>o8=ow{1~xClKhV4$lqylr&Tm^$yd7-CKynhF J+rr+g{4Y5uL_Gii diff --git a/packages/plugin-print/test/images/print-number.png b/packages/plugin-print/test/images/print-number.png index 4c0ee7bb341f4d39c8c6468fe2e0f02203bf540d..46f01d7c27511280e7b729d894c83203f2ce32cf 100644 GIT binary patch literal 1643 zcmeHI`%{ux7>0z8AXvll0<@ZG1FKyqOw&N4{m`^R-O(<(gIcDx06g zRJ&-vr)z9YVQYqNh!B(MOiY-Ll&OPRrdg)03bKm(xwAj*FZ&PdFXx>1%$f6^=Xsy! zJ*83HFanN@Lm&`@@V($S2n2EyyiQ&Tz#|h$&>|4P_Hd9LlZ*VM+qOSGb%l0H5WMY1 zXRZi6ekoZ?tptCIoW5~eQ+VGXaie5J1XORXdDGwV;(Btj{JXF^GPeEJ&vKHqV@0h& z6u`BuJu*u=GuBRB6tq!uGMm2^JFTv&15w^z5q%dbC8P&~?E9-~Dq6a6CGY928{^`O z*^UoQN3u>4IM`udNKM$<*FT;D7^H~;%oll^td>kV^H}EqWn{~}q+HlLateBJW zyll+E-d$mk9N$Dpe^!ZFq>wlzNR3j|`P}!$(_8W>me3o`;?#N2`Pro@+O%`#s6k z+CHC!DTnM@T$vM`$vhBPq0BWZgu|cZS57H&-e(0CPFWgSxjlDf=T~yDTXW2^r^0f+ z+fBWlF`5kO8Ey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N|VEgTkP-e>5{F1#VN;rR6r45Bkmak0p?t60c1&$z?0 zzgVmM)7q;QyC3m-dMQj;qQd0qwdmx2wc;JM57w7)AFI6)`PhB3hXSWZVY0+M zf5jhEzshv(`@=Qvxu|rz%2lD7OL2{l^}I9JA1Iu@bW8Yy9o;HduR+88$C5(E>BiG8 z?PxeH>75yK;3<#is<-ENoS*SOgCUi1wro~5GNrO|n%exHUpl#0(lZy^P1-WWVbUZH i70u333U3h9Gfb5%<~*_~q6L_L7(8A5T-G@yGywp?QeZv+ literal 869 zcmeAS@N?(olHy`uVBq!ia0y~yVAKJ!Q#jawqzxnQ0R{$U9Zwg>kP61P2iN*#bBZ)v zT>m>v;N-@{aAN@ZGG7?cS{U zy!s>0JGq~$?=}U>mtC8Zhuy5ra+9_Md}#j68B)B$FLAN6?sMT4&jRKia%+z|ryg*2p;c=yA4tW~3bv~< ztAZ_F1)auZDS7_a{;_D*;iGnQzOGn{N>5l4)uew*yWmc$=37yVcbles Date: Sun, 16 Sep 2018 23:23:22 -0700 Subject: [PATCH 2/5] easier to understand --- packages/plugin-print/src/index.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/packages/plugin-print/src/index.js b/packages/plugin-print/src/index.js index a9890553f..c8e979362 100644 --- a/packages/plugin-print/src/index.js +++ b/packages/plugin-print/src/index.js @@ -50,9 +50,10 @@ function printText(font, x, y, text, defaultCharWidth) { drawCharacter(this, font, x, y, fontChar || {}); - x += - (fontKerning && fontKerning[text[i + 1]] ? fontKerning[text[i + 1]] : 0) + - (fontChar.xadvance || defaultCharWidth); + const kerning = + fontKerning && fontKerning[text[i + 1]] ? fontKerning[text[i + 1]] : 0; + + x += kerning + (fontChar.xadvance || defaultCharWidth); } } @@ -291,18 +292,18 @@ export default () => ({ lines.forEach(line => { const lineString = line.join(' '); + const alignmentWidth = xOffsetBasedOnAlignment( + this.constructor, + font, + lineString, + maxWidth, + alignmentX + ); printText.call( this, font, - x + - xOffsetBasedOnAlignment( - this.constructor, - font, - lineString, - maxWidth, - alignmentX - ), + x + alignmentWidth, y, lineString, defaultCharWidth From eb83fc82b1926fa6522a06c9782561823f6e7570 Mon Sep 17 00:00:00 2001 From: Andrew Lisowski Date: Sun, 16 Sep 2018 23:34:23 -0700 Subject: [PATCH 3/5] add deps --- packages/plugin-print/package.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/plugin-print/package.json b/packages/plugin-print/package.json index 562a77b17..1087e99b5 100644 --- a/packages/plugin-print/package.json +++ b/packages/plugin-print/package.json @@ -24,11 +24,14 @@ "load-bmfont": "^1.4.0" }, "peerDependencies": { - "@jimp/custom": ">=0.3.5" + "@jimp/custom": ">=0.3.5", + "@jimp/plugin-crop": ">=0.3.5", + "@jimp/plugin-blit": ">=0.3.5" }, "devDependencies": { "@jimp/custom": "^0.5.0", "@jimp/plugin-crop": "^0.5.0", + "@jimp/plugin-blit": "^0.5.0", "@jimp/test-utils": "^0.5.0" }, "publishConfig": { From 039c44ccdbf89e934fbbe43a7b99642b16f33b5e Mon Sep 17 00:00:00 2001 From: Andrew Lisowski Date: Sun, 16 Sep 2018 23:37:19 -0700 Subject: [PATCH 4/5] lint --- packages/plugin-print/test/print.test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/plugin-print/test/print.test.js b/packages/plugin-print/test/print.test.js index 42dc90842..ff48b2d5e 100644 --- a/packages/plugin-print/test/print.test.js +++ b/packages/plugin-print/test/print.test.js @@ -111,6 +111,7 @@ describe('Write text over image', function() { ); const textImage = await createTextImage(320, 240, Jimp.FONT_SANS_16_BLACK, { text: 'This is only a test.', + maxWidth: 100 }); @@ -123,6 +124,7 @@ describe('Write text over image', function() { ); const textImage = await createTextImage(320, 240, Jimp.FONT_SANS_16_BLACK, { text: { text: 'This is only a test.' }, + maxWidth: 100 }); From fbe53491e104984c951f8c3ce7c6b367128bc551 Mon Sep 17 00:00:00 2001 From: Andrew Lisowski Date: Sun, 16 Sep 2018 23:48:22 -0700 Subject: [PATCH 5/5] crop no longer needed --- packages/plugin-print/package.json | 2 -- packages/plugin-print/test/print.test.js | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/plugin-print/package.json b/packages/plugin-print/package.json index 1087e99b5..aed96dd4a 100644 --- a/packages/plugin-print/package.json +++ b/packages/plugin-print/package.json @@ -25,12 +25,10 @@ }, "peerDependencies": { "@jimp/custom": ">=0.3.5", - "@jimp/plugin-crop": ">=0.3.5", "@jimp/plugin-blit": ">=0.3.5" }, "devDependencies": { "@jimp/custom": "^0.5.0", - "@jimp/plugin-crop": "^0.5.0", "@jimp/plugin-blit": "^0.5.0", "@jimp/test-utils": "^0.5.0" }, diff --git a/packages/plugin-print/test/print.test.js b/packages/plugin-print/test/print.test.js index ff48b2d5e..36a16669a 100644 --- a/packages/plugin-print/test/print.test.js +++ b/packages/plugin-print/test/print.test.js @@ -2,12 +2,11 @@ import { Jimp, getTestDir, hasOwnProp } from '@jimp/test-utils'; import configure from '@jimp/custom'; -import crop from '@jimp/plugin-crop'; import blit from '@jimp/plugin-blit'; import print from '../src'; -const jimp = configure({ plugins: [print, crop, blit] }, Jimp); +const jimp = configure({ plugins: [print, blit] }, Jimp); async function createTextImage( width,