core.git: editeng/source include/editeng sw/qa sw/source

2024-06-27 Thread Justin Luth (via logerrit)
 editeng/source/items/svxfont.cxx|6 +
 include/editeng/svxfont.hxx |3 
 sw/qa/extras/ooxmlexport/data/tdf43767_caseMapNumbering.odt |binary
 sw/qa/extras/ooxmlexport/ooxmlexport21.cxx  |   66 
 sw/source/core/text/inftxt.cxx  |3 
 sw/source/core/text/txtfld.cxx  |8 +
 6 files changed, 85 insertions(+), 1 deletion(-)

New commits:
commit 5c6c6a73e9c58ad934a4f89505d5b3e2b781e0b9
Author: Justin Luth 
AuthorDate: Mon Jun 24 13:12:59 2024 -0400
Commit: Justin Luth 
CommitDate: Fri Jun 28 01:24:36 2024 +0200

tdf#43767 mso-format layout: no smallcaps applied to numbering

If the paragraph marker is formatted as Uppercase,
then Uppercase is applied to that line's numbering as well.
However, if the marker is formatted as SmallCaps,
it MUST NOT be applied for MSO formats.

Apparently MSO only supports Uppercase and SmallCaps,
not Lowercase or Titlease.

I don't like these adhoc exceptions, so I didn't
attempt to apply them to ODF formats.
Let's keep it simple for ODF - any char format that applies
to the entire paragraph should apply to numbering as well
(except for the existing underline/overline exceptions).
- if you don't like that char attributes apply at all, blame MSO.
- if you don't like that DOCX is missing your goofy formatting,
  blame MSO for being inconsistent.

ooxmlexport12's tdf143384_tableInFoot_negativeMargins.docx
is almost interesting because it applies superscript
and small caps. However, the list is already uppercase,
so it can't be used for the test.

make CppunitTest_sw_ooxmlexport21 \
CPPUNIT_TEST_NAME=testTdf43767_caseMapNumbering

Change-Id: I273baebc996adfd001e1c591dbb9aef9272a42f0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169476
Reviewed-by: Justin Luth 
Tested-by: Jenkins

diff --git a/editeng/source/items/svxfont.cxx b/editeng/source/items/svxfont.cxx
index 2df18feb449f..3bd2c8086c07 100644
--- a/editeng/source/items/svxfont.cxx
+++ b/editeng/source/items/svxfont.cxx
@@ -670,6 +670,12 @@ SvxFont& SvxFont::operator=( const SvxFont& rFont )
 return *this;
 }
 
+bool SvxFont::SvxFontSubsetEquals(const SvxFont& rFont) const
+{
+return nEsc == rFont.GetEscapement() && nPropr == rFont.GetPropr()
+&& eCaseMap == rFont.GetCaseMap();
+}
+
 namespace {
 
 class SvxDoGetCapitalSize : public SvxDoCapitals
diff --git a/include/editeng/svxfont.hxx b/include/editeng/svxfont.hxx
index 126b56f8f65f..9061ffe398d2 100644
--- a/include/editeng/svxfont.hxx
+++ b/include/editeng/svxfont.hxx
@@ -113,6 +113,9 @@ public:
 
 SvxFont&operator=( const SvxFont& rFont );
 SvxFont&operator=( const Font& rFont );
+
+// returns true if the SvxFont's own properties are equal (the SvxFont 
portion of an operator==)
+bool SvxFontSubsetEquals(const SvxFont& rFont) const;
 };
 
 #endif // INCLUDED_EDITENG_SVXFONT_HXX
diff --git a/sw/qa/extras/ooxmlexport/data/tdf43767_caseMapNumbering.odt 
b/sw/qa/extras/ooxmlexport/data/tdf43767_caseMapNumbering.odt
new file mode 100644
index ..9b9c9a299503
Binary files /dev/null and 
b/sw/qa/extras/ooxmlexport/data/tdf43767_caseMapNumbering.odt differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
index 43dff8ae68cf..9ef569e47683 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
@@ -327,6 +327,72 @@ DECLARE_OOXMLEXPORT_TEST(testTdf158597, "tdf158597.docx")
 }
 }
 
+DECLARE_OOXMLEXPORT_TEST(testTdf43767_caseMapNumbering, 
"tdf43767_caseMapNumbering.odt")
+{
+// given a document with 2 numbered Lists [each entry restarts numbering 
for visual comparison]
+xmlDocUniquePtr pDump = parseLayoutDump();
+
+// using the relative width difference between "A)" and "a)" as the test 
comparison
+// since ListLabelString etc. does not output the actual string that is 
displayed on the screen
+
+// When the entire paragraph has a certain character attribute, that 
property is also applied
+// to the list numbering itself (with some differing exceptions) for both 
ODT and DOCX.
+
+// ESTABLISH A BASELINE: these baseline paragraphs have no special 
character attributes.
+// Paragraph 1/list 1(uppercase): no formatting applied to list numbering. 
Width is 253 for me
+const sal_Int32 nUpperCaseWidth
+= getXPath(pDump, 
"//body/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion"_ostr,
+   "width"_ostr)
+  .toInt32();
+// Paragraph 4/list 2(lowercase): no formatting applied to list numbering. 
Width is 186 for me.
+const sal_Int32 nLowerCaseWidth
+= getXPath(pDump, 
"//body/txt[5]/SwParaPortion/SwLineLayout/SwFieldPortion"_ostr,
+   

core.git: editeng/source include/editeng sw/qa sw/source

2023-12-18 Thread Mike Kaganski (via logerrit)
 editeng/source/misc/svxacorr.cxx  |   22 +-
 include/editeng/svxacorr.hxx  |4 +++-
 sw/qa/extras/uiwriter/data/tdf158703.fodt |   14 ++
 sw/qa/extras/uiwriter/uiwriter8.cxx   |   15 +++
 sw/source/core/edit/autofmt.cxx   |7 ---
 5 files changed, 49 insertions(+), 13 deletions(-)

New commits:
commit 1325d66a7f8657aaf9951a0664fbf14cca86905b
Author: Mike Kaganski 
AuthorDate: Mon Dec 18 17:44:41 2023 +0300
Commit: Mike Kaganski 
CommitDate: Mon Dec 18 18:45:51 2023 +0100

tdf#158703: return updated position from FnAddNonBrkSpace

The paragraph text may become shorter after the function succeeds,
because it may remove arbitrary number of preceding spaces; since
the position may then be used to access data in the string in the
caller, we need to update it, to avoid use of old position (which
may point beyond the string, and produce a crash; or it may point
to a wrong position in it).

Change-Id: Ib1b4b63cbd7150e0f69c97032e3410db7dadd4dc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160924
Tested-by: Jenkins
Reviewed-by: Mike Kaganski 

diff --git a/editeng/source/misc/svxacorr.cxx b/editeng/source/misc/svxacorr.cxx
index f6941d6cc371..ff2c4518aadd 100644
--- a/editeng/source/misc/svxacorr.cxx
+++ b/editeng/source/misc/svxacorr.cxx
@@ -667,12 +667,12 @@ bool SvxAutoCorrect::FnChgToEnEmDash(
 }
 
 // Add non-breaking space before specific punctuation marks in French text
-bool SvxAutoCorrect::FnAddNonBrkSpace(
+sal_Int32 SvxAutoCorrect::FnAddNonBrkSpace(
 SvxAutoCorrDoc& rDoc, std::u16string_view rTxt,
 sal_Int32 nEndPos,
 LanguageType eLang, bool& io_bNbspRunNext )
 {
-bool bRet = false;
+sal_Int32 nRet = -1;
 
 CharClass& rCC = GetCharClass( eLang );
 
@@ -706,7 +706,7 @@ bool SvxAutoCorrect::FnAddNonBrkSpace(
 if (nIndex + nProtocolLen <= rTxt.size())
 {
 if (INetURLObject::CompareProtocolScheme(rTxt.substr(nIndex, 
nProtocolLen)) != INetProtocol::NotValid)
-return false;
+return -1;
 }
 
 // Check the presence of "://" in the word
@@ -734,7 +734,7 @@ bool SvxAutoCorrect::FnAddNonBrkSpace(
 if ( bHasSpace )
 rDoc.Insert( nPos, OUString(cNonBreakingSpace) );
 io_bNbspRunNext = true;
-bRet = true;
+nRet = nPos;
 }
 else if ( chars.indexOf( cPrevChar ) != -1 )
 io_bNbspRunNext = true;
@@ -748,12 +748,12 @@ bool SvxAutoCorrect::FnAddNonBrkSpace(
 if ( cPrevChar == ':' && cMaybeSpaceChar == cNonBreakingSpace )
 {
 rDoc.Delete( nEndPos - 2, nEndPos - 1 );
-bRet = true;
+nRet = nEndPos - 1;
 }
 }
 }
 
-return bRet;
+return nRet;
 }
 
 // URL recognition
@@ -1501,10 +1501,14 @@ void SvxAutoCorrect::DoAutoCorrect( SvxAutoCorrDoc& 
rDoc, const OUString& rTxt,
 // Hardspaces autocorrection
 if ( IsAutoCorrFlag( ACFlags::AddNonBrkSpace ) )
 {
-if ( NeedsHardspaceAutocorr( cChar ) &&
-FnAddNonBrkSpace( rDoc, rTxt, nInsPos, GetDocLanguage( 
rDoc, nInsPos ), io_bNbspRunNext ) )
+// WARNING ATTENTION: rTxt is an alias of the text node's 
OUString
+// and its length may change (even become shorter) if 
FnAddNonBrkSpace succeeds!
+sal_Int32 nUpdatedPos = -1;
+if (NeedsHardspaceAutocorr(cChar))
+nUpdatedPos = FnAddNonBrkSpace( rDoc, rTxt, nInsPos, 
GetDocLanguage( rDoc, nInsPos ), io_bNbspRunNext );
+if (nUpdatedPos >= 0)
 {
-;
+nInsPos = nUpdatedPos;
 }
 else if ( bIsNextRun && !IsAutoCorrectChar( cChar ) )
 {
diff --git a/include/editeng/svxacorr.hxx b/include/editeng/svxacorr.hxx
index 6fe151449170..96415c20d8b6 100644
--- a/include/editeng/svxacorr.hxx
+++ b/include/editeng/svxacorr.hxx
@@ -411,7 +411,9 @@ public:
 bool FnChgToEnEmDash( SvxAutoCorrDoc&, const OUString&,
 sal_Int32 nSttPos, sal_Int32 nEndPos,
 LanguageType eLang );
-bool FnAddNonBrkSpace( SvxAutoCorrDoc&, std::u16string_view,
+// Returns an updated position, at which the insertion/removal happened. 
It may be
+// a smaller value, if leading spaces were removed. If unsuccessful, 
returns -1.
+sal_Int32 FnAddNonBrkSpace( SvxAutoCorrDoc&, std::u16string_view,
 sal_Int32 nEndPos,
 LanguageType eLang, bool& io_bNbspRunNext );
 

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

2021-07-26 Thread Vasily Melenchuk (via logerrit)
 editeng/source/items/numitem.cxx |   10 ++
 include/editeng/numitem.hxx  |2 +-
 sw/qa/core/fields/data/tdf143424.odt |binary
 sw/qa/core/fields/fields.cxx |   34 ++
 sw/source/core/doc/number.cxx|3 ++-
 sw/source/filter/ww8/wrtw8num.cxx|2 +-
 6 files changed, 48 insertions(+), 3 deletions(-)

New commits:
commit d44730148a95933f4a45a70241cb6d1d0546f626
Author: Vasily Melenchuk 
AuthorDate: Wed Jul 21 12:21:07 2021 +0300
Commit: Thorsten Behrens 
CommitDate: Mon Jul 26 15:18:16 2021 +0200

tdf#143424: support for "Chapter number without separator"

If LO is using list format strings (this is default behavior since
aa5c6d12) it was not able to show just numbering without all formatting,
as it used in some fields.

Change-Id: Ib4695b8e1c2d7a451522c7e04af2216d16aceefe
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119309
Reviewed-by: Thorsten Behrens 
Tested-by: Jenkins

diff --git a/editeng/source/items/numitem.cxx b/editeng/source/items/numitem.cxx
index 41ee6e4cf952..2f30242b911a 100644
--- a/editeng/source/items/numitem.cxx
+++ b/editeng/source/items/numitem.cxx
@@ -608,6 +608,16 @@ void 
SvxNumberFormat::SetListFormat(std::optional oSet)
 sSuffix = sListFormat->copy(nLastReplacement);
 }
 
+OUString SvxNumberFormat::GetListFormat(bool bIncludePrefixSuffix /*= true*/) 
const
+{
+assert(sListFormat.has_value());
+
+if (bIncludePrefixSuffix)
+return *sListFormat;
+
+// Strip prefix & suffix from string
+return sListFormat->copy(sPrefix.getLength(), sListFormat->getLength() - 
sPrefix.getLength() - sSuffix.getLength());
+}
 
 OUString SvxNumberFormat::GetCharFormatName()const
 {
diff --git a/include/editeng/numitem.hxx b/include/editeng/numitem.hxx
index bbcbecdf4c79..1846e6a8739c 100644
--- a/include/editeng/numitem.hxx
+++ b/include/editeng/numitem.hxx
@@ -175,7 +175,7 @@ public:
 voidSetListFormat(const OUString& rPrefix, const OUString& 
rSuffix, int nLevel);
 voidSetListFormat(std::optional oSet = std::nullopt);
 boolHasListFormat() const { return sListFormat.has_value(); }
-const OUString& GetListFormat() const { return *sListFormat; }
+OUStringGetListFormat(bool bIncludePrefixSuffix = true) const;
 
 voidSetCharFormatName(const OUString& rSet){ 
sCharStyleName = rSet; }
 virtual OUStringGetCharFormatName()const;
diff --git a/sw/qa/core/fields/data/tdf143424.odt 
b/sw/qa/core/fields/data/tdf143424.odt
new file mode 100644
index ..d485267f12e4
Binary files /dev/null and b/sw/qa/core/fields/data/tdf143424.odt differ
diff --git a/sw/qa/core/fields/fields.cxx b/sw/qa/core/fields/fields.cxx
index 74b94d7a3f8e..7f59597831ea 100644
--- a/sw/qa/core/fields/fields.cxx
+++ b/sw/qa/core/fields/fields.cxx
@@ -10,6 +10,8 @@
 #include 
 
 #include 
+#include 
+#include 
 
 #include 
 
@@ -26,6 +28,8 @@ class Test : public SwModelTestBase
 {
 };
 
+constexpr OUStringLiteral DATA_DIRECTORY = u"/sw/qa/core/fields/data/";
+
 CPPUNIT_TEST_FIXTURE(Test, testAuthorityTooltip)
 {
 // Create a document with a bibliography reference in it.
@@ -62,6 +66,36 @@ CPPUNIT_TEST_FIXTURE(Test, testAuthorityTooltip)
 // first inserting an empty bibliography table into the document.
 CPPUNIT_ASSERT_EQUAL(OUString("ARJ00: Ar, J, mytitle, 2020"), aTooltip);
 }
+
+CPPUNIT_TEST_FIXTURE(Test, testTdf143424)
+{
+createSwDoc(DATA_DIRECTORY, "tdf143424.odt");
+
+uno::Reference xTextFieldsSupplier(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xFieldsAccess(
+xTextFieldsSupplier->getTextFields());
+uno::Reference 
xFields(xFieldsAccess->createEnumeration());
+
+// TODO: I have no idea why fields are enumerated in invalid order, not 
like in document
+
+// Field: Chapter Format: Chapter name
+uno::Reference xField(xFields->nextElement(), 
uno::UNO_QUERY);
+CPPUNIT_ASSERT_EQUAL(OUString("Another title"), 
xField->getPresentation(false));
+
+// Field: Chapter Format: Chapter number and name
+xField.set(xFields->nextElement(), uno::UNO_QUERY);
+CPPUNIT_ASSERT_EQUAL(OUString("Chapter 2 -Another title"), 
xField->getPresentation(false));
+//   ^^ seems here must be a separator
+// Please modify this testcase once this behavior will be fixed. For now I 
just fix and check this behavior
+
+// Field: Chapter Format: Chapter number
+xField.set(xFields->nextElement(), uno::UNO_QUERY);
+CPPUNIT_ASSERT_EQUAL(OUString("Chapter 2 -"), 
xField->getPresentation(false));
+
+// Field: Chapter Format: Chapter number without separator
+xField.set(xFields->nextElement(), uno::UNO_QUERY);
+CPPUNIT_ASSERT_EQUAL(OUString("2"), xField->getPresentation(false));
+}
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/core/doc/number.cxx 

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

2021-02-08 Thread Miklos Vajna (via logerrit)
 editeng/source/items/frmitems.cxx  |5 +
 include/editeng/lrspitem.hxx   |4 
 sw/qa/core/layout/layout.cxx   |   31 +++
 sw/source/core/layout/frmtool.cxx  |   13 +
 sw/source/core/layout/pagedesc.cxx |1 +
 sw/source/core/layout/paintfrm.cxx |   21 +++--
 6 files changed, 69 insertions(+), 6 deletions(-)

New commits:
commit ffe7fd5c3f3de474b201fbb1e25b8251cb13574d
Author: Miklos Vajna 
AuthorDate: Mon Feb 8 16:49:45 2021 +0100
Commit: Miklos Vajna 
CommitDate: Mon Feb 8 17:53:27 2021 +0100

tdf#91920 sw page gutter margin: handle mirrored margins

- SwPageDesc::Mirror: generate "right gutter margin" from gutter margin
  for mirrored pages, we just lost the gutter margin here previously

- SwBorderAttrs::CalcRight: handle right gutter margin, so gutter
increases the right margin, not the left margin on mirrored pages

- lcl_CalcBorderRect: similar to left and top margins, compensate for
  right margin gutter as well, so borders are independent from the gutter
  margin (Word compat)

Change-Id: Ie4d3459ab6edcc60b20c2fed08dbf45060ca9828
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110585
Reviewed-by: Miklos Vajna 
Tested-by: Jenkins

diff --git a/editeng/source/items/frmitems.cxx 
b/editeng/source/items/frmitems.cxx
index c6b26c1c03a5..6e963e91cbaa 100644
--- a/editeng/source/items/frmitems.cxx
+++ b/editeng/source/items/frmitems.cxx
@@ -290,6 +290,7 @@ SvxLRSpaceItem::SvxLRSpaceItem( const sal_uInt16 nId ) :
 nLeftMargin ( 0 ),
 nRightMargin( 0 ),
 m_nGutterMargin(0),
+m_nRightGutterMargin(0),
 nPropFirstLineOffset( 100 ),
 nPropLeftMargin( 100 ),
 nPropRightMargin( 100 ),
@@ -310,6 +311,7 @@ SvxLRSpaceItem::SvxLRSpaceItem( const tools::Long nLeft, 
const tools::Long nRigh
 nLeftMargin ( nLeft ),
 nRightMargin( nRight ),
 m_nGutterMargin(0),
+m_nRightGutterMargin(0),
 nPropFirstLineOffset( 100 ),
 nPropLeftMargin( 100 ),
 nPropRightMargin( 100 ),
@@ -484,6 +486,7 @@ bool SvxLRSpaceItem::operator==( const SfxPoolItem& rAttr ) 
const
 nFirstLineOffset == rOther.GetTextFirstLineOffset() &&
 nTxtLeft == rOther.GetTextLeft() &&
 m_nGutterMargin == rOther.GetGutterMargin() &&
+m_nRightGutterMargin == rOther.GetRightGutterMargin() &&
 nLeftMargin == rOther.GetLeft()  &&
 nRightMargin == rOther.GetRight() &&
 nPropFirstLineOffset == rOther.GetPropTextFirstLineOffset() &&
@@ -608,6 +611,8 @@ void SvxLRSpaceItem::dumpAsXml(xmlTextWriterPtr pWriter) 
const
 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("nRightMargin"), 
BAD_CAST(OString::number(nRightMargin).getStr()));
 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_nGutterMargin"),
 
BAD_CAST(OString::number(m_nGutterMargin).getStr()));
+xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_nRightGutterMargin"),
+
BAD_CAST(OString::number(m_nRightGutterMargin).getStr()));
 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("nPropFirstLineOffset"), 
BAD_CAST(OString::number(nPropFirstLineOffset).getStr()));
 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("nPropLeftMargin"), 
BAD_CAST(OString::number(nPropLeftMargin).getStr()));
 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("nPropRightMargin"), 
BAD_CAST(OString::number(nPropRightMargin).getStr()));
diff --git a/include/editeng/lrspitem.hxx b/include/editeng/lrspitem.hxx
index 9b3ec7734a8e..0510ee47d521 100644
--- a/include/editeng/lrspitem.hxx
+++ b/include/editeng/lrspitem.hxx
@@ -53,6 +53,8 @@ class EDITENG_DLLPUBLIC SvxLRSpaceItem final : public 
SfxPoolItem
 tools::LongnRightMargin;   // The unproblematic right edge
 /// The amount of extra space added to the left margin.
 tools::Longm_nGutterMargin;
+/// The amount of extra space added to the right margin, on mirrored pages.
+tools::Longm_nRightGutterMargin;
 
 sal_uInt16  nPropFirstLineOffset, nPropLeftMargin, nPropRightMargin;
 short   nFirstLineOffset; // First-line indent _always_ relative to 
nTxtLeft
@@ -120,6 +122,8 @@ public:
 { nFirstLineOffset = nValue; }
 void SetGutterMargin(const tools::Long nGutterMargin) { m_nGutterMargin = 
nGutterMargin; }
 tools::Long GetGutterMargin() const { return m_nGutterMargin; }
+void SetRightGutterMargin(const tools::Long nRightGutterMargin) { 
m_nRightGutterMargin = nRightGutterMargin; }
+tools::Long GetRightGutterMargin() const { return m_nRightGutterMargin; }
 
 void dumpAsXml(xmlTextWriterPtr pWriter) const override;
 virtual boost::property_tree::ptree dumpAsJSON() const override;
diff --git a/sw/qa/core/layout/layout.cxx b/sw/qa/core/layout/layout.cxx
index ebf7f816b918..a9a738f26e1d 100644
--- a/sw/qa/core/layout/layout.cxx
+++ 

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

2018-03-15 Thread Mike Kaganski
 editeng/source/items/frmitems.cxx|  125 +
 include/editeng/boxitem.hxx  |   30 ++
 sw/qa/extras/ooxmlexport/data/tdf112118.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport11.cxx   |2 
 sw/qa/extras/ww8export/data/tdf112118.doc|binary
 sw/qa/extras/ww8export/ww8export2.cxx|   31 ++
 sw/source/filter/ww8/docxattributeoutput.cxx |  131 +++
 sw/source/filter/ww8/docxattributeoutput.hxx |   21 
 sw/source/filter/ww8/wrtw8sty.cxx|4 
 sw/source/filter/ww8/ww8atr.cxx  |   40 +---
 sw/source/filter/ww8/ww8attributeoutput.hxx  |6 +
 sw/source/filter/ww8/ww8par6.cxx |   81 
 writerfilter/source/dmapper/PropertyMap.cxx  |   36 +--
 13 files changed, 273 insertions(+), 234 deletions(-)

New commits:
commit 8805e10f5887df66edfd0a2fa4b70e87f0c74700
Author: Mike Kaganski 
Date:   Thu Mar 15 20:48:53 2018 +0300

tdf#112118: DOC: properly import/export border distance

DOCX part was done in fb959e581c900b392efd0bb329b7cf30c8ed56a5.

This commit fixes DOC part. Line width wasn't taken into account on
import; and export was done only with "from text" distance, which
gave poor interoperability with Word, where the borders were close
to page edge.

The common code is moved to editeng/source/items/frmitems.cxx and
include/editeng/boxitem.hxx.

Change-Id: I3d1d1312cb9dc9a9e00d9847ec11234cd787df60
Reviewed-on: https://gerrit.libreoffice.org/51366
Tested-by: Jenkins 
Reviewed-by: Mike Kaganski 

diff --git a/editeng/source/items/frmitems.cxx 
b/editeng/source/items/frmitems.cxx
index 85790110bc78..ea1d15126ff3 100644
--- a/editeng/source/items/frmitems.cxx
+++ b/editeng/source/items/frmitems.cxx
@@ -2592,6 +2592,131 @@ bool SvxBoxInfoItem::PutValue( const uno::Any& rVal, 
sal_uInt8 nMemberId )
 return true;
 }
 
+
+namespace editeng
+{
+
+void BorderDistanceFromWord(bool bFromEdge, sal_Int32& nMargin, sal_Int32& 
nBorderDistance,
+sal_Int32 nBorderWidth)
+{
+// See 
https://wiki.openoffice.org/wiki/Writer/MSInteroperability/PageBorder
+
+sal_Int32 nNewMargin = nMargin;
+sal_Int32 nNewBorderDistance = nBorderDistance;
+
+if (bFromEdge)
+{
+nNewMargin = nBorderDistance;
+nNewBorderDistance = nMargin - nBorderDistance - nBorderWidth;
+}
+else
+{
+nNewMargin -= nBorderDistance + nBorderWidth;
+}
+
+// Ensure correct distance from page edge to text in cases not supported 
by us:
+// when border is outside entire page area (!bFromEdge && BorderDistance > 
Margin),
+// and when border is inside page body area (bFromEdge && BorderDistance > 
Margin)
+if (nNewMargin < 0)
+{
+nNewMargin = 0;
+nNewBorderDistance = std::max(nMargin - nBorderWidth, 0);
+}
+else if (nNewBorderDistance < 0)
+{
+nNewMargin = std::max(nMargin - nBorderWidth, 0);
+nNewBorderDistance = 0;
+}
+
+nMargin = nNewMargin;
+nBorderDistance = nNewBorderDistance;
+}
+
+// Heuristics to decide if we need to use "from edge" offset of borders
+//
+// There are two cases when we can safely use "from text" or "from edge" 
offset without distorting
+// border position (modulo rounding errors):
+// 1. When distance of all borders from text is no greater than 31 pt, we use 
"from text"
+// 2. Otherwise, if distance of all borders from edge is no greater than 31 
pt, we use "from edge"
+// In all other cases, the position of borders would be distirted on export, 
because Word doesn't
+// support the offset of >31 pts 
(https://msdn.microsoft.com/en-us/library/ff533820), and we need
+// to decide which type of offset would provide less wrong result (i.e., the 
result would look
+// closer to original). Here, we just check sum of distances from text to 
borders, and if it is
+// less than sum of distances from borders to edges. The alternative would be 
to compare total areas
+// between text-and-borders and between borders-and-edges (taking into account 
different lengths of
+// borders, and visual impact of that).
+void BorderDistancesToWord(const SvxBoxItem& rBox, const WordPageMargins& 
rMargins,
+WordBorderDistances& rDistances)
+{
+// Use signed sal_Int32 that can hold sal_uInt16, to prevent overflow at 
substraction below
+const sal_Int32 nT = rBox.GetDistance(SvxBoxItemLine::TOP);
+const sal_Int32 nL = rBox.GetDistance(SvxBoxItemLine::LEFT);
+const sal_Int32 nB = rBox.GetDistance(SvxBoxItemLine::BOTTOM);
+const sal_Int32 nR = rBox.GetDistance(SvxBoxItemLine::RIGHT);
+
+// Only take into account existing borders
+const SvxBorderLine* pLnT = rBox.GetLine(SvxBoxItemLine::TOP);
+const SvxBorderLine* pLnL = rBox.GetLine(SvxBoxItemLine::LEFT);
+const SvxBorderLine* pLnB = 

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

2016-09-13 Thread Miklos Vajna
 editeng/source/editeng/editview.cxx|7 +++
 editeng/source/editeng/impedit.cxx |   17 +
 include/editeng/editview.hxx   |2 ++
 sw/qa/extras/tiledrendering/tiledrendering.cxx |   12 
 sw/source/core/crsr/crsrsh.cxx |3 +++
 5 files changed, 37 insertions(+), 4 deletions(-)

New commits:
commit 2ea385a54b53797ab3960869012f3ce3268eab2c
Author: Miklos Vajna 
Date:   Tue Sep 13 16:49:03 2016 +0200

sw draw text: emit LOK_CALLBACK_TEXT_VIEW_SELECTION from registerCallback()

With this, in case the first view has an active text edit selection and
a new view is created, then the text selection is instantly visible in
the second view, even if the first view's text selection does not change
later.

Change-Id: I3255febd5d65d6576ddbc57cf96836bdf0b06a72

diff --git a/editeng/source/editeng/editview.cxx 
b/editeng/source/editeng/editview.cxx
index f7f01f1..4915078 100644
--- a/editeng/source/editeng/editview.cxx
+++ b/editeng/source/editeng/editview.cxx
@@ -1353,4 +1353,11 @@ void EditView::SetCursorLogicPosition(const Point& 
rPosition, bool bPoint, bool
 ShowCursor(/*bGotoCursor=*/false);
 }
 
+void EditView::DrawSelection(OutlinerViewShell* pOtherShell)
+{
+pImpEditView->RegisterOtherShell(pOtherShell);
+pImpEditView->DrawSelection();
+pImpEditView->RegisterOtherShell(nullptr);
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/editeng/source/editeng/impedit.cxx 
b/editeng/source/editeng/impedit.cxx
index c0d9201..b04a491 100644
--- a/editeng/source/editeng/impedit.cxx
+++ b/editeng/source/editeng/impedit.cxx
@@ -377,8 +377,8 @@ void ImpEditView::DrawSelection( EditSelection aTmpSel, 
vcl::Region* pRegion, Ou
 aOrigin = pOutWin->GetMapMode().GetOrigin();
 
 OString sRectangle;
-// If we are not in selection mode, then the exported selection 
should be empty.
-if (pEditEngine->pImpEditEngine->IsInSelectionMode())
+// If we are not in selection mode, then the exported own 
selection should be empty.
+if (pEditEngine->pImpEditEngine->IsInSelectionMode() || 
mpOtherShell)
 {
 std::vector aRectangles;
 pRegion->GetRegionRectangles(aRectangles);
@@ -413,8 +413,17 @@ void ImpEditView::DrawSelection( EditSelection aTmpSel, 
vcl::Region* pRegion, Ou
 sRectangle = comphelper::string::join("; ", v);
 }
 
-
mpViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_TEXT_SELECTION, 
sRectangle.getStr());
-mpViewShell->NotifyOtherViews(LOK_CALLBACK_TEXT_VIEW_SELECTION, 
"selection", sRectangle);
+if (mpOtherShell)
+{
+// An other shell wants to know about our existing selection.
+if (mpViewShell != mpOtherShell)
+mpViewShell->NotifyOtherView(mpOtherShell, 
LOK_CALLBACK_TEXT_VIEW_SELECTION, "selection", sRectangle);
+}
+else
+{
+
mpViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_TEXT_SELECTION, 
sRectangle.getStr());
+
mpViewShell->NotifyOtherViews(LOK_CALLBACK_TEXT_VIEW_SELECTION, "selection", 
sRectangle);
+}
 
 pOutWin->Pop();
 }
diff --git a/include/editeng/editview.hxx b/include/editeng/editview.hxx
index df5..0f3c2de 100644
--- a/include/editeng/editview.hxx
+++ b/include/editeng/editview.hxx
@@ -260,6 +260,8 @@ public:
 bool bIsParaText );
 /// Allows adjusting the point or mark of the selection to a document 
coordinate.
 void SetCursorLogicPosition(const Point& rPosition, bool bPoint, bool 
bClearMark);
+/// Trigger selection drawing callback in pOtherShell based on our shell's 
selection state.
+void DrawSelection(OutlinerViewShell* pOtherShell);
 };
 
 #endif // INCLUDED_EDITENG_EDITVIEW_HXX
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx 
b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index 0424fea..eeef56d 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -1194,16 +1194,28 @@ void 
SwTiledRenderingTest::testShapeTextUndoGroupShells()
 // This was -1: the view shell id for the (top) undo list action wasn't 
known.
 CPPUNIT_ASSERT_EQUAL(nView1, 
rUndoManager.GetUndoAction()->GetViewShellId());
 
+// Create an editeng text selection in the first view.
+EditView& rEditView = pView->GetTextEditOutlinerView()->GetEditView();
+pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 'x', 0);
+pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 'x', 0);
+// 0th para, 0th char -> 0th para, 1st char.
+ESelection aWordSelection(0, 0, 0, 1);
+rEditView.SetSelection(aWordSelection);
+
 // Create a second view, and make sure that the new view sees 

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

2014-02-13 Thread Tushar Bende
 editeng/source/items/frmitems.cxx   |   12 +---
 include/editeng/lrspitem.hxx|   17 +
 sw/qa/extras/ooxmlexport/data/test_indentation.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport.cxx|   12 
 sw/source/filter/ww8/docxattributeoutput.cxx|   12 
 5 files changed, 46 insertions(+), 7 deletions(-)

New commits:
commit d9809c68f62af3b594854b142e1db5171804158d
Author: Tushar Bende tushar.be...@synerzip.com
Date:   Mon Feb 3 16:44:08 2014 +0530

fdo#74141 :In w:ind Right margin gets added even if not present in orig 
doc.

There was a problem that in style.xml and document.xml in w:ind tag 
right  left margin
attributes gets added(w:right=0  w:left=0),if these attributes are not set 
in original document.
(In this case LO should not write these attributes in w:ind)

eg. if original doc has implicit right and left indentation values set(In 
style.xml) and there is no
explicit values provided for some para (In document.xml) still it used to 
write w:right=0 and w:left=0
in w:ind tag of document.xml which overrides an entry from style.xml.

XML difference :
- Original file:
w:ind w:left=567 /
- Roundtrip file Before Fix:
w:ind w:left=567 w:right=0 w:hanging=0/
- Roundtrip file After Fix:
w:ind w:left=567 w:hanging=0/

Conflicts:
sw/qa/extras/ooxmlexport/ooxmlexport.cxx
Reviewed on:
https://gerrit.libreoffice.org/7816

Change-Id: Ifa01bae24d48bb38d5e255356247c46a43beefcc

diff --git a/editeng/source/items/frmitems.cxx 
b/editeng/source/items/frmitems.cxx
index 6eb012a..7f2cf42 100644
--- a/editeng/source/items/frmitems.cxx
+++ b/editeng/source/items/frmitems.cxx
@@ -420,7 +420,9 @@ SvxLRSpaceItem::SvxLRSpaceItem( const sal_uInt16 nId ) :
 nPropFirstLineOfst( 100 ),
 nPropLeftMargin( 100 ),
 nPropRightMargin( 100 ),
-bAutoFirst  ( 0 )
+bAutoFirst  ( 0 ),
+bExplicitZeroMarginValRight(sal_False),
+bExplicitZeroMarginValLeft(sal_False)
 {
 }
 
@@ -439,7 +441,9 @@ SvxLRSpaceItem::SvxLRSpaceItem( const long nLeft, const 
long nRight,
 nPropFirstLineOfst( 100 ),
 nPropLeftMargin( 100 ),
 nPropRightMargin( 100 ),
-bAutoFirst  ( 0 )
+bAutoFirst  ( 0 ),
+bExplicitZeroMarginValRight(sal_False),
+bExplicitZeroMarginValLeft(sal_False)
 {
 }
 
@@ -574,7 +578,9 @@ bool SvxLRSpaceItem::operator==( const SfxPoolItem rAttr ) 
const
 nPropFirstLineOfst == rOther.GetPropTxtFirstLineOfst() 
 nPropLeftMargin == rOther.GetPropLeft()  
 nPropRightMargin == rOther.GetPropRight() 
-bAutoFirst == rOther.IsAutoFirst() );
+bAutoFirst == rOther.IsAutoFirst() 
+bExplicitZeroMarginValRight == rOther.IsExplicitZeroMarginValRight() 
+bExplicitZeroMarginValLeft == rOther.IsExplicitZeroMarginValLeft() );
 }
 
 // ---
diff --git a/include/editeng/lrspitem.hxx b/include/editeng/lrspitem.hxx
index d56b268..a18b4ea 100644
--- a/include/editeng/lrspitem.hxx
+++ b/include/editeng/lrspitem.hxx
@@ -57,10 +57,13 @@ class EDITENG_DLLPUBLIC SvxLRSpaceItem : public SfxPoolItem
 
 sal_uInt16  nPropFirstLineOfst, nPropLeftMargin, nPropRightMargin;
 sal_BoolbAutoFirst  : 1;// Automatic calculation of the first line 
indent
+sal_Bool bExplicitZeroMarginValRight;
+sal_Bool bExplicitZeroMarginValLeft;
 
 void   AdjustLeft();// nLeftMargin and nTxtLeft are being adjusted.
 
 public:
+
 TYPEINFO();
 
 explicit SvxLRSpaceItem( const sal_uInt16 nId  );
@@ -99,6 +102,10 @@ public:
 inline sal_Bool IsAutoFirst()  const { return bAutoFirst; }
 inline void SetAutoFirst( const sal_Bool bNew ) { bAutoFirst = bNew; }
 
+inline sal_Bool IsExplicitZeroMarginValRight()  const { return 
bExplicitZeroMarginValRight; }
+inline sal_Bool IsExplicitZeroMarginValLeft()  const { return 
bExplicitZeroMarginValLeft; }
+inline void SetExplicitZeroMarginValRight( const sal_Bool eR ) { 
bExplicitZeroMarginValRight = eR; }
+inline void SetExplicitZeroMarginValLeft( const sal_Bool eL ) { 
bExplicitZeroMarginValLeft = eL; }
 // Query/Setting the percentage values
 inline void SetPropLeft( const sal_uInt16 nProp = 100 )
 { nPropLeftMargin = nProp; }
@@ -131,6 +138,8 @@ inline SvxLRSpaceItem SvxLRSpaceItem::operator=( const 
SvxLRSpaceItem rCpy )
 nPropLeftMargin = rCpy.nPropLeftMargin;
 nPropRightMargin = rCpy.nPropRightMargin;
 bAutoFirst = rCpy.bAutoFirst;
+bExplicitZeroMarginValRight = rCpy.bExplicitZeroMarginValRight;
+bExplicitZeroMarginValLeft = rCpy.bExplicitZeroMarginValLeft;
 return *this;
 }
 
@@ -142,6 +151,10 @@ inline void SvxLRSpaceItem::SetLeft( const long nL, const 
sal_uInt16 nProp )
 }
 inline void SvxLRSpaceItem::SetRight( const long nR, const sal_uInt16