| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @fileoverview JavaScript shim for the liblouis Native Client wrapper. | 6 * @fileoverview JavaScript shim for the liblouis Native Client wrapper. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 goog.provide('cvox.LibLouis'); | 9 goog.provide('cvox.LibLouis'); |
| 10 | 10 goog.provide('cvox.LibLouis.FormType'); |
| 11 | 11 |
| 12 /** | 12 /** |
| 13 * Encapsulates a liblouis Native Client instance in the page. | 13 * Encapsulates a liblouis Native Client instance in the page. |
| 14 * @constructor | 14 * @constructor |
| 15 * @param {string} nmfPath Path to .nmf file for the module. | 15 * @param {string} nmfPath Path to .nmf file for the module. |
| 16 * @param {string=} opt_tablesDir Path to tables directory. | 16 * @param {string=} opt_tablesDir Path to tables directory. |
| 17 */ | 17 */ |
| 18 cvox.LibLouis = function(nmfPath, opt_tablesDir) { | 18 cvox.LibLouis = function(nmfPath, opt_tablesDir) { |
| 19 /** | 19 /** |
| 20 * Path to .nmf file for the module. | 20 * Path to .nmf file for the module. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 43 | 43 |
| 44 /** | 44 /** |
| 45 * Next message ID to be used. Incremented with each sent message. | 45 * Next message ID to be used. Incremented with each sent message. |
| 46 * @private {number} | 46 * @private {number} |
| 47 */ | 47 */ |
| 48 this.nextMessageId_ = 1; | 48 this.nextMessageId_ = 1; |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 | 51 |
| 52 /** | 52 /** |
| 53 * Constants taken from liblouis.h. |
| 54 * Controls braille indicator insertion during translation. |
| 55 * @enum {number} |
| 56 */ |
| 57 cvox.LibLouis.FormType = { |
| 58 PLAIN_TEXT: 0, |
| 59 ITALIC: 1, |
| 60 UNDERLINE: 2, |
| 61 BOLD: 4, |
| 62 COMPUTER_BRAILLE: 8 |
| 63 }; |
| 64 |
| 65 |
| 66 /** |
| 53 * Set to {@code true} to enable debug logging of RPC messages. | 67 * Set to {@code true} to enable debug logging of RPC messages. |
| 54 * @type {boolean} | 68 * @type {boolean} |
| 55 */ | 69 */ |
| 56 cvox.LibLouis.DEBUG = false; | 70 cvox.LibLouis.DEBUG = false; |
| 57 | 71 |
| 58 | 72 |
| 59 /** | 73 /** |
| 60 * Attaches the Native Client wrapper to the DOM as a child of the provided | 74 * Attaches the Native Client wrapper to the DOM as a child of the provided |
| 61 * element, assumed to already be in the document. | 75 * element, assumed to already be in the document. |
| 62 * @param {!Element} elem Desired parent element of the instance. | 76 * @param {!Element} elem Desired parent element of the instance. |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 | 246 |
| 233 /** | 247 /** |
| 234 * Translates text into braille cells. | 248 * Translates text into braille cells. |
| 235 * @param {string} text Text to be translated. | 249 * @param {string} text Text to be translated. |
| 236 * @param {function(ArrayBuffer, Array<number>, Array<number>)} callback | 250 * @param {function(ArrayBuffer, Array<number>, Array<number>)} callback |
| 237 * Callback for result. Takes 3 parameters: the resulting cells, | 251 * Callback for result. Takes 3 parameters: the resulting cells, |
| 238 * mapping from text to braille positions and mapping from braille to | 252 * mapping from text to braille positions and mapping from braille to |
| 239 * text positions. If translation fails for any reason, all parameters are | 253 * text positions. If translation fails for any reason, all parameters are |
| 240 * {@code null}. | 254 * {@code null}. |
| 241 */ | 255 */ |
| 242 cvox.LibLouis.Translator.prototype.translate = function(text, callback) { | 256 cvox.LibLouis.Translator.prototype.translate = function( |
| 257 text, formTypeMap, callback) { |
| 243 if (!this.instance_.isAttached()) { | 258 if (!this.instance_.isAttached()) { |
| 244 callback(null /*cells*/, null /*textToBraille*/, null /*brailleToText*/); | 259 callback(null /*cells*/, null /*textToBraille*/, null /*brailleToText*/); |
| 245 return; | 260 return; |
| 246 } | 261 } |
| 247 var message = {'table_names': this.tableNames_, 'text': text}; | 262 var message = { |
| 263 'table_names': this.tableNames_, |
| 264 'text': text, |
| 265 form_type_map: formTypeMap |
| 266 }; |
| 248 this.instance_.rpc_('Translate', message, function(reply) { | 267 this.instance_.rpc_('Translate', message, function(reply) { |
| 249 var cells = null; | 268 var cells = null; |
| 250 var textToBraille = null; | 269 var textToBraille = null; |
| 251 var brailleToText = null; | 270 var brailleToText = null; |
| 252 if (reply['success'] && goog.isString(reply['cells'])) { | 271 if (reply['success'] && goog.isString(reply['cells'])) { |
| 253 cells = cvox.LibLouis.Translator.decodeHexString_(reply['cells']); | 272 cells = cvox.LibLouis.Translator.decodeHexString_(reply['cells']); |
| 254 if (goog.isDef(reply['text_to_braille'])) { | 273 if (goog.isDef(reply['text_to_braille'])) { |
| 255 textToBraille = reply['text_to_braille']; | 274 textToBraille = reply['text_to_braille']; |
| 256 } | 275 } |
| 257 if (goog.isDef(reply['braille_to_text'])) { | 276 if (goog.isDef(reply['braille_to_text'])) { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 */ | 343 */ |
| 325 cvox.LibLouis.Translator.encodeHexString_ = function(arrayBuffer) { | 344 cvox.LibLouis.Translator.encodeHexString_ = function(arrayBuffer) { |
| 326 var array = new Uint8Array(arrayBuffer); | 345 var array = new Uint8Array(arrayBuffer); |
| 327 var hex = ''; | 346 var hex = ''; |
| 328 for (var i = 0; i < array.length; i++) { | 347 for (var i = 0; i < array.length; i++) { |
| 329 var b = array[i]; | 348 var b = array[i]; |
| 330 hex += (b < 0x10 ? '0' : '') + b.toString(16); | 349 hex += (b < 0x10 ? '0' : '') + b.toString(16); |
| 331 } | 350 } |
| 332 return hex; | 351 return hex; |
| 333 }; | 352 }; |
| OLD | NEW |