Skip to content

Commit a5a5d8d

Browse files
committed
Fixed two bugs impacting textract
1 parent e068a96 commit a5a5d8d

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

js/fontStatistics.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ import { CharMetricsFamily, CharMetricsFont, CharMetricsRawFamily } from './obje
1717
* @param {Array<OcrPage>} pageArr
1818
*/
1919
export function calcCharMetricsFromPages(pageArr) {
20+
if (!pageArr || pageArr.length === 0) return {};
21+
2022
const pageCharMetricsArr = pageArr.map((x) => calcCharMetricsPage(x));
2123

24+
if (pageCharMetricsArr.length === 0) return {};
25+
2226
const charMetricsRawObj = pageCharMetricsArr.reduce((x, y) => unionCharMetricsRawObj(x, y));
2327

2428
/** @type {Object.<string, CharMetricsFamily>} */

js/import/convertDocTextract.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,11 @@ function convertLineTextract(lineBlock, blockMap, relationshipMap, pageObj, page
270270
lineObj.baseline[1] = -lineHeight / 3 - (lineObj.bbox.bottom - polyLine.bl.y);
271271
}
272272

273-
if (xHeight) lineObj.xHeight = xHeight;
274-
if (ascHeight) lineObj.ascHeight = ascHeight;
273+
// TODO: Properly process metrics when these are negative.
274+
// This seems to happen for certain orientations of text.
275+
// For now, we skip to ignore an error being thrown due to a negative value.
276+
if (xHeight && xHeight > 0) lineObj.xHeight = xHeight;
277+
if (ascHeight && ascHeight > 0) lineObj.ascHeight = ascHeight;
275278

276279
return lineObj.words.length > 0 ? lineObj : null;
277280
}

0 commit comments

Comments
 (0)