@echo off
setlocal

set bin=%~dp0
set lib=%bin%\..\lib

set jars=%lib%\w2x_rt.jar;%lib%\saxon.jar;%lib%\xmlresolver.jar;%lib%\whc.jar;%lib%\snowball.jar

if not exist "%lib%\wmf_converter.jar" goto skipwmf
set jars=%jars%;%lib%\wmf_converter.jar;%lib%\wmf2svg.jar
:skipwmf

if exist "%lib%\w2x.jar" goto usejar
set cp=%bin%\..\class;%jars%
goto setjre
:usejar
set cp=%lib%\w2x.jar;%jars%
:setjre

if not exist "%lib%\emf2png.jar" goto skipemf
set cp=%cp%;%lib%\emf2png.jar
:skipemf

set cp=%bin%\w2x_app.jar;%cp%;%bin%\flatlaf.jar;%bin%\w2x_app_cshelp.jar

if exist "%bin%\jre64\bin\java.exe" goto privatejre
set java=java
goto run
:privatejre
set java=%bin%\jre64\bin\java.exe
:run

rem --------------------------------------------------------------------------
rem Notes about the Java[tm] command line:
rem
rem * Disabled Java 9+ native HiDPI mode because the rendering of
rem   text and graphics is nicer using built-in HiDPI support:
rem   -Dsun.java2d.uiScale.enabled=false
rem   (option added after "-Xss4m -Xmx512m")
rem   You may re-enable Java 9+ native HiDPI mode by removing 
rem   this option.
rem 
rem * -Dsun.java2d.noddraw=true -Dsun.java2d.d3d=false are workaround 
rem   for various, sometime random, AWT bugs.
rem   For example, -Dsun.java2d.d3d=false is workaround for HiDPI bug
rem   https://bugs.openjdk.java.net/browse/JDK-8189416
rem --------------------------------------------------------------------------

"%java%" -Xss4m -Xmx512m -Dsun.java2d.uiScale.enabled=false -Dsun.java2d.noddraw=true -Dsun.java2d.d3d=false -DW2X_TRACE="%W2X_TRACE%" -DW2X_IMAGE_CONVERSIONS="%W2X_IMAGE_CONVERSIONS%" -DW2X_MATH_CONVERTER_XSLT="%W2X_MATH_CONVERTER_XSLT%" -Djava.library.path="%lib%" -classpath "%cp%" com.xmlmind.w2x_app.Start %*
