search/mag_sel search/close
Aspose::Words::Themes Namespace Reference

The Aspose.Words.Themes namespace provides classes that allow to access theme information in Microsoft Word documents.

A document theme can specify fonts and colors to be used in a document. Themes are supported in Word 2007 and higher.

Classes

class  Theme
 Represents document Theme, and provides access to main theme parts including MajorFonts, MinorFonts and Colors More...
 
class  ThemeColors
 Represents the color scheme of the document theme which contains twelve colors. ThemeColors object contains six accent colors, two dark colors, two light colors and a color for each of a hyperlink and followed hyperlink. More...
 
class  ThemeFonts
 Represents a collection of fonts in the font scheme, allowing to specify different fonts for different languages Latin, EastAsian and ComplexScript. More...
 

Enumerations

enum class  ThemeColor
 Specifies the theme colors for document themes. More...
 
enum class  ThemeFont
 Specifies the types of theme font names for document themes. More...
 

Enumeration Type Documentation

◆ ThemeColor

Specifies the theme colors for document themes.

Examples

Shows how to work with theme fonts and colors.

auto doc = MakeObject<Document>();
// Define fonts for languages uses by default.
doc->get_Theme()->get_MinorFonts()->set_Latin(u"Algerian");
doc->get_Theme()->get_MinorFonts()->set_EastAsian(u"Aharoni");
doc->get_Theme()->get_MinorFonts()->set_ComplexScript(u"Andalus");
SharedPtr<Font> font = doc->get_Styles()->idx_get(u"Normal")->get_Font();
std::cout << String::Format(u"Originally the Normal style theme color is: {0} and RGB color is: {1}\n", font->get_ThemeColor(), font->get_Color())
<< std::endl;
// We can use theme font and color instead of default values.
font->set_ThemeFont(ThemeFont::Minor);
font->set_ThemeColor(ThemeColor::Accent2);
ASSERT_EQ(ThemeFont::Minor, font->get_ThemeFont());
ASSERT_EQ(u"Algerian", font->get_Name());
ASSERT_EQ(ThemeFont::Minor, font->get_ThemeFontAscii());
ASSERT_EQ(u"Algerian", font->get_NameAscii());
ASSERT_EQ(ThemeFont::Minor, font->get_ThemeFontBi());
ASSERT_EQ(u"Andalus", font->get_NameBi());
ASSERT_EQ(ThemeFont::Minor, font->get_ThemeFontFarEast());
ASSERT_EQ(u"Aharoni", font->get_NameFarEast());
ASSERT_EQ(ThemeFont::Minor, font->get_ThemeFontOther());
ASSERT_EQ(u"Algerian", font->get_NameOther());
ASSERT_EQ(ThemeColor::Accent2, font->get_ThemeColor());
ASPOSE_ASSERT_EQ(System::Drawing::Color::Empty, font->get_Color());
// There are several ways of reset them font and color.
// 1 - By setting ThemeFont.None/ThemeColor.None:
font->set_ThemeFont(ThemeFont::None);
font->set_ThemeColor(ThemeColor::None);
ASSERT_EQ(ThemeFont::None, font->get_ThemeFont());
ASSERT_EQ(u"Algerian", font->get_Name());
ASSERT_EQ(ThemeFont::None, font->get_ThemeFontAscii());
ASSERT_EQ(u"Algerian", font->get_NameAscii());
ASSERT_EQ(ThemeFont::None, font->get_ThemeFontBi());
ASSERT_EQ(u"Andalus", font->get_NameBi());
ASSERT_EQ(ThemeFont::None, font->get_ThemeFontFarEast());
ASSERT_EQ(u"Aharoni", font->get_NameFarEast());
ASSERT_EQ(ThemeFont::None, font->get_ThemeFontOther());
ASSERT_EQ(u"Algerian", font->get_NameOther());
ASSERT_EQ(ThemeColor::None, font->get_ThemeColor());
ASPOSE_ASSERT_EQ(System::Drawing::Color::Empty, font->get_Color());
// 2 - By setting non-theme font/color names:
font->set_Name(u"Arial");
ASSERT_EQ(ThemeFont::None, font->get_ThemeFont());
ASSERT_EQ(u"Arial", font->get_Name());
ASSERT_EQ(ThemeFont::None, font->get_ThemeFontAscii());
ASSERT_EQ(u"Arial", font->get_NameAscii());
ASSERT_EQ(ThemeFont::None, font->get_ThemeFontBi());
ASSERT_EQ(u"Arial", font->get_NameBi());
ASSERT_EQ(ThemeFont::None, font->get_ThemeFontFarEast());
ASSERT_EQ(u"Arial", font->get_NameFarEast());
ASSERT_EQ(ThemeFont::None, font->get_ThemeFontOther());
ASSERT_EQ(u"Arial", font->get_NameOther());
ASSERT_EQ(ThemeColor::None, font->get_ThemeColor());
ASSERT_EQ(System::Drawing::Color::get_Blue().ToArgb(), font->get_Color().ToArgb());

Shows how to create and use themed style.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln();
// Create some style with theme font properties.
SharedPtr<Style> style = doc->get_Styles()->Add(StyleType::Paragraph, u"ThemedStyle");
style->get_Font()->set_ThemeFont(ThemeFont::Major);
style->get_Font()->set_ThemeColor(ThemeColor::Accent5);
style->get_Font()->set_TintAndShade(0.3);
builder->get_ParagraphFormat()->set_StyleName(u"ThemedStyle");
builder->Writeln(u"Text with themed style");
Enumerator
None 

No color.

Dark1 

Dark main color 1.

Light1 

Light main color 1.

Dark2 

Dark main color 2.

Light2 

Light main color 2.

Accent1 

Accent color 1.

Accent2 

Accent color 2.

Accent3 

Accent color 3.

Accent4 

Accent color 4.

Accent5 

Accent color 5.

Accent6 

Accent color 6.

Hyperlink 

Hyperlink color.

FollowedHyperlink 

Followed hyperlink color.

Text1 

Text color 1.

Text2 

Text color 2.

Background1 

Background color 1.

Background2 

Background color 2.

◆ ThemeFont

Specifies the types of theme font names for document themes.

Examples

Shows how to work with theme fonts and colors.

auto doc = MakeObject<Document>();
// Define fonts for languages uses by default.
doc->get_Theme()->get_MinorFonts()->set_Latin(u"Algerian");
doc->get_Theme()->get_MinorFonts()->set_EastAsian(u"Aharoni");
doc->get_Theme()->get_MinorFonts()->set_ComplexScript(u"Andalus");
SharedPtr<Font> font = doc->get_Styles()->idx_get(u"Normal")->get_Font();
std::cout << String::Format(u"Originally the Normal style theme color is: {0} and RGB color is: {1}\n", font->get_ThemeColor(), font->get_Color())
<< std::endl;
// We can use theme font and color instead of default values.
font->set_ThemeFont(ThemeFont::Minor);
font->set_ThemeColor(ThemeColor::Accent2);
ASSERT_EQ(ThemeFont::Minor, font->get_ThemeFont());
ASSERT_EQ(u"Algerian", font->get_Name());
ASSERT_EQ(ThemeFont::Minor, font->get_ThemeFontAscii());
ASSERT_EQ(u"Algerian", font->get_NameAscii());
ASSERT_EQ(ThemeFont::Minor, font->get_ThemeFontBi());
ASSERT_EQ(u"Andalus", font->get_NameBi());
ASSERT_EQ(ThemeFont::Minor, font->get_ThemeFontFarEast());
ASSERT_EQ(u"Aharoni", font->get_NameFarEast());
ASSERT_EQ(ThemeFont::Minor, font->get_ThemeFontOther());
ASSERT_EQ(u"Algerian", font->get_NameOther());
ASSERT_EQ(ThemeColor::Accent2, font->get_ThemeColor());
ASPOSE_ASSERT_EQ(System::Drawing::Color::Empty, font->get_Color());
// There are several ways of reset them font and color.
// 1 - By setting ThemeFont.None/ThemeColor.None:
font->set_ThemeFont(ThemeFont::None);
font->set_ThemeColor(ThemeColor::None);
ASSERT_EQ(ThemeFont::None, font->get_ThemeFont());
ASSERT_EQ(u"Algerian", font->get_Name());
ASSERT_EQ(ThemeFont::None, font->get_ThemeFontAscii());
ASSERT_EQ(u"Algerian", font->get_NameAscii());
ASSERT_EQ(ThemeFont::None, font->get_ThemeFontBi());
ASSERT_EQ(u"Andalus", font->get_NameBi());
ASSERT_EQ(ThemeFont::None, font->get_ThemeFontFarEast());
ASSERT_EQ(u"Aharoni", font->get_NameFarEast());
ASSERT_EQ(ThemeFont::None, font->get_ThemeFontOther());
ASSERT_EQ(u"Algerian", font->get_NameOther());
ASSERT_EQ(ThemeColor::None, font->get_ThemeColor());
ASPOSE_ASSERT_EQ(System::Drawing::Color::Empty, font->get_Color());
// 2 - By setting non-theme font/color names:
font->set_Name(u"Arial");
ASSERT_EQ(ThemeFont::None, font->get_ThemeFont());
ASSERT_EQ(u"Arial", font->get_Name());
ASSERT_EQ(ThemeFont::None, font->get_ThemeFontAscii());
ASSERT_EQ(u"Arial", font->get_NameAscii());
ASSERT_EQ(ThemeFont::None, font->get_ThemeFontBi());
ASSERT_EQ(u"Arial", font->get_NameBi());
ASSERT_EQ(ThemeFont::None, font->get_ThemeFontFarEast());
ASSERT_EQ(u"Arial", font->get_NameFarEast());
ASSERT_EQ(ThemeFont::None, font->get_ThemeFontOther());
ASSERT_EQ(u"Arial", font->get_NameOther());
ASSERT_EQ(ThemeColor::None, font->get_ThemeColor());
ASSERT_EQ(System::Drawing::Color::get_Blue().ToArgb(), font->get_Color().ToArgb());

Shows how to create and use themed style.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln();
// Create some style with theme font properties.
SharedPtr<Style> style = doc->get_Styles()->Add(StyleType::Paragraph, u"ThemedStyle");
style->get_Font()->set_ThemeFont(ThemeFont::Major);
style->get_Font()->set_ThemeColor(ThemeColor::Accent5);
style->get_Font()->set_TintAndShade(0.3);
builder->get_ParagraphFormat()->set_StyleName(u"ThemedStyle");
builder->Writeln(u"Text with themed style");
Enumerator
None 

No theme font.

Major 

Major theme font.

Minor 

Minor theme font.