[Libreoffice-commits] core.git: Branch 'private/tvajngerl/staging' - 3 commits - drawinglayer/source filter/CppunitTest_filter_pdfimporter_test.mk filter/Library_pdfimporter.mk filter/Module_filter.mk filter/qa filter/source include/filter include/sfx2 include/vcl officecfg/registry Repository.mk sc/uiconfig sd/uiconfig sfx2/inc sfx2/Library_sfx.mk sfx2/sdi sfx2/source sfx2/uiconfig sfx2/UIConfig_sfx.mk sw/uiconfig vcl/source

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Mon May 10 12:02:10 UTC 2021


Rebased ref, commits from common ancestor:
commit 84ce1a4551f93b7f583a0429211ae87f6fae4910
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Tue May 22 14:44:39 2018 +0900
Commit:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
CommitDate: Mon May 10 21:01:30 2021 +0900

    tdf#91874 Command Popup
    
    Change-Id: I92cdd3130b8de42ee0863c9e7154e7c7246d9377

diff --git a/include/sfx2/sfxsids.hrc b/include/sfx2/sfxsids.hrc
index 4bd6c194ff0e..a3c10ba915fb 100644
--- a/include/sfx2/sfxsids.hrc
+++ b/include/sfx2/sfxsids.hrc
@@ -385,7 +385,7 @@ class SvxSearchItem;
 
 // default-ids for windows
 
-// free                                     (SID_SFX_START + 610)
+#define SID_COMMAND_POPUP                   (SID_SFX_START + 610)
 #define SID_NEWWINDOW                       (SID_SFX_START + 620)
 #define SID_CLOSEWIN                        (SID_SFX_START + 621)
 #define SID_VIEWSHELL                       (SID_SFX_START + 623)
diff --git a/officecfg/registry/data/org/openoffice/Office/Accelerators.xcu b/officecfg/registry/data/org/openoffice/Office/Accelerators.xcu
index d3d77d8c818c..313a06b25a6a 100644
--- a/officecfg/registry/data/org/openoffice/Office/Accelerators.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/Accelerators.xcu
@@ -313,6 +313,12 @@ Ctrl+Shift+e aka E_SHIFT_MOD1 under GTK/IBUS is for some emoji thing
           <value xml:lang="en-US" install:module="unxwnt">.uno:OptionsTreeDialog</value>
         </prop>
       </node>
+      <node oor:name="F1_MOD1" oor:op="replace">
+        <prop oor:name="Command">
+          <value xml:lang="x-no-translate">I10N SHORTCUTS - NO TRANSLATE</value>
+          <value xml:lang="en-US">.uno:CommandPopup</value>
+        </prop>
+      </node>
     </node>
     <node oor:name="Modules">
       <node oor:name="com.sun.star.script.BasicIDE" oor:op="replace">
diff --git a/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu b/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu
index 95283860318e..b54acd108f4f 100644
--- a/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu
@@ -6529,6 +6529,14 @@ bit 3 (0x8): #define UICOMMANDDESCRIPTION_PROPERTIES_TOGGLEBUTTON 8
           <value>1</value>
         </prop>
       </node>
+      <node oor:name=".uno:CommandPopup" oor:op="replace">
+        <prop oor:name="Label" oor:type="xs:string">
+          <value xml:lang="en-US">Search Commands</value>
+        </prop>
+        <prop oor:name="Properties" oor:type="xs:int">
+          <value>1</value>
+        </prop>
+      </node>
       <node oor:name=".uno:DevelopmentToolsDockingWindow" oor:op="replace">
         <prop oor:name="Label" oor:type="xs:string">
           <value xml:lang="en-US">Development Tools</value>
diff --git a/sc/uiconfig/scalc/menubar/menubar.xml b/sc/uiconfig/scalc/menubar/menubar.xml
index 17916a541c63..eeb746de8432 100644
--- a/sc/uiconfig/scalc/menubar/menubar.xml
+++ b/sc/uiconfig/scalc/menubar/menubar.xml
@@ -766,6 +766,7 @@
       <menu:menuitem menu:id=".uno:ExtendedHelp"/>
       <menu:menuitem menu:id=".uno:Documentation"/>
       <menu:menuitem menu:id=".uno:TipOfTheDay"/>
+      <menu:menuitem menu:id=".uno:CommandPopup"/>
       <menu:menuseparator/>
       <menu:menuitem menu:id=".uno:QuestionAnswers"/>
       <menu:menuitem menu:id=".uno:SendFeedback"/>
diff --git a/sd/uiconfig/sdraw/menubar/menubar.xml b/sd/uiconfig/sdraw/menubar/menubar.xml
index 082e9e277929..544155d33f04 100644
--- a/sd/uiconfig/sdraw/menubar/menubar.xml
+++ b/sd/uiconfig/sdraw/menubar/menubar.xml
@@ -643,6 +643,7 @@
       <menu:menuitem menu:id=".uno:ExtendedHelp"/>
       <menu:menuitem menu:id=".uno:Documentation"/>
       <menu:menuitem menu:id=".uno:TipOfTheDay"/>
+      <menu:menuitem menu:id=".uno:CommandPopup"/>
       <menu:menuseparator/>
       <menu:menuitem menu:id=".uno:QuestionAnswers"/>
       <menu:menuitem menu:id=".uno:SendFeedback"/>
diff --git a/sd/uiconfig/simpress/menubar/menubar.xml b/sd/uiconfig/simpress/menubar/menubar.xml
index a6efad8be128..fc64d6050e6e 100644
--- a/sd/uiconfig/simpress/menubar/menubar.xml
+++ b/sd/uiconfig/simpress/menubar/menubar.xml
@@ -674,6 +674,7 @@
       <menu:menuitem menu:id=".uno:ExtendedHelp"/>
       <menu:menuitem menu:id=".uno:Documentation"/>
       <menu:menuitem menu:id=".uno:TipOfTheDay"/>
+      <menu:menuitem menu:id=".uno:CommandPopup"/>
       <menu:menuseparator/>
       <menu:menuitem menu:id=".uno:QuestionAnswers"/>
       <menu:menuitem menu:id=".uno:SendFeedback"/>
diff --git a/sfx2/Library_sfx.mk b/sfx2/Library_sfx.mk
index f2fe7c708da7..cab55c2a3335 100644
--- a/sfx2/Library_sfx.mk
+++ b/sfx2/Library_sfx.mk
@@ -130,6 +130,7 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\
     sfx2/source/bastyp/progress \
     sfx2/source/bastyp/sfxhtml \
     sfx2/source/bastyp/sfxresid \
+    sfx2/source/commandpopup/CommandPopup \
     sfx2/source/config/evntconf \
     sfx2/source/control/asyncfunc \
     sfx2/source/control/bindings \
diff --git a/sfx2/UIConfig_sfx.mk b/sfx2/UIConfig_sfx.mk
index a9eacafe4c7b..0ba3a5700a7c 100644
--- a/sfx2/UIConfig_sfx.mk
+++ b/sfx2/UIConfig_sfx.mk
@@ -21,6 +21,7 @@ $(eval $(call gb_UIConfig_add_uifiles,sfx,\
 	sfx2/uiconfig/ui/classificationbox \
 	sfx2/uiconfig/ui/cmisinfopage \
 	sfx2/uiconfig/ui/cmisline \
+	sfx2/uiconfig/ui/commandpopup \
 	sfx2/uiconfig/ui/custominfopage \
 	sfx2/uiconfig/ui/deck \
 	sfx2/uiconfig/ui/descriptioninfopage \
diff --git a/sfx2/inc/commandpopup/CommandPopup.hxx b/sfx2/inc/commandpopup/CommandPopup.hxx
new file mode 100644
index 000000000000..302a04fa410f
--- /dev/null
+++ b/sfx2/inc/commandpopup/CommandPopup.hxx
@@ -0,0 +1,104 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#pragma once
+
+#include <vcl/layout.hxx>
+
+#include <sfx2/dllapi.h>
+#include <sfx2/viewfrm.hxx>
+
+#include <vcl/weld.hxx>
+#include <vcl/window.hxx>
+
+#include <com/sun/star/container/XIndexAccess.hpp>
+#include <com/sun/star/frame/XFrame.hpp>
+
+struct CurrentEntry final
+{
+    OUString m_aCommandURL;
+    OUString m_aTooltip;
+
+    CurrentEntry(OUString const& rCommandURL, OUString const& rTooltip)
+        : m_aCommandURL(rCommandURL)
+        , m_aTooltip(rTooltip)
+    {
+    }
+};
+
+struct MenuContent final
+{
+    OUString m_aCommandURL;
+    OUString m_aMenuLabel;
+    OUString m_aFullLabelWithPath;
+    OUString m_aTooltip;
+    std::vector<MenuContent> m_aSubMenuContent;
+};
+
+class MenuContentHandler final
+{
+private:
+    css::uno::Reference<css::frame::XFrame> m_xFrame;
+    MenuContent m_aMenuContent;
+    OUString m_sModuleLongName;
+
+public:
+    MenuContentHandler(css::uno::Reference<css::frame::XFrame> const& xFrame);
+
+    void gatherMenuContent(css::uno::Reference<css::container::XIndexAccess> const& xIndexAccess,
+                           MenuContent& rMenuContent);
+
+    void findInMenu(OUString const& rText, std::unique_ptr<weld::TreeView>& rpCommandTreeView,
+                    std::vector<CurrentEntry>& rCommandList);
+
+private:
+    void findInMenuRecursive(MenuContent const& rMenuContent, OUString const& rText,
+                             std::unique_ptr<weld::TreeView>& rpCommandTreeView,
+                             std::vector<CurrentEntry>& rCommandList);
+};
+
+class SFX2_DLLPUBLIC CommandListBox final
+{
+private:
+    std::unique_ptr<weld::Builder> mxBuilder;
+    std::unique_ptr<weld::Popover> mxPopover;
+    std::unique_ptr<weld::Entry> mpEntry;
+    std::unique_ptr<weld::TreeView> mpCommandTreeView;
+
+    std::vector<CurrentEntry> maCommandList;
+    OUString m_PreviousText;
+    std::unique_ptr<MenuContentHandler> mpMenuContentHandler;
+
+    DECL_LINK(QueryTooltip, const weld::TreeIter&, OUString);
+    DECL_LINK(RowActivated, weld::TreeView&, bool);
+    DECL_LINK(ModifyHdl, weld::Entry&, void);
+    DECL_LINK(SelectionChanged, weld::TreeView&, void);
+    DECL_LINK(TreeViewKeyPress, const KeyEvent&, bool);
+
+    void dispatchCommandAndClose(OUString const& rCommand);
+
+public:
+    CommandListBox(weld::Window* pParent, css::uno::Reference<css::frame::XFrame> const& xFrame);
+    void connect_closed(const Link<weld::Popover&, void>& rLink)
+    {
+        mxPopover->connect_closed(rLink);
+    }
+};
+
+class SFX2_DLLPUBLIC CommandPopupHandler
+{
+private:
+    std::unique_ptr<CommandListBox> mpListBox;
+
+public:
+    void showPopup(weld::Window* pParent, css::uno::Reference<css::frame::XFrame> const& xFrame);
+    DECL_LINK(PopupModeEnd, weld::Popover&, void);
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/sdi/frmslots.sdi b/sfx2/sdi/frmslots.sdi
index 09aafef95b7d..a7c8a472e73d 100644
--- a/sfx2/sdi/frmslots.sdi
+++ b/sfx2/sdi/frmslots.sdi
@@ -262,6 +262,11 @@ interface TopWindow : BrowseWindow
         ExecMethod = MiscExec_Impl ;
         StateMethod = MiscState_Impl ;
     ]
+    SID_COMMAND_POPUP
+    [
+        ExecMethod = MiscExec_Impl ;
+        StateMethod = MiscState_Impl ;
+    ]
     SID_CLOSEWIN // ole(no) api(final/play/rec)
     [
         ExecMethod = Exec_Impl ;
@@ -307,4 +312,3 @@ shell SfxViewFrame
         StateMethod = GetState_Impl ;
     ]
 }
-
diff --git a/sfx2/sdi/sfx.sdi b/sfx2/sdi/sfx.sdi
index 43dc58e317bf..92e5a77ee299 100644
--- a/sfx2/sdi/sfx.sdi
+++ b/sfx2/sdi/sfx.sdi
@@ -1271,6 +1271,23 @@ SfxStringItem FullName SID_DOCFULLNAME
     GroupId = ;
 ]
 
+SfxVoidItem CommandPopup SID_COMMAND_POPUP
+[
+    AutoUpdate = TRUE,
+    FastCall = FALSE,
+    ReadOnlyDoc = TRUE,
+    Toggle = FALSE,
+    Container = TRUE,
+    RecordAbsolute = FALSE,
+    RecordPerSet;
+    Asynchron;
+
+
+    AccelConfig = TRUE,
+    MenuConfig = TRUE,
+    ToolBoxConfig = TRUE,
+    GroupId = SfxGroupId::View;
+]
 
 SfxBoolItem FullScreen SID_WIN_FULLSCREEN
 
diff --git a/sfx2/source/commandpopup/CommandPopup.cxx b/sfx2/source/commandpopup/CommandPopup.cxx
new file mode 100644
index 000000000000..25eaa0c62f1b
--- /dev/null
+++ b/sfx2/source/commandpopup/CommandPopup.cxx
@@ -0,0 +1,257 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <commandpopup/CommandPopup.hxx>
+
+#include <workwin.hxx>
+
+#include <sfx2/msgpool.hxx>
+#include <sfx2/bindings.hxx>
+
+#include <comphelper/processfactory.hxx>
+#include <comphelper/dispatchcommand.hxx>
+
+#include <com/sun/star/frame/Desktop.hpp>
+#include <com/sun/star/frame/theUICommandDescription.hpp>
+#include <com/sun/star/ui/theUICategoryDescription.hpp>
+#include <com/sun/star/ui/theModuleUIConfigurationManagerSupplier.hpp>
+#include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
+#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
+#include <com/sun/star/util/URL.hpp>
+#include <com/sun/star/util/URLTransformer.hpp>
+
+#include <vcl/commandinfoprovider.hxx>
+
+using namespace css;
+
+MenuContentHandler::MenuContentHandler(uno::Reference<frame::XFrame> const& xFrame)
+    : m_xFrame(xFrame)
+    , m_sModuleLongName(vcl::CommandInfoProvider::GetModuleIdentifier(xFrame))
+{
+    auto xComponentContext = comphelper::getProcessComponentContext();
+
+    uno::Reference<ui::XModuleUIConfigurationManagerSupplier> xModuleConfigSupplier;
+    xModuleConfigSupplier.set(ui::theModuleUIConfigurationManagerSupplier::get(xComponentContext));
+
+    uno::Reference<ui::XUIConfigurationManager> xConfigurationManager;
+    xConfigurationManager = xModuleConfigSupplier->getUIConfigurationManager(m_sModuleLongName);
+
+    uno::Reference<container::XIndexAccess> xConfigData;
+    xConfigData = xConfigurationManager->getSettings("private:resource/menubar/menubar", false);
+
+    gatherMenuContent(xConfigData, m_aMenuContent);
+}
+
+void MenuContentHandler::gatherMenuContent(
+    uno::Reference<container::XIndexAccess> const& xIndexAccess, MenuContent& rMenuContent)
+{
+    for (sal_Int32 n = 0; n < xIndexAccess->getCount(); n++)
+    {
+        MenuContent aNewContent;
+        uno::Sequence<beans::PropertyValue> aProperties;
+        uno::Reference<container::XIndexAccess> xIndexContainer;
+
+        if (!(xIndexAccess->getByIndex(n) >>= aProperties))
+            continue;
+
+        bool bIsVisible = true;
+        bool bIsEnabled = true;
+
+        for (auto const& rProperty : aProperties)
+        {
+            OUString aPropertyName = rProperty.Name;
+            if (aPropertyName == "CommandURL")
+                rProperty.Value >>= aNewContent.m_aCommandURL;
+            else if (aPropertyName == "ItemDescriptorContainer")
+                rProperty.Value >>= xIndexContainer;
+            else if (aPropertyName == "IsVisible")
+                rProperty.Value >>= bIsVisible;
+            else if (aPropertyName == "Enabled")
+                rProperty.Value >>= bIsEnabled;
+        }
+
+        if (!bIsEnabled || !bIsVisible)
+            continue;
+
+        auto aCommandProperties = vcl::CommandInfoProvider::GetCommandProperties(
+            aNewContent.m_aCommandURL, m_sModuleLongName);
+        OUString aLabel = vcl::CommandInfoProvider::GetLabelForCommand(aCommandProperties);
+        aNewContent.m_aMenuLabel = aLabel;
+
+        if (!rMenuContent.m_aFullLabelWithPath.isEmpty())
+            aNewContent.m_aFullLabelWithPath = rMenuContent.m_aFullLabelWithPath + " / ";
+        aNewContent.m_aFullLabelWithPath += aNewContent.m_aMenuLabel;
+
+        aNewContent.m_aTooltip = vcl::CommandInfoProvider::GetTooltipForCommand(
+            aNewContent.m_aCommandURL, aCommandProperties, m_xFrame);
+
+        if (xIndexContainer.is())
+            gatherMenuContent(xIndexContainer, aNewContent);
+
+        rMenuContent.m_aSubMenuContent.push_back(aNewContent);
+    }
+}
+
+void MenuContentHandler::findInMenu(OUString const& rText,
+                                    std::unique_ptr<weld::TreeView>& rpCommandTreeView,
+                                    std::vector<CurrentEntry>& rCommandList)
+{
+    findInMenuRecursive(m_aMenuContent, rText, rpCommandTreeView, rCommandList);
+}
+
+void MenuContentHandler::findInMenuRecursive(MenuContent const& rMenuContent, OUString const& rText,
+                                             std::unique_ptr<weld::TreeView>& rpCommandTreeView,
+                                             std::vector<CurrentEntry>& rCommandList)
+{
+    for (MenuContent const& aSubContent : rMenuContent.m_aSubMenuContent)
+    {
+        if (aSubContent.m_aMenuLabel.toAsciiLowerCase().startsWith(rText))
+        {
+            OUString sCommandURL = aSubContent.m_aCommandURL;
+            util::URL aCommandURL;
+            aCommandURL.Complete = sCommandURL;
+            uno::Reference<uno::XComponentContext> xContext
+                = comphelper::getProcessComponentContext();
+            uno::Reference<util::XURLTransformer> xParser = util::URLTransformer::create(xContext);
+            xParser->parseStrict(aCommandURL);
+
+            auto* pViewFrame = SfxViewFrame::Current();
+
+            SfxSlotPool& rSlotPool = SfxSlotPool::GetSlotPool(pViewFrame);
+            const SfxSlot* pSlot = rSlotPool.GetUnoSlot(aCommandURL.Path);
+            if (pSlot)
+            {
+                std::unique_ptr<SfxPoolItem> pState;
+                SfxItemState eState
+                    = pViewFrame->GetBindings().QueryState(pSlot->GetSlotId(), pState);
+
+                if (eState != SfxItemState::DISABLED)
+                {
+                    auto xGraphic
+                        = vcl::CommandInfoProvider::GetXGraphicForCommand(sCommandURL, m_xFrame);
+                    rCommandList.emplace_back(sCommandURL, aSubContent.m_aTooltip);
+
+                    auto pIter = rpCommandTreeView->make_iterator();
+                    rpCommandTreeView->insert(nullptr, -1, &aSubContent.m_aFullLabelWithPath,
+                                              nullptr, nullptr, nullptr, false, pIter.get());
+                    rpCommandTreeView->set_image(*pIter, xGraphic);
+                }
+            }
+        }
+        findInMenuRecursive(aSubContent, rText, rpCommandTreeView, rCommandList);
+    }
+}
+
+CommandListBox::CommandListBox(weld::Window* pParent, uno::Reference<frame::XFrame> const& xFrame)
+    : mxBuilder(Application::CreateBuilder(pParent, "sfx/ui/commandpopup.ui"))
+    , mxPopover(mxBuilder->weld_popover("CommandPopup"))
+    , mpEntry(mxBuilder->weld_entry("command_entry"))
+    , mpCommandTreeView(mxBuilder->weld_tree_view("command_treeview"))
+    , mpMenuContentHandler(std::make_unique<MenuContentHandler>(xFrame))
+{
+    mpEntry->connect_changed(LINK(this, CommandListBox, ModifyHdl));
+    mpEntry->connect_key_press(LINK(this, CommandListBox, TreeViewKeyPress));
+    mpCommandTreeView->connect_query_tooltip(LINK(this, CommandListBox, QueryTooltip));
+    mpCommandTreeView->connect_row_activated(LINK(this, CommandListBox, RowActivated));
+
+    Size aFrameSize = pParent->get_size();
+
+    // Set size of the pop-over window
+    tools::Long nWidth = std::max(tools::Long(400), aFrameSize.Width() / 3);
+    mpCommandTreeView->set_size_request(nWidth, 400);
+
+    // Set the location of the pop-over window
+    tools::Rectangle aRect(Point(aFrameSize.Width() / 2, 0), Size(0, 0));
+    mxPopover->popup_at_rect(pParent, aRect);
+    mpEntry->grab_focus();
+}
+
+IMPL_LINK_NOARG(CommandListBox, QueryTooltip, const weld::TreeIter&, OUString)
+{
+    size_t nSelected = mpCommandTreeView->get_selected_index();
+    if (nSelected < maCommandList.size())
+    {
+        auto const& rCurrent = maCommandList[nSelected];
+        return rCurrent.m_aTooltip;
+    }
+    return OUString();
+}
+
+IMPL_LINK_NOARG(CommandListBox, RowActivated, weld::TreeView&, bool)
+{
+    OUString aCommandURL;
+    int nSelected = mpCommandTreeView->get_selected_index();
+    if (nSelected < int(maCommandList.size()))
+    {
+        auto const& rCurrent = maCommandList[nSelected];
+        aCommandURL = rCurrent.m_aCommandURL;
+    }
+    dispatchCommandAndClose(aCommandURL);
+    return true;
+}
+
+IMPL_LINK(CommandListBox, TreeViewKeyPress, const KeyEvent&, rKeyEvent, bool)
+{
+    if (rKeyEvent.GetKeyCode().GetCode() == KEY_DOWN || rKeyEvent.GetKeyCode().GetCode() == KEY_UP)
+    {
+        int nDirection = rKeyEvent.GetKeyCode().GetCode() == KEY_DOWN ? 1 : -1;
+        int nNewIndex = mpCommandTreeView->get_selected_index() + nDirection;
+        nNewIndex = std::clamp(nNewIndex, 0, mpCommandTreeView->n_children());
+        mpCommandTreeView->select(nNewIndex);
+        mpCommandTreeView->set_cursor(nNewIndex);
+        return true;
+    }
+    else if (rKeyEvent.GetKeyCode().GetCode() == KEY_RETURN)
+    {
+        RowActivated(*mpCommandTreeView);
+    }
+
+    return false;
+}
+
+IMPL_LINK_NOARG(CommandListBox, ModifyHdl, weld::Entry&, void)
+{
+    mpCommandTreeView->clear();
+    maCommandList.clear();
+
+    OUString sText = mpEntry->get_text();
+    if (sText.isEmpty())
+        return;
+
+    mpCommandTreeView->freeze();
+    mpMenuContentHandler->findInMenu(sText.toAsciiLowerCase(), mpCommandTreeView, maCommandList);
+    mpCommandTreeView->thaw();
+
+    if (mpCommandTreeView->n_children() > 0)
+    {
+        mpCommandTreeView->set_cursor(0);
+        mpCommandTreeView->select(0);
+    }
+
+    mpEntry->grab_focus();
+}
+
+void CommandListBox::dispatchCommandAndClose(OUString const& rCommand)
+{
+    mxPopover->popdown();
+
+    if (!rCommand.isEmpty())
+        comphelper::dispatchCommand(rCommand, uno::Sequence<beans::PropertyValue>());
+}
+
+void CommandPopupHandler::showPopup(weld::Window* pParent,
+                                    css::uno::Reference<css::frame::XFrame> const& xFrame)
+{
+    mpListBox.reset(new CommandListBox(pParent, xFrame));
+    mpListBox->connect_closed(LINK(this, CommandPopupHandler, PopupModeEnd));
+}
+
+IMPL_LINK_NOARG(CommandPopupHandler, PopupModeEnd, weld::Popover&, void) { mpListBox.reset(); }
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx
index 09c54757986d..542ec9f78fa3 100644
--- a/sfx2/source/view/viewfrm.cxx
+++ b/sfx2/source/view/viewfrm.cxx
@@ -25,6 +25,7 @@
 #include <sfx2/viewfrm.hxx>
 #include <sfx2/classificationhelper.hxx>
 #include <sfx2/notebookbar/SfxNotebookBar.hxx>
+#include <svx/svdview.hxx>
 #include <com/sun/star/document/MacroExecMode.hpp>
 #include <com/sun/star/frame/Desktop.hpp>
 #include <com/sun/star/frame/DispatchRecorder.hpp>
@@ -45,6 +46,7 @@
 #include <svl/undo.hxx>
 #include <vcl/stdtext.hxx>
 #include <vcl/weld.hxx>
+#include <vcl/weldutils.hxx>
 #include <svtools/miscopt.hxx>
 #include <tools/diagnose_ex.h>
 #include <com/sun/star/container/XIndexAccess.hpp>
@@ -90,6 +92,7 @@
 
 #include <unotools/configmgr.hxx>
 #include <comphelper/sequenceashashmap.hxx>
+#include <commandpopup/CommandPopup.hxx>
 
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::uno;
@@ -2971,8 +2974,18 @@ void SfxViewFrame::MiscExec_Impl( SfxRequest& rReq )
             rReq.Done();
             break;
         }
+        case SID_COMMAND_POPUP:
+        {
+            static CommandPopupHandler spCommandPopupHandler;
+
+            tools::Rectangle aRectangle(Point(0,0), GetWindow().GetSizePixel());
+            weld::Window* pParent = weld::GetPopupParent(GetWindow(), aRectangle);
+            css::uno::Reference<css::frame::XFrame> xFrame(GetFrame().GetFrameInterface(), css::uno::UNO_QUERY);
+            spCommandPopupHandler.showPopup(pParent, xFrame);
 
-        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+            rReq.Done();
+            break;
+        }
         case SID_WIN_FULLSCREEN:
         {
             const SfxBoolItem* pItem = rReq.GetArg<SfxBoolItem>(rReq.GetSlot());
diff --git a/sfx2/uiconfig/ui/commandpopup.ui b/sfx2/uiconfig/ui/commandpopup.ui
new file mode 100644
index 000000000000..b329d64c6f1e
--- /dev/null
+++ b/sfx2/uiconfig/ui/commandpopup.ui
@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.38.2 -->
+<interface domain="sfx">
+  <requires lib="gtk+" version="3.18"/>
+  <object class="GtkTreeStore" id="liststore1">
+    <columns>
+      <!-- column-name icon -->
+      <column type="GdkPixbuf"/>
+      <!-- column-name text -->
+      <column type="gchararray"/>
+      <!-- column-name tooltip -->
+      <column type="gchararray"/>
+      <!-- column-name id -->
+      <column type="gchararray"/>
+    </columns>
+  </object>
+  <object class="GtkPopover" id="CommandPopup">
+    <property name="can-focus">False</property>
+    <property name="position">bottom</property>
+    <child>
+      <object class="GtkBox" id="container">
+        <property name="visible">True</property>
+        <property name="can-focus">False</property>
+        <property name="hexpand">True</property>
+        <property name="vexpand">True</property>
+        <property name="border-width">6</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">6</property>
+        <child>
+          <object class="GtkEntry" id="command_entry">
+            <property name="visible">True</property>
+            <property name="can-focus">True</property>
+            <property name="caps-lock-warning">False</property>
+            <property name="placeholder-text" translatable="yes" context="commandpopup|entry">Search command</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkScrolledWindow">
+            <property name="visible">True</property>
+            <property name="can-focus">True</property>
+            <property name="shadow-type">in</property>
+            <child>
+              <object class="GtkTreeView" id="command_treeview">
+                <property name="visible">True</property>
+                <property name="can-focus">False</property>
+                <property name="model">liststore1</property>
+                <property name="headers-visible">False</property>
+                <property name="headers-clickable">False</property>
+                <property name="enable-search">False</property>
+                <property name="search-column">0</property>
+                <property name="hover-selection">True</property>
+                <property name="show-expanders">False</property>
+                <property name="tooltip-column">2</property>
+                <property name="activate-on-single-click">True</property>
+                <child internal-child="selection">
+                  <object class="GtkTreeSelection"/>
+                </child>
+                <child>
+                  <object class="GtkTreeViewColumn" id="column">
+                    <property name="sizing">fixed</property>
+                    <child>
+                      <object class="GtkCellRendererPixbuf" id="cellrenderericon"/>
+                      <attributes>
+                        <attribute name="pixbuf">0</attribute>
+                      </attributes>
+                    </child>
+                    <child>
+                      <object class="GtkCellRendererText" id="cellrenderertext"/>
+                      <attributes>
+                        <attribute name="text">1</attribute>
+                      </attributes>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/sw/uiconfig/sglobal/menubar/menubar.xml b/sw/uiconfig/sglobal/menubar/menubar.xml
index 9c8f61f03d28..b8dafe715afe 100644
--- a/sw/uiconfig/sglobal/menubar/menubar.xml
+++ b/sw/uiconfig/sglobal/menubar/menubar.xml
@@ -787,6 +787,7 @@
       <menu:menuitem menu:id=".uno:ExtendedHelp"/>
       <menu:menuitem menu:id=".uno:Documentation"/>
       <menu:menuitem menu:id=".uno:TipOfTheDay"/>
+      <menu:menuitem menu:id=".uno:CommandPopup"/>
       <menu:menuseparator/>
       <menu:menuitem menu:id=".uno:QuestionAnswers"/>
       <menu:menuitem menu:id=".uno:SendFeedback"/>
diff --git a/sw/uiconfig/sweb/menubar/menubar.xml b/sw/uiconfig/sweb/menubar/menubar.xml
index 46c1a22f32fc..b8d6bc1b711a 100644
--- a/sw/uiconfig/sweb/menubar/menubar.xml
+++ b/sw/uiconfig/sweb/menubar/menubar.xml
@@ -653,6 +653,7 @@
       <menu:menuitem menu:id=".uno:ExtendedHelp"/>
       <menu:menuitem menu:id=".uno:Documentation"/>
       <menu:menuitem menu:id=".uno:TipOfTheDay"/>
+      <menu:menuitem menu:id=".uno:CommandPopup"/>
       <menu:menuseparator/>
       <menu:menuitem menu:id=".uno:QuestionAnswers"/>
       <menu:menuitem menu:id=".uno:SendFeedback"/>
diff --git a/sw/uiconfig/swform/menubar/menubar.xml b/sw/uiconfig/swform/menubar/menubar.xml
index 0e64a2315124..652ea24bfbb4 100644
--- a/sw/uiconfig/swform/menubar/menubar.xml
+++ b/sw/uiconfig/swform/menubar/menubar.xml
@@ -734,6 +734,7 @@
       <menu:menuitem menu:id=".uno:ExtendedHelp"/>
       <menu:menuitem menu:id=".uno:Documentation"/>
       <menu:menuitem menu:id=".uno:TipOfTheDay"/>
+      <menu:menuitem menu:id=".uno:CommandPopup"/>
       <menu:menuseparator/>
       <menu:menuitem menu:id=".uno:QuestionAnswers"/>
       <menu:menuitem menu:id=".uno:SendFeedback"/>
diff --git a/sw/uiconfig/swriter/menubar/menubar.xml b/sw/uiconfig/swriter/menubar/menubar.xml
index afc744f1b415..e71db98f06f7 100644
--- a/sw/uiconfig/swriter/menubar/menubar.xml
+++ b/sw/uiconfig/swriter/menubar/menubar.xml
@@ -807,6 +807,7 @@
       <menu:menuitem menu:id=".uno:ExtendedHelp"/>
       <menu:menuitem menu:id=".uno:Documentation"/>
       <menu:menuitem menu:id=".uno:TipOfTheDay"/>
+      <menu:menuitem menu:id=".uno:CommandPopup"/>
       <menu:menuseparator/>
       <menu:menuitem menu:id=".uno:QuestionAnswers"/>
       <menu:menuitem menu:id=".uno:SendFeedback"/>
diff --git a/sw/uiconfig/swxform/menubar/menubar.xml b/sw/uiconfig/swxform/menubar/menubar.xml
index 7fb669089632..e70d8b7e60de 100644
--- a/sw/uiconfig/swxform/menubar/menubar.xml
+++ b/sw/uiconfig/swxform/menubar/menubar.xml
@@ -781,6 +781,7 @@
       <menu:menuitem menu:id=".uno:ExtendedHelp"/>
       <menu:menuitem menu:id=".uno:Documentation"/>
       <menu:menuitem menu:id=".uno:TipOfTheDay"/>
+      <menu:menuitem menu:id=".uno:CommandPopup"/>
       <menu:menuseparator/>
       <menu:menuitem menu:id=".uno:QuestionAnswers"/>
       <menu:menuitem menu:id=".uno:SendFeedback"/>
commit e6f9726e3fc6a32504bc0c8b489459828661a120
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Mon May 10 15:45:13 2021 +0900
Commit:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
CommitDate: Mon May 10 21:01:30 2021 +0900

    vcl: add more methods to the PDFium
    
    Change-Id: I74ef0f713125c7069620d1abc9534a636c1707d9

diff --git a/include/vcl/filter/PDFiumLibrary.hxx b/include/vcl/filter/PDFiumLibrary.hxx
index c5f1766f60c0..46988cf3c946 100644
--- a/include/vcl/filter/PDFiumLibrary.hxx
+++ b/include/vcl/filter/PDFiumLibrary.hxx
@@ -111,6 +111,13 @@ public:
     virtual PDFSegmentType getType() const = 0;
 };
 
+struct PDFImageMetadata
+{
+    sal_uInt32 mnWidth;
+    sal_uInt32 mnHeight;
+    sal_uInt32 mnBitsPerPixel;
+};
+
 class VCL_DLLPUBLIC PDFiumPageObject
 {
 public:
@@ -127,15 +134,20 @@ public:
     virtual double getFontSize() = 0;
     virtual OUString getFontName() = 0;
     virtual PDFTextRenderMode getTextRenderMode() = 0;
+    virtual bool hasTransparency() = 0;
     virtual Color getFillColor() = 0;
     virtual Color getStrokeColor() = 0;
     virtual double getStrokeWidth() = 0;
     // Path
     virtual int getPathSegmentCount() = 0;
     virtual std::unique_ptr<PDFiumPathSegment> getPathSegment(int index) = 0;
+    virtual bool getDrawMode(PDFFillMode& eFillMode, bool& bStroke) = 0;
+    // Image
     virtual Size getImageSize(PDFiumPage& rPage) = 0;
+    virtual PDFImageMetadata getImageMetadata(PDFiumPage& rPage) = 0;
+
     virtual std::unique_ptr<PDFiumBitmap> getImageBitmap() = 0;
-    virtual bool getDrawMode(PDFFillMode& eFillMode, bool& bStroke) = 0;
+    virtual bool getDecodedImageData(std::vector<sal_uInt8>& rData) = 0;
 };
 
 class VCL_DLLPUBLIC PDFiumSearchHandle
diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx
index adfa4db4fa45..f0fa8a8c2ce0 100644
--- a/vcl/source/pdf/PDFiumLibrary.cxx
+++ b/vcl/source/pdf/PDFiumLibrary.cxx
@@ -254,15 +254,19 @@ public:
     double getFontSize() override;
     OUString getFontName() override;
     PDFTextRenderMode getTextRenderMode() override;
+    bool hasTransparency() override;
     Color getFillColor() override;
     Color getStrokeColor() override;
     double getStrokeWidth() override;
     // Path
     int getPathSegmentCount() override;
     std::unique_ptr<PDFiumPathSegment> getPathSegment(int index) override;
+    bool getDrawMode(PDFFillMode& eFillMode, bool& bStroke) override;
+    // Image
     Size getImageSize(PDFiumPage& rPage) override;
+    PDFImageMetadata getImageMetadata(PDFiumPage& rPage) override;
     std::unique_ptr<PDFiumBitmap> getImageBitmap() override;
-    bool getDrawMode(PDFFillMode& eFillMode, bool& bStroke) override;
+    bool getDecodedImageData(std::vector<sal_uInt8>& rData) override;
 };
 
 class PDFiumSearchHandleImpl final : public PDFiumSearchHandle
@@ -835,6 +839,8 @@ Color PDFiumPageObjectImpl::getFillColor()
     return aColor;
 }
 
+bool PDFiumPageObjectImpl::hasTransparency() { return FPDFPageObj_HasTransparency(mpPageObject); }
+
 Color PDFiumPageObjectImpl::getStrokeColor()
 {
     Color aColor = COL_TRANSPARENT;
@@ -874,6 +880,28 @@ Size PDFiumPageObjectImpl::getImageSize(PDFiumPage& rPage)
     return Size(aMeta.width, aMeta.height);
 }
 
+PDFImageMetadata PDFiumPageObjectImpl::getImageMetadata(PDFiumPage& rPage)
+{
+    FPDF_IMAGEOBJ_METADATA aMeta;
+    auto& rPageImpl = static_cast<PDFiumPageImpl&>(rPage);
+    FPDFImageObj_GetImageMetadata(mpPageObject, rPageImpl.getPointer(), &aMeta);
+    return { aMeta.width, aMeta.height, aMeta.bits_per_pixel };
+}
+
+bool PDFiumPageObjectImpl::getDecodedImageData(std::vector<sal_uInt8>& rData)
+{
+    unsigned long nLength = FPDFImageObj_GetImageDataDecoded(mpPageObject, nullptr, 0);
+    if (nLength > 0)
+    {
+        rData.resize(nLength);
+        unsigned long nReadLength
+            = FPDFImageObj_GetImageDataDecoded(mpPageObject, rData.data(), nLength);
+        if (nReadLength == nLength)
+            return true;
+    }
+    return false;
+}
+
 std::unique_ptr<PDFiumBitmap> PDFiumPageObjectImpl::getImageBitmap()
 {
     std::unique_ptr<PDFiumBitmap> pPDFiumBitmap;
commit df2c95bb2ffd2731da4463a7aaf6df8d70f0a357
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Mon May 3 16:42:22 2021 +0900
Commit:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
CommitDate: Mon May 10 21:01:29 2021 +0900

    Add PDF importer to read a PDF into drawinglayer primitives
    
    Change-Id: I8d2e28a39515dfef8a1b4c6b06df095dd3a4eaec

diff --git a/Repository.mk b/Repository.mk
index 8e6f0be49fc6..3481abf3dcc8 100644
--- a/Repository.mk
+++ b/Repository.mk
@@ -398,6 +398,7 @@ $(eval $(call gb_Helper_register_libraries_for_install,OOOLIBS,ooo, \
 	passwordcontainer \
 	pcr \
 	pdffilter \
+	pdfimporter \
 	$(call gb_Helper_optional,SCRIPTING,protocolhandler) \
 	sax \
 	sb \
diff --git a/drawinglayer/source/tools/primitive2dxmldump.cxx b/drawinglayer/source/tools/primitive2dxmldump.cxx
index ade8cfaed89b..992619fe89f6 100644
--- a/drawinglayer/source/tools/primitive2dxmldump.cxx
+++ b/drawinglayer/source/tools/primitive2dxmldump.cxx
@@ -113,6 +113,13 @@ void Primitive2dXmlDump::dump(
     aWriter.endDocument();
 
     pStream->Seek(STREAM_SEEK_TO_BEGIN);
+
+    std::size_t nSize = pStream->remainingSize();
+    std::unique_ptr<sal_uInt8[]> pBuffer(new sal_uInt8[nSize + 1]);
+    pStream->ReadBytes(pBuffer.get(), nSize);
+    pBuffer[nSize] = 0;
+
+    printf ("%s\n", pBuffer.get());
 }
 
 xmlDocUniquePtr Primitive2dXmlDump::dumpAndParse(
diff --git a/filter/CppunitTest_filter_pdfimporter_test.mk b/filter/CppunitTest_filter_pdfimporter_test.mk
new file mode 100644
index 000000000000..3b17dcdcb43f
--- /dev/null
+++ b/filter/CppunitTest_filter_pdfimporter_test.mk
@@ -0,0 +1,48 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_CppunitTest_CppunitTest,filter_pdfimporter_test))
+
+$(eval $(call gb_CppunitTest_use_externals,filter_pdfimporter_test,\
+	boost_headers \
+	libxml2 \
+))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,filter_pdfimporter_test, \
+    filter/qa/cppunit/PdfImporterTest \
+))
+
+$(eval $(call gb_CppunitTest_use_library_objects,filter_pdfimporter_test,\
+    pdfimporter \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,filter_pdfimporter_test, \
+    basegfx \
+    drawinglayer \
+    comphelper \
+    cppu \
+    cppuhelper \
+    sal \
+    test \
+    unotest \
+    utl \
+    tl \
+    vcl \
+    tk \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,filter_pdfimporter_test))
+
+$(eval $(call gb_CppunitTest_use_sdk_api,filter_pdfimporter_test))
+$(eval $(call gb_CppunitTest_use_ure,filter_pdfimporter_test))
+$(eval $(call gb_CppunitTest_use_vcl,filter_pdfimporter_test))
+$(eval $(call gb_CppunitTest_use_rdb,filter_pdfimporter_test,services))
+
+
+# vim: set noet sw=4 ts=4:
diff --git a/filter/Library_pdfimporter.mk b/filter/Library_pdfimporter.mk
new file mode 100644
index 000000000000..93a567cbc247
--- /dev/null
+++ b/filter/Library_pdfimporter.mk
@@ -0,0 +1,35 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_Library_Library,pdfimporter))
+
+$(eval $(call gb_Library_set_include,pdfimporter,\
+	-I$(SRCDIR)/filter/inc \
+	$$(INCLUDE) \
+))
+
+$(eval $(call gb_Library_use_external,pdfimporter,boost_headers))
+
+$(eval $(call gb_Library_add_exception_objects,pdfimporter,\
+	filter/source/pdfimporter/PDFImporter \
+))
+
+$(eval $(call gb_Library_use_libraries,pdfimporter,\
+	drawinglayer \
+	basegfx \
+	vcl \
+	tl \
+	sal \
+	cppu \
+	tk \
+))
+
+$(eval $(call gb_Library_use_sdk_api,pdfimporter))
+
+# vim: set noet sw=4 ts=4:
diff --git a/filter/Module_filter.mk b/filter/Module_filter.mk
index 42a82bacf5c0..e079e523aa99 100644
--- a/filter/Module_filter.mk
+++ b/filter/Module_filter.mk
@@ -26,6 +26,7 @@ $(eval $(call gb_Module_add_targets,filter,\
 	Library_msfilter \
 	Library_odfflatxml \
 	Library_pdffilter \
+	Library_pdfimporter \
 	Library_storagefd \
 	Library_svgfilter \
 	Library_graphicfilter \
@@ -49,6 +50,7 @@ $(eval $(call gb_Module_add_check_targets,filter,\
     CppunitTest_filter_xslt \
     CppunitTest_filter_priority \
     CppunitTest_filter_msfilter \
+    CppunitTest_filter_pdfimporter_test \
     CppunitTest_filter_textfilterdetect \
 ))
 
diff --git a/filter/qa/cppunit/PdfImporterTest.cxx b/filter/qa/cppunit/PdfImporterTest.cxx
new file mode 100644
index 000000000000..ee57b9bdbc67
--- /dev/null
+++ b/filter/qa/cppunit/PdfImporterTest.cxx
@@ -0,0 +1,173 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <sal/config.h>
+#include <sal/types.h>
+#include <test/bootstrapfixture.hxx>
+#include <test/xmltesttools.hxx>
+
+#include <filter/pdfimporter/PDFImporter.hxx>
+#include <vcl/BinaryDataContainer.hxx>
+#include <tools/stream.hxx>
+#include <drawinglayer/converters.hxx>
+#include <drawinglayer/geometry/viewinformation2d.hxx>
+#include <drawinglayer/tools/primitive2dxmldump.hxx>
+
+#include <tools/stream.hxx>
+#include <vcl/pngwrite.hxx>
+
+class PDFImporterTest : public test::BootstrapFixture, public XmlTestTools
+{
+    OUString getFullUrl(std::u16string_view sFileName)
+    {
+        return m_directories.getURLFromSrc(u"/filter/qa/cppunit/data/") + sFileName;
+    }
+
+    void testPath();
+    void testImage();
+    void testText();
+
+    CPPUNIT_TEST_SUITE(PDFImporterTest);
+    //CPPUNIT_TEST(testPath);
+    //CPPUNIT_TEST(testImage);
+    CPPUNIT_TEST(testText);
+    CPPUNIT_TEST_SUITE_END();
+};
+
+void PDFImporterTest::testPath()
+{
+    SvFileStream aFileStream(getFullUrl(u"/PdfTest-Rect.pdf"), StreamMode::READ);
+    const sal_uInt64 nStreamLength = aFileStream.TellEnd();
+    auto rData = std::make_unique<std::vector<sal_uInt8>>(nStreamLength);
+    aFileStream.ReadBytes(rData->data(), rData->size());
+    BinaryDataContainer aDataContainer(std::move(rData));
+    PDFImporter aImporter(aDataContainer);
+
+    drawinglayer::primitive2d::Primitive2DContainer aContainer;
+    aImporter.importPage(0, aContainer);
+
+    drawinglayer::geometry::ViewInformation2D rViewInformation2D;
+
+    auto aRange = aContainer.getB2DRange(rViewInformation2D);
+
+    BitmapEx aBitmapEx
+        = drawinglayer::convertToBitmapEx(aContainer, rViewInformation2D, 2000, 2000, 10000 * 1000);
+
+    SvFileStream aNew("~/xxxxxxx.png", StreamMode::WRITE | StreamMode::TRUNC);
+    vcl::PNGWriter aPNGWriter(aBitmapEx);
+    aPNGWriter.Write(aNew);
+
+    drawinglayer::Primitive2dXmlDump aDumper;
+    aDumper.dump(aContainer, OUString());
+    xmlDocUniquePtr pDocument = aDumper.dumpAndParse(aContainer);
+    CPPUNIT_ASSERT(pDocument);
+
+    assertXPath(pDocument, "/primitive2D/metafile/transform/mask/transform/unifiedtransparence",
+                "transparence", "0.498039215686275");
+
+    CPPUNIT_ASSERT_EQUAL(-0.5, aRange.getMinX());
+    CPPUNIT_ASSERT_EQUAL(-0.5, aRange.getMinY());
+    CPPUNIT_ASSERT_EQUAL(612.5, aRange.getMaxX());
+    CPPUNIT_ASSERT_EQUAL(792.5, aRange.getMaxY());
+
+    CPPUNIT_ASSERT_EQUAL(tools::Long(1000), aBitmapEx.GetSizePixel().Width());
+    CPPUNIT_ASSERT_EQUAL(tools::Long(1000), aBitmapEx.GetSizePixel().Height());
+
+    CPPUNIT_ASSERT(false);
+}
+
+void PDFImporterTest::testImage()
+{
+    SvFileStream aFileStream(getFullUrl(u"/PdfTest-Image.pdf"), StreamMode::READ);
+    const sal_uInt64 nStreamLength = aFileStream.TellEnd();
+    auto rData = std::make_unique<std::vector<sal_uInt8>>(nStreamLength);
+    aFileStream.ReadBytes(rData->data(), rData->size());
+    BinaryDataContainer aDataContainer(std::move(rData));
+    PDFImporter aImporter(aDataContainer);
+
+    drawinglayer::primitive2d::Primitive2DContainer aContainer;
+    aImporter.importPage(0, aContainer);
+
+    drawinglayer::geometry::ViewInformation2D rViewInformation2D;
+
+    auto aRange = aContainer.getB2DRange(rViewInformation2D);
+
+    BitmapEx aBitmapEx
+        = drawinglayer::convertToBitmapEx(aContainer, rViewInformation2D, 2000, 2000, 10000 * 1000);
+
+    SvFileStream aNew("~/xxxxxxx.png", StreamMode::WRITE | StreamMode::TRUNC);
+    vcl::PNGWriter aPNGWriter(aBitmapEx);
+    aPNGWriter.Write(aNew);
+
+    drawinglayer::Primitive2dXmlDump aDumper;
+    aDumper.dump(aContainer, OUString());
+    xmlDocUniquePtr pDocument = aDumper.dumpAndParse(aContainer);
+    CPPUNIT_ASSERT(pDocument);
+
+    assertXPath(pDocument, "/primitive2D/metafile/transform/mask/transform/unifiedtransparence",
+                "transparence", "0.498039215686275");
+
+    CPPUNIT_ASSERT_EQUAL(-0.5, aRange.getMinX());
+    CPPUNIT_ASSERT_EQUAL(-0.5, aRange.getMinY());
+    CPPUNIT_ASSERT_EQUAL(612.5, aRange.getMaxX());
+    CPPUNIT_ASSERT_EQUAL(792.5, aRange.getMaxY());
+
+    CPPUNIT_ASSERT_EQUAL(tools::Long(1000), aBitmapEx.GetSizePixel().Width());
+    CPPUNIT_ASSERT_EQUAL(tools::Long(1000), aBitmapEx.GetSizePixel().Height());
+
+    CPPUNIT_ASSERT(false);
+}
+
+void PDFImporterTest::testText()
+{
+    SvFileStream aFileStream(getFullUrl(u"/PdfTest-Text.pdf"), StreamMode::READ);
+    const sal_uInt64 nStreamLength = aFileStream.TellEnd();
+    auto rData = std::make_unique<std::vector<sal_uInt8>>(nStreamLength);
+    aFileStream.ReadBytes(rData->data(), rData->size());
+    BinaryDataContainer aDataContainer(std::move(rData));
+    PDFImporter aImporter(aDataContainer);
+
+    drawinglayer::primitive2d::Primitive2DContainer aContainer;
+    aImporter.importPage(0, aContainer);
+
+    drawinglayer::geometry::ViewInformation2D rViewInformation2D;
+
+    auto aRange = aContainer.getB2DRange(rViewInformation2D);
+
+    BitmapEx aBitmapEx
+        = drawinglayer::convertToBitmapEx(aContainer, rViewInformation2D, 2000, 2000, 10000 * 1000);
+
+    SvFileStream aNew("~/xxxxxxx.png", StreamMode::WRITE | StreamMode::TRUNC);
+    vcl::PNGWriter aPNGWriter(aBitmapEx);
+    aPNGWriter.Write(aNew);
+
+    drawinglayer::Primitive2dXmlDump aDumper;
+    aDumper.dump(aContainer, OUString());
+    xmlDocUniquePtr pDocument = aDumper.dumpAndParse(aContainer);
+    CPPUNIT_ASSERT(pDocument);
+
+    assertXPath(pDocument, "/primitive2D/metafile/transform/mask/transform/unifiedtransparence",
+                "transparence", "0.498039215686275");
+
+    CPPUNIT_ASSERT_EQUAL(-0.5, aRange.getMinX());
+    CPPUNIT_ASSERT_EQUAL(-0.5, aRange.getMinY());
+    CPPUNIT_ASSERT_EQUAL(612.5, aRange.getMaxX());
+    CPPUNIT_ASSERT_EQUAL(792.5, aRange.getMaxY());
+
+    CPPUNIT_ASSERT_EQUAL(tools::Long(1000), aBitmapEx.GetSizePixel().Width());
+    CPPUNIT_ASSERT_EQUAL(tools::Long(1000), aBitmapEx.GetSizePixel().Height());
+
+    CPPUNIT_ASSERT(false);
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(PDFImporterTest);
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/filter/qa/cppunit/data/PdfTest-Image.pdf b/filter/qa/cppunit/data/PdfTest-Image.pdf
new file mode 100644
index 000000000000..394ee272f3d4
Binary files /dev/null and b/filter/qa/cppunit/data/PdfTest-Image.pdf differ
diff --git a/filter/qa/cppunit/data/PdfTest-Rect.pdf b/filter/qa/cppunit/data/PdfTest-Rect.pdf
new file mode 100644
index 000000000000..7115df65176f
--- /dev/null
+++ b/filter/qa/cppunit/data/PdfTest-Rect.pdf
@@ -0,0 +1,134 @@
+%PDF-1.6
+%äüöß
+2 0 obj
+<</Length 3 0 R/Filter/FlateDecode>>
+stream
+xœ¥ÁJA†ïyŠœ{˜&Ù™ÙY(=¸UQè¡zð	Úªl.H_ßÄìÈ"¢™Ãü!Éÿ%¡Àx7$¤@R03‡®el;ÿÇ=<-ðŒöÆ#¦Oà…ò
X#7¾ìLyÅ3°¼y9¾ûÕj¹íï6HëõÕ¦
+1¶”´%K“̤0·ÙhL:R,ÊSsSHÇ8Sž¬õBJ¹duL’bg„¢|¸Õ•s ê4¸èŒ÷ºÜë¿h°ƒëmÿ}Eö¢	ç‰Æ…ª£*§H’™òlíø…'ž´‘8a¥ÔñM9¬É4Sž­ÓQºÃX8wY
+endstream
+endobj
+
+3 0 obj
+241
+endobj
+
+8 0 obj
+<<
+>>
+endobj
+
+9 0 obj
+<</Font 8 0 R
+/ProcSet[/PDF/Text]
+>>
+endobj
+
+1 0 obj
+<</Type/Page/Parent 7 0 R/Resources 9 0 R/MediaBox[0 0 612 792]/StructParents 0
+/Group<</S/Transparency/CS/DeviceRGB/I true>>/Contents 2 0 R>>
+endobj
+
+10 0 obj
+<</Count 1/First 11 0 R/Last 11 0 R
+>>
+endobj
+
+11 0 obj
+<</Count 0/Title<FEFF005000610067006500200031>
+/Dest[1 0 R/XYZ 0 792 0]/Parent 10 0 R>>
+endobj
+
+4 0 obj
+<</Type/StructElem
+/S/Figure
+/P 12 0 R
+/Pg 1 0 R
+/K[0 ]
+>>
+endobj
+
+5 0 obj
+<</Type/StructElem
+/S/Figure
+/P 12 0 R
+/Pg 1 0 R
+/K[1 ]
+>>
+endobj
+
+6 0 obj
+<</Type/StructElem
+/S/Figure
+/P 12 0 R
+/Pg 1 0 R
+/K[2 ]
+>>
+endobj
+
+12 0 obj
+<</Type/StructTreeRoot
+/ParentTree 13 0 R
+/K[4 0 R 5 0 R 6 0 R ]
+>>
+endobj
+
+13 0 obj
+<</Nums[
+0 [ 4 0 R 5 0 R 6 0 R ]
+]>>
+endobj
+
+7 0 obj
+<</Type/Pages
+/Resources 9 0 R
+/MediaBox[ 0 0 612 792 ]
+/Kids[ 1 0 R ]
+/Count 1>>
+endobj
+
+14 0 obj
+<</Type/Catalog/Pages 7 0 R
+/OpenAction[1 0 R /XYZ null null 0]
+/ViewerPreferences<</DisplayDocTitle true
+>>
+/Outlines 10 0 R
+/StructTreeRoot 12 0 R
+/MarkInfo<</Marked true>>
+>>
+endobj
+
+15 0 obj
+<</Title<FEFF004D007900540065006D0070006C006100740065>
+/Creator<FEFF0044007200610077>
+/Producer<FEFF004C0069006200720065004F0066006600690063006500200037002E0030>
+/CreationDate(D:20210505091047+09'00')>>
+endobj
+
+xref
+0 16
+0000000000 65535 f 
+0000000426 00000 n 
+0000000019 00000 n 
+0000000331 00000 n 
+0000000746 00000 n 
+0000000821 00000 n 
+0000000896 00000 n 
+0000001110 00000 n 
+0000000351 00000 n 
+0000000373 00000 n 
+0000000585 00000 n 
+0000000641 00000 n 
+0000000971 00000 n 
+0000001056 00000 n 
+0000001208 00000 n 
+0000001403 00000 n 
+trailer
+<</Size 16/Root 14 0 R
+/Info 15 0 R
+/ID [ <3F7788F2D0928B3B95B0CDBBD9EAC1B8>
+<3F7788F2D0928B3B95B0CDBBD9EAC1B8> ]
+/DocChecksum /F2715E25D79DC609834CA579FA23A5BA
+>>
+startxref
+1623
+%%EOF
diff --git a/filter/qa/cppunit/data/PdfTest-Text.pdf b/filter/qa/cppunit/data/PdfTest-Text.pdf
new file mode 100644
index 000000000000..c449bf559228
Binary files /dev/null and b/filter/qa/cppunit/data/PdfTest-Text.pdf differ
diff --git a/filter/source/pdfimporter/PDFImporter.cxx b/filter/source/pdfimporter/PDFImporter.cxx
new file mode 100644
index 000000000000..b4b37aea7128
--- /dev/null
+++ b/filter/source/pdfimporter/PDFImporter.cxx
@@ -0,0 +1,384 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#include <filter/pdfimporter/PDFImporter.hxx>
+
+#include <sal/log.hxx>
+#include <tools/UnitConversion.hxx>
+#include <tools/color.hxx>
+#include <vcl/bitmapex.hxx>
+#include <vcl/BitmapTools.hxx>
+
+#include <cmath>
+
+#include <toolkit/helper/vclunohelper.hxx>
+
+#include <basegfx/matrix/b2dhommatrix.hxx>
+#include <basegfx/matrix/b2dhommatrixtools.hxx>
+#include <basegfx/polygon/b2dpolypolygon.hxx>
+#include <basegfx/polygon/b2dpolygontools.hxx>
+#include <basegfx/polygon/b2dpolygon.hxx>
+
+#include <drawinglayer/attribute/lineattribute.hxx>
+#include <drawinglayer/attribute/strokeattribute.hxx>
+#include <drawinglayer/primitive2d/transformprimitive2d.hxx>
+#include <drawinglayer/primitive2d/maskprimitive2d.hxx>
+#include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
+#include <drawinglayer/primitive2d/hiddengeometryprimitive2d.hxx>
+#include <drawinglayer/primitive2d/PolyPolygonStrokePrimitive2D.hxx>
+#include <drawinglayer/primitive2d/PolyPolygonColorPrimitive2D.hxx>
+#include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
+
+PDFImporter::PDFImporter(BinaryDataContainer& rDataContainer)
+    : mpPDFium(vcl::pdf::PDFiumLibrary::get())
+{
+    auto* pData = rDataContainer.getData();
+    sal_Int32 nSize = rDataContainer.getSize();
+
+    mpPdfDocument = mpPDFium->openDocument(pData, nSize);
+}
+
+namespace
+{
+void setupPage(drawinglayer::primitive2d::Primitive2DContainer& rContainer,
+               basegfx::B2DSize const& rPageSize)
+{
+    basegfx::B2DRange aPageRange(0.0, 0.0, rPageSize.getX(), rPageSize.getY());
+
+    printf("Page Size %.2fpt %.2fpt\n", rPageSize.getX(), rPageSize.getY());
+
+    const auto aPolygon = basegfx::utils::createPolygonFromRect(aPageRange);
+
+    const drawinglayer::primitive2d::Primitive2DReference xPage(
+        new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(aPolygon,
+                                                                  basegfx::BColor(0.0, 0.0, 0.0)));
+    const drawinglayer::primitive2d::Primitive2DReference xHidden(
+        new drawinglayer::primitive2d::HiddenGeometryPrimitive2D(
+            drawinglayer::primitive2d::Primitive2DContainer{ xPage }));
+
+    rContainer.push_back(xHidden);
+}
+
+double sqrt2(double a, double b) { return sqrt(a * a + b * b); }
+
+} // end anonymous namespace
+
+bool PDFImporter::importPage(int nPageIndex,
+                             drawinglayer::primitive2d::Primitive2DContainer& rContainer)
+{
+    if (!mpPdfDocument)
+        return false;
+
+    drawinglayer::primitive2d::Primitive2DContainer aContent;
+
+    const int nPageCount = mpPdfDocument->getPageCount();
+    if (!(nPageCount > 0 && nPageIndex >= 0 && nPageIndex < nPageCount))
+        return false;
+
+    mpPdfPage = mpPdfDocument->openPage(nPageIndex);
+    if (!mpPdfPage)
+        return false;
+
+    basegfx::B2DSize aPageSize = mpPdfDocument->getPageSize(nPageIndex);
+
+    setupPage(aContent, aPageSize);
+
+    // Load the page text to extract it when we get text elements.
+    auto pTextPage = mpPdfPage->getTextPage();
+
+    const int nPageObjectCount = mpPdfPage->getObjectCount();
+
+    for (int nPageObjectIndex = 0; nPageObjectIndex < nPageObjectCount; ++nPageObjectIndex)
+    {
+        auto pPageObject = mpPdfPage->getObject(nPageObjectIndex);
+        importPdfObject(pPageObject, pTextPage, nPageObjectIndex, aContent);
+    }
+
+    // point to pixel conversion
+    double dConversionFactor = double(conversionFract(o3tl::Length::pt, o3tl::Length::px));
+    const auto aTransform = basegfx::utils::createScaleTranslateB2DHomMatrix(
+        dConversionFactor, -dConversionFactor, 0.0, aPageSize.getY() * dConversionFactor);
+
+    const drawinglayer::primitive2d::Primitive2DReference xTransform(
+        new drawinglayer::primitive2d::TransformPrimitive2D(aTransform, aContent));
+
+    rContainer.push_back(xTransform);
+
+    return true;
+}
+
+void PDFImporter::importPdfObject(std::unique_ptr<vcl::pdf::PDFiumPageObject> const& pPageObject,
+                                  std::unique_ptr<vcl::pdf::PDFiumTextPage> const& pTextPage,
+                                  int nPageObjectIndex,
+                                  drawinglayer::primitive2d::Primitive2DContainer& rContent)
+{
+    if (!pPageObject)
+        return;
+
+    const vcl::pdf::PDFPageObjectType ePageObjectType = pPageObject->getType();
+    switch (ePageObjectType)
+    {
+        case vcl::pdf::PDFPageObjectType::Text:
+            printf("pdf::PDFPageObjectType::Text\n");
+            importText(pPageObject, pTextPage, rContent);
+            break;
+        case vcl::pdf::PDFPageObjectType::Path:
+            printf("pdf::PDFPageObjectType::Path\n");
+            importPath(pPageObject, rContent);
+            break;
+        case vcl::pdf::PDFPageObjectType::Image:
+            printf("pdf::PDFPageObjectType::Image\n");
+            importImage(pPageObject, rContent);
+            break;
+        case vcl::pdf::PDFPageObjectType::Shading:
+            printf("pdf::PDFPageObjectType::Shading\n");
+            break;
+        case vcl::pdf::PDFPageObjectType::Form:
+            printf("pdf::PDFPageObjectType::Form\n");
+            break;
+        case vcl::pdf::PDFPageObjectType::Unknown:
+            SAL_WARN("filter", "Unknown PDF page object #" << nPageObjectIndex
+                                                           << " of type: " << int(ePageObjectType));
+            break;
+    }
+}
+
+void PDFImporter::importText(std::unique_ptr<vcl::pdf::PDFiumPageObject> const& pPageObject,
+                             std::unique_ptr<vcl::pdf::PDFiumTextPage> const& pTextPage,
+                             drawinglayer::primitive2d::Primitive2DContainer& rRootContainer)
+{
+    basegfx::B2DRectangle aTextRect = pPageObject->getBounds();
+    basegfx::B2DHomMatrix aMatrix = pPageObject->getMatrix();
+
+    OUString sText = pPageObject->getText(pTextPage);
+
+    const double dFontSize = pPageObject->getFontSize();
+    double dFontSizeH = std::fabs(sqrt2(aMatrix.a(), aMatrix.c()) * dFontSize);
+    double dFontSizeV = std::fabs(sqrt2(aMatrix.b(), aMatrix.d()) * dFontSize);
+
+    OUString sFontName = pPageObject->getFontName();
+
+    printf("TEXT: %s\n", sText.toUtf8().getStr());
+
+    Color aTextColor(COL_TRANSPARENT);
+    bool bFill = false;
+    bool bUse = true;
+
+    switch (pPageObject->getTextRenderMode())
+    {
+        case vcl::pdf::PDFTextRenderMode::Fill:
+        case vcl::pdf::PDFTextRenderMode::FillClip:
+        case vcl::pdf::PDFTextRenderMode::FillStroke:
+        case vcl::pdf::PDFTextRenderMode::FillStrokeClip:
+            bFill = true;
+            break;
+        case vcl::pdf::PDFTextRenderMode::Stroke:
+        case vcl::pdf::PDFTextRenderMode::StrokeClip:
+        case vcl::pdf::PDFTextRenderMode::Unknown:
+            break;
+        case vcl::pdf::PDFTextRenderMode::Invisible:
+        case vcl::pdf::PDFTextRenderMode::Clip:
+            bUse = false;
+            break;
+    }
+
+    if (bUse)
+    {
+        Color aColor = bFill ? pPageObject->getFillColor() : pPageObject->getStrokeColor();
+        if (aColor != COL_TRANSPARENT)
+        {
+            aTextColor = aColor.GetRGBColor();
+        }
+    }
+}
+
+void PDFImporter::importImage(std::unique_ptr<vcl::pdf::PDFiumPageObject> const& pPageObject,
+                              drawinglayer::primitive2d::Primitive2DContainer& rRootContainer)
+{
+    std::unique_ptr<vcl::pdf::PDFiumBitmap> pPdfBitmap = pPageObject->getImageBitmap();
+    if (!pPdfBitmap)
+    {
+        SAL_WARN("filter", "Failed to get IMAGE");
+        return;
+    }
+
+    const vcl::pdf::PDFBitmapType eFormat = pPdfBitmap->getFormat();
+    if (eFormat == vcl::pdf::PDFBitmapType::Unknown)
+    {
+        SAL_WARN("filter", "Failed to get IMAGE format");
+        return;
+    }
+
+    vcl::pdf::PDFImageMetadata aMetadata = pPageObject->getImageMetadata(*mpPdfPage);
+    printf("METADATA %lu %lu %lu\n", aMetadata.mnWidth, aMetadata.mnHeight,
+           aMetadata.mnBitsPerPixel);
+
+    const sal_uInt8* pBuffer = pPdfBitmap->getBuffer();
+    const int nWidth = pPdfBitmap->getWidth();
+    const int nHeight = pPdfBitmap->getHeight();
+    const int nStride = pPdfBitmap->getStride();
+
+    BitmapEx aBitmap;
+
+    printf("hasTransparency %d\n", pPageObject->hasTransparency());
+
+    switch (eFormat)
+    {
+        case vcl::pdf::PDFBitmapType::BGR:
+            printf("vcl::pdf::PDFBitmapType::BGR\n");
+            aBitmap = vcl::bitmap::CreateFromData(pBuffer, nWidth, nHeight, nStride,
+                                                  vcl::PixelFormat::N24_BPP);
+            break;
+        case vcl::pdf::PDFBitmapType::BGRx:
+            printf("vcl::pdf::PDFBitmapType::BGRx\n");
+            aBitmap = vcl::bitmap::CreateFromData(pBuffer, nWidth, nHeight, nStride,
+                                                  vcl::PixelFormat::N32_BPP);
+            break;
+        case vcl::pdf::PDFBitmapType::BGRA:
+            printf("vcl::pdf::PDFBitmapType::BGRA\n");
+            aBitmap = vcl::bitmap::CreateFromData(pBuffer, nWidth, nHeight, nStride,
+                                                  vcl::PixelFormat::N32_BPP);
+            break;
+        case vcl::pdf::PDFBitmapType::Gray:
+            // TODO
+        default:
+            SAL_WARN("filter", "Got IMAGE width: " << nWidth << ", height: " << nHeight
+                                                   << ", stride: " << nStride
+                                                   << ", format: " << int(eFormat));
+            break;
+    }
+
+    basegfx::B2DRectangle aBounds = pPageObject->getBounds();
+
+    rRootContainer.push_back(new drawinglayer::primitive2d::BitmapPrimitive2D(
+        VCLUnoHelper::CreateVCLXBitmap(aBitmap), basegfx::utils::createScaleTranslateB2DHomMatrix(
+                                                     aBounds.getRange(), aBounds.getMinimum())));
+}
+
+void PDFImporter::importPath(std::unique_ptr<vcl::pdf::PDFiumPageObject> const& pPageObject,
+                             drawinglayer::primitive2d::Primitive2DContainer& rRootContainer)
+{
+    drawinglayer::primitive2d::Primitive2DContainer aContent;
+
+    basegfx::B2DHomMatrix aPathMatrix = pPageObject->getMatrix();
+
+    basegfx::B2DPolyPolygon aPolyPolygon;
+    basegfx::B2DPolygon aPolygon;
+    std::vector<basegfx::B2DPoint> aBezier;
+
+    const int nSegments = pPageObject->getPathSegmentCount();
+    for (int nSegmentIndex = 0; nSegmentIndex < nSegments; ++nSegmentIndex)
+    {
+        auto pPathSegment = pPageObject->getPathSegment(nSegmentIndex);
+        if (!pPathSegment)
+            continue;
+
+        basegfx::B2DPoint aB2DPoint = pPathSegment->getPoint();
+
+        aPolygon.setClosed(pPathSegment->isClosed());
+
+        const vcl::pdf::PDFSegmentType eSegmentType = pPathSegment->getType();
+        switch (eSegmentType)
+        {
+            case vcl::pdf::PDFSegmentType::Lineto:
+            {
+                aPolygon.append(aB2DPoint);
+            }
+            break;
+
+            case vcl::pdf::PDFSegmentType::Bezierto:
+            {
+                aBezier.emplace_back(aB2DPoint.getX(), aB2DPoint.getY());
+                if (aBezier.size() == 3)
+                {
+                    aPolygon.appendBezierSegment(aBezier[0], aBezier[1], aBezier[2]);
+                    aBezier.clear();
+                }
+            }
+            break;
+
+            case vcl::pdf::PDFSegmentType::Moveto:
+            {
+                if (aPolygon.count() > 0)
+                {
+                    aPolyPolygon.append(aPolygon);
+                    aPolygon.clear();
+                }
+
+                aPolygon.append(aB2DPoint);
+            }
+            break;
+
+            case vcl::pdf::PDFSegmentType::Unknown:
+            default:
+            {
+                SAL_WARN("filter", "Unknown path segment type in PDF: " << int(eSegmentType));
+            }
+            break;
+        }
+    }
+
+    if (aBezier.size() == 3)
+    {
+        aPolygon.appendBezierSegment(aBezier[0], aBezier[1], aBezier[2]);
+        aBezier.clear();
+    }
+
+    if (aPolygon.count() > 0)
+    {
+        aPolyPolygon.append(aPolygon, 1);
+        aPolygon.clear();
+    }
+
+    printf("PolyPoly size %d\n", aPolyPolygon.count());
+    for (auto const& rPoly : aPolyPolygon)
+        printf("Poly size %d\n", rPoly.count());
+
+    double fStrokeWidth = pPageObject->getStrokeWidth();
+    printf("Stroke: %f\n", fStrokeWidth);
+
+    vcl::pdf::PDFFillMode nFillMode = vcl::pdf::PDFFillMode::Alternate;
+    bool bStroke = true;
+
+    if (!pPageObject->getDrawMode(nFillMode, bStroke))
+    {
+        SAL_WARN("filter", "Huh...");
+    }
+
+    Color aFillColor = pPageObject->getFillColor();
+    Color aStokeColor = COL_TRANSPARENT;
+
+    if (bStroke)
+    {
+        aStokeColor = pPageObject->getStrokeColor();
+    }
+
+    if (aStokeColor == COL_TRANSPARENT)
+        aStokeColor = aFillColor;
+
+    if (!bStroke)
+    {
+        const drawinglayer::primitive2d::Primitive2DReference xPolyPolygonColorPrimitive(
+            new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(aPolyPolygon,
+                                                                       aFillColor.getBColor()));
+        aContent.push_back(xPolyPolygonColorPrimitive);
+    }
+
+    drawinglayer::attribute::LineAttribute aLineAttribute(aStokeColor.getBColor(), fStrokeWidth);
+    const drawinglayer::primitive2d::Primitive2DReference xPolyPolygonStrokePrimitive(
+        new drawinglayer::primitive2d::PolyPolygonStrokePrimitive2D(aPolyPolygon, aLineAttribute));
+    aContent.push_back(xPolyPolygonStrokePrimitive);
+
+    const drawinglayer::primitive2d::Primitive2DReference xTransform(
+        new drawinglayer::primitive2d::TransformPrimitive2D(aPathMatrix, aContent));
+    rRootContainer.push_back(xTransform);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/filter/pdfimporter/PDFImporter.hxx b/include/filter/pdfimporter/PDFImporter.hxx
new file mode 100644
index 000000000000..01cd94d264c9
--- /dev/null
+++ b/include/filter/pdfimporter/PDFImporter.hxx
@@ -0,0 +1,45 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#pragma once
+
+#include <vcl/filter/PDFiumLibrary.hxx>
+#include <drawinglayer/primitive2d/Primitive2DContainer.hxx>
+#include <vcl/BinaryDataContainer.hxx>
+
+class PDFImporter
+{
+private:
+    std::shared_ptr<vcl::pdf::PDFium> mpPDFium;
+    std::unique_ptr<vcl::pdf::PDFiumDocument> mpPdfDocument;
+    std::unique_ptr<vcl::pdf::PDFiumPage> mpPdfPage;
+
+    void importPdfObject(std::unique_ptr<vcl::pdf::PDFiumPageObject> const& pPageObject,
+                         std::unique_ptr<vcl::pdf::PDFiumTextPage> const& pTextPage,
+                         int nPageObjectIndex,
+                         drawinglayer::primitive2d::Primitive2DContainer& rRootContainer);
+
+    void importText(std::unique_ptr<vcl::pdf::PDFiumPageObject> const& pPageObject,
+                    std::unique_ptr<vcl::pdf::PDFiumTextPage> const& pTextPage,
+                    drawinglayer::primitive2d::Primitive2DContainer& rRootContainer);
+
+    void importPath(std::unique_ptr<vcl::pdf::PDFiumPageObject> const& pPageObject,
+                    drawinglayer::primitive2d::Primitive2DContainer& rRootContainer);
+
+    void importImage(std::unique_ptr<vcl::pdf::PDFiumPageObject> const& pPageObject,
+                     drawinglayer::primitive2d::Primitive2DContainer& rRootContainer);
+
+public:
+    PDFImporter(BinaryDataContainer& rDataContainer);
+
+    bool importPage(int nPageIndex, drawinglayer::primitive2d::Primitive2DContainer& rContainer);
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list