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

Miklos Vajna vmiklos at collabora.co.uk
Fri Feb 14 16:50:45 CET 2014


 include/oox/drawingml/textfield.hxx                       |    3 ++-
 include/oox/drawingml/textparagraph.hxx                   |    3 ++-
 include/oox/drawingml/textrun.hxx                         |    3 ++-
 oox/source/drawingml/textbody.cxx                         |    5 ++++-
 oox/source/drawingml/textfield.cxx                        |    3 ++-
 oox/source/drawingml/textparagraph.cxx                    |    4 ++--
 oox/source/drawingml/textrun.cxx                          |    6 +++++-
 sw/qa/extras/ooxmlimport/data/dml-charheight-default.docx |binary
 sw/qa/extras/ooxmlimport/ooxmlimport.cxx                  |    8 ++++++++
 9 files changed, 27 insertions(+), 8 deletions(-)

New commits:
commit a6278bc3a9a7de6de5802fc4cbceb739bc0720d6
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Feb 14 16:19:50 2014 +0100

    drawingML import: fix inheritance of character height
    
    The problem was that in case a shape had multiple (e.g. two) paragraphs,
    and in case the first paragraph had an explicit character height, but
    not the second, then the cursor carried over the explicit character
    height to the second paragraph, but it shouldn't, as that leads to
    incorrect character height in the second paragraph.
    
    Fix this by remembering the default character height and using that in
    case nothing is set explicitly.
    
    Change-Id: I66e06d5cf192739fb254f7280c74617171d9ee6a

diff --git a/include/oox/drawingml/textfield.hxx b/include/oox/drawingml/textfield.hxx
index e191c7d..4a27918 100644
--- a/include/oox/drawingml/textfield.hxx
+++ b/include/oox/drawingml/textfield.hxx
@@ -45,7 +45,8 @@ public:
                         const ::oox::core::XmlFilterBase& rFilterBase,
                         const ::com::sun::star::uno::Reference < ::com::sun::star::text::XText > & xText,
                         const ::com::sun::star::uno::Reference < ::com::sun::star::text::XTextCursor > &xAt,
-                        const TextCharacterProperties& rTextCharacterStyle ) const;
+                        const TextCharacterProperties& rTextCharacterStyle,
+                        float nDefaultCharHeight) const;
 
 private:
     TextParagraphProperties  maTextParagraphProperties;
diff --git a/include/oox/drawingml/textparagraph.hxx b/include/oox/drawingml/textparagraph.hxx
index add0cef..f100458 100644
--- a/include/oox/drawingml/textparagraph.hxx
+++ b/include/oox/drawingml/textparagraph.hxx
@@ -54,7 +54,8 @@ public:
                                     const ::com::sun::star::uno::Reference < ::com::sun::star::text::XTextCursor > &xAt,
                                     const TextCharacterProperties& rTextStyleProperties,
                                     const TextListStyle& rTextListStyle,
-                                    bool bFirst = false ) const;
+                                    bool bFirst = false,
+                                    float nDefaultCharHeight = 0) const;
 
 private:
     TextParagraphProperties     maProperties;
diff --git a/include/oox/drawingml/textrun.hxx b/include/oox/drawingml/textrun.hxx
index 9c925f0..5fec1a3 100644
--- a/include/oox/drawingml/textrun.hxx
+++ b/include/oox/drawingml/textrun.hxx
@@ -45,7 +45,8 @@ public:
                                     const ::oox::core::XmlFilterBase& rFilterBase,
                                     const ::com::sun::star::uno::Reference < ::com::sun::star::text::XText >& xText,
                                     const ::com::sun::star::uno::Reference < ::com::sun::star::text::XTextCursor >& xAt,
-                                    const TextCharacterProperties& rTextCharacterStyle ) const;
+                                    const TextCharacterProperties& rTextCharacterStyle,
+                                    float nDefaultCharHeight) const;
 
 private:
     OUString             msText;
diff --git a/oox/source/drawingml/textbody.cxx b/oox/source/drawingml/textbody.cxx
index 3df7643..c90e482 100644
--- a/oox/source/drawingml/textbody.cxx
+++ b/oox/source/drawingml/textbody.cxx
@@ -20,6 +20,7 @@
 #include "oox/drawingml/textbody.hxx"
 #include <com/sun/star/text/XText.hpp>
 #include <com/sun/star/text/XTextCursor.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
 #include "oox/drawingml/textparagraph.hxx"
 
 using namespace ::com::sun::star::uno;
@@ -63,8 +64,10 @@ void TextBody::insertAt(
     aCombinedTextStyle.apply( *pMasterTextListStylePtr );
     aCombinedTextStyle.apply( maTextListStyle );
 
+    Reference<css::beans::XPropertySet> xPropertySet(xAt, UNO_QUERY);
+    float nCharHeight = xPropertySet->getPropertyValue("CharHeight").get<float>();
     for( TextParagraphVector::const_iterator aBeg = maParagraphs.begin(), aIt = aBeg, aEnd = maParagraphs.end(); aIt != aEnd; ++aIt )
-        (*aIt)->insertAt( rFilterBase, xText, xAt, rTextStyleProperties, aCombinedTextStyle, aIt == aBeg );
+        (*aIt)->insertAt( rFilterBase, xText, xAt, rTextStyleProperties, aCombinedTextStyle, aIt == aBeg, nCharHeight );
 }
 
 bool TextBody::isEmpty()
diff --git a/oox/source/drawingml/textfield.cxx b/oox/source/drawingml/textfield.cxx
index 76d909b..6006fea 100644
--- a/oox/source/drawingml/textfield.cxx
+++ b/oox/source/drawingml/textfield.cxx
@@ -132,7 +132,8 @@ sal_Int32 TextField::insertAt(
         const ::oox::core::XmlFilterBase& rFilterBase,
         const Reference < XText > & xText,
         const Reference < XTextCursor > &xAt,
-        const TextCharacterProperties& rTextCharacterStyle ) const
+        const TextCharacterProperties& rTextCharacterStyle,
+        float /*nDefaultCharHeight*/) const
 {
     sal_Int32 nCharHeight = 0;
     try
diff --git a/oox/source/drawingml/textparagraph.cxx b/oox/source/drawingml/textparagraph.cxx
index 7bb719a..7010847 100644
--- a/oox/source/drawingml/textparagraph.cxx
+++ b/oox/source/drawingml/textparagraph.cxx
@@ -47,7 +47,7 @@ void TextParagraph::insertAt(
         const Reference < XText > &xText,
         const Reference < XTextCursor > &xAt,
         const TextCharacterProperties& rTextStyleProperties,
-        const TextListStyle& rTextListStyle, bool bFirst) const
+        const TextListStyle& rTextListStyle, bool bFirst, float nDefaultCharHeight) const
 {
     try {
         sal_Int32 nParagraphSize = 0;
@@ -95,7 +95,7 @@ void TextParagraph::insertAt(
                 // This is currently applied to only empty runs
                 if( !nLen && ( ( aIt + 1 ) == aEnd ) )
                     (*aIt)->getTextCharacterProperties().assignUsed( maEndProperties );
-                nCharHeight = std::max< sal_Int32 >( nCharHeight, (*aIt)->insertAt( rFilterBase, xText, xAt, aTextCharacterStyle ) );
+                nCharHeight = std::max< sal_Int32 >( nCharHeight, (*aIt)->insertAt( rFilterBase, xText, xAt, aTextCharacterStyle, nDefaultCharHeight ) );
                 nParagraphSize += nLen;
             }
         }
diff --git a/oox/source/drawingml/textrun.cxx b/oox/source/drawingml/textrun.cxx
index c4648c2..1128918 100644
--- a/oox/source/drawingml/textrun.cxx
+++ b/oox/source/drawingml/textrun.cxx
@@ -50,7 +50,8 @@ sal_Int32 TextRun::insertAt(
         const ::oox::core::XmlFilterBase& rFilterBase,
         const Reference < XText > & xText,
         const Reference < XTextCursor > &xAt,
-        const TextCharacterProperties& rTextCharacterStyle ) const
+        const TextCharacterProperties& rTextCharacterStyle,
+        float nDefaultCharHeight) const
 {
     sal_Int32 nCharHeight = 0;
     try {
@@ -61,6 +62,9 @@ sal_Int32 TextRun::insertAt(
         aTextCharacterProps.assignUsed( maTextCharacterProperties );
         if ( aTextCharacterProps.moHeight.has() )
             nCharHeight = aTextCharacterProps.moHeight.get();
+        else
+            // UNO API has the character height as float, DML has it as int, but in hundreds.
+            aTextCharacterProps.moHeight = static_cast<sal_Int32>(nDefaultCharHeight * 100);
         aTextCharacterProps.pushToPropSet( aPropSet, rFilterBase );
 
         if( maTextCharacterProperties.maHyperlinkPropertyMap.empty() )
diff --git a/sw/qa/extras/ooxmlimport/data/dml-charheight-default.docx b/sw/qa/extras/ooxmlimport/data/dml-charheight-default.docx
new file mode 100755
index 0000000..0f22a87
Binary files /dev/null and b/sw/qa/extras/ooxmlimport/data/dml-charheight-default.docx differ
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index 3b3a227..f1e7abd 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -1756,6 +1756,14 @@ DECLARE_OOXMLIMPORT_TEST(testDMLGroupshapeSdt, "dml-groupshape-sdt.docx")
     CPPUNIT_ASSERT_EQUAL(OUString("sdt and sdtContent inside groupshape"), uno::Reference<text::XTextRange>(xGroupShape->getByIndex(1), uno::UNO_QUERY)->getString());
 }
 
+DECLARE_OOXMLIMPORT_TEST(testDmlCharheightDefault, "dml-charheight-default.docx")
+{
+    uno::Reference<container::XIndexAccess> xGroup(getShape(1), uno::UNO_QUERY);
+    uno::Reference<text::XTextRange> xShape(xGroup->getByIndex(0), uno::UNO_QUERY);
+    // This was 16: the first run of the second para incorrectly inherited the char height of the first para.
+    CPPUNIT_ASSERT_EQUAL(11.f, getProperty<float>(getRun(getParagraphOfText(2, xShape->getText()), 1), "CharHeight"));
+}
+
 DECLARE_OOXMLIMPORT_TEST(testGroupshapeRelsize, "groupshape-relsize.docx")
 {
     // This was 43760, i.e. the height of the groupshape was larger than the page height, which is obviously incorrect.


More information about the Libreoffice-commits mailing list