fdo#64232: export w:themeFontLang setting to docx
We store the values of themeFontLang tag to the document grab bag so we can save it back to the document on export time. Added unit tests to check that the attribute is properly set back and also that the theme fonts are correctly applied to the text. Change-Id: Ia54c513796ba38a571396ca7b72dfd28463c15fd
This commit is contained in:
parent
1835074d52
commit
ece66b11bd
Binary file not shown.
@ -2047,7 +2047,7 @@ DECLARE_OOXMLEXPORT_TEST(testThemePreservation, "theme-preservation.docx")
|
||||
if (!pXmlStyles)
|
||||
return;
|
||||
assertXPath(pXmlStyles, "/w:styles/w:docDefaults/w:rPrDefault/w:rPr/w:rFonts", "asciiTheme", "minorHAnsi");
|
||||
assertXPath(pXmlStyles, "/w:styles/w:docDefaults/w:rPrDefault/w:rPr/w:rFonts", "eastAsiaTheme", "minorEastAsia");
|
||||
assertXPath(pXmlStyles, "/w:styles/w:docDefaults/w:rPrDefault/w:rPr/w:rFonts", "cstheme", "minorBidi");
|
||||
|
||||
// check the font theme values in style definitions
|
||||
assertXPath(pXmlStyles, "/w:styles/w:style[1]/w:rPr/w:rFonts", "eastAsiaTheme", "minorEastAsia");
|
||||
@ -2056,8 +2056,30 @@ DECLARE_OOXMLEXPORT_TEST(testThemePreservation, "theme-preservation.docx")
|
||||
xmlDocPtr pXmlDocument = parseExport("word/document.xml");
|
||||
if (!pXmlDocument)
|
||||
return;
|
||||
assertXPath(pXmlDocument, "/w:document/w:body/w:p[1]/w:r[1]/w:rPr/w:rFonts", "hAnsiTheme", "majorBidi");
|
||||
assertXPath(pXmlDocument, "/w:document/w:body/w:p[1]/w:r[1]/w:rPr/w:rFonts", "cstheme", "majorBidi");
|
||||
assertXPath(pXmlDocument, "/w:document/w:body/w:p[5]/w:r[1]/w:rPr/w:rFonts", "hAnsiTheme", "majorHAnsi");
|
||||
assertXPath(pXmlDocument, "/w:document/w:body/w:p[5]/w:r[1]/w:rPr/w:rFonts", "asciiTheme", "majorHAnsi");
|
||||
|
||||
// check the themeFontLang values in settings file
|
||||
xmlDocPtr pXmlSettings = parseExport("word/settings.xml");
|
||||
if (!pXmlSettings)
|
||||
return;
|
||||
assertXPath(pXmlSettings, "/w:settings/w:themeFontLang", "val", "en-US");
|
||||
assertXPath(pXmlSettings, "/w:settings/w:themeFontLang", "eastAsia", "zh-CN");
|
||||
assertXPath(pXmlSettings, "/w:settings/w:themeFontLang", "bidi", "he-IL");
|
||||
|
||||
// check fonts have been applied properly
|
||||
sal_Unicode fontName[2]; //represents the string "宋体"
|
||||
fontName[0] = 0x5b8b;
|
||||
fontName[1] = 0x4f53;
|
||||
CPPUNIT_ASSERT_EQUAL(OUString(fontName, 2), getProperty<OUString>(getParagraph(1), "CharFontNameAsian"));
|
||||
CPPUNIT_ASSERT_EQUAL(OUString("Arial"),
|
||||
getProperty<OUString>(getParagraph(2), "CharFontNameComplex"));
|
||||
CPPUNIT_ASSERT_EQUAL(OUString("Trebuchet MS"),
|
||||
getProperty<OUString>(getParagraph(3, "Default style theme font"), "CharFontName"));
|
||||
CPPUNIT_ASSERT_EQUAL(OUString("Arial Black"),
|
||||
getProperty<OUString>(getRun(getParagraph(4, "Direct format font"), 1), "CharFontName"));
|
||||
CPPUNIT_ASSERT_EQUAL(OUString("Trebuchet MS"),
|
||||
getProperty<OUString>(getParagraph(5, "Major theme font"), "CharFontName"));
|
||||
}
|
||||
|
||||
DECLARE_OOXMLEXPORT_TEST(testcantSplit, "2_table_doc.docx")
|
||||
|
@ -753,6 +753,41 @@ void DocxExport::WriteSettings()
|
||||
if( m_pAttrOutput->HasEndnotes())
|
||||
m_pAttrOutput->WriteFootnoteEndnotePr( pFS, XML_endnotePr, pDoc->GetEndNoteInfo(), XML_endnote );
|
||||
|
||||
// Has themeFontLang information
|
||||
uno::Reference< beans::XPropertySet > xPropSet( pDoc->GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW );
|
||||
|
||||
uno::Reference< beans::XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
|
||||
OUString pName = UNO_NAME_MISC_OBJ_INTEROPGRABBAG;
|
||||
if ( xPropSetInfo->hasPropertyByName( pName ) )
|
||||
{
|
||||
uno::Sequence< beans::PropertyValue > propList;
|
||||
xPropSet->getPropertyValue( pName ) >>= propList;
|
||||
for( sal_Int32 i=0; i < propList.getLength(); ++i )
|
||||
{
|
||||
if ( propList[i].Name == "ThemeFontLangProps" )
|
||||
{
|
||||
uno::Sequence< beans::PropertyValue > themeFontLangProps;
|
||||
propList[i].Value >>= themeFontLangProps;
|
||||
OUString aValues[3];
|
||||
for( sal_Int32 j=0; j < themeFontLangProps.getLength(); ++j )
|
||||
{
|
||||
if( themeFontLangProps[j].Name == "val" )
|
||||
themeFontLangProps[j].Value >>= aValues[0];
|
||||
else if( themeFontLangProps[j].Name == "eastAsia" )
|
||||
themeFontLangProps[j].Value >>= aValues[1];
|
||||
else if( themeFontLangProps[j].Name == "bidi" )
|
||||
themeFontLangProps[j].Value >>= aValues[2];
|
||||
}
|
||||
pFS->singleElementNS( XML_w, XML_themeFontLang,
|
||||
FSNS( XML_w, XML_val ), OUStringToOString( aValues[0], RTL_TEXTENCODING_UTF8 ).getStr(),
|
||||
FSNS( XML_w, XML_eastAsia ), OUStringToOString( aValues[1], RTL_TEXTENCODING_UTF8 ).getStr(),
|
||||
FSNS( XML_w, XML_bidi ), OUStringToOString( aValues[2], RTL_TEXTENCODING_UTF8 ).getStr(),
|
||||
FSEND );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pFS->endElementNS( XML_w, XML_settings );
|
||||
}
|
||||
|
||||
|
@ -127,6 +127,8 @@ public:
|
||||
/// Get the stored tokens and clear the internal storage.
|
||||
beans::PropertyValue getInteropGrabBag();
|
||||
|
||||
uno::Sequence<beans::PropertyValue> GetThemeFontLangProperties() const;
|
||||
|
||||
private:
|
||||
// Stream
|
||||
virtual void lcl_startSectionGroup();
|
||||
|
@ -4364,6 +4364,11 @@ beans::PropertyValue DomainMapper::getInteropGrabBag()
|
||||
return aRet;
|
||||
}
|
||||
|
||||
uno::Sequence<beans::PropertyValue> DomainMapper::GetThemeFontLangProperties() const
|
||||
{
|
||||
return m_pImpl->GetSettingsTable()->GetThemeFontLangProperties();
|
||||
}
|
||||
|
||||
} //namespace dmapper
|
||||
} //namespace writerfilter
|
||||
|
||||
|
@ -100,7 +100,8 @@ sal_Bool WriterFilter::filter( const uno::Sequence< beans::PropertyValue >& aDes
|
||||
m_sFilterName == "writer_OOXML" || m_sFilterName == "writer_OOXML_Text_Template" ) ?
|
||||
writerfilter::dmapper::DOCUMENT_OOXML : writerfilter::dmapper::DOCUMENT_DOC;
|
||||
|
||||
writerfilter::Stream::Pointer_t pStream(new writerfilter::dmapper::DomainMapper(m_xContext, xInputStream, m_xDstDoc, bRepairStorage, eType, uno::Reference<text::XTextRange>()));
|
||||
writerfilter::dmapper::DomainMapper* aDomainMapper = new writerfilter::dmapper::DomainMapper(m_xContext, xInputStream, m_xDstDoc, bRepairStorage, eType, uno::Reference<text::XTextRange>());
|
||||
writerfilter::Stream::Pointer_t pStream(aDomainMapper);
|
||||
//create the tokenizer and domain mapper
|
||||
if( eType == writerfilter::dmapper::DOCUMENT_OOXML )
|
||||
{
|
||||
@ -221,6 +222,38 @@ sal_Bool WriterFilter::filter( const uno::Sequence< beans::PropertyValue >& aDes
|
||||
SAL_WARN("writerfilter","Failed to save ActiveX dom to documents grab bag");
|
||||
}
|
||||
|
||||
// Adding the saved w:themeFontLang setting to the document's grab bag
|
||||
if ( aDomainMapper->GetThemeFontLangProperties().hasElements() )
|
||||
try
|
||||
{
|
||||
uno::Reference<beans::XPropertySet> xDocProps( m_xDstDoc, uno::UNO_QUERY );
|
||||
if (xDocProps.is())
|
||||
{
|
||||
uno::Reference< beans::XPropertySetInfo > xPropsInfo = xDocProps->getPropertySetInfo();
|
||||
|
||||
const OUString aGrabBagPropName = "InteropGrabBag";
|
||||
if( xPropsInfo.is() && xPropsInfo->hasPropertyByName( aGrabBagPropName ) )
|
||||
{
|
||||
uno::Sequence< beans::PropertyValue > aGrabBag;
|
||||
|
||||
// We want to keep the previous items
|
||||
xDocProps->getPropertyValue( aGrabBagPropName ) >>= aGrabBag;
|
||||
sal_Int32 length = aGrabBag.getLength();
|
||||
aGrabBag.realloc( length+1 );
|
||||
|
||||
beans::PropertyValue* pValue = aGrabBag.getArray();
|
||||
pValue[length].Name = "ThemeFontLangProps";
|
||||
pValue[length].Value = uno::makeAny( aDomainMapper->GetThemeFontLangProperties() );
|
||||
|
||||
xDocProps->setPropertyValue( aGrabBagPropName, uno::Any( aGrabBag ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(const uno::Exception&)
|
||||
{
|
||||
SAL_WARN("writerfilter","Failed to save themeFontLang properties to documents grab bag");
|
||||
}
|
||||
|
||||
writerfilter::ooxml::OOXMLStream::Pointer_t pVBAProjectStream(writerfilter::ooxml::OOXMLDocumentFactory::createStream( pDocStream, writerfilter::ooxml::OOXMLStream::VBAPROJECT ));
|
||||
oox::StorageRef xVbaPrjStrg( new ::oox::ole::OleStorage( m_xContext, pVBAProjectStream->getDocumentStream(), false ) );
|
||||
if( xVbaPrjStrg.get() && xVbaPrjStrg->isStorage() )
|
||||
|
Loading…
x
Reference in New Issue
Block a user