Fix OTS warning about `maxp.maxSizeOfInstructions`.
[ttfautohint.git] / doc / make-snapshot.sh
blobfee70eaebf5fb3f296a641bba5493bb97b0c7b6b
1 #! /bin/sh
3 # Copyright (C) 2013-2022 by Werner Lemberg.
5 # This file is part of the ttfautohint library, and may only be used,
6 # modified, and distributed under the terms given in `COPYING'. By
7 # continuing to use, modify, or distribute this file you indicate that you
8 # have read `COPYING' and understand and accept it fully.
10 # The file `COPYING' mentioned in the previous paragraph is distributed
11 # with the ttfautohint library.
14 # make-snapshot.sh <application> [<application-options>...] > filename
16 # Make a snapshot from an application's start window and save it to a file.
17 # This needs X11 and ImageMagick's `import' tool.
19 # This script is very simple. Some possible problems:
21 # o In case the program doesn't create a visible X11 window, you have to
22 # abort the script with ^C.
24 # o It fails for intelligent applications like `firefox' in case they are
25 # already run, since firefox replaces the process with a new window of the
26 # already running instance.
28 # o It loops forever for programs like `k3b' that spawns itself, thus
29 # having a different process ID for the visible window.
32 # This script uses ideas from the now defunct site
33 # http://blog.chewearn.com/2010/01/18/find-window-id-of-a-process-id-in-bash-script/.
35 if [ $# -eq 0 ]; then
36 echo "Usage: $0 application [options...] > imagename"
37 exit 1
41 find_WID()
43 # Get all windows with the name $APP (ignoring case).
44 xwininfo -root -tree 2>/dev/null \
45 | grep -i $1 \
46 | while read DATA; do
47 # Extract Window ID.
48 WID=`echo $DATA | awk '{print $1}'`
50 # Check whether the window's PID is matching the application's PID.
51 # We use `=' for the comparison instead of `-eq' because `xprop'
52 # can return non-numerical values.
53 if [ `xprop -id $WID _NET_WM_PID | awk '{print $3}'` = $PID ]; then
54 # Check whether window is displayed actually.
55 if [ "`xwininfo -id $WID | grep 'IsViewable'`" != '' ]; then
56 echo $WID
57 return
60 done
64 # Start program in background and get its process ID.
65 $@ &
66 PID=$!
68 sleep 1
70 # Get application name.
71 APP=`ps --no-header -o comm -p $PID`
72 if [ "$APP" == "" ]; then
73 echo "Couldn't start application \`$@'"
74 exit 1
77 # Loop until program has displayed a window
78 # so that we can actually get the Windows ID.
79 while [ "$WID" == "" ]; do
80 WID=`find_WID $APP`
81 sleep 1
82 done
84 # Make snapshot.
85 import -silent -window $WID png:-
87 kill $PID
89 # eof