From 98839f116a36f22961ef98c25deb29aa9656cb53 Mon Sep 17 00:00:00 2001
From: Luigi Scarso <luigi.scarso@gmail.com>
Date: Fri, 15 Jan 2016 14:34:54 +0000
Subject: [PATCH] sync with experimental

---
 source/Build                                  |   9 +-
 source/build-aux/config.guess                 |  12 +-
 source/build-aux/config.sub                   |   8 +-
 source/build-aux/depcomp                      |   4 +-
 source/build-aux/install-sh                   |   4 +-
 source/build-aux/texinfo.tex                  |  62 ++++-
 source/libs/README                            |   6 +-
 source/libs/poppler/ChangeLog                 |   5 +
 source/libs/poppler/configure                 |  22 +-
 .../poppler/poppler-src-PATCHES/ChangeLog     |   7 +
 .../poppler/poppler-src-PATCHES/TL-Changes    |   3 +-
 .../poppler-src-PATCHES/patch-02-LLONG_MAX    |   6 +-
 .../patch-03-Object-functions                 |   6 +-
 .../libs/poppler/poppler-src/CMakeLists.txt   |   6 +-
 source/libs/poppler/poppler-src/ChangeLog     | 245 ++++++++++++++++++
 source/libs/poppler/poppler-src/NEWS          |  18 ++
 source/libs/poppler/poppler-src/configure.ac  |   2 +-
 .../poppler-src/poppler/CairoOutputDev.cc     |  49 ++--
 .../poppler/poppler-src/poppler/Function.cc   |   6 +-
 .../poppler-src/poppler/TextOutputDev.cc      | 195 ++++++++------
 .../poppler-src/poppler/UnicodeTypeTable.cc   |  20 +-
 .../poppler-src/poppler/UnicodeTypeTable.h    |   7 +-
 .../poppler/poppler-config.h.cmake            |   2 +-
 .../poppler-src/poppler/poppler-config.h.in   |   2 +-
 source/libs/poppler/version.ac                |   2 +-
 source/texk/README                            |   6 +-
 source/texk/web2c/c-auto.in                   |  10 +
 source/texk/web2c/configure                   |  70 +++++
 source/texk/web2c/configure.ac                |   2 +
 source/texk/web2c/help.h                      |  24 +-
 source/texk/web2c/lib/ChangeLog               |   4 +
 source/texk/web2c/lib/printversion.c          |   2 +-
 source/texk/web2c/lib/texmfmp.c               |   9 +-
 source/texk/web2c/texmfmp.h                   |  21 +-
 source/texk/web2c/tftopl.test                 |   2 +
 source/texk/web2c/triptrap/mtrap.mp           |   2 +-
 source/texk/web2c/vftovp.test                 |   2 +
 37 files changed, 680 insertions(+), 182 deletions(-)

diff --git a/source/Build b/source/Build
index 7f90ff644..f5ccc92d1 100755
--- a/source/Build
+++ b/source/Build
@@ -1,5 +1,5 @@
 #!/bin/sh
-# $Id: Build 35412 2014-10-21 18:19:11Z karl $
+# $Id: Build 35438 2014-10-25 15:33:44Z karl $
 # Public domain.  Originally written many years ago by Sebastian Rahtz.
 # The basic idea is to run configure && make, but with a multitude of
 # environment variables to allow overriding everything.
@@ -59,12 +59,13 @@ fi
 if test "x$1" = x--debug || test "x$1" = x-g; then
   shift
   # The idea is that with Build -g, you can set TL_COMPILER_GFLAGS in
-  # the environment with options common to all compilers.
-  # Not necessarily anything to do with debugging, e.g., -mcpu=sparvc9.
+  # the environment with options common to all compilers --
+  # not necessarily anything to do with debugging, e.g., -mcpu=sparvc9.
   : ${TL_COMPILER_GFLAGS=-g}
   c="CFLAGS='$TL_COMPILER_GFLAGS'"
   cxx="CXXFLAGS='$TL_COMPILER_GFLAGS'"
-  TL_BUILD_ENV="$c $cxx $TL_BUILD_ENV"
+  objcxx="OBJCXXFLAGS='$TL_COMPILER_GFLAGS'"  # needed only on macs
+  TL_BUILD_ENV="$c $cxx $objcxx $TL_BUILD_ENV"
 fi
 
 # allow override of configure location.
diff --git a/source/build-aux/config.guess b/source/build-aux/config.guess
index b82ee2315..dcd514968 100644
--- a/source/build-aux/config.guess
+++ b/source/build-aux/config.guess
@@ -1,8 +1,8 @@
 #! /bin/sh
 # Attempt to guess a canonical system name.
-#   Copyright 1992-2015 Free Software Foundation, Inc.
+#   Copyright 1992-2016 Free Software Foundation, Inc.
 
-timestamp='2015-12-14'
+timestamp='2016-01-01'
 
 # This file is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License as published by
@@ -27,7 +27,7 @@ timestamp='2015-12-14'
 # Originally written by Per Bothner; maintained since 2000 by Ben Elliston.
 #
 # You can get the latest version of this script from:
-# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD
+# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess
 #
 # Please send patches to <config-patches@gnu.org>.
 
@@ -50,7 +50,7 @@ version="\
 GNU config.guess ($timestamp)
 
 Originally written by Per Bothner.
-Copyright 1992-2015 Free Software Foundation, Inc.
+Copyright 1992-2016 Free Software Foundation, Inc.
 
 This is free software; see the source for copying conditions.  There is NO
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
@@ -1405,9 +1405,9 @@ This script, last modified $timestamp, has failed to recognize
 the operating system you are using. It is advised that you
 download the most up to date version of the config scripts from
 
-  http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD
+  http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess
 and
-  http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD
+  http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub
 
 If the version you run ($0) is already up to date, please
 send the following data and any information you think might be
diff --git a/source/build-aux/config.sub b/source/build-aux/config.sub
index 0cd701654..da6d1b682 100644
--- a/source/build-aux/config.sub
+++ b/source/build-aux/config.sub
@@ -1,8 +1,8 @@
 #! /bin/sh
 # Configuration validation subroutine script.
-#   Copyright 1992-2015 Free Software Foundation, Inc.
+#   Copyright 1992-2016 Free Software Foundation, Inc.
 
-timestamp='2015-12-14'
+timestamp='2016-01-01'
 
 # This file is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License as published by
@@ -33,7 +33,7 @@ timestamp='2015-12-14'
 # Otherwise, we print the canonical config type on stdout and succeed.
 
 # You can get the latest version of this script from:
-# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD
+# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub
 
 # This file is supposed to be the same for all GNU packages
 # and recognize all the CPU types, system types and aliases
@@ -67,7 +67,7 @@ Report bugs and patches to <config-patches@gnu.org>."
 version="\
 GNU config.sub ($timestamp)
 
-Copyright 1992-2015 Free Software Foundation, Inc.
+Copyright 1992-2016 Free Software Foundation, Inc.
 
 This is free software; see the source for copying conditions.  There is NO
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
diff --git a/source/build-aux/depcomp b/source/build-aux/depcomp
index fda2463f3..28ce42a9b 100644
--- a/source/build-aux/depcomp
+++ b/source/build-aux/depcomp
@@ -1,7 +1,7 @@
 #! /bin/sh
 # depcomp - compile a program generating dependencies as side-effects
 
-scriptversion=2013-05-30.07; # UTC
+scriptversion=2016-01-11.22; # UTC
 
 # Copyright (C) 1999-2015 Free Software Foundation, Inc.
 
@@ -751,6 +751,6 @@ exit 0
 # eval: (add-hook 'write-file-hooks 'time-stamp)
 # time-stamp-start: "scriptversion="
 # time-stamp-format: "%:y-%02m-%02d.%02H"
-# time-stamp-time-zone: "UTC"
+# time-stamp-time-zone: "UTC0"
 # time-stamp-end: "; # UTC"
 # End:
diff --git a/source/build-aux/install-sh b/source/build-aux/install-sh
index 0b0fdcbba..0360b79e7 100755
--- a/source/build-aux/install-sh
+++ b/source/build-aux/install-sh
@@ -1,7 +1,7 @@
 #!/bin/sh
 # install - install a program, script, or datafile
 
-scriptversion=2013-12-25.23; # UTC
+scriptversion=2016-01-11.22; # UTC
 
 # This originates from X11R5 (mit/util/scripts/install.sh), which was
 # later released in X11R6 (xc/config/util/install.sh) with the
@@ -496,6 +496,6 @@ done
 # eval: (add-hook 'write-file-hooks 'time-stamp)
 # time-stamp-start: "scriptversion="
 # time-stamp-format: "%:y-%02m-%02d.%02H"
-# time-stamp-time-zone: "UTC"
+# time-stamp-time-zone: "UTC0"
 # time-stamp-end: "; # UTC"
 # End:
diff --git a/source/build-aux/texinfo.tex b/source/build-aux/texinfo.tex
index f140bba94..936c32dc5 100644
--- a/source/build-aux/texinfo.tex
+++ b/source/build-aux/texinfo.tex
@@ -3,11 +3,11 @@
 % Load plain if necessary, i.e., if running under initex.
 \expandafter\ifx\csname fmtname\endcsname\relax\input plain\fi
 %
-\def\texinfoversion{2015-12-20.12}
+\def\texinfoversion{2016-01-11.19}
 %
 % Copyright 1985, 1986, 1988, 1990, 1991, 1992, 1993, 1994, 1995,
 % 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
-% 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015
+% 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016
 % Free Software Foundation, Inc.
 %
 % This texinfo.tex file is free software: you can redistribute it and/or
@@ -9428,6 +9428,45 @@ directory should work if nowhere else does.}
   \global\righthyphenmin = #3\relax
 }
 
+% Get input by bytes instead of by UTF-8 codepoints for XeTeX and LuaTeX, 
+% otherwise the encoding support is completely broken.
+\ifx\XeTeXrevision\thisisundefined
+\else
+\XeTeXdefaultencoding "bytes"  % For subsequent files to be read
+\XeTeXinputencoding "bytes"  % Effective in texinfo.tex only
+% Unfortunately, there seems to be no corresponding XeTeX command for
+% output encoding.  This is a problem for auxiliary index and TOC files.
+% The only solution would be perhaps to write out @U{...} sequences in
+% place of UTF-8 characters.
+\fi
+
+\ifx\luatexversion\thisisundefined
+\else
+\directlua{
+local utf8_char, byte, gsub = unicode.utf8.char, string.byte, string.gsub
+local function convert_char (char)
+  return utf8_char(byte(char))
+end
+
+local function convert_line (line)
+  return gsub(line, ".", convert_char)
+end
+
+callback.register("process_input_buffer", convert_line)
+
+local function convert_line_out (line)
+  local line_out = ""
+  for c in string.utfvalues(line) do
+     line_out = line_out .. string.char(c)
+  end
+  return line_out
+end
+
+callback.register("process_output_buffer", convert_line_out)
+}
+\fi
+
+
 % Helpers for encodings.
 % Set the catcode of characters 128 through 255 to the specified number.
 %
@@ -9452,6 +9491,14 @@ directory should work if nowhere else does.}
 %
 \def\documentencoding{\parseargusing\filenamecatcodes\documentencodingzzz}
 \def\documentencodingzzz#1{%
+  % Get input by bytes instead of by UTF-8 codepoints for XeTeX,
+  % otherwise the encoding support is completely broken.
+  % This settings is for the document root file.
+  \ifx\XeTeXrevision\thisisundefined
+  \else
+    \XeTeXinputencoding "bytes"
+  \fi
+  %
   % Encoding being declared for the document.
   \def\declaredencoding{\csname #1.enc\endcsname}%
   %
@@ -11004,9 +11051,20 @@ directory should work if nowhere else does.}
 {@catcode`@^=7 @catcode`@^^M=13%
 @gdef@eatinput input texinfo#1^^M{@fixbackslash}}
 
+% Emergency active definition of newline, in case an active newline token
+% appears by mistake.
+{@catcode`@^=7 @catcode13=13%
+@gdef@enableemergencynewline{%
+  @gdef^^M{%
+    @par%
+    %<warning: active newline>@par%
+}}}
+
+
 @gdef@fixbackslash{%
   @ifx\@eatinput @let\ = @ttbackslash @fi
   @catcode13=5 % regular end of line
+  @enableemergencynewline
   @let@c=@texinfoc
   % Also turn back on active characters that might appear in the input
   % file name, in case not using a pre-dumped format.
diff --git a/source/libs/README b/source/libs/README
index 0cf1ae6b6..a37dcf0d9 100644
--- a/source/libs/README
+++ b/source/libs/README
@@ -1,4 +1,4 @@
-$Id: README 39215 2015-12-28 14:09:09Z kakuto $
+$Id: README 39383 2016-01-14 04:46:03Z kakuto $
 Public domain.  Originally created by Karl Berry, 2005.
 
 Libraries we compile for TeX Live.
@@ -24,7 +24,7 @@ gmp 6.1.0 - checked 28dec15
 graphite2 1.3.3 - checked 27sep15
   http://sourceforge.net/projects/silgraphite/files/graphite2/
 
-harfbuzz 1.1.2 - checked 28dec15
+harfbuzz 1.1.3 - checked 12jan16
   http://www.freedesktop.org/software/harfbuzz/release/
 
 icu 56.1 (release) - checked 8oct15
@@ -49,7 +49,7 @@ mpfr 3.1.3 - checked 20jun15
 pixman 0.32.8 - checked 27sep15
   http://cairographics.org/releases/
 
-poppler 0.39.0 - checked 28dec15
+poppler 0.40.0 - checked 14jan16
   http://poppler.freedesktop.org/ - used by luatex and xetex
 
 potrace 1.13 - checked 28dec15
diff --git a/source/libs/poppler/ChangeLog b/source/libs/poppler/ChangeLog
index 71828d6f4..bfee65c2a 100644
--- a/source/libs/poppler/ChangeLog
+++ b/source/libs/poppler/ChangeLog
@@ -1,3 +1,8 @@
+2016-01-14  Akira Kakuto  <kakuto@fuk.kindai.ac.jp>
+
+	Import poppler-0.40.0.
+	* version.ac: Adjust.
+
 2015-12-28  Akira Kakuto  <kakuto@fuk.kindai.ac.jp>
 
 	Import poppler-0.39.0.
diff --git a/source/libs/poppler/configure b/source/libs/poppler/configure
index 8493e4281..cf42e8e68 100755
--- a/source/libs/poppler/configure
+++ b/source/libs/poppler/configure
@@ -1,6 +1,6 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.69 for poppler (TeX Live) 0.39.0.
+# Generated by GNU Autoconf 2.69 for poppler (TeX Live) 0.40.0.
 #
 # Report bugs to <tex-k@tug.org>.
 #
@@ -580,8 +580,8 @@ MAKEFLAGS=
 # Identity of this package.
 PACKAGE_NAME='poppler (TeX Live)'
 PACKAGE_TARNAME='poppler--tex-live-'
-PACKAGE_VERSION='0.39.0'
-PACKAGE_STRING='poppler (TeX Live) 0.39.0'
+PACKAGE_VERSION='0.40.0'
+PACKAGE_STRING='poppler (TeX Live) 0.40.0'
 PACKAGE_BUGREPORT='tex-k@tug.org'
 PACKAGE_URL=''
 
@@ -1306,7 +1306,7 @@ if test "$ac_init_help" = "long"; then
   # Omit some internal or obsolete options to make the list less imposing.
   # This message is too long to be a string in the A/UX 3.1 sh.
   cat <<_ACEOF
-\`configure' configures poppler (TeX Live) 0.39.0 to adapt to many kinds of systems.
+\`configure' configures poppler (TeX Live) 0.40.0 to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -1373,7 +1373,7 @@ fi
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of poppler (TeX Live) 0.39.0:";;
+     short | recursive ) echo "Configuration of poppler (TeX Live) 0.40.0:";;
    esac
   cat <<\_ACEOF
 
@@ -1486,7 +1486,7 @@ fi
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
-poppler (TeX Live) configure 0.39.0
+poppler (TeX Live) configure 0.40.0
 generated by GNU Autoconf 2.69
 
 Copyright (C) 2012 Free Software Foundation, Inc.
@@ -2076,7 +2076,7 @@ cat >config.log <<_ACEOF
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 
-It was created by poppler (TeX Live) $as_me 0.39.0, which was
+It was created by poppler (TeX Live) $as_me 0.40.0, which was
 generated by GNU Autoconf 2.69.  Invocation command line was
 
   $ $0 $@
@@ -3999,7 +3999,7 @@ fi
 
 # Define the identity of the package.
  PACKAGE='poppler--tex-live-'
- VERSION='0.39.0'
+ VERSION='0.40.0'
 
 
 # Some tools Automake needs.
@@ -6578,7 +6578,7 @@ ac_config_headers="$ac_config_headers poppler-config.h:poppler-src/poppler/poppl
 
 
 cat >>confdefs.h <<_ACEOF
-#define POPPLER_VERSION "0.39.0"
+#define POPPLER_VERSION "0.40.0"
 _ACEOF
 
 
@@ -7272,7 +7272,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
 # report actual input values of CONFIG_FILES etc. instead of their
 # values after options handling.
 ac_log="
-This file was extended by poppler (TeX Live) $as_me 0.39.0, which was
+This file was extended by poppler (TeX Live) $as_me 0.40.0, which was
 generated by GNU Autoconf 2.69.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
@@ -7338,7 +7338,7 @@ _ACEOF
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
 ac_cs_version="\\
-poppler (TeX Live) config.status 0.39.0
+poppler (TeX Live) config.status 0.40.0
 configured by $0, generated by GNU Autoconf 2.69,
   with options \\"\$ac_cs_config\\"
 
diff --git a/source/libs/poppler/poppler-src-PATCHES/ChangeLog b/source/libs/poppler/poppler-src-PATCHES/ChangeLog
index d83fdb8fc..0682274ab 100644
--- a/source/libs/poppler/poppler-src-PATCHES/ChangeLog
+++ b/source/libs/poppler/poppler-src-PATCHES/ChangeLog
@@ -1,3 +1,10 @@
+2016-01-14  Akira Kakuto  <kakuto@fuk.kindai.ac.jp>
+
+	Imported poppler-0.40.0 source tree from:
+	  http://poppler.freedesktop.org/
+
+	* patch-02-LLONG_MAX, patch-03-Object-functions: Adapted.
+
 2015-12-28  Akira Kakuto  <kakuto@fuk.kindai.ac.jp>
 
 	Imported poppler-0.39.0 source tree from:
diff --git a/source/libs/poppler/poppler-src-PATCHES/TL-Changes b/source/libs/poppler/poppler-src-PATCHES/TL-Changes
index 0e0ed2e9e..990ae4297 100644
--- a/source/libs/poppler/poppler-src-PATCHES/TL-Changes
+++ b/source/libs/poppler/poppler-src-PATCHES/TL-Changes
@@ -1,4 +1,4 @@
-Changes applied to the poppler-0.37.0 tree as obtained from:
+Changes applied to the poppler-0.40.0 tree as obtained from:
 	http://poppler.freedesktop.org/
 
 Removed:
@@ -27,4 +27,3 @@ Removed unused dirs:
 	qt5
 	test
 	utils
-
diff --git a/source/libs/poppler/poppler-src-PATCHES/patch-02-LLONG_MAX b/source/libs/poppler/poppler-src-PATCHES/patch-02-LLONG_MAX
index 8a1f73341..c2ea5b60b 100644
--- a/source/libs/poppler/poppler-src-PATCHES/patch-02-LLONG_MAX
+++ b/source/libs/poppler/poppler-src-PATCHES/patch-02-LLONG_MAX
@@ -1,6 +1,6 @@
-diff -ur poppler-0.39.0.orig/goo/GooString.h poppler-0.39.0/goo/GooString.h
---- poppler-0.39.0.orig/goo/GooString.h	Mon Jul 13 00:05:10 2015
-+++ poppler-0.39.0/goo/GooString.h	Mon Dec 28 22:41:39 2015
+diff -ur poppler-0.40.0.orig/goo/GooString.h poppler-0.40.0/goo/GooString.h
+--- poppler-0.40.0.orig/goo/GooString.h	Mon Jul 13 00:05:10 2015
++++ poppler-0.40.0/goo/GooString.h	Thu Jan 14 13:17:20 2016
 @@ -35,6 +35,21 @@
  #endif
  
diff --git a/source/libs/poppler/poppler-src-PATCHES/patch-03-Object-functions b/source/libs/poppler/poppler-src-PATCHES/patch-03-Object-functions
index 657d43b97..d90fb2ac7 100644
--- a/source/libs/poppler/poppler-src-PATCHES/patch-03-Object-functions
+++ b/source/libs/poppler/poppler-src-PATCHES/patch-03-Object-functions
@@ -1,6 +1,6 @@
-diff -ur poppler-0.39.0.orig/poppler/Object.h poppler-0.39.0/poppler/Object.h
---- poppler-0.39.0.orig/poppler/Object.h	Mon Nov 16 06:05:22 2015
-+++ poppler-0.39.0/poppler/Object.h	Mon Dec 28 22:45:05 2015
+diff -ur poppler-0.40.0.orig/poppler/Object.h poppler-0.40.0/poppler/Object.h
+--- poppler-0.40.0.orig/poppler/Object.h	Mon Nov 16 06:05:22 2015
++++ poppler-0.40.0/poppler/Object.h	Thu Jan 14 13:20:32 2016
 @@ -140,7 +140,7 @@
    Object *initStream(Stream *streamA);
    Object *initRef(int numA, int genA)
diff --git a/source/libs/poppler/poppler-src/CMakeLists.txt b/source/libs/poppler/poppler-src/CMakeLists.txt
index a1412d815..e58a41d5b 100644
--- a/source/libs/poppler/poppler-src/CMakeLists.txt
+++ b/source/libs/poppler/poppler-src/CMakeLists.txt
@@ -22,7 +22,7 @@ if (ECM_FOUND)
 endif()
 
 set(POPPLER_MAJOR_VERSION "0")
-set(POPPLER_MINOR_VERSION "39")
+set(POPPLER_MINOR_VERSION "40")
 set(POPPLER_MICRO_VERSION "0")
 set(POPPLER_VERSION "${POPPLER_MAJOR_VERSION}.${POPPLER_MINOR_VERSION}.${POPPLER_MICRO_VERSION}")
 
@@ -442,7 +442,6 @@ elseif (LIBOPENJPEG2_FOUND)
     poppler/JPEG2000Stream.cc
   )
   add_definitions(-DUSE_OPENJPEG2)
-MESSAGE(${LIBOPENJPEG2_LIBRARIES})
   set(poppler_LIBS ${poppler_LIBS} ${LIBOPENJPEG2_LIBRARIES})
 else ()
   set(poppler_SRCS ${poppler_SRCS}
@@ -479,8 +478,7 @@ else(MSVC)
 add_library(poppler SHARED ${poppler_SRCS})
 endif(MSVC)
 set_target_properties(poppler PROPERTIES VERSION 58.0.0 SOVERSION 58)
-target_link_libraries(poppler ${poppler_LIBS})
-target_link_libraries(poppler LINK_INTERFACE_LIBRARIES "")
+target_link_libraries(poppler LINK_PRIVATE ${poppler_LIBS})
 install(TARGETS poppler RUNTIME DESTINATION bin LIBRARY DESTINATION lib${LIB_SUFFIX} ARCHIVE DESTINATION lib${LIB_SUFFIX})
 
 if(ENABLE_XPDF_HEADERS)
diff --git a/source/libs/poppler/poppler-src/ChangeLog b/source/libs/poppler/poppler-src/ChangeLog
index 8d00b9d2e..0b23e0f8f 100644
--- a/source/libs/poppler/poppler-src/ChangeLog
+++ b/source/libs/poppler/poppler-src/ChangeLog
@@ -1,3 +1,248 @@
+commit 449d45fab8e61393d858549460e61599e4dbd7eb
+Author: Albert Astals Cid <aacid@kde.org>
+Date:   Wed Jan 13 23:19:12 2016 +0100
+
+    0.40.0 + NEWS
+
+ CMakeLists.txt   |  2 +-
+ NEWS             | 18 ++++++++++++++++++
+ configure.ac     |  2 +-
+ cpp/Doxyfile     |  2 +-
+ qt4/src/Doxyfile |  2 +-
+ qt5/src/Doxyfile |  2 +-
+ 6 files changed, 23 insertions(+), 5 deletions(-)
+
+commit e9740b57324cf5a09f6f4312165da13c7b3a576b
+Author: Albert Astals Cid <aacid@kde.org>
+Date:   Wed Jan 13 23:14:35 2016 +0100
+
+    Update copyrights
+
+ poppler/Function.cc | 2 +-
+ utils/pdftocairo.cc | 2 +-
+ 2 files changed, 2 insertions(+), 2 deletions(-)
+
+commit 3bfc45bfcca1a52447cedbb95afad1ef362ac6f0
+Author: Adrian Johnson <ajohnson@redneon.com>
+Date:   Mon Jan 11 21:46:49 2016 +1030
+
+    pdftocairo: check for invalid use of -scale-to* and -paper[wh] options
+
+    Bug 92195
+
+ utils/pdftocairo.cc | 12 +++++++++++-
+ 1 file changed, 11 insertions(+), 1 deletion(-)
+
+commit 819bea740b1fadb24833e0ecbdf4e75ddca8eb14
+Author: Adrian Johnson <ajohnson@redneon.com>
+Date:   Mon Jan 11 19:44:14 2016 +1030
+
+    pdftocairo: ensure surface flushed before accessing image data
+
+ utils/pdftocairo.cc | 1 +
+ 1 file changed, 1 insertion(+)
+
+commit f7542348b37cc881d854bbc36c3af0a4fe37d839
+Author: Adrian Johnson <ajohnson@redneon.com>
+Date:   Mon Jan 11 19:39:34 2016 +1030
+
+    pdftocairo: document that -singlefile appends file type
+
+    Bug 86254
+
+ utils/pdftocairo.1 | 9 +++++----
+ 1 file changed, 5 insertions(+), 4 deletions(-)
+
+commit 9fa58b1ef6c97e2a30bb3197c11000fac3b059f4
+Author: Adrian Johnson <ajohnson@redneon.com>
+Date:   Mon Jan 11 19:26:02 2016 +1030
+
+    pdftocairo: fix writing to stdout out with image output
+
+ utils/pdftocairo.cc | 14 ++++++++------
+ 1 file changed, 8 insertions(+), 6 deletions(-)
+
+commit 01d4bb222d63eda7dc5ec903c0735179edf77c0e
+Author: Albert Astals Cid <aacid@kde.org>
+Date:   Sun Jan 3 13:01:31 2016 +0100
+
+    Happy New Year
+
+ poppler/poppler-config.h.cmake | 2 +-
+ poppler/poppler-config.h.in    | 2 +-
+ 2 files changed, 2 insertions(+), 2 deletions(-)
+
+commit d8f418d2f2ec5966d77caf128a52c834fdd0efcf
+Author: Khaled Hosny <khaledhosny@eglug.org>
+Date:   Mon Nov 23 13:52:10 2015 +0400
+
+    Fix finding Arabic Presentation Forms ligatures
+
+    PDF text containing Arabic Presentation forms ligatures is still not
+    found after the previous commit.
+
+    This because the ligatures are decomposed in logical order after
+    normalisation, while the whole string is in visual order.  For example
+    the RTL text ABCD in visual order will be DCBA, and assuming B is a
+    ligature, it will be decomposed to B1B2 so the string after
+    normalization will be DCB1B2A while we are expecting it to be DCB2B1A.
+
+    This patch reverses the order of the decomposition of RTL characters
+    to
+    work around this issue.
+
+ poppler/TextOutputDev.cc    |  4 +++-
+ poppler/UnicodeTypeTable.cc | 20 ++++++++++++++++----
+ poppler/UnicodeTypeTable.h  |  7 ++++++-
+ 3 files changed, 25 insertions(+), 6 deletions(-)
+
+commit 67645087477beb618304ea34cbdbafd40b199276
+Author: Khaled Hosny <khaledhosny@eglug.org>
+Date:   Wed Nov 18 14:47:28 2015 +0400
+
+    Handle right-to-left text in search
+
+    Currently right-to-left text reversal is only done during text
+    dumping,
+    but not during search. This commit applies the same reversal logic
+    during PDF search as well.
+
+ poppler/TextOutputDev.cc | 191
+ ++++++++++++++++++++++++++---------------------
+ 1 file changed, 107 insertions(+), 84 deletions(-)
+
+commit 00422d0c6baaba639fa0660e3a933cdb76b28f88
+Author: Jason Crain <jason@aquaticape.us>
+Date:   Sun Dec 20 09:54:43 2015 -0600
+
+    cairo: use shape mask with soft mask
+
+    Clear target with the shape mask whether the soft mask is set or not.
+    Propagate the shape up to any higher level groups and destroy the
+    shape pattern when done.
+
+    Fix a memory leak by removing a call to 'cairo_reference
+    (cairo_shape)'.
+    We already keep track of the lifetime of cairo_shape using
+    knockoutCount.
+
+    bug 91931
+
+ poppler/CairoOutputDev.cc | 49
+ ++++++++++++++++++++++-------------------------
+ 1 file changed, 23 insertions(+), 26 deletions(-)
+
+commit bc4cab272e4fe28b836cb2ef1ff672f0d79d243c
+Author: Carlos Garcia Campos <carlosgc@gnome.org>
+Date:   Sat Jan 2 09:49:27 2016 +0100
+
+    regtest: Fix the number of worker threads spawned reported in log
+    of run-tests command
+
+ regtest/TestRun.py | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+commit ea75de614e666d8235c38048585315e0d7ff5522
+Author: Adam Reichold <adam.reichold@t-online.de>
+Date:   Sat Jan 2 09:48:03 2016 +0100
+
+    regtest: Limit the number of worker threads to the number of documents
+    to create references
+
+    The same way we do for the run-tests command.
+
+ regtest/TestReferences.py | 27 ++++++++++++++++++---------
+ 1 file changed, 18 insertions(+), 9 deletions(-)
+
+commit 25bb59a81de8a1b6dd23fec871a97ccb11fe9d64
+Author: Carlos Garcia Campos <carlosgc@gnome.org>
+Date:   Fri Jan 1 12:45:42 2016 +0100
+
+    regtest: Allow to interrupt run-tests and create-refs commands when
+    multiple threads are used
+
+    The Queue join implementation uses a non-timed wait that blocks
+    the main
+    thread, making it impossible to interrupt it with CTRL+C or sending
+    SIGINT signal. Using any timeout value for wait would fix the problem,
+    but Queue doesn't allow to pass a timeout to the join method. The
+    Queue implementation is actually quite simple, so we can just add our
+    own implementation with only the things we really need and use
+    a timeout
+    value when calling wait() in join().
+
+ regtest/InterruptibleQueue.py | 68
+ +++++++++++++++++++++++++++++++++++++++++++
+ regtest/TestReferences.py     |  4 +--
+ regtest/TestRun.py            |  4 +--
+ 3 files changed, 72 insertions(+), 4 deletions(-)
+
+commit ffb3ff633b124c476ab48bbcfce04d7f418df9bc
+Author: Adam Reichold <adam.reichold@t-online.de>
+Date:   Fri Jan 1 11:32:14 2016 +0100
+
+    regtest: Do not use the log printer with the TestReferences lock held
+
+ regtest/TestReferences.py | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+commit e3b09727ad96a03ba1250f49486948899b4df793
+Author: Adam Reichold <adam.reichold@t-online.de>
+Date:   Fri Dec 25 14:10:03 2015 +0100
+
+    Make detection of version one of OpenJPEG prefer a pkg-config manifest
+    if it exists.
+
+ CMakeLists.txt                      |  1 -
+ cmake/modules/FindLIBOPENJPEG.cmake | 37
+ +++++++++++++++++++++++--------------
+ 2 files changed, 23 insertions(+), 15 deletions(-)
+
+commit 7c880daecfcddac2f8181d5f3d506dd409812dbe
+Author: Adam Reichold <adam.reichold@t-online.de>
+Date:   Fri Dec 25 14:10:03 2015 +0100
+
+    Make use of LINK_PRIVATE flag to fix warning on CMake policy 0022.
+
+ CMakeLists.txt     | 3 +--
+ cpp/CMakeLists.txt | 3 +--
+ 2 files changed, 2 insertions(+), 4 deletions(-)
+
+commit 4a413b9b95d5c6815c91adb815254cce97dd5b4b
+Author: Adam Reichold <adam.reichold@t-online.de>
+Date:   Fri Dec 25 14:10:03 2015 +0100
+
+    Make target names for Qt4 and Qt5 builds unique so they can be built
+    at the same time using recent CMake and Ninja versions.
+
+ qt4/tests/CMakeLists.txt | 44 +++++++++++++++++++++---------------------
+ qt5/CMakeLists.txt       |  2 ++
+ qt5/demos/CMakeLists.txt |  2 --
+ qt5/src/CMakeLists.txt   |  2 --
+ qt5/tests/CMakeLists.txt | 50
+ +++++++++++++++++++++++-------------------------
+ 5 files changed, 48 insertions(+), 52 deletions(-)
+
+commit b3425dd3261679958cd56c0f71995c15d2124433
+Author: Albert Astals Cid <aacid@kde.org>
+Date:   Tue Dec 22 22:50:33 2015 +0100
+
+    Do not crash on invalid files
+
+    Bug #93476
+
+ poppler/Function.cc | 4 ++++
+ 1 file changed, 4 insertions(+)
+
+commit 5d57c34cbf9288eec6ddb149e905268405c19450
+Author: Pino Toscano <pino@kde.org>
+Date:   Sun Dec 20 08:42:25 2015 +0100
+
+    typo fix: "occurence" -> "occurrence"
+
+ utils/pdfunite.1 | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
 commit 3eee5274abb24d5b5be05262aafe794652cdac35
 Author: Albert Astals Cid <aacid@kde.org>
 Date:   Thu Dec 17 00:09:37 2015 +0100
diff --git a/source/libs/poppler/poppler-src/NEWS b/source/libs/poppler/poppler-src/NEWS
index ff547204a..cbe433d73 100644
--- a/source/libs/poppler/poppler-src/NEWS
+++ b/source/libs/poppler/poppler-src/NEWS
@@ -1,3 +1,21 @@
+Release 0.40.0
+        core:
+         * CairoOutputDev: Use shape mask with soft mask. Bug #91931
+         * TextOutputDev: Handle right-to-left text in search
+         * TextOutputDev: Fix finding Arabic Presentation Forms ligatures
+         * Fix crash in invalid file. Bug #93476
+         * Regression test improvements
+
+        utils:
+         * pdftocairo: fix writing to stdout out with image output
+         * pdftocairo: document that -singlefile appends file type. Bug #86254
+         * pdftocairo: ensure surface flushed before accessing image data
+         * pdftocairo: check for invalid use of options. Bug #92195
+         * pdfunite: Fix typo in manual
+
+        build system:
+         * Improve cmake build system
+
 Release 0.39.0
         core:
          * Ignore the alternateSpace and tintTransform. Bug #92381
diff --git a/source/libs/poppler/poppler-src/configure.ac b/source/libs/poppler/poppler-src/configure.ac
index b2fc6cf32..1e34506f7 100644
--- a/source/libs/poppler/poppler-src/configure.ac
+++ b/source/libs/poppler/poppler-src/configure.ac
@@ -1,5 +1,5 @@
 m4_define([poppler_version_major],[0])
-m4_define([poppler_version_minor],[39])
+m4_define([poppler_version_minor],[40])
 m4_define([poppler_version_micro],[0])
 m4_define([poppler_version],[poppler_version_major.poppler_version_minor.poppler_version_micro])
 
diff --git a/source/libs/poppler/poppler-src/poppler/CairoOutputDev.cc b/source/libs/poppler/poppler-src/poppler/CairoOutputDev.cc
index d06f3c72c..d0d6cb43f 100644
--- a/source/libs/poppler/poppler-src/poppler/CairoOutputDev.cc
+++ b/source/libs/poppler/poppler-src/poppler/CairoOutputDev.cc
@@ -1597,8 +1597,6 @@ void CairoOutputDev::beginTransparencyGroup(GfxState * /*state*/, double * /*bbo
       cairo_get_matrix (cairo, &matrix);
       //printMatrix(&matrix);
       cairo_set_matrix (cairo_shape, &matrix);
-    } else {
-      cairo_reference (cairo_shape);
     }
   }
   if (groupColorSpaceStack->next && groupColorSpaceStack->next->knockout) {
@@ -1638,33 +1636,22 @@ void CairoOutputDev::paintTransparencyGroup(GfxState * /*state*/, double * /*bbo
 
   cairo_save (cairo);
   cairo_set_matrix (cairo, &groupColorSpaceStack->group_matrix);
-  cairo_set_source (cairo, group);
-
-  if (!mask) {
-    //XXX: deal with mask && shape case
-    if (shape) {
-      cairo_save (cairo);
-
-      /* OPERATOR_SOURCE w/ a mask is defined as (src IN mask) ADD (dest OUT mask)
-       * however our source has already been clipped to mask so we only need to
-       * do ADD and OUT */
 
-      /* clear the shape mask */
-      cairo_set_source (cairo, shape);
-      cairo_set_operator (cairo, CAIRO_OPERATOR_DEST_OUT);
-      cairo_paint (cairo);
-
-      cairo_set_operator (cairo, CAIRO_OPERATOR_ADD);
-      cairo_set_source (cairo, group);
-      cairo_paint (cairo);
+  if (shape) {
+    /* OPERATOR_SOURCE w/ a mask is defined as (src IN mask) ADD (dest OUT mask)
+     * however our source has already been clipped to mask so we only need to
+     * do ADD and OUT */
 
-      cairo_restore (cairo);
+    /* clear the shape mask */
+    cairo_set_source (cairo, shape);
+    cairo_set_operator (cairo, CAIRO_OPERATOR_DEST_OUT);
+    cairo_paint (cairo);
+    cairo_set_operator (cairo, CAIRO_OPERATOR_ADD);
+  }
+  cairo_set_source (cairo, group);
 
-      cairo_pattern_destroy (shape);
-      shape = NULL;
-    } else {
-      cairo_paint_with_alpha (cairo, fill_opacity);
-    }
+  if (!mask) {
+    cairo_paint_with_alpha (cairo, fill_opacity);
     cairo_status_t status = cairo_status(cairo);
     if (status)
       printf("BAD status: %s\n", cairo_status_to_string(status));
@@ -1684,6 +1671,16 @@ void CairoOutputDev::paintTransparencyGroup(GfxState * /*state*/, double * /*bbo
     mask = NULL;
   }
 
+  if (shape) {
+    if (cairo_shape) {
+      cairo_set_source (cairo_shape, shape);
+      cairo_paint (cairo_shape);
+      cairo_set_source_rgb (cairo_shape, 0, 0, 0);
+    }
+    cairo_pattern_destroy (shape);
+    shape = NULL;
+  }
+
   popTransparencyGroup();
   cairo_restore(cairo);
 }
diff --git a/source/libs/poppler/poppler-src/poppler/Function.cc b/source/libs/poppler/poppler-src/poppler/Function.cc
index 67283dffe..7f359b8eb 100644
--- a/source/libs/poppler/poppler-src/poppler/Function.cc
+++ b/source/libs/poppler/poppler-src/poppler/Function.cc
@@ -13,7 +13,7 @@
 // All changes made under the Poppler project to this file are licensed
 // under GPL version 2 or later
 //
-// Copyright (C) 2006, 2008-2010, 2013, 2014 Albert Astals Cid <aacid@kde.org>
+// Copyright (C) 2006, 2008-2010, 2013-2015 Albert Astals Cid <aacid@kde.org>
 // Copyright (C) 2006 Jeff Muizelaar <jeff@infidigm.net>
 // Copyright (C) 2010 Christian Feuers�nger <cfeuersaenger@googlemail.com>
 // Copyright (C) 2011 Andrea Canciani <ranma42@gmail.com>
@@ -577,6 +577,10 @@ ExponentialFunction::ExponentialFunction(Object *funcObj, Dict *dict) {
       goto err2;
     }
     n = obj1.arrayGetLength();
+    if (unlikely(n > funcMaxOutputs)) {
+      error(errSyntaxError, -1, "Function's C0 array is wrong length");
+      n = funcMaxOutputs;
+    }
     for (i = 0; i < n; ++i) {
       obj1.arrayGet(i, &obj2);
       if (!obj2.isNum()) {
diff --git a/source/libs/poppler/poppler-src/poppler/TextOutputDev.cc b/source/libs/poppler/poppler-src/poppler/TextOutputDev.cc
index bbb371a30..fff3f05e8 100644
--- a/source/libs/poppler/poppler-src/poppler/TextOutputDev.cc
+++ b/source/libs/poppler/poppler-src/poppler/TextOutputDev.cc
@@ -35,6 +35,7 @@
 // Copyright (C) 2013 José Aliste <jaliste@src.gnome.org>
 // Copyright (C) 2013 Thomas Freitag <Thomas.Freitag@alfa.de>
 // Copyright (C) 2013 Ed Catmur <ed@catmur.co.uk>
+// Copyright (C) 2016 Khaled Hosny <khaledhosny@eglug.org>
 //
 // To see a description of the changes please see the Changelog file that
 // came with your tarball or type make ChangeLog if you are building from git
@@ -178,6 +179,94 @@
 #define combMaxMidDelta 0.3
 #define combMaxBaseDelta 0.4
 
+static int reorderText(Unicode *text, int len, UnicodeMap *uMap, GBool primaryLR, GooString *s, Unicode* u) {
+  char lre[8], rle[8], popdf[8], buf[8];
+  int lreLen = 0, rleLen = 0, popdfLen = 0, n;
+  int nCols, i, j, k;
+
+  nCols = 0;
+
+  if (s) {
+    lreLen = uMap->mapUnicode(0x202a, lre, sizeof(lre));
+    rleLen = uMap->mapUnicode(0x202b, rle, sizeof(rle));
+    popdfLen = uMap->mapUnicode(0x202c, popdf, sizeof(popdf));
+  }
+
+  if (primaryLR) {
+    i = 0;
+    while (i < len) {
+      // output a left-to-right section
+      for (j = i; j < len && !unicodeTypeR(text[j]); ++j) ;
+      for (k = i; k < j; ++k) {
+        if (s) {
+          n = uMap->mapUnicode(text[k], buf, sizeof(buf));
+          s->append(buf, n);
+        }
+        if (u) u[nCols] = text[k];
+        ++nCols;
+      }
+      i = j;
+      // output a right-to-left section
+      for (j = i;
+         j < len && !(unicodeTypeL(text[j]) || unicodeTypeNum(text[j]));
+         ++j) ;
+      if (j > i) {
+        if (s) s->append(rle, rleLen);
+        for (k = j - 1; k >= i; --k) {
+          if (s) {
+            n = uMap->mapUnicode(text[k], buf, sizeof(buf));
+            s->append(buf, n);
+          }
+          if (u) u[nCols] = text[k];
+          ++nCols;
+        }
+        if (s) s->append(popdf, popdfLen);
+        i = j;
+      }
+    }
+  } else {
+    // Note: This code treats numeric characters (European and
+    // Arabic/Indic) as left-to-right, which isn't strictly correct
+    // (incurs extra LRE/POPDF pairs), but does produce correct
+    // visual formatting.
+    if (s) s->append(rle, rleLen);
+    i = len - 1;
+    while (i >= 0) {
+      // output a right-to-left section
+      for (j = i;
+         j >= 0 && !(unicodeTypeL(text[j]) || unicodeTypeNum(text[j]));
+         --j) ;
+      for (k = i; k > j; --k) {
+        if (s) {
+          n = uMap->mapUnicode(text[k], buf, sizeof(buf));
+          s->append(buf, n);
+        }
+        if (u) u[nCols] = text[k];
+        ++nCols;
+      }
+      i = j;
+      // output a left-to-right section
+      for (j = i; j >= 0 && !unicodeTypeR(text[j]); --j) ;
+      if (j < i) {
+        if (s) s->append(lre, lreLen);
+        for (k = j + 1; k <= i; ++k) {
+          if (s) {
+            n = uMap->mapUnicode(text[k], buf, sizeof(buf));
+            s->append(buf, n);
+          }
+          if (u) u[nCols] = text[k];
+          ++nCols;
+        }
+        if (s) s->append(popdf, popdfLen);
+        i = j;
+      }
+    }
+    if (s) s->append(popdf, popdfLen);
+  }
+
+  return nCols;
+}
+
 //------------------------------------------------------------------------
 // TextUnderline
 //------------------------------------------------------------------------
@@ -3720,7 +3809,7 @@ GBool TextPage::findText(Unicode *s, int len,
 			 double *xMax, double *yMax) {
   TextBlock *blk;
   TextLine *line;
-  Unicode *s2, *txt;
+  Unicode *s2, *txt, *reordered;
   Unicode *p;
   int txtSize, m, i, j, k;
   double xStart, yStart, xStop, yStop;
@@ -3728,20 +3817,23 @@ GBool TextPage::findText(Unicode *s, int len,
   double xMin1, yMin1, xMax1, yMax1;
   GBool found;
 
-  //~ needs to handle right-to-left text
 
   if (rawOrder) {
     return gFalse;
   }
 
+  // handle right-to-left text
+  reordered = (Unicode*)gmallocn(len, sizeof(Unicode));
+  reorderText(s, len, NULL, primaryLR, NULL, reordered);
+
+  // normalize the search string
+  s2 = unicodeNormalizeNFKC(reordered, len, &len, NULL);
+
   // convert the search string to uppercase
   if (!caseSensitive) {
-    s2 = unicodeNormalizeNFKC(s, len, &len, NULL);
     for (i = 0; i < len; ++i) {
       s2[i] = unicodeToUpper(s2[i]);
     }
-  } else {
-    s2 = unicodeNormalizeNFKC(s, len, &len, NULL);
   }
 
   txt = NULL;
@@ -3809,7 +3901,8 @@ GBool TextPage::findText(Unicode *s, int len,
       if (!line->normalized)
 	line->normalized = unicodeNormalizeNFKC(line->text, line->len, 
 						&line->normalized_len, 
-						&line->normalized_idx);
+						&line->normalized_idx,
+						true);
       // convert the line to uppercase
       m = line->normalized_len;
       if (!caseSensitive) {
@@ -3915,6 +4008,7 @@ GBool TextPage::findText(Unicode *s, int len,
   }
 
   gfree(s2);
+  gfree(reordered);
   if (!caseSensitive) {
     gfree(txt);
   }
@@ -5330,91 +5424,22 @@ void TextPage::assignColumns(TextLineFrag *frags, int nFrags, GBool oneRot) {
 
 int TextPage::dumpFragment(Unicode *text, int len, UnicodeMap *uMap,
 			   GooString *s) {
-  char lre[8], rle[8], popdf[8], buf[8];
-  int lreLen, rleLen, popdfLen, n;
-  int nCols, i, j, k;
-
-  nCols = 0;
-
   if (uMap->isUnicode()) {
+    return reorderText(text, len, uMap, primaryLR, s, NULL);
+  } else {
+    int nCols = 0;
 
-    lreLen = uMap->mapUnicode(0x202a, lre, sizeof(lre));
-    rleLen = uMap->mapUnicode(0x202b, rle, sizeof(rle));
-    popdfLen = uMap->mapUnicode(0x202c, popdf, sizeof(popdf));
-
-    if (primaryLR) {
-
-      i = 0;
-      while (i < len) {
-	// output a left-to-right section
-	for (j = i; j < len && !unicodeTypeR(text[j]); ++j) ;
-	for (k = i; k < j; ++k) {
-	  n = uMap->mapUnicode(text[k], buf, sizeof(buf));
-	  s->append(buf, n);
-	  ++nCols;
-	}
-	i = j;
-	// output a right-to-left section
-	for (j = i;
-	     j < len && !(unicodeTypeL(text[j]) || unicodeTypeNum(text[j]));
-	     ++j) ;
-	if (j > i) {
-	  s->append(rle, rleLen);
-	  for (k = j - 1; k >= i; --k) {
-	    n = uMap->mapUnicode(text[k], buf, sizeof(buf));
-	    s->append(buf, n);
-	    ++nCols;
-	  }
-	  s->append(popdf, popdfLen);
-	  i = j;
-	}
-      }
-
-    } else {
-
-      // Note: This code treats numeric characters (European and
-      // Arabic/Indic) as left-to-right, which isn't strictly correct
-      // (incurs extra LRE/POPDF pairs), but does produce correct
-      // visual formatting.
-      s->append(rle, rleLen);
-      i = len - 1;
-      while (i >= 0) {
-	// output a right-to-left section
-	for (j = i;
-	     j >= 0 && !(unicodeTypeL(text[j]) || unicodeTypeNum(text[j]));
-	     --j) ;
-	for (k = i; k > j; --k) {
-	  n = uMap->mapUnicode(text[k], buf, sizeof(buf));
-	  s->append(buf, n);
-	  ++nCols;
-	}
-	i = j;
-	// output a left-to-right section
-	for (j = i; j >= 0 && !unicodeTypeR(text[j]); --j) ;
-	if (j < i) {
-	  s->append(lre, lreLen);
-	  for (k = j + 1; k <= i; ++k) {
-	    n = uMap->mapUnicode(text[k], buf, sizeof(buf));
-	    s->append(buf, n);
-	    ++nCols;
-	  }
-	  s->append(popdf, popdfLen);
-	  i = j;
-	}
-      }
-      s->append(popdf, popdfLen);
+    char buf[8];
+    int buflen = 0;
 
+    for (int i = 0; i < len; ++i) {
+      buflen = uMap->mapUnicode(text[i], buf, sizeof(buf));
+      s->append(buf, buflen);
+      nCols += buflen;
     }
 
-  } else {
-    for (i = 0; i < len; ++i) {
-      n = uMap->mapUnicode(text[i], buf, sizeof(buf));
-      s->append(buf, n);
-      nCols += n;
-    }
+    return nCols;
   }
-
-  return nCols;
 }
 
 #if TEXTOUT_WORD_LIST
diff --git a/source/libs/poppler/poppler-src/poppler/UnicodeTypeTable.cc b/source/libs/poppler/poppler-src/poppler/UnicodeTypeTable.cc
index 721af9db6..c9f8e2a3b 100644
--- a/source/libs/poppler/poppler-src/poppler/UnicodeTypeTable.cc
+++ b/source/libs/poppler/poppler-src/poppler/UnicodeTypeTable.cc
@@ -17,6 +17,7 @@
 // Copyright (C) 2007 Jeff Muizelaar <jeff@infidigm.net>
 // Copyright (C) 2008 Albert Astals Cid <aacid@kde.org>
 // Copyright (C) 2012 Adrian Johnson <ajohnson@redneon.com>
+// Copyright (C) 2016 Khaled Hosny <khaledhosny@eglug.org>
 //
 // To see a description of the changes please see the Changelog file that
 // came with your tarball or type make ChangeLog if you are building from git
@@ -1015,7 +1016,9 @@ Unicode unicodeToUpper(Unicode c) {
 // of characters written. @buf may be NULL, in which case the length of the
 // decomposition is returned but nothing is written. If @u is its own
 // decomposition, write @u into @buf and return 1.
-static int decomp_compat(Unicode u, Unicode *buf) {
+// If reverseRTL is true, then decompositions of RTL characters will be output
+// in reverse order.
+static int decomp_compat(Unicode u, Unicode *buf, GBool reverseRTL = false) {
   // decomposition tables stored as lists {character, decomp_length, offset}
   // so we do a binary search
   int start = 0, end = DECOMP_TABLE_LENGTH;
@@ -1031,7 +1034,10 @@ static int decomp_compat(Unicode u, Unicode *buf) {
 	  int length = decomp_table[midpoint].length, i;
 	  if (buf)
 	    for (i = 0; i < length; ++i)
-	      buf[i] = decomp_expansion[offset + i];
+		if (unicodeTypeR(u) && reverseRTL)
+		  buf[i] = decomp_expansion[offset + length - i - 1];
+		else
+		  buf[i] = decomp_expansion[offset + i];
 	  return length;
 	}
       } else if (midpoint == start)
@@ -1125,8 +1131,14 @@ static GBool combine(Unicode base, Unicode add, Unicode *out) {
 // for each character in the normalized string giving the index in @in of the 
 // corresponding unnormalized character. @indices is not guaranteed monotone or
 // onto.
-Unicode *unicodeNormalizeNFKC(Unicode *in, int len, 
+Unicode *unicodeNormalizeNFKC(Unicode *in, int len,
 			      int *out_len, int **indices) {
+    return unicodeNormalizeNFKC(in, len, out_len, indices, false);
+}
+
+Unicode *unicodeNormalizeNFKC(Unicode *in, int len,
+			      int *out_len, int **indices,
+			      GBool reverseRTL) {
   Unicode *out;
   int i, o, *classes, *idx = NULL;
 
@@ -1174,7 +1186,7 @@ Unicode *unicodeNormalizeNFKC(Unicode *in, int len,
 	u = in[j];
 	if (j != i && COMBINING_CLASS(u) == 0)
 	  break;
-	dlen = decomp_compat(u, out + p);
+	dlen = decomp_compat(u, out + p, reverseRTL);
 	for (q = p; q < p + dlen; ++q) {
 	  classes[q] = COMBINING_CLASS(out[q]);
 	  if (indices)
diff --git a/source/libs/poppler/poppler-src/poppler/UnicodeTypeTable.h b/source/libs/poppler/poppler-src/poppler/UnicodeTypeTable.h
index 869aad9e6..978d889f6 100644
--- a/source/libs/poppler/poppler-src/poppler/UnicodeTypeTable.h
+++ b/source/libs/poppler/poppler-src/poppler/UnicodeTypeTable.h
@@ -15,6 +15,7 @@
 //
 // Copyright (C) 2006 Ed Catmur <ed@catmur.co.uk>
 // Copyright (C) 2012 Adrian Johnson <ajohnson@redneon.com>
+// Copyright (C) 2016 Khaled Hosny <khaledhosny@eglug.org>
 //
 // To see a description of the changes please see the Changelog file that
 // came with your tarball or type make ChangeLog if you are building from git
@@ -38,7 +39,11 @@ extern GBool unicodeIsAlphabeticPresentationForm(Unicode c);
 
 extern Unicode unicodeToUpper(Unicode c);
 
-extern Unicode *unicodeNormalizeNFKC(Unicode *in, int len, 
+extern Unicode *unicodeNormalizeNFKC(Unicode *in, int len,
 				     int *out_len, int **offsets);
 
+extern Unicode *unicodeNormalizeNFKC(Unicode *in, int len,
+				     int *out_len, int **offsets,
+				     GBool reverseRTL);
+
 #endif
diff --git a/source/libs/poppler/poppler-src/poppler/poppler-config.h.cmake b/source/libs/poppler/poppler-src/poppler/poppler-config.h.cmake
index b087a693f..e3e2cfb7d 100644
--- a/source/libs/poppler/poppler-src/poppler/poppler-config.h.cmake
+++ b/source/libs/poppler/poppler-src/poppler/poppler-config.h.cmake
@@ -134,7 +134,7 @@
 //------------------------------------------------------------------------
 
 // copyright notice
-#define popplerCopyright "Copyright 2005-2015 The Poppler Developers - http://poppler.freedesktop.org"
+#define popplerCopyright "Copyright 2005-2016 The Poppler Developers - http://poppler.freedesktop.org"
 #define xpdfCopyright "Copyright 1996-2011 Glyph & Cog, LLC"
 
 //------------------------------------------------------------------------
diff --git a/source/libs/poppler/poppler-src/poppler/poppler-config.h.in b/source/libs/poppler/poppler-src/poppler/poppler-config.h.in
index f73d0f66e..cb77eb767 100644
--- a/source/libs/poppler/poppler-src/poppler/poppler-config.h.in
+++ b/source/libs/poppler/poppler-src/poppler/poppler-config.h.in
@@ -134,7 +134,7 @@
 //------------------------------------------------------------------------
 
 // copyright notice
-#define popplerCopyright "Copyright 2005-2015 The Poppler Developers - http://poppler.freedesktop.org"
+#define popplerCopyright "Copyright 2005-2016 The Poppler Developers - http://poppler.freedesktop.org"
 #define xpdfCopyright "Copyright 1996-2011 Glyph & Cog, LLC"
 
 //------------------------------------------------------------------------
diff --git a/source/libs/poppler/version.ac b/source/libs/poppler/version.ac
index 8ec642ad8..14b56aa52 100644
--- a/source/libs/poppler/version.ac
+++ b/source/libs/poppler/version.ac
@@ -8,4 +8,4 @@ dnl
 dnl --------------------------------------------------------
 dnl
 dnl  m4-include this file to define the current poppler version
-m4_define([poppler_version], [0.39.0])
+m4_define([poppler_version], [0.40.0])
diff --git a/source/texk/README b/source/texk/README
index 33630f670..d039d2321 100644
--- a/source/texk/README
+++ b/source/texk/README
@@ -1,4 +1,4 @@
-$Id: README 39217 2015-12-28 23:25:11Z kakuto $
+$Id: README 39295 2016-01-06 05:27:06Z kakuto $
 Copyright 2006-2015 TeX Users Group.
 You may freely use, modify and/or distribute this file.
 
@@ -59,10 +59,10 @@ dvipos - ?
 
 dvipsk - maintained here, by us
 
-dvisvgm 1.14 - checked 28dec15
+dvisvgm 1.14.1 - checked 6jan16
   http://dvisvgm.bplaced.net/Downloads
 
-gregorio 4.0.0 - checked 9dec15
+gregorio 4.0.1 - checked 29dec15
   https://github.com/gregorio-project/gregorio/releases/
 
 gsftopk - from Paul Vojta's xdvi?
diff --git a/source/texk/web2c/c-auto.in b/source/texk/web2c/c-auto.in
index 05fde80fe..ce18d89e4 100644
--- a/source/texk/web2c/c-auto.in
+++ b/source/texk/web2c/c-auto.in
@@ -216,6 +216,9 @@
 /* Define to 1 if you have the <time.h> header file. */
 #undef HAVE_TIME_H
 
+/* Define to 1 if the system has the type `uintptr_t'. */
+#undef HAVE_UINTPTR_T
+
 /* Define to 1 if you have the <unistd.h> header file. */
 #undef HAVE_UNISTD_H
 
@@ -277,6 +280,9 @@
 /* The size of `off_t', as computed by sizeof. */
 #undef SIZEOF_OFF_T
 
+/* The size of `void *', as computed by sizeof. */
+#undef SIZEOF_VOID_P
+
 /* Define to 1 if you have the ANSI C header files. */
 #undef STDC_HEADERS
 
@@ -361,6 +367,10 @@
    such a type exists and the standard includes do not define it. */
 #undef uint64_t
 
+/* Define to the type of an unsigned integer type wide enough to hold a
+   pointer, if such a type exists, and if the system does not define it. */
+#undef uintptr_t
+
 /* Define as empty if not declared in <zlib.h>. */
 #undef z_const
 
diff --git a/source/texk/web2c/configure b/source/texk/web2c/configure
index a5209b9c9..e8b1a6123 100755
--- a/source/texk/web2c/configure
+++ b/source/texk/web2c/configure
@@ -21622,6 +21622,76 @@ fi
 
 done
 
+# The cast to long int works around a bug in the HP C Compiler
+# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
+# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
+# This bug is HP SR number 8606223364.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking size of void *" >&5
+$as_echo_n "checking size of void *... " >&6; }
+if ${ac_cv_sizeof_void_p+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (void *))" "ac_cv_sizeof_void_p"        "$ac_includes_default"; then :
+
+else
+  if test "$ac_cv_type_void_p" = yes; then
+     { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error 77 "cannot compute sizeof (void *)
+See \`config.log' for more details" "$LINENO" 5; }
+   else
+     ac_cv_sizeof_void_p=0
+   fi
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_void_p" >&5
+$as_echo "$ac_cv_sizeof_void_p" >&6; }
+
+
+
+cat >>confdefs.h <<_ACEOF
+#define SIZEOF_VOID_P $ac_cv_sizeof_void_p
+_ACEOF
+
+
+
+  ac_fn_c_check_type "$LINENO" "uintptr_t" "ac_cv_type_uintptr_t" "$ac_includes_default"
+if test "x$ac_cv_type_uintptr_t" = xyes; then :
+
+$as_echo "#define HAVE_UINTPTR_T 1" >>confdefs.h
+
+else
+  for ac_type in 'unsigned int' 'unsigned long int' \
+	'unsigned long long int'; do
+       cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$ac_includes_default
+int
+main ()
+{
+static int test_array [1 - 2 * !(sizeof (void *) <= sizeof ($ac_type))];
+test_array [0] = 0;
+return test_array [0];
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+
+cat >>confdefs.h <<_ACEOF
+#define uintptr_t $ac_type
+_ACEOF
+
+	  ac_type=
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+       test -z "$ac_type" && break
+     done
+fi
+
+
 
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for long double" >&5
 $as_echo_n "checking for long double... " >&6; }
diff --git a/source/texk/web2c/configure.ac b/source/texk/web2c/configure.ac
index fe61d80d6..c6cd65893 100644
--- a/source/texk/web2c/configure.ac
+++ b/source/texk/web2c/configure.ac
@@ -227,6 +227,8 @@ AC_SEARCH_LIBS([pow], [m])
 AC_CHECK_FUNCS([access atoi fmax ftime gettimeofday mkdtemp setlocale strerror strlcat strlcpy strndup])
 AC_CHECK_DECLS([strndup])
 AC_CHECK_HEADERS([errno.h langinfo.h locale.h sys/time.h sys/timeb.h sys/wait.h time.h])
+AC_CHECK_SIZEOF([void *])
+AC_TYPE_UINTPTR_T
 AC_TYPE_LONG_DOUBLE
 AC_HEADER_STDBOOL
 
diff --git a/source/texk/web2c/help.h b/source/texk/web2c/help.h
index bee0a4f77..1d1285645 100644
--- a/source/texk/web2c/help.h
+++ b/source/texk/web2c/help.h
@@ -216,9 +216,19 @@ const_string OFM2OPLHELP[] = {
     "  Translate the font metrics OFMNAME to human-readable property list file",
     "  OPLFILE or standard output.",
     "",
+#ifdef OMFONTS
+    "-char-format=TYPE      output character codes according to TYPE,",
+    "                        either `num' or `ascii'; default is num,",
+    "                        ascii = ascii letters and digits, num for all else",
+    "-num-format=TYPE       output numbers according to TYPE,",
+    "                        either `hex' or `octal'; default is hex",
+    "-text-format=TYPE      output coding scheme and family according to TYPE,",
+    "                        either `mixed' or `upper' case; default is mixed",
+#else
     "-charcode-format=TYPE  output character codes according to TYPE,",
     "                        either `hex' or `ascii'; default is hex,",
     "                        ascii = ascii letters and digits, hex for all else",
+#endif
     "-help                  display this help and exit",
     "-verbose               display progress reports",
     "-version               output version information and exit",
@@ -260,9 +270,19 @@ const_string OVF2OVPHELP[] = {
     "  virtual property list file OVPFILE or standard output.",
     "  If OFMNAME is not specified, OVFNAME (with `.ovf' removed) is used.",
     "",
+#ifdef OMFONTS
+    "-char-format=TYPE      output character codes according to TYPE,",
+    "                        either `num' or `ascii'; default is num,",
+    "                        ascii = ascii letters and digits, num for all else",
+    "-num-format=TYPE       output numbers according to TYPE,",
+    "                        either `hex' or `octal'; default is hex",
+    "-text-format=TYPE      output coding scheme and family according to TYPE,",
+    "                        either `mixed' or `upper' case; default is mixed",
+#else
     "-charcode-format=TYPE  output character codes according to TYPE,",
     "                        either `hex' or `ascii'; default is hex,",
     "                        ascii = ascii letters and digits, hex for all else",
+#endif
     "-help                  display this help and exit",
     "-verbose               display progress reports",
     "-version               output version information and exit",
@@ -556,9 +576,9 @@ const_string VFTOVPHELP[] = {
     "  If TFMNAME is not specified, VFNAME (with `.vf' removed) is used.",
     "",
     "-charcode-format=TYPE  output character codes according to TYPE,",
-    "                       either `octal' or `ascii'; default is ascii for",
+    "                        either `octal' or `ascii'; default is ascii for",
     "                        letters and digits, octal for all else",
-    "-help                   display this help and exit",
+    "-help                  display this help and exit",
     "-verbose               display progress reports",
     "-version               output version information and exit",
     NULL
diff --git a/source/texk/web2c/lib/ChangeLog b/source/texk/web2c/lib/ChangeLog
index c4d82416a..32bf88532 100644
--- a/source/texk/web2c/lib/ChangeLog
+++ b/source/texk/web2c/lib/ChangeLog
@@ -1,3 +1,7 @@
+2016-01-02  Akira Kakuto  <kakuto@fuk.kinidai.ac.jp>
+
+	* printversion.c: 2015 ---> 2016.
+
 2015-11-15  Akira Kakuto  <kakuto@fuk.kinidai.ac.jp>
 
 	* texmfmp.c: Show return code of system() if it is not zero.
diff --git a/source/texk/web2c/lib/printversion.c b/source/texk/web2c/lib/printversion.c
index c1a32c887..8ba3f2c6f 100644
--- a/source/texk/web2c/lib/printversion.c
+++ b/source/texk/web2c/lib/printversion.c
@@ -51,7 +51,7 @@ printversionandexit (const_string banner,
 #endif
 
   if (copyright_holder) {
-    printf ("Copyright 2015 %s.\n", copyright_holder);
+    printf ("Copyright 2016 %s.\n", copyright_holder);
     if (!author)
       author = copyright_holder;
   }
diff --git a/source/texk/web2c/lib/texmfmp.c b/source/texk/web2c/lib/texmfmp.c
index 83555e3b1..75c846a33 100644
--- a/source/texk/web2c/lib/texmfmp.c
+++ b/source/texk/web2c/lib/texmfmp.c
@@ -536,6 +536,7 @@ runsystem (const char *cmd)
   int allow = 0;
   char *safecmd = NULL;
   char *cmdname = NULL;
+  int status = 0;
 
   if (shellenabledp <= 0) {
     return 0;
@@ -548,9 +549,13 @@ runsystem (const char *cmd)
     allow = shell_cmd_is_allowed (cmd, &safecmd, &cmdname);
 
   if (allow == 1)
-    (void) system (cmd);
+    status = system (cmd);
   else if (allow == 2)
-    (void) system (safecmd);
+    status =  system (safecmd);
+
+  /* Not really meaningful, but we have to manage the return value of system. */
+  if (status != 0)
+    fprintf(stderr,"system returned with code %d\n", status); 
 
   if (safecmd)
     free (safecmd);
diff --git a/source/texk/web2c/texmfmp.h b/source/texk/web2c/texmfmp.h
index 3fbf70215..571382294 100644
--- a/source/texk/web2c/texmfmp.h
+++ b/source/texk/web2c/texmfmp.h
@@ -304,6 +304,13 @@ extern void paintrow (/*screenrow, pixelcolor, transspec, screencol*/);
 #define	undumpthings(base, len) \
   do_undump ((char *) &(base), sizeof (base), (int) (len), DUMP_FILE)
 
+#ifndef PRIdPTR
+#define PRIdPTR "ld"
+#endif
+#ifndef PRIxPTR
+#define PRIxPTR "lx"
+#endif
+
 /* Like do_undump, but check each value against LOW and HIGH.  The
    slowdown isn't significant, and this improves the chances of
    detecting incompatible format files.  In fact, Knuth himself noted
@@ -315,9 +322,10 @@ extern void paintrow (/*screenrow, pixelcolor, transspec, screencol*/);
     undumpthings (base, len);                                           \
     for (i = 0; i < (len); i++) {                                       \
       if ((&(base))[i] < (low) || (&(base))[i] > (high)) {              \
-        FATAL5 ("Item %u (=%ld) of .fmt array at %lx <%ld or >%ld",     \
-                i, (unsigned long) (&(base))[i], (unsigned long) &(base),\
-                (unsigned long) low, (unsigned long) high);                   \
+        FATAL5 ("Item %u (=%" PRIdPTR ") of .fmt array at %" PRIxPTR    \
+                " <%" PRIdPTR " or >%" PRIdPTR,                         \
+                i, (uintptr_t) (&(base))[i], (uintptr_t) &(base),       \
+                (uintptr_t) low, (uintptr_t) high);                     \
       }                                                                 \
     }									\
   } while (0)
@@ -331,9 +339,10 @@ extern void paintrow (/*screenrow, pixelcolor, transspec, screencol*/);
     undumpthings (base, len);                                           \
     for (i = 0; i < (len); i++) {                                       \
       if ((&(base))[i] > (high)) {              			\
-        FATAL4 ("Item %u (=%ld) of .fmt array at %lx >%ld",     	\
-                i, (unsigned long) (&(base))[i], (unsigned long) &(base),\
-                (unsigned long) high);                         		\
+        FATAL4 ("Item %u (=%" PRIdPTR ") of .fmt array at %" PRIxPTR    \
+                " >%" PRIdPTR,                                          \
+                i, (uintptr_t) (&(base))[i], (uintptr_t) &(base),       \
+                (uintptr_t) high);                         		\
       }                                                                 \
     }									\
   } while (0)
diff --git a/source/texk/web2c/tftopl.test b/source/texk/web2c/tftopl.test
index 49237d2f9..b9a87fed4 100644
--- a/source/texk/web2c/tftopl.test
+++ b/source/texk/web2c/tftopl.test
@@ -5,6 +5,8 @@
 
 test -d tests || mkdir -p tests
 
+./tftopl -char=foo -help || exit 1
+
 ./tftopl -version || exit 1
 
 TEXMFCNF=$srcdir/../kpathsea
diff --git a/source/texk/web2c/triptrap/mtrap.mp b/source/texk/web2c/triptrap/mtrap.mp
index 826c7bc92..617a68cc2 100644
--- a/source/texk/web2c/triptrap/mtrap.mp
+++ b/source/texk/web2c/triptrap/mtrap.mp
@@ -1,4 +1,4 @@
-%batchmode;
+batchmode;
 delimiters ();
 def -- = {curl 1}..{curl 1} enddef;
 showstats;
diff --git a/source/texk/web2c/vftovp.test b/source/texk/web2c/vftovp.test
index 9623525d5..6e8b01af2 100644
--- a/source/texk/web2c/vftovp.test
+++ b/source/texk/web2c/vftovp.test
@@ -5,6 +5,8 @@
 
 test -d tests || mkdir -p tests
 
+./vftovp -char=bar -help  || exit 1
+
 ./vftovp -version  || exit 1
 
 TEXMFCNF=$srcdir/../kpathsea
-- 
GitLab