Skip to content

Commit

Permalink
[libmupdf] add ocr feature (#32084)
Browse files Browse the repository at this point in the history
* add libmupdf ocr feature WIP

* Fix compile defs

* Fix ocr feature

* Add version

* increment libmupdf port version

* add libmupdf version

* revert version change
  • Loading branch information
simon987 authored Jul 5, 2023
1 parent dad2e6f commit d06a922
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 4 deletions.
31 changes: 29 additions & 2 deletions ports/libmupdf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
cmake_minimum_required(VERSION 3.9)
project(libmupdf C)
project(libmupdf)

option(ENABLE_OCR "Build with OCR" OFF)

set(CMAKE_DEBUG_POSTFIX d)

Expand All @@ -25,18 +27,35 @@ find_package(ZLIB REQUIRED)
find_package(OpenJPEG CONFIG REQUIRED)
find_library(JBIG2DEC_LIB NAMES jbig2decd jbig2dec)

file(GLOB_RECURSE SOURCES "source/*.c" "generated/*.c")
if (ENABLE_OCR)
find_package(Leptonica CONFIG REQUIRED)
find_package(Tesseract CONFIG REQUIRED)
endif()

file(GLOB_RECURSE SOURCES "source/*.c" "generated/*.c" "source/*.h")
list(FILTER SOURCES EXCLUDE REGEX "source/tools/[a-z]*\\.c$")
list(FILTER SOURCES EXCLUDE REGEX "source/tests/.*.c$")
list(FILTER SOURCES EXCLUDE REGEX "source/fitz/output-docx.c")

if (ENABLE_OCR)
list(APPEND SOURCES "source/fitz/tessocr.cpp")
endif()

add_library(libmupdf ${SOURCES})

if(WIN32)
target_compile_definitions(libmupdf PRIVATE -DSHARE_JPEG -DFZ_ENABLE_JS=0 -DFZ_ENABLE_ICC=0 -DMEMENTO_MUPDF_HACKS -DFZ_ENABLE_DOCX_OUTPUT=0 -DFZ_ENABLE_ODT_OUTPUT=0)
else()
target_compile_definitions(libmupdf PRIVATE -DHAVE_PTHREAD=1 -DSHARE_JPEG -DFZ_ENABLE_JS=0 -DFZ_ENABLE_ICC=0 -DMEMENTO_MUPDF_HACKS -DFZ_ENABLE_DOCX_OUTPUT=0 -DFZ_ENABLE_ODT_OUTPUT=0)
endif()


if (ENABLE_OCR)
target_compile_definitions(libmupdf PRIVATE -DHAVE_TESSERACT=1 -DHAVE_LEPTONICA=1)
else()
target_compile_definitions(libmupdf PRIVATE -DOCR_DISABLED=1)
endif()

target_include_directories(libmupdf
PUBLIC
include
Expand All @@ -45,6 +64,14 @@ target_include_directories(libmupdf
${JPEG_INCLUDE_DIR}
${HARFBUZZ_INCLUDE}
)

if (ENABLE_OCR)
target_include_directories(libmupdf
PRIVATE
${Leptonica_INCLUDE_DIRS}
)
endif()

target_link_libraries(libmupdf PRIVATE
openjp2
freetype
Expand Down
7 changes: 7 additions & 0 deletions ports/libmupdf/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@ vcpkg_from_github(

file(COPY "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt" DESTINATION "${SOURCE_PATH}")

vcpkg_check_features(
OUT_FEATURE_OPTIONS FEATURE_OPTIONS
FEATURES
ocr ENABLE_OCR
)

vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
DISABLE_PARALLEL_CONFIGURE
OPTIONS
-DBUILD_EXAMPLES=OFF
${FEATURE_OPTIONS}
)

vcpkg_cmake_install()
Expand Down
12 changes: 11 additions & 1 deletion ports/libmupdf/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "libmupdf",
"version": "1.22.1",
"port-version": 1,
"description": "a lightweight PDF, XPS, and E-book library",
"homepage": "https://github.com/ArtifexSoftware/mupdf",
"license": "AGPL-3.0-only",
Expand All @@ -19,5 +20,14 @@
"host": true
},
"zlib"
]
],
"features": {
"ocr": {
"description": "Enable OCR support",
"dependencies": [
"leptonica",
"tesseract"
]
}
}
}
2 changes: 1 addition & 1 deletion versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -4330,7 +4330,7 @@
},
"libmupdf": {
"baseline": "1.22.1",
"port-version": 0
"port-version": 1
},
"libmysql": {
"baseline": "8.0.32",
Expand Down
5 changes: 5 additions & 0 deletions versions/l-/libmupdf.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "06c0e6bccfaf2ab9f729bfc79318da68cb4897dc",
"version": "1.22.1",
"port-version": 1
},
{
"git-tree": "c1684ff15eed2c86ba792de4e92d21b2ea58c188",
"version": "1.22.1",
Expand Down

0 comments on commit d06a922

Please sign in to comment.