????

Your IP : 18.191.255.7


Current Path : C:/inetpub/vhost/invest.gdtsolutions.vn/api/node_modules/@jimp/plugin-print/dist/
Upload File :
Current File : C:/inetpub/vhost/invest.gdtsolutions.vn/api/node_modules/@jimp/plugin-print/dist/measure-text.js

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.measureText = measureText;
exports.measureTextHeight = measureTextHeight;
exports.splitLines = splitLines;
function measureText(font, text) {
  let x = 0;
  for (let i = 0; i < text.length; i++) {
    if (font.chars[text[i]]) {
      const kerning = font.kernings[text[i]] && font.kernings[text[i]][text[i + 1]] ? font.kernings[text[i]][text[i + 1]] : 0;
      x += (font.chars[text[i]].xadvance || 0) + kerning;
    }
  }
  return x;
}
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 measureTextHeight(font, text, maxWidth) {
  const {
    lines
  } = splitLines(font, text, maxWidth);
  return lines.length * font.common.lineHeight;
}
//# sourceMappingURL=measure-text.js.map