groffstudio

Diff
Login

Differences From Artifact [a3a810c1b6]:

To Artifact [2e85f0db1a]:


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, StdCtrls,
  ExtCtrls, Buttons, ExtendedNotebook, SynEdit, fphttpclient, RegExpr, LCLIntf,
  LCLType, IniPropStorage, ComboEx, Process, Helpers, fileinfo,
  {$IF DEFINED(WINDOWS)}
  winpeimagereader, opensslsockets,
  {$ELSEIF DEFINED(DARWIN)}
  machoreader, ssockets, sslsockets, sslbase, opensslsockets,
  {$ELSEIF DEFINED(LINUX)}
  elfreader,
  {$ENDIF}
  BuildOutputWindow;

type

  { TMainForm }

  TMainForm = class(TForm)







|

|

|

|







19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, StdCtrls,
  ExtCtrls, Buttons, ExtendedNotebook, SynEdit, fphttpclient, RegExpr, LCLIntf,
  LCLType, IniPropStorage, ComboEx, Process, Helpers, fileinfo,
{$IF DEFINED(WINDOWS)}
  winpeimagereader, opensslsockets,
{$ELSEIF DEFINED(DARWIN)}
  machoreader, ssockets, sslsockets, sslbase, opensslsockets,
{$ELSEIF DEFINED(LINUX)}
  elfreader,
{$ENDIF}
  BuildOutputWindow;

type

  { TMainForm }

  TMainForm = class(TForm)
48
49
50
51
52
53
54

55
56
57
58
59
60
61
62
63
64
65
66

67
68
69
70
71
72
73
    chkBoxPreprocessors: TCheckComboBox;
    chkUpdateCheckOnStart: TCheckBox;
    chkLogFile: TCheckBox;
    chkAutoSaveBuildSettings: TCheckBox;
    cmbMacro: TComboBox;
    edtGroffInstalledVersion: TEdit;
    edtGroffstudioInstalledVersion: TEdit;

    edtOnlineGroffVersionWindows: TEdit;
    ExtendedNotebook1: TExtendedNotebook;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    GroupBox3: TGroupBox;
    iniStorage: TIniPropStorage;
    Label1: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;

    lblGithubRepo: TLabel;
    lblFossilRepo: TLabel;
    lblWebsite: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;







>












>







48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
    chkBoxPreprocessors: TCheckComboBox;
    chkUpdateCheckOnStart: TCheckBox;
    chkLogFile: TCheckBox;
    chkAutoSaveBuildSettings: TCheckBox;
    cmbMacro: TComboBox;
    edtGroffInstalledVersion: TEdit;
    edtGroffstudioInstalledVersion: TEdit;
    edtGhostscriptInstalledVersion: TEdit;
    edtOnlineGroffVersionWindows: TEdit;
    ExtendedNotebook1: TExtendedNotebook;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    GroupBox3: TGroupBox;
    iniStorage: TIniPropStorage;
    Label1: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    lblGithubRepo: TLabel;
    lblFossilRepo: TLabel;
    lblWebsite: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
    procedure chkUseGhostscriptChange(Sender: TObject);
    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure lblFossilRepoClick(Sender: TObject);
    procedure lblGithubRepoClick(Sender: TObject);
    procedure lblWebsiteClick(Sender: TObject);
    procedure SynEdit1Change(Sender: TObject);
    {$IFDEF DARWIN}
    procedure GetSocketHandler(Sender: TObject; const UseSSL: Boolean; out AHandler: TSocketHandler);
    {$ENDIF}
  private
  var
    currentGroffFilePath: string;
    currentGroffFileName: string;
    unsavedChanges: boolean;
    {$IFDEF WINDOWS}
    latestGroffWindowsUrl: String;
    {$ENDIF}
    // Settings:
    storeBuildSettings: boolean;
    updateCheck: boolean;
  public

  end;








|

|





|

|







98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
    procedure chkUseGhostscriptChange(Sender: TObject);
    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure lblFossilRepoClick(Sender: TObject);
    procedure lblGithubRepoClick(Sender: TObject);
    procedure lblWebsiteClick(Sender: TObject);
    procedure SynEdit1Change(Sender: TObject);
{$IFDEF DARWIN}
    procedure GetSocketHandler(Sender: TObject; const UseSSL: Boolean; out AHandler: TSocketHandler);
{$ENDIF}
  private
  var
    currentGroffFilePath: string;
    currentGroffFileName: string;
    unsavedChanges: boolean;
{$IFDEF WINDOWS}
    latestGroffWindowsUrl: String;
{$ENDIF}
    // Settings:
    storeBuildSettings: boolean;
    updateCheck: boolean;
  public

  end;

128
129
130
131
132
133
134

135
136
137
138
139
140
141
var
  MainForm: TMainForm;
  BuildWindow: TBuildStatusWindow;
  hasGroff: boolean;
  hasGhostscript: boolean;
  GroffOutputVersion: string;
  ps2pdfOutput: string;


implementation

{$R *.lfm}

procedure TDetectGroffThread.UpdateUI;
begin







>







130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
var
  MainForm: TMainForm;
  BuildWindow: TBuildStatusWindow;
  hasGroff: boolean;
  hasGhostscript: boolean;
  GroffOutputVersion: string;
  ps2pdfOutput: string;
  GhostscriptOutputVersion: string;

implementation

{$R *.lfm}

procedure TDetectGroffThread.UpdateUI;
begin
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172


173
174
175
176
177
178
179
180






181
182
183
184
185
186
187
188

189
190
191
192


193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
    hasGroff := True;
    MainForm.edtGroffInstalledVersion.Text := GroffOutputVersion;
  end;

  // Try to find ps2pdf:
  if pos('ps2pdf', ps2pdfOutput) = 0 then
  begin
    {$IFDEF WINDOWS}
    // ps2pdf is mandatory on Windows.
    ShowMessage('On Windows, for creating PDF files, you need Ghostscript installed.'
    + LineEnding + 'Sadly, groffstudio could not find ps2pdf.bat in your %PATH%, so '
    + 'writing PDF files will not be supported. Please install Ghostscript and make sure '
    + 'that the folder that contains ps2pdf.bat is in your %PATH%.');
    MainForm.rdPdf.Enabled := False;
    {$ENDIF}
    hasGhostscript := False;
    MainForm.chkUseGhostscript.Checked := False;
    MainForm.chkUseGhostscript.Enabled := False;


  end else begin
    hasGhostscript := True;
    {$IFDEF WINDOWS}
    MainForm.rdPdf.Enabled := True;
    MainForm.chkUseGhostscript.Checked := True;
    {$ENDIF}
    MainForm.chkUseGhostscript.Enabled := True;
  end;






end;

procedure TDetectGroffThread.Execute;
begin
  FreeOnTerminate := True;

  {$IFDEF WINDOWS}
  RunCommand('cmd', ['/c', 'troff --version'], GroffOutputVersion, [], swoHIDE);

  RunCommand('cmd', ['/c', 'ps2pdf'], ps2pdfOutput, [], swoHIDE);
  {$ELSE}
  RunCommand('/bin/sh', ['-c', 'troff --version'], GroffOutputVersion,
    [], swoHIDE);


  RunCommand('/bin/sh', ['-c', 'ps2pdf'], ps2pdfOutput, [], swoHIDE);
  {$ENDIF}
  Synchronize(@UpdateUI);
end;

{ TMainForm }

procedure TMainForm.FormCreate(Sender: TObject);
var
  OnlineVersionsFile: string;
  {$IFDEF WINDOWS}
  reGroffVersion: TRegExpr;
  {$ENDIF}
  reGroffStudioVersion: TRegExpr;
  FileVerInfo: TFileVersionInfo;
  HasVersionUpdate: integer;
  GroffHelpers: TGroffHelpers;
  ResStream: TResourceStream;
  {$IFDEF DARWIN}
  HTTPClient: TFPHttpClient;
  {$ENDIF}
begin
  // What's the current running groff version?
  TDetectGroffThread.Create(False);

  // Default file name
  currentGroffFileName := '[unsaved file]';

  // Embed the license
  ResStream := TResourceStream.Create(HInstance, 'LICENSE', RT_RCDATA);
  try
    mLicense.Lines.LoadFromStream(ResStream);
  finally
    ResStream.Free;
  end;

  {$IFNDEF WINDOWS}
  // Ghostscript is not optional on Windows.
  // On other platforms, let's use the stored setting.
  chkUseGhostscript.Checked := iniStorage.ReadBoolean('UseGhostscript', False);
  {$ENDIF}

  // Restore the settings
  iniStorage.Restore;
  storeBuildSettings := iniStorage.ReadBoolean('AutoSaveBuildSettings', False);
  chkAutoSaveBuildSettings.Checked := storeBuildSettings;

  {$IF DEFINED(LINUX) OR DEFINED(BSD)}
  // On platforms which probably use a package manager (currently, Linux and
  // BSDs), the "update check" checkbox is disabled.
  chkUpdateCheckOnStart.Enabled := False;
  {$ELSE}
  updateCheck := iniStorage.ReadBoolean('UpdateCheckOnStart', False);
  chkUpdateCheckOnStart.Checked := updateCheck;
  {$ENDIF}

  if storeBuildSettings then
  begin
    chkLogFile.Checked := iniStorage.ReadBoolean('BuildLogFile', False);
    cmbMacro.Text := iniStorage.ReadString('BuildChosenMacro', '[ select ]');
    chkBoxPreprocessors.Checked[0] := iniStorage.ReadBoolean('BuildUseChem', False);
    chkBoxPreprocessors.Checked[1] := iniStorage.ReadBoolean('BuildUseEqn', False);







|






|



>
>
|

|


|


>
>
>
>
>
>






|

>

|


>
>

|








|

|





|

|















|



|






|



|


|







158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
    hasGroff := True;
    MainForm.edtGroffInstalledVersion.Text := GroffOutputVersion;
  end;

  // Try to find ps2pdf:
  if pos('ps2pdf', ps2pdfOutput) = 0 then
  begin
{$IFDEF WINDOWS}
    // ps2pdf is mandatory on Windows.
    ShowMessage('On Windows, for creating PDF files, you need Ghostscript installed.'
    + LineEnding + 'Sadly, groffstudio could not find ps2pdf.bat in your %PATH%, so '
    + 'writing PDF files will not be supported. Please install Ghostscript and make sure '
    + 'that the folder that contains ps2pdf.bat is in your %PATH%.');
    MainForm.rdPdf.Enabled := False;
{$ENDIF}
    hasGhostscript := False;
    MainForm.chkUseGhostscript.Checked := False;
    MainForm.chkUseGhostscript.Enabled := False;
  end
  else
  begin
    hasGhostscript := True;
{$IFDEF WINDOWS}
    MainForm.rdPdf.Enabled := True;
    MainForm.chkUseGhostscript.Checked := True;
{$ENDIF}
    MainForm.chkUseGhostscript.Enabled := True;
  end;

  // Try to find Ghostscript, just for displaying the version:
  if hasGhostscript then
    MainForm.edtGhostscriptInstalledVersion.Text := GhostscriptOutputVersion
  else
    MainForm.edtGhostscriptInstalledVersion.Text := 'n/a';
end;

procedure TDetectGroffThread.Execute;
begin
  FreeOnTerminate := True;

{$IFDEF WINDOWS}
  RunCommand('cmd', ['/c', 'troff --version'], GroffOutputVersion, [], swoHIDE);
  RunCommand('cmd', ['/c', 'gs --version'], GhostscriptOutputVersion, [], swoHIDE);
  RunCommand('cmd', ['/c', 'ps2pdf'], ps2pdfOutput, [], swoHIDE);
{$ELSE}
  RunCommand('/bin/sh', ['-c', 'troff --version'], GroffOutputVersion,
    [], swoHIDE);
  RunCommand('/bin/sh', ['-c', 'gs --version'], GhostscriptOutputVersion,
    [], swoHIDE);
  RunCommand('/bin/sh', ['-c', 'ps2pdf'], ps2pdfOutput, [], swoHIDE);
{$ENDIF}
  Synchronize(@UpdateUI);
end;

{ TMainForm }

procedure TMainForm.FormCreate(Sender: TObject);
var
  OnlineVersionsFile: string;
{$IFDEF WINDOWS}
  reGroffVersion: TRegExpr;
{$ENDIF}
  reGroffStudioVersion: TRegExpr;
  FileVerInfo: TFileVersionInfo;
  HasVersionUpdate: integer;
  GroffHelpers: TGroffHelpers;
  ResStream: TResourceStream;
{$IFDEF DARWIN}
  HTTPClient: TFPHttpClient;
{$ENDIF}
begin
  // What's the current running groff version?
  TDetectGroffThread.Create(False);

  // Default file name
  currentGroffFileName := '[unsaved file]';

  // Embed the license
  ResStream := TResourceStream.Create(HInstance, 'LICENSE', RT_RCDATA);
  try
    mLicense.Lines.LoadFromStream(ResStream);
  finally
    ResStream.Free;
  end;

{$IFNDEF WINDOWS}
  // Ghostscript is not optional on Windows.
  // On other platforms, let's use the stored setting.
  chkUseGhostscript.Checked := iniStorage.ReadBoolean('UseGhostscript', False);
{$ENDIF}

  // Restore the settings
  iniStorage.Restore;
  storeBuildSettings := iniStorage.ReadBoolean('AutoSaveBuildSettings', False);
  chkAutoSaveBuildSettings.Checked := storeBuildSettings;

{$IF DEFINED(LINUX) OR DEFINED(BSD)}
  // On platforms which probably use a package manager (currently, Linux and
  // BSDs), the "update check" checkbox is disabled.
  chkUpdateCheckOnStart.Enabled := False;
{$ELSE}
  updateCheck := iniStorage.ReadBoolean('UpdateCheckOnStart', False);
  chkUpdateCheckOnStart.Checked := updateCheck;
{$ENDIF}

  if storeBuildSettings then
  begin
    chkLogFile.Checked := iniStorage.ReadBoolean('BuildLogFile', False);
    cmbMacro.Text := iniStorage.ReadString('BuildChosenMacro', '[ select ]');
    chkBoxPreprocessors.Checked[0] := iniStorage.ReadBoolean('BuildUseChem', False);
    chkBoxPreprocessors.Checked[1] := iniStorage.ReadBoolean('BuildUseEqn', False);
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
    edtGroffStudioInstalledVersion.Text :=
      FileVerInfo.VersionStrings.Values['FileVersion'];
    lblAboutProductName.Caption :=
      FileVerInfo.VersionStrings.Values['ProductName'] + ' ' +
      FileVerInfo.VersionStrings.Values['FileVersion'];
    MainStatusBar.Panels[2].Text := '';

    {$IFDEF WINDOWS}
    if updateCheck then
    begin
      OnlineVersionsFile := TFPCustomHTTPClient.SimpleGet('https://groff.tuxproject.de/updates/versions.txt');

      // 1. groff update check
      reGroffVersion := TRegExpr.Create('groff-win ([\d\.]+) (.*)$');
      reGroffVersion.ModifierM := True;







|







284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
    edtGroffStudioInstalledVersion.Text :=
      FileVerInfo.VersionStrings.Values['FileVersion'];
    lblAboutProductName.Caption :=
      FileVerInfo.VersionStrings.Values['ProductName'] + ' ' +
      FileVerInfo.VersionStrings.Values['FileVersion'];
    MainStatusBar.Panels[2].Text := '';

{$IFDEF WINDOWS}
    if updateCheck then
    begin
      OnlineVersionsFile := TFPCustomHTTPClient.SimpleGet('https://groff.tuxproject.de/updates/versions.txt');

      // 1. groff update check
      reGroffVersion := TRegExpr.Create('groff-win ([\d\.]+) (.*)$');
      reGroffVersion.ModifierM := True;
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
        if HasVersionUpdate > 0 then
          MainStatusBar.Panels[2].Text := 'update ' + reGroffStudioVersion.Match[1] + ' available';
      end;
    end else begin
        edtOnlineGroffVersionWindows.Text := 'n/a';
        btnDownloadGroffWindows.Enabled := False;
    end;
    {$ELSE}
    // Non-Windows platforms won't need some of that.
    {$IFDEF DARWIN}
    // What's the latest available version?
    try
      if updateCheck then
      begin
        HTTPClient := TFPHTTPClient.Create(Nil);







|







315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
        if HasVersionUpdate > 0 then
          MainStatusBar.Panels[2].Text := 'update ' + reGroffStudioVersion.Match[1] + ' available';
      end;
    end else begin
        edtOnlineGroffVersionWindows.Text := 'n/a';
        btnDownloadGroffWindows.Enabled := False;
    end;
{$ELSE}
    // Non-Windows platforms won't need some of that.
    {$IFDEF DARWIN}
    // What's the latest available version?
    try
      if updateCheck then
      begin
        HTTPClient := TFPHTTPClient.Create(Nil);
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
      end;
    finally
      if updateCheck then HTTPClient.Free;
    end;
    {$ENDIF}
    edtOnlineGroffVersionWindows.Text := 'n/a';
    btnDownloadGroffWindows.Enabled := False;
    {$ENDIF}
  finally
    FileVerInfo.Free;
  end;

  // Loaded file display
  MainStatusBar.Panels[0].Text := '';








|







347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
      end;
    finally
      if updateCheck then HTTPClient.Free;
    end;
    {$ENDIF}
    edtOnlineGroffVersionWindows.Text := 'n/a';
    btnDownloadGroffWindows.Enabled := False;
{$ENDIF}
  finally
    FileVerInfo.Free;
  end;

  // Loaded file display
  MainStatusBar.Panels[0].Text := '';

369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
  // Set the "Changed" mark:
  MainStatusBar.Panels[0].Text := '* ' + currentGroffFileName;
  unsavedChanges := True;
end;

procedure TMainForm.btnDownloadGroffWindowsClick(Sender: TObject);
begin
  {$IFDEF WINDOWS}
   // On other systems, the button is disabled anyway.
   OpenURL(latestGroffWindowsUrl);
  {$ENDIF}
end;

procedure TMainForm.btnBuildClick(Sender: TObject);
var
  buildSuccess: boolean;
  buildOpts: string;
  logFileName: string = '';







|


|







383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
  // Set the "Changed" mark:
  MainStatusBar.Panels[0].Text := '* ' + currentGroffFileName;
  unsavedChanges := True;
end;

procedure TMainForm.btnDownloadGroffWindowsClick(Sender: TObject);
begin
{$IFDEF WINDOWS}
   // On other systems, the button is disabled anyway.
   OpenURL(latestGroffWindowsUrl);
{$ENDIF}
end;

procedure TMainForm.btnBuildClick(Sender: TObject);
var
  buildSuccess: boolean;
  buildOpts: string;
  logFileName: string = '';
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
  if chkBoxPreprocessors.Checked[3] then  buildOpts := buildOpts + ' -pic';
  if chkBoxPreprocessors.Checked[4] then  buildOpts := buildOpts + ' -refer';
  if chkBoxPreprocessors.Checked[5] then  buildOpts := buildOpts + ' -tbl';

  if chkBoxExtras.Checked[0] then  buildOpts := buildOpts + ' -mhdtbl';

  // - PDF-specifics:
  {$IFNDEF WINDOWS}
  // On Windows, we use a two-step program:
  // 1) Output to PostScript,
  // 2) ps2pdf to PDF.
  // This is because there is no pdfroff.exe. Requires Ghostscript.
  if rdPdf.Checked and not chkUseGhostscript.Checked then
  begin
    buildOpts := buildOpts + ' -Tpdf';
    if chkBoxExtras.Checked[1] then buildOpts := buildOpts + ' -mpdfmark';
    outputFileName := currentGroffFilePath + '.pdf';
  end
  else
  {$ENDIF}
    outputFileName := currentGroffFilePath + '.ps';

  // - Input file:
  buildOpts := buildOpts + ' ' + currentGroffFilePath;
  buildOpts := buildOpts + ' > ' + outputFileName;

  // - Log file:
  if chkLogFile.Checked then logFileName := currentGroffFilePath + '.log';

  // Build:
  buildSuccess := BuildWindow.BuildDocument(buildOpts, logFileName);

  {$IFDEF WINDOWS}
  if buildSuccess and hasGhostscript and rdPdf.Checked then
  {$ELSE}
  // On non-Windows systems, Ghostscript is entirely optional.
  if buildSuccess and hasGhostscript and chkUseGhostscript.Checked and rdPdf.Checked then
  {$ENDIF}
  begin
    // Invoke ps2pdf:
    buildOpts := 'ps2pdf';
    // outputFileName is still the .ps file. Just use it as the input name.
    buildOpts := buildOpts + ' ' + outputFileName;
    buildSuccess := BuildWindow.BuildDocument(buildOpts, logFileName);

    if buildSuccess and not chkKeepPostscriptFile.Checked then;
       DeleteFile(outputFileName); // get rid of the .ps fil
  end;

  if buildSuccess then
    MainStatusBar.Panels[1].Text := 'build successful'
  else
    MainStatusBar.Panels[1].Text := 'build problem';








|











|












|

|


|







|
|







422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
  if chkBoxPreprocessors.Checked[3] then  buildOpts := buildOpts + ' -pic';
  if chkBoxPreprocessors.Checked[4] then  buildOpts := buildOpts + ' -refer';
  if chkBoxPreprocessors.Checked[5] then  buildOpts := buildOpts + ' -tbl';

  if chkBoxExtras.Checked[0] then  buildOpts := buildOpts + ' -mhdtbl';

  // - PDF-specifics:
{$IFNDEF WINDOWS}
  // On Windows, we use a two-step program:
  // 1) Output to PostScript,
  // 2) ps2pdf to PDF.
  // This is because there is no pdfroff.exe. Requires Ghostscript.
  if rdPdf.Checked and not chkUseGhostscript.Checked then
  begin
    buildOpts := buildOpts + ' -Tpdf';
    if chkBoxExtras.Checked[1] then buildOpts := buildOpts + ' -mpdfmark';
    outputFileName := currentGroffFilePath + '.pdf';
  end
  else
{$ENDIF}
    outputFileName := currentGroffFilePath + '.ps';

  // - Input file:
  buildOpts := buildOpts + ' ' + currentGroffFilePath;
  buildOpts := buildOpts + ' > ' + outputFileName;

  // - Log file:
  if chkLogFile.Checked then logFileName := currentGroffFilePath + '.log';

  // Build:
  buildSuccess := BuildWindow.BuildDocument(buildOpts, logFileName);

{$IFDEF WINDOWS}
  if buildSuccess and hasGhostscript and rdPdf.Checked then
{$ELSE}
  // On non-Windows systems, Ghostscript is entirely optional.
  if buildSuccess and hasGhostscript and chkUseGhostscript.Checked and rdPdf.Checked then
{$ENDIF}
  begin
    // Invoke ps2pdf:
    buildOpts := 'ps2pdf';
    // outputFileName is still the .ps file. Just use it as the input name.
    buildOpts := buildOpts + ' ' + outputFileName;
    buildSuccess := BuildWindow.BuildDocument(buildOpts, logFileName);

    if buildSuccess and not chkKeepPostscriptFile.Checked then
       DeleteFile(outputFileName); // get rid of the .ps file
  end;

  if buildSuccess then
    MainStatusBar.Panels[1].Text := 'build successful'
  else
    MainStatusBar.Panels[1].Text := 'build problem';