Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@jimp/plugin-print

Package Overview
Dependencies
Maintainers
2
Versions
242
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jimp/plugin-print - npm Package Compare versions

Comparing version 0.17.0 to 0.17.1--canary.e22c14a.0

31

dist/index.js

@@ -12,4 +12,2 @@ "use strict";

var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var _path = _interopRequireDefault(require("path"));

@@ -64,29 +62,2 @@

function splitLines(font, text, maxWidth) {
var words = text.split(" ");
var lines = [];
var currentLine = [];
var longestLine = 0;
words.forEach(function (word) {
var line = [].concat((0, _toConsumableArray2["default"])(currentLine), [word]).join(" ");
var length = (0, _measureText.measureText)(font, line);
if (length <= maxWidth) {
if (length > longestLine) {
longestLine = length;
}
currentLine.push(word);
} else {
lines.push(currentLine);
currentLine = [word];
}
});
lines.push(currentLine);
return {
lines: lines,
longestLine: longestLine
};
}
function loadPages(Jimp, dir, pages) {

@@ -237,3 +208,3 @@ var newPages = pages.map(function (page) {

var _splitLines = splitLines(font, text, maxWidth),
var _splitLines = (0, _measureText.splitLines)(font, text, maxWidth),
lines = _splitLines.lines,

@@ -240,0 +211,0 @@ longestLine = _splitLines.longestLine;

43

dist/measure-text.js
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {

@@ -7,4 +9,7 @@ value: true

exports.measureText = measureText;
exports.splitLines = splitLines;
exports.measureTextHeight = measureTextHeight;
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
function measureText(font, text) {

@@ -23,21 +28,35 @@ var x = 0;

function measureTextHeight(font, text, maxWidth) {
function splitLines(font, text, maxWidth) {
var words = text.split(" ");
var line = "";
var textTotalHeight = font.common.lineHeight;
var lines = [];
var currentLine = [];
var longestLine = 0;
words.forEach(function (word) {
var line = [].concat((0, _toConsumableArray2["default"])(currentLine), [word]).join(" ");
var length = measureText(font, line);
for (var n = 0; n < words.length; n++) {
var testLine = line + words[n] + " ";
var testWidth = measureText(font, testLine);
if (length <= maxWidth) {
if (length > longestLine) {
longestLine = length;
}
if (testWidth > maxWidth && n > 0) {
textTotalHeight += font.common.lineHeight;
line = words[n] + " ";
currentLine.push(word);
} else {
line = testLine;
lines.push(currentLine);
currentLine = [word];
}
}
});
lines.push(currentLine);
return {
lines: lines,
longestLine: longestLine
};
}
return textTotalHeight;
function measureTextHeight(font, text, maxWidth) {
var _splitLines = splitLines(font, text, maxWidth),
lines = _splitLines.lines;
return lines.length * font.common.lineHeight;
}
//# sourceMappingURL=measure-text.js.map
{
"name": "@jimp/plugin-print",
"version": "0.17.0",
"version": "0.17.1--canary.e22c14a.0",
"description": "print an image.",

@@ -24,4 +24,4 @@ "main": "dist/index.js",

"@babel/runtime": "^7.7.2",
"@jimp/utils": "^0.17.0",
"load-bmfont": "^1.4.0"
"@jimp/utils": "0.17.1--canary.e22c14a.0",
"load-bmfont": "^1.4.1"
},

@@ -33,5 +33,5 @@ "peerDependencies": {

"devDependencies": {
"@jimp/custom": "^0.17.0",
"@jimp/plugin-blit": "^0.17.0",
"@jimp/test-utils": "^0.17.0"
"@jimp/custom": "0.17.1--canary.e22c14a.0",
"@jimp/plugin-blit": "0.17.1--canary.e22c14a.0",
"@jimp/test-utils": "0.17.1--canary.e22c14a.0"
},

@@ -41,3 +41,3 @@ "publishConfig": {

},
"gitHead": "bb5433de761d6fc557c726f5622ec20669c558e9"
"gitHead": "e22c14a9aa3e2ba6d6dee4cf0fe1743186e58c7a"
}
import Path from "path";
import bMFont from "load-bmfont";
import { isNodePattern, throwError } from "@jimp/utils";
import { measureText, measureTextHeight } from "./measure-text";
import { measureText, measureTextHeight, splitLines } from "./measure-text";

@@ -60,32 +60,2 @@ function xOffsetBasedOnAlignment(constants, font, line, maxWidth, alignment) {

function splitLines(font, text, maxWidth) {
const words = text.split(" ");
const lines = [];
let currentLine = [];
let longestLine = 0;
words.forEach((word) => {
const line = [...currentLine, word].join(" ");
const length = measureText(font, line);
if (length <= maxWidth) {
if (length > longestLine) {
longestLine = length;
}
currentLine.push(word);
} else {
lines.push(currentLine);
currentLine = [word];
}
});
lines.push(currentLine);
return {
lines,
longestLine,
};
}
function loadPages(Jimp, dir, pages) {

@@ -92,0 +62,0 @@ const newPages = pages.map((page) => {

@@ -18,20 +18,36 @@ export function measureText(font, text) {

export function measureTextHeight(font, text, maxWidth) {
export function splitLines(font, text, maxWidth) {
const words = text.split(" ");
let line = "";
let textTotalHeight = font.common.lineHeight;
const lines = [];
let currentLine = [];
let longestLine = 0;
for (let n = 0; n < words.length; n++) {
const testLine = line + words[n] + " ";
const testWidth = measureText(font, testLine);
words.forEach((word) => {
const line = [...currentLine, word].join(" ");
const length = measureText(font, line);
if (testWidth > maxWidth && n > 0) {
textTotalHeight += font.common.lineHeight;
line = words[n] + " ";
if (length <= maxWidth) {
if (length > longestLine) {
longestLine = length;
}
currentLine.push(word);
} else {
line = testLine;
lines.push(currentLine);
currentLine = [word];
}
}
});
return textTotalHeight;
lines.push(currentLine);
return {
lines,
longestLine,
};
}
export function measureTextHeight(font, text, maxWidth) {
const { lines } = splitLines(font, text, maxWidth);
return lines.length * font.common.lineHeight;
}

@@ -284,2 +284,13 @@ /* eslint key-spacing: ["error", { "align": "value" }] */

});
it("measureText is consistent with measureTextWidth", async () => {
const font = await jimp.loadFont(Jimp.FONT_SANS_16_BLACK);
const text = "n n n";
const width = jimp.measureText(font, text);
const height = jimp.measureTextHeight(font, text, width);
const lineHeight = jimp.measureTextHeight(font, text, Infinity);
height.should.be.deepEqual(lineHeight);
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc