Skip to content

Commit

Permalink
1.2024.08.26: fix #20: margins: add framings
Browse files Browse the repository at this point in the history
  • Loading branch information
zvezdochiot committed Aug 26, 2024
1 parent 09b729a commit 6e6fa76
Show file tree
Hide file tree
Showing 41 changed files with 970 additions and 155 deletions.
2 changes: 1 addition & 1 deletion src/stages/page_layout/ApplyDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace page_layout

ApplyDialog::ApplyDialog(QWidget* parent, PageId const& cur_page,
PageSelectionAccessor const& page_selection_accessor)
: QDialog(parent),
: QDialog(parent),
m_pages(page_selection_accessor.allPages()),
m_selectedPages(page_selection_accessor.selectedPages()),
m_selectedRanges(page_selection_accessor.selectedRanges()),
Expand Down
1 change: 1 addition & 0 deletions src/stages/page_layout/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ SET(
ApplyDialog.cpp ApplyDialog.h
Alignment.cpp Alignment.h
MatchSizeMode.cpp MatchSizeMode.h
Framings.cpp Framings.h
PageLayout.cpp PageLayout.h
OrderByWidthProvider.cpp OrderByWidthProvider.h
OrderByHeightProvider.cpp OrderByHeightProvider.h
Expand Down
37 changes: 24 additions & 13 deletions src/stages/page_layout/CacheDrivenTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <memory>
#include <QSizeF>
#include <QRectF>
#include <QPolygonF>
#include "CacheDrivenTask.h"
#include "Settings.h"
#include "Params.h"
Expand All @@ -28,10 +32,6 @@
#include "stages/output/CacheDrivenTask.h"
#include "filter_dc/AbstractFilterDataCollector.h"
#include "filter_dc/ThumbnailCollector.h"
#include <QSizeF>
#include <QRectF>
#include <QPolygonF>
#include <memory>

using namespace imageproc;

Expand All @@ -41,8 +41,8 @@ namespace page_layout
CacheDrivenTask::CacheDrivenTask(
IntrusivePtr<output::CacheDrivenTask> const& next_task,
IntrusivePtr<Settings> const& settings)
: m_ptrNextTask(next_task)
, m_ptrSettings(settings)
: m_ptrNextTask(next_task)
, m_ptrSettings(settings)
{
}

Expand All @@ -52,7 +52,8 @@ CacheDrivenTask::~CacheDrivenTask()

void
CacheDrivenTask::process(
PageInfo const& page_info, AbstractFilterDataCollector* collector,
PageInfo const& page_info,
AbstractFilterDataCollector* collector,
std::shared_ptr<imageproc::AbstractImageTransform const> const& full_size_image_transform,
ContentBox const& content_box)
{
Expand Down Expand Up @@ -85,17 +86,24 @@ CacheDrivenTask::process(
);

PageLayout const page_layout(
unscaled_content_rect, m_ptrSettings->getAggregateHardSize(),
params->matchSizeMode(), params->alignment(), params->hardMargins()
unscaled_content_rect,
m_ptrSettings->getAggregateHardSize(),
params->matchSizeMode(),
params->alignment(),
params->framings(),
params->hardMargins()
);
page_layout.absorbScalingIntoTransform(*adjusted_transform);

if (m_ptrNextTask)
{

m_ptrNextTask->process(
page_info, adjusted_transform,
page_layout.innerRect(), page_layout.outerRect(), collector
page_info,
adjusted_transform,
page_layout.innerRect(),
page_layout.extraRect(params->framings()),
collector
);
return;
}
Expand All @@ -111,8 +119,11 @@ CacheDrivenTask::process(
new Thumbnail(
thumb_col->thumbnailCache(),
thumb_col->maxLogicalThumbSize(),
page_info.id(), *params,
*adjusted_transform, page_layout
page_info.id(),
*params,
*adjusted_transform,
page_layout,
params->framings()
)
);
}
Expand Down
22 changes: 12 additions & 10 deletions src/stages/page_layout/Filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <assert.h>
#include <QRectF>
#include <QSizeF>
#include <QString>
#include <QObject>
#include <QCoreApplication>
#include <QDomDocument>
#include <QDomElement>
#include "Filter.h"
#include "FilterUiInterface.h"
#include "OptionsWidget.h"
Expand All @@ -25,6 +33,7 @@
#include "RelativeMargins.h"
#include "MatchSizeMode.h"
#include "Alignment.h"
#include "Framings.h"
#include "Params.h"
#include "ProjectPages.h"
#include "ProjectReader.h"
Expand All @@ -35,22 +44,14 @@
#include "OrderByRatioProvider.h"
#include "OrderByAreaProvider.h"
#include "Utils.h"
#include <QRectF>
#include <QSizeF>
#include <QString>
#include <QObject>
#include <QCoreApplication>
#include <QDomDocument>
#include <QDomElement>
#include <assert.h>
#include "CommandLine.h"

namespace page_layout
{

Filter::Filter(IntrusivePtr<ProjectPages> const& pages,
PageSelectionAccessor const& page_selection_accessor)
: m_ptrPages(pages),
: m_ptrPages(pages),
m_ptrSettings(new Settings),
m_selectedPageOrder(0)
{
Expand Down Expand Up @@ -128,8 +129,9 @@ Filter::preUpdateUI(FilterUiInterface* ui, PageId const& page_id)
RelativeMargins const margins(m_ptrSettings->getHardMargins(page_id));
MatchSizeMode const match_size_mode(m_ptrSettings->getMatchSizeMode(page_id));
Alignment const alignment(m_ptrSettings->getPageAlignment(page_id));
Framings const framings(m_ptrSettings->getPageFramings(page_id));

m_ptrOptionsWidget->preUpdateUI(page_id, margins, match_size_mode, alignment);
m_ptrOptionsWidget->preUpdateUI(page_id, margins, match_size_mode, alignment, framings);
ui->setOptionsWidget(m_ptrOptionsWidget.get(), ui->KEEP_OWNERSHIP);
}

Expand Down
42 changes: 42 additions & 0 deletions src/stages/page_layout/Framings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Scan Tailor - Interactive post-processing tool for scanned pages.
Copyright (C) 2007-2008 Joseph Artsimovich <joseph_a@mail.ru>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <QDomDocument>
#include <QDomElement>
#include <QString>
#include "Framings.h"

namespace page_layout
{

Framings::Framings(QDomElement const& el)
: m_framingw(el.attribute("framingWidth").toDouble()),
m_framingh(el.attribute("framingHeight").toDouble())
{
}

QDomElement
Framings::toXml(QDomDocument& doc, QString const& name) const
{
QDomElement el(doc.createElement(name));
el.setAttribute("framingWidth", m_framingw);
el.setAttribute("framingHeight", m_framingh);
return el;
}

} // namespace page_layout
74 changes: 74 additions & 0 deletions src/stages/page_layout/Framings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
Scan Tailor - Interactive post-processing tool for scanned pages.
Copyright (C) 2007-2008 Joseph Artsimovich <joseph_a@mail.ru>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef PAGE_LAYOUT_FRAMINGS_H_
#define PAGE_LAYOUT_FRAMINGS_H_

class QDomDocument;
class QDomElement;
class QString;

namespace page_layout
{

class Framings
{
public:
Framings() : m_framingw(0.12), m_framingh(0.08) {}

Framings(double hor, double vert) : m_framingw(hor), m_framingh(vert) {}

Framings(QDomElement const& el);

double getFramingWidth() const
{
return m_framingw;
}
void setFramingWidth(double value)
{
m_framingw = value;
}

double getFramingHeight() const
{
return m_framingh;
}
void setFramingHeight(double value)
{
m_framingh = value;
}

bool operator==(Framings const& other) const
{
return m_framingw == other.m_framingw && m_framingh == other.m_framingh;
}

bool operator!=(Framings const& other) const
{
return !(*this == other);
}

QDomElement toXml(QDomDocument& doc, QString const& name) const;
private:
double m_framingw;
double m_framingh;
};

} // namespace page_layout

#endif
Loading

0 comments on commit 6e6fa76

Please sign in to comment.