Kaydet (Commit) 91b96323 authored tarafından Muhammet Kara's avatar Muhammet Kara Kaydeden (comit) Andras Timar

Redaction: Handle multiple Writer pages

 * Creates one GDIMetaFile from each Writer page * Inserts them as Shapes into the newly created Draw doc
 * Has some 'magic' numbers needs to be figured out
 * Tried with a 100-page Writer doc, seems okay
 * Seems slow, might need to be optimized
   * Seems like getDocumentSizeInPixels() and getDocumentSizeIn100mm()
     are consuming most of the cycles. Will look into this at the end.

Change-Id: Ic6046af0c12e26185edf59862e55b17117495922
Reviewed-on: https://gerrit.libreoffice.org/65847
Tested-by: Jenkins
Reviewed-by: 's avatarMuhammet Kara <muhammet.kara@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/69769Reviewed-by: 's avatarAndras Timar <andras.timar@collabora.com>
Tested-by: 's avatarAndras Timar <andras.timar@collabora.com>
üst 5ceee417
...@@ -542,12 +542,16 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq) ...@@ -542,12 +542,16 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)
if(!xCursor.is()) if(!xCursor.is())
return; return;
xCursor->jumpToLastPage();
sal_Int16 nPages = xCursor->getPage();
uno::Reference< lang::XComponent > xSourceDoc( xModel ); uno::Reference< lang::XComponent > xSourceDoc( xModel );
DocumentToGraphicRenderer aRenderer(xSourceDoc, /*bSelectionOnly=*/false); DocumentToGraphicRenderer aRenderer(xSourceDoc, /*bSelectionOnly=*/false);
// Only take the first page for now std::vector< GDIMetaFile > aMetaFiles;
sal_Int16 nPage = 1;
for (sal_Int32 nPage = 1; nPage <= nPages; ++nPage)
{
::Size aDocumentSizePixel = aRenderer.getDocumentSizeInPixels(nPage); ::Size aDocumentSizePixel = aRenderer.getDocumentSizeInPixels(nPage);
::Point aLogicPos; ::Point aLogicPos;
::Size aLogic = aRenderer.getDocumentSizeIn100mm(nPage, &aLogicPos); ::Size aLogic = aRenderer.getDocumentSizeIn100mm(nPage, &aLogicPos);
...@@ -561,10 +565,14 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq) ...@@ -561,10 +565,14 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)
// will be correct in MM. // will be correct in MM.
MapMode aMapMode; MapMode aMapMode;
aMapMode.SetMapUnit(MapUnit::Map100thMM); aMapMode.SetMapUnit(MapUnit::Map100thMM);
aMapMode.SetOrigin(::Point(-aLogicPos.getX(), -aLogicPos.getY())); // 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 )));
rGDIMetaFile.SetPrefMapMode(aMapMode); rGDIMetaFile.SetPrefMapMode(aMapMode);
rGDIMetaFile.SetPrefSize(aLogic); rGDIMetaFile.SetPrefSize(aLogic);
aMetaFiles.push_back(rGDIMetaFile);
}
// Create an empty Draw component. // Create an empty Draw component.
uno::Reference<frame::XDesktop2> xDesktop = css::frame::Desktop::create(comphelper::getProcessComponentContext()); uno::Reference<frame::XDesktop2> xDesktop = css::frame::Desktop::create(comphelper::getProcessComponentContext());
uno::Reference<frame::XComponentLoader> xComponentLoader(xDesktop, uno::UNO_QUERY); uno::Reference<frame::XComponentLoader> xComponentLoader(xDesktop, uno::UNO_QUERY);
...@@ -573,12 +581,17 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq) ...@@ -573,12 +581,17 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)
// Access the draw pages // Access the draw pages
uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(xComponent, uno::UNO_QUERY); uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(xComponent, uno::UNO_QUERY);
uno::Reference<drawing::XDrawPages> xDrawPages = xDrawPagesSupplier->getDrawPages(); uno::Reference<drawing::XDrawPages> xDrawPages = xDrawPagesSupplier->getDrawPages();
uno::Reference< drawing::XDrawPage > xPage( xDrawPages->getByIndex( 0 ), uno::UNO_QUERY_THROW ); uno::Reference<css::lang::XMultiServiceFactory> xFactory(xComponent, uno::UNO_QUERY);
for (sal_Int32 nPage = 0; nPage < nPages; ++nPage)
{
GDIMetaFile rGDIMetaFile = aMetaFiles[nPage];
Graphic aGraphic(rGDIMetaFile);
uno::Reference<graphic::XGraphic> xGraph = aGraphic.GetXGraphic(); uno::Reference<graphic::XGraphic> xGraph = aGraphic.GetXGraphic();
uno::Reference< drawing::XDrawPage > xPage = xDrawPages->insertNewByIndex(nPage);
// Create and insert the shape // Create and insert the shape
uno::Reference<css::lang::XMultiServiceFactory> xFactory(xComponent, uno::UNO_QUERY);
uno::Reference<drawing::XShape> xShape( uno::Reference<drawing::XShape> xShape(
xFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"), uno::UNO_QUERY); xFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"), uno::UNO_QUERY);
uno::Reference<beans::XPropertySet> xShapeProperySet(xShape, uno::UNO_QUERY); uno::Reference<beans::XPropertySet> xShapeProperySet(xShape, uno::UNO_QUERY);
...@@ -588,6 +601,11 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq) ...@@ -588,6 +601,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);
}
// Remove the extra page at the beginning
uno::Reference< drawing::XDrawPage > xPage( xDrawPages->getByIndex( 0 ), uno::UNO_QUERY_THROW );
xDrawPages->remove( xPage );
return; return;
} }
......
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