How does one get the font color for a run/txbody/paragraph from a presentation theme?

1.5k Views Asked by At

I'm working on a PresentationML parser, and I'm trying to implement support for themes with regard to font color. I'm working with the SDK, and I've puzzled out this monster:

Slide.SlidePart.SlideLayoutPart.SlideMasterPart.SlideMaster.SlideMasterPart.ThemePart.Theme.ThemeElements.ColorScheme

But it's still not clear where I go to get the color for a run which hasn't had it's color otherwise specified. Any help on this would be greatly appreciated.

TIA.

UPDATE: After just wading through the xml, it looks like the monster call I posted above is probably the right one...it yields an element with a "val" attribute that matches the hex code I'm looking for. But it's not clear how I would resolve the particular scheme in the color map ("Light1" in this case). I'm about 75% of the way there, I think - if someone can help me with the logic to know which scheme applies to a run, I think that's what I need.

1

There are 1 best solutions below

0
On

The free ebook Open XML Explained might give some insight to aid your understanding. Under the PresentationML section, Document Content Structure it talks about how Themes and Master Layouts are used to give default values:

page 86 - 2nd Paragraph:

DrawingML theming can be used to create default values for fonts, layouts, and other branding related data and allow it to be separated from the main body of the presentation. A theme is reusable across all the Open XML markup languages. Inside a PresentationML package various themes are in use. By default each individual master, slide-, note- and hand-out masters, references a separate theme part. The presentation itself also references a default theme to be used in the presentation. This default theme shared with the slide masters by referencing the same part inside the package.

So, in the theme1.xml of your presentations SlideMaster, you will find a theme definition which is used for the slide master and your presentation. The color name Light1, Dark1, etc map to 12 required colors in the Color Scheme of the Theme Element for each theme. See schema for details.

So in the Run, you see Light1, which maps to the number defined in the theme. If the author changes a Master Layout and/or Theme, the Light1 doesn't change in the run, but the value in the theme might and that is where you get the new value from.

On Page 121, the 12 colors are mentioned in Open XML Explained:

Inside the theme element you are required to create a themeElements node which holds all the theme's data. At this level you can also apply extra information or overrides on the existing information inside the theme elements. Theme elements are built up using a set of child nodes, each node identifying a specific data item such as the fonts or colors. The clrScheme element defines a list of colors. The list of themed colors is limited to items such as 'accent1', or 'visited link'. Each of these theme colors uses a separate XML element, where the node name identifies the theme color. Inside this element you make use of the coloring mechanism discussed earlier on coloring shapes using DrawingML. In the markup sample 157 there are two theme colors defined, the 'dark-1' and 'accent-1' colors. The markup sample is not complete. You are required to define value for all the twelve theme colors.

Hope this helps...