summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Lippert <drtl@fastmail.fm>2014-08-07 22:30:58 +0200
committerMatúš Kukan <matus.kukan@collabora.com>2014-09-19 21:53:55 +0000
commit5013ac55090ab7a64b9549df67196aa5c7479542 (patch)
treeb8305cc98935855ae69413b6afd1f1805591df41
parent234b5de79fd10bd99b75d7b968581af7b6ffe44b (diff)
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.kukan@collabora.com> Tested-by: Matúš Kukan <matus.kukan@collabora.com>
-rw-r--r--include/svx/svdotext.hxx10
-rw-r--r--svx/CppunitTest_svx_unit.mk32
-rw-r--r--svx/Module_svx.mk4
-rw-r--r--svx/qa/unit/svdraw/test_SdrTextObject.cxx48
-rw-r--r--svx/source/svdraw/svdotxat.cxx43
5 files changed, 123 insertions, 14 deletions
diff --git a/include/svx/svdotext.hxx b/include/svx/svdotext.hxx
index 9922e5e17ce8..a2b7b1f3e21c 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 000000000000..82d9cd48a4b2
--- /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 492f6f70b9f4..67dbe017d442 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 000000000000..fe16805ade14
--- /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 986ef3665138..161f9f95ebee 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: */