works on iOS Safari

master
Kevin Kwok 8 years ago
parent acc2b835ce
commit 2b141f8aa5
  1. 3
      examples/file-input/demo.html
  2. 2
      src/browser/index.js
  3. 18
      src/browser/lang.js
  4. 3
      src/common/worker.js

@ -122,7 +122,10 @@ function recognizeFile(file){
<option value='ukr' > Ukrainian </option>
<option value='vie' > Vietnamese </option>
</select>
<button onclick="recognizeFile('../node/cosmic.png')">Sample Image</button>
<input type="file" onchange="recognizeFile(window.lastFile=this.files[0])">
<div id="log"></div>

@ -6,7 +6,7 @@ var defaultOptions = {
if (process.env.NODE_ENV === "development") {
console.debug('Using Development Configuration')
defaultOptions.workerPath = location.protocol + '//' + location.host + '/dist/worker.dev.js'
defaultOptions.workerPath = location.protocol + '//' + location.host + '/dist/worker.dev.js?nocache=' + Math.random().toString(36).slice(3)
}else{
var version = require('../../package.json').version;
defaultOptions.workerPath = 'https://cdn.rawgit.com/naptha/tesseract.js/' + version + '/dist/worker.js'

@ -1,5 +1,12 @@
const leveljs = require('level-js')
var db = typeof indexedDB === 'undefined' ? { open: (_, cb) => cb(true) } : leveljs('./tessdata2')
// something about trying to store these language files in indexedDB
// causes iOS Safari to crash
var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent);
var noIDB = typeof indexedDB === 'undefined' || iOS;
var db = noIDB ? { open: (_, cb) => cb(true) } : leveljs('./tessdata2')
var langdata = require('../common/langdata.json')
@ -45,15 +52,20 @@ function fetchLanguageData(req, res, cb){
xhr.onload = e => {
if (!(xhr.status == 200 || (xhr.status == 0 && xhr.response))) return res.reject('Error downloading language ' + url);
res.progress({ status: 'unzipping ' + langfile })
res.progress({ status: 'unzipping ' + langfile, progress: 0 })
// in case the gzips are already ungzipped or extra gzipped
var response = new Uint8Array(xhr.response)
try {
while(response[0] == 0x1f && response[1] == 0x8b) response = ungzip(response);
var n = 2;
while(response[0] == 0x1f && response[1] == 0x8b){
response = ungzip(response);
res.progress({ status: 'unzipping ' + langfile, progress: 1 - 1 / (n++) })
}
} catch (err) {
return res.reject('Error unzipping language file ' + langfile + '\n' + err.message)
}
res.progress({ status: 'unzipping ' + langfile, progress: 1 })
cb(response)
}

@ -85,9 +85,10 @@ function loadLanguage(req, res, cb){
if(lang in Module._loadedLanguages) return cb();
adapter.getLanguageData(req, res, function(data){
res.progress({ status: 'loading ' + lang + '.traineddata', progress: 0 })
Module.FS_createDataFile('tessdata', lang + ".traineddata", data, true, false);
res.progress({ status: 'loading ' + lang + '.traineddata', progress: 1 })
Module._loadedLanguages[lang] = true;
res.progress({ status: 'loading ' + lang + '.traineddata', progress: 1 })
cb()
})
}

Loading…
Cancel
Save