python-pptx
python-pptx copied to clipboard
How to get the actual font size of a paragraph or a run x when x.font.size is None?
same problem. Have you solved?
I believe your question is how to find the "effective" value of a font formatting parameter.
The formatting for a run of text is determined by a set of rules operating on the style hierarchy. If a formatting attribute (say bold) is applied directly to the run, that takes precedence. When bold is not applied directly, run.bold
returns None
, and the run's "boldness" is determined by checking the rest of the style hierarchy. This could be a character style, a table style, or the document default (and perhaps other possibilities).
So finding the effective value requires discovering these rules and navigating the style hierarchy to resolve them for any given piece of text.
No one has wanted that bad enough yet to develop it or sponsor the feature.
I am also looking for this feature, and I'm trying to develop a workaround that's at least "good enough" for most cases.
As far as I can determine, the style hierarchy seems to be something like: slide.xml (run) ⇒ slideLayout.xml ⇒ slideMaster.xml ⇒ theme.xml Edit: Found a more detailed style hierarchy here. For example, in slideMaster.xml there are a number of default font styles defined such as titleStyle⇒lvl1pPr, bodyStyle => lvl1pPr, etc.
However, I can't figure out what actually links a given run to one of these styles... is it the attribute <p:ph type="subTitle">, or something else? Is there any documentation at all about this style hierarchy, or is trial-and-error really the only option?
I know this is not a top priority, but I would be most grateful for any hints you could provide!
This is necessary to be able to correctly parse a document.
Found a decent example here - https://stackoverflow.com/questions/37060820/pptx-style-inheritance/37124357
anybody found any solution to this?