DOCX import: handle font theme references in group shape text
Change-Id: I1d5b86ad17b2c4a0945f483c94ac6abf410cf1d6
This commit is contained in:
parent
757996c46e
commit
440fbd6090
6 changed files with 57 additions and 4 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
BIN
sw/qa/extras/ooxmlexport/data/groupshape-theme-font.docx
Normal file
BIN
sw/qa/extras/ooxmlexport/data/groupshape-theme-font.docx
Normal file
Binary file not shown.
|
@ -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<container::XIndexAccess> xGroup(getShape(1), uno::UNO_QUERY);
|
||||
uno::Reference<text::XText> xText = uno::Reference<text::XTextRange>(xGroup->getByIndex(0), uno::UNO_QUERY)->getText();
|
||||
uno::Reference<text::XTextRange> xRun = getRun(getParagraphOfText(1, xText),1);
|
||||
// This was Calibri.
|
||||
CPPUNIT_ASSERT_EQUAL(OUString("Cambria"), getProperty<OUString>(xRun, "CharFontName"));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
CPPUNIT_PLUGIN_IMPLEMENT();
|
||||
|
|
Loading…
Reference in a new issue