Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable copying of a run's font #1309

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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
6 changes: 6 additions & 0 deletions src/docx/text/font.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ def color(self):
font."""
return ColorFormat(self._element)

@color.setter
def color(self, value: ColorFormat):
this_color = self.color
this_color.theme_color = value.theme_color
this_color.rgb = value.rgb

@property
def complex_script(self) -> bool | None:
"""Read/write tri-state value.
Expand Down
12 changes: 12 additions & 0 deletions src/docx/text/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from __future__ import annotations

import copy

from typing import IO, TYPE_CHECKING, Iterator, cast

from docx.drawing import Drawing
Expand Down Expand Up @@ -136,6 +138,16 @@ def font(self) -> Font:
this run, such as font name and size."""
return Font(self._element)

@property
def formatting(self) -> CT_RPr:
"""The |CT_RPr| object providing access to the full range of formatting properties for
this run, such as font name and size."""
return copy.deepcopy(self._r.get_or_add_rPr())

@formatting.setter
def formatting(self, new_rPr: CT_RPr):
self._r.replace(self._r.get_or_add_rPr(), new_rPr)

@property
def italic(self) -> bool | None:
"""Read/write tri-state value.
Expand Down