Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9a3ca88

Browse files
committed
Merge pull request #216 from CenterForOpenScience/issue_216
Picts can have rects, which can have textbox
2 parents 997f89a + 0552303 commit 9a3ca88

File tree

7 files changed

+71
-3
lines changed

7 files changed

+71
-3
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
**0.9.8**
22

33
- Textboxes can now contain tables.
4+
- Pict elements can now contain Rect elements.
45

56
**0.9.7**
67

pydocx/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
'PyDocX',
77
]
88

9-
__version__ = '0.9.7'
9+
__version__ = '0.9.8'

pydocx/export/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def __init__(self, path):
6363
wordprocessing.FieldCode: self.export_field_code,
6464
wordprocessing.SimpleField: self.export_simple_field,
6565
vml.Shape: self.export_vml_shape,
66+
vml.Rect: self.export_vml_rect,
6667
vml.ImageData: self.export_vml_image_data,
6768
vml.Textbox: self.export_textbox,
6869
wordprocessing.EmbeddedObject: self.export_embedded_object,
@@ -481,6 +482,9 @@ def export_footnote_reference_mark(self, footnote_reference_mark):
481482
def export_vml_shape(self, shape):
482483
return self.yield_nested(shape.children, self.export_node)
483484

485+
def export_vml_rect(self, rect):
486+
return self.yield_nested(rect.children, self.export_node)
487+
484488
def export_embedded_object(self, obj):
485489
return self.yield_nested(obj.children, self.export_node)
486490

pydocx/openxml/vml/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# coding: utf-8
22
from pydocx.openxml.vml.image_data import ImageData
3+
from pydocx.openxml.vml.rect import Rect
34
from pydocx.openxml.vml.shape import Shape
45
from pydocx.openxml.vml.textbox import Textbox
56

67
__all__ = [
78
'ImageData',
9+
'Rect',
810
'Shape',
911
'Textbox',
1012
]

pydocx/openxml/vml/rect.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# coding: utf-8
2+
from __future__ import (
3+
absolute_import,
4+
print_function,
5+
unicode_literals,
6+
)
7+
8+
from pydocx.models import XmlModel, XmlCollection
9+
from pydocx.openxml.vml.image_data import ImageData
10+
11+
12+
class Rect(XmlModel):
13+
XML_TAG = 'rect'
14+
15+
children = XmlCollection(ImageData, 'vml.Textbox')

pydocx/openxml/wordprocessing/picture.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
)
77

88
from pydocx.models import XmlModel, XmlCollection
9-
from pydocx.openxml.vml import Shape
9+
from pydocx.openxml.vml import Shape, Rect
1010

1111

1212
class Picture(XmlModel):
1313
XML_TAG = 'pict'
1414

15-
children = XmlCollection(Shape)
15+
children = XmlCollection(Shape, Rect)

tests/export/html/test_rect.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# coding: utf-8
2+
3+
from __future__ import (
4+
absolute_import,
5+
print_function,
6+
unicode_literals,
7+
)
8+
9+
from pydocx.test import DocumentGeneratorTestCase
10+
from pydocx.test.utils import WordprocessingDocumentFactory
11+
from pydocx.openxml.packaging import MainDocumentPart
12+
13+
14+
class RectTestCase(DocumentGeneratorTestCase):
15+
def test_rect_with_textbox(self):
16+
document_xml = '''
17+
<p>
18+
<r>
19+
<pict>
20+
<rect>
21+
<textbox>
22+
<txbxContent>
23+
<p>
24+
<r>
25+
<t>AAA</t>
26+
</r>
27+
</p>
28+
</txbxContent>
29+
</textbox>
30+
</rect>
31+
</pict>
32+
</r>
33+
</p>
34+
'''
35+
36+
document = WordprocessingDocumentFactory()
37+
document.add(MainDocumentPart, document_xml)
38+
39+
expected_html = '''
40+
<p>
41+
<p>
42+
AAA
43+
</p>
44+
</p>
45+
'''
46+
self.assert_document_generates_html(document, expected_html)

0 commit comments

Comments
 (0)