Rebased ref, commits from common ancestor:
commit 044f467cbe14fcbad5ce929a24795676d4463d61
Author: David Tardon <dtar...@redhat.com>
Date:   Tue Jan 31 22:35:37 2017 +0100

    upload zlib 1.2.11
    
    Reviewed-on: https://gerrit.libreoffice.org/33770
    Tested-by: Jenkins <c...@libreoffice.org>
    Reviewed-by: David Tardon <dtar...@redhat.com>
    
    Conflicts:
            download.lst
    
    Change-Id: I4e19a9d976c28f5e6649bdbb3dd609e03a4c03a8

diff --git a/Makefile.fetch b/Makefile.fetch
index 6b6fbcb4cd1e..9b0e231d85ef 100644
--- a/Makefile.fetch
+++ b/Makefile.fetch
@@ -90,6 +90,7 @@ $(WORKDIR)/download: $(BUILDDIR)/config_host.mk 
$(SRCDIR)/download.lst $(SRCDIR)
                $(call fetch_Optional,ODFGEN,ODFGEN_TARBALL) \
                $(call fetch_Optional,PYTHON,PYTHON_TARBALL) \
                $(call fetch_Optional,VISIO,VISIO_TARBALL) \
+               $(call fetch_Optional,ZLIB,ZLIB_TARBALL) \
        ,$(call 
fetch_Download_item_special,http://dev-www.libreoffice.org/src,$(item)))
        $(foreach item, \
                $(call fetch_Optional,AFMS,$(AFMS_TARBALL)) \
@@ -172,7 +173,6 @@ $(WORKDIR)/download: $(BUILDDIR)/config_host.mk 
$(SRCDIR)/download.lst $(SRCDIR)
                $(call fetch_Optional,WPG,$(WPG_TARBALL)) \
                $(call fetch_Optional,WPS,$(WPS_TARBALL)) \
                $(call fetch_Optional,XSLTML,$(XSLTML_TARBALL)) \
-               $(call fetch_Optional,ZLIB,$(ZLIB_TARBALL)) \
        ,$(call fetch_Download_item,http://dev-www.libreoffice.org/src,$(item)))
        $(foreach item, \
                $(call fetch_Optional,DBGHELP,$(DBGHELP_DLL)) \
diff --git a/download.lst b/download.lst
index 059a06f684da..1e8e665767cf 100644
--- a/download.lst
+++ b/download.lst
@@ -32,6 +32,8 @@ PYTHON_MD5SUM := 803a75927f8f241ca78633890c798021
 export PYTHON_TARBALL := Python-3.3.5.tgz
 OPENSSL_MD5SUM := 44279b8557c3247cbe324e2322ecd114
 export OPENSSL_TARBALL := openssl-1.0.2o.tar.gz
+ZLIB_MD5SUM := 85adef240c5f370b308da8c938951a68
+export ZLIB_TARBALL := zlib-1.2.11.tar.xz
 
 export AFMS_TARBALL := 
1756c4fa6c616ae15973c104cd8cb256-Adobe-Core35_AFMs-314.tar.gz
 export APACHE_COMMONS_CODEC_TARBALL := 
2e482c7567908d334785ce7d69ddfff7-commons-codec-1.6-src.tar.gz
@@ -110,7 +112,6 @@ export WPD_TARBALL := 
a3dcac551fae5ebbec16e844810828c4-libwpd-0.9.9.tar.bz2
 export WPG_TARBALL := b85436266b2ac91d351ab5684b181151-libwpg-0.2.2.tar.bz2
 export WPS_TARBALL := 46eb0e7f213ad61bd5dee0c494132cb0-libwps-0.2.9.tar.bz2
 export XSLTML_TARBALL := a7983f859eafb2677d7ff386a023bc40-xsltml_2.1.2.zip
-export ZLIB_TARBALL := 2ab442d169156f34c379c968f3f482dd-zlib-1.2.7.tar.bz2
 
 export MOZ_ZIP_INC := $(OS)$(COM)$(if $(filter INTEL,$(CPUNAME)),I,X)inc.zip
 export MOZ_ZIP_LIB := $(OS)$(COM)$(if $(filter INTEL,$(CPUNAME)),I,X)lib.zip
commit 53299350e2aabe9f24b9a73c6033531358e881c2
Author: Thorsten Behrens <thorsten.behr...@cib.de>
Date:   Mon Apr 30 14:33:09 2018 +0200

    update openssl to 1.0.2o
    
    Change-Id: I6f7308e60ba74bbcec1719c9aeec8e6c21d24ecc

diff --git a/Makefile.fetch b/Makefile.fetch
index bb0b02f4ac5e..6b6fbcb4cd1e 100644
--- a/Makefile.fetch
+++ b/Makefile.fetch
@@ -86,6 +86,7 @@ $(WORKDIR)/download: $(BUILDDIR)/config_host.mk 
$(SRCDIR)/download.lst $(SRCDIR)
                $(call fetch_Optional,LIBLANGTAG,LANGTAGREG_TARBALL) \
                $(call fetch_Optional,MSPUB,MSPUB_TARBALL) \
                $(call fetch_Optional,MWAW,MWAW_TARBALL) \
+               $(call fetch_Optional,OPENSSL,OPENSSL_TARBALL) \
                $(call fetch_Optional,ODFGEN,ODFGEN_TARBALL) \
                $(call fetch_Optional,PYTHON,PYTHON_TARBALL) \
                $(call fetch_Optional,VISIO,VISIO_TARBALL) \
@@ -154,7 +155,6 @@ $(WORKDIR)/download: $(BUILDDIR)/config_host.mk 
$(SRCDIR)/download.lst $(SRCDIR)
                $(call fetch_Optional,NSS,$(NSS_TARBALL)) \
                $(NUMBERTEXT_EXTENSION_PACK) \
                $(call fetch_Optional,OPENLDAP,$(OPENLDAP_TARBALL)) \
-               $(call fetch_Optional,OPENSSL,$(OPENSSL_TARBALL)) \
                $(call fetch_Optional,ORCUS,$(ORCUS_TARBALL)) \
                $(call fetch_Optional,CAIRO,$(PIXMAN_TARBALL)) \
                $(call fetch_Optional,LIBPNG,$(PNG_TARBALL)) \
diff --git a/download.lst b/download.lst
index f83677a20ba9..059a06f684da 100644
--- a/download.lst
+++ b/download.lst
@@ -30,6 +30,8 @@ LANGTAGREG_MD5SUM := 504af523f5d1a5590bbeb6a4b55e8a97
 export LANGTAGREG_TARBALL := language-subtag-registry-2014-03-27.tar.bz2
 PYTHON_MD5SUM := 803a75927f8f241ca78633890c798021
 export PYTHON_TARBALL := Python-3.3.5.tgz
+OPENSSL_MD5SUM := 44279b8557c3247cbe324e2322ecd114
+export OPENSSL_TARBALL := openssl-1.0.2o.tar.gz
 
 export AFMS_TARBALL := 
1756c4fa6c616ae15973c104cd8cb256-Adobe-Core35_AFMs-314.tar.gz
 export APACHE_COMMONS_CODEC_TARBALL := 
2e482c7567908d334785ce7d69ddfff7-commons-codec-1.6-src.tar.gz
@@ -92,7 +94,6 @@ export MYTHES_TARBALL := 
46e92b68e31e858512b680b3b61dc4c1-mythes-1.2.3.tar.gz
 export NEON_TARBALL := ff369e69ef0f0143beb5626164e87ae2-neon-0.29.5.tar.gz
 export NSS_TARBALL := 
b279551b7638d0e36d1199548124c247-nss-3.16.5-with-nspr-4.10.6.tar.gz
 export OPENLDAP_TARBALL := 804c6cb5698db30b75ad0ff1c25baefd-openldap-2.4.31.tgz
-export OPENSSL_TARBALL := 
66bf6f10f060d561929de96f9dfe5b8c-openssl-1.0.1e.tar.gz
 export ORCUS_TARBALL := ea2acaf140ae40a87a952caa75184f4d-liborcus-0.5.1.tar.bz2
 export PIXMAN_TARBALL := c63f411b3ad147db2bcce1bf262a0e02-pixman-0.24.4.tar.bz2
 export PNG_TARBALL := 9e5d864bce8f06751bbd99962ecf4aad-libpng-1.5.10.tar.gz
commit 2ede29cb953330ba184a770e6e8fa9904c52b294
Author: Michael Stahl <mst...@redhat.com>
Date:   Mon Jan 8 17:48:40 2018 +0100

    openssl: fix MSVC 64-bit build
    
    For whatever reason OpenSSL wants to use "masm" (ml.exe) on 32-bit
    builds but "nasm" on 64-bit builds - this despite INSTALL.W32 claiming
    that only nasm is "supported".
    
    But /safeseh doesn't make sense on 64-bit anyway because there
    is no "unsafe" SEH there, so just apply the patch only for 32-bit.
    
    Change-Id: Ie32b17dfeeaf11c49ee29c3181021ffa5bd99091

diff --git a/external/openssl/UnpackedTarball_openssl.mk 
b/external/openssl/UnpackedTarball_openssl.mk
index 1d8728381e78..05fd56448a58 100644
--- a/external/openssl/UnpackedTarball_openssl.mk
+++ b/external/openssl/UnpackedTarball_openssl.mk
@@ -14,6 +14,7 @@ $(eval $(call 
gb_UnpackedTarball_set_tarball,openssl,$(OPENSSL_TARBALL),,openssl
 $(eval $(call gb_UnpackedTarball_add_patches,openssl,\
        external/openssl/openssllnx.patch \
        external/openssl/opensslwnt.patch \
+       $(if $(filter 
INTEL,$(CPUNAME)),external/openssl/opensslwnt_safeseh.patch) \
        external/openssl/openssl-1.0.1h-win64.patch.1 \
        external/openssl/opensslsol.patch \
        external/openssl/opensslios.patch \
diff --git a/external/openssl/opensslwnt.patch 
b/external/openssl/opensslwnt.patch
index ffdcc5353913..2d00736f1317 100644
--- a/external/openssl/opensslwnt.patch
+++ b/external/openssl/opensslwnt.patch
@@ -79,26 +79,15 @@ diff -ru openssl.orig/util/mk1mf.pl openssl/util/mk1mf.pl
  APP_CFLAG=$app_cflag
  LIB_CFLAG=$lib_cflag
  SHLIB_CFLAG=$shl_cflag
-@@ -488,8 +493,8 @@
- SRC_D=$src_dir
+@@ -488,7 +493,7 @@
  
  LINK_CMD=$link
--LFLAGS=$lflags
-+LFLAGS=$lflags /SAFESEH
+ LFLAGS=$lflags
 -RSC=$rsc
 +RSC=$rsc \$(SOLARINC)
  
  # The output directory for everything interesting
  OUT_D=$out_dir
-@@ -511,7 +516,7 @@
- MKDIR=$mkdir
- MKLIB=$bin_dir$mklib
- MLFLAGS=$mlflags
--ASM=$bin_dir$asm
-+ASM=$bin_dir$asm /safeseh
- 
- # FIPS validated module and support file locations
- 
 @@ -669,7 +674,7 @@
  printf OUT <<EOF;
  #ifdef $platform_cpp_symbol
diff --git a/external/openssl/opensslwnt_safeseh.patch 
b/external/openssl/opensslwnt_safeseh.patch
new file mode 100644
index 000000000000..f2eafab5b9ed
--- /dev/null
+++ b/external/openssl/opensslwnt_safeseh.patch
@@ -0,0 +1,23 @@
+use /safeseh in 32-bit MSVC builds; this is not required for 64-bit
+
+diff -ru openssl.orig/util/mk1mf.pl openssl/util/mk1mf.pl
+--- a/openssl.orig/util/mk1mf.pl       2016-03-03 20:22:21.043924505 +0100
++++ b/openssl/util/mk1mf.pl    2016-03-03 20:34:45.015901171 +0100
+@@ -488,7 +493,7 @@
+ SRC_D=$src_dir
+ 
+ LINK_CMD=$link
+-LFLAGS=$lflags
++LFLAGS=$lflags /SAFESEH
+ RSC=$rsc \$(SOLARINC)
+ 
+ # The output directory for everything interesting
+@@ -511,7 +516,7 @@
+ MKDIR=$mkdir
+ MKLIB=$bin_dir$mklib
+ MLFLAGS=$mlflags
+-ASM=$bin_dir$asm
++ASM=$bin_dir$asm /safeseh
+ 
+ # FIPS validated module and support file locations
+ 
commit 2f3ec3a30128b6428e9fcf7785780430393d559d
Author: David Tardon <dtar...@redhat.com>
Date:   Wed Feb 1 12:47:04 2017 +0100

    upload openssl 1.0.2k
    
    Change-Id: I26d49db0207b3f4f64aa9698da4cf3567d195834
    Reviewed-on: https://gerrit.libreoffice.org/33800
    Tested-by: Jenkins <c...@libreoffice.org>
    Reviewed-by: David Tardon <dtar...@redhat.com>

diff --git a/external/openssl/openssllnx.patch 
b/external/openssl/openssllnx.patch
index de19807b313e..224df8f87b2e 100644
--- a/external/openssl/openssllnx.patch
+++ b/external/openssl/openssllnx.patch
@@ -19,5 +19,5 @@
 -              AS='$(CC)' ASFLAG='$(CFLAG) -c'                 \
 +              AS='$(CC)' ASFLAG='$(CFLAG) -c -Wa,--noexecstack'       \
                AR='$(AR)' NM='$(NM)' RANLIB='$(RANLIB)'        \
+               RC='$(RC)'                                      \
                CROSS_COMPILE='$(CROSS_COMPILE)'        \
-               PERL='$(PERL)' ENGDIRS='$(ENGDIRS)'             \
commit 364ed6405fe416182f8a5a0ffa4f6a69312c5229
Author: Michael Stahl <mst...@redhat.com>
Date:   Mon Jan 8 12:31:39 2018 +0100

    openssl: MSVC build: link and run MSASM with /SAFESEH
    
    Actually the assembler requires lowercase /safeseh, oddly enough.
    
    Change-Id: I1569409a2d6358282a7463ea996a6b1615e6ed8c

diff --git a/external/openssl/opensslwnt.patch 
b/external/openssl/opensslwnt.patch
index 2d00736f1317..ffdcc5353913 100644
--- a/external/openssl/opensslwnt.patch
+++ b/external/openssl/opensslwnt.patch
@@ -79,15 +79,26 @@ diff -ru openssl.orig/util/mk1mf.pl openssl/util/mk1mf.pl
  APP_CFLAG=$app_cflag
  LIB_CFLAG=$lib_cflag
  SHLIB_CFLAG=$shl_cflag
-@@ -488,7 +493,7 @@
+@@ -488,8 +493,8 @@
+ SRC_D=$src_dir
  
  LINK_CMD=$link
- LFLAGS=$lflags
+-LFLAGS=$lflags
++LFLAGS=$lflags /SAFESEH
 -RSC=$rsc
 +RSC=$rsc \$(SOLARINC)
  
  # The output directory for everything interesting
  OUT_D=$out_dir
+@@ -511,7 +516,7 @@
+ MKDIR=$mkdir
+ MKLIB=$bin_dir$mklib
+ MLFLAGS=$mlflags
+-ASM=$bin_dir$asm
++ASM=$bin_dir$asm /safeseh
+ 
+ # FIPS validated module and support file locations
+ 
 @@ -669,7 +674,7 @@
  printf OUT <<EOF;
  #ifdef $platform_cpp_symbol
commit f1019f5c599a991624877a633d7a9d1071f49181
Author: Caolán McNamara <caol...@redhat.com>
Date:   Thu Jan 28 14:51:47 2016 +0000

    upgrade openssl to 1.0.2g
    
    We can't "break symlinks after extracting tarball" because they populate
    that dir during the build now. So instead cripple mklink.pl to
    copy instead of link. (Configure no-symlinks simply skips the symlink
    step instead of copying, so that appears useless)
    
    Change-Id: Ib30b2c1b8b3de72511d09c478297a7a5a4bc691e
    Reviewed-on: https://gerrit.libreoffice.org/21880
    Reviewed-by: Caolán McNamara <caol...@redhat.com>
    Tested-by: Caolán McNamara <caol...@redhat.com>

diff --git a/external/openssl/UnpackedTarball_openssl.mk 
b/external/openssl/UnpackedTarball_openssl.mk
index d36aba5ebdd0..1d8728381e78 100644
--- a/external/openssl/UnpackedTarball_openssl.mk
+++ b/external/openssl/UnpackedTarball_openssl.mk
@@ -11,24 +11,14 @@ $(eval $(call gb_UnpackedTarball_UnpackedTarball,openssl))
 
 $(eval $(call 
gb_UnpackedTarball_set_tarball,openssl,$(OPENSSL_TARBALL),,openssl))
 
-# break symlinks after extracting tarball
-# note: escape \; because LO patched make 3.82 cuts off the command otherwise
-ifeq ($(OS_FOR_BUILD),WNT)
-$(eval $(call gb_UnpackedTarball_set_pre_action,openssl,\
-       cd include/openssl && \
-       for header in `find . -type l` \; do \
-               cp --remove-destination `readlink $$$$header` $$$$header \; \
-       done && cd -))
-endif
-
 $(eval $(call gb_UnpackedTarball_add_patches,openssl,\
        external/openssl/openssllnx.patch \
        external/openssl/opensslwnt.patch \
-       external/openssl/openssl-1.0.1g-msvc2012-winxp.patch.1 \
        external/openssl/openssl-1.0.1h-win64.patch.1 \
        external/openssl/opensslsol.patch \
        external/openssl/opensslios.patch \
        external/openssl/openssl-3650-masm.patch.1 \
+       external/openssl/openssl-fixbuild.patch.1 \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/external/openssl/openssl-1.0.1g-msvc2012-winxp.patch.1 
b/external/openssl/openssl-1.0.1g-msvc2012-winxp.patch.1
deleted file mode 100644
index de9e6fc09f4a..000000000000
--- a/external/openssl/openssl-1.0.1g-msvc2012-winxp.patch.1
+++ /dev/null
@@ -1,20 +0,0 @@
---- openssl.org/util/pl/VC-32.pl       2014-05-18 23:41:39.336594400 +0200
-+++ openssl/util/pl/VC-32.pl   2014-05-18 23:47:40.055279300 +0200
-@@ -48,7 +48,7 @@
-     my $f = $shlib || $fips ?' /MD':' /MT';
-     $opt_cflags=$f.' /Ox';
-     $dbg_cflags=$f.'d /Od -DDEBUG -D_DEBUG';
--    $lflags="/nologo /subsystem:console /opt:ref";
-+    $lflags="/nologo /subsystem:console,5.02 /opt:ref";
- 
-     *::perlasm_compile_target = sub {
-       my ($target,$source,$bname)=@_;
-@@ -135,7 +135,7 @@
-     $ff = "/fixed";
-     $opt_cflags=$f.' -Ox -O2 -Ob2';
-     $dbg_cflags=$f.'d -Od -DDEBUG -D_DEBUG';
--    $lflags="/nologo /subsystem:console /opt:ref";
-+    $lflags="/nologo /subsystem:console,5.01 /opt:ref";
-     }
- $lib_cflag='-Zl' if (!$shlib);        # remove /DEFAULTLIBs from static lib
- $mlflags='';
diff --git a/external/openssl/openssl-fixbuild.patch.1 
b/external/openssl/openssl-fixbuild.patch.1
new file mode 100644
index 000000000000..5a986e87214b
--- /dev/null
+++ b/external/openssl/openssl-fixbuild.patch.1
@@ -0,0 +1,23 @@
+--- a/crypto/evp/Makefile
++++ b/crypto/evp/Makefile
+@@ -289,7 +289,7 @@
+ e_idea.o: ../../e_os.h ../../include/openssl/asn1.h 
../../include/openssl/bio.h
+ e_idea.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
+ e_idea.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
+-e_idea.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
++e_idea.o: ../../include/openssl/evp.h ../idea/idea.h
+ e_idea.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+ e_idea.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+ e_idea.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+--- a/util/mklink.pl
++++ b/util/mklink.pl
+@@ -50,8 +50,7 @@
+ my $to = join('/', @to_path);
+ 
+ my $file;
+-$symlink_exists=eval {symlink("",""); 1};
+-if ($^O eq "msys") { $symlink_exists=0 };
++$symlink_exists=0;
+ foreach $file (@files) {
+     my $err = "";
+     if ($symlink_exists) {
diff --git a/external/openssl/openssllnx.patch 
b/external/openssl/openssllnx.patch
index 23a7d9e4c228..de19807b313e 100644
--- a/external/openssl/openssllnx.patch
+++ b/external/openssl/openssllnx.patch
@@ -12,12 +12,12 @@
  
 --- build/openssl-0.9.8v/Makefile.org  2010-01-27 17:06:36.000000000 +0100
 +++ build/openssl-0.9.8v/Makefile.org  2010-09-20 09:24:00.000000000 +0100
-@@ -199,7 +199,7 @@
- 
- BUILDENV=     PLATFORM='$(PLATFORM)' PROCESSOR='$(PROCESSOR)' \
+@@ -206,7 +206,7 @@
+ # same language for uniform treatment.
+ BUILDENV=     LC_ALL=C PLATFORM='$(PLATFORM)' PROCESSOR='$(PROCESSOR)'\
                CC='$(CC)' CFLAG='$(CFLAG)'                     \
 -              AS='$(CC)' ASFLAG='$(CFLAG) -c'                 \
-+              AS='$(CC)' ASFLAG='$(CFLAG) -c -Wa,--noexecstack'       \
++              AS='$(CC)' ASFLAG='$(CFLAG) -c -Wa,--noexecstack'       \
                AR='$(AR)' NM='$(NM)' RANLIB='$(RANLIB)'        \
                CROSS_COMPILE='$(CROSS_COMPILE)'        \
                PERL='$(PERL)' ENGDIRS='$(ENGDIRS)'             \
diff --git a/external/openssl/opensslwnt.patch 
b/external/openssl/opensslwnt.patch
index e033d25f602f..2d00736f1317 100644
--- a/external/openssl/opensslwnt.patch
+++ b/external/openssl/opensslwnt.patch
@@ -1,32 +1,39 @@
---- misc/openssl-0.9.8v/crypto/x509v3/v3_pci.c 2007-03-05 01:06:47.000000000 
+0100
-+++ build/openssl-0.9.8v/crypto/x509v3/v3_pci.c        2010-03-26 
12:04:20.961547300 +0100
+diff -ru openssl.orig/crypto/x509v3/v3_pci.c openssl/crypto/x509v3/v3_pci.c
+--- a/openssl.orig/crypto/x509v3/v3_pci.c      2016-03-01 14:35:05.000000000 
+0100
++++ b/openssl/crypto/x509v3/v3_pci.c   2016-03-03 20:27:42.195914432 +0100
 @@ -3,7 +3,7 @@
   * Contributed to the OpenSSL Project 2004 by Richard Levitte
   * (rich...@levitte.org)
   */
--/* Copyright (c) 2004 Kungliga Tekniska H�gskolan
+-/* Copyright (c) 2004 Kungliga Tekniska Högskolan
 +/* Copyright (c) 2004 Kungliga Tekniska Hoegskolan
   * (Royal Institute of Technology, Stockholm, Sweden).
   * All rights reserved.
   *
---- misc/openssl-0.9.8v/crypto/x509v3/v3_pcia.c        2004-12-28 
01:21:33.000000000 +0100
-+++ build/openssl-0.9.8v/crypto/x509v3/v3_pcia.c       2010-03-26 
12:04:20.961547300 +0100
+diff -ru openssl.orig/crypto/x509v3/v3_pcia.c openssl/crypto/x509v3/v3_pcia.c
+--- a/openssl.orig/crypto/x509v3/v3_pcia.c     2016-03-01 14:35:05.000000000 
+0100
++++ b/openssl/crypto/x509v3/v3_pcia.c  2016-03-03 20:27:56.495913984 +0100
 @@ -3,7 +3,7 @@
   * Contributed to the OpenSSL Project 2004 by Richard Levitte
   * (rich...@levitte.org)
   */
--/* Copyright (c) 2004 Kungliga Tekniska H�gskolan
+-/* Copyright (c) 2004 Kungliga Tekniska Högskolan
 +/* Copyright (c) 2004 Kungliga Tekniska Hoegskolan
   * (Royal Institute of Technology, Stockholm, Sweden).
   * All rights reserved.
   *
---- misc/openssl-0.9.8v/ms/do_ms.bat   2009-07-28 14:51:19.000000000 +0200
-+++ build/openssl-0.9.8v/ms/do_ms.bat  2010-03-26 12:19:19.399047300 +0100
+diff -ru openssl.orig/ms/do_ms.bat openssl/ms/do_ms.bat
+--- a/openssl.orig/ms/do_ms.bat        2015-01-15 15:43:14.000000000 +0100
++++ b/openssl/ms/do_ms.bat     2016-03-03 20:31:09.355907935 +0100
 @@ -1,11 +1,11 @@
  
 -perl util\mkfiles.pl >MINFO
 -perl util\mk1mf.pl no-asm VC-WIN32 >ms\nt.mak
 -perl util\mk1mf.pl dll no-asm VC-WIN32 >ms\ntdll.mak
+-if x%OSVERSION% == x goto skipce
+-perl util\mk1mf.pl no-asm VC-CE >ms\ce.mak
+-perl util\mk1mf.pl dll no-asm VC-CE >ms\cedll.mak
+-:skipce
 +%1 util\mkfiles.pl >MINFO
 +if %2 == VC-WIN32 goto not64a
 +perl ms\uplink.pl win64a > ms\uptable.asm
@@ -34,17 +41,14 @@
 +:not64a
 +%1 util\mk1mf.pl no-asm %2 >ms\nt.mak
 +%1 util\mk1mf.pl dll no-asm %2 >ms\ntdll.mak
--if x%OSVERSION% == x goto skipce
--perl util\mk1mf.pl no-asm VC-CE >ms\ce.mak
--perl util\mk1mf.pl dll no-asm VC-CE >ms\cedll.mak
--:skipce
  
 -perl util\mkdef.pl 32 libeay > ms\libeay32.def
 -perl util\mkdef.pl 32 ssleay > ms\ssleay32.def
 +%1 util\mkdef.pl 32 libeay > ms\libeay32.def
 +%1 util\mkdef.pl 32 ssleay > ms\ssleay32.def
---- misc/openssl-0.9.8v/util/mk1mf.pl  2009-09-20 14:46:42.000000000 +0200
-+++ build/openssl-0.9.8v/util/mk1mf.pl 2010-03-26 12:04:20.977172300 +0100
+diff -ru openssl.orig/util/mk1mf.pl openssl/util/mk1mf.pl
+--- a/openssl.orig/util/mk1mf.pl       2016-03-03 20:22:21.043924505 +0100
++++ b/openssl/util/mk1mf.pl    2016-03-03 20:34:45.015901171 +0100
 @@ -163,7 +163,7 @@
  $inc_def="outinc";
  $tmp_def="tmp";
@@ -54,8 +58,8 @@
  $mkdir="-mkdir" unless defined $mkdir;
  
  ($ssl,$crypto)=("ssl","crypto");
-@@ -343,6 +343,11 @@
-       chop;
+@@ -347,6 +347,11 @@
+       s/\s*$//; # was chop, didn't work in mixture of perls for Windows...
  
        ($key,$val)=/^([^=]+)=(.*)/;
 +
@@ -66,7 +70,7 @@
        if ($key eq "RELATIVE_DIRECTORY")
                {
                if ($lib ne "")
-@@ -469,7 +474,7 @@
+@@ -473,7 +478,7 @@
  # Set your compiler options
  PLATFORM=$platform
  CC=$bin_dir${cc}
@@ -75,16 +79,16 @@
  APP_CFLAG=$app_cflag
  LIB_CFLAG=$lib_cflag
  SHLIB_CFLAG=$shl_cflag
-@@ -484,7 +489,7 @@
+@@ -488,7 +493,7 @@
  
- LINK=$link
+ LINK_CMD=$link
  LFLAGS=$lflags
 -RSC=$rsc
 +RSC=$rsc \$(SOLARINC)
  
  # The output directory for everything interesting
  OUT_D=$out_dir
-@@ -665,7 +670,7 @@
+@@ -669,7 +674,7 @@
  printf OUT <<EOF;
  #ifdef $platform_cpp_symbol
    /* auto-generated/updated by util/mk1mf.pl for crypto/cversion.c */
@@ -93,8 +97,9 @@
    #define PLATFORM "$platform"
  EOF
  printf OUT "  #define DATE \"%s\"\n", scalar gmtime();
---- misc/openssl-0.9.8v/util/pl/VC-32.pl       2010-02-04 02:10:24.000000000 
+0100
-+++ build/openssl-0.9.8v/util/pl/VC-32.pl      2010-03-26 12:04:20.977172300 
+0100
+diff -ru openssl.orig/util/pl/VC-32.pl openssl/util/pl/VC-32.pl
+--- a/openssl.orig/util/pl/VC-32.pl    2016-03-01 14:35:53.000000000 +0100
++++ b/openssl/util/pl/VC-32.pl 2016-03-03 21:15:14.083824986 +0100
 @@ -30,7 +30,7 @@
  my $ff = "";
  
@@ -104,6 +109,15 @@
  if ($FLAVOR =~ /WIN64/)
      {
      # Note that we currently don't have /WX on Win64! There is a lot of
+@@ -48,7 +48,7 @@
+     my $f = $shlib || $fips ?' /MD':' /MT';
+     $opt_cflags=$f.' /Ox';
+     $dbg_cflags=$f.'d /Od -DDEBUG -D_DEBUG';
+-    $lflags="/nologo /subsystem:console /opt:ref";
++    $lflags="/nologo /subsystem:console,5.02 /opt:ref";
+ 
+     *::perlasm_compile_target = sub {
+       my ($target,$source,$bname)=@_;
 @@ -114,7 +114,7 @@
      }
  
@@ -132,9 +146,10 @@
      $ff = "/fixed";
 -    $opt_cflags=$f.' /Ox /O2 /Ob2';
 -    $dbg_cflags=$f.'d /Od -DDEBUG -D_DEBUG';
+-    $lflags="/nologo /subsystem:console /opt:ref";
++    $lflags="/nologo /subsystem:console,5.01 /opt:ref";
 +    $opt_cflags=$f.' -Ox -O2 -Ob2';
 +    $dbg_cflags=$f.'d -Od -DDEBUG -D_DEBUG';
-     $lflags="/nologo /subsystem:console /opt:ref";
      }
 -$lib_cflag='/Zl' if (!$shlib);        # remove /DEFAULTLIBs from static lib
 +$lib_cflag='-Zl' if (!$shlib);        # remove /DEFAULTLIBs from static lib
@@ -150,8 +165,9 @@
  
  # EXE linking stuff
  $link="link";
---- build/openssl-0.9.8v/ms/uplink.c
-+++ build/openssl-0.9.8v/ms/uplink.c
+diff -ru openssl.orig/ms/uplink.c openssl/ms/uplink.c
+--- a/openssl.orig/ms/uplink.c 2015-03-19 15:02:02.000000000 +0100
++++ b/openssl/ms/uplink.c      2016-03-03 20:39:19.403892565 +0100
 @@ -1,5 +1,6 @@
  #if (defined(_WIN64) || defined(_WIN32_WCE)) && !defined(UNICODE)
  # define UNICODE
commit 5a607ab52498bc731f7ffe15d6ceeee0de0d9760
Author: Caolán McNamara <caol...@redhat.com>
Date:   Tue Apr 7 11:51:50 2015 +0100

    upgrade to openssl-1.0.2a
    
    and de-ifdef-per-platform the patch makefile so an upgrade attempt on one
    platform tests the patchs applying on all platforms
    
    ubsan.patch.0 was effectively applied upstream while need
    to add http://rt.openssl.org/Ticket/Display.html?id=3650 to build
    under windows
    
    Change-Id: Ieffd9bc3dd861a94a083d8b6b8d4117bba7f527c
    Reviewed-on: https://gerrit.libreoffice.org/15183
    Tested-by: Jenkins <c...@libreoffice.org>
    Reviewed-by: Caolán McNamara <caol...@redhat.com>
    Tested-by: Caolán McNamara <caol...@redhat.com>

diff --git a/external/openssl/UnpackedTarball_openssl.mk 
b/external/openssl/UnpackedTarball_openssl.mk
index eb521bc196b9..d36aba5ebdd0 100644
--- a/external/openssl/UnpackedTarball_openssl.mk
+++ b/external/openssl/UnpackedTarball_openssl.mk
@@ -22,33 +22,13 @@ $(eval $(call gb_UnpackedTarball_set_pre_action,openssl,\
 endif
 
 $(eval $(call gb_UnpackedTarball_add_patches,openssl,\
-       external/openssl/CVE-2013-6449.patch \
-       external/openssl/CVE-2013-6450.patch \
-       external/openssl/CVE-2013-4353.patch \
-       external/openssl/CVE-2014-0160.patch \
-       external/openssl/CVE-2010-5298.patch \
-       external/openssl/CVE-2014-0195.patch \
-       external/openssl/CVE-2014-0198.patch \
-       external/openssl/CVE-2014-0221.patch \
-       external/openssl/CVE-2014-0224.patch \
-       external/openssl/CVE-2014-3470.patch \
-       external/openssl/CVE-2014-3505.patch \
-       external/openssl/CVE-2014-3506.patch \
-       external/openssl/CVE-2014-3507.patch \
-       external/openssl/CVE-2014-3508.patch \
-       external/openssl/CVE-2014-3509.patch \
-       external/openssl/CVE-2014-3510.patch \
-       external/openssl/CVE-2014-3511.patch \
-       external/openssl/CVE-2014-3513.patch \
-       external/openssl/CVE-2014-3567.patch \
-       external/openssl/CVE-2014-3566.patch \
-       $(if $(filter LINUX FREEBSD 
ANDROID,$(OS)),external/openssl/openssllnx.patch) \
-       $(if $(filter WNTGCC,$(OS)$(COM)),external/openssl/opensslmingw.patch) \
-       $(if $(filter MSC,$(COM)),external/openssl/opensslwnt.patch) \
-       $(if $(filter 
MSC,$(COM)),external/openssl/openssl-1.0.1g-msvc2012-winxp.patch.1) \
-       $(if $(filter 
MSC,$(COM)),external/openssl/openssl-1.0.1h-win64.patch.1) \
-       $(if $(filter SOLARIS,$(OS)),external/openssl/opensslsol.patch) \
-       $(if $(filter IOS,$(OS)),external/openssl/opensslios.patch) \
+       external/openssl/openssllnx.patch \
+       external/openssl/opensslwnt.patch \
+       external/openssl/openssl-1.0.1g-msvc2012-winxp.patch.1 \
+       external/openssl/openssl-1.0.1h-win64.patch.1 \
+       external/openssl/opensslsol.patch \
+       external/openssl/opensslios.patch \
+       external/openssl/openssl-3650-masm.patch.1 \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/external/openssl/openssl-1.0.1g-msvc2012-winxp.patch.1 
b/external/openssl/openssl-1.0.1g-msvc2012-winxp.patch.1
index 611ffbcd67f3..de9e6fc09f4a 100644
--- a/external/openssl/openssl-1.0.1g-msvc2012-winxp.patch.1
+++ b/external/openssl/openssl-1.0.1g-msvc2012-winxp.patch.1
@@ -1,7 +1,7 @@
 --- openssl.org/util/pl/VC-32.pl       2014-05-18 23:41:39.336594400 +0200
 +++ openssl/util/pl/VC-32.pl   2014-05-18 23:47:40.055279300 +0200
-@@ -49,7 +49,7 @@
-     $lib_cflag='/Zl' if (!$shlib);    # remove /DEFAULTLIBs from static lib
+@@ -48,7 +48,7 @@
+     my $f = $shlib || $fips ?' /MD':' /MT';
      $opt_cflags=$f.' /Ox';
      $dbg_cflags=$f.'d /Od -DDEBUG -D_DEBUG';
 -    $lflags="/nologo /subsystem:console /opt:ref";
@@ -9,12 +9,12 @@
  
      *::perlasm_compile_target = sub {
        my ($target,$source,$bname)=@_;
-@@ -131,7 +131,7 @@
+@@ -135,7 +135,7 @@
      $ff = "/fixed";
      $opt_cflags=$f.' -Ox -O2 -Ob2';
      $dbg_cflags=$f.'d -Od -DDEBUG -D_DEBUG';
 -    $lflags="/nologo /subsystem:console /opt:ref";
 +    $lflags="/nologo /subsystem:console,5.01 /opt:ref";
      }
+ $lib_cflag='-Zl' if (!$shlib);        # remove /DEFAULTLIBs from static lib
  $mlflags='';
- 
diff --git a/external/openssl/openssl-3650-masm.patch.1 
b/external/openssl/openssl-3650-masm.patch.1
new file mode 100644
index 000000000000..97f1eb6446c3
--- /dev/null
+++ b/external/openssl/openssl-3650-masm.patch.1
@@ -0,0 +1,35 @@
+diff --git a/crypto/perlasm/x86masm.pl b/crypto/perlasm/x86masm.pl
+index 1741342..917d0f8 100644
+--- a/crypto/perlasm/x86masm.pl
++++ b/crypto/perlasm/x86masm.pl
+@@ -18,10 +18,10 @@ sub ::generic
+ 
+     if ($opcode =~ /lea/ && @arg[1] =~ s/.*PTR\s+(\(.*\))$/OFFSET $1/)        
# no []
+     { $opcode="mov";  }
+-    elsif ($opcode !~ /movq/)
++    elsif ($opcode !~ /mov[dq]$/)
+     { # fix xmm references
+-      $arg[0] =~ s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i if 
($arg[1]=~/\bxmm[0-7]\b/i);
+-      $arg[1] =~ s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i if 
($arg[0]=~/\bxmm[0-7]\b/i);
++      $arg[0] =~ s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i if 
($arg[-1]=~/\bxmm[0-7]\b/i);
++      $arg[-1] =~ s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i if 
($arg[0]=~/\bxmm[0-7]\b/i);
+     }
+ 
+     &::emit($opcode,@arg);
+@@ -160,13 +160,13 @@ sub ::public_label
+ {   push(@out,"PUBLIC\t".&::LABEL($_[0],$nmdecor.$_[0])."\n");   }
+ 
+ sub ::data_byte
+-{   push(@out,("DB\t").join(',',@_)."\n");    }
++{   push(@out,("DB\t").join(',',splice(@_,0,16))."\n") while(@_);     }
+ 
+ sub ::data_short
+-{   push(@out,("DW\t").join(',',@_)."\n");    }
++{   push(@out,("DW\t").join(',',splice(@_,0,8))."\n") while(@_);      }
+ 
+ sub ::data_word
+-{   push(@out,("DD\t").join(',',@_)."\n");    }
++{   push(@out,("DD\t").join(',',splice(@_,0,4))."\n") while(@_);      }
+ 
+ sub ::align
+ {   push(@out,"ALIGN\t$_[0]\n");      }
diff --git a/external/openssl/opensslmingw.patch 
b/external/openssl/opensslmingw.patch
deleted file mode 100644
index e0dc96029d6b..000000000000
--- a/external/openssl/opensslmingw.patch
+++ /dev/null
@@ -1,109 +0,0 @@
---- misc/openssl-0.9.8v/Makefile.shared        2008-09-17 17:56:40.000000000 
+0200
-+++ misc/build/openssl-0.9.8v/Makefile.shared  2009-03-30 11:52:53.684538000 
+0200
-@@ -254,13 +254,17 @@
-       base=-Wl,--enable-auto-image-base; \
-       if expr $(PLATFORM) : 'mingw' > /dev/null; then \
-               SHLIB=$(LIBNAME)eay32; \
--              base=;  [ $(LIBNAME) = "crypto" ] && 
base=-Wl,--image-base,0x63000000; \
-+              base=;  \
-+                if test $(LIBNAME) = "crypto"; then \
-+                        SHLIB=libeay32; \
-+                        base=-Wl,--image-base,0x63000000; \
-+                fi; \
-       fi; \
-       SHLIB_SUFFIX=.dll; \
--      SHLIB_SOVER=-$(LIBVERSION); \
-+      SHLIB_SOVER=; \
-       ALLSYMSFLAGS='-Wl,--whole-archive'; \
-       NOALLSYMSFLAGS='-Wl,--no-whole-archive'; \
--      SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared $$base -Wl,-Bsymbolic 
-Wl,--out-implib,lib$(LIBNAME).dll.a"; \
-+      SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared $$base -Wl,-Bsymbolic 
-Wl,--export-all-symbols -Wl,--out-implib,lib$(LIBNAME).dll.a"; \
-       [ -f apps/$$SHLIB$$SHLIB_SUFFIX ] && rm apps/$$SHLIB$$SHLIB_SUFFIX; \
-       [ -f test/$$SHLIB$$SHLIB_SUFFIX ] && rm test/$$SHLIB$$SHLIB_SUFFIX; \
-       $(LINK_SO_A) || exit 1; \
---- misc/openssl-0.9.8v/e_os2.h        2005-12-19 03:57:07.000000000 +0900
-+++ misc/build/openssl-0.9.8v/e_os2.h  2009-04-04 23:07:15.324250000 +0900
-@@ -264,7 +264,7 @@
- # define OPENSSL_IMPLEMENT_GLOBAL(type,name)                       \
-       extern type _hide_##name;                                    \
-       type *_shadow_##name(void) { return &_hide_##name; }         \
--      static type _hide_##name
-+      type _hide_##name
- # define OPENSSL_DECLARE_GLOBAL(type,name) type *_shadow_##name(void)
- # define OPENSSL_GLOBAL_REF(name) (*(_shadow_##name()))
- #else
---- misc/openssl-0.9.8v/ms/mingw32.bat 2006-05-05 15:19:32.000000000 +0200
-+++ misc/build/openssl-0.9.8v/ms/mingw32.bat   2009-03-30 11:54:10.000000000 
+0200
-@@ -79,15 +79,41 @@
- rem copy ms\tlhelp32.h outinc
- 
- echo Building the libraries
--mingw32-make -f ms/mingw32a.mak
-+make -f ms/mingw32a.mak
- if errorlevel 1 goto end
- 
- echo Generating the DLLs and input libraries
--dllwrap --dllname libeay32.dll --output-lib out/libeay32.a --def 
ms/libeay32.def out/libcrypto.a -lwsock32 -lgdi32
-+mv out/libcrypto.a out/libcrypto_static.a
-+mv out/libssl.a out/libssl_static.a
-+dlltool --dllname libeay32.dll --output-lib out/libcrypto.a --input-def 
ms/libeay32.def
- if errorlevel 1 goto end
--dllwrap --dllname libssl32.dll --output-lib out/libssl32.a --def 
ms/ssleay32.def out/libssl.a out/libeay32.a
-+gcc --shared --enable-pseudo-reloc -Wl,-Map,out/libeay32.map ms/libeay32.def 
-o out/libeay32.dll out/libcrypto_static.a -lwsock32 -lgdi32
- if errorlevel 1 goto end
-+dlltool --dllname ssleay32.dll --output-lib out/libssl.a --input-def 
ms/ssleay32.def
-+if errorlevel 1 goto end
-+if "%MINGW_SHARED_GXXLIB%"=="YES" goto shared_gxxlib
-+if "%MINGW_SHARED_GCCLIB%"=="YES" goto shared_gcclib
-+gcc --shared --enable-pseudo-reloc -Wl,-Map,out/libeay32.map ms/libeay32.def 
-o out/libeay32.dll out/libcrypto_static.a -lwsock32 -lgdi32 
-+if errorlevel 1 goto end
-+gcc --shared --enable-pseudo-reloc -Wl,-Map,out/ssleay32.map -Lout 
ms/ssleay32.def -o out/ssleay32.dll out/libssl_static.a -lcrypto 
-+if errorlevel 1 goto end
-+goto finished
-+
-+:shared_gcclib
-+gcc --shared -shared-libgcc --enable-pseudo-reloc -Wl,-Map,out/libeay32.map 
ms/libeay32.def -o out/libeay32.dll out/libcrypto_static.a -lwsock32 -lgdi32 
-+if errorlevel 1 goto end
-+gcc --shared -shared-libgcc --enable-pseudo-reloc -Wl,-Map,out/ssleay32.map 
-Lout ms/ssleay32.def -o out/ssleay32.dll out/libssl_static.a -lcrypto 
-+if errorlevel 1 goto end
-+goto finished
-+
-+:shared_gxxlib
-+gcc --shared -shared-libgcc --enable-pseudo-reloc -Wl,-Map,out/libeay32.map 
ms/libeay32.def -o out/libeay32.dll out/libcrypto_static.a -lwsock32 -lgdi32 
%MINGW_SHARED_LIBSTDSPP%
-+if errorlevel 1 goto end
-+gcc --shared -shared-libgcc --enable-pseudo-reloc -Wl,-Map,out/ssleay32.map 
-Lout ms/ssleay32.def -o out/ssleay32.dll out/libssl_static.a -lcrypto 
%MINGW_SHARED_LIBSTDSPP%
-+if errorlevel 1 goto end
-+goto finished
- 
-+:finished
- echo Done compiling OpenSSL
- 
- :end
---- misc/openssl-0.9.8v/util/pl/Mingw32.pl     2006-05-05 15:19:34.000000000 
+0200
-+++ misc/build/openssl-0.9.8v/util/pl/Mingw32.pl       2009-03-30 
11:55:04.000000000 +0200
-@@ -6,11 +6,11 @@
- $o='/';
- $cp='cp';
- $rm='rm -f';
--$mkdir='gmkdir';
-+#$mkdir='gmkdir';
- 
--$o='\\';
--$cp='copy';
--$rm='del';
-+#$o='\\';
-+#$cp='copy';
-+#$rm='del';
- $mkdir='mkdir';
- 
- # C compiler stuff
-@@ -87,7 +87,8 @@
-       ($Name=$name) =~ tr/a-z/A-Z/;
- 
-       $ret.="$target: \$(${Name}OBJ)\n";
--      $ret.="\tif exist $target \$(RM) $target\n";
-+    $ret.="\t\$(RM) $target\n";
-+#     $ret.="\tif exist $target \$(RM) $target\n";
-       $ret.="\t\$(MKLIB) $target \$(${Name}OBJ)\n";
-       $ret.="\t\$(RANLIB) $target\n\n";
-       }
diff --git a/external/openssl/opensslsol.patch 
b/external/openssl/opensslsol.patch
index a22dc05cee39..ef70130aab9b 100644
--- a/external/openssl/opensslsol.patch
+++ b/external/openssl/opensslsol.patch
@@ -1,81 +1,33 @@
 --- misc/openssl-0.9.8v/Configure      Mon Nov  9 15:14:26 2009
 +++ build/openssl-0.9.8v/Configure     Fri Mar 26 16:01:32 2010
-@@ -212,8 +212,8 @@
- "solaris64-x86_64-gcc","gcc:-m64 -O3 -Wall -DL_ENDIAN 
-DMD32_REG_T=int::-D_REENTRANT::-lsocket -lnsl -ldl:SIXTY_FOUR_BIT_LONG 
RC4_CHUNK DES_INT DES_UNROLL:${x86_64_asm}:dlfcn:solaris-shared:-fPIC:-m64 
-shared -static-libgcc:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+@@ -228,8 +228,8 @@
+ "solaris64-x86_64-gcc","gcc:-m64 -O3 -Wall -DL_ENDIAN::-D_REENTRANT::-lsocket 
-lnsl -ldl:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT 
DES_UNROLL:${x86_64_asm}:elf:dlfcn:solaris-shared:-fPIC:-m64 -shared 
-static-libgcc:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR):::/64",
   
  #### Solaris x86 with Sun C setups
--"solaris-x86-cc","cc:-fast -O -Xa::-D_REENTRANT::-lsocket -lnsl -ldl:BN_LLONG 
RC4_CHAR RC4_CHUNK DES_PTR DES_UNROLL 
BF_PTR:${no_asm}:dlfcn:solaris-shared:-KPIC:-G -dy -z 
text:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
--"solaris64-x86_64-cc","cc:-fast -xarch=amd64 -xstrconst -Xa 
-DL_ENDIAN::-D_REENTRANT::-lsocket -lnsl -ldl:SIXTY_FOUR_BIT_LONG RC4_CHUNK 
DES_INT DES_UNROLL:${x86_64_asm}:dlfcn:solaris-shared:-KPIC:-xarch=amd64 -G -dy 
-z text:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
-+"solaris-x86-cc","cc:-O -Xa::-D_REENTRANT::-lsocket -lnsl -ldl:BN_LLONG 
RC4_CHAR RC4_CHUNK DES_PTR DES_UNROLL 
BF_PTR:${no_asm}:dlfcn:solaris-shared:-KPIC:-G -dy -z 
text:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
-+"solaris64-x86_64-cc","cc:-xarch=amd64 -xstrconst -Xa 
-DL_ENDIAN::-D_REENTRANT::-lsocket -lnsl -ldl:SIXTY_FOUR_BIT_LONG RC4_CHUNK 
BF_PTR2 DES_INT 
DES_UNROLL:${x86_64_asm}:dlfcn:solaris-shared:-KPIC:-xarch=amd64 -G -dy -z 
text:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+-"solaris-x86-cc","cc:-fast -xarch=generic -O -Xa::-D_REENTRANT::-lsocket 
-lnsl -ldl:BN_LLONG RC4_CHAR RC4_CHUNK DES_PTR DES_UNROLL 
BF_PTR:${no_asm}:dlfcn:solaris-shared:-KPIC:-G -dy -z 
text:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+-"solaris64-x86_64-cc","cc:-fast -xarch=amd64 -xstrconst -Xa 
-DL_ENDIAN::-D_REENTRANT::-lsocket -lnsl -ldl:SIXTY_FOUR_BIT_LONG RC4_CHUNK 
DES_INT DES_UNROLL:${x86_64_asm}:elf:dlfcn:solaris-shared:-KPIC:-xarch=amd64 -G 
-dy -z text:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR):::/64",
++"solaris-x86-cc","cc:-xarch=generic -O -Xa::-D_REENTRANT::-lsocket -lnsl 
-ldl:BN_LLONG RC4_CHAR RC4_CHUNK DES_PTR DES_UNROLL 
BF_PTR:${no_asm}:dlfcn:solaris-shared:-KPIC:-G -dy -z 
text:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
++"solaris64-x86_64-cc","cc:-xarch=amd64 -xstrconst -Xa 
-DL_ENDIAN::-D_REENTRANT::-lsocket -lnsl -ldl:SIXTY_FOUR_BIT_LONG RC4_CHUNK 
BF_PTR2 DES_INT 
DES_UNROLL:${x86_64_asm}:elf:dlfcn:solaris-shared:-KPIC:-xarch=amd64 -G -dy -z 
text:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR):::/64",
  
  #### SPARC Solaris with GNU C setups
  "solaris-sparcv7-gcc","gcc:-O3 -fomit-frame-pointer -Wall -DB_ENDIAN 
-DBN_DIV2W::-D_REENTRANT::-lsocket -lnsl -ldl:BN_LLONG RC4_CHAR RC4_CHUNK 
DES_UNROLL 
BF_PTR:${no_asm}:dlfcn:solaris-shared:-fPIC:-shared:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
 --- misc/openssl-0.9.8v/Makefile.shared        Wed Sep 17 17:56:40 2008
 +++ build/openssl-0.9.8v/Makefile.shared       Fri Mar 26 16:04:41 2010
-@@ -93,7 +93,7 @@
+@@ -95,7 +95,7 @@
      LDCMD="$${LDCMD:-$(CC)}"; LDFLAGS="$${LDFLAGS:-$(CFLAGS)}"; \
-     LIBPATH=`for x in $$LIBDEPS; do if echo $$x | grep '^ *-L' > /dev/null 
2>&1; then echo $$x | sed -e 's/^ *-L//'; fi; done | uniq`; \
+     LIBPATH=`for x in $$LIBDEPS; do echo $$x; done | sed -e 's/^ *-L//;t' -e 
d | uniq`; \
      LIBPATH=`echo $$LIBPATH | sed -e 's/ /:/g'`; \
 -    LD_LIBRARY_PATH=$$LIBPATH:$$LD_LIBRARY_PATH \
 +    LD_LIBRARY_PATH=$$LD_LIBRARY_PATH \
      $${LDCMD} $${LDFLAGS} -o $${APPNAME:=$(APPNAME)} $(OBJECTS) $${LIBDEPS} )
  
  LINK_SO=      \
-@@ -103,7 +103,7 @@
+@@ -105,7 +105,7 @@
      SHAREDFLAGS="$${SHAREDFLAGS:-$(CFLAGS) $(SHARED_LDFLAGS)}"; \
-     LIBPATH=`for x in $$LIBDEPS; do if echo $$x | grep '^ *-L' > /dev/null 
2>&1; then echo $$x | sed -e 's/^ *-L//'; fi; done | uniq`; \
+     LIBPATH=`for x in $$LIBDEPS; do echo $$x; done | sed -e 's/^ *-L//;t' -e 
d | uniq`; \
      LIBPATH=`echo $$LIBPATH | sed -e 's/ /:/g'`; \
 -    LD_LIBRARY_PATH=$$LIBPATH:$$LD_LIBRARY_PATH \
 +    LD_LIBRARY_PATH=$$LD_LIBRARY_PATH \
      $${SHAREDCMD} $${SHAREDFLAGS} \
        -o $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX \
        $$ALLSYMSFLAGS $$SHOBJECTS $$NOALLSYMSFLAGS $$LIBDEPS \
---- misc/openssl-0.9.8v/config Tue Mar  9 18:08:24 2010
-+++ build/openssl-0.9.8v/config        Fri Mar 26 16:07:55 2010
-@@ -399,28 +399,25 @@
- # this is where the translation occurs into SSLeay terms
- # ---------------------------------------------------------------------------
- 
--GCCVER=`(gcc -dumpversion) 2>/dev/null`
--if [ "$GCCVER" != "" ]; then
--  # then strip off whatever prefix egcs prepends the number with...
--  # Hopefully, this will work for any future prefixes as well.
--  GCCVER=`echo $GCCVER | LC_ALL=C sed 's/^[a-zA-Z]*\-//'`
--  # Since gcc 3.1 gcc --version behaviour has changed.  gcc -dumpversion
--  # does give us what we want though, so we use that.  We just just the
--  # major and minor version numbers.
--  # peak single digit before and after first dot, e.g. 2.95.1 gives 29
--  GCCVER=`echo $GCCVER | sed 's/\([0-9]\)\.\([0-9]\).*/\1\2/'`
-+if [ -z "$CC" ];then
-+  GCCVER=`(gcc -dumpversion) 2>/dev/null`
-+ if [ "$GCCVER" != "" ]; then
-+   CC=gcc
-+    # then strip off whatever prefix egcs prepends the number with...
-+    # Hopefully, this will work for any future prefixes as well.
-+    GCCVER=`echo $GCCVER | LC_ALL=C sed 's/^[a-zA-Z]*\-//'`
-+    # Since gcc 3.1 gcc --version behaviour has changed.  gcc -dumpversion
-+    # does give us what we want though, so we use that.  We just just the
-+    # major and minor version numbers.
-+    # peak single digit before and after first dot, e.g. 2.95.1 gives 29
-+    GCCVER=`echo $GCCVER | sed 's/\([0-9]\)\.\([0-9]\).*/\1\2/'`
-+ else
-+   CC=cc
-+ fi
-+else
-+    CC=`echo $CC | sed 's/^[^ ]*\/\(..\).*/\1/'`
- fi
- 
--# Only set CC if not supplied already
--if [ -z "$CC" ]; then
--# figure out if gcc is available and if so we use it otherwise
--# we fallback to whatever cc does on the system
--  if [ "$GCCVER" != "" ]; then
--    CC=gcc
--  else
--    CC=cc
--  fi
--fi
- GCCVER=${GCCVER:-0}
- if [ "$SYSTEM" = "HP-UX" ];then
-   # By default gcc is a ILP32 compiler (with long long == 64).
diff --git a/external/openssl/opensslwnt.patch 
b/external/openssl/opensslwnt.patch
index 5be9c958a37a..e033d25f602f 100644
--- a/external/openssl/opensslwnt.patch
+++ b/external/openssl/opensslwnt.patch
@@ -1,8 +1,8 @@
 --- misc/openssl-0.9.8v/crypto/x509v3/v3_pci.c 2007-03-05 01:06:47.000000000 
+0100
 +++ build/openssl-0.9.8v/crypto/x509v3/v3_pci.c        2010-03-26 
12:04:20.961547300 +0100
-@@ -2,7 +2,7 @@
- /* Contributed to the OpenSSL Project 2004
-  * by Richard Levitte (rich...@levitte.org)
+@@ -3,7 +3,7 @@
+  * Contributed to the OpenSSL Project 2004 by Richard Levitte
+  * (rich...@levitte.org)
   */
 -/* Copyright (c) 2004 Kungliga Tekniska H�gskolan
 +/* Copyright (c) 2004 Kungliga Tekniska Hoegskolan
@@ -11,9 +11,9 @@
   *
 --- misc/openssl-0.9.8v/crypto/x509v3/v3_pcia.c        2004-12-28 
01:21:33.000000000 +0100
 +++ build/openssl-0.9.8v/crypto/x509v3/v3_pcia.c       2010-03-26 
12:04:20.961547300 +0100
-@@ -2,7 +2,7 @@
- /* Contributed to the OpenSSL Project 2004
-  * by Richard Levitte (rich...@levitte.org)
+@@ -3,7 +3,7 @@
+  * Contributed to the OpenSSL Project 2004 by Richard Levitte
+  * (rich...@levitte.org)
   */
 -/* Copyright (c) 2004 Kungliga Tekniska H�gskolan
 +/* Copyright (c) 2004 Kungliga Tekniska Hoegskolan
@@ -45,7 +45,7 @@
 +%1 util\mkdef.pl 32 ssleay > ms\ssleay32.def
 --- misc/openssl-0.9.8v/util/mk1mf.pl  2009-09-20 14:46:42.000000000 +0200
 +++ build/openssl-0.9.8v/util/mk1mf.pl 2010-03-26 12:04:20.977172300 +0100
-@@ -128,7 +128,7 @@
+@@ -163,7 +163,7 @@
  $inc_def="outinc";
  $tmp_def="tmp";
  
@@ -54,7 +54,7 @@
  $mkdir="-mkdir" unless defined $mkdir;
  
  ($ssl,$crypto)=("ssl","crypto");
-@@ -290,6 +290,11 @@
+@@ -343,6 +343,11 @@
        chop;
  
        ($key,$val)=/^([^=]+)=(.*)/;
@@ -66,7 +66,7 @@
        if ($key eq "RELATIVE_DIRECTORY")
                {
                if ($lib ne "")
-@@ -529,7 +529,7 @@
+@@ -469,7 +474,7 @@
  # Set your compiler options
  PLATFORM=$platform
  CC=$bin_dir${cc}
@@ -75,27 +75,27 @@
  APP_CFLAG=$app_cflag
  LIB_CFLAG=$lib_cflag
  SHLIB_CFLAG=$shl_cflag
-@@ -544,7 +544,7 @@
+@@ -484,7 +489,7 @@
  
  LINK=$link
  LFLAGS=$lflags
 -RSC=$rsc
 +RSC=$rsc \$(SOLARINC)
  
- # The output directory for everything intersting
+ # The output directory for everything interesting
  OUT_D=$out_dir
-@@ -730,7 +735,7 @@
+@@ -665,7 +670,7 @@
  printf OUT <<EOF;
  #ifdef $platform_cpp_symbol
    /* auto-generated/updated by util/mk1mf.pl for crypto/cversion.c */
--  #define CFLAGS "$cc $cflags"
-+  #define CFLAGS "$cflags"
+-  #define CFLAGS "compiler: $cc $cflags"
++  #define CFLAGS "compiler: $cflags"
    #define PLATFORM "$platform"
  EOF
  printf OUT "  #define DATE \"%s\"\n", scalar gmtime();
 --- misc/openssl-0.9.8v/util/pl/VC-32.pl       2010-02-04 02:10:24.000000000 
+0100
 +++ build/openssl-0.9.8v/util/pl/VC-32.pl      2010-03-26 12:04:20.977172300 
+0100
-@@ -32,7 +32,7 @@
+@@ -30,7 +30,7 @@
  my $ff = "";
  
  # C compiler stuff
@@ -104,29 +104,31 @@
  if ($FLAVOR =~ /WIN64/)
      {
      # Note that we currently don't have /WX on Win64! There is a lot of
-@@ -103,22 +103,22 @@
+@@ -114,7 +114,7 @@
      }
  
-     $cc='$(CC)';
+     $cc=($ENV{CC} or "cl");
 -    $base_cflags=' /W3 /WX /GF /Gy /nologo -DUNICODE -D_UNICODE 
-DOPENSSL_SYSNAME_WINCE -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -DDSO_WIN32 -DNO_CHMOD 
-DOPENSSL_SMALL_FOOTPRINT';
 +    $base_cflags=' -W3 -GF -Gy -nologo -DUNICODE -D_UNICODE 
-DOPENSSL_SYSNAME_WINCE -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -DDSO_WIN32 -DNO_CHMOD 
-DOPENSSL_SMALL_FOOTPRINT';
      $base_cflags.=" $wcecdefs";
      $base_cflags.=' -I$(WCECOMPAT)/include'           if 
(defined($ENV{'WCECOMPAT'}));
      $base_cflags.=' -I$(PORTSDK_LIBPATH)/../../include'       if 
(defined($ENV{'PORTSDK_LIBPATH'}));
--    $opt_cflags=' /MC /O1i';  # optimize for space, but with intrinsics...
--    $dbg_cflags=' /MC /Od -DDEBUG -D_DEBUG';
-+    $opt_cflags=' -MC -O1i';  # optimize for space, but with intrinsics...
-+    $dbg_cflags=' -MC -Od -DDEBUG -D_DEBUG';
+@@ -123,20 +123,21 @@
+     } else {
+       $base_cflags.=' /MC';
+     }
+-    $opt_cflags=' /O1i';      # optimize for space, but with intrinsics...
+-    $dbg_cflags=' /Od -DDEBUG -D_DEBUG';
++    $opt_cflags=' -O1i';   # optimize for space, but with intrinsics...
++    $dbg_cflags=' -Od -DDEBUG -D_DEBUG';
++
      $lflags="/nologo /opt:ref $wcelflag";
      }
  else  # Win32
      {
--    $base_cflags= " $mf_cflag";
-+    $base_cflags= " $mf_cflag";
+     $base_cflags= " $mf_cflag";
 -    my $f = $shlib || $fips ?' /MD':' /MT';
--    $lib_cflag='/Zl' if (!$shlib);    # remove /DEFAULTLIBs from static lib
 +    my $f = $shlib || $fips ? (($ENV{MSVC_USE_DEBUG_RUNTIME} eq "TRUE") ? ' 
-MDd' : ' -MD' ):' -MT';
-+    $lib_cflag='-Zl' if (!$shlib);    # remove /DEFAULTLIBs from static lib
      $ff = "/fixed";
 -    $opt_cflags=$f.' /Ox /O2 /Ob2';
 -    $dbg_cflags=$f.'d /Od -DDEBUG -D_DEBUG';
@@ -134,8 +136,12 @@
 +    $dbg_cflags=$f.'d -Od -DDEBUG -D_DEBUG';
      $lflags="/nologo /subsystem:console /opt:ref";
      }
+-$lib_cflag='/Zl' if (!$shlib);        # remove /DEFAULTLIBs from static lib
++$lib_cflag='-Zl' if (!$shlib);        # remove /DEFAULTLIBs from static lib
  $mlflags='';
-@@ -138,7 +138,7 @@
+ 
+ $out_def ="out32";    $out_def.="dll"                 if ($shlib);
+@@ -161,7 +162,7 @@
  
  $obj='.obj';
  $asm_suffix='.asm';
@@ -148,8 +154,8 @@
 +++ build/openssl-0.9.8v/ms/uplink.c
 @@ -1,5 +1,6 @@
  #if (defined(_WIN64) || defined(_WIN32_WCE)) && !defined(UNICODE)
- #define UNICODE
-+#define _CRT_NON_CONFORMING_SWPRINTFS
+ # define UNICODE
++# define _CRT_NON_CONFORMING_SWPRINTFS
  #endif
  #if defined(UNICODE) && !defined(_UNICODE)
- #define _UNICODE
+ # define _UNICODE
commit 7c908cbb75eac06f90bb9516fb021a368957969c
Author: Thomas Arnhold <tho...@arnhold.org>
Date:   Sun Aug 10 04:08:27 2014 +0200

    win64: make openssl work
    
    fix windows style path separator to unix style, needed for cygwin.
    
    Change-Id: I4de78d6901378644857c28a59467b59ef886f47b
    Reviewed-on: https://gerrit.libreoffice.org/10855
    Reviewed-by: Thomas Arnhold <tho...@arnhold.org>
    Tested-by: Thomas Arnhold <tho...@arnhold.org>

diff --git a/external/openssl/UnpackedTarball_openssl.mk 
b/external/openssl/UnpackedTarball_openssl.mk
index 23ba0e7fcf16..eb521bc196b9 100644
--- a/external/openssl/UnpackedTarball_openssl.mk
+++ b/external/openssl/UnpackedTarball_openssl.mk
@@ -46,6 +46,7 @@ $(eval $(call gb_UnpackedTarball_add_patches,openssl,\
        $(if $(filter WNTGCC,$(OS)$(COM)),external/openssl/opensslmingw.patch) \
        $(if $(filter MSC,$(COM)),external/openssl/opensslwnt.patch) \
        $(if $(filter 
MSC,$(COM)),external/openssl/openssl-1.0.1g-msvc2012-winxp.patch.1) \
+       $(if $(filter 
MSC,$(COM)),external/openssl/openssl-1.0.1h-win64.patch.1) \
        $(if $(filter SOLARIS,$(OS)),external/openssl/opensslsol.patch) \
        $(if $(filter IOS,$(OS)),external/openssl/opensslios.patch) \
 ))
diff --git a/external/openssl/openssl-1.0.1h-win64.patch.1 
b/external/openssl/openssl-1.0.1h-win64.patch.1
new file mode 100644
index 000000000000..aea914633ebb
--- /dev/null
+++ b/external/openssl/openssl-1.0.1h-win64.patch.1
@@ -0,0 +1,47 @@
+diff --git a/ms/do_win64a.bat b/ms/do_win64a.bat
+index 8768dc6..6772390 100755
+--- a/ms/do_win64a.bat
++++ b/ms/do_win64a.bat
+@@ -1,19 +1,19 @@
+-perl util\mkfiles.pl >MINFO
++perl util/mkfiles.pl >MINFO
+ 
+ cmd /c "nasm -f win64 -v" >NUL 2>&1
+ if %errorlevel% neq 0 goto ml64
+ 
+-perl ms\uplink-x86_64.pl nasm > ms\uptable.asm
+-nasm -f win64 -o ms\uptable.obj ms\uptable.asm
++perl ms/uplink-x86_64.pl nasm > ms/uptable.asm
++nasm -f win64 -o ms/uptable.obj ms/uptable.asm
+ goto proceed
+ 
+ :ml64
+-perl ms\uplink-x86_64.pl masm > ms\uptable.asm
+-ml64 -c -Foms\uptable.obj ms\uptable.asm
++perl ms/uplink-x86_64.pl masm > ms/uptable.asm
++ml64 -c -Foms/uptable.obj ms/uptable.asm
+ 
+ :proceed
+-perl util\mk1mf.pl VC-WIN64A >ms\nt.mak
+-perl util\mk1mf.pl dll VC-WIN64A >ms\ntdll.mak
++perl util/mk1mf.pl VC-WIN64A >ms/nt.mak
++perl util/mk1mf.pl dll VC-WIN64A >ms/ntdll.mak
+ 
+-perl util\mkdef.pl 32 libeay > ms\libeay32.def
+-perl util\mkdef.pl 32 ssleay > ms\ssleay32.def
++perl util/mkdef.pl 32 libeay > ms/libeay32.def
++perl util/mkdef.pl 32 ssleay > ms/ssleay32.def
+diff --git a/util/mk1mf.pl b/util/mk1mf.pl
+index 72fa089..d98def1 100755
+--- a/util/mk1mf.pl
++++ b/util/mk1mf.pl
+@@ -233,6 +233,9 @@ else
+       $cflags.=' -DTERMIO';
+       }
+ 
++# force unix style path separator
++${o} = "/";
++
+ $fipsdir =~ s/\//${o}/g;
+ 
+ $out_dir=(defined($VARS{'OUT'}))?$VARS{'OUT'}:$out_def.($debug?".dbg":"");
commit eb5618e0455de320308736f0fd567b2bff0b6379
Author: Michael Stahl <mst...@redhat.com>
Date:   Mon Jun 2 23:30:03 2014 +0200

    openssl: stop (ab)using fix_end_of_line to break symlinks
    
    Win32 make has problems because the command line gets too long.
    
    Change-Id: I157b7b2b61353b158b1a3f412331e54aafec206c

diff --git a/external/openssl/UnpackedTarball_openssl.mk 
b/external/openssl/UnpackedTarball_openssl.mk
index 681049f9542e..23ba0e7fcf16 100644
--- a/external/openssl/UnpackedTarball_openssl.mk
+++ b/external/openssl/UnpackedTarball_openssl.mk
@@ -11,84 +11,15 @@ $(eval $(call gb_UnpackedTarball_UnpackedTarball,openssl))
 
 $(eval $(call 
gb_UnpackedTarball_set_tarball,openssl,$(OPENSSL_TARBALL),,openssl))
 
-# hack to fix symlinks with MSVC
-$(eval $(call gb_UnpackedTarball_fix_end_of_line,openssl,\
-       include/openssl/aes.h \
-       include/openssl/asn1.h \
-       include/openssl/asn1_mac.h \
-       include/openssl/asn1t.h \
-       include/openssl/bio.h \
-       include/openssl/blowfish.h \
-       include/openssl/bn.h \
-       include/openssl/buffer.h \
-       include/openssl/camellia.h \
-       include/openssl/cast.h \
-       include/openssl/cmac.h \
-       include/openssl/cms.h \
-       include/openssl/comp.h \
-       include/openssl/conf.h \
-       include/openssl/conf_api.h \
-       include/openssl/crypto.h \
-       include/openssl/des.h \
-       include/openssl/des_old.h \
-       include/openssl/dh.h \
-       include/openssl/dsa.h \
-       include/openssl/dso.h \
-       include/openssl/dtls1.h \
-       include/openssl/e_os2.h \
-       include/openssl/ebcdic.h \
-       include/openssl/ec.h \
-       include/openssl/ecdh.h \
-       include/openssl/ecdsa.h \
-       include/openssl/engine.h \
-       include/openssl/err.h \
-       include/openssl/evp.h \
-       include/openssl/hmac.h \
-       include/openssl/idea.h \
-       include/openssl/krb5_asn.h \
-       include/openssl/kssl.h \
-       include/openssl/lhash.h \
-       include/openssl/md4.h \
-       include/openssl/md5.h \
-       include/openssl/mdc2.h \
-       include/openssl/modes.h \
-       include/openssl/obj_mac.h \
-       include/openssl/objects.h \
-       include/openssl/ocsp.h \
-       include/openssl/opensslconf.h \
-       include/openssl/opensslv.h \
-       include/openssl/ossl_typ.h \
-       include/openssl/pem.h \
-       include/openssl/pem2.h \
-       include/openssl/pkcs12.h \
-       include/openssl/pkcs7.h \
-       include/openssl/pqueue.h \
-       include/openssl/rand.h \
-       include/openssl/rc2.h \
-       include/openssl/rc4.h \
-       include/openssl/ripemd.h \
-       include/openssl/rsa.h \
-       include/openssl/safestack.h \
-       include/openssl/seed.h \
-       include/openssl/sha.h \
-       include/openssl/srp.h \
-       include/openssl/srtp.h \
-       include/openssl/ssl.h \
-       include/openssl/ssl2.h \
-       include/openssl/ssl23.h \
-       include/openssl/ssl3.h \
-       include/openssl/stack.h \
-       include/openssl/symhacks.h \
-       include/openssl/tls1.h \
-       include/openssl/ts.h \
-       include/openssl/txt_db.h \
-       include/openssl/ui.h \
-       include/openssl/ui_compat.h \
-       include/openssl/whrlpool.h \
-       include/openssl/x509.h \
-       include/openssl/x509_vfy.h \
-       include/openssl/x509v3.h \
-))
+# break symlinks after extracting tarball
+# note: escape \; because LO patched make 3.82 cuts off the command otherwise
+ifeq ($(OS_FOR_BUILD),WNT)
+$(eval $(call gb_UnpackedTarball_set_pre_action,openssl,\
+       cd include/openssl && \
+       for header in `find . -type l` \; do \
+               cp --remove-destination `readlink $$$$header` $$$$header \; \
+       done && cd -))
+endif
 
 $(eval $(call gb_UnpackedTarball_add_patches,openssl,\
        external/openssl/CVE-2013-6449.patch \
commit d1da9c141b0b4f625f7397462bd766f9aabb89f4
Author: Michael Stahl <mst...@redhat.com>
Date:   Tue Apr 8 14:35:38 2014 +0200

    openssl: fix WNT patch to apply
    
    Change-Id: I31494d4314557672b7e3c2ff6846663fb9ed981a

diff --git a/external/openssl/opensslwnt.patch 
b/external/openssl/opensslwnt.patch
index b68e03715f2a..5be9c958a37a 100644
--- a/external/openssl/opensslwnt.patch
+++ b/external/openssl/opensslwnt.patch
@@ -96,7 +96,7 @@
 --- misc/openssl-0.9.8v/util/pl/VC-32.pl       2010-02-04 02:10:24.000000000 
+0100
 +++ build/openssl-0.9.8v/util/pl/VC-32.pl      2010-03-26 12:04:20.977172300 
+0100
 @@ -32,7 +32,7 @@
- $l_flags =~ s/-L(\S+)/\/libpath:$1/g;
+ my $ff = "";
  
  # C compiler stuff
 -$cc='cl';
@@ -104,7 +104,7 @@
  if ($FLAVOR =~ /WIN64/)
      {
      # Note that we currently don't have /WX on Win64! There is a lot of
-@@ -103,21 +103,21 @@
+@@ -103,22 +103,22 @@
      }
  
      $cc='$(CC)';
@@ -125,10 +125,11 @@
 +    $base_cflags= " $mf_cflag";
 -    my $f = $shlib || $fips ?' /MD':' /MT';
 -    $lib_cflag='/Zl' if (!$shlib);    # remove /DEFAULTLIBs from static lib
--    $opt_cflags=$f.' /Ox /O2 /Ob2';
--    $dbg_cflags=$f.'d /Od -DDEBUG -D_DEBUG';
 +    my $f = $shlib || $fips ? (($ENV{MSVC_USE_DEBUG_RUNTIME} eq "TRUE") ? ' 
-MDd' : ' -MD' ):' -MT';
 +    $lib_cflag='-Zl' if (!$shlib);    # remove /DEFAULTLIBs from static lib
+     $ff = "/fixed";
+-    $opt_cflags=$f.' /Ox /O2 /Ob2';
+-    $dbg_cflags=$f.'d /Od -DDEBUG -D_DEBUG';
 +    $opt_cflags=$f.' -Ox -O2 -Ob2';
 +    $dbg_cflags=$f.'d -Od -DDEBUG -D_DEBUG';
      $lflags="/nologo /subsystem:console /opt:ref";
commit 67aae7bc2aa6909e7d8c1ac684f6e8be0ae80ccc
Author: Thorsten Behrens <thorsten.behr...@cib.de>
Date:   Mon Apr 30 14:01:29 2018 +0200

    Update graphite to 1.3.6
    
    Change-Id: I4cd07ffd7cd2be94a830c9ecdeedb59950b115bb

diff --git a/download.lst b/download.lst
index c1ed0723601c..f83677a20ba9 100644
--- a/download.lst
+++ b/download.lst
@@ -60,7 +60,7 @@ export FONT_PTSERIF_TARBALL := 
c3c1a8ba7452950636e871d25020ce0d-pt-serif-font-1.
 export FONT_SOURCECODE_TARBALL := 
0279a21fab6f245e85a6f85fea54f511-source-code-font-1.009.tar.gz
 export FONT_SOURCESANS_TARBALL := 
1e9ddfe25ac9577da709d7b2ea36f939-source-sans-font-1.036.tar.gz
 export FREETYPE_TARBALL := 
dbf2caca1d3afd410a29217a9809d397-freetype-2.4.8.tar.bz2
-export GRAPHITE_TARBALL := 
28935e208c311761c29983c739db08d8-graphite2-minimal-1.3.5.tgz
+export GRAPHITE_TARBALL := 
17df8301bcc459e83f8a8f3aca6183b2-graphite-minimal-1.3.6.tgz
 export HSQLDB_TARBALL := 17410483b5b5f267aa18b7e00b65e6e0-hsqldb_1_8_0.zip
 export HUNSPELL_TARBALL := 
3121aaf3e13e5d88dfff13fb4a5f1ab8-hunspell-1.3.2.tar.gz
 export HYPHEN_TARBALL := a2f6010987e1c601274ab5d63b72c944-hyphen-2.8.4.tar.gz
commit 6b4e39d603ef8a214067361a1fdc3c55078af119
Author: Thorsten Behrens <thorsten.behr...@cib.de>
Date:   Mon Apr 30 13:45:25 2018 +0200

    fixup update graphite to 1.3.5
    
    Change-Id: I50c07f8698c06c96bc922845e11e7e7e57b2ca1d

diff --git a/Makefile.fetch b/Makefile.fetch
index 6f246571a538..bb0b02f4ac5e 100644
--- a/Makefile.fetch
+++ b/Makefile.fetch
@@ -81,7 +81,6 @@ $(WORKDIR)/download: $(BUILDDIR)/config_host.mk 
$(SRCDIR)/download.lst $(SRCDIR)
                $(call fetch_Optional,FREEHAND,FREEHAND_TARBALL) \
                $(call fetch_Optional,ETONYEK,ETONYEK_TARBALL) \
                $(call fetch_Optional,FIREBIRD,FIREBIRD_TARBALL) \
-               $(call fetch_Optional,GRAPHITE,GRAPHITE_TARBALL) \
                $(call fetch_Optional,HARFBUZZ,HARFBUZZ_TARBALL) \
                $(call fetch_Optional,LIBEOT,LIBEOT_TARBALL) \
                $(call fetch_Optional,LIBLANGTAG,LANGTAGREG_TARBALL) \
@@ -121,6 +120,7 @@ $(WORKDIR)/download: $(BUILDDIR)/config_host.mk 
$(SRCDIR)/download.lst $(SRCDIR)
                $(call fetch_Optional,MORE_FONTS,$(FONT_SOURCECODE_TARBALL)) \
                $(call fetch_Optional,FONTCONFIG,$(FONTCONFIG_TARBALL)) \
                $(call fetch_Optional,FREETYPE,$(FREETYPE_TARBALL)) \
+               $(call fetch_Optional,GRAPHITE,$(GRAPHITE_TARBALL)) \
                $(GOOGLE_DOCS_EXTENSION_PACK) \
                $(call fetch_Optional,HSQLDB,$(HSQLDB_TARBALL)) \
                $(call fetch_Optional,HUNSPELL,$(HUNSPELL_TARBALL)) \
diff --git a/download.lst b/download.lst
index fdd5bff22d53..c1ed0723601c 100644
--- a/download.lst
+++ b/download.lst
@@ -20,8 +20,6 @@ FIREBIRD_MD5SUM := 21154d2004e025c8a3666625b0357bb5
 export FIREBIRD_TARBALL := Firebird-2.5.2.26540-0.tar.bz2
 # FIREBIRD_MD5SUM := b259c2d1c60a03bd104108405ae990a7
 # export FIREBIRD_TARBALL := Firebird-3.0-alpha1-20130302.tar.gz
-GRAPHITE_MD5SUM := 2ef839348fe28e3b923bf8cced440227
-export GRAPHITE_TARBALL := graphite2-1.2.4.tgz
 HARFBUZZ_MD5SUM := a4a9b548577e2ee22f0887937da5fd6c
 export HARFBUZZ_TARBALL := harfbuzz-0.9.23.tar.bz2
 LIBATOMIC_OPS_MD5SUM := c0b86562d5aa40761a87134f83e6adcf
diff --git a/vcl/source/glyphs/graphite_layout.cxx 
b/vcl/source/glyphs/graphite_layout.cxx
index c6c3c7b3dd31..ef76f85172de 100644
--- a/vcl/source/glyphs/graphite_layout.cxx
+++ b/vcl/source/glyphs/graphite_layout.cxx
@@ -701,7 +701,7 @@ unsigned int GraphiteLayout::ScanFwdForChar(int &findChar, 
bool fallback) const
 
 void GraphiteLayout::ApplyDXArray(ImplLayoutArgs &args, std::vector<int> & 
rDeltaWidth)
 {
-    bool bRtl(mnLayoutFlags & SalLayoutFlags::BiDiRtl);
+    bool bRtl(mnLayoutFlags & SAL_LAYOUT_BIDI_RTL);
     int startChar = args.mnMinCharPos < mnMinCharPos ? mnMinCharPos : 
args.mnMinCharPos;
     int endChar = args.mnEndCharPos >= mnEndCharPos ? mnEndCharPos - 1 : 
args.mnEndCharPos;
     unsigned int startGi = ScanFwdForChar(startChar, !bRtl);
commit 925ddedc250eeaf1da75d565e42e5c6bf1544dfa
Author: Tomáš Chvátal <tchva...@suse.com>
Date:   Tue Dec 22 15:41:25 2015 +0100

    Refresh graphite2.win64.patch.1 to apply using sle11 patch binary.
    
    Change-Id: If43ca99631fab5a3a04e7dead9b694cf52944666
    Reviewed-on: https://gerrit.libreoffice.org/20882
    Reviewed-by: Michael Stahl <mst...@redhat.com>
    Tested-by: Michael Stahl <mst...@redhat.com>
    (cherry picked from commit 817192b3f55be0b0a4a6e877a3c1ab95d3a4b4cb)
    Reviewed-on: https://gerrit.libreoffice.org/22845
    Tested-by: Christian Lohmaier <lohmaier+libreoff...@googlemail.com>
    Tested-by: Jenkins <c...@libreoffice.org>
    Reviewed-by: Christian Lohmaier <lohmaier+libreoff...@googlemail.com>

diff --git a/external/graphite/graphite2.win64.patch.1 
b/external/graphite/graphite2.win64.patch.1
index e7c36c63c21b..4e1172ad8222 100644
--- a/external/graphite/graphite2.win64.patch.1
+++ b/external/graphite/graphite2.win64.patch.1
@@ -1,19 +1,6 @@
-diff -ur graphite.org/src/inc/Main.h graphite/src/inc/Main.h
---- graphite.org/src/inc/Main.h        2015-09-07 20:09:25.572279671 +0700
---- graphite/src/inc/Main.h    2015-09-07 20:09:25.572279671 +0700
-@@ -25,6 +25,9 @@
- of the License or (at your option) any later version.
- */
- #pragma once
-+#ifdef _WIN32
-+#pragma warning(disable: 4510 4610)
-+#endif
- 
- #include <cstdlib>
- #include "graphite2/Types.h"
-diff -ur graphite.org/src/inc/json.h graphite/src/inc/json.h
---- graphite.org/src/inc/json.h        2015-02-03 14:49:24.408101900 +0100
-+++ graphite/src/inc/json.h    2015-02-03 14:50:59.697552200 +0100
+diff -urN graphite2-1.3.4.orig/src/inc/json.h graphite2-1.3.4/src/inc/json.h
+--- graphite2-1.3.4.orig/src/inc/json.h        2015-12-22 14:25:46.403566441 
+0100
++++ graphite2-1.3.4/src/inc/json.h     2015-12-22 14:26:13.439722846 +0100
 @@ -85,6 +85,9 @@
      json & operator << (string) throw();
      json & operator << (number) throw();
@@ -24,10 +11,24 @@ diff -ur graphite.org/src/inc/json.h graphite/src/inc/json.h
      json & operator << (long unsigned int d) throw();
      json & operator << (boolean) throw();
      json & operator << (_null_t) throw();
-diff -ur graphite.org/src/json.cpp graphite/src/json.cpp
---- graphite.org/src/json.cpp  2015-02-03 14:49:24.409102000 +0100
-+++ graphite/src/json.cpp      2015-02-03 14:50:49.814986900 +0100
-@@ -134,5 +134,8 @@
+diff -urN graphite2-1.3.4.orig/src/inc/Main.h graphite2-1.3.4/src/inc/Main.h
+--- graphite2-1.3.4.orig/src/inc/Main.h        2015-12-22 14:25:46.399566417 
+0100
++++ graphite2-1.3.4/src/inc/Main.h     2015-12-22 14:26:13.439722846 +0100
+@@ -25,6 +25,9 @@
+ of the License or (at your option) any later version.
+ */
+ #pragma once
++#ifdef _WIN32
++#pragma warning(disable: 4510 4610)
++#endif
+ 
+ #include <cstdlib>
+ #include "graphite2/Types.h"
+diff -urN graphite2-1.3.4.orig/src/json.cpp graphite2-1.3.4/src/json.cpp
+--- graphite2-1.3.4.orig/src/json.cpp  2015-12-22 14:25:46.399566417 +0100
++++ graphite2-1.3.4/src/json.cpp       2015-12-22 14:26:13.439722846 +0100
+@@ -133,6 +133,9 @@
+ }
  json & json::operator << (json::integer d) throw()  { context(seq); 
fprintf(_stream, "%ld", d); return *this; }
  json & json::operator << (long unsigned d) throw()  { context(seq); 
fprintf(_stream, "%ld", d); return *this; }
 +#ifdef _WIN64
@@ -36,10 +37,10 @@ diff -ur graphite.org/src/json.cpp graphite/src/json.cpp
  json & json::operator << (json::boolean b) throw()  { context(seq); fputs(b ? 
"true" : "false", _stream); return *this; }
  json & json::operator << (json::_null_t) throw()    { context(seq); 
fputs("null",_stream); return *this; }
  
-diff -ur graphite.org/src/Pass.cpp graphite/src/Pass.cpp
---- graphite.org/src/Pass.cpp  2015-02-03 14:49:24.413102200 +0100
-+++ graphite/src/Pass.cpp      2015-02-03 14:50:37.873303900 +0100
-@@ -544,7 +544,7 @@
+diff -urN graphite2-1.3.4.orig/src/Pass.cpp graphite2-1.3.4/src/Pass.cpp
+--- graphite2-1.3.4.orig/src/Pass.cpp  2015-12-22 14:25:46.399566417 +0100
++++ graphite2-1.3.4/src/Pass.cpp       2015-12-22 14:26:13.439722846 +0100
+@@ -554,7 +554,7 @@
          if (r->rule->preContext > fsm.slots.context())
              continue;
          *fsm.dbgout << json::flat << json::object
@@ -48,7 +49,7 @@ diff -ur graphite.org/src/Pass.cpp graphite/src/Pass.cpp
                      << "failed" << true
                      << "input" << json::flat << json::object
                          << "start" << objectid(dslot(&fsm.slots.segment, 
input_slot(fsm.slots, -r->rule->preContext)))
-@@ -558,7 +558,7 @@
+@@ -568,7 +568,7 @@
  void Pass::dumpRuleEventOutput(const FiniteStateMachine & fsm, Machine & m, 
const Rule & r, Slot * const last_slot) const
  {
      *fsm.dbgout     << json::item << json::flat << json::object
commit d9aeaac9d5b35988f717e072ff0956a7f155fd23
Author: Caolán McNamara <caol...@redhat.com>
Date:   Mon Jun 29 12:26:16 2015 +0200

    update graphite to 1.3.5
    
    (cherry picked from commit c64ea526dc71da6e3aad188ac71e58047ed74b5a)
    
    and sync the various upgrade patches together
    
    Change-Id: I3287d51430d7a0901dd8bbf2458b845bcf92a8d2
    Reviewed-on: https://gerrit.libreoffice.org/22210
    Reviewed-by: Miklos Vajna <vmik...@collabora.co.uk>
    Tested-by: Miklos Vajna <vmik...@collabora.co.uk>

diff --git a/download.lst b/download.lst
index 542a0f516e64..fdd5bff22d53 100644
--- a/download.lst
+++ b/download.lst
@@ -62,6 +62,7 @@ export FONT_PTSERIF_TARBALL := 
c3c1a8ba7452950636e871d25020ce0d-pt-serif-font-1.
 export FONT_SOURCECODE_TARBALL := 
0279a21fab6f245e85a6f85fea54f511-source-code-font-1.009.tar.gz
 export FONT_SOURCESANS_TARBALL := 
1e9ddfe25ac9577da709d7b2ea36f939-source-sans-font-1.036.tar.gz
 export FREETYPE_TARBALL := 
dbf2caca1d3afd410a29217a9809d397-freetype-2.4.8.tar.bz2
+export GRAPHITE_TARBALL := 
28935e208c311761c29983c739db08d8-graphite2-minimal-1.3.5.tgz
 export HSQLDB_TARBALL := 17410483b5b5f267aa18b7e00b65e6e0-hsqldb_1_8_0.zip
 export HUNSPELL_TARBALL := 
3121aaf3e13e5d88dfff13fb4a5f1ab8-hunspell-1.3.2.tar.gz
 export HYPHEN_TARBALL := a2f6010987e1c601274ab5d63b72c944-hyphen-2.8.4.tar.gz
diff --git a/editeng/source/editeng/impedit3.cxx 
b/editeng/source/editeng/impedit3.cxx
index a2d92a65311f..34fb23145180 100644
--- a/editeng/source/editeng/impedit3.cxx
+++ b/editeng/source/editeng/impedit3.cxx
@@ -734,6 +734,8 @@ sal_Bool ImpEditEngine::CreateLines( sal_Int32 nPara, 
sal_uInt32 nStartPosY )
     EditLine aSaveLine( *pLine );
     SvxFont aTmpFont( pNode->GetCharAttribs().GetDefFont() );
 
+    ImplInitLayoutMode( GetRefDevice(), nPara, nIndex );
+
     sal_Bool bCalcCharPositions = sal_True;
     sal_Int32* pBuf = new sal_Int32[ pNode->Len() ];
 
@@ -1058,6 +1060,8 @@ sal_Bool ImpEditEngine::CreateLines( sal_Int32 nPara, 
sal_uInt32 nStartPosY )
                 aTmpFont.SetPhysFont( GetRefDevice() );
                 ImplInitDigitMode(GetRefDevice(), aTmpFont.GetLanguage());
 
+                pPortion->SetRightToLeft( GetRightToLeft( nPara, nTmpPos+1 ) );
+
                 if ( bCalcCharPositions || !pPortion->HasValidSize() )
                 {
                     pPortion->GetSize() = aTmpFont.QuickGetTextSize( 
GetRefDevice(), pParaPortion->GetNode()->GetString(), nTmpPos, 
pPortion->GetLen(), pBuf );
@@ -1089,8 +1093,6 @@ sal_Bool ImpEditEngine::CreateLines( sal_Int32 nPara, 
sal_uInt32 nStartPosY )
 
                 nTmpWidth += pPortion->GetSize().Width();
 
-                pPortion->SetRightToLeft( GetRightToLeft( nPara, nTmpPos+1 ) );
-
                 sal_uInt16 _nPortionEnd = nTmpPos + pPortion->GetLen();
                 if( bScriptSpace && ( _nPortionEnd < pNode->Len() ) && ( 
nTmpWidth < nXWidth ) && IsScriptChange( EditPaM( pNode, _nPortionEnd ) ) )
                 {
diff --git a/external/graphite/StaticLibrary_graphite.mk 
b/external/graphite/StaticLibrary_graphite.mk
index de3950f10b86..ddbf9955e6d7 100644
--- a/external/graphite/StaticLibrary_graphite.mk
+++ b/external/graphite/StaticLibrary_graphite.mk
@@ -19,8 +19,8 @@ $(eval $(call gb_StaticLibrary_set_include,graphite,\
 ))
 
 $(eval $(call gb_StaticLibrary_add_defs,graphite,\
-       -DDISABLE_TRACING \
-       -DGR2_STATIC \
+       -DGRAPHITE2_NTRACING \
+       -DGRAPHITE2_STATIC \
 ))
 
 ifeq ($(COM),GCC)
@@ -43,19 +43,22 @@ $(eval $(call 
gb_StaticLibrary_add_generated_cxxobjects,graphite,\
        UnpackedTarball/graphite/src/gr_segment \
        UnpackedTarball/graphite/src/gr_slot \
        UnpackedTarball/graphite/src/json \
-       UnpackedTarball/graphite/src/Bidi \
        UnpackedTarball/graphite/src/CachedFace \
        UnpackedTarball/graphite/src/CmapCache \
        UnpackedTarball/graphite/src/Code \
+       UnpackedTarball/graphite/src/Collider \
+       UnpackedTarball/graphite/src/Decompressor \
        UnpackedTarball/graphite/src/Face \
        UnpackedTarball/graphite/src/FeatureMap \
        UnpackedTarball/graphite/src/FileFace \
        UnpackedTarball/graphite/src/Font \
        UnpackedTarball/graphite/src/GlyphCache \
        UnpackedTarball/graphite/src/GlyphFace \
+       UnpackedTarball/graphite/src/Intervals \
        UnpackedTarball/graphite/src/Justifier \
        UnpackedTarball/graphite/src/NameTable \
        UnpackedTarball/graphite/src/Pass \
+       UnpackedTarball/graphite/src/Position \
        UnpackedTarball/graphite/src/SegCache \
        UnpackedTarball/graphite/src/SegCacheEntry \
        UnpackedTarball/graphite/src/SegCacheStore \
diff --git a/external/graphite/UnpackedTarball_graphite.mk 
b/external/graphite/UnpackedTarball_graphite.mk
index c7fa86e0e149..a162d172b795 100644
--- a/external/graphite/UnpackedTarball_graphite.mk
+++ b/external/graphite/UnpackedTarball_graphite.mk
@@ -11,10 +11,12 @@ $(eval $(call gb_UnpackedTarball_UnpackedTarball,graphite))
 
 $(eval $(call gb_UnpackedTarball_set_tarball,graphite,$(GRAPHITE_TARBALL)))
 
-# http://projects.palaso.org/issues/1115
+$(eval $(call gb_UnpackedTarball_set_patchlevel,graphite,0))
+
 $(eval $(call gb_UnpackedTarball_add_patches,graphite,\
        external/graphite/graphite2.issue1115.patch.1 \
     external/graphite/graphite2.win64.patch.1 \
+    external/graphite/ubsan.patch \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/external/graphite/graphite2.issue1115.patch.1 
b/external/graphite/graphite2.issue1115.patch.1
index f19c8a3749f4..454114bb32c9 100644
--- a/external/graphite/graphite2.issue1115.patch.1
+++ b/external/graphite/graphite2.issue1115.patch.1
@@ -1,6 +1,6 @@
 --- graphite/src/Code.cpp
 +++ graphite/src/Code.cpp
-@@ -169,8 +169,8 @@ Machine::Code::Code(bool is_constraint,
+@@ -175,8 +175,8 @@ Machine::Code::Code(bool is_constraint,
          bytecode_end,
          pre_context,
          rule_length,
@@ -11,7 +11,7 @@
          face.numFeatures(), 
          {1,1,1,1,1,1,1,1, 
           1,1,1,1,1,1,1,255,
-@@ -178,7 +178,7 @@ Machine::Code::Code(bool is_constraint,
+@@ -184,7 +184,7 @@ Machine::Code::Code(bool is_constraint,
           1,1,1,1,1,1,0,0, 
           0,0,0,0,0,0,0,0, 
           0,0,0,0,0,0,0,0, 
@@ -19,4 +19,4 @@
 +         0,0,0,0,0,0,0, static_cast<byte>(silf.numUser())}
      };
      
-     decoder dec(lims, *this);
+     decoder dec(lims, *this, pt);
diff --git a/external/graphite/graphite2.win64.patch.1 
b/external/graphite/graphite2.win64.patch.1
index 6bf8c88907d1..e7c36c63c21b 100644
--- a/external/graphite/graphite2.win64.patch.1
+++ b/external/graphite/graphite2.win64.patch.1
@@ -1,7 +1,20 @@
+diff -ur graphite.org/src/inc/Main.h graphite/src/inc/Main.h
+--- graphite.org/src/inc/Main.h        2015-09-07 20:09:25.572279671 +0700
+--- graphite/src/inc/Main.h    2015-09-07 20:09:25.572279671 +0700
+@@ -25,6 +25,9 @@
+ of the License or (at your option) any later version.
+ */
+ #pragma once
++#ifdef _WIN32
++#pragma warning(disable: 4510 4610)
++#endif
+ 
+ #include <cstdlib>
+ #include "graphite2/Types.h"
 diff -ur graphite.org/src/inc/json.h graphite/src/inc/json.h
 --- graphite.org/src/inc/json.h        2015-02-03 14:49:24.408101900 +0100
 +++ graphite/src/inc/json.h    2015-02-03 14:50:59.697552200 +0100
-@@ -78,6 +78,9 @@
+@@ -85,6 +85,9 @@
      json & operator << (string) throw();
      json & operator << (number) throw();
      json & operator << (integer) throw();
@@ -14,8 +27,7 @@ diff -ur graphite.org/src/inc/json.h graphite/src/inc/json.h
 diff -ur graphite.org/src/json.cpp graphite/src/json.cpp
 --- graphite.org/src/json.cpp  2015-02-03 14:49:24.409102000 +0100
 +++ graphite/src/json.cpp      2015-02-03 14:50:49.814986900 +0100
-@@ -119,6 +119,9 @@
- json & json::operator << (json::number f) throw()   { context(seq); 
fprintf(_stream, "%g", f); return *this; }
+@@ -134,5 +134,8 @@
  json & json::operator << (json::integer d) throw()  { context(seq); 
fprintf(_stream, "%ld", d); return *this; }
  json & json::operator << (long unsigned d) throw()  { context(seq); 
fprintf(_stream, "%ld", d); return *this; }
 +#ifdef _WIN64
@@ -27,17 +39,17 @@ diff -ur graphite.org/src/json.cpp graphite/src/json.cpp
 diff -ur graphite.org/src/Pass.cpp graphite/src/Pass.cpp
 --- graphite.org/src/Pass.cpp  2015-02-03 14:49:24.413102200 +0100
 +++ graphite/src/Pass.cpp      2015-02-03 14:50:37.873303900 +0100
-@@ -466,7 +466,7 @@
-     {
-         if (r->rule->preContext > fsm.slots.context())  continue;
-     *fsm.dbgout << json::flat << json::object
--                    << "id"     << r->rule - m_rules
-+                    << "id"     << static_cast<size_t>(r->rule - m_rules)
+@@ -544,7 +544,7 @@
+         if (r->rule->preContext > fsm.slots.context())
+             continue;
+         *fsm.dbgout << json::flat << json::object
+-                    << "id" << r->rule - m_rules
++                    << "id" << static_cast<size_t>(r->rule - m_rules)
                      << "failed" << true
                      << "input" << json::flat << json::object
                          << "start" << objectid(dslot(&fsm.slots.segment, 
input_slot(fsm.slots, -r->rule->preContext)))
-@@ -480,7 +480,7 @@
- void Pass::dumpRuleEventOutput(const FiniteStateMachine & fsm, const Rule & 
r, Slot * const last_slot) const
+@@ -558,7 +558,7 @@
+ void Pass::dumpRuleEventOutput(const FiniteStateMachine & fsm, Machine & m, 
const Rule & r, Slot * const last_slot) const
  {
      *fsm.dbgout     << json::item << json::flat << json::object
 -                        << "id"     << &r - m_rules
diff --git a/external/graphite/ubsan.patch b/external/graphite/ubsan.patch
new file mode 100644
index 000000000000..b1617b138630
--- /dev/null
+++ b/external/graphite/ubsan.patch
@@ -0,0 +1,51 @@
+--- src/Pass.cpp
++++ src/Pass.cpp
+@@ -294,7 +294,7 @@
+         s->rules = begin;
+         s->rules_end = (end - begin <= FiniteStateMachine::MAX_RULES)? end :
+             begin + FiniteStateMachine::MAX_RULES;
+-        qsort(begin, end - begin, sizeof(RuleEntry), &cmpRuleEntry);
++        if (end != begin) qsort(begin, end - begin, sizeof(RuleEntry), 
&cmpRuleEntry);
+     }
+ 
+     return true;
+--- src/gr_face.cpp
++++ src/gr_face.cpp
+@@ -87,7 +87,7 @@
+ 
+     Face *res = new Face(appFaceHandle, *ops);
+     if (res && load_face(*res, faceOptions))
+-        return static_cast<gr_face *>(res);
++        return reinterpret_cast<gr_face *>(res);
+ 
+     delete res;
+     return 0;
+@@ -195,7 +195,7 @@
+ 
+ void gr_face_destroy(gr_face *face)
+ {
+-    delete face;
++    delete static_cast<Face *>(face);
+ }
+ 
+ 
+--- src/gr_font.cpp
++++ src/gr_font.cpp
+@@ -50,7 +50,7 @@
+     if (face == 0)  return 0;
+ 
+     Font * const res = new Font(ppm, *face, appFontHandle, font_ops);
+-    return static_cast<gr_font*>(res);
++    return reinterpret_cast<gr_font*>(res);
+ }
+ 
+ gr_font* gr_make_font_with_advance_fn(float ppm/*pixels per em*/, const void* 
appFontHandle/*non-NULL*/, gr_advance_fn getAdvance, const gr_face * 
face/*needed for scaling*/)
+@@ -61,7 +61,7 @@
+ 
+ void gr_font_destroy(gr_font *font)
+ {
+-    delete font;
++    delete static_cast<Font *>(font);
+ }
+ 
+ 
diff --git a/vcl/inc/graphite_layout.hxx b/vcl/inc/graphite_layout.hxx
index 434d6f6dca94..d439026f1fcb 100644
--- a/vcl/inc/graphite_layout.hxx
+++ b/vcl/inc/graphite_layout.hxx
@@ -97,9 +97,10 @@ public:
 private:
     const gr_face *         mpFace; // not owned by layout
     gr_font *               mpFont; // not owned by layout
-    int                     mnSegCharOffset; // relative to 
ImplLayoutArgs::mpStr
+    unsigned int            mnSegCharOffset; // relative to 
ImplLayoutArgs::mpStr
     long                    mnWidth;
     std::vector<int>        mvChar2BaseGlyph;
+    std::vector<int>        mvChar2Glyph;
     std::vector<int>        mvGlyph2Char;
     std::vector<int>        mvCharDxs;
     std::vector<int>        mvCharBreaks;
@@ -113,8 +114,6 @@ public:
     // used by upper layers
     virtual bool  LayoutText( ImplLayoutArgs& );    // first step of layout
     // split into two stages to allow dc to be restored on the segment
-    gr_segment * CreateSegment(ImplLayoutArgs& rArgs);
-    bool LayoutGlyphs(ImplLayoutArgs& rArgs, gr_segment * pSegment);
 
     virtual void  AdjustLayout( ImplLayoutArgs& );  // adjusting positions
 
@@ -149,13 +148,14 @@ public:
     static const int EXTRA_CONTEXT_LENGTH;
 private:
     void expandOrCondense(ImplLayoutArgs &rArgs);
-    void    fillFrom(gr_segment * rSeg, ImplLayoutArgs & rArgs, float 
fScaling);
+    void    fillFrom(gr_segment * rSeg, ImplLayoutArgs & rArgs, float 
fScaling, bool bRtl, int firstCharOffset);
 
     float append(gr_segment * pSeg,
                 ImplLayoutArgs & rArgs,
                 const gr_slot * pSlot, float gOrigin,
                 float nextGlyphOrigin, float fScaling,
-                long & rDXOffset, bool bIsBase, int baseChar);
+                long & rDXOffset, bool bIsBase, int baseChar, int baseGlyph, 
bool bRtl);
+    unsigned int ScanFwdForChar(int &findChar, bool fallback) const;
 };
 
 #endif // INCLUDED_VCL_INC_GRAPHITE_LAYOUT_HXX
diff --git a/vcl/source/fontsubset/sft.cxx b/vcl/source/fontsubset/sft.cxx
index 76f8abfe44d2..408fa1eb49ee 100644
--- a/vcl/source/fontsubset/sft.cxx
+++ b/vcl/source/fontsubset/sft.cxx
@@ -1782,6 +1782,9 @@ int GetTTGlyphComponents(TrueTypeFont *ttf, sal_uInt32 
glyphID, std::vector< sal
 
     const sal_uInt8* glyf = getTable(ttf, O_glyf);
     const sal_uInt8* ptr = glyf + ttf->goffsets[glyphID];
+    const sal_uInt8* nptr = glyf + ttf->goffsets[glyphID+1];
+    if (nptr <= ptr)
+        return 0;
 
     glyphlist.push_back( glyphID );
 
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx 
b/vcl/source/gdi/pdfwriter_impl.cxx
index 89355ad6422d..a5d3c375b1b4 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -7567,22 +7567,27 @@ void PDFWriterImpl::drawLayout( SalLayout& rLayout, 
const OUString& rText, bool
             else if( pCharPosAry[i] >= nMinCharPos && pCharPosAry[i] <= 
nMaxCharPos )
             {
                 int nChars = 1;
-                aUnicodes.push_back( rText[ 
sal::static_int_cast<xub_StrLen>(pCharPosAry[i]) ] );
                 pUnicodesPerGlyph[i] = 1;
                 // try to handle ligatures and such
                 if( i < nGlyphs-1 )
                 {
                     nChars = pCharPosAry[i+1] - pCharPosAry[i];
+                    int start = pCharPosAry[i];
                     // #i115618# fix for simple RTL+CTL cases
-                    // TODO: sanitize for RTL ligatures, more complex CTL, etc.
+                    // supports RTL ligatures. TODO: more complex CTL, etc.
                     if( nChars < 0 )
+                    {
                         nChars = -nChars;
-                    else if( nChars == 0 )
+                        start = pCharPosAry[i+1] + 1;
+                    }
+                    else if (nChars == 0)
                         nChars = 1;
                     pUnicodesPerGlyph[i] = nChars;
-                    for( int n = 1; n < nChars; n++ )
-                        aUnicodes.push_back( rText[ 
sal::static_int_cast<xub_StrLen>(pCharPosAry[i]+n) ] );
+                    for( int n = 0; n < nChars; n++ )
+                        aUnicodes.push_back( rText[ start + n ] );
                 }
+                else
+                    aUnicodes.push_back( rText[ pCharPosAry[i] ] );
                 // #i36691# hack that is needed because currently the pGlyphs[]
                 // argument is ignored for embeddable fonts and so the layout
                 // engine's glyph work is ignored (i.e. char mirroring)
diff --git a/vcl/source/glyphs/graphite_layout.cxx 
b/vcl/source/glyphs/graphite_layout.cxx
index 230583b191af..c6c3c7b3dd31 100644
--- a/vcl/source/glyphs/graphite_layout.cxx
+++ b/vcl/source/glyphs/graphite_layout.cxx
@@ -27,7 +27,7 @@
 #undef NDEBUG
 #endif
 
-// #define GRLAYOUT_DEBUG 1
+//#define GRLAYOUT_DEBUG 1
 
 // Header files
 //
@@ -105,23 +105,6 @@ namespace
         return is_subrange(s.first, s.second, b, e);
     }
 
-    int findSameDirLimit(const sal_Unicode* buffer, int charCount, bool rtl)
-    {
-        UErrorCode status = U_ZERO_ERROR;
-        UBiDi *ubidi = ubidi_openSized(charCount, 0, &status);
-        int limit = 0;
-        ubidi_setPara(ubidi, reinterpret_cast<const UChar *>(buffer), 
charCount,
-            (rtl)?UBIDI_DEFAULT_RTL:UBIDI_DEFAULT_LTR, NULL, &status);
-        UBiDiLevel level = 0;
-        ubidi_getLogicalRun(ubidi, 0, &limit, &level);
-        ubidi_close(ubidi);
-        if ((rtl && !(level & 1)) || (!rtl && (level & 1)))
-        {
-            limit = 0;
-        }
-        return limit;
-    }
-
     template <typename T>
     T maximum(T a, T b)
     {
@@ -141,43 +124,21 @@ namespace
 //        o Querying clustering relationships.
 //        o manipulations that affect neighouring glyphs.
 
-const int GraphiteLayout::EXTRA_CONTEXT_LENGTH = 10;
+const int GraphiteLayout::EXTRA_CONTEXT_LENGTH = 32;
 
-// find first slot of cluster and first slot of subsequent cluster
-static void findFirstClusterSlot(const gr_slot* base, gr_slot const** first, 
gr_slot const** after, int * firstChar, int * lastChar, bool bRtl)
+const gr_slot *get_next_base(const gr_slot *slot, bool bRtl)
 {
-    if (gr_slot_attached_to(base) == NULL)
-    {
-        *first = base;
-        *after = (bRtl)? gr_slot_prev_in_segment(base) :
-            gr_slot_next_in_segment(base);
-        *firstChar = gr_slot_before(base);
-        *lastChar = gr_slot_after(base);
-    }
-    const gr_slot * attachment = gr_slot_first_attachment(base);
-    while (attachment)
-    {
-        if (gr_slot_origin_X(*first) > gr_slot_origin_X(attachment))
-            *first = attachment;
-        const gr_slot* attachmentNext = (bRtl)?
-            gr_slot_prev_in_segment(attachment) : 
gr_slot_next_in_segment(attachment);
-        if (attachmentNext)
-        {
-            if (*after && (gr_slot_origin_X(*after) < 
gr_slot_origin_X(attachmentNext)))
-                *after = attachmentNext;
-        }
-        else
-        {
-            *after = NULL;
-        }
-        if (gr_slot_before(attachment) < *firstChar)
-            *firstChar = gr_slot_before(attachment);
-        if (gr_slot_after(attachment) > *lastChar)
-            *lastChar = gr_slot_after(attachment);
-        if (gr_slot_first_attachment(attachment))
-            findFirstClusterSlot(attachment, first, after, firstChar, 
lastChar, bRtl);
-        attachment = gr_slot_next_sibling_attachment(attachment);
-    }
+    for ( ; slot; slot = bRtl ? gr_slot_prev_in_segment(slot) : 
gr_slot_next_in_segment(slot))
+        if (!gr_slot_attached_to(slot) || gr_slot_can_insert_before(slot))
+            break;
+    return slot;
+}
+
+bool isWhite(sal_Unicode nChar)
+{
+    if (nChar <= 0x0020 || nChar == 0x00A0 || (nChar >= 0x2000 && nChar <= 
0x200F) || nChar == 0x3000)
+        return true;
+    return false;
 }
 
 // The Graphite glyph stream is really a sequence of glyph attachment trees
@@ -185,202 +146,130 @@ static void findFirstClusterSlot(const gr_slot* base, 
gr_slot const** first, gr_
 //  finds each non-attached base glyph and calls append to record them as a
 //  sequence of clusters.
 void
-GraphiteLayout::fillFrom(gr_segment * pSegment, ImplLayoutArgs &rArgs, float 
fScaling)
+GraphiteLayout::fillFrom(gr_segment * pSegment, ImplLayoutArgs &rArgs, float 
fScaling, bool bRtl, int lastCharPos)
 {
-    bool bRtl = (rArgs.mnFlags & SAL_LAYOUT_BIDI_RTL);
-    int nCharRequested = rArgs.mnEndCharPos - rArgs.mnMinCharPos;
-    int nChar = gr_seg_n_cinfo(pSegment);
     float fMinX = gr_seg_advance_X(pSegment);
     float fMaxX = 0.0f;
     long nDxOffset = 0; // from dropped glyphs
-    int nFirstCharInCluster = 0;
-    int nLastCharInCluster = 0;
+    int origNumGlyphs = mvGlyphs.size();
     unsigned int nGlyphs = gr_seg_n_slots(pSegment);
-    mvGlyph2Char.assign(nGlyphs, -1);
-    mvGlyphs.reserve(nGlyphs);
-
-    if (bRtl)
+    mvGlyph2Char.resize(mvGlyph2Char.size() + nGlyphs, -1);
+    mvGlyphs.reserve(mvGlyphs.size() + nGlyphs);
+    int clusterStart = -1;
+    int clusterFirstChar = -1;
+    const gr_slot *nextBaseSlot;
+    const sal_Unicode *pStr = rArgs.mpStr;
+    int firstChar;
+
+    if (!nGlyphs || lastCharPos - mnSegCharOffset == 0) return;
+    const gr_slot* baseSlot = bRtl ? gr_seg_last_slot(pSegment) : 
gr_seg_first_slot(pSegment);
+    // find first base
+    while (baseSlot && gr_slot_attached_to(baseSlot) != NULL && 
!gr_slot_can_insert_before(baseSlot))
+        baseSlot = bRtl ? gr_slot_prev_in_segment(baseSlot) : 
gr_slot_next_in_segment(baseSlot);
+    assert(baseSlot);
+    int nextChar = gr_cinfo_base(gr_seg_cinfo(pSegment, 
gr_slot_before(baseSlot))) + mnSegCharOffset;
+    float thisBoundary = 0.;
+    float nextBoundary = gr_slot_origin_X(baseSlot);
+    // now loop over bases
+    for ( ; baseSlot; baseSlot = nextBaseSlot)
     {
-        const gr_slot* baseSlot = gr_seg_last_slot(pSegment);
-        // find first base
-        while (baseSlot && (gr_slot_attached_to(baseSlot) != NULL))
-            baseSlot = gr_slot_prev_in_segment(baseSlot);
-        int iChar = nChar - 1;
-        int iNextChar = nChar - 1;
-        bool reordered = false;
-        int nBaseGlyphIndex = 0;
-        // now loop over bases
-        while (baseSlot)
+        firstChar = nextChar;
+        thisBoundary = nextBoundary;
+        nextBaseSlot = get_next_base(bRtl ? gr_slot_prev_in_segment(baseSlot) 
: gr_slot_next_in_segment(baseSlot), bRtl);
+        nextChar = nextBaseSlot ? gr_cinfo_base(gr_seg_cinfo(pSegment, 
gr_slot_before(nextBaseSlot))) + mnSegCharOffset : -1;
+        nextBoundary = nextBaseSlot ? gr_slot_origin_X(nextBaseSlot) : 
gr_seg_advance_X(pSegment);
+
+        if (firstChar < mnMinCharPos || firstChar >= mnEndCharPos)
         {
-            bool bCluster = !reordered;
-            const gr_slot * clusterFirst = NULL;
-            const gr_slot * clusterAfter = NULL;
-            int firstChar = -1;
-            int lastChar = -1;
-            findFirstClusterSlot(baseSlot, &clusterFirst, &clusterAfter, 
&firstChar, &lastChar, bRtl);
-            iNextChar = minimum<int>(firstChar, iNextChar);
-            if (bCluster)
-            {
-                nBaseGlyphIndex = mvGlyphs.size();
-                mvGlyph2Char[nBaseGlyphIndex] = iChar + mnSegCharOffset;
-                nFirstCharInCluster = firstChar;
-                nLastCharInCluster = lastChar;
-            }
-            else
-            {
-                mvGlyph2Char[mvGlyphs.size()] = firstChar + mnSegCharOffset;
-                nFirstCharInCluster = minimum<int>(firstChar, 
nFirstCharInCluster);
-                nLastCharInCluster = maximum<int>(firstChar, 
nLastCharInCluster);
-            }
-            float leftBoundary = gr_slot_origin_X(clusterFirst);
-            float rightBoundary = (clusterAfter)?
-                gr_slot_origin_X(clusterAfter) : gr_seg_advance_X(pSegment);
-            if (
-                lastChar < iChar &&
-                 (gr_cinfo_after(gr_seg_cinfo(pSegment, iChar)) >
-                 static_cast<int>(gr_slot_index(clusterAfter)))
-               )
-            {
-                reordered = true;
-            }
-            else
-            {
-                reordered = false;
-                iChar = iNextChar - 1;
-            }
-            if (mnSegCharOffset + nFirstCharInCluster >= mnMinCharPos &&
-                mnSegCharOffset + nFirstCharInCluster < mnEndCharPos)
-            {
-                fMinX = minimum<float>(fMinX, leftBoundary);
-                fMaxX = maximum<float>(fMaxX, rightBoundary);
-                if (!reordered)
-                {
-                    for (int i = nFirstCharInCluster; i <= nLastCharInCluster; 
i++)
-                    {
-                        if (mnSegCharOffset + i >= mnEndCharPos)
-                            break;
-                        // from the point of view of the dx array, the xpos is
-                        // the origin of the first glyph of the cluster rtl
-                        mvCharDxs[mnSegCharOffset + i - mnMinCharPos] =
-                            static_cast<int>(leftBoundary * fScaling) + 
nDxOffset;
-                        mvCharBreaks[mnSegCharOffset + i - mnMinCharPos] = 
gr_cinfo_break_weight(gr_seg_cinfo(pSegment, i));
-                    }
-                    mvChar2BaseGlyph[mnSegCharOffset + nFirstCharInCluster - 
mnMinCharPos] = nBaseGlyphIndex;
-                }
-                append(pSegment, rArgs, baseSlot, gr_slot_origin_X(baseSlot), 
rightBoundary, fScaling,
-                       nDxOffset, bCluster, mnSegCharOffset + firstChar);
-            }
-            if (mnSegCharOffset + nLastCharInCluster < mnMinCharPos)
-                break;
-            baseSlot = gr_slot_next_sibling_attachment(baseSlot);
+            // handle clipping of diacritic from base
+            nextBaseSlot = bRtl ? gr_slot_prev_in_segment(baseSlot) : 
gr_slot_next_in_segment(baseSlot);
+            nextBoundary = nextBaseSlot ? gr_slot_origin_X(nextBaseSlot) : 
gr_seg_advance_X(pSegment);
+            nextChar = nextBaseSlot ? gr_cinfo_base(gr_seg_cinfo(pSegment, 
gr_slot_before(nextBaseSlot))) + mnSegCharOffset : -1;
+            continue;
         }
-    }
-    else
-    {
-        const gr_slot* baseSlot = gr_seg_first_slot(pSegment);
-        // find first base
-        while (baseSlot && (gr_slot_attached_to(baseSlot) != NULL))
-            baseSlot = gr_slot_next_in_segment(baseSlot);
-        int iChar = 0; // relative to segment
-        int iNextChar = 0;
-        bool reordered = false;
-        int nBaseGlyphIndex = 0;
-        // now loop over bases
-        while (baseSlot)
+        // handle reordered clusters. Presumes reordered glyphs have monotonic 
opposite char index until the cluster base.
+        bool isReordered = (nextBaseSlot && ((bRtl != 
(gr_cinfo_base(gr_seg_cinfo(pSegment, gr_slot_before(nextBaseSlot))) < 
firstChar - mnSegCharOffset))
+                                             || 
gr_cinfo_base(gr_seg_cinfo(pSegment, gr_slot_before(nextBaseSlot))) == 
firstChar - mnSegCharOffset));
+        if (clusterStart >= 0 && !isReordered)      // we hit the base (end) 
of a reordered cluster
         {
-            bool bCluster = !reordered;
-            const gr_slot * clusterFirst = NULL;
-            const gr_slot * clusterAfter = NULL;
-            int firstChar = -1;
-            int lastChar = -1;
-            findFirstClusterSlot(baseSlot, &clusterFirst, &clusterAfter, 
&firstChar, &lastChar, bRtl);
-            iNextChar = maximum<int>(lastChar, iNextChar);
-            if (bCluster)
-            {
-                nBaseGlyphIndex = mvGlyphs.size();
-                mvGlyph2Char[nBaseGlyphIndex] = iChar + mnSegCharOffset;
-                nFirstCharInCluster = firstChar;
-                nLastCharInCluster = lastChar;
-            }
-            else
-            {
-                mvGlyph2Char[mvGlyphs.size()] = firstChar + mnSegCharOffset;
-                nFirstCharInCluster = minimum<int>(firstChar, 
nFirstCharInCluster);
-                nLastCharInCluster = maximum<int>(lastChar, 
nLastCharInCluster);
-            }
-            if (
-                firstChar > iChar &&
-                 (gr_cinfo_before(gr_seg_cinfo(pSegment, iChar)) >
-                 static_cast<int>(gr_slot_index(clusterFirst)))
-               )
+            int clusterEnd = mvGlyphs.size();
+            for (int i = clusterStart; i < clusterEnd; ++i)
+                mvGlyph2Char[i] = firstChar;
+            if (bRtl)
             {
-                reordered = true;
+                for ( ; clusterFirstChar < firstChar; ++clusterFirstChar)
+                    if (clusterFirstChar >= mnMinCharPos && clusterFirstChar < 
mnEndCharPos)
+                    {
+                        mvChar2BaseGlyph[clusterFirstChar - mnMinCharPos] = 
clusterStart;  // lowest glyphItem index
+                        mvCharDxs[clusterFirstChar - mnMinCharPos] = 
static_cast<int>(thisBoundary * fScaling) + mnWidth + nDxOffset;
+                    }
             }
             else
             {
-                reordered = false;
-                iChar = iNextChar + 1;
-            }
-            float leftBoundary = gr_slot_origin_X(clusterFirst);
-            float rightBoundary = (clusterAfter)?
-                gr_slot_origin_X(clusterAfter) : gr_seg_advance_X(pSegment);
-            int bFirstChar = gr_cinfo_base(gr_seg_cinfo(pSegment, 
nFirstCharInCluster));
-            if (mnSegCharOffset + bFirstChar >= mnMinCharPos &&
-                mnSegCharOffset + bFirstChar < mnEndCharPos)
-            {
-                fMinX = minimum<float>(fMinX, leftBoundary);
-                fMaxX = maximum<float>(fMaxX, rightBoundary);
-                if (!reordered)
-                {
-                    for (int i = nFirstCharInCluster; i <= nLastCharInCluster; 
i++)
+                for ( ; clusterFirstChar > firstChar; --clusterFirstChar)
+                    if (clusterFirstChar < mnEndCharPos && clusterFirstChar >= 
mnMinCharPos)
                     {
-                        int ibase = gr_cinfo_base(gr_seg_cinfo(pSegment, i));
-                        if (mnSegCharOffset + ibase >= mnEndCharPos)
-                            break;
-                        // from the point of view of the dx array, the xpos is
-                        // the origin of the first glyph of the next cluster 
ltr
-                        mvCharDxs[mnSegCharOffset + ibase - mnMinCharPos] =
-                            static_cast<int>(rightBoundary * fScaling) + 
nDxOffset;
-                        mvCharBreaks[mnSegCharOffset + ibase - mnMinCharPos] = 
gr_cinfo_break_weight(gr_seg_cinfo(pSegment, i));
+                        mvChar2BaseGlyph[clusterFirstChar - mnMinCharPos] = 
clusterStart;
+                        mvCharDxs[clusterFirstChar - mnMinCharPos] = 
static_cast<int>(nextBoundary * fScaling) + mnWidth + nDxOffset;
                     }
-                    // only set mvChar2BaseGlyph for first character of cluster
-                    mvChar2BaseGlyph[mnSegCharOffset + bFirstChar - 
mnMinCharPos] = nBaseGlyphIndex;
-                }
-                append(pSegment, rArgs, baseSlot, gr_slot_origin_X(baseSlot), 
rightBoundary, fScaling,
-                       nDxOffset, true, mnSegCharOffset + firstChar);
             }
-            if (mnSegCharOffset + bFirstChar >= mnEndCharPos)
-                break;
-            baseSlot = gr_slot_next_sibling_attachment(baseSlot);
+            clusterStart = -1;
+            clusterFirstChar = -1;
         }
+        else if (clusterStart < 0 && isReordered) // we hit the start of a 
reordered cluster
+        {
+            clusterStart = mvGlyphs.size();
+            clusterFirstChar = firstChar;
+        }
+
+        int baseGlyph = mvGlyphs.size();
+        int scaledGlyphPos = round(gr_slot_origin_X(baseSlot) * fScaling) + 
mnWidth + nDxOffset;
+        if (mvChar2Glyph[firstChar - mnMinCharPos] == -1 || 
mvGlyphs[mvChar2Glyph[firstChar - mnMinCharPos]].maLinearPos.X() < 
scaledGlyphPos)
+        {
+            mvChar2Glyph[firstChar - mnMinCharPos] = mvGlyphs.size();
+            mvCharDxs[firstChar - mnMinCharPos] = static_cast<int>((bRtl ? 
thisBoundary : nextBoundary) * fScaling) + mnWidth + nDxOffset;
+            mvChar2BaseGlyph[firstChar - mnMinCharPos] = baseGlyph;
+            mvCharBreaks[firstChar - mnMinCharPos] = 
gr_cinfo_break_weight(gr_seg_cinfo(pSegment, gr_slot_before(baseSlot)));
+        }
+        mvGlyph2Char[baseGlyph] = firstChar;
+        append(pSegment, rArgs, baseSlot, thisBoundary, nextBoundary, 
fScaling, nDxOffset, true, firstChar, baseGlyph, bRtl);
+        if (thisBoundary < fMinX) fMinX = thisBoundary;
+        if (nextBoundary > fMaxX && (nextChar < mnMinCharPos || nextChar >= 
mnEndCharPos || !isWhite(pStr[nextChar]) || fMaxX <= 0.0f))
+            fMaxX = nextBoundary;
     }
     long nXOffset = round(fMinX * fScaling);
-    mnWidth = round(fMaxX * fScaling) - nXOffset + nDxOffset;
-    if (mnWidth < 0)
-    {
-        // This can happen when there was no base inside the range
-        mnWidth = 0;
-    }
+    long nXEnd = round(fMaxX * fScaling);
+    int nCharRequested = minimum<int>(lastCharPos, mnEndCharPos) - 
mnMinCharPos;
+    int firstCharOffset = maximum<int>(mnSegCharOffset, mnMinCharPos) - 
mnMinCharPos;
     // fill up non-base char dx with cluster widths from previous base glyph
     if (bRtl)
     {
         if (mvCharDxs[nCharRequested-1] == -1)
-            mvCharDxs[nCharRequested-1] = 0;
+            mvCharDxs[nCharRequested-1] = nXEnd - nXOffset + mnWidth + 
nDxOffset;
         else
-            mvCharDxs[nCharRequested-1] -= nXOffset;
-        for (int i = nCharRequested - 2; i >= 0; i--)
+            mvCharDxs[nCharRequested-1] = nXEnd - mvCharDxs[nCharRequested-1] 
+ 2 * (mnWidth + nDxOffset);
+#ifdef GRLAYOUT_DEBUG
+            fprintf(grLog(),"%d,%d ", nCharRequested - 1, 
(int)mvCharDxs[nCharRequested-1]);
+#endif
+        for (int i = nCharRequested - 2; i >= firstCharOffset; i--)
         {
             if (mvCharDxs[i] == -1) mvCharDxs[i] = mvCharDxs[i+1];
-            else mvCharDxs[i] -= nXOffset;
+            else mvCharDxs[i] = nXEnd - mvCharDxs[i] + 2 * (mnWidth + 
nDxOffset);
+#ifdef GRLAYOUT_DEBUG
+            fprintf(grLog(),"%d,%d ", (int)i, (int)mvCharDxs[i]);
+#endif
         }
     }
     else
     {
-        if (mvCharDxs[0] == -1)
-            mvCharDxs[0] = 0;
+        if (mvCharDxs[firstCharOffset] == -1)
+            mvCharDxs[firstCharOffset] = 0;
         else
-            mvCharDxs[0] -= nXOffset;
-        for (int i = 1; i < nCharRequested; i++)
+            mvCharDxs[firstCharOffset] -= nXOffset;
+#ifdef GRLAYOUT_DEBUG
+            fprintf(grLog(),"%d,%d ", firstCharOffset, 
(int)mvCharDxs[firstCharOffset]);
+#endif
+        for (int i = firstCharOffset + 1; i < nCharRequested; i++)
         {
             if (mvCharDxs[i] == -1) mvCharDxs[i] = mvCharDxs[i-1];
             else mvCharDxs[i] -= nXOffset;
@@ -392,11 +281,17 @@ GraphiteLayout::fillFrom(gr_segment * pSegment, 
ImplLayoutArgs &rArgs, float fSc
     // remove offset due to context if there is one
     if (nXOffset != 0)
     {
-        for (size_t i = 0; i < mvGlyphs.size(); i++)
+        for (size_t i = origNumGlyphs; i < mvGlyphs.size(); i++)
             mvGlyphs[i].maLinearPos.X() -= nXOffset;
     }
+    mnWidth += nXEnd - nXOffset + nDxOffset;
+    if (mnWidth < 0)
+    {
+        // This can happen when there was no base inside the range
+        mnWidth = 0;
+    }
 #ifdef GRLAYOUT_DEBUG
-    fprintf(grLog(), "fillFrom %" SAL_PRI_SIZET "u glyphs offset %ld width 
%ld\n", mvGlyphs.size(), nXOffset, mnWidth);
+    fprintf(grLog(), "fillFrom %" SAL_PRI_SIZET "u glyphs offset %ld width %ld 
for %d\n", mvGlyphs.size(), nXOffset, mnWidth, nCharRequested);
 #endif
 }
 
@@ -405,37 +300,29 @@ GraphiteLayout::fillFrom(gr_segment * pSegment, 
ImplLayoutArgs &rArgs, float fSc
 float
 GraphiteLayout::append(gr_segment *pSeg, ImplLayoutArgs &rArgs,
     const gr_slot * gi, float gOrigin, float nextGlyphOrigin, float scaling, 
long & rDXOffset,
-    bool bIsBase, int baseChar)
+    bool bIsBase, int baseChar, int baseGlyph, bool bRtl)
 {
-    bool bRtl = (rArgs.mnFlags & SAL_LAYOUT_BIDI_RTL);
-    float nextOrigin;
     assert(gi);
-    assert(gr_slot_before(gi) <= gr_slot_after(gi));
-    int firstChar = gr_slot_before(gi) + mnSegCharOffset;
+    // assert(gr_slot_before(gi) <= gr_slot_after(gi));
+    int firstChar = gr_cinfo_base(gr_seg_cinfo(pSeg, gr_slot_before(gi))) + 
mnSegCharOffset;
     assert(mvGlyphs.size() < mvGlyph2Char.size());
-    if (!bIsBase) mvGlyph2Char[mvGlyphs.size()] = baseChar;//firstChar;
-    // is the next glyph attached or in the next cluster?
-    //glyph_set_range_t iAttached = gi.attachedClusterGlyphs();
-    const gr_slot * pFirstAttached = gr_slot_first_attachment(gi);
-    const gr_slot * pNextSibling = gr_slot_next_sibling_attachment(gi);
-    if (pFirstAttached)
-        nextOrigin = gr_slot_origin_X(pFirstAttached);
-    else if (!bIsBase && pNextSibling)
-        nextOrigin = gr_slot_origin_X(pNextSibling);
-    else
-        nextOrigin = nextGlyphOrigin;
+    if (firstChar < mnMinCharPos || firstChar >= mnEndCharPos)
+        return nextGlyphOrigin;
+
     long glyphId = gr_slot_gid(gi);
     long deltaOffset = 0;
-    int scaledGlyphPos = round(gr_slot_origin_X(gi) * scaling);
-    int glyphWidth = round((nextOrigin - gOrigin) * scaling);
-//    if (glyphWidth < 0)
-//    {
-//        nextOrigin = gOrigin;
-//        glyphWidth = 0;
-//    }
+    int scaledGlyphPos = round(gr_slot_origin_X(gi) * scaling) + mnWidth + 
rDXOffset;
+    int glyphWidth = round((nextGlyphOrigin - gOrigin) * scaling);
+    if (!bIsBase)
+    {
+        mvChar2BaseGlyph[firstChar - mnMinCharPos] = baseGlyph;
+        mvCharDxs[firstChar - mnMinCharPos] = mvCharDxs[baseChar - 
mnMinCharPos];
+        mvCharBreaks[firstChar - mnMinCharPos] = 
gr_cinfo_break_weight(gr_seg_cinfo(pSeg, gr_slot_before(gi)));
+    }
+
 #ifdef GRLAYOUT_DEBUG
-    fprintf(grLog(),"c%d g%ld,X%d W%d nX%f ", firstChar, glyphId,
-        (int)(gr_slot_origin_X(gi) * scaling), glyphWidth, nextOrigin * 
scaling);
+    fprintf(grLog(),"c%d g%ld,X%d W%d nX%f @%d=%d ", firstChar, glyphId,
+        scaledGlyphPos, glyphWidth, nextGlyphOrigin * scaling, 
mvChar2Glyph[firstChar-mnMinCharPos], mvCharDxs[firstChar-mnMinCharPos]);
 #endif
     if (glyphId == 0)
     {
@@ -465,11 +352,12 @@ GraphiteLayout::append(gr_segment *pSeg, ImplLayoutArgs 
&rArgs,
     }
     // append this glyph. Set the cluster flag if this glyph is attached to 
another
     long nGlyphFlags = bIsBase ? 0 : GlyphItem::IS_IN_CLUSTER;
+    if (gr_slot_attached_to(gi))
+        nGlyphFlags |= GlyphItem::IS_DIACRITIC;
     nGlyphFlags |= (bRtl)? GlyphItem::IS_RTL_GLYPH : 0;
     GlyphItem aGlyphItem(mvGlyphs.size(),
         glyphId,
-        Point(scaledGlyphPos + rDXOffset,
-            round((-gr_slot_origin_Y(gi) * scaling))),
+        Point(scaledGlyphPos, round((-gr_slot_origin_Y(gi) * scaling))),
         nGlyphFlags,
         glyphWidth);
     if (glyphId != static_cast<long>(GF_DROPPED))
@@ -480,9 +368,10 @@ GraphiteLayout::append(gr_segment *pSeg, ImplLayoutArgs 
&rArgs,
     rDXOffset += deltaOffset;
 
     // Recursively append all the attached glyphs.
-    float cOrigin = nextOrigin;
+    float cOrigin = nextGlyphOrigin;
     for (const gr_slot * agi = gr_slot_first_attachment(gi); agi != NULL; agi 
= gr_slot_next_sibling_attachment(agi))
-        cOrigin = append(pSeg, rArgs, agi, cOrigin, nextGlyphOrigin, scaling, 
rDXOffset, false, baseChar);
+        if (!gr_slot_can_insert_before(agi))
+            cOrigin = append(pSeg, rArgs, agi, cOrigin, nextGlyphOrigin, 
scaling, rDXOffset, false, baseChar, baseGlyph, bRtl);
 
     return cOrigin;
 }
@@ -516,6 +405,7 @@ void GraphiteLayout::clear()
     mvGlyphs.clear();
     mvCharDxs.clear();
     mvChar2BaseGlyph.clear();
+    mvChar2Glyph.clear();
     mvGlyph2Char.clear();
 
     // Reset the state to the empty state.
@@ -526,168 +416,61 @@ void GraphiteLayout::clear()
 // This method shouldn't be called on windows, since it needs the dc reset
 bool GraphiteLayout::LayoutText(ImplLayoutArgs & rArgs)
 {
+    clear();
     bool success = true;
-    if (rArgs.mnMinCharPos < rArgs.mnEndCharPos)
-    {

... etc. - the rest is truncated
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to