python-pptx icon indicating copy to clipboard operation
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?

Open chqiwang opened this issue 6 years ago • 6 comments

chqiwang avatar Apr 26 '18 03:04 chqiwang

same problem. Have you solved?

morocarlo avatar May 15 '18 15:05 morocarlo

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.

scanny avatar May 15 '18 16:05 scanny

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!

agargara avatar Oct 16 '18 00:10 agargara

This is necessary to be able to correctly parse a document.

rahul-dutt-sharma avatar Feb 26 '21 11:02 rahul-dutt-sharma

Found a decent example here - https://stackoverflow.com/questions/37060820/pptx-style-inheritance/37124357

rahul-dutt-sharma avatar Feb 26 '21 12:02 rahul-dutt-sharma

anybody found any solution to this?

AM-ash-OR-AM-I avatar Mar 10 '23 15:03 AM-ash-OR-AM-I