|
10 | 10 |
|
11 | 11 | from mock import Mock |
12 | 12 |
|
13 | | -from docx.enum.shape import WD_INLINE_SHAPE |
14 | 13 | from docx.opc.constants import CONTENT_TYPE as CT, RELATIONSHIP_TYPE as RT |
15 | 14 | from docx.opc.package import PartFactory |
16 | 15 | from docx.opc.packuri import PackURI |
17 | 16 | from docx.oxml.parts.document import CT_Body, CT_Document |
18 | | -from docx.oxml.shared import nsmap |
19 | 17 | from docx.oxml.text import CT_R |
20 | 18 | from docx.package import ImageParts, Package |
21 | 19 | from docx.parts.document import _Body, DocumentPart, InlineShapes |
|
24 | 22 | from docx.table import Table |
25 | 23 | from docx.text import Paragraph |
26 | 24 |
|
27 | | -from ..oxml.unitdata.dml import ( |
28 | | - a_blip, a_blipFill, a_cNvPr, a_cNvPicPr, a_docPr, a_drawing, a_fillRect, |
29 | | - a_graphic, a_graphicData, a_pic, a_prstGeom, a_stretch, an_ext, |
30 | | - an_extent, an_inline, an_nvPicPr, an_off, an_spPr, an_xfrm |
31 | | -) |
| 25 | +from ..oxml.unitdata.dml import a_drawing, an_inline |
32 | 26 | from ..oxml.parts.unitdata.document import a_body, a_document |
33 | 27 | from ..oxml.unitdata.table import ( |
34 | 28 | a_gridCol, a_tbl, a_tblGrid, a_tblPr, a_tc, a_tr |
@@ -393,136 +387,6 @@ def _tr_bldr(self, cols): |
393 | 387 | return tr_bldr |
394 | 388 |
|
395 | 389 |
|
396 | | -class DescribeInlineShape(object): |
397 | | - |
398 | | - def it_knows_what_type_of_shape_it_is(self, shape_type_fixture): |
399 | | - inline_shape, inline_shape_type = shape_type_fixture |
400 | | - assert inline_shape.type == inline_shape_type |
401 | | - |
402 | | - def it_can_contruct_a_new_inline_picture_shape( |
403 | | - self, new_picture_fixture): |
404 | | - inline_shape, r, image_part_, rId, shape_id, expected_inline_xml = ( |
405 | | - new_picture_fixture |
406 | | - ) |
407 | | - picture = inline_shape.new_picture(r, image_part_, rId, shape_id) |
408 | | - assert picture._inline.xml == expected_inline_xml |
409 | | - assert r[0][0] is picture._inline |
410 | | - |
411 | | - # fixtures ------------------------------------------------------- |
412 | | - |
413 | | - @pytest.fixture |
414 | | - def image_params(self): |
415 | | - filename = 'foobar.garf' |
416 | | - rId = 'rId42' |
417 | | - cx, cy = 914422, 223344 |
418 | | - return filename, rId, cx, cy |
419 | | - |
420 | | - @pytest.fixture |
421 | | - def image_part_(self, request, image_params): |
422 | | - filename, rId, cx, cy = image_params |
423 | | - image_part_ = instance_mock(request, ImagePart) |
424 | | - image_part_.default_cx = cx |
425 | | - image_part_.default_cy = cy |
426 | | - image_part_.filename = filename |
427 | | - return image_part_ |
428 | | - |
429 | | - @pytest.fixture |
430 | | - def new_picture_fixture(self, request, image_part_, image_params): |
431 | | - filename, rId, cx, cy = image_params |
432 | | - inline_shape = InlineShape(None) |
433 | | - r = an_r().with_nsdecls().element |
434 | | - shape_id = 7 |
435 | | - name = 'Picture %d' % shape_id |
436 | | - uri = nsmap['pic'] |
437 | | - expected_inline = ( |
438 | | - an_inline().with_nsdecls('r', 'wp', 'w').with_child( |
439 | | - an_extent().with_cx(cx).with_cy(cy)).with_child( |
440 | | - a_docPr().with_id(shape_id).with_name(name)).with_child( |
441 | | - a_graphic().with_nsdecls().with_child( |
442 | | - a_graphicData().with_uri(uri).with_child( |
443 | | - self._pic_bldr(filename, rId, cx, cy)))) |
444 | | - ).element |
445 | | - expected_inline_xml = expected_inline.xml |
446 | | - return ( |
447 | | - inline_shape, r, image_part_, rId, shape_id, expected_inline_xml |
448 | | - ) |
449 | | - |
450 | | - @pytest.fixture(params=[ |
451 | | - 'embed pic', 'link pic', 'link+embed pic', 'chart', 'smart art', |
452 | | - 'not implemented' |
453 | | - ]) |
454 | | - def shape_type_fixture(self, request): |
455 | | - if request.param == 'embed pic': |
456 | | - inline = self._inline_with_picture(embed=True) |
457 | | - shape_type = WD_INLINE_SHAPE.PICTURE |
458 | | - |
459 | | - elif request.param == 'link pic': |
460 | | - inline = self._inline_with_picture(link=True) |
461 | | - shape_type = WD_INLINE_SHAPE.LINKED_PICTURE |
462 | | - |
463 | | - elif request.param == 'link+embed pic': |
464 | | - inline = self._inline_with_picture(embed=True, link=True) |
465 | | - shape_type = WD_INLINE_SHAPE.LINKED_PICTURE |
466 | | - |
467 | | - elif request.param == 'chart': |
468 | | - inline = self._inline_with_uri(nsmap['c']) |
469 | | - shape_type = WD_INLINE_SHAPE.CHART |
470 | | - |
471 | | - elif request.param == 'smart art': |
472 | | - inline = self._inline_with_uri(nsmap['dgm']) |
473 | | - shape_type = WD_INLINE_SHAPE.SMART_ART |
474 | | - |
475 | | - elif request.param == 'not implemented': |
476 | | - inline = self._inline_with_uri('foobar') |
477 | | - shape_type = WD_INLINE_SHAPE.NOT_IMPLEMENTED |
478 | | - |
479 | | - return InlineShape(inline), shape_type |
480 | | - |
481 | | - def _inline_with_picture(self, embed=False, link=False): |
482 | | - picture_ns = nsmap['pic'] |
483 | | - |
484 | | - blip_bldr = a_blip() |
485 | | - if embed: |
486 | | - blip_bldr.with_embed('rId1') |
487 | | - if link: |
488 | | - blip_bldr.with_link('rId2') |
489 | | - |
490 | | - inline = ( |
491 | | - an_inline().with_nsdecls('wp', 'r').with_child( |
492 | | - a_graphic().with_nsdecls().with_child( |
493 | | - a_graphicData().with_uri(picture_ns).with_child( |
494 | | - a_pic().with_nsdecls().with_child( |
495 | | - a_blipFill().with_child( |
496 | | - blip_bldr))))) |
497 | | - ).element |
498 | | - return inline |
499 | | - |
500 | | - def _inline_with_uri(self, uri): |
501 | | - inline = ( |
502 | | - an_inline().with_nsdecls('wp').with_child( |
503 | | - a_graphic().with_nsdecls().with_child( |
504 | | - a_graphicData().with_uri(uri))) |
505 | | - ).element |
506 | | - return inline |
507 | | - |
508 | | - def _pic_bldr(self, name, rId, cx, cy): |
509 | | - return ( |
510 | | - a_pic().with_nsdecls().with_child( |
511 | | - an_nvPicPr().with_child( |
512 | | - a_cNvPr().with_id(0).with_name(name)).with_child( |
513 | | - a_cNvPicPr())).with_child( |
514 | | - a_blipFill().with_child( |
515 | | - a_blip().with_embed(rId)).with_child( |
516 | | - a_stretch().with_child( |
517 | | - a_fillRect()))).with_child( |
518 | | - an_spPr().with_child( |
519 | | - an_xfrm().with_child( |
520 | | - an_off().with_x(0).with_y(0)).with_child( |
521 | | - an_ext().with_cx(cx).with_cy(cy))).with_child( |
522 | | - a_prstGeom().with_prst('rect'))) |
523 | | - ) |
524 | | - |
525 | | - |
526 | 390 | class DescribeInlineShapes(object): |
527 | 391 |
|
528 | 392 | def it_knows_how_many_inline_shapes_it_contains( |
|
0 commit comments