Merge pull request #601 from andreasb242/cleanup

Cleanup
presentation
andreasb242 7 years ago committed by GitHub
commit bc13f3dbf2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      .travis.yml
  2. 17
      CMakeLists.txt
  3. 7
      readme/LinuxBuild.md
  4. 1
      src/control/Control.cpp
  5. 3
      src/control/jobs/PdfExportJob.cpp
  6. 2
      src/model/Document.cpp
  7. 42
      src/util/GzHelper.cpp
  8. 29
      src/util/GzHelper.h
  9. 172
      src/util/XojPreviewExtractor.cpp
  10. 10
      src/util/XojPreviewExtractor.h
  11. 1
      src/util/XournalTypeList.h
  12. 7
      src/view/background/BackgroundConfig.cpp
  13. 12
      src/xoj-preview-extractor/CMakeLists.txt
  14. 4
      src/xoj-preview-extractor/xournal-thumbnailer.cpp
  15. 0
      test/files/load/test.xoi
  16. 6
      test/util/XojPreviewExtractorTest.cpp

@ -25,7 +25,6 @@ addons:
- cmake
- libboost-filesystem-dev
- libboost-iostreams-dev
- libcppunit-dev
@ -36,11 +35,6 @@ addons:
- libgtk-3-dev
- libpoppler-glib-dev
# Do not use PPAs, use standard Ubuntu Sources
# sources:
# - boost-latest
# - kalakris-cmake
coverity_scan:
project:
name: "xournalpp/xournalpp"
@ -56,7 +50,7 @@ before_script:
script:
- "cmake .. -DCMAKE_DEBUG_INCLUDES_LDFLAGS=ON -DENABLE_MATHTEX=ON -DENABLE_CPPUNIT=ON -DUNSTABLE_LAYERS_SIDEBAR=ON -DDEBUG_COMPILE=ON"
- "make -j`grep processor /proc/cpuinfo | tail -c 2`"
- "make -j `grep processor /proc/cpuinfo | tail -c 2`"
- "ctest"
notifications:

@ -77,7 +77,7 @@ if (BUILD_BOOST)
BUILD_COMMAND cd "${BOOST_PREFIX}/src/boost" && ./b2
${BOOST_CXXFLAGS}
--with-filesystem --with-iostreams
--with-filesystem
"--prefix=${BOOST_PREFIX}"
"--build-dir=${BOOST_PREFIX}/src/boost-build"
"--stagedir=${BOOST_PREFIX}"
@ -89,7 +89,6 @@ if (BUILD_BOOST)
link_directories ("${BOOST_PREFIX}/lib/")
set (Boost_LIBRARIES
boost_filesystem
boost_iostreams
${ICU_LIBRARIES}
)
set (Boost_INCLUDE_DIRS "${BOOST_PREFIX}/src/boost")
@ -97,7 +96,7 @@ if (BUILD_BOOST)
else (BUILD_BOOST)
set (Boost_USE_MULTITHREADED ON)
find_package (Boost 1.54 COMPONENTS filesystem iostreams)
find_package (Boost 1.54 COMPONENTS filesystem)
if (Boost_VERSION VERSION_LESS 1.54)
message (FATAL_ERROR "Boost 1.54 or newer not found – you should enable BUILD_BOOST CMake flag")
endif (Boost_VERSION VERSION_LESS 1.54)
@ -121,19 +120,7 @@ add_includes_ldflags ("${GThread_LDFLAGS}" "${GThread_INCLUDE_DIRS}")
pkg_check_modules (Libxml REQUIRED "libxml-2.0 >= 2.0.0")
add_includes_ldflags ("${Libxml_LDFLAGS}" "${Libxml_INCLUDE_DIRS}")
find_program(LSB_RELEASE_EXEC lsb_release)
execute_process(COMMAND ${LSB_RELEASE_EXEC} -is
OUTPUT_VARIABLE LSB_RELEASE_ID_SHORT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
find_program(LSB_RELEASE_EXEC lsb_release)
execute_process(COMMAND ${LSB_RELEASE_EXEC} -rs
OUTPUT_VARIABLE LSB_RELEASE_NUMBER_SHORT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Poppler
pkg_check_modules (PopplerGlib REQUIRED "poppler-glib >= 0.41.0")
add_includes_ldflags ("${PopplerGlib_LDFLAGS}" "${PopplerGlib_INCLUDE_DIRS}")
set(POPPLER_INCLUDE_DIR, "${PopplerGlib_INCLUDE_DIRS}")

@ -21,15 +21,14 @@ dnf install cmake texlive-scheme-basic texlive-dvipng poppler-glib-devel
### For Ubuntu/Debian:
````bash
sudo apt-get install cmake libgtk-3-dev libpoppler-glib-dev \
libboost-filesystem-dev libboost-locale-dev libboost-iostreams-dev \
libcppunit-dev dvipng texlive
libboost-filesystem-dev libcppunit-dev dvipng texlive
````
### For OpenSuse:
```bash
sudo zypper install cmake gtk3-devel cppunit-devel \
libboost_filesystem-devel libboost_locale-devel libboost_iostreams-devel \
texlive-dvipng texlive libxml2-devel libpoppler-glib-devel
libboost_filesystem-devel texlive-dvipng texlive libxml2-devel \
libpoppler-glib-devel
```
### For Fedora:

@ -1985,7 +1985,6 @@ bool Control::newFile(string pageTemplate)
return true;
}
/**
* Check if this is an autosave file, return false in this case and display a user instruction
*/

@ -5,9 +5,6 @@
#include <i18n.h>
#include <boost/algorithm/string/predicate.hpp>
PdfExportJob::PdfExportJob(Control* control)
: BaseExportJob(control, _("PDF Export"))
{

@ -187,7 +187,7 @@ path Document::createSaveFilename(DocumentType type, string defaultSaveName)
{
if (!filename.empty())
{
//This can be any extension
// This can be any extension
return filename.stem();
}
else if (!pdfFilename.empty())

@ -1,42 +0,0 @@
#include "GzHelper.h"
#include "Stacktrace.h"
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filtering_streambuf.hpp>
namespace bio = boost::iostreams;
#include <sstream>
using std::stringstream;
GzHelper::GzHelper() { }
GzHelper::~GzHelper() { }
string GzHelper::gzcompress(const string& str, const bio::zlib_params& params)
{
stringstream decompressed;
decompressed << str;
bio::filtering_istreambuf out;
out.push(bio::zlib_compressor(params));
out.push(decompressed);
stringstream compressed;
bio::copy(out, compressed);
return compressed.str();
}
string GzHelper::gzuncompress(const string& str)
{
stringstream compressed;
compressed << str;
bio::filtering_istreambuf in;
in.push(bio::zlib_decompressor());
in.push(compressed);
stringstream decompressed;
bio::copy(in, decompressed);
return decompressed.str();
}

@ -1,29 +0,0 @@
/*
* Xournal++
*
* Helper functions for ZLib GZip Compression
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <boost/iostreams/filter/gzip.hpp>
namespace bio = boost::iostreams;
#include <string>
using std::string;
class GzHelper
{
private:
GzHelper();
virtual ~GzHelper();
public:
static string gzcompress(const string& str, const bio::zlib_params& = bio::zlib::default_compression);
static string gzuncompress(const string& str);
};

@ -1,22 +1,15 @@
#include "XojPreviewExtractor.h"
#include <glib.h>
#include <glib/gstdio.h>
#include <boost/iostreams/filter/gzip.hpp>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/algorithm/string.hpp>
namespace bio = boost::iostreams;
#include <iostream>
using std::istream;
#include <fstream>
using std::ifstream;
#include <memory>
using std::unique_ptr;
#define TAG_PREVIEW_NAME "preview"
#define TAG_PAGE_NAME "page"
#include <zlib.h>
#include <string.h>
const char* TAG_PREVIEW_NAME = "preview";
const int TAG_PREVIEW_NAME_LEN = strlen(TAG_PREVIEW_NAME);
const char* TAG_PAGE_NAME = "page";
const int TAG_PAGE_NAME_LEN = strlen(TAG_PAGE_NAME);
const char* TAG_PREVIEW_END_NAME = "/preview";
const int TAG_PREVIEW_END_NAME_LEN = strlen(TAG_PREVIEW_END_NAME);
#define BUF_SIZE 8192
XojPreviewExtractor::XojPreviewExtractor()
@ -32,7 +25,6 @@ XojPreviewExtractor::~XojPreviewExtractor()
dataLen = 0;
}
/**
* @return The preview data, should be a binary PNG
*/
@ -42,13 +34,67 @@ unsigned char* XojPreviewExtractor::getData(gsize& dataLen)
return this->data;
}
#define CLOSE \
if (gzip) \
{ \
delete in; \
} \
ifile.close(); \
return
/**
* Try to read the preview from byte buffer
* @param buffer Buffer
* @param len Buffer len
* @return If an image was read, or the error
*/
PreviewExtractResult XojPreviewExtractor::readPreview(char* buffer, int len)
{
bool inTag = false;
int startTag = 0;
int startPreview = -1;
int endPreview = -1;
int pageStart = -1;
for (int i = 0; i < len; i++)
{
if (inTag)
{
if (buffer[i] == '>')
{
inTag = false;
int tagLen = i - startTag;
if (tagLen == TAG_PREVIEW_NAME_LEN && strncmp(TAG_PREVIEW_NAME, buffer + startTag, TAG_PREVIEW_NAME_LEN) == 0)
{
startPreview = i + 1;
}
if (tagLen == TAG_PREVIEW_END_NAME_LEN && strncmp(TAG_PREVIEW_END_NAME, buffer + startTag, TAG_PREVIEW_END_NAME_LEN) == 0)
{
endPreview = i - TAG_PREVIEW_END_NAME_LEN - 1;
break;
}
if (tagLen >= TAG_PAGE_NAME_LEN && strncmp(TAG_PAGE_NAME, buffer + startTag, TAG_PAGE_NAME_LEN) == 0)
{
pageStart = i;
break;
}
}
continue;
}
if (buffer[i] == '<')
{
inTag = true;
startTag = i + 1;
continue;
}
}
if (startPreview != -1 && endPreview != -1)
{
buffer[endPreview] = 0;
this->data = g_base64_decode(buffer + startPreview, &dataLen);
return PREVIEW_RESULT_IMAGE_READ;
}
if (pageStart != -1)
{
return PREVIEW_RESULT_NO_PREVIEW;
}
return PREVIEW_RESULT_ERROR_READING_PREVIEW;
}
/**
* Try to read the preview from file
@ -63,7 +109,6 @@ PreviewExtractResult XojPreviewExtractor::readFile(string file)
if (dotPos != string::npos)
{
ext = file.substr(dotPos);
boost::algorithm::to_lower(ext);
}
if (!(ext == ".xoj" || ext == ".xopp"))
@ -71,79 +116,22 @@ PreviewExtractResult XojPreviewExtractor::readFile(string file)
return PREVIEW_RESULT_BAD_FILE_EXTENSION;
}
// open input file
ifstream ifile(file, ifstream::in | ifstream::binary);
if (!ifile.is_open())
gzFile fp = gzopen(file.c_str(), "r");
if (!fp)
{
return PREVIEW_RESULT_COULD_NOT_OPEN_FILE;
}
istream* in;
bio::filtering_istreambuf inbuf;
bool gzip;
// check for gzip magic header
if (ifile.get() == 0x1F && ifile.get() == 0x8B)
{
gzip = true;
ifile.seekg(0); //seek back to beginning
inbuf.push(bio::gzip_decompressor());
inbuf.push(ifile);
// The <preview> Tag is within the first 179 Bytes
// The Preview should end within the first 8k
in = new istream(&inbuf);
}
else
{
gzip = false;
in = &ifile;
}
char buf[BUF_SIZE];
bool inPreview = false;
bool inTag = false;
string preview;
while (!in->eof())
{
if (in->peek() == '<')
{
in->ignore();
inTag = true;
continue;
}
in->get(buf, BUF_SIZE, '<');
if (!inPreview)
{
if (inTag)
{
if (strncmp(TAG_PREVIEW_NAME, buf, sizeof(TAG_PREVIEW_NAME) - 1) == 0)
{
inPreview = true;
preview += (buf + sizeof(TAG_PREVIEW_NAME));
}
else if (strncmp(TAG_PAGE_NAME, buf, sizeof(TAG_PAGE_NAME) - 1) == 0)
{
CLOSE PREVIEW_RESULT_NO_PREVIEW;
}
inTag = false;
}
}
else
{
if (inTag)
{
this->data = g_base64_decode(preview.c_str(), &this->dataLen);
CLOSE PREVIEW_RESULT_IMAGE_READ;
}
else
{
preview += buf;
}
}
}
char buffer[BUF_SIZE];
int readLen = gzread(fp, buffer, BUF_SIZE);
PreviewExtractResult result = readPreview(buffer, readLen);
CLOSE PREVIEW_RESULT_ERROR_READING_PREVIEW;
gzclose(fp);
return result;
}

@ -4,7 +4,7 @@
* Extracts a preview of an .xoj file, used by xournal-thumbnailer and xournalpp
* Because of this xournal type checks cannot be used
*
* @author Andreas Butti <andreasbutti@gmail.com>
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
@ -60,6 +60,14 @@ public:
*/
PreviewExtractResult readFile(string file);
/**
* Try to read the preview from byte buffer
* @param buffer Buffer
* @param len Buffer len
* @return If an image was read, or the error
*/
PreviewExtractResult readPreview(char* buffer, int len);
/**
* @return The preview data, should be a binary PNG
*/

@ -250,4 +250,5 @@ XOJ_DECLARE_TYPE(InputSequence, 239);
XOJ_DECLARE_TYPE(ZoomGesture, 240);
XOJ_DECLARE_TYPE(GroupUndoAction, 241);
XOJ_DECLARE_TYPE(FillTransparencyDialog, 242);
XOJ_DECLARE_TYPE(Path, 243);

@ -1,15 +1,12 @@
#include "BackgroundConfig.h"
#include <boost/algorithm/string.hpp>
#include <StringUtils.h>
BackgroundConfig::BackgroundConfig(string config)
{
XOJ_INIT_TYPE(BackgroundConfig);
vector<string> parts;
boost::split(parts, config, boost::is_any_of(","));
for (string s : parts)
for (string s : StringUtils::split(config, ','))
{
size_t dotPos = s.find_last_of("=");
if (dotPos != string::npos)

@ -1,6 +1,7 @@
## xournal-thumbnailer executable ##
if (WIN32)
# Windows does not support the thumbniler like this
return ()
endif ()
@ -11,22 +12,11 @@ add_executable (xournal-thumbnailer
)
target_link_libraries (xournal-thumbnailer
${Boost_LIBRARIES}
${Glibmm_LDFLAGS}
${ZLIB_LIBRARIES}
${Glib_LDFLAGS}
${GThread_LDFLAGS}
${Libxml_LDFLAGS}
)
if (BUILD_BOOST)
add_dependencies (xournal-thumbnailer boost)
endif (BUILD_BOOST)
set (THUMBNAILER_BIN "xournal-thumbnailer")
if (WIN32)
set (THUMBNAILER_BIN "${THUMBNAILER_BIN}.exe")
endif (WIN32)
add_custom_command (TARGET xournal-thumbnailer POST_BUILD
COMMAND ${CMAKE_STRIP} ${THUMBNAILER_BIN}

@ -3,7 +3,7 @@
*
* This small program extracts a preview out of a xoj file
*
* @author MarPiRK
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GPL
@ -23,8 +23,6 @@
using std::cerr;
using std::cout;
using std::endl;
#include <string>
using std::string;
void initLocalisation()
{

@ -52,13 +52,9 @@ public:
void testExtensionCheck()
{
XojPreviewExtractor extractor;
PreviewExtractResult result = extractor.readFile(GET_TESTFILE("THIS FILE DOES NOT EXIST.xoi"));
PreviewExtractResult result = extractor.readFile(GET_TESTFILE("test.xoi"));
CPPUNIT_ASSERT_EQUAL(PREVIEW_RESULT_BAD_FILE_EXTENSION, result);
result = extractor.readFile(GET_TESTFILE("THIS FILE DOES NOT EXIST.xOj"));
CPPUNIT_ASSERT_EQUAL(PREVIEW_RESULT_COULD_NOT_OPEN_FILE, result);
}
void testLoadGzipped()

Loading…
Cancel
Save