include/svx/svdotext.hxx                  |   10 ++++++
 svx/CppunitTest_svx_unit.mk               |   32 ++++++++++++++++++++
 svx/Module_svx.mk                         |    4 ++
 svx/qa/unit/svdraw/test_SdrTextObject.cxx |   48 ++++++++++++++++++++++++++++++
 svx/source/svdraw/svdotxat.cxx            |   43 ++++++++++++++++++--------
 5 files changed, 123 insertions(+), 14 deletions(-)

New commits:
commit 5013ac55090ab7a64b9549df67196aa5c7479542
Author: Tobias Lippert <d...@fastmail.fm>
Date:   Thu Aug 7 22:30:58 2014 +0200

    fdo#84061 Fix setting text style sheet listeners in SdrTextObj
    
    The code in SdrTextObj::ImpSetTextStyleSheetListeners is obviously not
    working correctly.
    
    The families of the stylesheets are appended to the name of the family
    for further usage.
    An encoded string looks like "STYLE_NAME|3     "
    The family is then extracted by copying the first (length-6) bytes,
    e.g., "STYLE_NAME" in this example. Then another copy starting a
    position 1 is created, e.g., "TYLE_NAME". This string is cast to an
    Int32. Since this is not possible, 0 is returned, and the originally
    stored family is lost.
    
    This patch corrects this behavior, and adds a unit test.
    
    Change-Id: I60c0add6e4b670acbbc264cc77672452f282f737
    Reviewed-on: https://gerrit.libreoffice.org/10818
    Reviewed-by: Matúš Kukan <matus.ku...@collabora.com>
    Tested-by: Matúš Kukan <matus.ku...@collabora.com>

diff --git a/include/svx/svdotext.hxx b/include/svx/svdotext.hxx
index 9922e5e..a2b7b1f 100644
--- a/include/svx/svdotext.hxx
+++ b/include/svx/svdotext.hxx
@@ -25,6 +25,7 @@
 #include <svx/svdoattr.hxx>
 #include <svx/svdtrans.hxx>
 #include <tools/datetime.hxx>
+#include <rsc/rscsfx.hxx>
 #include <svx/xtextit0.hxx>
 #include <svx/svdtext.hxx>
 #include <vector>
@@ -40,6 +41,7 @@
 class OutlinerParaObject;
 class SdrOutliner;
 class SdrTextObj;
+class SdrTextObjTest;
 class SvxFieldItem;
 class ImpSdrObjTextLink;
 class EditStatus;
@@ -271,6 +273,12 @@ private:
     SVX_DLLPRIVATE ImpSdrObjTextLinkUserData* GetLinkUserData() const;
 //  void ImpCheckItemSetChanges(const SfxItemSet& rAttr);
 
+    /** Appends the style family to a provided style name */
+    static void AppendFamilyToStyleName(OUString& styleName, SfxStyleFamily 
family);
+
+    /** Reads the style family from a style name to which the family has been 
appended. */
+    static SfxStyleFamily ReadFamilyFromStyleName(const OUString& styleName);
+
 protected:
     bool ImpCanConvTextToCurve() const;
     SdrObject* ImpConvertMakeObj(const basegfx::B2DPolyPolygon& rPolyPolygon, 
bool bClosed, bool bBezier, bool bNoSetAttr = false) const;
@@ -591,6 +599,8 @@ public:
         Also checks for one empty paragraph.
     */
     static bool HasTextImpl( SdrOutliner* pOutliner );
+
+    friend class ::SdrTextObjTest;
 };
 
 
diff --git a/svx/CppunitTest_svx_unit.mk b/svx/CppunitTest_svx_unit.mk
new file mode 100644
index 0000000..82d9cd4
--- /dev/null
+++ b/svx/CppunitTest_svx_unit.mk
@@ -0,0 +1,32 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_CppunitTest_CppunitTest,svx_unit))
+
+$(eval $(call gb_CppunitTest_use_external,svx_unit,boost_headers))
+
+$(eval $(call gb_CppunitTest_use_api,svx_unit, \
+       offapi \
+       udkapi \
+))
+
+$(eval $(call gb_CppunitTest_set_include,svx_unit,\
+       $$(INCLUDE) \
+))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,svx_unit, \
+       svx/qa/unit/svdraw/test_SdrTextObject \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,svx_unit, \
+       sal \
+       svxcore \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/svx/Module_svx.mk b/svx/Module_svx.mk
index 492f6f7..67dbe01 100644
--- a/svx/Module_svx.mk
+++ b/svx/Module_svx.mk
@@ -32,6 +32,10 @@ $(eval $(call gb_Module_add_l10n_targets,svx,\
     UIConfig_svx \
 ))
 
+$(eval $(call gb_Module_add_check_targets,svx,\
+       CppunitTest_svx_unit \
+))
+
 ifneq (,$(filter DESKTOP,$(BUILD_TYPE)))
 $(eval $(call gb_Module_add_targets,svx,\
     Executable_gengal \
diff --git a/svx/qa/unit/svdraw/test_SdrTextObject.cxx 
b/svx/qa/unit/svdraw/test_SdrTextObject.cxx
new file mode 100644
index 0000000..fe16805
--- /dev/null
+++ b/svx/qa/unit/svdraw/test_SdrTextObject.cxx
@@ -0,0 +1,48 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <svx/svdotext.hxx>
+#include <rtl/ustring.hxx>
+
+#include <cppunit/TestAssert.h>
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/plugin/TestPlugIn.h>
+
+#include <boost/foreach.hpp>
+
+class SdrTextObjTest : public CppUnit::TestFixture {
+public:
+    void AllFamiliesCanBeRestoredFromSavedString();
+
+    CPPUNIT_TEST_SUITE(SdrTextObjTest);
+    CPPUNIT_TEST(AllFamiliesCanBeRestoredFromSavedString);
+    CPPUNIT_TEST_SUITE_END();
+};
+
+void SdrTextObjTest::AllFamiliesCanBeRestoredFromSavedString() {
+    std::vector<SfxStyleFamily> allFamilies;
+    allFamilies.push_back(SFX_STYLE_FAMILY_CHAR);
+    allFamilies.push_back(SFX_STYLE_FAMILY_PARA);
+    allFamilies.push_back(SFX_STYLE_FAMILY_PAGE);
+    allFamilies.push_back(SFX_STYLE_FAMILY_PSEUDO);
+
+    BOOST_FOREACH(SfxStyleFamily family, allFamilies) {
+      OUString styleName = "styleName";
+      SdrTextObj::AppendFamilyToStyleName(styleName, family);
+      SfxStyleFamily readFamily = 
SdrTextObj::ReadFamilyFromStyleName(styleName);
+      CPPUNIT_ASSERT_EQUAL(family, readFamily);
+    }
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(SdrTextObjTest);
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/svdraw/svdotxat.cxx b/svx/source/svdraw/svdotxat.cxx
index 986ef36..161f9f9 100644
--- a/svx/source/svdraw/svdotxat.cxx
+++ b/svx/source/svdraw/svdotxat.cxx
@@ -50,6 +50,12 @@
 
 #include <set>
 
+namespace {
+// The style family which is appended to the style names is padded to this 
many characters.
+const short PADDING_LENGTH_FOR_STYLE_FAMILY = 5;
+// this character will be used to pad the style families when they are 
appended to the style names
+const sal_Char PADDING_CHARACTER_FOR_STYLE_FAMILY = ' ';
+}
 
 bool SdrTextObj::AdjustTextFrameWidthAndHeight(Rectangle& rR, bool bHgt, bool 
bWdt) const
 {
@@ -236,18 +242,14 @@ void SdrTextObj::ImpSetTextStyleSheetListeners()
             SfxStyleFamily eStyleFam;
             sal_Int32 nParaAnz=rTextObj.GetParagraphCount();
 
+
             for(sal_Int32 nParaNum(0); nParaNum < nParaAnz; nParaNum++)
             {
                 rTextObj.GetStyleSheet(nParaNum, aStyleName, eStyleFam);
 
                 if (!aStyleName.isEmpty())
                 {
-                    OUStringBuffer aFam;
-                    aFam.append(static_cast<sal_Int32>(eStyleFam));
-                    comphelper::string::padToLength(aFam, 5, ' ');
-
-                    aStyleName += OUString('|');
-                    aStyleName += aFam.makeStringAndClear();
+                    AppendFamilyToStyleName(aStyleName, eStyleFam);
 
                     bool bFnd(false);
                     sal_uInt32 nNum(aStyleNames.size());
@@ -273,14 +275,7 @@ void SdrTextObj::ImpSetTextStyleSheetListeners()
             OUString aName = aStyleNames.back();
             aStyleNames.pop_back();
 
-            OUString aFam = aName.copy(0, aName.getLength() - 6);
-
-            aFam = aFam.copy(1);
-            aFam = comphelper::string::stripEnd(aFam, ' ');
-
-            sal_uInt16 nFam = (sal_uInt16)aFam.toInt32();
-
-            SfxStyleFamily eFam = (SfxStyleFamily)nFam;
+            SfxStyleFamily eFam = ReadFamilyFromStyleName(aName);
             SfxStyleSheetBase* pStyleBase = pStylePool->Find(aName,eFam);
             SfxStyleSheet* pStyle = PTR_CAST(SfxStyleSheet,pStyleBase);
             if (pStyle!=NULL && pStyle!=GetStyleSheet()) {
@@ -372,4 +367,24 @@ bool SdrTextObj::HasText() const
     return bHasText;
 }
 
+void SdrTextObj::AppendFamilyToStyleName(OUString& styleName, SfxStyleFamily 
family)
+{
+    OUStringBuffer aFam;
+    aFam.append(static_cast<sal_Int32>(family));
+    comphelper::string::padToLength(aFam, PADDING_LENGTH_FOR_STYLE_FAMILY , 
PADDING_CHARACTER_FOR_STYLE_FAMILY);
+
+    styleName += OUString('|');
+    styleName += aFam.makeStringAndClear();
+}
+
+SfxStyleFamily SdrTextObj::ReadFamilyFromStyleName(const OUString& styleName)
+{
+    OUString familyString = styleName.copy(styleName.getLength() - 
PADDING_LENGTH_FOR_STYLE_FAMILY);
+    familyString = comphelper::string::stripEnd(familyString, 
PADDING_CHARACTER_FOR_STYLE_FAMILY);
+    sal_uInt16 nFam = static_cast<sal_uInt16>(familyString.toInt32());
+    assert(nFam != 0);
+    return static_cast<SfxStyleFamily>(nFam);
+}
+
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to