Kaydet (Commit) 9d754a59 authored tarafından Miklos Vajna's avatar Miklos Vajna

sw: give the 'Default Style' char style a programmatic name

So that referring to that style is possible from UNO API client code in
a way that is portable across multiple locales.

This also improves consistency between the default para and default char
styles, as the default para style already had this behavior.

Also add a new CppunitTest_sw_unowriter for such tests which assert the
UNO API from cppunit, instead of hacking this into
CppunitTest_sw_uiwriter.

Change-Id: I0a2b02378dce53c6b79c57780d1b7f14e89242e8
Reviewed-on: https://gerrit.libreoffice.org/57191Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins
üst 5f3914ad
# -*- 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,sw_unowriter))
$(eval $(call gb_CppunitTest_add_exception_objects,sw_unowriter, \
sw/qa/extras/unowriter/unowriter \
))
# note: this links msword only for the reason to have a order dependency,
# because "make sw.check" will not see the dependency through services.rdb
$(eval $(call gb_CppunitTest_use_libraries,sw_unowriter, \
comphelper \
cppu \
cppuhelper \
editeng \
msword \
sal \
sfx \
svl \
svt \
svxcore \
sw \
test \
unotest \
vcl \
tl \
utl \
))
$(eval $(call gb_CppunitTest_use_externals,sw_unowriter,\
boost_headers \
libxml2 \
))
$(eval $(call gb_CppunitTest_set_include,sw_unowriter,\
-I$(SRCDIR)/sw/inc \
-I$(SRCDIR)/sw/source/core/inc \
-I$(SRCDIR)/sw/qa/extras/inc \
$$(INCLUDE) \
))
$(eval $(call gb_CppunitTest_use_api,sw_unowriter,\
udkapi \
offapi \
oovbaapi \
))
$(eval $(call gb_CppunitTest_use_ure,sw_unowriter))
$(eval $(call gb_CppunitTest_use_vcl,sw_unowriter))
$(eval $(call gb_CppunitTest_use_rdb,sw_unowriter,services))
$(eval $(call gb_CppunitTest_use_configuration,sw_unowriter))
$(eval $(call gb_CppunitTest_use_uiconfigs,sw_unowriter, \
modules/swriter \
))
$(call gb_CppunitTest_get_target,sw_unowriter): \
$(call gb_Library_get_target,textconv_dict)
ifneq ($(filter MORE_FONTS,$(BUILD_TYPE)),)
$(call gb_CppunitTest_get_target,sw_unowriter): \
$(call gb_ExternalPackage_get_target,fonts_liberation)
endif
# vim: set noet sw=4 ts=4:
......@@ -94,6 +94,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\
CppunitTest_sw_globalfilter \
CppunitTest_sw_accessible_relation_set \
CppunitTest_sw_apitests \
CppunitTest_sw_unowriter \
))
ifneq ($(ENABLE_HEADLESS),TRUE)
......
/* -*- 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 <swmodeltestbase.hxx>
#include <com/sun/star/awt/FontSlant.hpp>
/// Test to assert UNO API call results of Writer.
class SwUnoWriter : public SwModelTestBase
{
public:
void testDefaultCharStyle();
CPPUNIT_TEST_SUITE(SwUnoWriter);
CPPUNIT_TEST(testDefaultCharStyle);
CPPUNIT_TEST_SUITE_END();
};
void SwUnoWriter::testDefaultCharStyle()
{
// Create a new document, type a character, set its char style to Emphasis
// and assert the style was set.
loadURL("private:factory/swriter", nullptr);
uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
uno::Reference<text::XSimpleText> xBodyText(xTextDocument->getText(), uno::UNO_QUERY);
xBodyText->insertString(xBodyText->getStart(), "x", false);
uno::Reference<text::XTextCursor> xCursor(xBodyText->createTextCursor());
xCursor->goLeft(1, true);
uno::Reference<beans::XPropertySet> xCursorProps(xCursor, uno::UNO_QUERY);
xCursorProps->setPropertyValue("CharStyleName", uno::makeAny(OUString("Emphasis")));
CPPUNIT_ASSERT_EQUAL(awt::FontSlant_ITALIC,
getProperty<awt::FontSlant>(xCursorProps, "CharPosture"));
// Now reset the char style and assert that the font slant is back to none.
// This resulted in a lang.IllegalArgumentException, Standard was not
// mapped to 'Default Style'.
xCursorProps->setPropertyValue("CharStyleName", uno::makeAny(OUString("Standard")));
CPPUNIT_ASSERT_EQUAL(awt::FontSlant_NONE,
getProperty<awt::FontSlant>(xCursorProps, "CharPosture"));
}
CPPUNIT_TEST_SUITE_REGISTRATION(SwUnoWriter);
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -123,7 +123,7 @@ class CheckStyle(unittest.TestCase):
def test_CharacterFamily(self):
xDoc = CheckStyle._uno.openEmptyWriterDoc()
xCharStyles = xDoc.StyleFamilies["CharacterStyles"]
vEmptyDocStyles = ['Default Style', 'Footnote Symbol', 'Page Number', 'Caption characters', 'Drop Caps', 'Numbering Symbols', 'Bullet Symbols', 'Internet link', 'Visited Internet Link', 'Placeholder', 'Index Link', 'Endnote Symbol', 'Line numbering', 'Main index entry', 'Footnote anchor', 'Endnote anchor', 'Rubies', 'Vertical Numbering Symbols', 'Emphasis', 'Citation', 'Strong Emphasis', 'Source Text', 'Example', 'User Entry', 'Variable', 'Definition', 'Teletype']
vEmptyDocStyles = ['Standard', 'Footnote Symbol', 'Page Number', 'Caption characters', 'Drop Caps', 'Numbering Symbols', 'Bullet Symbols', 'Internet link', 'Visited Internet Link', 'Placeholder', 'Index Link', 'Endnote Symbol', 'Line numbering', 'Main index entry', 'Footnote anchor', 'Endnote anchor', 'Rubies', 'Vertical Numbering Symbols', 'Emphasis', 'Citation', 'Strong Emphasis', 'Source Text', 'Example', 'User Entry', 'Variable', 'Definition', 'Teletype']
self.__test_StyleFamily(xCharStyles, vEmptyDocStyles, "SwXStyle")
self.__test_StyleFamilyIndex(xCharStyles, vEmptyDocStyles, "SwXStyle")
self.__test_StyleFamilyInsert(xDoc, xCharStyles, vEmptyDocStyles, "com.sun.star.style.CharacterStyle", "com.sun.star.style.ParagraphStyle")
......
......@@ -22,6 +22,8 @@
#include <SwStyleNameMapper.hxx>
#include <poolfmt.hxx>
#include <strings.hrc>
#include <swtypes.hxx>
#ifdef _NEED_TO_DEBUG_MAPPING
#include <stdlib.h>
......@@ -588,6 +590,9 @@ void SwStyleNameMapper::FillProgName(
// If we aren't trying to disambiguate, then just do a normal fill
fillNameFromId(nId, rFillName, true);
}
if (eFlags == SwGetPoolIdFromName::ChrFmt && rName == SwResId(STR_POOLCOLL_STANDARD))
rFillName = "Standard";
}
// Get the UI name from the programmatic name in rName and put it into rFillName
......@@ -595,11 +600,15 @@ void SwStyleNameMapper::FillUIName(
const OUString& rName, OUString& rFillName,
SwGetPoolIdFromName const eFlags)
{
sal_uInt16 nId = GetPoolIdFromProgName ( rName, eFlags );
OUString aName = rName;
if (eFlags == SwGetPoolIdFromName::ChrFmt && rName == "Standard")
aName = SwResId(STR_POOLCOLL_STANDARD);
sal_uInt16 nId = GetPoolIdFromProgName ( aName, eFlags );
if ( nId == USHRT_MAX )
{
rFillName = rName;
// rName isn't in our Prog name table...check if it has a " (user)" suffix, if so remove it
rFillName = aName;
// aName isn't in our Prog name table...check if it has a " (user)" suffix, if so remove it
lcl_CheckSuffixAndDelete ( rFillName );
}
else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment