summaryrefslogtreecommitdiff
path: root/sw/source/core/inc
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2021-12-07 23:25:54 +0100
committerMiklos Vajna <vmiklos@collabora.com>2022-01-06 09:18:40 +0100
commitd9ad5c6c174b22e0808b948bfc5087d38874f9b2 (patch)
tree882037b7156a0363844e1b6669a9a3779a8412c9 /sw/source/core/inc
parent331b1fba6b1981a867678795e2fc38185bc0cac6 (diff)
Add graphic size checker for the preferred document DPI
This change adds a graphic size checker, which checks all the images in the document, if they largely differ (outside of 50% and 110% of the image size) from the set preferred image DPI document setting. For all images that don't fall under this bounds, list them in the dialog and offer the posibility to select/goto the image and pop-up the properties dialog for the image to change its size. Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127094 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com> (cherry picked from commit 046e6cfa544d2ffd67fd29ba7dde41b495744618) Change-Id: I06efce77c291fdb6ec3864d72c2f4d15dba9c42b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127207 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sw/source/core/inc')
-rw-r--r--sw/source/core/inc/GraphicSizeCheck.hxx99
-rw-r--r--sw/source/core/inc/ModelTraverser.hxx51
2 files changed, 150 insertions, 0 deletions
diff --git a/sw/source/core/inc/GraphicSizeCheck.hxx b/sw/source/core/inc/GraphicSizeCheck.hxx
new file mode 100644
index 000000000000..f708b0a5f4dc
--- /dev/null
+++ b/sw/source/core/inc/GraphicSizeCheck.hxx
@@ -0,0 +1,99 @@
+/* -*- 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 <doc.hxx>
+#include "ModelTraverser.hxx"
+#include <svx/GenericCheckDialog.hxx>
+
+namespace sw
+{
+class GraphicSizeViolation final
+{
+private:
+ const SwGrfNode* m_pGraphicNode;
+
+ sal_Int32 m_nLowDPILimit = 0;
+ sal_Int32 m_nHighDPILimit = 0;
+
+ sal_Int32 m_nDPIX = 0;
+ sal_Int32 m_nDPIY = 0;
+
+public:
+ GraphicSizeViolation(sal_Int32 nDPI, const SwGrfNode* pGraphicNode);
+ bool check();
+
+ OUString getGraphicName();
+
+ bool isDPITooLow() { return m_nDPIX < m_nLowDPILimit || m_nDPIY < m_nLowDPILimit; }
+
+ bool isDPITooHigh() { return m_nDPIX > m_nHighDPILimit || m_nDPIY > m_nHighDPILimit; }
+
+ sal_Int32 getDPIX() { return m_nDPIX; }
+
+ sal_Int32 getDPIY() { return m_nDPIY; }
+};
+
+class GraphicSizeCheck final
+{
+private:
+ SwDoc* m_pDocument;
+ std::vector<std::unique_ptr<GraphicSizeViolation>> m_aGraphicSizeViolationList;
+
+public:
+ GraphicSizeCheck(SwDoc* pDocument)
+ : m_pDocument(pDocument)
+ {
+ }
+
+ void check();
+
+ std::vector<std::unique_ptr<GraphicSizeViolation>>& getViolationList()
+ {
+ return m_aGraphicSizeViolationList;
+ }
+};
+
+class GraphicSizeCheckGUIEntry : public svx::CheckData
+{
+private:
+ SwDoc* m_pDocument;
+ std::unique_ptr<GraphicSizeViolation> m_pViolation;
+
+public:
+ GraphicSizeCheckGUIEntry(SwDoc* pDocument, std::unique_ptr<GraphicSizeViolation>&& pViolation)
+ : m_pDocument(pDocument)
+ , m_pViolation(std::move(pViolation))
+ {
+ }
+
+ OUString getText() override;
+
+ bool canMarkObject() override { return true; }
+
+ void markObject() override;
+
+ bool hasProperties() override { return true; }
+
+ void runProperties() override;
+};
+
+class GraphicSizeCheckGUIResult : public svx::CheckDataCollection
+{
+public:
+ GraphicSizeCheckGUIResult(SwDoc* pDocument);
+
+ OUString getTitle() override;
+};
+
+} // end sw namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/inc/ModelTraverser.hxx b/sw/source/core/inc/ModelTraverser.hxx
new file mode 100644
index 000000000000..f3c6acb9c6dd
--- /dev/null
+++ b/sw/source/core/inc/ModelTraverser.hxx
@@ -0,0 +1,51 @@
+/* -*- 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 <doc.hxx>
+
+class SwNode;
+class SdrObject;
+
+namespace sw
+{
+class SW_DLLPUBLIC ModelTraverseHandler
+{
+public:
+ virtual ~ModelTraverseHandler() {}
+
+ virtual void handleNode(SwNode* pNode) = 0;
+ virtual void handleSdrObject(SdrObject* pObject) = 0;
+};
+
+class ModelTraverser
+{
+private:
+ std::vector<std::shared_ptr<ModelTraverseHandler>> mpNodeHandler;
+ SwDoc* m_pDoc;
+
+public:
+ ModelTraverser(SwDoc* pDoc)
+ : m_pDoc(pDoc)
+ {
+ }
+
+ void traverse();
+
+ void addNodeHandler(std::shared_ptr<ModelTraverseHandler> pHandler)
+ {
+ mpNodeHandler.push_back(pHandler);
+ }
+};
+
+} // end sw namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */