示例#1
0
	def getTextWithFields(self,formatConfig=None):
		if not formatConfig:
			formatConfig=config.conf['documentFormatting']
		formatConfig['autoLanguageSwitching']=config.conf['speech'].get('autoLanguageSwitching',False)
		startOffset=self._rangeObj.start
		endOffset=self._rangeObj.end
		if startOffset==endOffset:
			return []
		text=BSTR()
		formatConfigFlags=sum(y for x,y in formatConfigFlagsMap.iteritems() if formatConfig.get(x,False))
		res=NVDAHelper.localLib.nvdaInProcUtils_winword_getTextInRange(self.obj.appModule.helperLocalBindingHandle,self.obj.windowHandle,startOffset,endOffset,formatConfigFlags,ctypes.byref(text))
		if res or not text:
			log.debugWarning("winword_getTextInRange failed with %d"%res)
			return [self.text]
		commandList=XMLFormatting.XMLTextParser().parse(text.value)
		for index,item in enumerate(commandList):
			if isinstance(item,textInfos.FieldCommand):
				field=item.field
				if isinstance(field,textInfos.ControlField):
					item.field=self._normalizeControlField(field)
				elif isinstance(field,textInfos.FormatField):
					item.field=self._normalizeFormatField(field)
			elif index>0 and isinstance(item,basestring) and item.isspace():
				 #2047: don't expose language for whitespace as its incorrect for east-asian languages 
				lastItem=commandList[index-1]
				if isinstance(lastItem,textInfos.FieldCommand) and isinstance(lastItem.field,textInfos.FormatField):
					try:
						del lastItem.field['language']
					except KeyError:
						pass
		return commandList
示例#2
0
	def _get__storyFieldsAndRects(self):
		# All returned coordinates are logical coordinates.
		if self._location:
			left, top, right, bottom = self._location
		else:
			try:
				left, top, width, height = self.obj.location
			except TypeError:
				# No location; nothing we can do.
				return [],[],[]
			right = left + width
			bottom = top + height
		bindingHandle=self.obj.appModule.helperLocalBindingHandle
		if not bindingHandle:
			log.debugWarning("AppModule does not have a binding handle")
			return [],[],[]
		left,top=windowUtils.physicalToLogicalPoint(self.obj.windowHandle,left,top)
		right,bottom=windowUtils.physicalToLogicalPoint(self.obj.windowHandle,right,bottom)
		text,rects=getWindowTextInRect(bindingHandle, self.obj.windowHandle, left, top, right, bottom, self.minHorizontalWhitespace, self.minVerticalWhitespace,self.stripOuterWhitespace,self.includeDescendantWindows)
		if not text:
			return [],[],[]
		text="<control>%s</control>"%text
		commandList=XMLFormatting.XMLTextParser().parse(text)
		curFormatField=None
		lastEndOffset=0
		lineStartOffset=0
		lineStartIndex=0
		lineBaseline=None
		lineEndOffsets=[]
		for index in range(len(commandList)):
			item=commandList[index]
			if isinstance(item,str):
				lastEndOffset += textUtils.WideStringOffsetConverter(item).wideStringLength
			elif isinstance(item,textInfos.FieldCommand):
				if isinstance(item.field,textInfos.FormatField):
					curFormatField=item.field
					self._normalizeFormatField(curFormatField)
				else:
					curFormatField=None
				baseline=curFormatField['baseline'] if curFormatField  else None
				if baseline!=lineBaseline:
					if lineBaseline is not None:
						processWindowChunksInLine(commandList,rects,lineStartIndex,lineStartOffset,index,lastEndOffset)
						#Convert the whitespace at the end of the line into a line feed
						item=commandList[index-1]
						if (
							isinstance(item,str)
							# Since we're searching for white space, it is safe to
							# do this opperation on the length of the pythonic string
							and len(item)==1
							and item.isspace()
						):
							commandList[index-1]=u'\n'
						lineEndOffsets.append(lastEndOffset)
					if baseline is not None:
						lineStartIndex=index
						lineStartOffset=lastEndOffset
						lineBaseline=baseline
		return commandList,rects,lineEndOffsets
示例#3
0
	def _getFieldsInRange(self, start: int, end: int) -> textInfos.TextInfo.TextWithFieldsT:
		text=NVDAHelper.VBuf_getTextInRange(self.obj.VBufHandle,start,end,True)
		if not text:
			return [""]
		commandList = XMLFormatting.XMLTextParser().parse(text)
		commandList = [
			self._normalizeCommand(command)
			for command in commandList
			# drop None to convert from XMLFormatting.CommandListT to textInfos.TextInfo.TextWithFieldsT
			if command is not None
		]
		return commandList
	def _getFieldsInRange(self,start,end):
		text=NVDAHelper.VBuf_getTextInRange(self.obj.VBufHandle,start,end,True)
		if not text:
			return ""
		commandList=XMLFormatting.XMLTextParser().parse(text)
		for index in range(len(commandList)):
			if isinstance(commandList[index],textInfos.FieldCommand):
				field=commandList[index].field
				if isinstance(field,textInfos.ControlField):
					commandList[index].field=self._normalizeControlField(field)
				elif isinstance(field,textInfos.FormatField):
					commandList[index].field=self._normalizeFormatField(field)
		return commandList
示例#5
0
	def getTextWithFields(self,formatConfig=None):
		start=self._startOffset
		end=self._endOffset
		if start==end:
			return ""
		text=NVDAHelper.VBuf_getTextInRange(self.obj.VBufHandle,start,end,True)
		if not text:
			return ""
		commandList=XMLFormatting.XMLTextParser().parse(text)
		for index in xrange(len(commandList)):
			if isinstance(commandList[index],textInfos.FieldCommand):
				field=commandList[index].field
				if isinstance(field,textInfos.ControlField):
					commandList[index].field=self._normalizeControlField(field)
				elif isinstance(field,textInfos.FormatField):
					commandList[index].field=self._normalizeFormatField(field)
		return commandList
示例#6
0
    def _getFieldsInRange(self, start, end):
        text = NVDAHelper.VBuf_getTextInRange(self.obj.VBufHandle, start, end,
                                              True)
        if not text:
            return ""
        commandList: typing.List[
            textInfos.FieldCommand] = XMLFormatting.XMLTextParser().parse(text)
        for command in commandList:
            if not isinstance(command, textInfos.FieldCommand):
                continue  # no need to normalize str or None

            field = command.field
            if isinstance(field, textInfos.ControlField):
                command.field = self._normalizeControlField(field)
            elif isinstance(field, textInfos.FormatField):
                command.field = self._normalizeFormatField(field)
        return commandList
示例#7
0
 def getTextWithFields(self, formatConfig=None):
     start = self._startOffset
     end = self._endOffset
     if start == end:
         return u""
     text = self._get__textAndRects(useXML=True)[0]
     if not text:
         return u""
     text = "<control>%s</control>" % text
     commandList = XMLFormatting.XMLTextParser().parse(text)
     #Strip  unwanted commands and text from the start and the end to honour the requested offsets
     stringOffset = 0
     for index in xrange(len(commandList) - 1):
         command = commandList[index]
         if isinstance(command, basestring):
             stringLen = len(command)
             if (stringOffset + stringLen) <= start:
                 stringOffset += stringLen
             else:
                 del commandList[1:index - 1]
                 commandList[2] = command[start - stringOffset:]
                 break
     end = end - start
     stringOffset = 0
     for index in xrange(1, len(commandList) - 1):
         command = commandList[index]
         if isinstance(command, basestring):
             stringLen = len(command)
             if (stringOffset + stringLen) < end:
                 stringOffset += stringLen
             else:
                 commandList[index] = command[0:end - stringOffset]
                 del commandList[index + 1:-1]
                 break
     for item in commandList:
         if isinstance(item, textInfos.FieldCommand) and isinstance(
                 item.field, textInfos.FormatField):
             self._normalizeFormatField(item.field)
     return commandList