Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pdf text recognition phase1. basic text import and layout #135

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scribus/plugins/import/pdf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ set(IMPORTPDF_PLUGIN_SOURCES
importpdfplugin.cpp
pdfimportoptions.cpp
slaoutput.cpp
pdftextrecognition.cpp
)

if(HAVE_POPPLER)
Expand Down
12 changes: 10 additions & 2 deletions scribus/plugins/import/pdf/importpdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ for which a new license (GPL+exception) is in place.
#include "importpdf.h"
#include "importpdfconfig.h"
#include "slaoutput.h"
#include "pdftextrecognition.h"

#include "commonstrings.h"
#include "loadsaveplugin.h"
Expand Down Expand Up @@ -430,6 +431,7 @@ bool PdfPlug::convert(const QString& fn)
else if (getCBox(Art_Box, 1) != mediaRect)
boxesAreDifferent = true;
bool cropped = false;
bool importTextAsVectors = true;
int contentRect = Media_Box;
if (((interactive) || (importerFlags & LoadSavePlugin::lfCreateDoc)) && ((lastPage > 1) || boxesAreDifferent))
{
Expand All @@ -455,6 +457,7 @@ bool PdfPlug::convert(const QString& fn)
cropped = optImp->croppingEnabled();
if (!cropped)
crop = cropped;
importTextAsVectors = optImp->getImportAsVectors();
// When displaying pages slices, we should always set useMediaBox to true
// in order to use MediaBox (x, y) as coordinate system
if (contentRect != Media_Box)
Expand All @@ -468,7 +471,12 @@ bool PdfPlug::convert(const QString& fn)
}
parsePagesString(pageString, &pageNs, lastPage);
firstPage = pageNs[0];
SlaOutputDev *dev = new SlaOutputDev(m_Doc, &Elements, &importedColors, importerFlags);
SlaOutputDev* dev = {};
if (importTextAsVectors)
dev = new SlaOutputDev(m_Doc, &Elements, &importedColors, importerFlags);
else
dev = new PdfTextOutputDev(m_Doc, &Elements, &importedColors, importerFlags);

if (dev->isOk())
{
OCGs* ocg = pdfDoc->getOptContentConfig();
Expand Down Expand Up @@ -899,7 +907,7 @@ QImage PdfPlug::readPreview(int pgNum, int width, int height, int box)
{
if (!m_pdfDoc)
return QImage();

double h = m_pdfDoc->getPageMediaHeight(pgNum);
double w = m_pdfDoc->getPageMediaWidth(pgNum);
double scale = qMin(height / h, width / w);
Expand Down
7 changes: 7 additions & 0 deletions scribus/plugins/import/pdf/pdfimportoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ bool PdfImportOptions::croppingEnabled()
return ui->cropGroup->isChecked();
}

bool PdfImportOptions::getImportAsVectors()
{
return ui->textAsVectors->isChecked();
}

void PdfImportOptions::setUpOptions(const QString& fileName, int actPage, int numPages, bool interact, bool cropPossible, PdfPlug* plug)
{
m_plugin = plug;
Expand All @@ -71,6 +76,8 @@ void PdfImportOptions::setUpOptions(const QString& fileName, int actPage, int nu
ui->cropGroup->setVisible(cropPossible);
ui->cropGroup->setChecked(cropPossible);
ui->cropBox->setCurrentIndex(3); // Use CropBox by default
ui->textAsVectors->setChecked(true);
ui->textAsText->setChecked(false);
if (interact)
{
ui->allPages->setChecked(false);
Expand Down
1 change: 1 addition & 0 deletions scribus/plugins/import/pdf/pdfimportoptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class PdfImportOptions : public QDialog
QString getPagesString();
int getCropBox();
bool croppingEnabled();
bool getImportAsVectors();
void paintEvent(QPaintEvent *e);

protected:
Expand Down
35 changes: 35 additions & 0 deletions scribus/plugins/import/pdf/pdfimportoptions.ui
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,41 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string/>
</property>
<layout class="QVBoxLayout" name="verticalLayout_8">
<item>
<widget class="QRadioButton" name="textAsVectors">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Import Text As Vectors</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="textAsText">
<property name="text">
<string>Import Text As Text</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
Expand Down
Loading