Add fixedsize as third image_size value

When True, enclose the image cell in a table without borders to avoid
narrow borders when the fixed width is less than the node width.
This commit is contained in:
KV 2020-08-12 18:04:37 +02:00
parent 41b3f3acfe
commit 3d7f027a4e

View File

@ -58,8 +58,18 @@ def nested_html_table(rows):
def html_image(node): def html_image(node):
if not node.image: if not node.image:
return None return None
return f'''<tdX{' sides="TLR"' if node.caption else ''}{html_size_attr(node.image_size)}>''' \ size = html_size_attr(node.image_size)
f'''<img scale="{node.image_scale}" src="{node.image}"/>''' # The leading attributes belong to the preceeding tag. See where used below.
html = f'{"".join(size)}><img scale="{node.image_scale}" src="{node.image}"/>'
if size[2]: # fixedsize
# Close the preceeding tag and enclose the image cell in a table without
# borders to avoid narrow borders when the fixed width < the node width.
html = f'''>
<table border="0" cellspacing="0" cellborder="0"><tr>
<td{html}</td>
</tr></table>
'''
return f'''<tdX{' sides="TLR"' if node.caption else ''}{html}'''
def html_caption(node): def html_caption(node):
return f'''<tdX{' sides="LRB"' if node.image else ''}>{html_line_breaks(node.caption)}''' if node.caption else None return f'''<tdX{' sides="LRB"' if node.image else ''}>{html_line_breaks(node.caption)}''' if node.caption else None
@ -69,10 +79,13 @@ def html_size_attr(size):
# size: List of values where only these are used: # size: List of values where only these are used:
# - First value is minimum width of object in points, an int value in the range 1-65535. (Default 0 = none) # - First value is minimum width of object in points, an int value in the range 1-65535. (Default 0 = none)
# - Second value is minimum height of the object in points, an int value in the range 1-65535. (Default 0 = none) # - Second value is minimum height of the object in points, an int value in the range 1-65535. (Default 0 = none)
# - Third value is a boolean where TRUE specify that the first two values are the fixed image cell size.
# (Default FALSE) Other string values, e.g. FIXED are also interpreted as TRUE.
if not size or not isinstance(size, list): if not size or not isinstance(size, list):
return '' return [''] * 3
return ((f' width="{size[0]}"' if len(size) > 0 and size[0] else '') return [f' width="{size[0]}"' if len(size) > 0 and size[0] else '',
+ (f' height="{size[1]}"' if len(size) > 1 and size[1] else '')) f' height="{size[1]}"' if len(size) > 1 and size[1] else '',
' fixedsize="TRUE"' if len(size) > 2 and size[2] else '']
def expand(yaml_data): def expand(yaml_data):