@jimp/plugin-print
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -11,3 +11,4 @@ { | ||
"../**/*.test.ts", | ||
"../src/package.json" | ||
"../src/package.json", | ||
"../src/dirname-cjs.cts" | ||
], | ||
@@ -14,0 +15,0 @@ "compilerOptions": { |
@@ -0,1 +1,14 @@ | ||
# v1.1.2 (Mon Sep 02 2024) | ||
#### 🐛 Bug Fix | ||
- Fix printing string when words are longer than max-width [#1313](https://github.com/jimp-dev/jimp/pull/1313) ([@hipstersmoothie](https://github.com/hipstersmoothie)) | ||
- Fix using dirname in print plugin [#1310](https://github.com/jimp-dev/jimp/pull/1310) ([@hipstersmoothie](https://github.com/hipstersmoothie)) | ||
#### Authors: 1 | ||
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie)) | ||
--- | ||
# v1.1.0 (Sun Sep 01 2024) | ||
@@ -2,0 +15,0 @@ |
@@ -8,3 +8,4 @@ "use strict"; | ||
const path_1 = __importDefault(require("path")); | ||
const dir = path_1.default.join(__dirname, "../"); | ||
const dirname_js_1 = require("./dirname.js"); | ||
const dir = path_1.default.join(dirname_js_1.dirname, "../"); | ||
exports.SANS_8_BLACK = path_1.default.join(dir, "fonts/open-sans/open-sans-8-black/open-sans-8-black.fnt"); | ||
@@ -11,0 +12,0 @@ exports.SANS_10_BLACK = path_1.default.join(dir, "fonts/open-sans/open-sans-10-black/open-sans-10-black.fnt"); |
@@ -28,2 +28,26 @@ "use strict"; | ||
words.forEach((word) => { | ||
const wordWidth = measureText(font, word + (words.length > 1 ? " " : "")); | ||
// If a word is longer than the allowable width we need to split it across lines. | ||
if (wordWidth > maxWidth) { | ||
const characterIterator = word[Symbol.iterator](); | ||
let current = ""; | ||
for (const char of characterIterator) { | ||
const nextLine = [...currentLine, current + char].join(" "); | ||
const length = measureText(font, nextLine); | ||
if (length < maxWidth) { | ||
current += char; | ||
} | ||
else if (length > maxWidth) { | ||
lines.push([...currentLine, current]); | ||
currentLine = []; | ||
current = char; | ||
} | ||
else { | ||
lines.push([...currentLine, current + char]); | ||
currentLine = []; | ||
current = ""; | ||
} | ||
} | ||
return; | ||
} | ||
const line = [...currentLine, word].join(" "); | ||
@@ -30,0 +54,0 @@ const length = measureText(font, line); |
import path from "path"; | ||
const dir = path.join(__dirname, "../"); | ||
import { dirname } from "./dirname.js"; | ||
const dir = path.join(dirname, "../"); | ||
export const SANS_8_BLACK = path.join(dir, "fonts/open-sans/open-sans-8-black/open-sans-8-black.fnt"); | ||
@@ -4,0 +5,0 @@ export const SANS_10_BLACK = path.join(dir, "fonts/open-sans/open-sans-10-black/open-sans-10-black.fnt"); |
@@ -23,2 +23,26 @@ export function measureText(font, text) { | ||
words.forEach((word) => { | ||
const wordWidth = measureText(font, word + (words.length > 1 ? " " : "")); | ||
// If a word is longer than the allowable width we need to split it across lines. | ||
if (wordWidth > maxWidth) { | ||
const characterIterator = word[Symbol.iterator](); | ||
let current = ""; | ||
for (const char of characterIterator) { | ||
const nextLine = [...currentLine, current + char].join(" "); | ||
const length = measureText(font, nextLine); | ||
if (length < maxWidth) { | ||
current += char; | ||
} | ||
else if (length > maxWidth) { | ||
lines.push([...currentLine, current]); | ||
currentLine = []; | ||
current = char; | ||
} | ||
else { | ||
lines.push([...currentLine, current + char]); | ||
currentLine = []; | ||
current = ""; | ||
} | ||
} | ||
return; | ||
} | ||
const line = [...currentLine, word].join(" "); | ||
@@ -25,0 +49,0 @@ const length = measureText(font, line); |
{ | ||
"name": "@jimp/plugin-print", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"repository": "jimp-dev/jimp", | ||
@@ -9,3 +9,3 @@ "sideEffects": false, | ||
"test": "vitest", | ||
"build": "tshy", | ||
"build": "tshy && cp -r fonts dist", | ||
"dev": "tshy --watch", | ||
@@ -17,6 +17,6 @@ "clean": "rm -rf node_modules .tshy .tshy-build dist .turbo" | ||
"devDependencies": { | ||
"@jimp/config-eslint": "1.1.1", | ||
"@jimp/config-typescript": "1.1.1", | ||
"@jimp/config-eslint": "1.1.2", | ||
"@jimp/config-typescript": "1.1.2", | ||
"@jimp/js-png": "workspace:*", | ||
"@jimp/test-utils": "1.1.1", | ||
"@jimp/test-utils": "1.1.2", | ||
"@types/node": "^20.12.5", | ||
@@ -76,7 +76,7 @@ "eslint": "^8.57.0", | ||
"dependencies": { | ||
"@jimp/core": "1.1.1", | ||
"@jimp/js-jpeg": "1.1.1", | ||
"@jimp/js-png": "1.1.1", | ||
"@jimp/plugin-blit": "1.1.1", | ||
"@jimp/types": "1.1.1", | ||
"@jimp/core": "1.1.2", | ||
"@jimp/js-jpeg": "1.1.2", | ||
"@jimp/js-png": "1.1.2", | ||
"@jimp/plugin-blit": "1.1.2", | ||
"@jimp/types": "1.1.2", | ||
"parse-bmfont-ascii": "^1.0.6", | ||
@@ -91,3 +91,3 @@ "parse-bmfont-binary": "^1.0.6", | ||
"module": "./dist/esm/index.js", | ||
"gitHead": "310b6ef10aaddedf85fb326fcc793d29f23c36d8" | ||
"gitHead": "ba9de4df25a2f0e41f11a68c7aa50181a52115cb" | ||
} |
import path from "path"; | ||
import { dirname } from "./dirname.js"; | ||
const dir = path.join(__dirname, "../"); | ||
const dir = path.join(dirname, "../"); | ||
@@ -5,0 +6,0 @@ export const SANS_8_BLACK = path.join( |
@@ -112,2 +112,20 @@ import { expect, test, describe } from "vitest"; | ||
test("Max width works without spaces", async () => { | ||
const font = await loadFont( | ||
"https://raw.githubusercontent.com/jimp-dev/jimp/main/plugins/plugin-print/fonts/open-sans/open-sans-16-black/open-sans-16-black.fnt" | ||
); | ||
const image = new Jimp({ width: 300, height: 100, color: 0xff8800ff }); | ||
const output = await image | ||
.print({ | ||
font, | ||
x: 150, | ||
y: 50, | ||
text: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", | ||
maxWidth: 100, | ||
}) | ||
.getBuffer("image/png"); | ||
expect(output).toMatchImageSnapshot(); | ||
}); | ||
test("Jimp renders ? for unknown characters", async () => { | ||
@@ -114,0 +132,0 @@ const font = await loadFont(fonts.SANS_16_BLACK); |
@@ -33,2 +33,30 @@ import { BmFont } from "./types.js"; | ||
words.forEach((word) => { | ||
const wordWidth = measureText(font, word + (words.length > 1 ? " " : "")); | ||
// If a word is longer than the allowable width we need to split it across lines. | ||
if (wordWidth > maxWidth) { | ||
const characterIterator = word[Symbol.iterator](); | ||
let current = ""; | ||
for (const char of characterIterator) { | ||
const nextLine = [...currentLine, current + char].join(" "); | ||
const length = measureText(font, nextLine); | ||
if (length < maxWidth) { | ||
current += char; | ||
} else if (length > maxWidth) { | ||
lines.push([...currentLine, current]); | ||
currentLine = []; | ||
current = char; | ||
} else { | ||
lines.push([...currentLine, current + char]); | ||
currentLine = []; | ||
current = ""; | ||
} | ||
} | ||
return; | ||
} | ||
const line = [...currentLine, word].join(" "); | ||
@@ -35,0 +63,0 @@ const length = measureText(font, line); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2326256
182
2085
+ Added@jimp/core@1.1.2(transitive)
+ Added@jimp/file-ops@1.1.2(transitive)
+ Added@jimp/js-jpeg@1.1.2(transitive)
+ Added@jimp/js-png@1.1.2(transitive)
+ Added@jimp/plugin-blit@1.1.2(transitive)
+ Added@jimp/types@1.1.2(transitive)
+ Added@jimp/utils@1.1.2(transitive)
- Removed@jimp/core@1.1.1(transitive)
- Removed@jimp/file-ops@1.1.1(transitive)
- Removed@jimp/js-jpeg@1.1.1(transitive)
- Removed@jimp/js-png@1.1.1(transitive)
- Removed@jimp/plugin-blit@1.1.1(transitive)
- Removed@jimp/types@1.1.1(transitive)
- Removed@jimp/utils@1.1.1(transitive)
Updated@jimp/core@1.1.2
Updated@jimp/js-jpeg@1.1.2
Updated@jimp/js-png@1.1.2
Updated@jimp/plugin-blit@1.1.2
Updated@jimp/types@1.1.2