Skip to content

Commit

Permalink
Add support for text-align in paragraphs
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Forbes committed Jun 23, 2017
1 parent 7694884 commit 57ca197
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.0.4
Add support for text-alignment in paragraphs.

## 1.0.3
Add support for table cell text orientations through the css `writing-mode` property

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

setup(
name='wordinserter',
version='1.0.3',
version='1.0.4',
packages=find_packages(),
url='https://github.com/orf/wordinserter',
license='MIT',
Expand Down
2 changes: 0 additions & 2 deletions wordinserter/parsers/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,4 @@ def _build_format(self, element, style):
if name in Format.optional:
args[name] = style.value.strip()



return Format(**args)
18 changes: 11 additions & 7 deletions wordinserter/renderers/com.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ def table_cell(self, op: TableCell):
yield

if op.orientation:
# ToDo: Move this to the Format handling. It is specific to a table cell though
mapping = {
'sideways-lr': 'wdTextOrientationUpward',
'sideways-rl': 'wdTextOrientationDownward',
Expand Down Expand Up @@ -621,14 +622,17 @@ def handle_format(self, op, parent_operation, element_range):
parent_operation.render.cell_object.VerticalAlignment = alignment[op.vertical_align]

if op.text_align:
if isinstance(parent_operation, TableCell):
alignment = {
'center': self.constants.wdAlignParagraphCenter,
'left': self.constants.wdAlignParagraphLeft,
'right': self.constants.wdAlignParagraphRight
}
if op.text_align in alignment:
alignment = {
'center': self.constants.wdAlignParagraphCenter,
'left': self.constants.wdAlignParagraphLeft,
'right': self.constants.wdAlignParagraphRight
}

if op.text_align in alignment:
if isinstance(parent_operation, TableCell):
parent_operation.render.cell_object.Range.ParagraphFormat.Alignment = alignment[op.text_align]
elif isinstance(parent_operation, Paragraph):
element_range.ParagraphFormat.Alignment = alignment[op.text_align]

if op.writing_mode:
orientations = {"vertical-lr": 1, "sideways-lr": 2}
Expand Down

0 comments on commit 57ca197

Please sign in to comment.