示例#1
0
    def _getTableDimensions(self, info: textInfos.TextInfo) -> Tuple[int, int]:
        """
		Fetches information about the deepest table dimension.
		@param info:  the position where the table cell should be looked for.
		@returns: a tuple of table height and width.
		@raises: LookupError if there is no table cell at this position.
		"""
        if info.isCollapsed:
            info = info.copy()
            info.expand(textInfos.UNIT_CHARACTER)
        fields = list(info.getTextWithFields())
        layoutIDs = self._maybeGetLayoutTableIds(info)
        for field in reversed(fields):
            if not (isinstance(field, textInfos.FieldCommand)
                    and field.command == "controlStart"
                    and field.field.get("role") == controlTypes.Role.TABLE):
                # Not a table control field.
                continue
            attrs = field.field
            tableID = attrs.get('table-id')
            if tableID is None or tableID in layoutIDs:
                continue
            break
        else:
            raise LookupError("Not in a table cell")
        try:
            nRows = int(attrs.get("table-rowcount"))
            nCols = int(attrs.get("table-columncount"))
        except (TypeError, ValueError):
            raise LookupError("Not in a table cell")
        return (nRows, nCols)
示例#2
0
    def _getTableCellCoords(
        self,
        info: textInfos.TextInfo,
    ) -> _TableCell:
        """
		Fetches information about the deepest table cell at the given position.
		@param info:  the position where the table cell should be looked for.
		@returns: Information about requested cell.
		@raises: LookupError if there is no table cell at this position.
		"""
        if info.isCollapsed:
            info = info.copy()
            info.expand(textInfos.UNIT_CHARACTER)
        fields = list(info.getTextWithFields())
        layoutIDs = self._maybeGetLayoutTableIds(info)
        for field in reversed(fields):
            if not (isinstance(field, textInfos.FieldCommand)
                    and field.command == "controlStart"):
                # Not a control field.
                continue
            attrs = field.field
            tableID = attrs.get('table-id')
            if tableID is None or tableID in layoutIDs:
                continue
            if "table-columnnumber" in attrs and not attrs.get('table-layout'):
                break
        else:
            raise LookupError("Not in a table cell")
        return _TableCell(
            attrs["table-id"],
            attrs["table-rownumber"],
            attrs["table-columnnumber"],
            attrs.get("table-rowsspanned", 1),
            attrs.get("table-columnsspanned", 1),
        )
示例#3
0
文件: util.py 项目: larry801/nvda
def getRectFromTextInfo(textInfo: textInfos.TextInfo) -> locationHelper.RectLTRB:
	if textInfo.isCollapsed:
		textInfo.expand(textInfos.UNIT_CHARACTER)
	try:
		rects = textInfo.boundingRects
	except NotImplementedError:
		rects = None
	if rects:
		index = 0 if textInfo.obj.isTextSelectionAnchoredAtStart else -1
		rect = rects[index].toLTRB()
	else:
		rect = locationHelper.RectLTRB.fromPoint(textInfo.pointAtStart)
	return rect
示例#4
0
def getMathMlFromTextInfo(pos: textInfos.TextInfo) -> Optional[str]:
    """Get MathML (if any) at the start of a TextInfo.
	@param pos: The TextInfo in question.
	@return: The MathML or C{None} if there is no math.
	"""
    pos = pos.copy()
    pos.expand(textInfos.UNIT_CHARACTER)
    for item in reversed(pos.getTextWithFields()):
        if not isinstance(
                item,
                textInfos.FieldCommand) or item.command != "controlStart":
            continue
        field = item.field
        if field.get("role") != controlTypes.Role.MATH:
            continue
        try:
            return pos.getMathMl(field)
        except (NotImplementedError, LookupError):
            continue
    return None
示例#5
0
    def _maybeGetLayoutTableIds(self, info: textInfos.TextInfo):
        """
		If "Include layout tables" option is on, this will
		compute the set of layout tables that this textInfo is enclosed in,
		otherwise it will return empty set.
		@param info:  the position where the layout tables should be looked for.
		@returns: A set of table IDs or empty set.
		"""
        fields = list(info.getTextWithFields())
        # If layout tables should not be reported, we should First record the ID of all layout tables,
        # so that we can skip them when searching for the deepest table
        layoutIDs = set()
        if not config.conf["documentFormatting"]["includeLayoutTables"]:
            for field in fields:
                if (isinstance(field, textInfos.FieldCommand)
                        and field.command == "controlStart"
                        and field.field.get('table-layout')):
                    tableID = field.field.get('table-id')
                    if tableID is not None:
                        layoutIDs.add(tableID)
        return layoutIDs
示例#6
0
 def _getText(self, ti: TextInfo) -> str:
     return "\n".join(ti.getTextInChunks(UNIT_LINE))
示例#7
0
	def updateCaret(self, updater: textInfos.TextInfo) -> None:
		updater.updateCaret()
		if config.conf["reviewCursor"]["followCaret"]:
			api.setReviewPosition(updater, isCaret=True)