From 854cef60cb1b340d12506e9c62b6e7012fec55ad Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Mon, 11 Dec 2023 18:38:11 +0100 Subject: [PATCH] (Android) Made PDF rendering work correctly using Poppler --- CMakeLists.txt | 26 ++++++++++++++------------ es-app/CMakeLists.txt | 5 ++--- es-app/src/PDFViewer.cpp | 17 +++++++++++++++++ es-core/CMakeLists.txt | 5 +++++ 4 files changed, 38 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 27477c0b6..606d81387 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -221,7 +221,8 @@ if(APPLE AND CMAKE_CXX_COMPILER_VERSION GREATER_EQUAL 15.0.0) endif() if(ANDROID) - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -llog") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden") + set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -llog") endif() if(EMSCRIPTEN) @@ -442,7 +443,8 @@ set(COMMON_INCLUDE_DIRS ${CURL_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/external/lunasvg/include ${CMAKE_CURRENT_SOURCE_DIR}/external/rapidjson/include ${CMAKE_CURRENT_SOURCE_DIR}/external/rlottie/inc - ${CMAKE_CURRENT_SOURCE_DIR}/es-core/src) + ${CMAKE_CURRENT_SOURCE_DIR}/es-core/src + ${CMAKE_CURRENT_SOURCE_DIR}/es-pdf-converter/src) if(APPLE) set(COMMON_INCLUDE_DIRS ${COMMON_INCLUDE_DIRS} @@ -572,11 +574,15 @@ elseif(ANDROID) ${PROJECT_SOURCE_DIR}/android/libs/${ANDROID_CPU_ARCH}/libswscale.so # Other dependencies. ${PROJECT_SOURCE_DIR}/android/libs/${ANDROID_CPU_ARCH}/libcurl.so - ${PROJECT_SOURCE_DIR}/android/libs/${ANDROID_CPU_ARCH}/libfreeimage.a + ${PROJECT_SOURCE_DIR}/android/libs/${ANDROID_CPU_ARCH}/libcrypto.so + ${PROJECT_SOURCE_DIR}/android/libs/${ANDROID_CPU_ARCH}/libfreeimage.so ${PROJECT_SOURCE_DIR}/android/libs/${ANDROID_CPU_ARCH}/libfreetype.so ${PROJECT_SOURCE_DIR}/android/libs/${ANDROID_CPU_ARCH}/libgit2.so + ${PROJECT_SOURCE_DIR}/android/libs/${ANDROID_CPU_ARCH}/libjpeg.so + ${PROJECT_SOURCE_DIR}/android/libs/${ANDROID_CPU_ARCH}/libpoppler.so ${PROJECT_SOURCE_DIR}/android/libs/${ANDROID_CPU_ARCH}/libpugixml.a - ${PROJECT_SOURCE_DIR}/android/libs/${ANDROID_CPU_ARCH}/libSDL2.so) + ${PROJECT_SOURCE_DIR}/android/libs/${ANDROID_CPU_ARCH}/libSDL2.so + ${PROJECT_SOURCE_DIR}/android/libs/${ANDROID_CPU_ARCH}/libssl.so) elseif(EMSCRIPTEN) set(COMMON_LIBRARIES ${COMMON_LIBRARIES} # FFmpeg core libraries. @@ -673,18 +679,14 @@ set(EXECUTABLE_OUTPUT_PATH ${dir} CACHE PATH "Build directory" FORCE) set(LIBRARY_OUTPUT_PATH ${dir} CACHE PATH "Build directory" FORCE) # Add each component. -if(NOT ANDROID) - add_subdirectory(es-pdf-converter) -endif() +add_subdirectory(es-pdf-converter) add_subdirectory(external) add_subdirectory(es-core) add_subdirectory(es-app) -if(NOT ANDROID) - # Make sure that es-pdf-convert is built first, and then that rlottie is built before es-core. - # Also set lottie2gif to not be built. - add_dependencies(lunasvg es-pdf-convert) -endif() +# Make sure that es-pdf-convert is built first, and then that rlottie is built before es-core. +# Also set lottie2gif to not be built. +add_dependencies(lunasvg es-pdf-convert) add_dependencies(es-core rlottie) set_target_properties(lottie2gif PROPERTIES EXCLUDE_FROM_ALL 1 EXCLUDE_FROM_DEFAULT_BUILD 1) diff --git a/es-app/CMakeLists.txt b/es-app/CMakeLists.txt index 8c3d5fdcd..48a33fcff 100644 --- a/es-app/CMakeLists.txt +++ b/es-app/CMakeLists.txt @@ -134,9 +134,8 @@ elseif(WIN32) set_target_properties(EmulationStation PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE) elseif(ANDROID) include_directories(${COMMON_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/src) - add_library(main SHARED ${ES_SOURCES} ${ES_HEADERS}) - target_link_libraries(main ${COMMON_LIBRARIES} ${CMAKE_DL_LIBS} es-core) - set_target_properties(main PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE) + add_library(main MODULE ${ES_SOURCES} ${ES_HEADERS}) + target_link_libraries(main PRIVATE ${COMMON_LIBRARIES} ${CMAKE_DL_LIBS} es-core es-pdf-convert) else() include_directories(${COMMON_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/src) add_executable(emulationstation ${ES_SOURCES} ${ES_HEADERS}) diff --git a/es-app/src/PDFViewer.cpp b/es-app/src/PDFViewer.cpp index 6f59e98f0..67ef2b28d 100644 --- a/es-app/src/PDFViewer.cpp +++ b/es-app/src/PDFViewer.cpp @@ -20,6 +20,10 @@ #include #endif +#if defined(__ANDROID__) +#include "ConvertPDF.h" +#endif + #define DEBUG_PDF_CONVERSION false #define KEY_REPEAT_START_DELAY 600 @@ -51,6 +55,7 @@ bool PDFViewer::startPDFViewer(FileData* game) { ViewController::getInstance()->pauseViewVideos(); +#if !defined(__ANDROID__) #if defined(_WIN64) const std::string convertBinary {"/es-pdf-converter/es-pdf-convert.exe"}; #else @@ -67,6 +72,7 @@ bool PDFViewer::startPDFViewer(FileData* game) ViewController::getInstance()->startViewVideos(); return false; } +#endif // !__ANDROID__ mGame = game; mManualPath = mGame->getManualPath(); @@ -298,6 +304,8 @@ bool PDFViewer::getDocumentInfo() // Close process and thread handles. CloseHandle(pi.hProcess); CloseHandle(pi.hThread); +#elif defined(__ANDROID__) + ConvertPDF::processFile(mManualPath, "-fileinfo", 0, 0, 0, commandOutput); #else FILE* commandPipe; std::array buffer {}; @@ -439,6 +447,13 @@ void PDFViewer::convertPage(int pageNum) CloseHandle(childStdoutRead); WaitForSingleObject(pi.hThread, INFINITE); WaitForSingleObject(pi.hProcess, INFINITE); +#elif (__ANDROID__) + ConvertPDF::processFile(mManualPath, "-convert", pageNum, + static_cast(mPages[pageNum].width), + static_cast(mPages[pageNum].height), imageData); + mPages[pageNum].imageData.insert(mPages[pageNum].imageData.end(), + std::make_move_iterator(imageData.begin()), + std::make_move_iterator(imageData.end())); #else FILE* commandPipe; std::array buffer {}; @@ -461,6 +476,8 @@ void PDFViewer::convertPage(int pageNum) #if defined(_WIN64) if (!processReturnValue || (static_cast(imageDataSize) < mPages[pageNum].width * mPages[pageNum].height * 4)) { +#elif defined(__ANDROID__) + if (static_cast(imageDataSize) < mPages[pageNum].width * mPages[pageNum].height * 4) { #else if (returnValue != 0 || (static_cast(imageDataSize) < mPages[pageNum].width * mPages[pageNum].height * 4)) { diff --git a/es-core/CMakeLists.txt b/es-core/CMakeLists.txt index 91c91604a..9f60146f7 100644 --- a/es-core/CMakeLists.txt +++ b/es-core/CMakeLists.txt @@ -169,6 +169,11 @@ set(CORE_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/utils/TimeUtil.cpp ) +if(ANDROID) + set(CORE_HEADERS ${CORE_HEADERS} ${CMAKE_CURRENT_SOURCE_DIR}/src/utils/PlatformUtilAndroid.h) + set(CORE_SOURCES ${CORE_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/src/utils/PlatformUtilAndroid.cpp) +endif() + #--------------------------------------------------------------------------------------------------- # Miscellaneous configuration.