diff --git a/include/oox/drawingml/textcharacterproperties.hxx b/include/oox/drawingml/textcharacterproperties.hxx index c07901554fac..bddd25c5f735 100644 --- a/include/oox/drawingml/textcharacterproperties.hxx +++ b/include/oox/drawingml/textcharacterproperties.hxx @@ -36,8 +36,11 @@ struct TextCharacterProperties { PropertyMap maHyperlinkPropertyMap; TextFont maLatinFont; + TextFont maLatinThemeFont; TextFont maAsianFont; + TextFont maAsianThemeFont; TextFont maComplexFont; + TextFont maComplexThemeFont; TextFont maSymbolFont; Color maCharColor; Color maUnderlineColor; diff --git a/oox/source/drawingml/textcharacterproperties.cxx b/oox/source/drawingml/textcharacterproperties.cxx index 1ad0bae6e51e..b7827616ecfb 100644 --- a/oox/source/drawingml/textcharacterproperties.cxx +++ b/oox/source/drawingml/textcharacterproperties.cxx @@ -44,8 +44,11 @@ void TextCharacterProperties::assignUsed( const TextCharacterProperties& rSource // overwrite all properties exisiting in rSourceProps maHyperlinkPropertyMap.insert( rSourceProps.maHyperlinkPropertyMap.begin(), rSourceProps.maHyperlinkPropertyMap.end() ); maLatinFont.assignIfUsed( rSourceProps.maLatinFont ); + maLatinThemeFont.assignIfUsed( rSourceProps.maLatinThemeFont ); maAsianFont.assignIfUsed( rSourceProps.maAsianFont ); + maAsianThemeFont.assignIfUsed( rSourceProps.maAsianThemeFont ); maComplexFont.assignIfUsed( rSourceProps.maComplexFont ); + maComplexThemeFont.assignIfUsed( rSourceProps.maComplexThemeFont ); maSymbolFont.assignIfUsed( rSourceProps.maSymbolFont ); maCharColor.assignIfUsed( rSourceProps.maCharColor ); maHighlightColor.assignIfUsed( rSourceProps.maHighlightColor ); @@ -68,21 +71,31 @@ void TextCharacterProperties::pushToPropMap( PropertyMap& rPropMap, const XmlFil sal_Int16 nFontPitch = 0; sal_Int16 nFontFamily = 0; - if( maLatinFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter ) ) + bool bRet = maLatinFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter ); + if (!bRet) + // In case there is no direct font, try to look it up as a theme reference. + bRet = maLatinThemeFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter ); + if (bRet) { rPropMap[ PROP_CharFontName ] <<= aFontName; rPropMap[ PROP_CharFontPitch ] <<= nFontPitch; rPropMap[ PROP_CharFontFamily ] <<= nFontFamily; } - if( maAsianFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter ) ) + bRet = maAsianFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter ); + if (!bRet) + bRet = maAsianThemeFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter ); + if (bRet) { rPropMap[ PROP_CharFontNameAsian ] <<= aFontName; rPropMap[ PROP_CharFontPitchAsian ] <<= nFontFamily; rPropMap[ PROP_CharFontFamilyAsian ] <<= nFontPitch; } - if( maComplexFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter ) ) + bRet = maComplexFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter ); + if (!bRet) + bRet = maComplexThemeFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter ); + if (bRet) { rPropMap[ PROP_CharFontNameComplex ] <<= aFontName; rPropMap[ PROP_CharFontPitchComplex ] <<= nFontPitch; diff --git a/oox/source/drawingml/textcharacterpropertiescontext.cxx b/oox/source/drawingml/textcharacterpropertiescontext.cxx index 8b6156ec64fb..cde4a636282b 100644 --- a/oox/source/drawingml/textcharacterpropertiescontext.cxx +++ b/oox/source/drawingml/textcharacterpropertiescontext.cxx @@ -136,14 +136,26 @@ ContextHandlerRef TextCharacterPropertiesContext::onCreateContext( sal_Int32 aEl { mrTextCharacterProperties.maLatinFont.setAttributes(rAttribs.getString(OOX_TOKEN(doc, ascii), OUString())); } + if (rAttribs.hasAttribute(OOX_TOKEN(doc, asciiTheme))) + { + mrTextCharacterProperties.maLatinThemeFont.setAttributes(rAttribs.getString(OOX_TOKEN(doc, asciiTheme), OUString())); + } if( rAttribs.hasAttribute(OOX_TOKEN(doc, cs)) ) { mrTextCharacterProperties.maComplexFont.setAttributes(rAttribs.getString(OOX_TOKEN(doc, cs), OUString())); } + if (rAttribs.hasAttribute(OOX_TOKEN(doc, cstheme))) + { + mrTextCharacterProperties.maComplexThemeFont.setAttributes(rAttribs.getString(OOX_TOKEN(doc, cstheme), OUString())); + } if( rAttribs.hasAttribute(OOX_TOKEN(doc, eastAsia)) ) { mrTextCharacterProperties.maAsianFont.setAttributes(rAttribs.getString(OOX_TOKEN(doc, eastAsia), OUString())); } + if (rAttribs.hasAttribute(OOX_TOKEN(doc, eastAsiaTheme))) + { + mrTextCharacterProperties.maAsianThemeFont.setAttributes(rAttribs.getString(OOX_TOKEN(doc, eastAsiaTheme), OUString())); + } break; case OOX_TOKEN( doc, b ): mrTextCharacterProperties.moBold = rAttribs.getBool(OOX_TOKEN( doc, val ), true); diff --git a/oox/source/drawingml/theme.cxx b/oox/source/drawingml/theme.cxx index 1fbcf1134261..859488f25105 100644 --- a/oox/source/drawingml/theme.cxx +++ b/oox/source/drawingml/theme.cxx @@ -67,13 +67,13 @@ const TextCharacterProperties* Theme::getFontStyle( sal_Int32 nSchemeType ) cons const TextFont* Theme::resolveFont( const OUString& rName ) const { + const TextCharacterProperties* pCharProps = 0; /* Resolves the following names: +mj-lt, +mj-ea, +mj-cs -- major Latin, Asian, Complex font +mn-lt, +mn-ea, +mn-cs -- minor Latin, Asian, Complex font */ if( (rName.getLength() == 6) && (rName[ 0 ] == '+') && (rName[ 3 ] == '-') ) { - const TextCharacterProperties* pCharProps = 0; if( (rName[ 1 ] == 'm') && (rName[ 2 ] == 'j') ) pCharProps = maFontScheme.get( XML_major ).get(); else if( (rName[ 1 ] == 'm') && (rName[ 2 ] == 'n') ) @@ -88,6 +88,21 @@ const TextFont* Theme::resolveFont( const OUString& rName ) const return &pCharProps->maComplexFont; } } + + // See writerfilter::dmapper::ThemeTable::getFontNameForTheme(). + if (rName == "majorHAnsi" || rName == "majorAscii" || rName == "majorBidi" || rName == "majorEastAsia") + pCharProps = maFontScheme.get(XML_major).get(); + else if (rName == "minorHAnsi" || rName == "minorAscii" || rName == "minorBidi" || rName == "minorEastAsia") + pCharProps = maFontScheme.get(XML_minor).get(); + if (pCharProps) + { + if (rName == "majorAscii" || rName == "majorHAnsi" || rName == "minorAscii" || rName == "minorHAnsi") + return &pCharProps->maLatinFont; + else if (rName == "minorBidi" || rName == "majorBidi") + return &pCharProps->maComplexFont; + else if (rName == "minorEastAsia" || rName == "majorEastAsia") + return &pCharProps->maAsianFont; + } return 0; } diff --git a/sw/qa/extras/ooxmlexport/data/groupshape-theme-font.docx b/sw/qa/extras/ooxmlexport/data/groupshape-theme-font.docx new file mode 100644 index 000000000000..75011d7e5c3e Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/groupshape-theme-font.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlsdrexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlsdrexport.cxx index 038b40415cb8..8dc0ef5d85fd 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlsdrexport.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlsdrexport.cxx @@ -879,6 +879,16 @@ DECLARE_OOXMLEXPORT_TEST(testMSwordHang,"test_msword_hang.docx") assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r[2]/mc:AlternateContent/mc:Choice/w:drawing/wp:anchor/a:graphic/a:graphicData/wps:wsp/wps:txbx/w:txbxContent/w:p/w:r[2]/w:drawing/wp:inline", "distT", "0"); } +DECLARE_OOXMLEXPORT_TEST(testGroupshapeThemeFont, "groupshape-theme-font.docx") +{ + // Font was specified using a theme reference, which wasn't handled. + uno::Reference xGroup(getShape(1), uno::UNO_QUERY); + uno::Reference xText = uno::Reference(xGroup->getByIndex(0), uno::UNO_QUERY)->getText(); + uno::Reference xRun = getRun(getParagraphOfText(1, xText),1); + // This was Calibri. + CPPUNIT_ASSERT_EQUAL(OUString("Cambria"), getProperty(xRun, "CharFontName")); +} + #endif CPPUNIT_PLUGIN_IMPLEMENT();