Ejemplo n.º 1
0
 def check_translate(self):
     if self.cursorPos is not None:
         brl, temp1, temp2, brlCursorPos = translate(self.tables, self.input, mode=self.mode, cursorPos=self.cursorPos)
     elif self.typeform is not None:
         brl, temp1, temp2, brlCursorPos = translate(self.tables, self.input, mode=self.mode, typeform=self.typeform)
     else:
         brl, temp1, temp2, brlCursorPos = translate(self.tables, self.input, mode=self.mode)
     assert brl == self.expected, self.report_error("Braille Difference", brl)
Ejemplo n.º 2
0
 def check_translate(self):
     if self.cursorPos is not None:
         brl, temp1, temp2, brlCursorPos = translate(self.tables, self.input, mode=self.mode, cursorPos=self.cursorPos)
     elif self.typeform is not None:
         brl, temp1, temp2, brlCursorPos = translate(self.tables, self.input, mode=self.mode, typeform=self.typeform)
     else:
         brl, temp1, temp2, brlCursorPos = translate(self.tables, self.input, mode=self.mode)
     try:
         assert brl == self.expected, self.report_error("Braille Difference", brl)
     except AssertionError, e:
         raise SkipTest if self.xfail else e
Ejemplo n.º 3
0
 def check_translate_and_cursor(self):
     brl, temp1, temp2, brlCursorPos = translate(self.tables, self.input, mode=self.mode, cursorPos=self.cursorPos)
     try:
         assert brl == self.expected, self.report_error("Braille Difference", brl)
         assert brlCursorPos == self.expectedBrlCursorPos, self.report_error("Braille Cursor Difference", brl, brlCursorPos=brlCursorPos)
     except AssertionError, e:
         raise SkipTest if self.xfail else e
Ejemplo n.º 4
0
 def check_translate(self):
     if self.cursorPos is not None:
         tBrl, temp1, temp2, tBrlCurPos = translate(self.tables, self.input, mode=self.mode, cursorPos=self.cursorPos)
     else:
         tBrl, temp1, temp2, tBrlCurPos = translate(self.tables, self.input, mode=self.mode)
     template = "%-25s '%s'"
     tBrlCurPosStr = showCurPos(len(tBrl), tBrlCurPos)
     report = [
         "--- Braille Difference Failure: %s ---" % self.__str__(),
         template % ("comment:", "".join(self.comment)),
         template % ("input:", self.input),
         template % ("expected brl:", self.expectedOutput),
         template % ("actual brl:", tBrl),
         "--- end ---",
     ]
     assert tBrl == self.expectedOutput, u("\n".join(report))
Ejemplo n.º 5
0
	def update(self):
		"""Update this region.
		Subclasses should extend this to update L{rawText} and L{cursorPos} if necessary.
		The base class method handles translation of L{rawText} into braille, placing the result in L{brailleCells}. L{rawToBraillePos} and L{brailleToRawPos} are updated according to the translation.
		L{brailleCursorPos} is similarly updated based on L{cursorPos}.
		@postcondition: L{brailleCells} and L{brailleCursorPos} are updated and ready for rendering.
		"""
		mode = louis.dotsIO | louis.pass1Only
		if config.conf["braille"]["expandAtCursor"] and self.cursorPos is not None:
			mode |= louis.compbrlAtCursor
		text=unicode(self.rawText).replace('\0','')
		braille, self.brailleToRawPos, self.rawToBraillePos, brailleCursorPos = louis.translate([os.path.join(TABLES_DIR, config.conf["braille"]["translationTable"])], text, mode=mode, cursorPos=self.cursorPos or 0)
		# liblouis gives us back a character string of cells, so convert it to a list of ints.
		# For some reason, the highest bit is set, so only grab the lower 8 bits.
		self.brailleCells = [ord(cell) & 255 for cell in braille]
		# HACK: Work around a liblouis bug whereby an empty braille translation is returned.
		if not self.brailleCells:
			# Just provide a space.
			self.brailleCells.append(0)
			self.brailleToRawPos.append(0)
		if self.cursorPos is not None:
			# HACK: Work around a liblouis bug whereby the returned cursor position is not within the braille cells returned.
			if brailleCursorPos >= len(self.brailleCells):
				brailleCursorPos = len(self.brailleCells) - 1
			self.brailleCursorPos = brailleCursorPos
Ejemplo n.º 6
0
 def check_translate(self):
     if self.cursorPos is not None:
         tBrl, temp1, temp2, tBrlCurPos = translate(
             self.tables,
             self.input,
             mode=self.mode,
             cursorPos=self.cursorPos)
     else:
         tBrl, temp1, temp2, tBrlCurPos = translate(self.tables,
                                                    self.input,
                                                    mode=self.mode)
     template = "%-25s '%s'"
     tBrlCurPosStr = showCurPos(len(tBrl), tBrlCurPos)
     report = [
         "--- Braille Difference Failure: %s ---" % self.__str__(),
         template % ("input:", self.input),
         template % ("expected brl:", self.expectedOutput),
         template % ("actual brl:", tBrl),
         "--- end ---",
     ]
     assert tBrl == self.expectedOutput, u("\n".join(report))
Ejemplo n.º 7
0
 def check_cursor(self):
     tBrl, temp1, temp2, tBrlCurPos = translate(self.tables, self.input, mode=self.mode, cursorPos=self.cursorPos)
     template = "%-25s '%s'"
     etBrlCurPosStr = showCurPos(len(tBrl), tBrlCurPos, pos2=self.expectedBrlCursorPos)
     report = [
         "--- Braille Cursor Difference Failure: %s ---" %self.__str__(),
         template % ("comment:", "".join(self.comment)),
         template % ("input:", self.input),
         template % ("received brl:", tBrl),
         template % ("BRLCursorAt %d expected %d:" %(tBrlCurPos, self.expectedBrlCursorPos), 
                     etBrlCurPosStr),
         "--- end ---"
     ]
     assert tBrlCurPos == self.expectedBrlCursorPos, u("\n".join(report))
Ejemplo n.º 8
0
def translate(ctx, str, translation_table, emphasis=None):
    global nodeName
    
    try:
        pctxt = libxslt.xpathParserContext(_obj=ctx)
        ctxt = pctxt.context()
        tctxt = ctxt.transformContext()
        nodeName = tctxt.insertNode().name
    except:
        pass

    typeform = len(str)*[emphasisMap[emphasis]] if emphasis else None
    braille = louis.translate([translation_table], str.decode('utf-8'), typeform=typeform)[0]
    return braille.encode('utf-8')
Ejemplo n.º 9
0
def translate(ctx, str, translation_table, emphasis=None):
    global nodeName

    try:
        pctxt = libxslt.xpathParserContext(_obj=ctx)
        ctxt = pctxt.context()
        tctxt = ctxt.transformContext()
        nodeName = tctxt.insertNode().name
    except:
        pass

    typeform = len(str) * [emphasisMap[emphasis]] if emphasis else None
    braille = louis.translate([translation_table],
                              str.decode('utf-8'),
                              typeform=typeform)[0]
    return braille.encode('utf-8')
Ejemplo n.º 10
0
def text2uni(text, regularSpace=False):
    """Convert text to Unicode braille
	@param text: the text to convert
	@param regularSpace boolean if True, space will be replaced by a regular one instead of the braille space
	@return the result in Unicode
	"""
    text = text_type(text).replace('\0', '')
    text = louis.translate([
        os.path.join(brailleTables.TABLES_DIR,
                     config.conf['braille']['inputTable']),
        'braille-patterns.cti'
    ],
                           text,
                           mode=louis.dotsIO)[0]
    out = "".join(conv(0x2800 | ord(cell) & 255) for cell in text)
    if regularSpace:
        out = out.replace(u'\u2800', ' ')
    return out
Ejemplo n.º 11
0
 def check_cursor(self):
     tBrl, temp1, temp2, tBrlCurPos = translate(self.tables,
                                                self.input,
                                                mode=self.mode,
                                                cursorPos=self.cursorPos)
     template = "%-25s '%s'"
     etBrlCurPosStr = showCurPos(len(tBrl),
                                 tBrlCurPos,
                                 pos2=self.expectedBrlCursorPos)
     report = [
         "--- Braille Cursor Difference Failure: %s ---" % self.__str__(),
         template % ("input:", self.input),
         template % ("received brl:", tBrl), template %
         ("BRLCursorAt %d expected %d:" %
          (tBrlCurPos, self.expectedBrlCursorPos), etBrlCurPosStr),
         "--- end ---"
     ]
     assert tBrlCurPos == self.expectedBrlCursorPos, u("\n".join(report))
Ejemplo n.º 12
0
def translate(tableList, inbuf, typeform=None, cursorPos=None, mode=0):
    """
	Convenience wrapper for louis.translate that:
	* returns a list of integers instead of a string with cells, and
	* distinguishes between cursor position 0 (cursor at first character) and None (no cursor at all)
	"""
    text = inbuf.replace('\0', '')
    braille, brailleToRawPos, rawToBraillePos, brailleCursorPos = louis.translate(
        tableList,
        text,
        # liblouis mutates typeform if it is a list.
        typeform=tuple(typeform) if isinstance(typeform, list) else typeform,
        cursorPos=cursorPos or 0,
        mode=mode)
    # liblouis gives us back a character string of cells, so convert it to a list of ints.
    # For some reason, the highest bit is set, so only grab the lower 8 bits.
    braille = [ord(cell) & 255 for cell in braille]
    if cursorPos is None:
        brailleCursorPos = None
    return braille, brailleToRawPos, rawToBraillePos, brailleCursorPos
Ejemplo n.º 13
0
def translate(tableList, inbuf, typeform=None, cursorPos=None, mode=0):
	"""
	Convenience wrapper for louis.translate that:
	* returns a list of integers instead of an string with cells, and
	* distinguishes between cursor position 0 (cursor at first character) and None (no cursor at all)
	"""
	text = unicode(inbuf).replace('\0','')
	braille, brailleToRawPos, rawToBraillePos, brailleCursorPos = louis.translate(
		tableList,
		text,
		# liblouis mutates typeform if it is a list.
		typeform=tuple(typeform) if isinstance(typeform, list) else typeform,
		cursorPos=cursorPos or 0,
		mode=mode
	)
	# liblouis gives us back a character string of cells, so convert it to a list of ints.
	# For some reason, the highest bit is set, so only grab the lower 8 bits.
	braille = [ord(cell) & 255 for cell in braille]
	if cursorPos is None:
		brailleCursorPos = None
	return braille, brailleToRawPos, rawToBraillePos, brailleCursorPos
Ejemplo n.º 14
0
def update(self):
    """Update this region.
	Subclasses should extend this to update L{rawText}, L{cursorPos}, L{selectionStart} and L{selectionEnd} if necessary.
	The base class method handles translation of L{rawText} into braille, placing the result in L{brailleCells}.
	Typeform information from L{rawTextTypeforms} is used, if any.
	L{rawToBraillePos} and L{brailleToRawPos} are updated according to the translation.
	L{brailleCursorPos}, L{brailleSelectionStart} and L{brailleSelectionEnd} are similarly updated based on L{cursorPos}, L{selectionStart} and L{selectionEnd}, respectively.
	@postcondition: L{brailleCells}, L{brailleCursorPos}, L{brailleSelectionStart} and L{brailleSelectionEnd} are updated and ready for rendering.
	"""
    try:
        mode = louis.dotsIO
        if config.conf["braille"][
                "expandAtCursor"] and self.cursorPos is not None:
            mode |= louis.compbrlAtCursor
        try:
            text = unicode(self.rawText).replace('\0', '')
            braille, self.brailleToRawPos, self.rawToBraillePos, brailleCursorPos = louis.translate(
                configBE.preTable + [
                    os.path.join(brailleTables.TABLES_DIR,
                                 config.conf["braille"]["translationTable"]),
                    os.path.join(brailleTables.TABLES_DIR,
                                 "braille-patterns.cti")
                ] + configBE.postTable,
                text,
                # liblouis mutates typeform if it is a list.
                typeform=tuple(self.rawTextTypeforms) if isinstance(
                    self.rawTextTypeforms, list) else self.rawTextTypeforms,
                mode=mode,
                cursorPos=self.cursorPos or 0)
        except BaseException:
            if len(configBE.postTable) == 0:
                log.error(
                    "Error with update braille function patch, disabling: %s")
                braille.Region.update = backupUpdate
                core.restart()
                return
            log.warning(
                'Unable to translate with secondary table: %s and %s.' %
                (config.conf["braille"]["translationTable"],
                 configBE.postTable))
            configBE.postTable = []
            config.conf["brailleExtender"]["postTable"] = "None"
            update(self)
            return
        # liblouis gives us back a character string of cells, so convert it to a list of ints.
        # For some reason, the highest bit is set, so only grab the lower 8
        # bits.
        self.brailleCells = [ord(cell) & 255 for cell in braille]
        # #2466: HACK: liblouis incorrectly truncates trailing spaces from its output in some cases.
        # Detect this and add the spaces to the end of the output.
        if self.rawText and self.rawText[-1] == " ":
            # rawToBraillePos isn't truncated, even though brailleCells is.
            # Use this to figure out how long brailleCells should be and thus
            # how many spaces to add.
            correctCellsLen = self.rawToBraillePos[-1] + 1
            currentCellsLen = len(self.brailleCells)
            if correctCellsLen > currentCellsLen:
                self.brailleCells.extend(
                    (0, ) * (correctCellsLen - currentCellsLen))
        if self.cursorPos is not None:
            # HACK: The cursorPos returned by liblouis is notoriously buggy (#2947 among other issues).
            # rawToBraillePos is usually accurate.
            try:
                brailleCursorPos = self.rawToBraillePos[self.cursorPos]
            except IndexError:
                pass
        else:
            brailleCursorPos = None
        self.brailleCursorPos = brailleCursorPos
        if self.selectionStart is not None and self.selectionEnd is not None:
            try:
                # Mark the selection.
                self.brailleSelectionStart = self.rawToBraillePos[
                    self.selectionStart]
                if self.selectionEnd >= len(self.rawText):
                    self.brailleSelectionEnd = len(self.brailleCells)
                else:
                    self.brailleSelectionEnd = self.rawToBraillePos[
                        self.selectionEnd]
                for pos in xrange(self.brailleSelectionStart,
                                  self.brailleSelectionEnd):
                    self.brailleCells[pos] |= SELECTION_SHAPE()
            except IndexError:
                pass
        else:
            if instanceGP.hideDots78:
                for i, j in enumerate(self.brailleCells):
                    self.brailleCells[i] &= 63
    except BaseException as e:
        log.error("Error with update braille patch, disabling: %s" % e)
        braille.Region.update = backupUpdate
Ejemplo n.º 15
0
 def cursor(self, txt, cursorPos):
     return louis.translate(self.tables,
                            txt,
                            cursorPos=cursorPos,
                            mode=louis.compbrlAtCursor)[0:4:3]
import louis

with open("braille_result1.txt", 'w') as braille_result1:
  print(louis.translate(["unicode.dis","en-chardefs.cti"], "abcdefghijklmnopqrstuvwxyz")[0], file=braille_result1)

with open("braille_result2.txt", 'w') as braille_result2:
  print(louis.translate(["unicode.dis","en-chardefs.cti"], "ABCDEFGHIJKLMNOPQRSTUVWXYZ")[0], file=braille_result2)

symbols = ' !"#$%()*+-./:;<=>?@[\]_{}~123456790'+"'" 
with open("braille_result3.txt", 'w') as braille_result3:
  print(louis.translate(["unicode.dis","en-chardefs.cti"], symbols)[0], file=braille_result3)
Ejemplo n.º 17
0
 def check_cursor(self):
     brl, temp1, temp2, brlCursorPos = translate(self.tables, self.input, mode=self.mode, cursorPos=self.cursorPos)
     assert brlCursorPos == self.expectedBrlCursorPos, self.report_error("Braille Cursor Difference", brl, brlCursorPos=brlCursorPos)
Ejemplo n.º 18
0
 def cursor(self, txt, cursorPos):
     return louis.translate(self.tables, txt, 
                            cursorPos=cursorPos, 
                            mode=louis.compbrlAtCursor)[0:4:3]
Ejemplo n.º 19
0
def update(self):
	"""Update this region.
	Subclasses should extend this to update L{rawText}, L{cursorPos}, L{selectionStart} and L{selectionEnd} if necessary.
	The base class method handles translation of L{rawText} into braille, placing the result in L{brailleCells}.
	Typeform information from L{rawTextTypeforms} is used, if any.
	L{rawToBraillePos} and L{brailleToRawPos} are updated according to the translation.
	L{brailleCursorPos}, L{brailleSelectionStart} and L{brailleSelectionEnd} are similarly updated based on L{cursorPos}, L{selectionStart} and L{selectionEnd}, respectively.
	@postcondition: L{brailleCells}, L{brailleCursorPos}, L{brailleSelectionStart} and L{brailleSelectionEnd} are updated and ready for rendering.
	"""
	try:
		mode = louis.dotsIO
		if config.conf["braille"]["expandAtCursor"] and self.cursorPos is not None: mode |= louis.compbrlAtCursor
		try:
			if isPy3:
				self.brailleCells, self.brailleToRawPos, self.rawToBraillePos, self.brailleCursorPos = louisHelper.translate(
					getCurrentBrailleTables(),
					self.rawText,
					typeform=self.rawTextTypeforms,
					mode=mode,
					cursorPos=self.cursorPos
				)
			else:
				text = unicode(self.rawText).replace('\0', '')
				braille, self.brailleToRawPos, self.rawToBraillePos, brailleCursorPos = louis.translate(getCurrentBrailleTables(),
					text,
					# liblouis mutates typeform if it is a list.
					typeform=tuple(
						self.rawTextTypeforms) if isinstance(
						self.rawTextTypeforms,
						list) else self.rawTextTypeforms,
					mode=mode,
					cursorPos=self.cursorPos or 0
				)
		except BaseException as e:
			global errorTable
			if not errorTable:
				log.error("Unable to translate with tables: %s\nDetails: %s" % (getCurrentBrailleTables(), e))
				errorTable = True
				if instanceGP.BRFMode: instanceGP.BRFMode = False
				instanceGP.errorMessage(_("An unexpected error was produced while using several braille tables. Using default settings to avoid other errors. More information in NVDA log. Thanks to report it."))
			return
		if not isPy3:
			# liblouis gives us back a character string of cells, so convert it to a list of ints.
			# For some reason, the highest bit is set, so only grab the lower 8
			# bits.
			self.brailleCells = [ord(cell) & 255 for cell in braille]
			# #2466: HACK: liblouis incorrectly truncates trailing spaces from its output in some cases.
			# Detect this and add the spaces to the end of the output.
			if self.rawText and self.rawText[-1] == " ":
				# rawToBraillePos isn't truncated, even though brailleCells is.
				# Use this to figure out how long brailleCells should be and thus
				# how many spaces to add.
				correctCellsLen = self.rawToBraillePos[-1] + 1
				currentCellsLen = len(self.brailleCells)
				if correctCellsLen > currentCellsLen:
					self.brailleCells.extend(
						(0,) * (correctCellsLen - currentCellsLen))
			if self.cursorPos is not None:
				# HACK: The cursorPos returned by liblouis is notoriously buggy (#2947 among other issues).
				# rawToBraillePos is usually accurate.
				try:
					brailleCursorPos = self.rawToBraillePos[self.cursorPos]
				except IndexError:
					pass
			else:
				brailleCursorPos = None
			self.brailleCursorPos = brailleCursorPos
		if self.selectionStart is not None and self.selectionEnd is not None:
			try:
				# Mark the selection.
				self.brailleSelectionStart = self.rawToBraillePos[self.selectionStart]
				if self.selectionEnd >= len(self.rawText):
					self.brailleSelectionEnd = len(self.brailleCells)
				else:
					self.brailleSelectionEnd = self.rawToBraillePos[self.selectionEnd]
				fn = range if isPy3 else xrange
				for pos in fn(self.brailleSelectionStart, self.brailleSelectionEnd):
					self.brailleCells[pos] |= SELECTION_SHAPE()
			except IndexError: pass
		else:
			if instanceGP.hideDots78:
				self.brailleCells = [(cell & 63) for cell in self.brailleCells]
	except BaseException as e:
		log.error("Error with update braille patch, disabling: %s" % e)
		errorTable = True
Ejemplo n.º 20
0
 def check_cursor(self):
     brl, temp1, temp2, brlCursorPos = translate(self.tables, self.input, mode=self.mode, cursorPos=self.cursorPos)
     assert brlCursorPos == self.expectedBrlCursorPos, self.report_error("Braille Cursor Difference", brl, brlCursorPos=brlCursorPos)
Ejemplo n.º 21
0
    # dont know name:
    u' க்ஷ ': ' q ',
    # test it with a full stop at the end.
    u'க்ஷ்.': '`q4',

    ## punctuation
    # left quote
    u'“': ',8',
    # right quote
    u'”': '0.',

    #left single quote
    u'‘': '8',
    #right single quote
    u'’': '0',
}

# note: if the test fails saying it cant find tables then:
# copy en-us-g1.ctb and chardefs.cti into this directory.
table = ['tamil.ctb']

for test in testHarness.keys():
    #test = test.decode('utf-8')
    braille = louis.translate(table, test, typeform=None)[0]
    if testHarness[test] == braille:
        print "ok"
    else:
        print "%s failed, got '%s' expected '%s'" % (test, braille,
                                                     testHarness[test])
Ejemplo n.º 22
0
 def check_translate(self):
     if self.cursorPos is not None:
         brl, temp1, temp2, brlCursorPos = translate(self.tables, self.input, mode=self.mode, cursorPos=self.cursorPos)
     else:
         brl, temp1, temp2, brlCursorPos = translate(self.tables, self.input, mode=self.mode)
     assert brl == self.expected, self.report_error("Braille Difference", brl)