Skip to content

Commit 15ed597

Browse files
authored
Removed various depreciated functions, including default parameters to fix #975 (#981)
1 parent 2f2b5e3 commit 15ed597

File tree

4 files changed

+1
-72
lines changed

4 files changed

+1
-72
lines changed

src/createWorker.js

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,6 @@ module.exports = async (langs = 'eng', oem = OEM.LSTM_ONLY, _options = {}, confi
104104
}))
105105
);
106106

107-
const loadLanguage = () => (
108-
console.warn('`loadLanguage` is depreciated and should be removed from code (workers now come with language pre-loaded)')
109-
);
110-
111107
const loadLanguageInternal = (_langs, jobId) => startJob(createJob({
112108
id: jobId,
113109
action: 'loadLanguage',
@@ -125,10 +121,6 @@ module.exports = async (langs = 'eng', oem = OEM.LSTM_ONLY, _options = {}, confi
125121
},
126122
}));
127123

128-
const initialize = () => (
129-
console.warn('`initialize` is depreciated and should be removed from code (workers now come pre-initialized)')
130-
);
131-
132124
const initializeInternal = (_langs, _oem, _config, jobId) => (
133125
startJob(createJob({
134126
id: jobId,
@@ -182,15 +174,6 @@ module.exports = async (langs = 'eng', oem = OEM.LSTM_ONLY, _options = {}, confi
182174
}))
183175
);
184176

185-
const getPDF = (title = 'Tesseract OCR Result', textonly = false, jobId) => {
186-
console.log('`getPDF` function is depreciated. `recognize` option `savePDF` should be used instead.');
187-
return startJob(createJob({
188-
id: jobId,
189-
action: 'getPDF',
190-
payload: { title, textonly },
191-
}));
192-
};
193-
194177
const detect = async (image, jobId) => {
195178
if (lstmOnlyCore) throw Error('`worker.detect` requires Legacy model, which was not loaded.');
196179

@@ -224,8 +207,6 @@ module.exports = async (langs = 'eng', oem = OEM.LSTM_ONLY, _options = {}, confi
224207
let d = data;
225208
if (action === 'recognize') {
226209
d = circularize(data);
227-
} else if (action === 'getPDF') {
228-
d = Array.from({ ...data, length: Object.keys(data).length });
229210
}
230211
promises[promiseId].resolve({ jobId, data: d });
231212
delete promises[promiseId];
@@ -251,12 +232,9 @@ module.exports = async (langs = 'eng', oem = OEM.LSTM_ONLY, _options = {}, confi
251232
readText,
252233
removeFile,
253234
FS,
254-
loadLanguage,
255-
initialize,
256235
reinitialize,
257236
setParameters,
258237
recognize,
259-
getPDF,
260238
detect,
261239
terminate,
262240
};

src/index.d.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ declare namespace Tesseract {
2626
recognize(image: ImageLike, options?: Partial<RecognizeOptions>, output?: Partial<OutputFormats>, jobId?: string): Promise<RecognizeResult>
2727
detect(image: ImageLike, jobId?: string): Promise<DetectResult>
2828
terminate(jobId?: string): Promise<ConfigResult>
29-
getPDF(title?: string, textonly?: boolean, jobId?: string):Promise<GetPDFResult>
3029
}
3130

3231
interface Lang {
@@ -71,11 +70,6 @@ declare namespace Tesseract {
7170
tessedit_char_blacklist: string
7271
preserve_interword_spaces: string
7372
user_defined_dpi: string
74-
tessjs_create_hocr: string
75-
tessjs_create_tsv: string
76-
tessjs_create_box: string
77-
tessjs_create_unlv: string
78-
tessjs_create_osd: string
7973
[propName: string]: any
8074
}
8175
interface OutputFormats {
@@ -108,10 +102,6 @@ declare namespace Tesseract {
108102
jobId: string
109103
data: Page
110104
}
111-
interface GetPDFResult {
112-
jobId: string
113-
data: number[]
114-
}
115105
interface DetectResult {
116106
jobId: string
117107
data: DetectData

src/worker-script/constants/defaultParams.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/worker-script/index.js

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const isURL = require('is-url');
1212
const dump = require('./utils/dump');
1313
const env = require('../utils/getEnvironment')('type');
1414
const setImage = require('./utils/setImage');
15-
const defaultParams = require('./constants/defaultParams');
1615
const defaultOutput = require('./constants/defaultOutput');
1716
const { log, setLogging } = require('../utils/log');
1817
const PSM = require('../constants/PSM');
@@ -27,7 +26,7 @@ let TessModule;
2726
let api = null;
2827
let latestJob;
2928
let adapter = {};
30-
let params = defaultParams;
29+
let params = {};
3130
let loadLanguageLangsWorker;
3231
let loadLanguageOptionsWorker;
3332
let dataFromCache = false;
@@ -305,8 +304,6 @@ const initialize = async ({
305304
res.reject('initialization failed');
306305
}
307306

308-
params = defaultParams;
309-
await setParameters({ payload: { params } });
310307
res.progress({
311308
workerId, status: statusText, progress: 1,
312309
});
@@ -316,31 +313,10 @@ const initialize = async ({
316313
}
317314
};
318315

319-
const getPDFInternal = (title, textonly) => {
320-
const pdfRenderer = new TessModule.TessPDFRenderer('tesseract-ocr', '/', textonly);
321-
pdfRenderer.BeginDocument(title);
322-
pdfRenderer.AddImage(api);
323-
pdfRenderer.EndDocument();
324-
TessModule._free(pdfRenderer);
325-
326-
return TessModule.FS.readFile('/tesseract-ocr.pdf');
327-
};
328-
329-
const getPDF = async ({ payload: { title, textonly } }, res) => {
330-
res.resolve(getPDFInternal(title, textonly));
331-
};
332-
333316
// Combines default output with user-specified options and
334317
// counts (1) total output formats requested and (2) outputs that require OCR
335318
const processOutput = (output) => {
336319
const workingOutput = JSON.parse(JSON.stringify(defaultOutput));
337-
// Output formats were set using `setParameters` in previous versions
338-
// These settings are copied over for compatability
339-
if (params.tessjs_create_box === '1') workingOutput.box = true;
340-
if (params.tessjs_create_hocr === '1') workingOutput.hocr = true;
341-
if (params.tessjs_create_osd === '1') workingOutput.osd = true;
342-
if (params.tessjs_create_tsv === '1') workingOutput.tsv = true;
343-
if (params.tessjs_create_unlv === '1') workingOutput.unlv = true;
344320

345321
const nonRecOutputs = ['imageColor', 'imageGrey', 'imageBinary', 'layoutBlocks', 'debug'];
346322
let recOutputCount = 0;
@@ -546,7 +522,6 @@ exports.dispatchHandlers = (packet, send) => {
546522
initialize,
547523
setParameters,
548524
recognize,
549-
getPDF,
550525
detect,
551526
terminate,
552527
})[packet.action](packet, res)

0 commit comments

Comments
 (0)