Kaydet (Commit) 189f4d3b authored tarafından Muhammet Kara's avatar Muhammet Kara

Redaction: Adjust offset for multiple Calc pages

* Add an enum and some methods to DocumentToGraphicRenderer
  to differentiate between the doc/module types:
    isWriter(), isCalc(), isImpress()
* Put some checks for module/doc type
* The result seems ok for a Calc document of multiple sheets
  with hundreds of pages

Change-Id: Idf3e1966d4239df30a48a947a95c9085c25ee1bb
Reviewed-on: https://gerrit.libreoffice.org/66605
Tested-by: Jenkins
Reviewed-by: 's avatarMuhammet Kara <muhammet.kara@collabora.com>
üst 16fffbe8
...@@ -46,12 +46,19 @@ class SVT_DLLPUBLIC DocumentToGraphicRenderer ...@@ -46,12 +46,19 @@ class SVT_DLLPUBLIC DocumentToGraphicRenderer
{ {
const css::uno::Reference<css::lang::XComponent>& mxDocument; const css::uno::Reference<css::lang::XComponent>& mxDocument;
enum DocType {
WRITER,
CALC,
IMPRESS,
UNKNOWN
};
css::uno::Reference<css::frame::XModel> mxModel; css::uno::Reference<css::frame::XModel> mxModel;
css::uno::Reference<css::frame::XController> mxController; css::uno::Reference<css::frame::XController> mxController;
css::uno::Reference<css::view::XRenderable> mxRenderable; css::uno::Reference<css::view::XRenderable> mxRenderable;
css::uno::Reference<css::awt::XToolkit> mxToolkit; css::uno::Reference<css::awt::XToolkit> mxToolkit;
css::uno::Any maSelection; css::uno::Any maSelection;
bool mbIsWriter; DocType meDocType;
std::vector<OUString> maChapterNames; std::vector<OUString> maChapterNames;
bool hasSelection() const; bool hasSelection() const;
...@@ -77,7 +84,8 @@ public: ...@@ -77,7 +84,8 @@ public:
Size getDocumentSizeInPixels( sal_Int32 nCurrentPage ); Size getDocumentSizeInPixels( sal_Int32 nCurrentPage );
Size getDocumentSizeIn100mm(sal_Int32 nCurrentPage, Point* pDocumentPosition = nullptr); Size getDocumentSizeIn100mm(sal_Int32 nCurrentPage, Point* pDocumentPosition = nullptr,
Point* pCalcPagePosition = nullptr, Size *pCalcPageSize = nullptr);
Graphic renderToGraphic( sal_Int32 nCurrentPage, Size aDocumentSizePixel, Graphic renderToGraphic( sal_Int32 nCurrentPage, Size aDocumentSizePixel,
Size aTargetSizePixel, Color aPageColor, bool bExtOutDevData); Size aTargetSizePixel, Color aPageColor, bool bExtOutDevData);
...@@ -92,6 +100,10 @@ public: ...@@ -92,6 +100,10 @@ public:
css::uno::Reference< css::drawing::XShapes > & rxShapes, css::uno::Reference< css::drawing::XShapes > & rxShapes,
css::uno::Reference< css::drawing::XShape > & rxShape, css::uno::Reference< css::drawing::XShape > & rxShape,
const css::uno::Reference< css::frame::XController > & rxController ); const css::uno::Reference< css::frame::XController > & rxController );
bool isWriter() const;
bool isCalc() const;
bool isImpress() const;
}; };
#endif #endif
......
...@@ -549,7 +549,16 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq) ...@@ -549,7 +549,16 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)
uno::Reference< lang::XComponent > xSourceDoc( xModel ); uno::Reference< lang::XComponent > xSourceDoc( xModel );
DocumentToGraphicRenderer aRenderer(xSourceDoc, /*bSelectionOnly=*/false); DocumentToGraphicRenderer aRenderer(xSourceDoc, false);
bool bIsWriter = aRenderer.isWriter();
bool bIsCalc = aRenderer.isCalc();
if (!bIsWriter && !bIsCalc)
{
SAL_WARN( "sfx.doc", "Redaction is supported only for Writer and Calc! (for now...)");
return;
}
sal_Int32 nPages = aRenderer.getPageCount(); sal_Int32 nPages = aRenderer.getPageCount();
...@@ -559,7 +568,9 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq) ...@@ -559,7 +568,9 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)
{ {
::Size aDocumentSizePixel = aRenderer.getDocumentSizeInPixels(nPage); ::Size aDocumentSizePixel = aRenderer.getDocumentSizeInPixels(nPage);
::Point aLogicPos; ::Point aLogicPos;
::Size aLogic = aRenderer.getDocumentSizeIn100mm(nPage, &aLogicPos); ::Point aCalcPageLogicPos;
::Size aCalcPageContentSize;
::Size aLogic = aRenderer.getDocumentSizeIn100mm(nPage, &aLogicPos, &aCalcPageLogicPos, &aCalcPageContentSize);
// FIXME: This is a temporary hack. Need to figure out a proper way to derive this scale factor. // FIXME: This is a temporary hack. Need to figure out a proper way to derive this scale factor.
::Size aTargetSize(aDocumentSizePixel.Width() * 1.23, aDocumentSizePixel.Height() * 1.23); ::Size aTargetSize(aDocumentSizePixel.Width() * 1.23, aDocumentSizePixel.Height() * 1.23);
...@@ -572,9 +583,21 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq) ...@@ -572,9 +583,21 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)
MapMode aMapMode; MapMode aMapMode;
aMapMode.SetMapUnit(MapUnit::Map100thMM); aMapMode.SetMapUnit(MapUnit::Map100thMM);
// FIXME: This is a temporary hack. Need to figure out a proper way to derive these magic numbers. // FIXME: This is a temporary hack. Need to figure out a proper way to derive these magic numbers.
aMapMode.SetOrigin(::Point(-(aLogicPos.getX() - 512) * 1.53, -((aLogicPos.getY() - 501)* 1.53 + (nPage-1)*740 ))); if (bIsWriter)
aMapMode.SetOrigin(::Point(-(aLogicPos.getX() - 512) * 1.53, -((aLogicPos.getY() - 501)* 1.53 + (nPage-1)*740 )));
else if (bIsCalc)
rGDIMetaFile.Scale(0.566, 0.566);
rGDIMetaFile.SetPrefMapMode(aMapMode); rGDIMetaFile.SetPrefMapMode(aMapMode);
rGDIMetaFile.SetPrefSize(aLogic);
if (bIsCalc)
{
double aWidthRatio = static_cast<double>(aCalcPageContentSize.Width()) / aLogic.Width();
// FIXME: Get rid of these magic numbers. Also watch for floating point rounding errors
rGDIMetaFile.Move(-2400 + aCalcPageLogicPos.X() * (aWidthRatio - 0.0887), -3300 + aCalcPageLogicPos.Y() * 0.64175);
}
rGDIMetaFile.SetPrefSize( bIsCalc ? aCalcPageContentSize : aLogic );
aMetaFiles.push_back(rGDIMetaFile); aMetaFiles.push_back(rGDIMetaFile);
} }
...@@ -608,6 +631,11 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq) ...@@ -608,6 +631,11 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)
xShape->setSize(awt::Size(rGDIMetaFile.GetPrefSize().Width(),rGDIMetaFile.GetPrefSize().Height()) ); xShape->setSize(awt::Size(rGDIMetaFile.GetPrefSize().Width(),rGDIMetaFile.GetPrefSize().Height()) );
xPage->add(xShape); xPage->add(xShape);
// Shapes from Calc have the size of the content instead of the whole standard page (like A4)
// so it needs positioning on the draw page
if (bIsCalc)
xShape->setPosition(awt::Point(1000,1000));
} }
// Remove the extra page at the beginning // Remove the extra page at the beginning
......
...@@ -49,7 +49,7 @@ DocumentToGraphicRenderer::DocumentToGraphicRenderer( const Reference<XComponent ...@@ -49,7 +49,7 @@ DocumentToGraphicRenderer::DocumentToGraphicRenderer( const Reference<XComponent
mxController( mxModel->getCurrentController() ), mxController( mxModel->getCurrentController() ),
mxRenderable (mxDocument, uno::UNO_QUERY ), mxRenderable (mxDocument, uno::UNO_QUERY ),
mxToolkit( VCLUnoHelper::CreateToolkit() ), mxToolkit( VCLUnoHelper::CreateToolkit() ),
mbIsWriter( false ) meDocType( UNKNOWN )
{ {
try try
{ {
...@@ -57,7 +57,13 @@ DocumentToGraphicRenderer::DocumentToGraphicRenderer( const Reference<XComponent ...@@ -57,7 +57,13 @@ DocumentToGraphicRenderer::DocumentToGraphicRenderer( const Reference<XComponent
if (xServiceInfo.is()) if (xServiceInfo.is())
{ {
if (xServiceInfo->supportsService("com.sun.star.text.TextDocument")) if (xServiceInfo->supportsService("com.sun.star.text.TextDocument"))
mbIsWriter = true; meDocType = WRITER;
else if (xServiceInfo->supportsService("com.sun.star.sheet.SpreadsheetDocument"))
meDocType = CALC;
else if (xServiceInfo->supportsService("com.sun.star.presentation.PresentationDocument"))
meDocType = IMPRESS;
else
meDocType = UNKNOWN;
} }
} }
catch (const uno::Exception&) catch (const uno::Exception&)
...@@ -80,7 +86,7 @@ DocumentToGraphicRenderer::DocumentToGraphicRenderer( const Reference<XComponent ...@@ -80,7 +86,7 @@ DocumentToGraphicRenderer::DocumentToGraphicRenderer( const Reference<XComponent
* XRenderable::render() it always renders an empty page. * XRenderable::render() it always renders an empty page.
* So disable the selection already here. The current page * So disable the selection already here. The current page
* the cursor is on is rendered. */ * the cursor is on is rendered. */
if (!mbIsWriter) if (!isWriter())
maSelection = aViewSelection; maSelection = aViewSelection;
} }
} }
...@@ -116,7 +122,7 @@ uno::Any DocumentToGraphicRenderer::getSelection() const ...@@ -116,7 +122,7 @@ uno::Any DocumentToGraphicRenderer::getSelection() const
} }
Size DocumentToGraphicRenderer::getDocumentSizeIn100mm(sal_Int32 nCurrentPage, Size DocumentToGraphicRenderer::getDocumentSizeIn100mm(sal_Int32 nCurrentPage,
Point* pDocumentPosition) Point* pDocumentPosition, Point* pCalcPagePosition, Size* pCalcPageSize)
{ {
Reference< awt::XDevice > xDevice(mxToolkit->createScreenCompatibleDevice( 32, 32 ) ); Reference< awt::XDevice > xDevice(mxToolkit->createScreenCompatibleDevice( 32, 32 ) );
...@@ -135,7 +141,9 @@ Size DocumentToGraphicRenderer::getDocumentSizeIn100mm(sal_Int32 nCurrentPage, ...@@ -135,7 +141,9 @@ Size DocumentToGraphicRenderer::getDocumentSizeIn100mm(sal_Int32 nCurrentPage,
renderProperties[3].Value <<= true; renderProperties[3].Value <<= true;
awt::Size aSize; awt::Size aSize;
awt::Size aCalcPageSize;
awt::Point aPos; awt::Point aPos;
awt::Point aCalcPos;
sal_Int32 nPages = mxRenderable->getRendererCount( selection, renderProperties ); sal_Int32 nPages = mxRenderable->getRendererCount( selection, renderProperties );
if (nPages >= nCurrentPage) if (nPages >= nCurrentPage)
...@@ -151,6 +159,14 @@ Size DocumentToGraphicRenderer::getDocumentSizeIn100mm(sal_Int32 nCurrentPage, ...@@ -151,6 +159,14 @@ Size DocumentToGraphicRenderer::getDocumentSizeIn100mm(sal_Int32 nCurrentPage,
{ {
aResult[nProperty].Value >>= aPos; aResult[nProperty].Value >>= aPos;
} }
else if (aResult[nProperty].Name == "CalcPagePos")
{
aResult[nProperty].Value >>= aCalcPos;
}
else if (aResult[nProperty].Name == "CalcPageContentSize")
{
aResult[nProperty].Value >>= aCalcPageSize;
}
} }
} }
...@@ -158,6 +174,14 @@ Size DocumentToGraphicRenderer::getDocumentSizeIn100mm(sal_Int32 nCurrentPage, ...@@ -158,6 +174,14 @@ Size DocumentToGraphicRenderer::getDocumentSizeIn100mm(sal_Int32 nCurrentPage,
{ {
*pDocumentPosition = Point(aPos.X, aPos.Y); *pDocumentPosition = Point(aPos.X, aPos.Y);
} }
if (pCalcPagePosition)
{
*pCalcPagePosition = Point(aCalcPos.X, aCalcPos.Y);
}
if (pCalcPageSize)
{
*pCalcPageSize = Size(aCalcPageSize.Width, aCalcPageSize.Height);
}
return Size( aSize.Width, aSize.Height ); return Size( aSize.Width, aSize.Height );
} }
...@@ -246,7 +270,7 @@ sal_Int32 DocumentToGraphicRenderer::getCurrentPage() ...@@ -246,7 +270,7 @@ sal_Int32 DocumentToGraphicRenderer::getCurrentPage()
if (hasSelection()) if (hasSelection())
return 1; return 1;
if (mbIsWriter) if (isWriter())
return getCurrentPageWriter(); return getCurrentPageWriter();
/* TODO: other application specific page detection? */ /* TODO: other application specific page detection? */
...@@ -307,4 +331,28 @@ bool DocumentToGraphicRenderer::isShapeSelected( ...@@ -307,4 +331,28 @@ bool DocumentToGraphicRenderer::isShapeSelected(
return bShape; return bShape;
} }
bool DocumentToGraphicRenderer::isWriter() const
{
if (meDocType == WRITER)
return true;
else
return false;
}
bool DocumentToGraphicRenderer::isCalc() const
{
if (meDocType == CALC)
return true;
else
return false;
}
bool DocumentToGraphicRenderer::isImpress() const
{
if (meDocType == IMPRESS)
return true;
else
return false;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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