Skip to content

Commit b46a1cd

Browse files
authored
Merge 4edc60d into 8d6a860
2 parents 8d6a860 + 4edc60d commit b46a1cd

3 files changed

Lines changed: 36 additions & 18 deletions

File tree

nvdaHelper/vbufBackends/adobeAcrobat/adobeAcrobat.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,6 @@ AdobeAcrobatVBufStorage_controlFieldNode_t* AdobeAcrobatVBufBackend_t::fillVBuf(
437437
}
438438

439439
BSTR stdName = NULL;
440-
BSTR tagName = NULL;
441440
int textFlags = 0;
442441
// Whether to render just a space in place of the content.
443442
bool renderSpace = false;
@@ -454,18 +453,8 @@ AdobeAcrobatVBufStorage_controlFieldNode_t* AdobeAcrobatVBufBackend_t::fillVBuf(
454453
// This is an inline element.
455454
parentNode->isBlock=false;
456455
}
457-
}
458-
459-
// Get tagName.
460-
if ((res = domElement->GetTagName(&tagName)) != S_OK) {
461-
LOG_DEBUG(L"IPDDomElement::GetTagName returned " << res);
462-
tagName = NULL;
463-
}
464-
if (tagName) {
465-
parentNode->addAttribute(L"acrobat::tagname", tagName);
466-
if (wcscmp(tagName, L"math") == 0) {
467-
// We don't want the content of math nodes here,
468-
// As it will be fetched by NVDAObjects outside of the virtualBuffer.
456+
if (wcscmp(stdName, L"Formula") == 0) {
457+
// We don't want the content of formulas,
469458
// but we still want a space so the user can get at them.
470459
renderSpace = true;
471460
}
@@ -747,8 +736,6 @@ AdobeAcrobatVBufStorage_controlFieldNode_t* AdobeAcrobatVBufBackend_t::fillVBuf(
747736
delete pageNum;
748737
if (stdName)
749738
SysFreeString(stdName);
750-
if (tagName)
751-
SysFreeString(tagName);
752739
if (domElement) {
753740
LOG_DEBUG(L"Releasing IPDDomElement");
754741
domElement->Release();

source/NVDAObjects/IAccessible/adobeAcrobat.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,17 @@ def initOverlayClass(self):
7676
self.accID = None
7777

7878
# Get the IPDDomNode.
79+
try:
80+
serv.QueryService(SID_GetPDDomNode, IGetPDDomNode)
81+
except COMError:
82+
log.debugWarning("FAILED: QueryService(SID_GetPDDomNode, IGetPDDomNode)")
83+
self.pdDomNode = None
7984
try:
8085
self.pdDomNode = serv.QueryService(SID_GetPDDomNode, IGetPDDomNode).get_PDDomNode(
8186
self.IAccessibleChildID,
8287
)
8388
except COMError:
89+
log.debugWarning("FAILED: get_PDDomNode")
8490
self.pdDomNode = None
8591

8692
if self.pdDomNode:
@@ -136,16 +142,38 @@ def _getNodeMathMl(self, node):
136142
yield sub
137143
yield "</%s>" % tag
138144

139-
def _get_mathMl(self):
140-
# There could be other stuff before the math element. Ug.
145+
def _get_mathMl(self) -> str:
146+
"""Return the MathML associated with a Formula tag"""
147+
if self.pdDomNode is None:
148+
log.debugWarning("_get_mathMl: self.pdDomNode is None!")
149+
raise LookupError
150+
mathMl = self.pdDomNode.GetValue()
151+
if log.isEnabledFor(log.DEBUG):
152+
log.debug(
153+
(
154+
f"_get_mathMl: math recognized: {mathMl.startswith('<math')}, "
155+
f"child count={self.pdDomNode.GetChildCount()},"
156+
f"\n name='{self.pdDomNode.GetName()}', value='{mathMl}'"
157+
),
158+
)
159+
# this test and the replacement doesn't work if someone uses a namespace tag (which they shouldn't, but..)
160+
if mathMl.startswith("<math"):
161+
return mathMl.replace('xmlns:mml="http://www.w3.org/1998/Math/MathML"', "")
162+
# Alternative for tagging: all the sub expressions are tagged -- gather up the MathML
141163
for childNum in range(self.pdDomNode.GetChildCount()):
142164
try:
143165
child = self.pdDomNode.GetChild(childNum).QueryInterface(IPDDomElement)
144166
except COMError:
167+
log.debugWarning(f"COMError trying to get childNum={childNum}")
145168
continue
169+
if log.isEnabledFor(log.DEBUG):
170+
log.debug(f"\tget_mathMl: tag={child.GetTagName()}")
146171
if child.GetTagName() == "math":
147172
return "".join(self._getNodeMathMl(child))
148-
raise LookupError
173+
# fall back to return the contents, which is hopefully alt text
174+
if log.isEnabledFor(log.DEBUG):
175+
log.debug("_get_mathMl: didn't find MathML -- returning value as mtext")
176+
return f"<math><mtext>{self.pdDomNode.GetValue()}</mtext></math>"
149177

150178

151179
class RootNode(AcrobatNode):

user_docs/en/changes.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
### New Features
88

9+
* Support for math in PDFs has been added.
10+
This works for formulas with associated MathML, such as some files generated by newer versions of TeX/LaTeX.
11+
Currently this is only supported in Foxit Reader & Foxit Editor. (#9288, @NSoiffer)
912
* Commands to adjust the volume of other applications besides NVDA have been added.
1013
To use this feature, "allow NVDA to control the volume of other applications" must be enabled in the audio settings panel. (#16052, @mltony, @codeofdusk)
1114
* `NVDA+alt+pageUp`: Increase the volume of all other applications.

0 commit comments

Comments
 (0)