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';
// Sizes of characters and lines used in character bounding boxes generated by
// these tests, expressed as percentages of the image size.
const charWidth = 4;
const charHeight = 8;
const charSpacing = 5;
const lineSpacing = 10;
// Sizes and spacing between character bounding boxes in these tests, expressed
// as fractions of the image size.
const charWidth = 0.04;
const charHeight = 0.08;
const charSpacing = 0.05;
const lineSpacing = 0.1;
/**
* Return a `[left, top, width, height]` tuple of the expected position of
* a word in the text layer.
*/
function expectedBoxOffsetAndSize(imageWidth, imageHeight, lineIndex, text) {
const xScale = imageWidth / 100;
const yScale = imageHeight / 100;
const width =
(text.length - 1) * charSpacing * imageWidth + charWidth * imageWidth;
const height = charHeight * imageHeight;
const width = (text.length - 1) * charSpacing * xScale + charWidth * xScale;
const height = charHeight * yScale;
return [0, lineSpacing * lineIndex * yScale, width, height];
return [0, lineSpacing * lineIndex * imageHeight, width, height].map(coord =>
Math.round(coord)
);
}
/**
......@@ -33,10 +33,10 @@ function createCharBoxes(text) {
for (let char of text) {
charBoxes.push({
left: (charIndex * charSpacing) / 100,
right: (charIndex * charSpacing + charWidth) / 100,
top: (lineIndex * lineSpacing) / 100,
bottom: (lineIndex * lineSpacing + charHeight) / 100,
left: charIndex * charSpacing,
right: charIndex * charSpacing + charWidth,
top: lineIndex * lineSpacing,
bottom: lineIndex * lineSpacing + charHeight,
});
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