Skip to content

Commit

Permalink
Added more functions to interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Balearica committed Aug 15, 2024
1 parent 16520e6 commit 30552e7
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 12 deletions.
5 changes: 2 additions & 3 deletions js/fontContainerMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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');
Expand Down
8 changes: 4 additions & 4 deletions js/fontEval.js
Original file line number Diff line number Diff line change
@@ -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';

/**
Expand Down Expand Up @@ -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) {
Expand All @@ -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));

Expand Down Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions js/import/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
}
}

Expand Down
8 changes: 8 additions & 0 deletions js/objects/layoutObjects.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,11 @@ export function LayoutDataTablePage() {
/** @type {Array<LayoutDataTable>} */
this.tables = [];
}

const layout = {
LayoutDataColumn,
LayoutDataTable,
LayoutRegion,
};

export default layout;
5 changes: 4 additions & 1 deletion module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -157,13 +158,15 @@ export default {
combineOCRPage,
compareOCR,
data,
enableFontOpt,
evalOCRPage,
exportData,
download,
importFiles,
importFilesSupp,
inputData,
init,
layout,
opt,
recognize,
recognizePage,
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 30552e7

Please sign in to comment.