Skip to content

Commit b6a64ad

Browse files
authored
Merge 909423d into 94062a9
2 parents 94062a9 + 909423d commit b6a64ad

3 files changed

Lines changed: 33 additions & 19 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: 27 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,34 @@ 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+
if self.pdDomNode is None:
147+
log.debugWarning("_get_mathMl: self.pdDomNode is None!")
148+
raise LookupError
149+
mathMl = self.pdDomNode.GetValue()
150+
if log.isEnabledFor(log.DEBUG):
151+
log.debug(
152+
f'_get_mathMl: math recognized: {mathMl.startswith("<math")},
153+
child count={self.pdDomNode.GetChildCount()},
154+
name={self.pdDomNode.GetName()}, value={mathMl}'
155+
)
156+
# this test and the replacement doesn't work if someone uses a namespace tag (which they shouldn't, but..)
157+
if mathMl.startswith("<math"):
158+
return mathMl.replace('xmlns:mml="http://www.w3.org/1998/Math/MathML"', "")
159+
# Alternative for tagging: all the sub expressions are tagged -- gather up the MathML
141160
for childNum in range(self.pdDomNode.GetChildCount()):
142161
try:
143162
child = self.pdDomNode.GetChild(childNum).QueryInterface(IPDDomElement)
144163
except COMError:
164+
log.debugWarning(f"COMError trying to get childNum={childNum}")
145165
continue
166+
log.debug(f"\tget_mathMl: tag={child.GetTagName()}")
146167
if child.GetTagName() == "math":
147168
return "".join(self._getNodeMathMl(child))
148-
raise LookupError
169+
# fall back to return the contents, which is hopefully to be alt text
170+
if log.isEnabledFor(log.DEBUG):
171+
log.debug("_get_mathMl: didn't find MathML -- returning value as mtext")
172+
return f"<math><mtext>{self.pdDomNode.GetValue()}</mtext></math>"
149173

150174

151175
class RootNode(AcrobatNode):

user_docs/en/changes.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
### Important notes
66

77
### New Features
8-
8+
* Support for math in PDFs has been added.
9+
This works for Formulas that have MathML in an Associated File (AF) when rendered by a PDF processor that implements taking that MathML and putting it into the content of the Formula tag.
10+
Adding AFs to Formulas are supported in newer versions of TeX/LaTeX.
11+
Currently only Foxit Reader & Foxit Editor do this, but Adobe is on board with the idea. (9288, @NSoiffer)
912
* 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)
1013
* Added command to mute or unmute all other applications, assigned to `NVDA+alt+delete`.
1114
In order to use this feature, the application volume adjuster needs to be enabled in the Audio category of NVDA settings. (#16052, @mltony)

0 commit comments

Comments
 (0)