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

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 6 additions & 1 deletion pydocx/export/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,7 @@ def export_table_cell(self, table_cell):
def export_drawing(self, drawing):
length, width = drawing.get_picture_extents()
rotate = drawing.get_picture_rotate_angle()
description = drawing.get_picture_description()
relationship_id = drawing.get_picture_relationship_id()
if not relationship_id:
return
Expand All @@ -705,6 +706,8 @@ def export_drawing(self, drawing):
attrs['height'] = height_px
if rotate:
attrs['rotate'] = rotate
if description:
attrs['description'] = description

tag = self.get_image_tag(image=image, **attrs)
if tag:
Expand All @@ -726,7 +729,7 @@ def get_image_source(self, image):
)
return self.escape(b64_encoded_src)

def get_image_tag(self, image, width=None, height=None, rotate=None):
def get_image_tag(self, image, width=None, height=None, rotate=None, description=None):
image_src = self.get_image_source(image)
if image_src:
attrs = {
Expand All @@ -737,6 +740,8 @@ def get_image_tag(self, image, width=None, height=None, rotate=None):
attrs['height'] = height
if rotate:
attrs['style'] = 'transform: rotate(%sdeg);' % rotate
if description:
attrs['alt'] = description

return HtmlTag(
'img',
Expand Down
8 changes: 4 additions & 4 deletions pydocx/export/numbering_span.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,10 @@ def detect_parent_child_map_for_items(self):
list_start_stop_index = {}
# we are interested only in components that are part of the listing
components = [component for component in self.components if
hasattr(component, 'properties')
and hasattr(component.properties, 'numbering_properties')
and component.numbering_definition
and component.get_numbering_level()]
hasattr(component, 'properties') and
hasattr(component.properties, 'numbering_properties') and
component.numbering_definition and
component.get_numbering_level()]
if not components:
return False

Expand Down
2 changes: 2 additions & 0 deletions pydocx/openxml/drawing/wordprocessing/inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

from pydocx.models import XmlModel, XmlChild
from pydocx.openxml.drawing.graphic import Graphic
from pydocx.openxml.wordprocessing.document_properties import DocPr


class Inline(XmlModel):
XML_TAG = 'inline'

graphic = XmlChild(type=Graphic)
DocPr = XmlChild(type=DocPr)
14 changes: 14 additions & 0 deletions pydocx/openxml/wordprocessing/document_properties.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from __future__ import (
absolute_import,
print_function,
unicode_literals,
)

from pydocx.models import XmlModel, XmlAttribute


class DocPr(XmlModel):
XML_TAG = 'docPr'

title = XmlAttribute(name='title')
descr = XmlAttribute(name='descr')
6 changes: 6 additions & 0 deletions pydocx/openxml/wordprocessing/drawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ def graphic(self):
except AttributeError:
pass

def get_picture_description(self):
try:
return self.inline.DocPr.descr
except AttributeError:
return None

def get_picture_extents(self):
graphic = self.graphic
length = 0
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/external_image.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<p>
AAA
<img
alt="A description..."
height="55px"
src="https://www.google.com/images/srpr/logo11w.png"
width="260px"
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/rotate_image.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p>This arrow should point down: <img height="15px" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAYAAAALCAYAAABcUvyWAAAABGdBTUEAALGPC/xhBQAAAH1JREFUGBlVjkEOABEMRVtjxzFcQFxwrsXGHaxdwMIFbIzfhJiftH35P1o8l2ip1opBzjmZWvpqMUbBHag72KF4WDXGmNZaKTBEaDln3JECQ7LqXnEYqff+vABD1FqbzHwCMDyVUsKd/TlheI8x5i2lnACwPNK9dwoh/AJ4H3PDYR3buAoNAAAAAElFTkSuQmCC" style="transform: rotate(180deg);" width="8px" /></p>
<p>This arrow should point down: <img alt="Macintosh HD:Users:jhubert:tmp:up.png" height="15px" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAYAAAALCAYAAABcUvyWAAAABGdBTUEAALGPC/xhBQAAAH1JREFUGBlVjkEOABEMRVtjxzFcQFxwrsXGHaxdwMIFbIzfhJiftH35P1o8l2ip1opBzjmZWvpqMUbBHag72KF4WDXGmNZaKTBEaDln3JECQ7LqXnEYqff+vABD1FqbzHwCMDyVUsKd/TlheI8x5i2lnACwPNK9dwoh/AJ4H3PDYR3buAoNAAAAAElFTkSuQmCC" style="transform: rotate(180deg);" width="8px" /></p>