Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpenBoard
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lifo
Nicolas Ollinger
OpenBoard
Commits
d86e3c01
Commit
d86e3c01
authored
Aug 05, 2011
by
ivan.ilyin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added initial sources for sff files import.
parent
eaf2558d
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
822 additions
and
94 deletions
+822
-94
UBCFFSubsetAdaptor.cpp
src/adaptors/UBCFFSubsetAdaptor.cpp
+593
-5
UBCFFSubsetAdaptor.h
src/adaptors/UBCFFSubsetAdaptor.h
+61
-2
UBImportCFF.cpp
src/adaptors/UBImportCFF.cpp
+109
-32
adaptors.pri
src/adaptors/adaptors.pri
+59
-55
No files found.
src/adaptors/UBCFFSubsetAdaptor.cpp
View file @
d86e3c01
This diff is collapsed.
Click to expand it.
src/adaptors/UBCFFSubsetAdaptor.h
View file @
d86e3c01
...
...
@@ -3,24 +3,83 @@
#include <QtXml>
#include <QString>
#include <QStack>
class
UBDocumentProxy
;
class
UBGraphicsScene
;
class
QSvgGenerator
;
class
UBCFFSubsetAdaptor
{
public
:
UBCFFSubsetAdaptor
();
static
void
ConvertCFFFileToUbz
(
QString
&
cffSourceFolder
,
QString
&
destinationFolder
);
static
bool
ConvertCFFFileToUbz
(
QString
&
cffSourceFile
,
UBDocumentProxy
*
pDocument
);
private
:
class
UBCFFSubsetReader
{
//xml parse states definition
enum
{
NONE
,
IWB
,
SVG
,
PAGESET
,
PAGE
,
TEXTAREA
,
TSPAN
};
public
:
UBCFFSubsetReader
(
UBDocumentProxy
*
proxy
);
UBCFFSubsetReader
(
UBDocumentProxy
*
proxy
,
QByteArray
&
content
);
QXmlStreamReader
mReader
;
UBDocumentProxy
*
mProxy
;
bool
parse
();
private
:
QString
mTempFilePath
;
UBGraphicsScene
*
mCurrentScene
;
QString
mIndent
;
QRectF
mViewBox
;
QSize
mSize
;
//methods to store current xml parse state
int
PopState
();
void
PushState
(
int
state
);
//elements parsing methods
bool
parseDoc
();
bool
parseCurrentElementStart
();
bool
parseCurrentElementCharacters
();
bool
parseCurrentElementEnd
();
bool
parseIwb
();
bool
parseIwbMeta
();
bool
parseSvg
();
bool
parseRect
();
bool
parseEllipse
();
bool
parseTextArea
();
bool
parsePolygon
();
bool
parsePage
();
bool
parsePageSet
();
bool
parseIwbElementRef
();
bool
createNewScene
();
bool
persistCurrentScene
();
QStack
<
int
>
stateStack
;
int
currentState
;
//helper methods
QColor
colorFromString
(
const
QString
&
clrString
);
QTransform
transformFromString
(
const
QString
trString
);
bool
getViewBoxDimenstions
(
const
QString
&
viewBox
);
QSvgGenerator
*
createSvgGenerator
();
bool
getTempFileName
();
};
};
...
...
src/adaptors/UBImportCFF.cpp
View file @
d86e3c01
...
...
@@ -5,14 +5,15 @@
#include "core/UBApplication.h"
#include "core/UBPersistenceManager.h"
#include "core/UBDocumentManager.h"
#include "core/memcheck.h"
#include "core/UBPersistenceManager.h"
#include "frameworks/UBFileSystemUtils.h"
#include "domain/UBGraphicsPDFItem.h"
#include "pdf/PDFRenderer.h"
#include "core/memcheck.h"
#include "core/UBPersistenceManager.h"
#include "UBCFFSubsetAdaptor.h"
...
...
@@ -63,25 +64,53 @@ QString UBImportCFF::importFileFilter()
bool
UBImportCFF
::
addFileToDocument
(
UBDocumentProxy
*
pDocument
,
const
QFile
&
pFile
)
{
//TODO add cff file import here
/* int res = UBDocumentManager::documentManager()->addImageAsPageToDocument(QStringList(QFileInfo(pFile).absoluteFilePath()), pDocument);
if (res == 0)
{
UBApplication::showMessage(tr("Image import failed."));
return false;
QFileInfo
fi
(
pFile
);
UBApplication
::
showMessage
(
tr
(
"Importing file %1..."
).
arg
(
fi
.
baseName
()),
true
);
// first unzip the file to the correct place
//TODO create temporary path for iwb file content
QString
path
=
QDir
::
tempPath
();
QString
documentRootFolder
=
expandFileToDir
(
pFile
,
path
);
QString
contentFile
;
if
(
documentRootFolder
.
isEmpty
())
//if file has failed to unzip it is probably just xml file
contentFile
=
pFile
.
fileName
();
else
//get path to content xml (according to iwbcff specification)
contentFile
=
documentRootFolder
.
append
(
"/content.xml"
);
if
(
!
contentFile
.
length
()){
UBApplication
::
showMessage
(
tr
(
"Import of file %1 failed."
).
arg
(
fi
.
baseName
()));
return
false
;
}
else
{
//TODO convert expanded CFF file content to the destination document
//create destination document proxy
//fill metadata and save
UBDocumentProxy
*
destDocument
=
new
UBDocumentProxy
(
UBPersistenceManager
::
persistenceManager
()
->
generateUniqueDocumentPath
());
QDir
dir
;
dir
.
mkdir
(
destDocument
->
persistencePath
());
//try to import cff to document
if
(
UBCFFSubsetAdaptor
::
ConvertCFFFileToUbz
(
contentFile
,
destDocument
))
{
UBPersistenceManager
::
persistenceManager
()
->
addDirectoryContentToDocument
(
destDocument
->
persistencePath
(),
pDocument
);
UBFileSystemUtils
::
deleteDir
(
destDocument
->
persistencePath
());
delete
destDocument
;
UBApplication
::
showMessage
(
tr
(
"Import successful."
));
return
true
;
}
else
{
UBFileSystemUtils
::
deleteDir
(
destDocument
->
persistencePath
());
delete
destDocument
;
UBApplication
::
showMessage
(
tr
(
"Import failed."
));
return
false
;
}
}
else
{
UBApplication::showMessage(tr("Image import successful."));
return true;
}*/
return
true
;
}
QString
UBImportCFF
::
expandFileToDir
(
const
QFile
&
pZipFile
,
const
QString
&
pDir
)
{
QDir
rootDir
(
pDir
);
QuaZip
zip
(
pZipFile
.
fileName
());
if
(
!
zip
.
open
(
QuaZip
::
mdUnzip
))
...
...
@@ -94,10 +123,34 @@ QString UBImportCFF::expandFileToDir(const QFile& pZipFile, const QString& pDir)
QuaZipFileInfo
info
;
QuaZipFile
file
(
&
zip
);
// TODO UB 4.x implement a mechanism that can replace an existing
// document based on the UID of the document.
bool
createNewDocument
=
true
;
//create unique cff document root fodler
//use current date/time and temp number for folder name
QString
documentRootFolder
;
int
tmpNumber
=
0
;
QDir
rootDir
;
while
(
true
)
{
QString
tempPath
=
QString
(
"%1/sank%2.%3"
)
.
arg
(
pDir
)
.
arg
(
QDateTime
::
currentDateTime
().
toString
(
"dd_MM_yyyy_HH-mm"
))
.
arg
(
tmpNumber
);
if
(
!
rootDir
.
exists
(
tempPath
))
{
documentRootFolder
=
tempPath
;
break
;
}
tmpNumber
++
;
if
(
tmpNumber
==
100000
)
{
qWarning
()
<<
"Import failed. Failed to create temporary directory for iwb file"
;
return
""
;
}
}
if
(
!
rootDir
.
mkdir
(
documentRootFolder
))
{
qWarning
()
<<
"Import failed. Couse: failed to create temp folder for cff package"
;
}
// first we search the metadata.rdf to check the document properties
for
(
bool
more
=
zip
.
goToFirstFile
();
more
;
more
=
zip
.
goToNextFile
())
...
...
@@ -111,9 +164,6 @@ QString UBImportCFF::expandFileToDir(const QFile& pZipFile, const QString& pDir)
QFileInfo
currentFileInfo
(
pDir
+
"/"
+
file
.
getActualFileName
());
}
if
(
createNewDocument
)
documentRootFolder
=
UBPersistenceManager
::
persistenceManager
()
->
generateUniqueDocumentPath
();
QFile
out
;
char
c
;
...
...
@@ -208,22 +258,49 @@ UBDocumentProxy* UBImportCFF::importFile(const QFile& pFile, const QString& pGro
QString
path
=
QDir
::
tempPath
();
QString
documentRootFolder
=
expandFileToDir
(
pFile
,
path
);
QString
contentFile
;
if
(
documentRootFolder
.
isEmpty
())
documentRootFolder
=
pFile
.
fileName
();
//if file has failed to umzip it is probably just xml file
contentFile
=
pFile
.
fileName
();
else
documentRootFolder
=
path
.
append
(
"
\\
content.xml"
);
//get path to content xml
contentFile
=
QString
(
"%1/content.xml"
).
arg
(
documentRootFolder
);
if
(
!
documentRootFolder
.
length
()){
if
(
!
contentFile
.
length
()){
UBApplication
::
showMessage
(
tr
(
"Import of file %1 failed."
).
arg
(
fi
.
baseName
()));
return
0
;
}
else
{
//TODO convert expanded CFF file content to ubz destination folder
QString
temporaryFolder
=
QDir
::
tempPath
();
UBCFFSubsetAdaptor
::
ConvertCFFFileToUbz
(
documentRootFolder
,
temporaryFolder
);
// create document proxy for destination folder and return
UBDocumentProxy
*
newDocument
=
UBPersistenceManager
::
persistenceManager
()
->
createDocumentFromDir
(
temporaryFolder
);
UBApplication
::
showMessage
(
tr
(
"Import successful."
));
//create destination document proxy
//fill metadata and save
UBDocumentProxy
*
destDocument
=
new
UBDocumentProxy
(
UBPersistenceManager
::
persistenceManager
()
->
generateUniqueDocumentPath
());
QDir
dir
;
dir
.
mkdir
(
destDocument
->
persistencePath
());
if
(
pGroup
.
length
()
>
0
)
destDocument
->
setMetaData
(
UBSettings
::
documentGroupName
,
pGroup
);
if
(
fi
.
baseName
()
>
0
)
destDocument
->
setMetaData
(
UBSettings
::
documentName
,
fi
.
baseName
());
destDocument
->
setMetaData
(
UBSettings
::
documentVersion
,
UBSettings
::
currentFileVersion
);
destDocument
->
setMetaData
(
UBSettings
::
documentUpdatedAt
,
UBStringUtils
::
toUtcIsoDateTime
(
QDateTime
::
currentDateTime
()));
UBDocumentProxy
*
newDocument
=
NULL
;
//try to import cff to document
if
(
UBCFFSubsetAdaptor
::
ConvertCFFFileToUbz
(
contentFile
,
destDocument
))
{
newDocument
=
UBPersistenceManager
::
persistenceManager
()
->
createDocumentFromDir
(
destDocument
->
persistencePath
());
UBApplication
::
showMessage
(
tr
(
"Import successful."
));
}
else
{
UBFileSystemUtils
::
deleteDir
(
destDocument
->
persistencePath
());
UBApplication
::
showMessage
(
tr
(
"Import failed."
));
}
delete
destDocument
;
if
(
documentRootFolder
.
length
()
!=
0
)
UBFileSystemUtils
::
deleteDir
(
documentRootFolder
);
return
newDocument
;
}
}
src/adaptors/adaptors.pri
View file @
d86e3c01
HEADERS += src/adaptors/UBExportAdaptor.h\
src/adaptors/UBExportPDF.h \
src/adaptors/UBExportFullPDF.h \
src/adaptors/UBExportDocument.h \
src/adaptors/UBSvgSubsetAdaptor.h \
src/adaptors/UBMetadataDcSubsetAdaptor.h \
src/adaptors/UBImportAdaptor.h \
src/adaptors/UBImportDocument.h \
src/adaptors/UBThumbnailAdaptor.h \
src/adaptors/UBImportPDF.h \
src/adaptors/UBImportImage.h \
src/adaptors/UBIniFileParser.h \
src/adaptors/UBExportWeb.h \
src/adaptors/UBWebPublisher.h
HEADERS += src/adaptors/publishing/UBDocumentPublisher.h \
src/adaptors/publishing/UBCapturePublisher.h \
src/adaptors/publishing/UBAbstractPublisher.h \
src/adaptors/publishing/UBSvgSubsetRasterizer.h
HEADERS += src/adaptors/voting/UBAbstractVotingSystem.h
SOURCES += src/adaptors/UBExportAdaptor.cpp\
src/adaptors/UBExportPDF.cpp \
src/adaptors/UBExportFullPDF.cpp \
src/adaptors/UBExportDocument.cpp \
src/adaptors/UBSvgSubsetAdaptor.cpp \
src/adaptors/UBMetadataDcSubsetAdaptor.cpp \
src/adaptors/UBImportAdaptor.cpp \
src/adaptors/UBImportDocument.cpp \
src/adaptors/UBThumbnailAdaptor.cpp \
src/adaptors/UBImportPDF.cpp \
src/adaptors/UBImportImage.cpp \
src/adaptors/UBIniFileParser.cpp \
src/adaptors/UBExportWeb.cpp \
src/adaptors/UBWebPublisher.cpp
SOURCES += src/adaptors/publishing/UBDocumentPublisher.cpp \
src/adaptors/publishing/UBCapturePublisher.cpp \
src/adaptors/publishing/UBAbstractPublisher.cpp \
src/adaptors/publishing/UBSvgSubsetRasterizer.cpp
SOURCES += src/adaptors/voting/UBAbstractVotingSystem.cpp
win32 {
SOURCES += src/adaptors/voting/UBReply2005VotingSystem.cpp \
src/adaptors/voting/UBReplyWRS970VotingSystem.cpp
HEADERS += src/adaptors/voting/UBReply2005VotingSystem.h \
src/adaptors/voting/UBReplyWRS970VotingSystem.h
}
HEADERS += src/adaptors/UBExportAdaptor.h\
src/adaptors/UBExportPDF.h \
src/adaptors/UBExportFullPDF.h \
src/adaptors/UBExportDocument.h \
src/adaptors/UBSvgSubsetAdaptor.h \
src/adaptors/UBMetadataDcSubsetAdaptor.h \
src/adaptors/UBImportAdaptor.h \
src/adaptors/UBImportDocument.h \
src/adaptors/UBThumbnailAdaptor.h \
src/adaptors/UBImportPDF.h \
src/adaptors/UBImportImage.h \
src/adaptors/UBIniFileParser.h \
src/adaptors/UBExportWeb.h \
src/adaptors/UBWebPublisher.h \
src/adaptors/UBImportCFF.h \
src/adaptors/UBCFFSubsetAdaptor.h
HEADERS += src/adaptors/publishing/UBDocumentPublisher.h \
src/adaptors/publishing/UBCapturePublisher.h \
src/adaptors/publishing/UBAbstractPublisher.h \
src/adaptors/publishing/UBSvgSubsetRasterizer.h
HEADERS += src/adaptors/voting/UBAbstractVotingSystem.h
SOURCES += src/adaptors/UBExportAdaptor.cpp\
src/adaptors/UBExportPDF.cpp \
src/adaptors/UBExportFullPDF.cpp \
src/adaptors/UBExportDocument.cpp \
src/adaptors/UBSvgSubsetAdaptor.cpp \
src/adaptors/UBMetadataDcSubsetAdaptor.cpp \
src/adaptors/UBImportAdaptor.cpp \
src/adaptors/UBImportDocument.cpp \
src/adaptors/UBThumbnailAdaptor.cpp \
src/adaptors/UBImportPDF.cpp \
src/adaptors/UBImportImage.cpp \
src/adaptors/UBIniFileParser.cpp \
src/adaptors/UBExportWeb.cpp \
src/adaptors/UBWebPublisher.cpp \
src/adaptors/UBImportCFF.cpp \
src/adaptors/UBCFFSubsetAdaptor.cpp
SOURCES += src/adaptors/publishing/UBDocumentPublisher.cpp \
src/adaptors/publishing/UBCapturePublisher.cpp \
src/adaptors/publishing/UBAbstractPublisher.cpp \
src/adaptors/publishing/UBSvgSubsetRasterizer.cpp
SOURCES += src/adaptors/voting/UBAbstractVotingSystem.cpp
win32 {
SOURCES += src/adaptors/voting/UBReply2005VotingSystem.cpp \
src/adaptors/voting/UBReplyWRS970VotingSystem.cpp
HEADERS += src/adaptors/voting/UBReply2005VotingSystem.h \
src/adaptors/voting/UBReplyWRS970VotingSystem.h
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment