Kaydet (Commit) 209f2fe0 authored tarafından Miklos Vajna's avatar Miklos Vajna

tdf#121867 DOCX filter: handle page width zoom

And other non-fixed zoom types, similar to how DOC does it.

Change-Id: Ie84340b4e662d2329b5d3918900adfd0c3e9b8e9
Reviewed-on: https://gerrit.libreoffice.org/67378
Tested-by: Jenkins
Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.com>
üst c394e6a5
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
#include <sfx2/docfilt.hxx> #include <sfx2/docfilt.hxx>
#include <svx/xfillit0.hxx> #include <svx/xfillit0.hxx>
#include <editsh.hxx>
class Test : public SwModelTestBase class Test : public SwModelTestBase
{ {
public: public:
...@@ -86,6 +88,14 @@ DECLARE_OOXMLEXPORT_TEST(testDateControl, "empty-date-control.odt") ...@@ -86,6 +88,14 @@ DECLARE_OOXMLEXPORT_TEST(testDateControl, "empty-date-control.odt")
assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtContent/w:r/w:t", u" "); assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtContent/w:r/w:t", u" ");
} }
DECLARE_OOXMLEXPORT_TEST(testTdf121867, "tdf121867.odt")
{
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
SwEditShell* pEditShell = pTextDoc->GetDocShell()->GetEditShell();
// Without the accompanying fix in place, this test would have failed with
// 'Expected: 3; Actual : 0', i.e. page width zoom was lost on export.
CPPUNIT_ASSERT_EQUAL(SvxZoomType::PAGEWIDTH, pEditShell->GetViewOptions()->GetZoomType());
}
DECLARE_OOXMLEXPORT_TEST(testInputListExport, "tdf122186_input_list.odt") DECLARE_OOXMLEXPORT_TEST(testInputListExport, "tdf122186_input_list.odt")
{ {
......
...@@ -932,8 +932,28 @@ void DocxExport::WriteSettings() ...@@ -932,8 +932,28 @@ void DocxExport::WriteSettings()
// Zoom // Zoom
if (pViewShell) if (pViewShell)
{ {
rtl::Reference<sax_fastparser::FastAttributeList> pAttributeList(
sax_fastparser::FastSerializerHelper::createAttrList());
switch (pViewShell->GetViewOptions()->GetZoomType())
{
case SvxZoomType::WHOLEPAGE:
pAttributeList->add(FSNS(XML_w, XML_val), "fullPage");
break;
case SvxZoomType::PAGEWIDTH:
pAttributeList->add(FSNS(XML_w, XML_val), "bestFit");
break;
case SvxZoomType::OPTIMAL:
pAttributeList->add(FSNS(XML_w, XML_val), "textFit");
break;
default:
break;
}
OString aZoom(OString::number(pViewShell->GetViewOptions()->GetZoom())); OString aZoom(OString::number(pViewShell->GetViewOptions()->GetZoom()));
pFS->singleElementNS(XML_w, XML_zoom, FSNS(XML_w, XML_percent), aZoom.getStr(), FSEND); pAttributeList->add(FSNS(XML_w, XML_percent), aZoom);
sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList.get());
pFS->singleElementNS(XML_w, XML_zoom, xAttributeList);
} }
// Display Background Shape // Display Background Shape
......
...@@ -5802,7 +5802,9 @@ void DomainMapper_Impl::ApplySettingsTable() ...@@ -5802,7 +5802,9 @@ void DomainMapper_Impl::ApplySettingsTable()
{ {
aViewProps.emplace_back("ZoomFactor", -1, uno::makeAny(m_pSettingsTable->GetZoomFactor()), beans::PropertyState_DIRECT_VALUE); aViewProps.emplace_back("ZoomFactor", -1, uno::makeAny(m_pSettingsTable->GetZoomFactor()), beans::PropertyState_DIRECT_VALUE);
aViewProps.emplace_back("VisibleBottom", -1, uno::makeAny(sal_Int32(0)), beans::PropertyState_DIRECT_VALUE); aViewProps.emplace_back("VisibleBottom", -1, uno::makeAny(sal_Int32(0)), beans::PropertyState_DIRECT_VALUE);
aViewProps.emplace_back("ZoomType", -1, uno::makeAny(sal_Int16(0)), beans::PropertyState_DIRECT_VALUE); aViewProps.emplace_back("ZoomType", -1,
uno::makeAny(m_pSettingsTable->GetZoomType()),
beans::PropertyState_DIRECT_VALUE);
} }
uno::Reference<container::XIndexContainer> xBox = document::IndexedPropertyValues::create(m_xComponentContext); uno::Reference<container::XIndexContainer> xBox = document::IndexedPropertyValues::create(m_xComponentContext);
xBox->insertByIndex(sal_Int32(0), uno::makeAny(comphelper::containerToSequence(aViewProps))); xBox->insertByIndex(sal_Int32(0), uno::makeAny(comphelper::containerToSequence(aViewProps)));
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <vector> #include <vector>
#include <rtl/ustring.hxx> #include <rtl/ustring.hxx>
#include <sfx2/zoomitem.hxx>
#include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/beans/XPropertyState.hpp> #include <com/sun/star/beans/XPropertyState.hpp>
#include <com/sun/star/container/XNameContainer.hpp> #include <com/sun/star/container/XNameContainer.hpp>
...@@ -36,6 +37,24 @@ ...@@ -36,6 +37,24 @@
using namespace com::sun::star; using namespace com::sun::star;
namespace writerfilter { namespace writerfilter {
namespace
{
/// Maps OOXML <w:zoom w:val="..."> to SvxZoomType.
sal_Int16 lcl_GetZoomType(Id nType)
{
switch (nType)
{
case NS_ooxml::LN_Value_doc_ST_Zoom_fullPage:
return sal_Int16(SvxZoomType::WHOLEPAGE);
case NS_ooxml::LN_Value_doc_ST_Zoom_bestFit:
return sal_Int16(SvxZoomType::PAGEWIDTH);
case NS_ooxml::LN_Value_doc_ST_Zoom_textFit:
return sal_Int16(SvxZoomType::OPTIMAL);
}
return sal_Int16(SvxZoomType::PERCENT);
}
}
namespace dmapper namespace dmapper
{ {
...@@ -221,6 +240,7 @@ struct SettingsTable_Impl ...@@ -221,6 +240,7 @@ struct SettingsTable_Impl
bool m_bRecordChanges; bool m_bRecordChanges;
bool m_bLinkStyles; bool m_bLinkStyles;
sal_Int16 m_nZoomFactor; sal_Int16 m_nZoomFactor;
sal_Int16 m_nZoomType = 0;
Id m_nView; Id m_nView;
bool m_bEvenAndOddHeaders; bool m_bEvenAndOddHeaders;
bool m_bUsePrinterMetrics; bool m_bUsePrinterMetrics;
...@@ -292,6 +312,9 @@ void SettingsTable::lcl_attribute(Id nName, Value & val) ...@@ -292,6 +312,9 @@ void SettingsTable::lcl_attribute(Id nName, Value & val)
case NS_ooxml::LN_CT_Zoom_percent: case NS_ooxml::LN_CT_Zoom_percent:
m_pImpl->m_nZoomFactor = nIntValue; m_pImpl->m_nZoomFactor = nIntValue;
break; break;
case NS_ooxml::LN_CT_Zoom_val:
m_pImpl->m_nZoomType = lcl_GetZoomType(nIntValue);
break;
case NS_ooxml::LN_CT_Language_val: case NS_ooxml::LN_CT_Language_val:
m_pImpl->m_pThemeFontLangProps[0].Name = "val"; m_pImpl->m_pThemeFontLangProps[0].Name = "val";
m_pImpl->m_pThemeFontLangProps[0].Value <<= sStringValue; m_pImpl->m_pThemeFontLangProps[0].Value <<= sStringValue;
...@@ -503,6 +526,8 @@ sal_Int16 SettingsTable::GetZoomFactor() const ...@@ -503,6 +526,8 @@ sal_Int16 SettingsTable::GetZoomFactor() const
return m_pImpl->m_nZoomFactor; return m_pImpl->m_nZoomFactor;
} }
sal_Int16 SettingsTable::GetZoomType() const { return m_pImpl->m_nZoomType; }
Id SettingsTable::GetView() const Id SettingsTable::GetView() const
{ {
return m_pImpl->m_nView; return m_pImpl->m_nView;
......
...@@ -57,6 +57,9 @@ class SettingsTable : public LoggedProperties, public LoggedTable ...@@ -57,6 +57,9 @@ class SettingsTable : public LoggedProperties, public LoggedTable
/// What's the zoom factor set in percents? /// What's the zoom factor set in percents?
sal_Int16 GetZoomFactor() const; sal_Int16 GetZoomFactor() const;
/// Gets the type of the zoom.
sal_Int16 GetZoomType() const;
/// What's the requested view? E.g. "web". /// What's the requested view? E.g. "web".
Id GetView() const; Id GetView() const;
......
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