Commit df5ae027 authored by Robert Knight's avatar Robert Knight

Use fractions instead of percentages for metrics

Use fractions instead of percentages for the character and line metrics
in ImageTextLayer tests, for consistency with the ImageTextLayer API.
parent 4b2dc699
import { ImageTextLayer } from '../image-text-layer'; import { ImageTextLayer } from '../image-text-layer';
// Sizes of characters and lines used in character bounding boxes generated by // Sizes and spacing between character bounding boxes in these tests, expressed
// these tests, expressed as percentages of the image size. // as fractions of the image size.
const charWidth = 4; const charWidth = 0.04;
const charHeight = 8; const charHeight = 0.08;
const charSpacing = 5; const charSpacing = 0.05;
const lineSpacing = 10; const lineSpacing = 0.1;
/** /**
* Return a `[left, top, width, height]` tuple of the expected position of * Return a `[left, top, width, height]` tuple of the expected position of
* a word in the text layer. * a word in the text layer.
*/ */
function expectedBoxOffsetAndSize(imageWidth, imageHeight, lineIndex, text) { function expectedBoxOffsetAndSize(imageWidth, imageHeight, lineIndex, text) {
const xScale = imageWidth / 100; const width =
const yScale = imageHeight / 100; (text.length - 1) * charSpacing * imageWidth + charWidth * imageWidth;
const height = charHeight * imageHeight;
const width = (text.length - 1) * charSpacing * xScale + charWidth * xScale; return [0, lineSpacing * lineIndex * imageHeight, width, height].map(coord =>
const height = charHeight * yScale; Math.round(coord)
);
return [0, lineSpacing * lineIndex * yScale, width, height];
} }
/** /**
...@@ -33,10 +33,10 @@ function createCharBoxes(text) { ...@@ -33,10 +33,10 @@ function createCharBoxes(text) {
for (let char of text) { for (let char of text) {
charBoxes.push({ charBoxes.push({
left: (charIndex * charSpacing) / 100, left: charIndex * charSpacing,
right: (charIndex * charSpacing + charWidth) / 100, right: charIndex * charSpacing + charWidth,
top: (lineIndex * lineSpacing) / 100, top: lineIndex * lineSpacing,
bottom: (lineIndex * lineSpacing + charHeight) / 100, bottom: lineIndex * lineSpacing + charHeight,
}); });
if (char === ' ') { if (char === ' ') {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment