From 30552e7a5e01b7d9dec895d943c4d3a44fa76575 Mon Sep 17 00:00:00 2001 From: Balearica Date: Thu, 15 Aug 2024 09:03:20 -0700 Subject: [PATCH] Added more functions to interface --- js/fontContainerMain.js | 5 ++--- js/fontEval.js | 8 ++++---- js/import/import.js | 4 ++-- js/objects/layoutObjects.js | 8 ++++++++ module.js | 5 ++++- package-lock.json | 4 ++-- 6 files changed, 22 insertions(+), 12 deletions(-) diff --git a/js/fontContainerMain.js b/js/fontContainerMain.js index 6b9219d..f450f8c 100644 --- a/js/fontContainerMain.js +++ b/js/fontContainerMain.js @@ -114,8 +114,7 @@ export async function loadChiSimFont() { * @param {boolean} [forceWorkerUpdate=false] - If true, forces the worker to update the font data even if the font data of this type is already loaded. * This should be used when switching from unvalidated to validated optimized fonts. */ -export async function enableDisableFontOpt(enable, useInitial = false, forceWorkerUpdate = false) { - const browserMode = typeof process === 'undefined'; +export async function enableFontOpt(enable, useInitial = false, forceWorkerUpdate = false) { // Enable/disable optimized font if (enable && useInitial && fontAll.optInitial) { @@ -127,7 +126,7 @@ export async function enableDisableFontOpt(enable, useInitial = false, forceWork } // Enable/disable optimized font in workers - if (browserMode) { + if (typeof process === 'undefined') { await setBuiltInFontsWorker(gs.schedulerInner, forceWorkerUpdate); } else { // const { setFontAll } = await import('./worker/compareOCRModule.js'); diff --git a/js/fontEval.js b/js/fontEval.js index 0a8ddca..7367494 100644 --- a/js/fontEval.js +++ b/js/fontEval.js @@ -1,7 +1,7 @@ import { DebugData, fontMetricsObj, pageMetricsArr } from './containers/dataContainer.js'; import { fontAll } from './containers/fontContainer.js'; import { ImageCache } from './containers/imageContainer.js'; -import { enableDisableFontOpt, optimizeFontContainerAll, setDefaultFontAuto } from './fontContainerMain.js'; +import { enableFontOpt, optimizeFontContainerAll, setDefaultFontAuto } from './fontContainerMain.js'; import { gs } from './generalWorkerMain.js'; /** @@ -188,7 +188,7 @@ export async function runFontOptimization(ocrArr) { const pageNum = Math.min(ImageCache.pageCount, 5); // Set raw font in workers - await enableDisableFontOpt(false); + await enableFontOpt(false); // This step needs to happen here as all fonts must be registered before initializing the canvas. if (!browserMode) { @@ -202,7 +202,7 @@ export async function runFontOptimization(ocrArr) { if (calculateOpt && Object.keys(fontAll.optInitial).length > 0) { // Enable optimized fonts - await enableDisableFontOpt(true, true, true); + await enableFontOpt(true, true, true); const evalOpt = await evaluateFonts(ocrArr.slice(0, pageNum)); @@ -248,7 +248,7 @@ export async function runFontOptimization(ocrArr) { } // Set final fonts in workers - await enableDisableFontOpt(true, false, true); + await enableFontOpt(true, false, true); const enableOpt = enableOptSerif || enableOptSans; diff --git a/js/import/import.js b/js/import/import.js index df8b04a..10e5ab6 100644 --- a/js/import/import.js +++ b/js/import/import.js @@ -11,7 +11,7 @@ import { } from '../containers/dataContainer.js'; import { fontAll } from '../containers/fontContainer.js'; import { ImageCache, imageUtils, ImageWrapper } from '../containers/imageContainer.js'; -import { enableDisableFontOpt, optimizeFontContainerAll, setDefaultFontAuto } from '../fontContainerMain.js'; +import { enableFontOpt, optimizeFontContainerAll, setDefaultFontAuto } from '../fontContainerMain.js'; import { runFontOptimization } from '../fontEval.js'; import { calcFontMetricsFromPages } from '../fontStatistics.js'; import { gs } from '../generalWorkerMain.js'; @@ -327,7 +327,7 @@ export async function importFiles(files) { if (!fontRaw) throw new Error('Raw font data not found.'); fontAll.opt = await optimizeFontContainerAll(fontRaw, fontMetricsObj); opt.enableOpt = true; - await enableDisableFontOpt(true); + await enableFontOpt(true); } } diff --git a/js/objects/layoutObjects.js b/js/objects/layoutObjects.js index 1d837c2..ffa0ee6 100644 --- a/js/objects/layoutObjects.js +++ b/js/objects/layoutObjects.js @@ -84,3 +84,11 @@ export function LayoutDataTablePage() { /** @type {Array} */ this.tables = []; } + +const layout = { + LayoutDataColumn, + LayoutDataTable, + LayoutRegion, +}; + +export default layout; diff --git a/module.js b/module.js index 43277c9..ec6a659 100644 --- a/module.js +++ b/module.js @@ -17,7 +17,7 @@ import { loadBuiltInFontsRaw } from './js/fontContainerMain.js'; import { gs } from './js/generalWorkerMain.js'; import { importFiles, importFilesSupp } from './js/import/import.js'; import { calcBoxOverlap, combineOCRPage } from './js/modifyOCR.js'; -import { calcTableBbox } from './js/objects/layoutObjects.js'; +import layout, { calcTableBbox } from './js/objects/layoutObjects.js'; import ocr from './js/objects/ocrObjects.js'; import { calcEvalStatsDoc, @@ -30,6 +30,7 @@ import { imageStrToBlob } from './js/utils/imageUtils.js'; import { countSubstringOccurrences, getRandomAlphanum, replaceSmartQuotes } from './js/utils/miscUtils.js'; import { calcConf, mergeOcrWords, splitOcrWord } from './js/utils/ocrUtils.js'; import { assignParagraphs } from './js/utils/reflowPars.js'; +import { enableFontOpt } from './js/fontContainerMain.js'; /** * Initialize the program and optionally pre-load resources. @@ -157,6 +158,7 @@ export default { combineOCRPage, compareOCR, data, + enableFontOpt, evalOCRPage, exportData, download, @@ -164,6 +166,7 @@ export default { importFilesSupp, inputData, init, + layout, opt, recognize, recognizePage, diff --git a/package-lock.json b/package-lock.json index 5bbb241..cd6b9c3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { - "name": "scribe.js", + "name": "scribe.js-ocr", "version": "0.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "scribe.js", + "name": "scribe.js-ocr", "version": "0.1.0", "license": "AGPL-3.0", "dependencies": {