summaryrefslogtreecommitdiff
path: root/support/dktools/f2lto.ctr
blob: 7cfcf35eb979600080a44439bd42fcbfa842a636 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
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
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
%%	options

copyright owner	=	Dirk Krause
copyright year	=	2013-xxxx
license		=	bsd


%%	header

#ifdef __cplusplus
extern "C" {
#endif

/**	Register PS font in a storage.
	@param	sFonts		Fonts storage.
	@param	iFonts		Storage iterator.
	@param	nFonts		Pointer to variable for total number of used
				fonts.
	@param	fontno		PS font number.
	@param	fontsize	Font size.
	@param	app		Application structure for diagnostics.
	@return	Pointer to text handling on success, NULL on error.
*/
f2l_text_handling_t *
f2l_tool_register_font(
  dk3_sto_t		*sFonts,
  dk3_sto_it_t		*iFonts,
  unsigned long		*nFonts,
  int			 fontno,
  double		 fontsize,
  dk3_app_t		*app
);

/**	Start LaTeX part of EPS+TEX or PDF+TEX.
	@param	of		Output file.
	@param	job		Job structure.
	@param	drw		Drawing structure.
	@param	shortOutFile	Short output file name of EPS or PDF file.
	@param	iFonts		Font storage iterator.
	@param	nFonts		Total number of fonts.
*/
void
f2l_tool_start_tex_part(
  FILE			*of,
  f2l_job_t		*job,
  dk3_fig_drawing_t	*drw,
  char const		*shortOutFile,
  dk3_sto_it_t		*iFonts,
  unsigned long		 nFonts
);

/**	Start LaTeX part of EPS+TEX, PDF+TEX or PGF.
	@param	of		Output file.
	@param	job		Job structure.
	@param	drw		Drawing structure.
	@param	shortOutFile	Short output file name of EPS or PDF file.
	@param	iFonts		Font storage iterator.
	@param	nFonts		Total number of fonts.
	@param	wp		Flag: With picture environments.
*/
void
f2l_tool_start_tex_part_with_picture(
  FILE			*of,
  f2l_job_t		*job,
  dk3_fig_drawing_t	*drw,
  char const		*shortOutFile,
  dk3_sto_it_t		*iFonts,
  unsigned long		 nFonts,
  int			 wp
);

/**	End LaTeX part of EPS+TEX or PDF+TEX.
	@param	of	Output file.
*/
void
f2l_tool_end_tex_part(
  FILE			*of
);

/**	Write one font name.
	@param	of	Output file.
	@param	fontno	Number of font to write.
	@param	nFonts	Total number of font definitions.
*/
void
f2l_tool_write_font_name(
  FILE			*of,
  unsigned long		 fontno,
  unsigned long		 nFonts
);

/**	Write inner part of text object.
	This function is used both for writing to a picture environment
	in a *.tex file and pgf text labels.
	@param	of	Output file.
	@param	job	Job structure.
	@param	drw	Drawing structure.
	@param	obj	Text object.
	@param	nFonts	Total number of PS fonts.
*/
void
f2l_tool_inner_text_object(
  FILE			*of,
  f2l_job_t		*job,
  dk3_fig_drawing_t	*drw,
  dk3_fig_obj_t		*obj,
  unsigned long		 nFonts
);

/**	Write one text object to LaTeX output in a picture environment.
	@param	of	Output file.
	@param	job	Job structure.
	@param	drw	Drawing structure.
	@param	obj	Text object.
	@param	x	X position.
	@param	y	Y position.
	@param	nFonts	Total number of PS fonts.
*/
void
f2l_tool_text_object(
  FILE			*of,
  f2l_job_t		*job,
  dk3_fig_drawing_t	*drw,
  dk3_fig_obj_t		*obj,
  double		 x,
  double		 y,
  unsigned long		 nFonts
);

/**	Write commands to choose a font.
	@param	of	Output file.
	@param	job	Job structure.
	@param	drw	Drawing structure.
	@param	obj	Text object.
	@param	nFonts	Total number of PS fonts.
*/
void
f2l_tool_font_selection(
  FILE			*of,
  f2l_job_t		*job,
  dk3_fig_drawing_t	*drw,
  dk3_fig_obj_t		*obj,
  unsigned long		 nFonts
);

/**	Write string to LaTeX output.
	@param	of	Output file.
	@param	txt	String, ISO-LATIN-1 encoded.
*/
void
f2l_tool_tex_string(
  FILE			*of,
  char const		*txt
);

/**	Write instruction to select a font by features to LaTeX output.
	@param	of		Output file.
	@param	job		Job structure.
	@param	drw		Drawing structure.
	@param	obj		Text object.
	@param	fontSize	Font size.
	@param	fontFeatures	Font features.
	@param	useFamily	Flag: Choose font family.
*/
void
f2l_tool_font_select_by_features(
  FILE			*of,
  f2l_job_t		*job,
  dk3_fig_drawing_t	*drw,
  dk3_fig_obj_t		*obj,
  double		 fontSize,
  int			 fontFeatures,
  int			 useFamily
);

/**	Create image file data.
	@param	filename	File name.
	@param	app		Application structure for diagnostics.
	@param	li		Line number of object definition.
	@return	Pointer to image file data on success, NULL on error.
*/
f2l_image_t *
f2l_tool_image_new(char const *filename, dk3_app_t *app, unsigned long li);

/**	Destroy image data.
	@param	im	Image data to destroy.
*/
void
f2l_tool_image_delete(f2l_image_t *im);

/**	Compare two image entries.
	@param	l	Left image entry.
	@param	r	Right image entry or unique file identifier.
	@param	cr	Comparison criteria (0=image/image, 1=image/ufi).
	@return	Comparison result.
*/
int
f2l_tool_compare_images(void const *l, void const *r, int cr);

/**	Set exit status code to error code if exit status indicates success.
	@param	job	Job structure.
	@param	exval	Error code.
*/
void
f2l_tool_set_exit_status(f2l_job_t *job, int exval);

/**	Begin LaTeX document (write document preamble and begin document line).
	@param	of	Output file.
	@param	job	Job structure.
	@param	drw	Drawing structure.
*/
void
f2l_tool_begin_latex_document(
  FILE			*of,
  f2l_job_t		*job,
  dk3_fig_drawing_t	*drw
);

/**	End LaTeX document (write end document line).
	@param	of	Output file.
	@param	job	Job structure.
	@param	drw	Drawing structure.
*/
void
f2l_tool_end_latex_document(
  FILE			*of,
  f2l_job_t		*job,
  dk3_fig_drawing_t	*drw
);

/**	Find drawing direction for embedded image.
	@param	job	Job structure.
	@param	drw	Drawing structure.
	@param	obj	Current object to process.
	@param	ec	Pointer to error code variable, may be NULL.
	@return	Drawing direction.
*/
int
f2lto_find_draw_direction(
  f2l_job_t		*job,
  dk3_fig_drawing_t	*drw,
  dk3_fig_obj_t		*obj,
  int			*ec
);

/**	Find suitable length for gaps in line styles.
	@param	job	Job structure.
	@param	lw	Line width.
	@param	lsv	Style value.
	@return	Gap length.
*/
double
f2lto_find_gap_length(f2l_job_t *job, double lw, double lsv);

#ifdef __cplusplus
}
#endif



%%	module

#include "dk3all.h"
#include "dk3bezcu.h"
#include "fig2lat.h"
#include "f2lud.h"
#include "f2lsvg.h"
#include "dk3figto.h"
#if 0
#include "dkt-version.h"
#endif
#include "dk4vers.h"
#include "dk3font.h"
#include "dk3bm.h"
#include "dk3bmeps.h"


$!trace-include



/**	LaTeX encodings for 0x00-0xFF.
*/
static char const * const f2l_tool_l2l_enc[] = {
/* 000 00 */ "",
/* 001 01 */ "",
/* 002 02 */ "",
/* 003 03 */ "",
/* 004 04 */ "",
/* 005 05 */ "",
/* 006 06 */ "",
/* 007 07 */ "",
/* 008 08 */ "",
/* 009 09 */ "\t",
/* 010 0a */ "\\\\*",
/* 011 0b */ "",
/* 012 0c */ "",
/* 013 0d */ "",
/* 014 0e */ "",
/* 015 0f */ "",
/* 016 10 */ "",
/* 017 11 */ "",
/* 018 12 */ "",
/* 019 13 */ "",
/* 020 14 */ "",
/* 021 15 */ "",
/* 022 16 */ "",
/* 023 17 */ "",
/* 024 18 */ "",
/* 025 19 */ "",
/* 026 1a */ "",
/* 027 1b */ "",
/* 028 1c */ "",
/* 029 1d */ "",
/* 030 1e */ "",
/* 031 1f */ "",
/* 032 20 */ " ",
/* 033 21 */ "!",
/* 034 22 */ "\\textquotedbl{}",
/* 035 23 */ "\\#",
/* 036 24 */ "\\textdollar{}",
/* 037 25 */ "\\%",
/* 038 26 */ "\\&",
/* 039 27 */ "\\textquoteright{}",
/* 040 28 */ "(",
/* 041 29 */ ")",
/* 042 2a */ "\\textasteriskcentered{}",
/* 043 2b */ "+",
/* 044 2c */ ",",
/* 045 2d */ "-",
/* 046 2e */ ".",
/* 047 2f */ "/",
/* 048 30 */ "0",
/* 049 31 */ "1",
/* 050 32 */ "2",
/* 051 33 */ "3",
/* 052 34 */ "4",
/* 053 35 */ "5",
/* 054 36 */ "6",
/* 055 37 */ "7",
/* 056 38 */ "8",
/* 057 39 */ "9",
/* 058 3a */ ":",
/* 059 3b */ ";",
/* 060 3c */ "\\textless{}",
/* 061 3d */ "=",
/* 062 3e */ "\\textgreater{}",
/* 063 3f */ "?",
/* 064 40 */ "@",
/* 065 41 */ "A",
/* 066 42 */ "B",
/* 067 43 */ "C",
/* 068 44 */ "D",
/* 069 45 */ "E",
/* 070 46 */ "F",
/* 071 47 */ "G",
/* 072 48 */ "H",
/* 073 49 */ "I",
/* 074 4a */ "J",
/* 075 4b */ "K",
/* 076 4c */ "L",
/* 077 4d */ "M",
/* 078 4e */ "N",
/* 079 4f */ "O",
/* 080 50 */ "P",
/* 081 51 */ "Q",
/* 082 52 */ "R",
/* 083 53 */ "S",
/* 084 54 */ "T",
/* 085 55 */ "U",
/* 086 56 */ "V",
/* 087 57 */ "W",
/* 088 58 */ "X",
/* 089 59 */ "Y",
/* 090 5a */ "Z",
/* 091 5b */ "[",
/* 092 5c */ "\\textbackslash{}",
/* 093 5d */ "]",
/* 094 5e */ "\\textasciicircum{}",
/* 095 5f */ "\\textunderscore{}",
/* 096 60 */ "\\textasciigrave{}",
/* 097 61 */ "a",
/* 098 62 */ "b",
/* 099 63 */ "c",
/* 100 64 */ "d",
/* 101 65 */ "e",
/* 102 66 */ "f",
/* 103 67 */ "g",
/* 104 68 */ "h",
/* 105 69 */ "i",
/* 106 6a */ "j",
/* 107 6b */ "k",
/* 108 6c */ "l",
/* 109 6d */ "m",
/* 110 6e */ "n",
/* 111 6f */ "o",
/* 112 70 */ "p",
/* 113 71 */ "q",
/* 114 72 */ "r",
/* 115 73 */ "s",
/* 116 74 */ "t",
/* 117 75 */ "u",
/* 118 76 */ "v",
/* 119 77 */ "w",
/* 120 78 */ "x",
/* 121 79 */ "y",
/* 122 7a */ "z",
/* 123 7b */ "\\textbraceleft{}",
/* 124 7c */ "\\textbar{}",
/* 125 7d */ "\\textbraceright{}",
/* 126 7e */ "\\textasciitilde{}",
/* 127 7f */ "",
/* 128 80 */ "",
/* 129 81 */ "",
/* 130 82 */ "",
/* 131 83 */ "",
/* 132 84 */ "",
/* 133 85 */ "",
/* 134 86 */ "",
/* 135 87 */ "",
/* 136 88 */ "",
/* 137 89 */ "",
/* 138 8a */ "",
/* 139 8b */ "",
/* 140 8c */ "",
/* 141 8d */ "",
/* 142 8e */ "",
/* 143 8f */ "",
/* 144 90 */ "",
/* 145 91 */ "",
/* 146 92 */ "",
/* 147 93 */ "",
/* 148 94 */ "",
/* 149 95 */ "",
/* 150 96 */ "",
/* 151 97 */ "",
/* 152 98 */ "",
/* 153 99 */ "",
/* 154 9a */ "",
/* 155 9b */ "",
/* 156 9c */ "",
/* 157 9d */ "",
/* 158 9e */ "",
/* 159 9f */ "",
/* 160 a0 */ "",
/* 161 a1 */ "\\textexclamdown{}",
/* 162 a2 */ "\\textcentoldstyle{}",
/* 163 a3 */ "\\textstirling{}",
/* 164 a4 */ "\\textcurrency{}",
/* 165 a5 */ "\\textyen{}",
/* 166 a6 */ "\\textbrokenbar{}",
/* 167 a7 */ "\\textsection{}",
/* 168 a8 */ "\\textasciidieresis{}",
/* 169 a9 */ "\\textcopyright{}",
/* 170 aa */ "\\textordfeminine{}",
/* 171 ab */ "\\quillemotleft{}",
/* 172 ac */ "\\textlnot{}",
/* 173 ad */ "",
/* 174 ae */ "\\textregistered{}",
/* 175 af */ "\\textasciimacron{}",
/* 176 b0 */ "\\textdegree{}",
/* 177 b1 */ "\\textpm{}",
/* 178 b2 */ "\\texttwosuperior{}",
/* 179 b3 */ "\\textthreesuperior{}",
/* 180 b4 */ "\\textasciiacute{}",
/* 181 b5 */ "\\textmu{}",
/* 182 b6 */ "\\P{}",
/* 183 b7 */ "\\textperiodcentered{}",
/* 184 b8 */ "\\c{}",
/* 185 b9 */ "\\textonesuperior{}",
/* 186 ba */ "\\textordmasculine{}",
/* 187 bb */ "\\quillemotright{}",
/* 188 bc */ "\\textonequarter{}",
/* 189 bd */ "\\textonehalf{}",
/* 190 be */ "\\textthreequarters{}",
/* 191 bf */ "?`",
/* 192 c0 */ "\\`{A}",
/* 193 c1 */ "\\'{A}",
/* 194 c2 */ "\\^{A}",
/* 195 c3 */ "\\~{A}",
/* 196 c4 */ "\\\"{A}",
/* 197 c5 */ "\\AA{}",
/* 198 c6 */ "\\AE{}",
/* 199 c7 */ "\\c{C}",
/* 200 c8 */ "\\`{E}",
/* 201 c9 */ "\\'{E}",
/* 202 ca */ "\\^{E}",
/* 203 cb */ "\\\"{E}",
/* 204 cc */ "\\`{I}",
/* 205 cd */ "\\'{I}",
/* 206 ce */ "\\^{I}",
/* 207 cf */ "\\\"{I}",
/* 208 d0 */ "\\DH{}",
/* 209 d1 */ "\\~{N}",
/* 210 d2 */ "\\`{O}",
/* 211 d3 */ "\\'{O}",
/* 212 d4 */ "\\^{O}",
/* 213 d5 */ "\\~{O}",
/* 214 d6 */ "\\\"{O}",
/* 215 d7 */ "\\texttimes{}",
/* 216 d8 */ "\\O{}",
/* 217 d9 */ "\\`{U}",
/* 218 da */ "\\'{U}",
/* 219 db */ "\\^{U}",
/* 220 dc */ "\\\"{U}",
/* 221 dd */ "\\'{Y}",
/* 222 de */ "\\TH{}",
/* 223 df */ "\\ss{}",
/* 224 e0 */ "\\`{a}",
/* 225 e1 */ "\\'{a}",
/* 226 e2 */ "\\^{a}",
/* 227 e3 */ "\\~{a}",
/* 228 e4 */ "\\\"{a}",
/* 229 e5 */ "\\aa{}",
/* 230 e6 */ "\\ae{}",
/* 231 e7 */ "\\c{c}",
/* 232 e8 */ "\\`{e}",
/* 233 e9 */ "\\'{e}",
/* 234 ea */ "\\^{e}",
/* 235 eb */ "\\\"{e}",
/* 236 ec */ "\\`{i}",
/* 237 ed */ "\\'{i}",
/* 238 ee */ "\\^{i}",
/* 239 ef */ "\\\"{i}",
/* 240 f0 */ "\\dh{}",
/* 241 f1 */ "\\~{n}",
/* 242 f2 */ "\\`{o}",
/* 243 f3 */ "\\'{o}",
/* 244 f4 */ "\\^{o}",
/* 245 f5 */ "\\~{o}",
/* 246 f6 */ "\\\"{o}",
/* 247 f7 */ "\\textdiv{}",
/* 248 f8 */ "\\o{}",
/* 249 f9 */ "\\`{u}",
/* 250 fa */ "\\'{u}",
/* 251 fb */ "\\^{u}",
/* 252 fc */ "\\\"{u}",
/* 253 fd */ "\\'{y}",
/* 254 fe */ "\\th{}",
/* 255 ff */ "\\\"{y}"
};


/**	Keywords used by the module.
*/
static char const * const	f2lto_c8_kw[] = {
$!string-table
#
#   0:	Begin a picture.
#
\\begin{picture}(0,0)\n
#
#   1:	End the picture.
#
\\end{picture}%\n
#
#   2:	Include a graphics file.
#
\\includegraphics{
#
#   3:	End of graphics file inclusion.
#
}\n
#
#   4:	Switch length unit to 1 bp.
#
\\setlength{\\unitlength}{1bp}%\n
#
#   5:	Begin picture of given width and height.
#
\\begin{picture}(%ld,%ld)\n
#
#   6:	Newfont instruction.
#
\\newfont{
#
#   7:	Between font name and definition.
#
}{
#
#   8:	End of font definition.
#
}%\n
#
#   9:	Start of all font names.
#
\\FigToLatFont
#
#  10:	Default font: ptmr
#
ptmr
#
#  11:	Keyword at.
#
 at 
#
#  12:	Font size unit pt.
#
pt
#
#  13:	Put instruction.
#
\\put(
#
#  14:	Comma.
#
,
#
#  15:	In put instruction.
#
){
#
#  16:	Closing curly bracket.
#
}
#
#  17:	rotatebox
#
\\rotatebox{
#
#  18:	makebox
#
\\makebox(0,0)[
#
#  19:	in makebox
#
]{
#
#  20:	Text position: left
#
lb
#
#  21:	Text position: centered
#
b
#
#  22:	Text position: right
#
rb
#
#  23:	smash instruction
#
\\smash{
#
#  24:	mbox instruction
#
\\mbox{
#
#  25:	Color instruction
#
\\color[rgb]{
#
#  26:	Newline
#
\n
#
#  27:	Reset font.
#
\\reset@font
#
#  28:	Select this font.
#
\\selectfont
#
#  29:	Font size.
#
\\fontsize{
#
#  30:	Font family: roman
#
\\fontfamily{\\rmdefault}
#
#  31:	Font family: sans-serif
#
\\fontfamily{\\sfdefault}
#
#  32:	Font family: typewriter
#
\\fontfamily{\\ttdefault}
#
#  33:	Font series: medium density
#
\\fontseries{\\mddefault}
#
#  34:	Font series: bold font
#
\\fontseries{\\bfdefault}
#
#  35:	Font shape: upright
#
\\fontshape{\\updefault}
#
#  36:	Font shape: italic
#
\\fontshape{\\itdefault}
#
#  37:	Font family: Default font family.
#
\\fontfamily{\\familydefault}
#
#  38:	Open a LaTeX group.
#
{
#
#  39:	End LaTeX document.
#
\\end{document}\n
#
#  40:	LaTeX document class
#
\\documentclass[%lgpt]{article}\n
#
#  41:	Paper width
#
\\setlength{\\paperwidth}{%ldbp}\n
#
#  42:	Paper height
#
\\setlength{\\paperheight}{%ldbp}\n
#
#  43:	Use package PGF core
#
\\usepackage{pgfcore}\n
#
#  44:	File name: f2lfonts.tex
#
f2lfonts.tex
#
#  45:	File name: f2lother.tex
#
f2lother.tex
#
#  46:	File opening mode: Read
#
r
$!end
};



/**	LaTeX preamble, part 1 (font encoding and font selection packages).
*/
static char const * const f2l_tool_preamble_1[] = {
$!text
% begin font setup
\usepackage[T1]{fontenc}
\usepackage{mathptmx}
\usepackage[scaled=.92]{helvet}
\usepackage{courier}
% end font setup
$!end
};



/**	LaTex preamble, part 2 (other packages).
*/
static char const * const f2l_tool_preamble_2[] = {
$!text
% begin other packages
\usepackage{textcomp}
\usepackage[intlimits]{amsmath}
% end other packages
$!end
};



/**	LaTeX preamble, part 3 (graphics and color).
*/
static char const * const f2l_tool_preamble_3[] = {
$!text
\usepackage{graphicx}
\usepackage{color}
$!end
};



/**	LaTeX preamble, part 4 (set borders to 0).
*/
static char const * const f2l_tool_preamble_4[] = {
$!text
\pagestyle{empty}
\setlength{\voffset}{-1in}
\setlength{\topmargin}{0bp}
\setlength{\headheight}{0bp}
\setlength{\headsep}{0bp}
\setlength{\topskip}{0bp}
\setlength{\hoffset}{-1in}
\setlength{\oddsidemargin}{0bp}
\setlength{\evensidemargin}{0bp}
\setlength{\marginparwidth}{0bp}
\setlength{\marginparsep}{0bp}
\setlength{\textwidth}{\paperwidth}
\setlength{\textheight}{\paperheight}
\setlength{\parskip}{0bp}
\setlength{\parindent}{0bp}
\setlength{\pdfpagewidth}{\paperwidth}
\setlength{\pdfpageheight}{\paperheight}
\begin{document}%
$!end
};



f2l_text_handling_t *
f2l_tool_register_font(
  dk3_sto_t		*sFonts,
  dk3_sto_it_t		*iFonts,
  unsigned long		*nFonts,
  int			 fontno,
  double		 fontsize,
  dk3_app_t		*app
)
{
  f2l_text_handling_t	 myth;		/* New text handling. */
  f2l_text_handling_t	*back = NULL;
  $? "+ f2l_tool_register_font %d %lg", fontno, fontsize
  if((sFonts) && (iFonts) && (nFonts)) {
    myth.fontSize = fontsize;	$? ". font size %lg", fontsize
    myth.fontNumber = 0UL;
    myth.psFontNo = fontno;	$? ". PS font no %d", fontno
    back = (f2l_text_handling_t *)dk3sto_it_find_like(iFonts,(void *)(&myth),0);
    if(!(back)) {		$? ". font not yet found"
      back = dk3_new_app(f2l_text_handling_t,1,app);
      if(back) {		$? ". new font ok"
        back->fontSize = fontsize;
	back->fontNumber = *(nFonts);
	back->psFontNo = fontno;
	if(fontno <  0) { back->psFontNo = 0; }
	if(fontno > 34) { back->psFontNo = 34; }
	if(dk3sto_add(sFonts, (void *)back)) {	$? ". add"
	  *nFonts += 1UL;
	  if(0UL == *nFonts) {
	    back = NULL;	/* Overflow */
	  }
	} else {				$? "! add"
	  dk3_delete(back);
	  back = NULL;
	}
      } else {			$? "! memory"
      }
    } else {	$? ". font found %d %lg", back->psFontNo, back->fontSize
    }
  } $? "- f2l_tool_register_font PTR=%d", TR_IPTR(back)
  return back;
}



void
f2l_tool_write_font_name(
  FILE			*of,
  unsigned long		 fontno,
  unsigned long		 nFonts
)
{
  char		 buffer[64];	/* Buffer for number converted to string. */
  char		*ptr;		/* Current character in buffer. */
  size_t	 lgt;		/* Length of current number. */
  size_t	 l1;		/* Length of maximum number. */
  size_t	 i;		/* Used to write leading zeros. */

  if(of) {
    fputs(f2lto_c8_kw[9], of);
    sprintf(buffer, "%lu", nFonts);
    lgt = strlen(buffer);
    sprintf(buffer, "%lu", fontno);
    l1  = strlen(buffer);
    for(i = l1; i < lgt; i++) { fputc('A', of); }
    ptr = buffer;
    while(*ptr) {
      switch(*ptr) {
        case '9': { fputc('J', of); } break;
        case '8': { fputc('I', of); } break;
        case '7': { fputc('H', of); } break;
        case '6': { fputc('G', of); } break;
        case '5': { fputc('F', of); } break;
        case '4': { fputc('E', of); } break;
        case '3': { fputc('D', of); } break;
        case '2': { fputc('C', of); } break;
        case '1': { fputc('B', of); } break;
        default:  { fputc('A', of); } break;
      }
      ptr++;
    }
  }
}



void
f2l_tool_start_tex_part_with_picture(
  FILE			*of,
  f2l_job_t		*job,
  dk3_fig_drawing_t	*drw,
  char const		*shortOutFile,
  dk3_sto_it_t		*iFonts,
  unsigned long		 nFonts,
  int			 wp
)
{
  f2l_text_handling_t	*th;		/* Current text handling. */
  char const		*psfontname;	/* PS font name. */
  double		 fs;		/* Font size. */

  if(wp) {
    /* begin{picture}(0,0) */
    fputs(f2lto_c8_kw[0], of);
    fputs(f2lto_c8_kw[2], of);
    fputs(shortOutFile, of);
    fputs(f2lto_c8_kw[3], of);
    /* end{picture} */
    fputs(f2lto_c8_kw[1], of);
    fputs(f2lto_c8_kw[4], of);
  }
  if((iFonts) && (nFonts)) {
    dk3sto_it_reset(iFonts);
    while(NULL != (th = (f2l_text_handling_t *)dk3sto_it_next(iFonts))) {
      fputs(f2lto_c8_kw[6], of);
      /* Write font name */
      f2l_tool_write_font_name(of, th->fontNumber, nFonts);
      fputs(f2lto_c8_kw[7], of);
      /* Write font description */
      psfontname = dk3font_get_tex_font_name(th->psFontNo);
      if(!(psfontname)) { psfontname = f2lto_c8_kw[10]; }
      fputs(psfontname, of);
      fputs(f2lto_c8_kw[11], of);
      fs = th->fontSize;
      if(job->nts > 0.0) {
        fs = fs * job->nts;
      }
      fs = dk3ma_d_restrict_digits(fs, 2);
      dk3ma_print_double_c8_no_sci(of, fs);
      fputs(f2lto_c8_kw[12], of);
      fputs(f2lto_c8_kw[8], of);
    }
  }
  if(wp) {
    fprintf(of, f2lto_c8_kw[5], job->lwidth, job->lheight);
  }
}




void
f2l_tool_start_tex_part(
  FILE			*of,
  f2l_job_t		*job,
  dk3_fig_drawing_t	*drw,
  char const		*shortOutFile,
  dk3_sto_it_t		*iFonts,
  unsigned long		 nFonts
)
{
  f2l_tool_start_tex_part_with_picture(
    of, job, drw, shortOutFile, iFonts, nFonts, 1
  );
}



void
f2l_tool_end_tex_part(
  FILE			*of
)
{
  fputs(f2lto_c8_kw[1], of);
}



/**	Write font size to output file.
	@param	of	Output file.
	@param	fs	Font size.
	@param	sp	Line base to line base distance.
*/
static
void
f2l_tool_write_font_size(
  FILE		*of,
  double	 fs,
  double	 sp
)
{

  fputs(f2lto_c8_kw[29], of);
  dk3ma_print_double_c8_no_sci(of, fs);
  fputs(f2lto_c8_kw[12], of);
  fputs(f2lto_c8_kw[7], of);
  dk3ma_print_double_c8_no_sci(of, sp);
  fputs(f2lto_c8_kw[12], of);
  fputs(f2lto_c8_kw[16], of);
}



void
f2l_tool_font_select_by_features(
  FILE			*of,
  f2l_job_t		*job,
  dk3_fig_drawing_t	*drw,
  dk3_fig_obj_t		*obj,
  double		 fontSize,
  int			 fontFeatures,
  int			 useFamily
)
{
  double 		 fs;	/* Font size. */
  double		 sp;	/* Line base to line base distance. */

  fs = fontSize;
  if(job->nts > 0.0) {
    fs = fs * job->nts;
  }
  sp = 1.2 * fs;
  fs = dk3ma_d_restrict_digits(fs, 2);
  sp = dk3ma_d_restrict_digits(sp, 2);
  if(useFamily) {
    /*
    	Complete font selection.
    */
    if(job->resfont) {
      fputs(f2lto_c8_kw[27], of);
    }
    /* Font size. */
    f2l_tool_write_font_size(of, fs, sp);
    /* Font family */
    switch(fontFeatures & DK3_FONT_FAMILY) {
      case DK3_FONT_TYPEWRITER: {
        fputs(f2lto_c8_kw[32], of);
      } break;
      case DK3_FONT_SANS_SERIF: {
        fputs(f2lto_c8_kw[31], of);
      } break;
      default: {
        fputs(f2lto_c8_kw[30], of);
      } break;
    }
    /* Font series */
    fputs(f2lto_c8_kw[(fontFeatures & DK3_FONT_BOLD) ? 34 : 33], of);
    /* Font shape */
    /*	2013-01-22 Correction to test with DK3_FONT_ITOB.
    */
    fputs(f2lto_c8_kw[(fontFeatures & DK3_FONT_ITOB) ? 36 : 35], of);
  } else {
    /*
    	Adjust the size only.
    */
    f2l_tool_write_font_size(of, fs, sp);
    fputs(f2lto_c8_kw[37], of);
    fputs(f2lto_c8_kw[33], of);
    fputs(f2lto_c8_kw[35], of);
  }
  fputs(f2lto_c8_kw[28], of);
}



void
f2l_tool_font_selection(
  FILE			*of,
  f2l_job_t		*job,
  dk3_fig_drawing_t	*drw,
  dk3_fig_obj_t		*obj,
  unsigned long		 nFonts
)
{
  f2l_text_handling_t	*th;		/* Text handling. */
  int			 ff;		/* Font flags. */
  int			 fontFeatures;	/* Font features. */

  ff = (obj->dt).txt.ff;
  /*
  	No font selection... for special text.
  */
  if(!(ff & DK3_FIG_FONT_FLAG_SPECIAL)) {
    if((ff & DK3_FIG_FONT_FLAG_PS) && (obj->dsd)) {
      /*
      	Use one of the defined fonts.
      */
      th = (f2l_text_handling_t *)(obj->dsd);
      f2l_tool_write_font_name(of, th->fontNumber, nFonts);
    } else {
      /*
      	Select font by features.
      */
      fontFeatures = DK3_FONT_ROMAN;
      if(ff & DK3_FIG_FONT_FLAG_PS) {
        /*
		Switch from PS font to font with similar features.
	*/
        fontFeatures = dk3font_get_features((obj->dt).txt.fo);
	f2l_tool_font_select_by_features(
	  of, job, drw, obj, (obj->dt).txt.fs, fontFeatures, 1
	);
      } else {
        /*
		Use LaTeX font with specified features.
	*/
        switch((obj->dt).txt.fo) {
	  case 0: {
	    f2l_tool_font_select_by_features(
	      of, job, drw, obj, (obj->dt).txt.fs, fontFeatures, 0
	    );
	  } break;
	  case 1: {
	    f2l_tool_font_select_by_features(
	      of, job, drw, obj, (obj->dt).txt.fs, fontFeatures, 1
	    );
	  } break;
	  case 2: {
	    fontFeatures |= DK3_FONT_BOLD;
	    f2l_tool_font_select_by_features(
	      of, job, drw, obj, (obj->dt).txt.fs, fontFeatures, 1
	    );
	  } break;
	  case 3: {
	    fontFeatures |= DK3_FONT_ITALIC;
	    f2l_tool_font_select_by_features(
	      of, job, drw, obj, (obj->dt).txt.fs, fontFeatures, 1
	    );
	  } break;
	  case 4: {
	    fontFeatures = DK3_FONT_SANS_SERIF;
	    f2l_tool_font_select_by_features(
	      of, job, drw, obj, (obj->dt).txt.fs, fontFeatures, 1
	    );
	  } break;
	  case 5: {
	    fontFeatures = DK3_FONT_TYPEWRITER;
	    f2l_tool_font_select_by_features(
	      of, job, drw, obj, (obj->dt).txt.fs, fontFeatures, 1
	    );
	  } break;
	  default: {
	    f2l_tool_font_select_by_features(
	      of, job, drw, obj, (obj->dt).txt.fs, fontFeatures, 1
	    );
	  } break;
	}
      }
    }
  }
}



void
f2l_tool_tex_string(
  FILE			*of,
  char const		*txt
)
{
  char const	*ptr;	/* Current input character to process. */
  char const	*sptr;	/* Output string for current input character. */
  char		 c;	/* Current input character. */
  unsigned char	 uc;	/* Current input character conv to unsigned char. */
  unsigned	 un;	/* Current input character converted to unsigned. */

  ptr = txt;
  while(*ptr) {
    c = *(ptr++);
    uc = (unsigned char)c;
    un = (unsigned)uc;
    while(un > 255) {
      un = un - 256;
    }
    sptr = f2l_tool_l2l_enc[un];
    if(sptr) {
      fputs(sptr, of);
    }
  }
}



/**	Write string, convert to UTF-8 if necessary.
	@param	txt	String to write.
	@param	fipo	Output file.
*/
static
void
f2lto_utf8_out(char const *txt, FILE *fipo)
{
  unsigned char	 buf[16];
  char const	*cptr;
  dk3_c32_t	 c32;
  size_t	 sz;
  size_t	 i;
  char		 c;

  cptr = txt;
  while(*cptr) {
    c = *(cptr++);
    c32 =  (dk3_c32_t)c;
    c32 &= 0x000000FFUL;
    if(c32 < 128UL) {
      fputc(c, fipo);
    } else {
      sz = dk3enc_uc2utf8(c32, buf, sizeof(buf));
      if(0 < sz) {
        for(i = 0; i < sz; i++) {
	  fputc(buf[i], fipo);
	}
      }
    }
  }
}



void
f2l_tool_inner_text_object(
  FILE			*of,
  f2l_job_t		*job,
  dk3_fig_drawing_t	*drw,
  dk3_fig_obj_t		*obj,
  unsigned long		 nFonts
)
{
  dk3_rgb_color_t	 rgb;	/* Color cell for text color. */

  rgb.r = rgb.g = rgb.b = 0.0;
  dk3fig_tool_find_color(&rgb, drw, obj->pc, 20);
  if(job->smash) {
    /* \smash{ */
    fputs(f2lto_c8_kw[23], of);
  }
  if(job->mbox) {
    /* \mbox{ */
    fputs(f2lto_c8_kw[24], of);
  }
  fputs(f2lto_c8_kw[38], of); 
  /* font selection */
  f2l_tool_font_selection(of, job, drw, obj, nFonts);
  fputs(f2lto_c8_kw[25], of);
  /* red */
  dk3ma_print_double_c8_no_sci(of, rgb.r);
  fputs(f2lto_c8_kw[14], of);
  /* green */
  dk3ma_print_double_c8_no_sci(of, rgb.g);
  fputs(f2lto_c8_kw[14], of);
  /* blue */
  dk3ma_print_double_c8_no_sci(of, rgb.b);
  fputs(f2lto_c8_kw[16], of);
  /* text */
  if(((obj->dt).txt.ff) & DK3_FIG_FONT_FLAG_SPECIAL) {
    if(job->stu8) {
      f2lto_utf8_out((obj->dt).txt.st, of);
    } else {
      fputs((obj->dt).txt.st, of);
    }
  } else {
    f2l_tool_tex_string(of, (obj->dt).txt.st);
  }
  fputs(f2lto_c8_kw[16], of);
  if(job->mbox) {
    /* } */
    fputs(f2lto_c8_kw[16], of);
  }
  if(job->smash) {
    /* } */
    fputs(f2lto_c8_kw[16], of);
  }
}


void
f2l_tool_text_object(
  FILE			*of,
  f2l_job_t		*job,
  dk3_fig_drawing_t	*drw,
  dk3_fig_obj_t		*obj,
  double		 x,
  double		 y,
  unsigned long		 nFonts
)
{
  double	 an;			/* Rotation in degree. */
  double	 ian;			/* Rotation as integer. */
  int		 haverotation = 0;	/* Flag: Have rotation. */

  /* \put( */
  fputs(f2lto_c8_kw[13], of);
  /* x position */
  dk3ma_print_double_c8_no_sci(of, x);
  /* , */
  fputs(f2lto_c8_kw[14], of);
  /* y position */
  dk3ma_print_double_c8_no_sci(of, y);
  /* ){ */
  fputs(f2lto_c8_kw[15], of);
  if(fabs((obj->dt).txt.an) > 1.0e-6) {
    haverotation = 1;
    an  = ((obj->dt).txt.an * 180.0) / M_PI;
    ian = dk3ma_d_rint(an);
    if(fabs(an - ian) < 1.0e-3) {
      an = ian;
    }
    /* \rotatebox{ */
    fputs(f2lto_c8_kw[17], of);
    /* degrees */
    dk3ma_print_double_c8_no_sci(of, an);
    /* }{ */
    fputs(f2lto_c8_kw[7], of);
  }
  /* \makebox(0,0)[ */
  fputs(f2lto_c8_kw[18], of);
  /* justification */
  switch(obj->st) {
    case 2: {
      fputs(f2lto_c8_kw[22], of);
    } break;
    case 1: {
      fputs(f2lto_c8_kw[21], of);
    } break;
    default: {
      fputs(f2lto_c8_kw[20], of);
    } break;
  }
  /* ]{ */
  fputs(f2lto_c8_kw[19], of);
  f2l_tool_inner_text_object(of, job, drw, obj, nFonts);
  /* } */
  fputs(f2lto_c8_kw[16], of);
  if(haverotation) {
    /* } */
    fputs(f2lto_c8_kw[16], of);
  }
  /* } */
  fputs(f2lto_c8_kw[16], of);
  fputs(f2lto_c8_kw[26], of);
}



void
f2l_tool_image_delete(f2l_image_t *im)
{
  $? "+ f2l_tool_image_delete"
  if(im) {	$? ". number = %lu", im->imageNumber
    dk3_release(im->filename);
    im->xo = NULL;
    im->width = 0UL;
    im->height = 0UL;
    im->xres = 0.0;
    im->yres = 0.0;
    im->imageNumber = 0UL;
    im->lineno = 0UL;
    dk3_delete(im);
  } $? "- f2l_tool_image_delete"
}



f2l_image_t *
f2l_tool_image_new(char const *filename, dk3_app_t *app, unsigned long li)
{
  dk3_ufi_t		 ufi;		/* Unique file identifier. */
  f2l_image_t		*back = NULL;
  $? "+ f2l_tool_image_new"
  if((filename) && (app)) {
    if(dk3ufi_c8_get(&ufi, filename)) {
      back = dk3_new_app(f2l_image_t,1,app);
      if(back) {
        dk3mem_cpy((void *)(&(back->ufi)), (void *)(&ufi), sizeof(dk3_ufi_t));
	back->xo = NULL;
	back->width = 0UL;
	back->height = 0UL;
	back->xres = 0.0;
	back->yres = 0.0;
	back->imageNumber = 0UL;
	back->lineno = li;
	back->filename = dk3str_c8_dup_app(filename, app);
	if(!(back->filename)) {
	  f2l_tool_image_delete(back);
	  back = NULL;
	}
      }
    }
  } $? "- f2l_tool_image_new PTR=%d", TR_IPTR(back)
  return back;
}



int
f2l_tool_compare_images(void const *l, void const *r, int cr)
{
  f2l_image_t const		*pl;		/* Left object. */
  f2l_image_t const		*pr;		/* Right object. */
  int		 		 back = 0;

  if(l) {
    if(r) {
      pl = (f2l_image_t const *)l;
      pr = (f2l_image_t const *)r;
      switch(cr) {
        case 1: {
	  back = dk3ufi_compare((void *)(&(pl->ufi)), r, 0);
	} break;
	default: {
	  back = dk3ufi_compare((void *)(&(pl->ufi)), (void *)(&(pr->ufi)), 0);
	} break;
      }
    } else { back = 1; }
  } else {
    if(r) { back = -1; }
  }
  return back;
}



void
f2l_tool_set_exit_status(f2l_job_t *job, int exval)
{
  if(job) {
    if(0 == job->exval) {
      job->exval = exval;
    }
  }
}



/**	Write entire section of text to output file.
	@param	of	Output file.
	@param	txt	Pointer to array of text lines, NULL-finalized.
*/
static
void
f2l_tool_add_text_section_to_file(FILE *of, char const * const *txt)
{
  char const * const	*ptr;	/* Current line to add. */

  ptr = txt;
  while(*ptr) {
    fputs(*ptr, of);
    fputc('\n', of);
    ptr++;
  }
}



/**	Write preamble part to output file, either the contents of a
	file (if found) or a default text.
	@param	of		Output file.
	@param	job		Job structure.
	@param	drw		Drawing structure.
	@param	fileName	Name of file containing the preamble part.
	@param	preamble	Default preamble text if fileName is not found.
*/
static
void
fl2_tool_write_preamble_part_or_file(
  FILE			*of,
  f2l_job_t		*job,
  dk3_fig_drawing_t	*drw,
  char const		*fileName,
  char const * const	*preamble
)
{
  char 		 line[1024];	/* Line buffer to read input file. */
  FILE		*fipo;		/* Input file. */
  int		 done = 0;	/* Flag: Successfully handled file. */
  $? "+ fl2_tool_write_preamble_part_or_file \"%!8s\"", TR_8STR(fileName)
  fipo = fopen(fileName, f2lto_c8_kw[46]);
  if(fipo) {		$? ". fipo ok"
    done = 1;
    while(fgets(line, sizeof(line), fipo)) {	$? ". line \"%!8s\"", line
      dk3str_c8_chomp(line, NULL);		$? ". chomp"
      fputs(line, of);				$? ". fputs"
      fputc('\n', of);				$? ". fputc"
    }
    fclose(fipo);
  } else {		$? "! failed to open file"
  }
  if(!(done)) {			$? ". not yet done"
    f2l_tool_add_text_section_to_file(of, preamble);
  }
  $? "- fl2_tool_write_preamble_part_or_file"
}



void
f2l_tool_begin_latex_document(
  FILE			*of,
  f2l_job_t		*job,
  dk3_fig_drawing_t	*drw
)
{
  fprintf(of, f2lto_c8_kw[40], job->tts);
#if 0
  f2l_tool_add_text_section_to_file(of, f2l_tool_preamble_1);
#else
  fl2_tool_write_preamble_part_or_file(
    of, job, drw, f2lto_c8_kw[44], f2l_tool_preamble_1
  );
#endif
#if 0
  f2l_tool_add_text_section_to_file(of, f2l_tool_preamble_2);
#else
  fl2_tool_write_preamble_part_or_file(
    of, job, drw, f2lto_c8_kw[45], f2l_tool_preamble_2
  );
#endif
  f2l_tool_add_text_section_to_file(of, f2l_tool_preamble_3);
  switch(job->dr) {
    case FIG2LAT_DRIVER_PGF:
    case FIG2LAT_DRIVER_TEX_FULL_PGF: {
      fputs(f2lto_c8_kw[43], of);
    } break;
  }
  fprintf(of, f2lto_c8_kw[41], job->lwidth);
  fprintf(of, f2lto_c8_kw[42], job->lheight);
  f2l_tool_add_text_section_to_file(of, f2l_tool_preamble_4);
}



void
f2l_tool_end_latex_document(
  FILE			*of,
  f2l_job_t		*job,
  dk3_fig_drawing_t	*drw
)
{
  fputs(f2lto_c8_kw[39], of);
}



int
f2lto_find_draw_direction(
  f2l_job_t		*job,
  dk3_fig_drawing_t	*drw,
  dk3_fig_obj_t		*obj,
  int			*ec
)
{
  dk3_fig_poly_point_t	*po;	/* Point set. */
  size_t		 np;	/* Number of points. */
  int		 back = 0;
  $? "+ f2lud_find_draw_direction"
  if(DK3_FIG_SRCTYPE_JFIG != drw->srctype) {		$? ". xfig/winfig"
    po = (obj->dt).pol.po;
    np = (obj->dt).pol.np;
    if(4 <= np) {					$? ". enough points"
      if(po[1].x > (dk3ma_d_add_ok(po[0].x, 0.5, ec))) {
        /* 0 on the left, 1 on the right */
	if(po[3].y > (dk3ma_d_add_ok(po[0].y, 0.5, ec))) {
	  back = 0;
	} else {
	  back = 1;
	}
      } else {
        if(po[1].x < (dk3ma_d_sub_ok(po[0].x, 0.5, ec))) {
	  /* 0 on the right, 1 on the left. */
	  if(po[3].y > (dk3ma_d_add_ok(po[0].y, 0.5, ec))) {
	    back = 2;
	  } else {
	    back = 3;
	  }
	} else {
	  /* 0 and 1 in one row. */
	  if(po[2].x > (dk3ma_d_add_ok(po[0].x, 0.5, ec))) {
	    /* 0 and 1 left */
	    if(po[1].y > (dk3ma_d_add_ok(po[0].y, 0.5, ec))) {
	      back = 0;
	    } else {
	      back = 1;
	    }
	  } else {
	    /* 0 and 1 right */
	    if(po[1].y > (dk3ma_d_add_ok(po[0].y, 0.5, ec))) {
	      back = 2;
	    } else {
	      back = 3;
	    }
	  }
	}
      }
      if((obj->dt).pol.flf) {		$? ". flip flag on"
        back += 4;
      } else {				$? ". flip flag off"
      }
    } else {				$? "! too few points"
    }
  } else {				$? ". jFig file"
  } $? "- f2lud_find_draw_direction %d", back
  return back;
}



double
f2lto_find_gap_length(f2l_job_t *job, double lw, double lsv)
{
  double	back;
  if(job->cols) {
    back = lsv;
  } else {
    back = 0.5 * lw + 0.5 * lsv;
    if((0.5 * back) > lw) {
      back = 2.0 * lw;
    }
  }
  return back;
}