summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Hung <marklh9@gmail.com>2015-05-14 23:02:21 +0800
committerCaolán McNamara <caolanm@redhat.com>2015-05-25 14:55:53 +0000
commit5ad8c6c313f3d540f93742e9308a2773937b3120 (patch)
tree3756fd388556134d9260b9c2f60b0511b4bc23a5
parent2a407768564ddf05b1b2cdd373b8e32091575acb (diff)
tdf#91261: DOCX import: snapGrid property of paragraphs are ignored
Fix the situation for OOXML import filter: a) While handling DocGrid type, SnapToChars was treated as None. Now it is implemented as described in the article: http://linpeifeng.blogspot.tw/2007/02/text-grid-enhancement.html Both LinesAndChars and SnapToChars will be translated to Writer grid type "lines and characters", and set SnapToGrid property to false or true accordingly. b) All the imported paragraphs snap to grid because SnapToGrid was appended to grabbag, now it allows SnapToGrid property in paragraph and paragraph styles to be imported properly. Reviewed-on: https://gerrit.libreoffice.org/15732 Reviewed-by: Michael Stahl <mstahl@redhat.com> Tested-by: Michael Stahl <mstahl@redhat.com> (cherry picked from commit b7c8c337d4ffad55fe111c9634c4c04afce78bad) Conflicts: sw/qa/extras/ooxmlexport/ooxmlexport.cxx Change-Id: I446b4c64c0ed86960896bcd61a1006c9173a757a Reviewed-on: https://gerrit.libreoffice.org/15843 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--sw/qa/extras/ooxmlexport/data/tdf91261.docxbin0 -> 22081 bytes
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport.cxx19
-rw-r--r--writerfilter/source/dmapper/DomainMapper.cxx21
-rw-r--r--writerfilter/source/dmapper/PropertyIds.cxx2
-rw-r--r--writerfilter/source/dmapper/PropertyIds.hxx2
-rw-r--r--writerfilter/source/dmapper/PropertyMap.cxx5
-rw-r--r--writerfilter/source/dmapper/PropertyMap.hxx2
7 files changed, 46 insertions, 5 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/tdf91261.docx b/sw/qa/extras/ooxmlexport/data/tdf91261.docx
new file mode 100644
index 000000000000..6edb8b8755d7
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/tdf91261.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index 5e05f6a08c92..e43cf9002e55 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -613,6 +613,25 @@ DECLARE_OOXMLEXPORT_TEST(testTdf88583, "tdf88583.odt")
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0x00cc00), getProperty<sal_Int32>(getParagraph(1), "FillColor"));
}
+DECLARE_OOXMLEXPORT_TEST(testTdf91261, "tdf91261.docx")
+{
+ bool snapToGrid = true;
+ uno::Reference< text::XTextRange > xPara = getParagraph( 2 );
+ uno::Reference< beans::XPropertySet > properties( xPara, uno::UNO_QUERY);
+ properties->getPropertyValue("SnapToGrid") >>= snapToGrid ;
+ CPPUNIT_ASSERT_EQUAL(false, snapToGrid);
+
+ uno::Reference< beans::XPropertySet> xStyle(getStyles("PageStyles")->getByName("Standard"), uno::UNO_QUERY);
+ sal_Int16 nGridMode;
+ xStyle->getPropertyValue("GridMode") >>= nGridMode;
+ CPPUNIT_ASSERT_EQUAL( sal_Int16(2), nGridMode);
+
+ bool bGridSnapToChars;
+ xStyle->getPropertyValue("GridSnapToChars") >>= bGridSnapToChars;
+ CPPUNIT_ASSERT_EQUAL(true, bGridSnapToChars);
+
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index ad477c52221e..e1c595454f33 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -918,14 +918,18 @@ void DomainMapper::lcl_attribute(Id nName, Value & val)
switch( nIntValue )
{
case NS_ooxml::LN_Value_doc_ST_DocGrid_default:
- case NS_ooxml::LN_Value_doc_ST_DocGrid_snapToChars:
- pSectionContext->SetGridType( 0 );
+ pSectionContext->SetGridType(text::TextGridMode::NONE);
break;
case NS_ooxml::LN_Value_doc_ST_DocGrid_lines:
- pSectionContext->SetGridType( 1 );
+ pSectionContext->SetGridType(text::TextGridMode::LINES);
break;
case NS_ooxml::LN_Value_doc_ST_DocGrid_linesAndChars:
- pSectionContext->SetGridType( 2 );
+ pSectionContext->SetGridType(text::TextGridMode::LINES_AND_CHARS);
+ pSectionContext->SetGridSnapToChars( false );
+ break;
+ case NS_ooxml::LN_Value_doc_ST_DocGrid_snapToChars:
+ pSectionContext->SetGridType(text::TextGridMode::LINES_AND_CHARS);
+ pSectionContext->SetGridSnapToChars( true );
break;
default :
OSL_FAIL("unknown SwTextGrid value");
@@ -1983,7 +1987,14 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, PropertyMapPtr rContext )
break;
case NS_ooxml::LN_CT_PPrBase_snapToGrid:
- m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "snapToGrid", OUString::number(nIntValue));
+ if (!IsStyleSheetImport()||!m_pImpl->isInteropGrabBagEnabled())
+ {
+ rContext->Insert( PROP_SNAP_TO_GRID, uno::makeAny(bool(nIntValue)));
+ }
+ else
+ {
+ m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "snapToGrid", OUString::number(nIntValue));
+ }
break;
case NS_ooxml::LN_CT_PPrBase_pStyle:
{
diff --git a/writerfilter/source/dmapper/PropertyIds.cxx b/writerfilter/source/dmapper/PropertyIds.cxx
index f380c457c8a0..9247989a42cf 100644
--- a/writerfilter/source/dmapper/PropertyIds.cxx
+++ b/writerfilter/source/dmapper/PropertyIds.cxx
@@ -403,6 +403,8 @@ OUString PropertyNameSupplier::GetName( PropertyIds eId ) const
case PROP_FOLLOW_TEXT_FLOW: sName = "IsFollowingTextFlow"; break;
case PROP_FILL_STYLE: sName = "FillStyle"; break;
case PROP_FILL_COLOR: sName = "FillColor"; break;
+ case PROP_SNAP_TO_GRID: sName = "SnapToGrid"; break;
+ case PROP_GRID_SNAP_TO_CHARS: sName = "GridSnapToChars"; break;
}
::std::pair<PropertyNameMap_t::iterator,bool> aInsertIt =
m_pImpl->aNameMap.insert( PropertyNameMap_t::value_type( eId, sName ));
diff --git a/writerfilter/source/dmapper/PropertyIds.hxx b/writerfilter/source/dmapper/PropertyIds.hxx
index cd52d488fbbc..e7927eea6b79 100644
--- a/writerfilter/source/dmapper/PropertyIds.hxx
+++ b/writerfilter/source/dmapper/PropertyIds.hxx
@@ -375,6 +375,8 @@ enum PropertyIds
,PROP_FOLLOW_TEXT_FLOW
,PROP_FILL_STYLE
,PROP_FILL_COLOR
+ ,PROP_SNAP_TO_GRID
+ ,PROP_GRID_SNAP_TO_CHARS
};
struct PropertyNameSupplier_Impl;
class PropertyNameSupplier
diff --git a/writerfilter/source/dmapper/PropertyMap.cxx b/writerfilter/source/dmapper/PropertyMap.cxx
index f1f3a65c9ac6..845dbe6cd2a2 100644
--- a/writerfilter/source/dmapper/PropertyMap.cxx
+++ b/writerfilter/source/dmapper/PropertyMap.cxx
@@ -435,6 +435,7 @@ SectionPropertyMap::SectionPropertyMap(bool bIsFirstSection) :
,m_nGridType(0)
,m_nGridLinePitch( 1 )
,m_nDxtCharSpace( 0 )
+ ,m_bGridSnapToChars(true)
,m_nLnnMod( 0 )
,m_nLnc( 0 )
,m_ndxaLnn( 0 )
@@ -1177,6 +1178,10 @@ void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl )
// PROP_GRID_MODE
Insert( PROP_GRID_MODE, uno::makeAny( static_cast<sal_Int16> (m_nGridType) ));
+ if (m_nGridType == text::TextGridMode::LINES_AND_CHARS)
+ {
+ Insert( PROP_GRID_SNAP_TO_CHARS, uno::makeAny(m_bGridSnapToChars));
+ }
sal_Int32 nCharWidth = 423; //240 twip/ 12 pt
//todo: is '0' the right index here?
diff --git a/writerfilter/source/dmapper/PropertyMap.hxx b/writerfilter/source/dmapper/PropertyMap.hxx
index 36d770529f86..fd612677f6cb 100644
--- a/writerfilter/source/dmapper/PropertyMap.hxx
+++ b/writerfilter/source/dmapper/PropertyMap.hxx
@@ -230,6 +230,7 @@ class SectionPropertyMap : public PropertyMap
sal_Int32 m_nGridType;
sal_Int32 m_nGridLinePitch;
sal_Int32 m_nDxtCharSpace;
+ bool m_bGridSnapToChars;
//line numbering
sal_Int32 m_nLnnMod;
@@ -309,6 +310,7 @@ public:
void SetGridType(sal_Int32 nSet) { m_nGridType = nSet; }
void SetGridLinePitch( sal_Int32 nSet ) { m_nGridLinePitch = nSet; }
+ void SetGridSnapToChars( bool bSet) { m_bGridSnapToChars = bSet; }
void SetDxtCharSpace( sal_Int32 nSet ) { m_nDxtCharSpace = nSet; }
void SetLnnMod( sal_Int32 nValue ) { m_nLnnMod = nValue; }