Skip to content

Commit

Permalink
update mupdf
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzysztof Kowalczyk committed Feb 4, 2024
1 parent 46871ed commit 5e71a71
Show file tree
Hide file tree
Showing 15 changed files with 167 additions and 97 deletions.
19 changes: 12 additions & 7 deletions mupdf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ incdir ?= $(prefix)/include
mandir ?= $(prefix)/share/man
docdir ?= $(prefix)/share/doc/mupdf
pydir ?= $(shell python3 -c "import sysconfig; print(sysconfig.get_path('platlib'))")
SO_INSTALL_MODE ?= 644

third: $(THIRD_LIB)
extra-libs: $(THIRD_GLUT_LIB)
Expand Down Expand Up @@ -612,13 +613,17 @@ $(error OUT=$(OUT) does not contain shared)
endif

# C++, Python and C# shared libraries.
#
# To disable automatic use of a venv, use `make VENV_FLAG= ...` or `VENV_FLAG=
# make ...`.
#
VENV_FLAG ?= --venv
c++-%: shared-%
./scripts/mupdfwrap.py --venv -d $(OUT) -b 01
./scripts/mupdfwrap.py $(VENV_FLAG) -d $(OUT) -b 01
python-%: c++-%
./scripts/mupdfwrap.py --venv -d $(OUT) -b 23
./scripts/mupdfwrap.py $(VENV_FLAG) -d $(OUT) -b 23
csharp-%: c++-%
./scripts/mupdfwrap.py --venv -d $(OUT) -b --csharp 23

./scripts/mupdfwrap.py $(VENV_FLAG) -d $(OUT) -b --csharp 23

# Installs of C, C++, Python and C# shared libraries
#
Expand All @@ -632,21 +637,21 @@ endif

install-shared-c: install-shared-check shared install-headers
install -d $(DESTDIR)$(libdir)
install -m 644 $(OUT)/libmupdf.$(SO)$(SO_VERSION) $(DESTDIR)$(libdir)/
install -m $(SO_INSTALL_MODE) $(OUT)/libmupdf.$(SO)$(SO_VERSION) $(DESTDIR)$(libdir)/
ifneq ($(OS),OpenBSD)
ln -sf libmupdf.$(SO)$(SO_VERSION) $(DESTDIR)$(libdir)/libmupdf.$(SO)
endif

install-shared-c++: install-shared-c c++
install -m 644 platform/c++/include/mupdf/*.h $(DESTDIR)$(incdir)/mupdf
install -m 644 $(OUT)/libmupdfcpp.$(SO)$(SO_VERSION) $(DESTDIR)$(libdir)/
install -m $(SO_INSTALL_MODE) $(OUT)/libmupdfcpp.$(SO)$(SO_VERSION) $(DESTDIR)$(libdir)/
ifneq ($(OS),OpenBSD)
ln -sf libmupdfcpp.$(SO)$(SO_VERSION) $(DESTDIR)$(libdir)/libmupdfcpp.$(SO)
endif

install-shared-python: install-shared-c++ python
install -d $(DESTDIR)$(pydir)/mupdf
install -m 644 $(OUT)/_mupdf.$(SO) $(DESTDIR)$(pydir)/mupdf
install -m $(SO_INSTALL_MODE) $(OUT)/_mupdf.$(SO) $(DESTDIR)$(pydir)/mupdf
install -m 644 $(OUT)/mupdf.py $(DESTDIR)$(pydir)/mupdf/__init__.py

else
Expand Down
1 change: 1 addition & 0 deletions mupdf/Makelists
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ TESSERACT_SRC += thirdparty/tesseract/src/api/pdfrenderer.cpp
TESSERACT_SRC += thirdparty/tesseract/src/api/renderer.cpp
TESSERACT_SRC += thirdparty/tesseract/src/api/wordstrboxrenderer.cpp
TESSERACT_SRC += thirdparty/tesseract/src/arch/dotproduct.cpp
TESSERACT_SRC += thirdparty/tesseract/src/arch/dotproductneon.cpp
TESSERACT_SRC += thirdparty/tesseract/src/arch/intsimdmatrix.cpp
TESSERACT_SRC += thirdparty/tesseract/src/arch/simddetect.cpp
TESSERACT_SRC += thirdparty/tesseract/src/ccmain/applybox.cpp
Expand Down
6 changes: 6 additions & 0 deletions mupdf/include/mupdf/fitz/string-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ const char *fz_runeptr(const char *str, int idx);
*/
int fz_utflen(const char *s);

/*
Convert a wchar string into a new heap allocated utf8 one.
*/
char *fz_utf8_from_wchar(fz_context *ctx, const wchar_t *s);


/**
Locale-independent decimal to binary conversion. On overflow
return (-)INFINITY and set errno to ERANGE. On underflow return
Expand Down
5 changes: 2 additions & 3 deletions mupdf/include/mupdf/fitz/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,6 @@ static __inline int signbit(double x)

#ifdef _WIN32

char *fz_utf8_from_wchar(const wchar_t *s);
wchar_t *fz_wchar_from_utf8(const char *s);

/* really a FILE* but we don't want to include stdio.h here */
void *fz_fopen_utf8(const char *name, const char *mode);
int fz_remove_utf8(const char *name);
Expand All @@ -184,6 +181,8 @@ void fz_free_argv(int argc, char **argv);

int64_t fz_stat_ctime(const char *path);
int64_t fz_stat_mtime(const char *path);
int fz_mkdir(char *path);


/* inline is standard in C++. For some compilers we can enable it within
* C too. Some compilers think they know better than we do about when
Expand Down
19 changes: 0 additions & 19 deletions mupdf/platform/gl/gl-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,25 +499,6 @@ static void save_history(void)
js_freestate(J);
}

static int
fz_mkdir(char *path)
{
#ifdef _WIN32
int ret;
wchar_t *wpath = fz_wchar_from_utf8(path);

if (wpath == NULL)
return -1;

ret = _wmkdir(wpath);

free(wpath);

return ret;
#else
return mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO);
#endif
}

static int create_accel_path(char outname[], size_t len, int create, const char *absname, ...)
{
Expand Down
3 changes: 2 additions & 1 deletion mupdf/platform/win32/libtesseract.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>..\..\include;..\..\thirdparty\leptonica\src;..\..\thirdparty\tesseract\include;..\..\thirdparty\tesseract\src\api;..\..\thirdparty\tesseract\src\arch;..\..\thirdparty\tesseract\src\ccmain;..\..\thirdparty\tesseract\src\ccstruct;..\..\thirdparty\tesseract\src\ccutil;..\..\thirdparty\tesseract\src\classify;..\..\thirdparty\tesseract\src\dict;..\..\thirdparty\tesseract\src\lstm;..\..\thirdparty\tesseract\src\textord;..\..\thirdparty\tesseract\src\viewer;..\..\thirdparty\tesseract\src\wordrec;..\..\thirdparty\tesseract\src\cutil;..\..\scripts\tesseract</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp17</LanguageStandard>
<UndefinePreprocessorDefinitions>
</UndefinePreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
Expand Down Expand Up @@ -650,4 +651,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
20 changes: 0 additions & 20 deletions mupdf/platform/x11/pdfapp.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,6 @@
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#endif

static int
fz_mkdir(char *path)
{
#ifdef _WIN32
int ret;
wchar_t *wpath = fz_wchar_from_utf8(path);

if (wpath == NULL)
return -1;

ret = _wmkdir(wpath);

free(wpath);

return ret;
#else
return mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO);
#endif
}

static int create_accel_path(fz_context *ctx, char outname[], size_t len, int create, const char *absname, ...)
{
va_list args;
Expand Down
42 changes: 39 additions & 3 deletions mupdf/scripts/pipcl.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,8 @@ def __init__(self,
assumed to be relative to `root`.
`to_` identifies what the file should be called within a wheel
or when installing. If `to_` ends with `/`, the leaf of `from_`
is appended to it.
or when installing. If `to_` is '' or ends with `/`, the leaf
of `from_` is appended to it.
Initial `$dist-info/` in `_to` is replaced by
`{name}-{version}.dist-info/`; this is useful for license files
Expand Down Expand Up @@ -1541,7 +1541,7 @@ def build_extension(
if command_was_run and darwin():
# We need to patch up references to shared libraries in `libs`.
sublibraries = list()
for lib in libs:
for lib in () if libs is None else libs:
for libpath in libpaths:
found = list()
for suffix in '.so', '.dylib':
Expand Down Expand Up @@ -1745,6 +1745,7 @@ def run( command, capture=False, check=1):
else:
return (cp.returncode, cp.stdout) if capture else cp.returncode


def darwin():
return sys.platform.startswith( 'darwin')

Expand All @@ -1760,6 +1761,9 @@ def pyodide():
def linux():
return platform.system() == 'Linux'

def openbsd():
return platform.system() == 'OpenBSD'

class PythonFlags:
'''
Compile/link flags for the current python, for example the include path
Expand Down Expand Up @@ -1875,6 +1879,8 @@ def macos_patch( library, *sublibraries):
log2( f'macos_patch(): library={library} sublibraries={sublibraries}')
if not darwin():
return
if not sublibraries:
return
subprocess.run( f'otool -L {library}', shell=1, check=1)
command = 'install_name_tool'
names = []
Expand Down Expand Up @@ -2172,6 +2178,36 @@ def _so_suffix():
return sysconfig.get_config_var('EXT_SUFFIX')


def get_soname(path):
'''
If we are on Linux and `path` is softlink and points to a shared library
for which `objdump -p` contains 'SONAME', return the pointee. Otherwise
return `path`. Useful if Linux shared libraries have been created with
`-Wl,-soname,...`, where we need to embed the versioned library.
'''
log1(f'{path=} {os.path.abspath(path)=}.')
if linux() and os.path.islink(path):
path2 = os.path.realpath(path)
log1(f'Is link: {path} -> {path2}.')
if subprocess.run(f'objdump -p {path2}|grep SONAME', shell=1, check=0).returncode == 0:
log1(f'SONAME, returning {path2=}.')
return path2
log1(f'Not SONAME')
elif openbsd():
# Return newest .so with version suffix.
sos = glob.glob(f'{path}.*')
log1(f'{sos=}')
sos2 = list()
for so in sos:
suffix = so[len(path):]
if not suffix or re.match('^[.][0-9.]*[0-9]$', suffix):
sos2.append(so)
sos2.sort(key=lambda p: os.path.getmtime(p))
log1(f'{sos2=}')
return sos2[-1]
return path


def install_dir(root=None):
'''
Returns install directory used by `install()`.
Expand Down
10 changes: 9 additions & 1 deletion mupdf/scripts/wrap/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,7 @@ def _get_m_command( build_dirs, j=None, make=None, m_target=None, m_vars=None):
make_args += f' {m_vars}'
suffix = None
build_prefix = ''
build_suffix = ''
in_prefix = True
for i, flag in enumerate( flags):
if flag in ('x32', 'x64') or re.match('py[0-9]', flag):
Expand All @@ -1219,6 +1220,7 @@ def _get_m_command( build_dirs, j=None, make=None, m_target=None, m_vars=None):
# when creating wheels; we need to ignore
# them.
jlib.log('Ignoring {flag=}')
build_suffix += f'-{flag}'
else:
if 0: pass # lgtm [py/unreachable-statement]
elif flag == 'debug':
Expand Down Expand Up @@ -1259,6 +1261,8 @@ def _get_m_command( build_dirs, j=None, make=None, m_target=None, m_vars=None):
assert suffix, f'Leaf must contain "shared-" or "fpic-": build_dirs.dir_so={build_dirs.dir_so}'
if build_prefix:
make_args += f' build_prefix={build_prefix}'
if build_suffix:
make_args += f' build_suffix={build_suffix}'
if m_target:
make_args += f' {m_target}'
command = f'cd {build_dirs.dir_mupdf} &&'
Expand Down Expand Up @@ -1456,7 +1460,11 @@ def link_l_flags(sos):
if state.state_.pyodide:
# Don't add '-Wl,-rpath*' etc if building for Pyodide.
ld_origin = False
return jlib.link_l_flags( sos, ld_origin)
ret = jlib.link_l_flags( sos, ld_origin)
r = os.environ.get('LDFLAGS')
if r:
ret += f' {r}'
return ret


def build( build_dirs, swig_command, args, vs_upgrade, make_command):
Expand Down
24 changes: 12 additions & 12 deletions mupdf/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,30 +309,30 @@ def build():
if windows():
infix = '' if sys.maxsize == 2**31 - 1 else '64'
names = [
f'mupdfcpp{infix}.dll', # C and C++.
'_mupdf.pyd', # Python internals.
'mupdf.py', # Python.
f'{build_dir()}/mupdfcpp{infix}.dll', # C and C++.
f'{build_dir()}/_mupdf.pyd', # Python internals.
f'{build_dir()}/mupdf.py', # Python.
]
elif macos():
log( f'Contents of {build_dir()} are:')
for leaf in os.listdir(build_dir()):
log( f' {leaf}')
names = [
'libmupdf.dylib', # C.
'libmupdfcpp.so', # C++.
'_mupdf.so', # Python internals.
'mupdf.py', # Python.
f'{build_dir()}/libmupdf.dylib', # C.
f'{build_dir()}/libmupdfcpp.so', # C++.
f'{build_dir()}/_mupdf.so', # Python internals.
f'{build_dir()}/mupdf.py', # Python.
]
else:
names = [
'libmupdf.so', # C.
'libmupdfcpp.so', # C++.
'_mupdf.so', # Python internals.
'mupdf.py', # Python.
pipcl.get_soname(f'{build_dir()}/libmupdf.so'), # C.
pipcl.get_soname(f'{build_dir()}/libmupdfcpp.so'), # C++.
f'{build_dir()}/_mupdf.so', # Python internals.
f'{build_dir()}/mupdf.py', # Python.
]
paths = []
for name in names:
paths.append((f'{build_dir()}/{name}', name))
paths.append((name, ''))

log(f'build(): returning: {paths}')
return paths
Expand Down
25 changes: 25 additions & 0 deletions mupdf/source/fitz/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -938,3 +938,28 @@ void *fz_memmem(const void *h0, size_t k, const void *n0, size_t l)

return twoway_memmem(h, h+k, n, l);
}

char *
fz_utf8_from_wchar(fz_context *ctx, const wchar_t *s)
{
const wchar_t *src = s;
char *d;
char *dst;
int len = 1;

while (*src)
{
len += fz_runelen(*src++);
}

d = Memento_label(fz_malloc(ctx, len), "utf8_from_wchar");
dst = d;
src = s;
while (*src)
{
dst += fz_runetochar(dst, *src++);
}
*dst = 0;

return d;
}
Loading

0 comments on commit 5e71a71

Please sign in to comment.