Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to read math in PDF documents #17276

Merged
merged 21 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
7f816e6
Mostly revert commit #fbfcd14b5f14609fba7a919c67431a1912b0da51 ("Adob…
NSoiffer Oct 10, 2024
e923065
Pre-commit auto-fix
pre-commit-ci[bot] Oct 10, 2024
be541bd
Add MathML support in PDF change.
NSoiffer Oct 12, 2024
9588e13
Merge branch 'SupportMathML' of github.com:NSoiffer/nvda into Support…
NSoiffer Oct 12, 2024
11e2128
Pre-commit auto-fix
pre-commit-ci[bot] Oct 12, 2024
1485fdf
Apply suggestions from code review
seanbudd Oct 16, 2024
b95c078
Pre-commit auto-fix
pre-commit-ci[bot] Oct 16, 2024
0a62929
Clean up comments and log.debug statements
NSoiffer Oct 17, 2024
e626dae
Improve the change comment
NSoiffer Oct 17, 2024
62926e2
Merge branch 'SupportMathML' of github.com:NSoiffer/nvda into Support…
NSoiffer Oct 17, 2024
909423d
Made each sentence be on its own line as requested by @codeofdusk.
NSoiffer Oct 17, 2024
c6d85d6
Fix multiline debug "fix" -- actually tested the code this time...
NSoiffer Oct 17, 2024
a8c59f2
Pre-commit auto-fix
pre-commit-ci[bot] Oct 17, 2024
c2f6529
Update user_docs/en/changes.md
SaschaCowley Oct 17, 2024
ba3803a
Add documentation string.
NSoiffer Oct 19, 2024
b4a7a41
Merge branch 'SupportMathML' of github.com:NSoiffer/nvda into Support…
NSoiffer Oct 19, 2024
de5e89c
Update user_docs/en/changes.md
NSoiffer Oct 19, 2024
188119d
Merge branch 'master' into SupportMathML
NSoiffer Oct 19, 2024
c77a07e
Update user_docs/en/changes.md
NSoiffer Oct 22, 2024
6d92dc4
Update user_docs/en/changes.md
NSoiffer Oct 22, 2024
4edc60d
Update user_docs/en/changes.md
SaschaCowley Oct 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 2 additions & 15 deletions nvdaHelper/vbufBackends/adobeAcrobat/adobeAcrobat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,6 @@ AdobeAcrobatVBufStorage_controlFieldNode_t* AdobeAcrobatVBufBackend_t::fillVBuf(
}

BSTR stdName = NULL;
BSTR tagName = NULL;
int textFlags = 0;
// Whether to render just a space in place of the content.
bool renderSpace = false;
Expand All @@ -454,18 +453,8 @@ AdobeAcrobatVBufStorage_controlFieldNode_t* AdobeAcrobatVBufBackend_t::fillVBuf(
// This is an inline element.
parentNode->isBlock=false;
}
}

// Get tagName.
if ((res = domElement->GetTagName(&tagName)) != S_OK) {
LOG_DEBUG(L"IPDDomElement::GetTagName returned " << res);
tagName = NULL;
}
if (tagName) {
parentNode->addAttribute(L"acrobat::tagname", tagName);
if (wcscmp(tagName, L"math") == 0) {
// We don't want the content of math nodes here,
// As it will be fetched by NVDAObjects outside of the virtualBuffer.
if (wcscmp(stdName, L"Formula") == 0) {
// We don't want the content of formulas,
// but we still want a space so the user can get at them.
renderSpace = true;
}
Expand Down Expand Up @@ -747,8 +736,6 @@ AdobeAcrobatVBufStorage_controlFieldNode_t* AdobeAcrobatVBufBackend_t::fillVBuf(
delete pageNum;
if (stdName)
SysFreeString(stdName);
if (tagName)
SysFreeString(tagName);
if (domElement) {
LOG_DEBUG(L"Releasing IPDDomElement");
domElement->Release();
Expand Down
23 changes: 22 additions & 1 deletion source/NVDAObjects/IAccessible/adobeAcrobat.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,17 @@ def initOverlayClass(self):
self.accID = None

# Get the IPDDomNode.
try:
serv.QueryService(SID_GetPDDomNode, IGetPDDomNode)
except COMError:
log.debugWarning("FAILED: QueryService(SID_GetPDDomNode, IGetPDDomNode)")
self.pdDomNode = None
try:
self.pdDomNode = serv.QueryService(SID_GetPDDomNode, IGetPDDomNode).get_PDDomNode(
self.IAccessibleChildID,
)
except COMError:
log.debugWarning("FAILED: get_PDDomNode")
self.pdDomNode = None

if self.pdDomNode:
Expand Down Expand Up @@ -137,15 +143,30 @@ def _getNodeMathMl(self, node):
yield "</%s>" % tag

def _get_mathMl(self):
seanbudd marked this conversation as resolved.
Show resolved Hide resolved
if self.pdDomNode is None:
log.debugWarning("_get_mathMl: self.pdDomNode is None!")
raise LookupError
# There could be other stuff before the math element. Ug.
mathMl = self.pdDomNode.GetValue()
log.debug(
f'\n_get_mathMl: math recognized: {mathMl.startswith("<math")}, child count={self.pdDomNode.GetChildCount()}',
NSoiffer marked this conversation as resolved.
Show resolved Hide resolved
)
log.debug(f"\nname={self.pdDomNode.GetName()}\nvalue={self.pdDomNode.GetValue()}")
seanbudd marked this conversation as resolved.
Show resolved Hide resolved
# this test and the replacement doesn't work if someone uses a namespace tag (which they shouldn't, but..)
if mathMl.startswith("<math"):
return mathMl.replace('xmlns:mml="http://www.w3.org/1998/Math/MathML"', "")
NSoiffer marked this conversation as resolved.
Show resolved Hide resolved
for childNum in range(self.pdDomNode.GetChildCount()):
try:
child = self.pdDomNode.GetChild(childNum).QueryInterface(IPDDomElement)
except COMError:
log.debugWarning(f"COMError trying to get childNum={childNum}")
continue
log.debug(f" get_mathMl: tag={child.GetTagName()}")
seanbudd marked this conversation as resolved.
Show resolved Hide resolved
if child.GetTagName() == "math":
return "".join(self._getNodeMathMl(child))
raise LookupError
# fall back to return the contents, which is hopefully to be alt text
log.debug("_get_mathMl: didn't find MathML -- returning value as mtext")
return f"<math><mtext>{self.pdDomNode.GetValue()}</mtext></math>"


class RootNode(AcrobatNode):
Expand Down
2 changes: 1 addition & 1 deletion user_docs/en/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
### Important notes

### New Features
SaschaCowley marked this conversation as resolved.
Show resolved Hide resolved

* Support for math in PDFs has been added. This works for formulas that have MathML in an Associated File. Tagged formulas are supported in newer versions of TeX/LaTeX (9288, @NSoiffer)
seanbudd marked this conversation as resolved.
Show resolved Hide resolved
NSoiffer marked this conversation as resolved.
Show resolved Hide resolved
* The volume of other applications can be adjusted by `NVDA+alt+pageUp` and `NVDA+alt+pageDown`. In order to use this feature, application volume adjuster needs to be enabled in Audio pane of NVDA settings. (#16052, @mltony)
* Added command to mute or unmute all other applications, assigned to `NVDA+alt+delete`.
In order to use this feature, the application volume adjuster needs to be enabled in the Audio category of NVDA settings. (#16052, @mltony)
Expand Down