#!/bin/bash

cd qtpdfium-master

## patch qtpdfium for windows build:

# # fix windows build: (Q_CC_MSV is not known, when QtGlobal is not included)
sed -i '325s/^/#if _FXM_PLATFORM_ == _FXM_PLATFORM_QT_\n#include <QtGlobal>\n#endif\n/' src/3rdparty/pdfium/core/fxcrt/fx_system.h
# # fix missing windows.h include 
sed -i '13s/^/#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ || (_FXM_PLATFORM_ == _FXM_PLATFORM_QT_ \&\& defined(Q_OS_WIN))\n#include <windows.h>\n#endif\n/'  src/3rdparty/pdfium/core/fxcrt/fx_stream.h
# fix windows.h desaster
for f in `fgrep "#include <windows.h>" src/ -ril`
do
    `sed -i "s/#include <windows.h>/#define NOMINMAX\n#include <windows.h>\n#ifdef GetObject\n#undef GetObject\n#endif\n/g" $f`
done

cd ../
