Skip to content

Commit

Permalink
[Gtk] Restore cross-compilation for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
AvtechScientific authored Jul 8, 2021
1 parent e1fad70 commit e5b3188
Show file tree
Hide file tree
Showing 17 changed files with 57 additions and 25 deletions.
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ IF("${INTERFACE_TYPE}" STREQUAL "gtk")
ENDIF()
ENDIF()
PKG_CHECK_MODULES(FONTCONFIG REQUIRED fontconfig)
PKG_CHECK_MODULES(UUID REQUIRED uuid)
INCLUDE_DIRECTORIES(
${GTKMM_INCLUDE_DIRS}
${GTKSOURCEVIEWMM_INCLUDE_DIRS}
Expand All @@ -141,7 +140,6 @@ IF("${INTERFACE_TYPE}" STREQUAL "gtk")
${LIBJPEG_INCLUDE_DIRS}
${FONTCONFIG_INCLUDE_DIRS}
${LIBZIP_INCLUDE_DIRS}
${UUID_INCLUDE_DIRS}
)
SET(gimagereader_LIBS
${GTKMM_LDFLAGS}
Expand All @@ -155,7 +153,6 @@ IF("${INTERFACE_TYPE}" STREQUAL "gtk")
${LIBJPEG_LDFLAGS}
${FONTCONFIG_LDFLAGS}
${LIBZIP_LDFLAGS}
${UUID_LDFLAGS}
)
SET(srcdir "gtk")
ELSEIF("${INTERFACE_TYPE}" STREQUAL "qt5")
Expand Down
2 changes: 1 addition & 1 deletion gtk/src/Config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ std::string Config::tessdataLocation(Location location) {
if(location == SystemLocation) {
#ifdef G_OS_WIN32
std::string dataDir = Glib::build_filename(pkgDir, "share");
Glib::setenv("TESSDATA_PREFIX", Glib::build_filename(dataDir, "tessdata");
Glib::setenv("TESSDATA_PREFIX", Glib::build_filename(dataDir, "tessdata"));
#else
Glib::unsetenv("TESSDATA_PREFIX");
#endif
Expand Down
10 changes: 7 additions & 3 deletions gtk/src/FileDialogs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <gdk/gdkwin32.h>
#include <windows.h>
#include <locale>
#include <shlobj.h>
#else
#include <gdk/gdkx.h>
#endif
Expand Down Expand Up @@ -120,12 +121,15 @@ static std::string win32_open_folder_dialog(const Glib::ustring& title, const st
binfo.iImage = 0;
PIDLIST_ABSOLUTE result = SHBrowseForFolderW(&binfo);
if(result == NULL) {
// ToDo: shouldn't we release the memory hold by "result"?...
return std::string();
}
wchar_t buffer[MAX_PATH];
if(SHGetPathFromIDList(pidl, buffer)) {
return ws2s(buffer);
TCHAR buffer[MAX_PATH];
if(SHGetPathFromIDList(result, buffer)) {
// ToDo: shouldn't we release the memory hold by "result"?...
return std::string(buffer);
}
// ToDo: shouldn't we release the memory hold by "result"?...
return std::string();
}

Expand Down
4 changes: 2 additions & 2 deletions gtk/src/FileTreeModel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void FileTreeModel::recursive_row_inserted(const Gtk::TreeIter& index) {

Gtk::TreeIter FileTreeModel::insertFile(std::string filePath, DataObject* data, const Glib::ustring& displayName) {
#ifdef G_OS_WIN32
std::string fileDir = std::string("/") + Glib::path_get_dirname(filePath);
Glib::ustring fileDir = std::string("/") + Glib::path_get_dirname(filePath);
Utils::string_replace(fileDir, "\\", "/", true);
filePath = std::string("/") + filePath;
std::string tempPath = std::string("/") + Glib::get_tmp_dir();
Expand Down Expand Up @@ -182,7 +182,7 @@ Gtk::TreeIter FileTreeModel::findFile(const std::string& filePath, bool isFile)

#ifdef G_OS_WIN32
std::string prefix = "/";
std::string fileDir = std::string("/") + Glib::path_get_dirname(filePath);
Glib::ustring fileDir = std::string("/") + Glib::path_get_dirname(filePath);
Utils::string_replace(fileDir, "\\", "/", true);
std::string tempPath = std::string("/") + Glib::get_tmp_dir();
#else
Expand Down
7 changes: 7 additions & 0 deletions gtk/src/Utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
#include <clocale>
#include <csignal>
#include <fontconfig/fontconfig.h>

#ifdef G_OS_WIN32
#include <windows.h>
#endif

#define USE_STD_NAMESPACE
#include <tesseract/baseapi.h>
#undef USE_STD_NAMESPACE
Expand Down Expand Up @@ -192,9 +197,11 @@ std::string Utils::make_absolute_path(const std::string& path, const std::string
return path;
}
std::string abspath = Glib::build_filename(basepath, path);
#ifdef G_OS_UNIX
char* realabspath = realpath(abspath.c_str(), nullptr);
abspath = std::string(realabspath);
free(realabspath);
#endif
return abspath;
}

Expand Down
20 changes: 7 additions & 13 deletions gtk/src/hocr/HOCROdtExporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <cstring>
#include <iomanip>
#include <libxml++/libxml++.h>
#include <uuid/uuid.h>
#include <glib/guuid.h>
#include <zip.h>

static Glib::ustring manifestNS_URI("urn:oasis:names:tc:opendocument:xmlns:manifest:1.0");
Expand Down Expand Up @@ -352,18 +352,12 @@ void HOCROdtExporter::writeImage(zip* fzip, std::map<const HOCRItem*, Glib::ustr
if(item->itemClass() == "ocr_graphic") {
Cairo::RefPtr<Cairo::ImageSurface> selection;
Utils::runInMainThreadBlocking([&] { selection = getSelection(item->bbox()); });
//#if GLIB_CHECK_VERSION(2, 52, 0)
// gchar* guuid = g_uuid_string_random();
// Glib::ustring uuid(guuid);
// g_free(guuid);
// uuid = uuid.substr(1, uuid.length() - 2); // Remove {}
//#else
uuid_t uuidGenerated;
uuid_generate_random(uuidGenerated);
char uuidBuff[36];
uuid_unparse(uuidGenerated, uuidBuff);
Glib::ustring uuid(uuidBuff);
//#endif

gchar* guuid = g_uuid_string_random();
Glib::ustring uuid(guuid);
g_free(guuid);
uuid = uuid.substr(1, uuid.length() - 2); // Remove {}

Glib::ustring filename = Glib::ustring::compose("Pictures/%1.png", uuid);

Glib::RefPtr<Glib::ByteArray> pngbytes = Glib::ByteArray::create();
Expand Down
34 changes: 32 additions & 2 deletions packaging/win32/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ FROM fedora:rawhide

MAINTAINER Sandro Mani <[email protected]>

RUN dnf -y update; dnf clean all

RUN \
echo all > /etc/rpm/macros.image-language-conf && \
dnf install -y \
Expand All @@ -16,6 +18,7 @@ dnf install -y \
tesseract \
mingw32-nsis \
zip \
python3-gobject \
\
mingw32-gdb \
mingw32-gcc-c++ \
Expand All @@ -34,6 +37,19 @@ dnf install -y \
mingw32-twaindsm \
mingw32-quazip-qt5 \
\
mingw32-libzip \
mingw32-gtk3 gtk3 gtk3-devel \
mingw32-glib2-static glib2 glib2-devel \
mingw32-gtkmm30 \
mingw32-gtkspell3 \
mingw32-gtkspellmm30 \
mingw32-gtksourceviewmm3 \
mingw32-cairomm \
mingw32-poppler \
mingw32-poppler-glib \
mingw32-json-glib \
mingw32-libxml++ \
\
mingw64-gdb \
mingw64-gcc-c++ \
mingw64-dlfcn \
Expand All @@ -49,7 +65,21 @@ dnf install -y \
mingw64-qtspell-qt5 \
mingw64-tesseract \
mingw64-twaindsm \
mingw64-quazip-qt5
mingw64-quazip-qt5 \
\
mingw64-libzip \
mingw64-gtk3 gtk3 gtk3-devel \
mingw64-glib2-static glib2 glib2-devel \
mingw64-gtkmm30 \
mingw64-gtkspell3 \
mingw64-gtkspellmm30 \
mingw64-gtksourceviewmm3 \
mingw64-cairomm \
mingw64-poppler \
mingw64-poppler-glib \
mingw64-json-glib \
mingw64-libxml++


WORKDIR /workspace
VOLUME ["/workspace"]
VOLUME ["/workspace"]
2 changes: 1 addition & 1 deletion packaging/win32/makeinstaller.sh
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,4 @@ makensis -DNAME=$progName -DARCH=$arch -DVARIANT="$variant" -DPROGVERSION="$prog
# Cleanup
rm -rf $installroot

echo "Installer written to $PWD/${progName}_${progVersion}_${iface}_${arch}.exe"
echo "Installer written to $PWD/${progName}_${progVersion}_${iface}_${arch}.exe"
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e5b3188

Please sign in to comment.