[Libreoffice-commits] core.git: include/oox oox/source sw/qa

Miklos Vajna vmiklos at collabora.co.uk
Fri Feb 28 04:52:03 PST 2014


 include/oox/drawingml/textcharacterproperties.hxx        |    3 ++
 oox/source/drawingml/textcharacterproperties.cxx         |   19 ++++++++++++---
 oox/source/drawingml/textcharacterpropertiescontext.cxx  |   12 +++++++++
 oox/source/drawingml/theme.cxx                           |   17 ++++++++++++-
 sw/qa/extras/ooxmlexport/data/groupshape-theme-font.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlsdrexport.cxx              |   10 +++++++
 6 files changed, 57 insertions(+), 4 deletions(-)

New commits:
commit 440fbd609054d78e37f4953dfdde8c79c10b4981
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Feb 28 12:17:51 2014 +0100

    DOCX import: handle font theme references in group shape text
    
    Change-Id: I1d5b86ad17b2c4a0945f483c94ac6abf410cf1d6

diff --git a/include/oox/drawingml/textcharacterproperties.hxx b/include/oox/drawingml/textcharacterproperties.hxx
index c079015..bddd25c 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 1ad0bae..b782761 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 8b6156e..cde4a63 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 1fbcf11..859488f 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 0000000..75011d7
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 038b404..8dc0ef5 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<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();


More information about the Libreoffice-commits mailing list