[Libreoffice-commits] core.git: sfx2/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Mon Jan 7 16:15:14 UTC 2019


 sfx2/source/doc/objserv.cxx |   80 +++++++++++++++++++++++++++-----------------
 1 file changed, 50 insertions(+), 30 deletions(-)

New commits:
commit c5a7e5d9348d809a61449226ac4169619f89a904
Author:     Muhammet Kara <muhammet.kara at collabora.com>
AuthorDate: Fri Jan 4 10:07:03 2019 +0300
Commit:     Muhammet Kara <muhammet.kara at collabora.com>
CommitDate: Mon Jan 7 17:14:53 2019 +0100

    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: Ie40cd64b69fad3e66d74b6b05600cb9f52f1021b
    Reviewed-on: https://gerrit.libreoffice.org/65847
    Tested-by: Jenkins
    Reviewed-by: Muhammet Kara <muhammet.kara at collabora.com>

diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx
index 0b1a879e7678..fed50045b256 100644
--- a/sfx2/source/doc/objserv.cxx
+++ b/sfx2/source/doc/objserv.cxx
@@ -548,29 +548,37 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)
             if(!xCursor.is())
                 return;
 
+            xCursor->jumpToLastPage();
+            sal_Int16 nPages = xCursor->getPage();
+
             uno::Reference< lang::XComponent > xSourceDoc( xModel );
             DocumentToGraphicRenderer aRenderer(xSourceDoc, /*bSelectionOnly=*/false);
 
-            // Only take the first page for now
-            sal_Int16 nPage = 1;
-
-            ::Size aDocumentSizePixel = aRenderer.getDocumentSizeInPixels(nPage);
-            ::Point aLogicPos;
-            ::Size aLogic = aRenderer.getDocumentSizeIn100mm(nPage, &aLogicPos);
-            // 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);
+            std::vector< GDIMetaFile > aMetaFiles;
 
-            Graphic aGraphic = aRenderer.renderToGraphic(nPage, aDocumentSizePixel, aTargetSize, COL_TRANSPARENT,
-                                                         /*bExtOutDevData=*/true);
-            auto& rGDIMetaFile = const_cast<GDIMetaFile&>(aGraphic.GetGDIMetaFile());
-
-            // Set preferred map unit and size on the metafile, so the Shape size
-            // will be correct in MM.
-            MapMode aMapMode;
-            aMapMode.SetMapUnit(MapUnit::Map100thMM);
-            aMapMode.SetOrigin(::Point(-aLogicPos.getX(), -aLogicPos.getY()));
-            rGDIMetaFile.SetPrefMapMode(aMapMode);
-            rGDIMetaFile.SetPrefSize(aLogic);
+            for (sal_Int32 nPage = 1; nPage <= nPages; ++nPage)
+            {
+                ::Size aDocumentSizePixel = aRenderer.getDocumentSizeInPixels(nPage);
+                ::Point aLogicPos;
+                ::Size aLogic = aRenderer.getDocumentSizeIn100mm(nPage, &aLogicPos);
+                // 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);
+
+                Graphic aGraphic = aRenderer.renderToGraphic(nPage, aDocumentSizePixel, aTargetSize, COL_TRANSPARENT,
+                                                             true);
+                auto& rGDIMetaFile = const_cast<GDIMetaFile&>(aGraphic.GetGDIMetaFile());
+
+                // Set preferred map unit and size on the metafile, so the Shape size
+                // will be correct in MM.
+                MapMode aMapMode;
+                aMapMode.SetMapUnit(MapUnit::Map100thMM);
+                // 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.SetPrefSize(aLogic);
+
+                aMetaFiles.push_back(rGDIMetaFile);
+            }
 
             // Create an empty Draw component.
             uno::Reference<frame::XDesktop2> xDesktop = css::frame::Desktop::create(comphelper::getProcessComponentContext());
@@ -580,21 +588,32 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)
             // Access the draw pages
             uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(xComponent, uno::UNO_QUERY);
             uno::Reference<drawing::XDrawPages> xDrawPages = xDrawPagesSupplier->getDrawPages();
-            uno::Reference< drawing::XDrawPage > xPage( xDrawPages->getByIndex( 0 ), uno::UNO_QUERY_THROW );
 
-            uno::Reference<graphic::XGraphic> xGraph = aGraphic.GetXGraphic();
-
-            // Create and insert the shape
             uno::Reference<css::lang::XMultiServiceFactory> xFactory(xComponent, uno::UNO_QUERY);
-            uno::Reference<drawing::XShape> xShape(
-                    xFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"), uno::UNO_QUERY);
-            uno::Reference<beans::XPropertySet> xShapeProperySet(xShape, uno::UNO_QUERY);
-            xShapeProperySet->setPropertyValue("Graphic", uno::Any( xGraph ));
 
-            // Set size and position
-            xShape->setSize(awt::Size(rGDIMetaFile.GetPrefSize().Width(),rGDIMetaFile.GetPrefSize().Height()) );
+            for (sal_Int32 nPage = 0; nPage < nPages; ++nPage)
+            {
+                GDIMetaFile rGDIMetaFile = aMetaFiles[nPage];
+                Graphic aGraphic(rGDIMetaFile);
 
-            xPage->add(xShape);
+                uno::Reference<graphic::XGraphic> xGraph = aGraphic.GetXGraphic();
+                uno::Reference< drawing::XDrawPage > xPage = xDrawPages->insertNewByIndex(nPage);
+
+                // Create and insert the shape
+                uno::Reference<drawing::XShape> xShape(
+                        xFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"), uno::UNO_QUERY);
+                uno::Reference<beans::XPropertySet> xShapeProperySet(xShape, uno::UNO_QUERY);
+                xShapeProperySet->setPropertyValue("Graphic", uno::Any( xGraph ));
+
+                // Set size and position
+                xShape->setSize(awt::Size(rGDIMetaFile.GetPrefSize().Width(),rGDIMetaFile.GetPrefSize().Height()) );
+
+                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;
         }
@@ -692,6 +711,7 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)
                         xParentWindow = xCtrl->getFrame()->getContainerWindow();
 
                     uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
+
                     uno::Reference< task::XInteractionHandler2 > xInteract(
                         task::InteractionHandler::createWithParent(xContext, xParentWindow) );
 


More information about the Libreoffice-commits mailing list