summaryrefslogtreecommitdiff
path: root/sw/source/filter/ww8/wrtw8esh.cxx
blob: 5e79c975b5571bb934c970353fab09a0cd3a3a91 (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
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
/*************************************************************************
 *
 *  $RCSfile: wrtw8esh.cxx,v $
 *
 *  $Revision: 1.57 $
 *
 *  last change: $Author: cmc $ $Date: 2002-12-10 12:41:14 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#ifdef PCH
#include "filt_pch.hxx"
#endif

#pragma hdrstop

#ifndef _HINTIDS_HXX
#include <hintids.hxx>
#endif

#define _SVSTDARR_ULONGSSORT
#define _SVSTDARR_USHORTS
#include <svtools/svstdarr.hxx>

#ifndef _SV_CVTGRF_HXX
#include <vcl/cvtgrf.hxx>
#endif
#ifndef _SV_VIRDEV_HXX
#include <vcl/virdev.hxx>
#endif

#ifndef _COM_SUN_STAR_DRAWING_XSHAPE_HPP_
#include <com/sun/star/drawing/XShape.hpp>
#endif
#ifndef _SV_SVAPP_HXX
#include <vcl/svapp.hxx>
#endif
#ifndef _SVSTOR_HXX
#include <so3/svstor.hxx>
#endif
#ifndef _IPOBJ_HXX
#include <so3/ipobj.hxx>
#endif
#ifndef _FILTER_HXX
#include <svtools/filter.hxx>
#endif
#ifndef _SFXITEMITER_HXX
#include <svtools/itemiter.hxx>
#endif
#ifndef _SVDOBJ_HXX
#include <svx/svdobj.hxx>
#endif
#ifndef _SVDOTEXT_HXX
#include <svx/svdotext.hxx>
#endif
#ifndef _SVDMODEL_HXX
#include <svx/svdmodel.hxx>
#endif
#ifndef _SVDPAGE_HXX
#include <svx/svdpage.hxx>
#endif
#ifndef _OUTLOBJ_HXX
#include <svx/outlobj.hxx>
#endif
#ifndef _EDITOBJ_HXX
#include <svx/editobj.hxx>
#endif
#ifndef _SVX_UNOSHAPE_HXX
#include <svx/unoshape.hxx>
#endif
#ifndef _SVX_BRSHITEM_HXX
#include <svx/brshitem.hxx>
#endif
#ifndef _SVX_BOXITEM_HXX
#include <svx/boxitem.hxx>
#endif
#ifndef _SVX_LRSPITEM_HXX
#include <svx/lrspitem.hxx>
#endif
#ifndef _SVX_ULSPITEM_HXX
#include <svx/ulspitem.hxx>
#endif
#ifndef _SVX_FONTITEM_HXX
#include <svx/fontitem.hxx>
#endif
#ifndef _SVX_FRMDIRITEM_HXX
#include <svx/frmdiritem.hxx>
#endif
#ifndef _SVDOOLE2_HXX
#include <svx/svdoole2.hxx>
#endif

#ifndef _MyEDITENG_HXX
#include <svx/editeng.hxx>
#endif
#ifndef _SVX_FLDITEM_HXX
//miserable hack to get around #98519#
#define ITEMID_FIELD            EE_FEATURE_FIELD
#include <svx/flditem.hxx>
#endif


#ifndef _SVX_FMGLOB_HXX
#include <svx/fmglob.hxx>
#endif
#ifndef _SVDOUNO_HXX
#include <svx/svdouno.hxx>
#endif
#ifndef _SVX_UNOAPI_HXX_
#include <svx/unoapi.hxx>
#endif
#ifndef _COM_SUN_STAR_UNO_REFERENCE_H_
#include <com/sun/star/uno/Reference.h>
#endif
#ifndef _COM_SUN_STAR_FORM_FORMCOMPONENTTYPE_HPP_
#include <com/sun/star/form/FormComponentType.hpp>
#endif

#ifndef _WRTWW8_HXX
#include <wrtww8.hxx>
#endif
#ifndef _FLYPOS_HXX
#include <flypos.hxx>
#endif
#ifndef _FMTCNCT_HXX
#include <fmtcnct.hxx>
#endif
#ifndef _FMTANCHR_HXX
#include <fmtanchr.hxx>
#endif
#ifndef _FMTSRND_HXX
#include <fmtsrnd.hxx>
#endif
#ifndef _FMTORNT_HXX
#include <fmtornt.hxx>
#endif
#ifndef _FMTFSIZE_HXX
#include <fmtfsize.hxx>
#endif
#ifndef _DCONTACT_HXX
#include <dcontact.hxx>
#endif
#ifndef _CALBCK_HXX
#include <calbck.hxx>
#endif
#ifndef _FRMFMT_HXX
#include <frmfmt.hxx>
#endif
#ifndef _FMTCNTNT_HXX
#include <fmtcntnt.hxx>
#endif
#ifndef _NDINDEX_HXX
#include <ndindex.hxx>
#endif
#ifndef _NODE_HXX
#include <node.hxx>
#endif
#ifndef _DOC_HXX
#include <doc.hxx>
#endif
#ifndef _DOCARY_HXX
#include <docary.hxx>
#endif
#ifndef _PAM_HXX
#include <pam.hxx>
#endif
#ifndef _SWRECT_HXX
#include <swrect.hxx>
#endif
#ifndef _NDGRF_HXX
#include <ndgrf.hxx>
#endif
#ifndef _GRFATR_HXX
#include <grfatr.hxx>
#endif
#ifndef _NDOLE_HXX
#include <ndole.hxx>
#endif
#ifndef _UNODRAW_HXX
#include <unodraw.hxx>
#endif
#ifndef _WW8PAR_HXX
#include <ww8par.hxx>
#endif
#ifndef _BREAKIT_HXX
#include <breakit.hxx>
#endif
#ifndef _COM_SUN_STAR_I18N_SCRIPTTYPE_HDL_
#include <com/sun/star/i18n/ScriptType.hdl>
#endif
#ifndef _ERRHDL_HXX
#include <errhdl.hxx>
#endif
#ifndef _GRFMGR_HXX
#include <goodies/grfmgr.hxx>
#endif

#ifndef _ESCHER_HXX
#include "escher.hxx"
#endif

using namespace ::com::sun::star;

namespace wwUtility
{
    Graphic MakeSafeGDIMetaFile(SvInPlaceObjectRef xObj);
};


PlcDrawObj::~PlcDrawObj()
{
}

void PlcDrawObj::WritePlc(SwWW8Writer& rWrt) const
{
    if (8 > rWrt.pFib->nVersion)    // Cannot export drawobject in vers 7-
        return;

    sal_uInt32 nFcStart = rWrt.pTableStrm->Tell();

    if (!maDrawObjs.empty())
    {
        // write CPs
        WW8Fib& rFib = *rWrt.pFib;
        WW8_CP nCpOffs = GetCpOffset(rFib);

        typedef ::std::vector<DrawObj>::const_iterator myiter;
        myiter aEnd = maDrawObjs.end();
        myiter aIter;

        for (aIter = maDrawObjs.begin(); aIter < aEnd; ++aIter)
            SwWW8Writer::WriteLong(*rWrt.pTableStrm, aIter->mnCp - nCpOffs);

        SwWW8Writer::WriteLong(*rWrt.pTableStrm, rFib.ccpText + rFib.ccpFtn +
            rFib.ccpHdr + rFib.ccpEdn + rFib.ccpTxbx + rFib.ccpHdrTxbx + 1);

        for (aIter = maDrawObjs.begin(); aIter < aEnd; ++aIter)
        {
            // write the fspa-struct
            const SwFrmFmt& rFmt = aIter->mrCntnt;
            const SdrObject* pObj = rFmt.FindRealSdrObject();

            Rectangle aRect;
            const SwFmtVertOrient& rVOr = rFmt.GetVertOrient();
            const SwFmtHoriOrient& rHOr = rFmt.GetHoriOrient();
            if (RES_FLYFRMFMT == rFmt.Which())
            {
                Point aObjPos;
                SwRect aLayRect(rFmt.FindLayoutRect(false, &aObjPos));
                // the Object is not visible - so get the values from
                // the format. The Position may not be correct.
                if( aLayRect.IsEmpty() )
                    aRect.SetSize( rFmt.GetFrmSize().GetSize() );
                else
                    aRect = aLayRect.SVRect();

                aRect -= aIter->maParentPos;
                aObjPos = aRect.TopLeft();
                if (VERT_NONE == rVOr.GetVertOrient())
                    aObjPos.Y() = rVOr.GetPos();
                if (HORI_NONE == rHOr.GetHoriOrient())
                    aObjPos.X() = rHOr.GetPos();
                aRect.SetPos( aObjPos );
            }
            else
            {
                ASSERT(pObj, "wo ist das SDR-Object?");
                if (pObj)
                    aRect = pObj->GetSnapRect();
                aRect -= aIter->maParentPos;
            }

            // spid
            SwWW8Writer::WriteLong(*rWrt.pTableStrm, aIter->mnShapeId);

            //xaLeft/yaTop/xaRight/yaBottom - rel. to anchor
            //(most of) the border is outside the graphic is word, so
            //change dimensions to fit
            SwWW8Writer::WriteLong(*rWrt.pTableStrm,aRect.Left() +
                aIter->mnThick);
            SwWW8Writer::WriteLong(*rWrt.pTableStrm,aRect.Top() +
                aIter->mnThick);
            SwWW8Writer::WriteLong(*rWrt.pTableStrm,aRect.Right() -
                aIter->mnThick);
            SwWW8Writer::WriteLong(*rWrt.pTableStrm,aRect.Bottom() -
                aIter->mnThick);

            //fHdr/bx/by/wr/wrk/fRcaSimple/fBelowText/fAnchorLock
            USHORT nFlags=0;
            //If nFlags isn't 0x14 its overridden by the escher properties
            if( FLY_PAGE == rFmt.GetAnchor().GetAnchorId())
                nFlags = 0x0000;
            else
                nFlags = 0x0014;        // x-rel to text,  y-rel to text

            const SwFmtSurround& rSurr = rFmt.GetSurround();
            USHORT nContour = rSurr.IsContour() ? 0x0080 : 0x0040;
            switch (rSurr.GetSurround())
            {
                case SURROUND_NONE:
                    nFlags |= 0x0020;
                    break;
                case SURROUND_THROUGHT:
                    nFlags |= 0x0060;
                    break;
                case SURROUND_PARALLEL:
                    nFlags |= 0x0000 | nContour;
                    break;
                case SURROUND_IDEAL:
                    nFlags |= 0x0600 | nContour;
                    break;
                case SURROUND_LEFT:
                    nFlags |= 0x0200 | nContour;
                    break;
                case SURROUND_RIGHT:
                    nFlags |= 0x0400 | nContour;
                    break;
            }
            if( pObj && pObj->GetLayer() == rWrt.pDoc->GetHellId() )
                nFlags |= 0x4000;

            SwWW8Writer::WriteShort(*rWrt.pTableStrm, nFlags);

            // cTxbx
            SwWW8Writer::WriteLong(*rWrt.pTableStrm, 0);
        }

        RegisterWithFib(rFib, nFcStart, rWrt.pTableStrm->Tell() - nFcStart);
    }
}

void MainTxtPlcDrawObj::RegisterWithFib(WW8Fib &rFib, sal_uInt32 nStart,
    sal_uInt32 nLen) const
{
    rFib.fcPlcfspaMom = nStart;
    rFib.lcbPlcfspaMom = nLen;
}

WW8_CP MainTxtPlcDrawObj::GetCpOffset(const WW8Fib &) const
{
    return 0;
}

void HdFtPlcDrawObj::RegisterWithFib(WW8Fib &rFib, sal_uInt32 nStart,
    sal_uInt32 nLen) const
{
    rFib.fcPlcfspaHdr = nStart;
    rFib.lcbPlcfspaHdr = nLen;
}

WW8_CP HdFtPlcDrawObj::GetCpOffset(const WW8Fib &rFib) const
{
    return rFib.ccpText + rFib.ccpFtn;
}

bool PlcDrawObj::Append(SwWW8Writer& rWrt, WW8_CP nCp, const SwFrmFmt& rFmt,
    const Point& rNdTopLeft)
{
    bool bRet = false;
    if (TXT_HDFT == rWrt.nTxtTyp || TXT_MAINTEXT == rWrt.nTxtTyp)
    {
        if (RES_FLYFRMFMT == rFmt.Which())
        {
            // check for textflyframe and if it is the first in a Chain
            if (rFmt.GetCntnt().GetCntntIdx())
                bRet = true;
        }
        else
            bRet = true;
    }

    if (bRet)
        maDrawObjs.push_back(
            DrawObj(rFmt,nCp,rNdTopLeft,rWrt.TrueFrameDirection(rFmt)));
    return bRet;
}

class HasThisFrame: public std::unary_function<const DrawObj &, bool>
{
private:
    const SwFrmFmt& mrFmt;
public:
    explicit HasThisFrame(const SwFrmFmt& rFmt) : mrFmt(rFmt) {}
    bool operator()(const DrawObj &rIn) const
    {
        return (&rIn.mrCntnt == &mrFmt);
    }
private:
    //No assignment
    HasThisFrame& operator=(const HasThisFrame&);
};

void PlcDrawObj::SetShapeDetails( const SwFrmFmt& rFmt, UINT32 nId,
    INT32 nThick )
{
    typedef ::std::vector<DrawObj>::iterator myiter;
    myiter aEnd = maDrawObjs.end();
    myiter aIter = ::std::find_if(maDrawObjs.begin(), aEnd, HasThisFrame(rFmt));
    if (aIter != aEnd)
    {
        aIter->mnShapeId = nId;
        aIter->mnThick = nThick;
    }
}

/*  */

bool WW8_WrPlcTxtBoxes::WriteTxt(SwWW8Writer& rWrt)
{
    bool bRet = false;
    rWrt.bInWriteEscher = true;
    long& rccp=TXT_TXTBOX == nTyp ? rWrt.pFib->ccpTxbx : rWrt.pFib->ccpHdrTxbx;

    bRet = WriteGenericTxt( rWrt, nTyp, rccp );

    WW8_CP nCP = rWrt.Fc2Cp( rWrt.Strm().Tell() );
    WW8Fib& rFib = *rWrt.pFib;
    long nMyOffset = rFib.ccpText + rFib.ccpFtn + rFib.ccpHdr + rFib.ccpAtn
                            + rFib.ccpEdn;
    if( TXT_TXTBOX == nTyp )
        rWrt.pFldTxtBxs->Finish( nCP, nMyOffset );
    else
        rWrt.pFldHFTxtBxs->Finish( nCP, nMyOffset + rFib.ccpTxbx );
    rWrt.bInWriteEscher = false;
    return bRet;
}

void WW8_WrPlcTxtBoxes::Append( const SdrObject& rObj, UINT32 nShapeId )
{
    void* p = (void*)&rObj;
    aCntnt.Insert( p, aCntnt.Count() );
    aShapeIds.Insert( nShapeId, aShapeIds.Count() );
}

const SvULongs* WW8_WrPlcTxtBoxes::GetShapeIdArr() const
{
    return &aShapeIds;
}

/*  */

UINT32 SwWW8Writer::GetSdrOrdNum( const SwFrmFmt& rFmt ) const
{
    UINT32 nOrdNum;
    const SdrObject* pObj = rFmt.FindRealSdrObject();
    if( pObj )
        nOrdNum = pObj->GetOrdNum();
    else
    {
        // no Layout for this format, then recalc the ordnum
        SwFrmFmt* pFmt = (SwFrmFmt*)&rFmt;
        nOrdNum = pDoc->GetSpzFrmFmts()->GetPos( pFmt );

        const SdrModel* pModel = pDoc->GetDrawModel();
        if( pModel )
            nOrdNum += pModel->GetPage( 0 )->GetObjCount();
    }
    return nOrdNum;
}

static bool lcl_IsFlyInFlyHere(const SwFrmFmt* pFmt, ULONG nStart, ULONG nEnd)
{
    bool bRet = false;
    const SwFmtAnchor* pAnchor = &pFmt->GetAnchor();
    const SwPosition* pAPos;
    ULONG nIdx;
    if( ( pAnchor->GetAnchorId() == FLY_AT_CNTNT ||
        pAnchor->GetAnchorId() == FLY_AT_FLY ||
        pAnchor->GetAnchorId() == FLY_AUTO_CNTNT ) &&
        0 != ( pAPos = pAnchor->GetCntntAnchor()) &&
        nStart <= ( nIdx = pAPos->nNode.GetIndex()) &&
        nIdx < nEnd )
    {
        bRet = true;
    }
    return bRet;
}

void SwWW8Writer::AppendFlyInFlys(WW8_CP& rCP, const SwFrmFmt& rFrmFmt,
    const Point& rNdTopLeft)
{
    ASSERT(!pEscher, "der EscherStream wurde schon geschrieben!");
    if (pEscher)
        return ;
    bool bExportAsTable = false;
    USHORT nArrLen = 0, nLastFmt = 0;
    ULONG nStart = 0, nEnd = 0;

    if (RES_FLYFRMFMT == rFrmFmt.Which())
    {
        const SwNodeIndex* pNdIdx = rFrmFmt.GetCntnt().GetCntntIdx();
        ASSERT( pNdIdx, "wo ist der NodeIndex geblieben?" );
        nStart = pNdIdx->GetIndex();
        nEnd = pNdIdx->GetNode().EndOfSectionIndex();
        nArrLen = pDoc->GetSpzFrmFmts()->Count();
        for (nLastFmt = 0; nLastFmt < nArrLen; ++nLastFmt)
        {
            if (lcl_IsFlyInFlyHere(
                (*pDoc->GetSpzFrmFmts())[nLastFmt], nStart, nEnd))
            {
                bExportAsTable = true;
                break;
            }
        }
    }

    if (bExportAsTable)
    {
        SwTwips nTblOffset=0;
        WW8Bytes aAt( 128, 128 );
        USHORT nStdAtLen = StartTableFromFrmFmt(aAt,&rFrmFmt,nTblOffset);

        static BYTE __READONLY_DATA aNullBytes[] = { 0, 0, 0, 0 };
        BYTE nWWColMax = 1;

        if( bWrtWW8 )
            SwWW8Writer::InsUInt16( aAt, 0x3404 );
        else
            aAt.Insert( 186, aAt.Count() );
        aAt.Insert( 1, aAt.Count() );

        long nHeight=0;
        const SwFmtFrmSize& rLSz = rFrmFmt.GetFrmSize();
        if( ATT_VAR_SIZE != rLSz.GetSizeType() && rLSz.GetHeight() )
            nHeight = ATT_MIN_SIZE == rLSz.GetSizeType()
                ? rLSz.GetHeight() : -rLSz.GetHeight();

        if( nHeight )
        {
            if( bWrtWW8 )
                SwWW8Writer::InsUInt16( aAt, 0x9407 );
            else
                aAt.Insert( 189, aAt.Count() );
            SwWW8Writer::InsUInt16( aAt, (USHORT)nHeight );
        }

        if( bWrtWW8 )
            SwWW8Writer::InsUInt16( aAt, 0x3403 );
        else
            aAt.Insert( 185, aAt.Count() );
        aAt.Insert( (BYTE)0, aAt.Count() );

        const SwNodeIndex* pNodeIndex = rFrmFmt.GetCntnt().GetCntntIdx();
        ULONG nNodeStt = pNodeIndex ? pNodeIndex->GetIndex()+1 : 0;
        ULONG nNodeEnd = pNodeIndex ?
            pNodeIndex->GetNode().EndOfSectionIndex() : 0;

        WW8SaveData aSaveData(*this,nNodeStt,nNodeEnd);
        bOutTable = true;
        bIsInTable= true;
        WriteText();
        WriteCellEnd();
        WriteRowEnd();

        if( bWrtWW8 )
        {
            SwWW8Writer::InsUInt16( aAt, 0xD608 );
            SwWW8Writer::InsUInt16( aAt, 2 + ( nWWColMax + 1 ) * 2 +
                ( nWWColMax * 20 ));
            aAt.Insert( nWWColMax, aAt.Count() );
        }
        else
        {
            aAt.Insert( 190, aAt.Count() );
            SwWW8Writer::InsUInt16( aAt, nWWColMax * 12 + 4 );
            aAt.Insert( nWWColMax, aAt.Count() );
        }
        SwWW8Writer::InsUInt16( aAt, (USHORT)nTblOffset );

        SwTwips nCalc = rFrmFmt.GetFrmSize().GetWidth();
        SwWW8Writer::InsUInt16( aAt, (USHORT)(nTblOffset + nCalc ));

        if( bWrtWW8 )
        {
            USHORT nFlags = 0;
            SwWW8Writer::InsUInt16( aAt, nFlags );
            aAt.Insert( aNullBytes, 2, aAt.Count() );
            Out_SwFmtTableBox( aAt, rFrmFmt.GetBox() );

            static USHORT __READONLY_DATA aBorders[] =
            {
                BOX_LINE_TOP, BOX_LINE_LEFT,
                BOX_LINE_BOTTOM, BOX_LINE_RIGHT
            };
            const USHORT* pBrd = aBorders;

            for( int i = 0; i < 4; ++i, ++pBrd)
            {
                SwWW8Writer::InsUInt16(aAt, 0xD634);
                aAt.Insert( BYTE(6), aAt.Count() );
                aAt.Insert( BYTE(0), aAt.Count() );
                aAt.Insert( BYTE(3), aAt.Count() );
                aAt.Insert( BYTE(1 << i), aAt.Count() );
                aAt.Insert( BYTE(3), aAt.Count() );
                SwWW8Writer::InsUInt16(aAt,
                    rFrmFmt.GetBox().GetDistance(*pBrd));
            }
        }

        pPapPlc->AppendFkpEntry( Strm().Tell(),
                aAt.Count(), aAt.GetData() );

        if( aAt.Count() > nStdAtLen )
            aAt.Remove( nStdAtLen, aAt.Count() - nStdAtLen );
    }
    else
    {
        PlcDrawObj *pDrwO;
        if (TXT_HDFT == nTxtTyp)
            pDrwO = pHFSdrObjs;
        else
            pDrwO = pSdrObjs;

        if (pDrwO->Append( *this, rCP, rFrmFmt, rNdTopLeft))
        {
            static BYTE __READONLY_DATA aSpec8[] = {
                0x03, 0x6a, 0, 0, 0, 0, // sprmCObjLocation
                0x55, 0x08, 1           // sprmCFSpec
            };
                                                    // fSpec-Attribut true
                                // Fuer DrawObjets muss ein Spezial-Zeichen
                                // in den Text und darum ein fSpec-Attribut
            pChpPlc->AppendFkpEntry( Strm().Tell() );
            WriteChar( 0x8 );
            rCP += 1;       // to next charakter position
            pChpPlc->AppendFkpEntry( Strm().Tell(), sizeof( aSpec8 ), aSpec8 );

            if (RES_FLYFRMFMT == rFrmFmt.Which())
            {
                // search all Flys/DrawObj in Flys and put it after this text
                // position. The test to change the parent fly frame into a
                // table will have left nLastFmt pointing to the first frame
                // to begin exporting
                for( ; nLastFmt < nArrLen; ++nLastFmt )
                {
                    const SwFrmFmt* pFmt = (*pDoc->GetSpzFrmFmts())[nLastFmt];
                    if (lcl_IsFlyInFlyHere(pFmt, nStart, nEnd))
                        AppendFlyInFlys( rCP, *pFmt, rNdTopLeft );
                }
            }
        }
    }
}

class WW8_SdrAttrIter : public WW8_AttrIter
{
private:
    const EditTextObject* pEditObj;
    const SfxItemPool* pEditPool;
    EECharAttribArray aTxtAtrArr;
    SvPtrarr aChrTxtAtrArr;
    SvUShorts aChrSetArr;
    USHORT nPara;
    xub_StrLen nAktSwPos;
    xub_StrLen nTmpSwPos;                   // fuer HasItem()
    rtl_TextEncoding eNdChrSet;
    USHORT nScript;
    BYTE mnTyp;

    xub_StrLen SearchNext( xub_StrLen nStartPos );
    void SetCharSet(const EECharAttrib& rTxtAttr, bool bStart);

    //No copying
    WW8_SdrAttrIter(const WW8_SdrAttrIter&);
    WW8_SdrAttrIter& operator=(const WW8_SdrAttrIter&);
public:
    WW8_SdrAttrIter(SwWW8Writer& rWr, const EditTextObject& rEditObj,
        BYTE nType);
    void NextPara( USHORT nPar );
    void OutParaAttr(bool bCharAttr);
    void OutEEField(const SfxPoolItem& rHt);

    bool IsTxtAttr(xub_StrLen nSwPos);

    void NextPos() { nAktSwPos = SearchNext( nAktSwPos + 1 ); }

    void OutAttr( xub_StrLen nSwPos );
    virtual const SfxPoolItem* HasTextItem( USHORT nWhich ) const;
    virtual const SfxPoolItem& GetItem( USHORT nWhich ) const;
    bool OutAttrWithRange(xub_StrLen nPos);
    xub_StrLen WhereNext() const                { return nAktSwPos; }
    rtl_TextEncoding GetNextCharSet() const;
    rtl_TextEncoding GetNodeCharSet() const     { return eNdChrSet; }
};


WW8_SdrAttrIter::WW8_SdrAttrIter(SwWW8Writer& rWr,
    const EditTextObject& rEditObj, BYTE nTyp)
    : WW8_AttrIter( rWr ), pEditObj(&rEditObj), pEditPool(0),
    aTxtAtrArr( 0, 4 ), aChrTxtAtrArr( 0, 4 ), aChrSetArr( 0, 4 ),
    mnTyp(nTyp)
{
    NextPara( 0 );
}

void WW8_SdrAttrIter::NextPara( USHORT nPar )
{
    nPara = nPar;
    // Attributwechsel an Pos 0 wird ignoriert, da davon ausgegangen
    // wird, dass am Absatzanfang sowieso die Attribute neu ausgegeben
    // werden.
    aChrTxtAtrArr.Remove( 0, aChrTxtAtrArr.Count() );
    aChrSetArr.Remove( 0, aChrSetArr.Count() );
    nAktSwPos = nTmpSwPos = 0;

    SfxItemSet aSet( pEditObj->GetParaAttribs( nPara ));
    pEditPool = aSet.GetPool();
    eNdChrSet = ((SvxFontItem&)aSet.Get( EE_CHAR_FONTINFO )).GetCharSet();

    if( pBreakIt->xBreak.is() )
        nScript = pBreakIt->xBreak->getScriptType( pEditObj->GetText(nPara), 0);
    else
        nScript = i18n::ScriptType::LATIN;

    pEditObj->GetCharAttribs( nPara, aTxtAtrArr );
    nAktSwPos = SearchNext( 1 );
}

rtl_TextEncoding WW8_SdrAttrIter::GetNextCharSet() const
{
    if( aChrSetArr.Count() )
        return (rtl_TextEncoding)aChrSetArr[ aChrSetArr.Count() - 1 ];
    return eNdChrSet;
}

// der erste Parameter in SearchNext() liefert zurueck, ob es ein TxtAtr ist.
xub_StrLen WW8_SdrAttrIter::SearchNext( xub_StrLen nStartPos )
{
    register xub_StrLen nPos;
    register xub_StrLen nMinPos = STRING_MAXLEN;
    register xub_StrLen i;

    for( i = 0; i < aTxtAtrArr.Count(); i++ )
    {
        const EECharAttrib& rHt = aTxtAtrArr[ i ];
        nPos = rHt.nStart;  // gibt erstes Attr-Zeichen
        if( nPos >= nStartPos && nPos <= nMinPos )
        {
            nMinPos = nPos;
            SetCharSet(rHt, true);
        }

//??        if( pHt->GetEnd() )         // Attr mit Ende
        {
            nPos = rHt.nEnd;        // gibt letztes Attr-Zeichen + 1
            if( nPos >= nStartPos && nPos < nMinPos )
            {
                nMinPos = nPos;
                SetCharSet(rHt, false);
            }
        }
/*      else
        {                                   // Attr ohne Ende
            nPos = rHt.nStart + 1;  // Laenge 1 wegen CH_TXTATR im Text
            if( nPos >= nStartPos && nPos < nMinPos )
            {
                nMinPos = nPos;
                SetCharSet(rHt, false);
            }
        }
*/
    }
    return nMinPos;
}

void WW8_SdrAttrIter::SetCharSet(const EECharAttrib& rAttr, bool bStart)
{
    void* p = 0;
    rtl_TextEncoding eChrSet;
    const SfxPoolItem& rItem = *rAttr.pAttr;
    switch( rItem.Which() )
    {
    case EE_CHAR_FONTINFO:
        p = (void*)&rAttr;
        eChrSet = ((SvxFontItem&)rItem).GetCharSet();
        break;
    }

    if( p )
    {
        USHORT nPos;
        if( bStart )
        {
            nPos = aChrSetArr.Count();
            aChrSetArr.Insert( eChrSet, nPos );
            aChrTxtAtrArr.Insert( p, nPos );
        }
        else if( USHRT_MAX != ( nPos = aChrTxtAtrArr.GetPos( p )) )
        {
            aChrTxtAtrArr.Remove( nPos );
            aChrSetArr.Remove( nPos );
        }
    }
}

void WW8_SdrAttrIter::OutEEField(const SfxPoolItem& rHt)
{
    const SvxFieldItem &rField = (const SvxFieldItem &)rHt;
    const SvxFieldData *pFld = rField.GetField();
    if (pFld && pFld->ISA(SvxURLField))
    {
        BYTE nOldTxtTyp = rWrt.nTxtTyp;
        rWrt.nTxtTyp = mnTyp;
        const SvxURLField *pURL = (const SvxURLField *)pFld;
        StartURL(pURL->GetURL(), pURL->GetTargetFrame());

        const String &rStr = pURL->GetRepresentation();
        rWrt.OutSwString(rStr, 0, rStr.Len(), true, GetNodeCharSet());

        EndURL();
        rWrt.nTxtTyp = nOldTxtTyp;
    }
}

void WW8_SdrAttrIter::OutAttr( xub_StrLen nSwPos )
{
    OutParaAttr(true);

    if( aTxtAtrArr.Count() )
    {
        const SwModify* pOldMod = rWrt.pOutFmtNode;
        rWrt.pOutFmtNode = 0;

        const SfxItemPool* pSrcPool = pEditPool;

        nTmpSwPos = nSwPos;
        register USHORT i, nWhich, nSlotId;
        FnAttrOut pOut;
        for( i = 0; i < aTxtAtrArr.Count(); i++ )
        {
            const EECharAttrib& rHt = aTxtAtrArr[ i ];
            if (nSwPos >= rHt.nStart && nSwPos < rHt.nEnd)
            {
                nWhich = rHt.pAttr->Which();
                if (nWhich == EE_FEATURE_FIELD)
                {
                    OutEEField(*rHt.pAttr);
                    continue;
                }
                nSlotId = pSrcPool->GetSlotId(nWhich);

                if (nSlotId && nWhich != nSlotId)
                {
                    if (nWhich && nWhich < RES_UNKNOWNATR_BEGIN &&
                        (pOut = aWW8AttrFnTab[nWhich - RES_CHRATR_BEGIN]))
                    {
                        if (rWrt.CollapseScriptsforWordOk(nScript,nWhich))
                        {
                            // use always the SW-Which Id !
                            SfxPoolItem* pI = rHt.pAttr->Clone();
                            pI->SetWhich( nWhich );
                            (*pOut)( rWrt, *pI );
                            delete pI;
                        }
                    }
                }
            }

            if( nSwPos < rHt.nStart )
                break;
        }

        nTmpSwPos = 0;      // HasTextItem nur in dem obigen Bereich erlaubt
        rWrt.pOutFmtNode = pOldMod;
    }
}

bool WW8_SdrAttrIter::IsTxtAttr(xub_StrLen nSwPos)
{
    for (USHORT i = 0; i < aTxtAtrArr.Count(); ++i)
    {
        const EECharAttrib& rHt = aTxtAtrArr[ i ];
        if (nSwPos >= rHt.nStart && nSwPos < rHt.nEnd)
        {
            if (rHt.pAttr->Which() == EE_FEATURE_FIELD)
                return true;
        }
    }
    return false;
}

// HasItem ist fuer die Zusammenfassung des Doppel-Attributes Underline
// und WordLineMode als TextItems. OutAttr() ruft die Ausgabefunktion,
// die dann ueber HasItem() nach anderen Items an der
// Attribut-Anfangposition fragen kann.
// Es koennen nur Attribute mit Ende abgefragt werden.
// Es wird mit bDeep gesucht
const SfxPoolItem* WW8_SdrAttrIter::HasTextItem( USHORT nWhich ) const
{
    const SfxPoolItem* pRet = 0;
    USHORT nSlotId = rWrt.pDoc->GetAttrPool().GetSlotId( nWhich );
    if( nSlotId && nWhich != nSlotId &&
        0 != ( nWhich = pEditPool->GetWhich( nSlotId ) ) &&
        nWhich != nSlotId )
    {
        register USHORT i;
        for( i = 0; i < aTxtAtrArr.Count(); ++i )
        {
            const EECharAttrib& rHt = aTxtAtrArr[ i ];
            if( nWhich == rHt.pAttr->Which() &&
                nTmpSwPos >= rHt.nStart && nTmpSwPos < rHt.nEnd )
            {
                pRet = rHt.pAttr;       // gefunden
                break;
            }
            else if( nTmpSwPos < rHt.nStart )
                break;              // dann kommt da nichts mehr
        }
    }
    return pRet;
}

const SfxPoolItem& WW8_SdrAttrIter::GetItem( USHORT nWhich ) const
{
    const SfxPoolItem* pRet = HasTextItem( nWhich );
    if( !pRet )
    {
        SfxItemSet aSet( pEditObj->GetParaAttribs( nPara ));

        USHORT nNewW, nSlotId = rWrt.pDoc->GetAttrPool().GetSlotId( nWhich );
        if( nSlotId && nWhich != nSlotId &&
            0 != ( nNewW = aSet.GetPool()->GetWhich( nSlotId ) ) &&
            nNewW != nSlotId )
            pRet = &aSet.Get( nNewW );
    }
    return *pRet;
}

void WW8_SdrAttrIter::OutParaAttr(bool bCharAttr)
{
    SfxItemSet aSet( pEditObj->GetParaAttribs( nPara ));
    if( aSet.Count() )
    {
        const SfxItemSet* pOldSet = rWrt.GetCurItemSet();
        rWrt.SetCurItemSet( &aSet );

        SfxItemIter aIter( aSet );
        const SfxPoolItem* pItem = aIter.GetCurItem();
        FnAttrOut pOut;

        const SfxItemPool* pSrcPool = pEditPool,
                            * pDstPool = &rWrt.pDoc->GetAttrPool();

        do {
                USHORT nWhich = pItem->Which(),
                       nSlotId = pSrcPool->GetSlotId( nWhich );
                if( nSlotId && nWhich != nSlotId &&
                    0 != ( nWhich = pDstPool->GetWhich( nSlotId ) ) &&
                    nWhich != nSlotId &&
                    0 != ( pOut = aWW8AttrFnTab[ nWhich - RES_CHRATR_BEGIN ] )
                    && ( bCharAttr ? ( nWhich >= RES_CHRATR_BEGIN
                                      && nWhich < RES_TXTATR_END)
                                   : (nWhich >= RES_PARATR_BEGIN
                                      && nWhich < RES_FRMATR_END) ) )
                {
                    // use always the SW-Which Id !
                    SfxPoolItem* pI = pItem->Clone();
                    pI->SetWhich( nWhich );
                    if (rWrt.CollapseScriptsforWordOk(nScript,nWhich))
                        (*pOut)( rWrt, *pI );
                    delete pI;
                }

        } while( !aIter.IsAtEnd() && 0 != ( pItem = aIter.NextItem() ) );
        rWrt.SetCurItemSet( pOldSet );
    }
}

void SwWW8Writer::WriteSdrTextObj(const SdrObject& rObj, BYTE nTyp)
{
    const SdrTextObj* pTxtObj = PTR_CAST( SdrTextObj, &rObj );
    ASSERT( pTxtObj, "das ist gar kein SdrTextObj!" );

    bool bAnyWrite = false;
    const OutlinerParaObject* pParaObj = pTxtObj->GetOutlinerParaObject();
    if( pParaObj )
    {
        const EditTextObject& rEditObj = pParaObj->GetTextObject();
        WW8_SdrAttrIter aAttrIter( *this, rEditObj, nTyp );

        USHORT nPara = rEditObj.GetParagraphCount();
        BYTE bNul = 0;
        for( USHORT n = 0; n < nPara; ++n )
        {
            if( n )
                aAttrIter.NextPara( n );

            rtl_TextEncoding eChrSet = aAttrIter.GetNodeCharSet();

            ASSERT( !pO->Count(), " pO ist am Zeilenanfang nicht leer" );

            String aStr( rEditObj.GetText( n ));
            xub_StrLen nAktPos = 0;
            xub_StrLen nEnd = aStr.Len();
            do {
                xub_StrLen nNextAttr = aAttrIter.WhereNext();
                rtl_TextEncoding eNextChrSet = aAttrIter.GetNextCharSet();

                if( nNextAttr > nEnd )
                    nNextAttr = nEnd;

                bool bTxtAtr = aAttrIter.IsTxtAttr( nAktPos );
                if( !bTxtAtr )
                    OutSwString( aStr, nAktPos, nNextAttr - nAktPos,
                                    true, eChrSet );

                            // Am Zeilenende werden die Attribute bis ueber das CR
                            // aufgezogen. Ausnahme: Fussnoten am Zeilenende
                if( nNextAttr == nEnd && !bTxtAtr )
                    WriteCR();              // CR danach

                                                // Ausgabe der Zeichenattribute
                aAttrIter.OutAttr( nAktPos );   // nAktPos - 1 ??
                pChpPlc->AppendFkpEntry( Strm().Tell(),
                                                pO->Count(), pO->GetData() );
                pO->Remove( 0, pO->Count() );                   // leeren

                            // Ausnahme: Fussnoten am Zeilenende
                if( nNextAttr == nEnd && bTxtAtr )
                    WriteCR();              // CR danach

                nAktPos = nNextAttr;
                eChrSet = eNextChrSet;
                aAttrIter.NextPos();
            }
            while( nAktPos < nEnd );

            ASSERT( !pO->Count(), " pO ist am ZeilenEnde nicht leer" );

            pO->Insert( bNul, pO->Count() );        // Style # as short
            pO->Insert( bNul, pO->Count() );

            aAttrIter.OutParaAttr(false);

            ULONG nPos = Strm().Tell();
            pPapPlc->AppendFkpEntry( Strm().Tell(),
                                            pO->Count(), pO->GetData() );
            pO->Remove( 0, pO->Count() );                       // leeren
            pChpPlc->AppendFkpEntry( nPos );
        }
        bAnyWrite = 0 != nPara;
    }
    if( !bAnyWrite )
        WriteStringAsPara( aEmptyStr );
}

void WinwordAnchoring::WriteData( EscherEx& rEx ) const
{
    //Toplevel groups get their winword extra data attached, and sub elements
    //use the defaults
    if( rEx.GetGroupLevel() <= 1 )
    {
        rEx.AddAtom(24, DFF_msofbtUDefProp, 3, 4 ); //Prop id is 0xF122
        SvStream& rSt = rEx.GetStream();
        rSt << (UINT16)0x038F << nXAlign;
        rSt << (UINT16)0x0390 << nXRelTo;
        rSt << (UINT16)0x0391 << nYAlign;
        rSt << (UINT16)0x0392 << nYRelTo;
    }
}

/*  */

void SwWW8Writer::CreateEscher()
{
    if(pHFSdrObjs->size() || pSdrObjs->size())
    {
        ASSERT( !pEscher, "wer hat den Pointer nicht geloescht?" );
        SvMemoryStream* pEscherStrm = new SvMemoryStream;
        pEscherStrm->SetNumberFormatInt(NUMBERFORMAT_INT_LITTLEENDIAN);
        pEscher = new SwEscherEx(pEscherStrm, *this);
    }
}

void SwWW8Writer::WriteEscher()
{
    if( pEscher )
    {
        ULONG nStart = pTableStrm->Tell();

        pEscher->WritePictures();
        pEscher->FinishEscher();

        pFib->fcDggInfo = nStart;
        pFib->lcbDggInfo = pTableStrm->Tell() - nStart;
        delete pEscher, pEscher = 0;
    }
}

void SwEscherEx::WritePictures()
{
    if (pPictStrm)
    {
        // set the blip - entries to the correct stream pos
        INT32 nEndPos = rWrt.Strm().Tell();
        SetNewBlipStreamOffset( nEndPos );

        pPictStrm->Seek( 0 );
        rWrt.Strm() << *pPictStrm;

        delete pPictStrm, pPictStrm = 0;
    }
    Flush();
}

/*  */

// Output- Routines for Escher Export

SwBasicEscherEx::SwBasicEscherEx(SvStream* pStrm, SwWW8Writer& rWW8Wrt,
    UINT32 nDrawings)
    : EscherEx(*pStrm, nDrawings), rWrt(rWW8Wrt), pEscherStrm(pStrm),
    pPictStrm(0)
{
    Init();
}

SwBasicEscherEx::~SwBasicEscherEx()
{
}

void SwBasicEscherEx::WriteFrmExtraData(const SwFrmFmt&)
{
    AddAtom(4, ESCHER_ClientAnchor);
    GetStream() << 0x80000000;
}

INT32 SwBasicEscherEx::WriteGrfFlyFrame(const SwFrmFmt& rFmt, UINT32 nShapeId)
{
    INT32 nBorderThick=0;
    OpenContainer( ESCHER_SpContainer );

    AddShape( ESCHER_ShpInst_PictureFrame, 0xa00, nShapeId );

    EscherPropertyContainer aPropOpt;

    UINT32 nFlags = ESCHER_BlipFlagDefault;
    SwNodeIndex aIdx( *rFmt.GetCntnt().GetCntntIdx(), 1 );
    SwGrfNode& rGrfNd = *aIdx.GetNode().GetGrfNode();
    if( rGrfNd.IsLinkedFile() )
    {
        String sURL;
        rGrfNd.GetFileFilterNms( &sURL, 0 );

        WW8Bytes aBuf;
        SwWW8Writer::InsAsString16( aBuf, sURL );
        SwWW8Writer::InsUInt16( aBuf, 0 );

        USHORT nArrLen = aBuf.Count();
        BYTE* pArr = new BYTE[ nArrLen ];
        memcpy( pArr, aBuf.GetData(), nArrLen );

        aPropOpt.AddOpt(ESCHER_Prop_pibName, true, nArrLen, pArr, nArrLen);
        nFlags = ESCHER_BlipFlagLinkToFile | ESCHER_BlipFlagURL |
                    ESCHER_BlipFlagDoNotSave;
    }
    else
    {
        rGrfNd.SwapIn(true);

        Graphic         aGraphic( rGrfNd.GetGrf() );
        GraphicObject   aGraphicObject( aGraphic );
        ByteString      aUniqueId = aGraphicObject.GetUniqueID();

        if ( aUniqueId.Len() )
        {
             const  MapMode aMap100mm( MAP_100TH_MM );
            Size    aSize( aGraphic.GetPrefSize() );

            if ( MAP_PIXEL == aGraphic.GetPrefMapMode().GetMapUnit() )
            {
                aSize = Application::GetDefaultDevice()->PixelToLogic(
                    aSize, aMap100mm );
            }
            else
            {
                aSize = OutputDevice::LogicToLogic( aSize,
                    aGraphic.GetPrefMapMode(), aMap100mm );
            }

            Point aEmptyPoint = Point();
            Rectangle aRect( aEmptyPoint, aSize );

            sal_uInt32 nBlibId = GetBlibID( *QueryPicStream(), aUniqueId,
                aRect, 0 );
            if ( nBlibId )
            {
                aPropOpt.AddOpt( ESCHER_Prop_fillType, ESCHER_FillPicture );
                aPropOpt.AddOpt( ESCHER_Prop_pib, nBlibId, sal_True );
            }
        }
    }

    aPropOpt.AddOpt( ESCHER_Prop_pibFlags, nFlags );
    nBorderThick = WriteFlyFrameAttr(rFmt,mso_sptPictureFrame,aPropOpt);
    WriteGrfAttr( rGrfNd, aPropOpt );

    aPropOpt.Commit( GetStream() );

    // store anchor attribute
    WriteFrmExtraData( rFmt );

    CloseContainer();   // ESCHER_SpContainer
    return nBorderThick;
}

void SwBasicEscherEx::WriteGrfAttr(const SwNoTxtNode& rNd,
    EscherPropertyContainer& rPropOpt)
{
    const SfxPoolItem* pItem;
    sal_uInt32 nMode = GRAPHICDRAWMODE_STANDARD;
    sal_Int32 nContrast = 0;
    sal_Int16 nBrightness = 0;

    if (SFX_ITEM_SET == rNd.GetSwAttrSet().GetItemState(RES_GRFATR_CONTRAST,
        true, &pItem))
    {
        nContrast = ((SfxInt16Item*)pItem)->GetValue();
    }

    if (SFX_ITEM_SET == rNd.GetSwAttrSet().GetItemState(RES_GRFATR_LUMINANCE,
        true, &pItem))
    {
        nBrightness = ((SfxInt16Item*)pItem)->GetValue();
    }


    if (SFX_ITEM_SET == rNd.GetSwAttrSet().GetItemState(RES_GRFATR_DRAWMODE,
        true, &pItem))
    {
        nMode = ((SfxEnumItem*)pItem)->GetValue();
        if (nMode == GRAPHICDRAWMODE_WATERMARK)
        {
            /*
            There is no real watermark mode in word, we must use standard
            mode and modify our ones by 70% extra brightness and 70% less
            contrast. This means that unmodified default OOo watermark
            will turn back into watermark, and modified OOo watermark will
            change into a close visual representation in standardmode
            */
            nBrightness += 70;
            if (nBrightness > 100)
                nBrightness = 100;
            nContrast -= 70;
            if (nContrast < -100)
                nContrast = -100;
            nMode = GRAPHICDRAWMODE_STANDARD;
        }
    }

    if (nMode == GRAPHICDRAWMODE_GREYS)
        nMode = 0x40004;
    else if (nMode == GRAPHICDRAWMODE_MONO)
        nMode = 0x60006;
    else
        nMode = 0;
    rPropOpt.AddOpt( ESCHER_Prop_pictureActive, nMode );

    if (nContrast != 0)
    {
        nContrast+=100;
        if (nContrast == 100)
            nContrast = 0x10000;
        else if (nContrast < 100)
        {
            nContrast *= 0x10000;
            nContrast /= 100;
        }
        else if (nContrast < 200)
            nContrast = (100 * 0x10000) / (200-nContrast);
        else
            nContrast = 0x7fffffff;
        rPropOpt.AddOpt( ESCHER_Prop_pictureContrast, nContrast);
    }

    if (nBrightness != 0)
        rPropOpt.AddOpt( ESCHER_Prop_pictureBrightness, nBrightness * 327 );

    if (SFX_ITEM_SET == rNd.GetSwAttrSet().GetItemState(RES_GRFATR_CROPGRF,
        true, &pItem))
    {
        const Size aSz( rNd.GetTwipSize() );
        INT32 nVal;
        if( 0 != ( nVal = ((SwCropGrf*)pItem )->GetLeft() ) )
            rPropOpt.AddOpt( ESCHER_Prop_cropFromLeft, ToFract16( nVal, aSz.Width()) );
        if( 0 != ( nVal = ((SwCropGrf*)pItem )->GetRight() ) )
            rPropOpt.AddOpt( ESCHER_Prop_cropFromRight, ToFract16( nVal, aSz.Width()));
        if( 0 != ( nVal = ((SwCropGrf*)pItem )->GetTop() ) )
            rPropOpt.AddOpt( ESCHER_Prop_cropFromTop, ToFract16( nVal, aSz.Height()));
        if( 0 != ( nVal = ((SwCropGrf*)pItem )->GetBottom() ) )
            rPropOpt.AddOpt( ESCHER_Prop_cropFromBottom, ToFract16( nVal, aSz.Height()));
    }
    // mirror ??
}

void SwBasicEscherEx::SetPicId(const SdrObject &, UINT32,
    EscherPropertyContainer &)
{
}

void SwEscherEx::SetPicId(const SdrObject &rSdrObj, UINT32 nShapeId,
    EscherPropertyContainer &rPropOpt)
{
    pTxtBxs->Append(rSdrObj, nShapeId);
    UINT32 nPicId = pTxtBxs->Count();
    nPicId *= 0x10000;
    rPropOpt.AddOpt( ESCHER_Prop_pictureId, nPicId );
}

INT32 SwBasicEscherEx::WriteOLEFlyFrame(const SwFrmFmt& rFmt, UINT32 nShapeId)
{
    INT32 nBorderThick = 0;
    if (const SdrObject* pSdrObj = rFmt.FindRealSdrObject())
    {
        SwNodeIndex aIdx(*rFmt.GetCntnt().GetCntntIdx(), 1);
        SwOLENode& rOLENd = *aIdx.GetNode().GetOLENode();
        const SvInPlaceObjectRef xObj(rOLENd.GetOLEObj().GetOleRef());

        /*
        #i5970#
        Export floating ole2 .doc ver 8+ wmf ole2 previews as emf previews
        instead ==> allows unicode text to be preserved
        */
#ifdef OLE_PREVIEW_AS_EMF
        Graphic aGraphic = wwUtility::MakeSafeGDIMetaFile(xObj);
#endif
        OpenContainer(ESCHER_SpContainer);

        AddShape(ESCHER_ShpInst_PictureFrame, 0xa10, nShapeId);
        EscherPropertyContainer aPropOpt;

        GraphicObject aGraphicObject(aGraphic);
        ByteString aId = aGraphicObject.GetUniqueID();
        if (aId.Len())
        {
            Size aSz(rOLENd.GetTwipSize());
            aSz.Width() = DrawModelToEmu(aSz.Width());
            aSz.Height() = DrawModelToEmu(aSz.Height());
            Rectangle aRect(Point(0,0), aSz);

            sal_uInt32 nBlibId = GetBlibID(*QueryPicStream(), aId, aRect, 0);
            if (nBlibId)
            {
                aPropOpt.AddOpt(ESCHER_Prop_fillType, ESCHER_FillPicture);
                aPropOpt.AddOpt(ESCHER_Prop_pib, nBlibId, sal_True);
            }
        }

        SetPicId(*pSdrObj, nShapeId, aPropOpt);

        aPropOpt.AddOpt(ESCHER_Prop_pictureActive, 0x10000);
        nBorderThick = WriteFlyFrameAttr(rFmt, mso_sptPictureFrame, aPropOpt);
        WriteGrfAttr(rOLENd, aPropOpt);
        aPropOpt.Commit(GetStream());

        // store anchor attribute
        WriteFrmExtraData( rFmt );

        CloseContainer();   // ESCHER_SpContainer
    }
    return nBorderThick;
}

INT32 SwBasicEscherEx::WriteFlyFrameAttr(const SwFrmFmt& rFmt, MSO_SPT eShapeType,
    EscherPropertyContainer& rPropOpt)
{
    INT32 nLineWidth=0;
    const SfxPoolItem* pItem;
    bool bFirstLine = true;
    if (SFX_ITEM_SET == rFmt.GetItemState(RES_BOX, true, &pItem))
    {
        static UINT16 __READONLY_DATA aExhperProp[ 4 ] = {
            ESCHER_Prop_dyTextTop,  ESCHER_Prop_dyTextBottom,
            ESCHER_Prop_dxTextLeft, ESCHER_Prop_dxTextRight
        };
        const SvxBorderLine* pLine;

        for( int n = 0; n < 4; ++n )
            if( 0 != ( pLine = ((SvxBoxItem*)pItem)->GetLine( n )) )
            {
                if( bFirstLine )
                {
                    UINT32 nLineColor = GetColor(pLine->GetColor(), false);
                    rPropOpt.AddOpt( ESCHER_Prop_lineColor, nLineColor );
                    rPropOpt.AddOpt( ESCHER_Prop_lineBackColor,
                        nLineColor ^ 0xffffff );

                    MSO_LineStyle eStyle;
                    if( pLine->GetInWidth() )
                    {
                        // double line
                        nLineWidth = pLine->GetInWidth() + pLine->GetOutWidth()
                            + pLine->GetDistance();
                        if( pLine->GetInWidth() == pLine->GetOutWidth() )
                            eStyle = mso_lineDouble;
                        else if( pLine->GetInWidth() < pLine->GetOutWidth() )
                            eStyle = mso_lineThickThin;
                        else
                            eStyle = mso_lineThinThick;
                    }
                    else
                    {
                        // simple line
                        eStyle = mso_lineSimple;
                        nLineWidth = pLine->GetOutWidth();
                    }

                    rPropOpt.AddOpt( ESCHER_Prop_lineStyle, eStyle );
                    rPropOpt.AddOpt( ESCHER_Prop_lineWidth,
                        DrawModelToEmu( nLineWidth ));
                    rPropOpt.AddOpt( ESCHER_Prop_fNoLineDrawDash, 0x8000E );

                    //Use import logic to determine how much of border will go
                    //outside graphic
                    nLineWidth = SwMSDffManager::GetEscherLineMatch(
                        eStyle,eShapeType,nLineWidth);
                    bFirstLine = false;
                }
                rPropOpt.AddOpt( aExhperProp[ n ], DrawModelToEmu(
                    ((SvxBoxItem*)pItem)->GetDistance( n ) ));
            }
    }
    if( bFirstLine )                // no valid line found
    {
        rPropOpt.AddOpt( ESCHER_Prop_fNoLineDrawDash, 0x80000 );
        rPropOpt.AddOpt( ESCHER_Prop_dyTextTop, 0 );
        rPropOpt.AddOpt( ESCHER_Prop_dyTextBottom, 0 );
        rPropOpt.AddOpt( ESCHER_Prop_dxTextLeft, 0 );
        rPropOpt.AddOpt( ESCHER_Prop_dxTextRight, 0 );
    }

    if ((pItem = rWrt.TrueFrameBgBrush(rFmt)))
    {
        const SvxBrushItem *pBrush= (const SvxBrushItem*)pItem;
        bool bSetOpacity = false;
        sal_uInt32 nOpaque = 0;

        if (const GraphicObject *pGraphicObject = pBrush->GetGraphicObject())
        {
            ByteString aUniqueId = pGraphicObject->GetUniqueID();
            if (aUniqueId.Len())
            {
                const Graphic &rGraphic = pGraphicObject->GetGraphic();
                Size aSize(rGraphic.GetPrefSize());
                const MapMode aMap100mm(MAP_100TH_MM);
                if (MAP_PIXEL == rGraphic.GetPrefMapMode().GetMapUnit())
                {
                    aSize = Application::GetDefaultDevice()->PixelToLogic(
                        aSize, aMap100mm);
                }
                else
                {
                    aSize = OutputDevice::LogicToLogic(aSize,
                        rGraphic.GetPrefMapMode(), aMap100mm);
                }

                Point aEmptyPoint = Point();
                Rectangle aRect(aEmptyPoint, aSize);

                sal_uInt32 nBlibId = GetBlibID(*QueryPicStream(), aUniqueId,
                    aRect, 0);
                if (nBlibId)
                    rPropOpt.AddOpt(ESCHER_Prop_fillBlip,nBlibId,sal_True);
            }

            if ((nOpaque = pGraphicObject->GetAttr().GetTransparency()))
                bSetOpacity = true;

            rPropOpt.AddOpt( ESCHER_Prop_fillType, ESCHER_FillPicture );
            rPropOpt.AddOpt( ESCHER_Prop_fNoFillHitTest, 0x140014 );
            rPropOpt.AddOpt( ESCHER_Prop_fillBackColor, 0 );
        }
        else
        {
            UINT32 nFillColor = GetColor(pBrush->GetColor(), false);
            rPropOpt.AddOpt( ESCHER_Prop_fillColor, nFillColor );
            rPropOpt.AddOpt( ESCHER_Prop_fillBackColor, nFillColor ^ 0xffffff );
            rPropOpt.AddOpt( ESCHER_Prop_fNoFillHitTest, 0x100010 );

            if ((nOpaque = pBrush->GetColor().GetTransparency()))
                bSetOpacity = true;
        }

        if (bSetOpacity)
        {
            nOpaque = (nOpaque * 100) / 0xFE;
            nOpaque = ((100 - nOpaque) << 16) / 100;
            rPropOpt.AddOpt(ESCHER_Prop_fillOpacity, nOpaque);
        }
    }

    const SdrObject* pObj = rFmt.FindRealSdrObject();
    if( pObj && pObj->GetLayer() == GetHellLayerId() )
        rPropOpt.AddOpt( ESCHER_Prop_fPrint, 0x200020 );

    return nLineWidth;
}

INT32 SwEscherEx::WriteFlyFrameAttr(const SwFrmFmt& rFmt, MSO_SPT eShapeType,
    EscherPropertyContainer& rPropOpt)
{
    INT32 nLineWidth = SwBasicEscherEx::WriteFlyFrameAttr(rFmt, eShapeType,
        rPropOpt);

    /*
     These are not in SwBasicEscherEx::WriteFlyFrameAttr because inline objs
     can't do it in word and it hacks it in by stretching the graphic that
     way, perhaps we should actually draw in this space into the graphic we
     are exporting!
     */
    const SfxPoolItem* pItem;
    if (SFX_ITEM_SET == rFmt.GetItemState(RES_LR_SPACE, true, &pItem))
    {
        rPropOpt.AddOpt( ESCHER_Prop_dxWrapDistLeft,
                DrawModelToEmu( ((SvxLRSpaceItem*)pItem)->GetLeft() ) );
        rPropOpt.AddOpt( ESCHER_Prop_dxWrapDistRight,
                DrawModelToEmu( ((SvxLRSpaceItem*)pItem)->GetRight() ) );
    }
    else
    {
        rPropOpt.AddOpt( ESCHER_Prop_dxWrapDistLeft, 0 );
        rPropOpt.AddOpt( ESCHER_Prop_dxWrapDistRight, 0 );
    }

    if (SFX_ITEM_SET == rFmt.GetItemState(RES_UL_SPACE, true, &pItem))
    {
        rPropOpt.AddOpt( ESCHER_Prop_dyWrapDistTop,
                DrawModelToEmu( ((SvxULSpaceItem*)pItem)->GetUpper() ) );
        rPropOpt.AddOpt( ESCHER_Prop_dyWrapDistBottom,
                DrawModelToEmu( ((SvxULSpaceItem*)pItem)->GetLower() ) );
    }

    return nLineWidth;
}

void SwBasicEscherEx::Init()
{
    MapUnit eMap = MAP_TWIP;
    if (SdrModel *pModel = rWrt.pDoc->GetDrawModel())
    {
        // PPT arbeitet nur mit Einheiten zu 576DPI
        // WW hingegen verwendet twips, dh. 1440DPI.
        eMap = pModel->GetScaleUnit();
    }

    // MS-DFF-Properties sind grossteils in EMU (English Metric Units) angegeben
    // 1mm=36000emu, 1twip=635emu
    Fraction aFact(360, 1);
    aFact /= GetMapFactor(MAP_100TH_MM, eMap).X();
    // create little values
    aFact = Fraction(aFact.GetNumerator(), aFact.GetDenominator());
    mnEmuMul = aFact.GetNumerator();
    mnEmuDiv = aFact.GetDenominator();

    SetHellLayerId(rWrt.pDoc->GetHellId());
}

INT32 SwBasicEscherEx::ToFract16(INT32 nVal, UINT32 nMax) const
{
    if (nMax)
    {
        INT32 nMSVal = (nVal / 65536) * nMax;
        nMSVal += (nVal * 65536 ) / nMax;
        return nMSVal;
    }
    return 0;
}

SvStream* SwBasicEscherEx::QueryPicStream()
{
    if (!pPictStrm)
    {
        pPictStrm = new SvMemoryStream;
        pPictStrm->SetNumberFormatInt(NUMBERFORMAT_INT_LITTLEENDIAN);
    }
    return pPictStrm;
}

void SwBasicEscherEx::WritePictures()
{
    ASSERT(pPictStrm, "no picture!");
    if (pPictStrm)
    {
        // set the blip - entries to the correct stream pos
        INT32 nEndPos = pPictStrm->Tell();
        WriteBlibStoreEntry(*pEscherStrm, 1, sal_True, nEndPos);

        pPictStrm->Seek(0);
        *pEscherStrm << *pPictStrm;

        delete pPictStrm, pPictStrm = 0;
    }
}

SwEscherEx::SwEscherEx(SvStream* pStrm, SwWW8Writer& rWW8Wrt)
    : SwBasicEscherEx(pStrm, rWW8Wrt, rWW8Wrt.pHFSdrObjs->size() ? 2 : 1),
    pTxtBxs(0)
{
    aHostData.SetClientData(&aWinwordAnchoring);
    OpenContainer( ESCHER_DggContainer );

    sal_uInt16 nColorCount = 4;
    *pStrm  << (sal_uInt16)( nColorCount << 4 )     // instance
            << (sal_uInt16)ESCHER_SplitMenuColors   // record type
            << (sal_uInt32)( nColorCount * 4 )      // size
            << (sal_uInt32)0x08000004
            << (sal_uInt32)0x08000001
            << (sal_uInt32)0x08000002
            << (sal_uInt32)0x100000f7;

    CloseContainer();   // ESCHER_DggContainer

    BYTE i = 2;     // for header/footer and the other
    PlcDrawObj *pSdrObjs = rWrt.pHFSdrObjs;
    pTxtBxs = rWrt.pHFTxtBxs;

    // if no header/footer -> skip over
    if (!pSdrObjs->size())
    {
        --i;
        pSdrObjs = rWrt.pSdrObjs;
        pTxtBxs = rWrt.pTxtBxs;
    }

    for( ; i--; pSdrObjs = rWrt.pSdrObjs, pTxtBxs = rWrt.pTxtBxs )
    {
        // "dummy char" (or any Count ?) - why? This knows only M$
        GetStream() << (sal_Char)i;

        OpenContainer( ESCHER_DgContainer );

        EnterGroup( 0 );

        ULONG nSecondShapeId = pSdrObjs == rWrt.pSdrObjs ? GetShapeID() : 0;

        // write now all Writer-/DrawObjects
        MakeZOrderArrAndFollowIds( pSdrObjs->GetObjArr() );

        ULONG nShapeId=0;
        for( USHORT n = 0; n < aSortFmts.Count(); ++n )
        {
            INT32 nBorderThick=0;
            const SwFrmFmt& rFmt = *(const SwFrmFmt*)aSortFmts[n];
            if (RES_FLYFRMFMT == rFmt.Which())
                nBorderThick = WriteFlyFrm(rFmt, nShapeId, maDirections[n]);
            else if (rFmt.FindRealSdrObject()->GetObjInventor() ==
                     FmFormInventor)
            {
                WriteOCXControl(rFmt,nShapeId=GetShapeID());
            }
            else
            {
                aWinwordAnchoring.SetAnchoring(rFmt, true);
                const SdrObject* pObj = rFmt.FindRealSdrObject();
                if( pObj )
                    nShapeId = AddSdrObject( *pObj );
#ifndef PRODUCT
                else
                    ASSERT( !this, "wo ist das SDR-Object?" );
#endif
            }

            if( !nShapeId )
            {
                /*!!!*/ const SdrObject* pObj = 0;
                nShapeId = AddDummyShape( *pObj );
            }

            pSdrObjs->SetShapeDetails(rFmt, nShapeId, nBorderThick);
        }

        EndSdrObjectPage();         // ???? Bugfix for 74724

//        LeaveGroup();             // done in EndSdrObjectPage()

        if( nSecondShapeId )
        {
            OpenContainer( ESCHER_SpContainer );

            AddShape( ESCHER_ShpInst_Rectangle, 0xe00, nSecondShapeId );

            EscherPropertyContainer aPropOpt;
            // default Fuellfarbe ist das StarOffice blau7
            // ----> von DrawingLayer besorgen !!
            aPropOpt.AddOpt( ESCHER_Prop_fillColor, 0xffb800 );
            aPropOpt.AddOpt( ESCHER_Prop_fillBackColor, 0 );
            aPropOpt.AddOpt( ESCHER_Prop_fNoFillHitTest, 0x00100010 );
            aPropOpt.AddOpt( ESCHER_Prop_lineColor, 0x8000001 );
            aPropOpt.AddOpt( ESCHER_Prop_fNoLineDrawDash, 0x00080008 );
            aPropOpt.AddOpt( ESCHER_Prop_shadowColor, 0x8000002 );
            aPropOpt.AddOpt( ESCHER_Prop_lineWidth, 0 );

// winword defaults!
//          aPropOpt.AddOpt( ESCHER_Prop_fNoFillHitTest, 0x100000 );
//          aPropOpt.AddOpt( ESCHER_Prop_lineWidth, 0 );
//          aPropOpt.AddOpt( ESCHER_Prop_fNoLineDrawDash, 0x80000 );
//          aPropOpt.AddOpt( ESCHER_Prop_bWMode, 0x9 );
//          aPropOpt.AddOpt( ESCHER_Prop_fBackground, 0x10001 );

            aPropOpt.Commit( *pStrm );

            AddAtom( 4, ESCHER_ClientData );
            GetStream() << 1L;

            CloseContainer();   // ESCHER_SpContainer
        }
    CloseContainer();   // ESCHER_DgContainer
    }
}

SwEscherEx::~SwEscherEx()
{
}

void SwEscherEx::FinishEscher()
{
    pEscherStrm->Seek(0);
    *rWrt.pTableStrm << *pEscherStrm;
    delete pEscherStrm, pEscherStrm = 0;

    /*#82587# Everytime MS 2000 creates an escher stream there is always an
     ObjectPool dir (even if empty). It turns out that if a copy of MS 2000 is
     used to open a document that contains escher graphics exported from
     StarOffice without this empty dir then *if* that copy of MS Office has
     never been used to open a MSOffice document that has escher graphics (and
     an ObjectPool dir of course) and that copy of office has not been used to
     draw escher graphics then our exported graphics do not appear. Once you
     do open a ms document with escher graphics or draw an escher graphic with
     that copy of word, then all documents from staroffice that contain escher
     work from then on. Tricky to track down, some sort of late binding
     trickery in MS where solely for first time initialization the existence
     of an ObjectPool dir is necessary for triggering some magic. cmc*/
    rWrt.GetStorage().OpenStorage(CREATE_CONST_ASC(SL::aObjectPool),
        STREAM_READWRITE | STREAM_SHARE_DENYALL);
}

extern "C"
{
    static int CompUINT32( const void *pFirst, const void *pSecond)
    {
        return(
            (*((UINT32*)pFirst ) & 0xFFFFFF00) -
            (*((UINT32*)pSecond) & 0xFFFFFF00) );
    }
}

void WinwordAnchoring::SetAnchoring(const SwFrmFmt& rFmt, bool bBROKEN)
{
    const RndStdIds eAnchor = rFmt.GetAnchor().GetAnchorId();

    const SwFmtHoriOrient&  rHoriOri = rFmt.GetHoriOrient();
    const SwFmtVertOrient&  rVertOri = rFmt.GetVertOrient();

    const SwHoriOrient eHOri = rHoriOri.GetHoriOrient();
    const SwVertOrient eVOri = rVertOri.GetVertOrient();

    SwRelationOrient   eHRel = rHoriOri.GetRelationOrient();
    SwRelationOrient   eVRel = rVertOri.GetRelationOrient();

    //There must be a problem with page anchoring and draw objects in writer
    //must be a problem somewhere.
    if (bBROKEN)
    {
        if (eHRel == PRTAREA)
            eHRel = FRAME;
        if (eVRel == PRTAREA)
            eVRel = FRAME;
    }

    UINT32 nHIndex = 0;
    UINT32 nVIndex = 0;

    switch( eAnchor )
    {
        case FLY_PAGE:
            nHIndex = 0x00000000;
            nVIndex = 0x10000000;
            // match eHRel ?
            if(      PRTAREA == eHRel ) eHRel = REL_PG_PRTAREA;
            else if( FRAME   == eHRel ) eHRel = REL_PG_FRAME;
            // match eVRel ?
            if(      REL_PG_PRTAREA == eVRel ) eVRel = PRTAREA;
            else
            if(      REL_PG_FRAME   == eVRel ) eVRel = FRAME;
            break;
        case FLY_AT_CNTNT:
            nHIndex = 0x01000000;
            nVIndex = 0x11000000;
            break;
        case FLY_AUTO_CNTNT:
            nHIndex = 0x01000000;
            nVIndex = 0x12000000;
            break;
        case FLY_IN_CNTNT:
            nHIndex = 0x02000000;
            nVIndex = 0x13000000;
            break;
        default:
            nHIndex = 0x01000000; // FLY_AT_CNTNT
            nVIndex = 0x11000000;
            break;
    }

    switch( eHRel )
    {
        case FRAME:
        //  nHIndex |= 0x00000000;
            break;
        case PRTAREA:
            nHIndex |= 0x00010000;
            break;
        case REL_PG_LEFT:
            nHIndex |= 0x00020000;
            break;
        case REL_PG_RIGHT:
            nHIndex |= 0x00030000;
            break;
        case REL_FRM_LEFT:
            nHIndex |= 0x00040000;
            break;
        case REL_FRM_RIGHT:
            nHIndex |= 0x00050000;
            break;
        case REL_PG_FRAME:
            nHIndex |= 0x00060000;
            break;
        case REL_PG_PRTAREA:
            nHIndex |= 0x00070000;
            break;
        case REL_CHAR:
            nHIndex |= 0x00080000;
            break;
        default:
            nHIndex |= 0x00090000; // PRTAREA
            break;
    }

    switch( eHOri )
    {
        case HORI_LEFT:
        //  nHIndex |= 0x00000000;
            break;
        case HORI_INSIDE:
            nHIndex |= 0x00000100;
            break;
        case HORI_RIGHT:
            nHIndex |= 0x00000200;
            break;
        case HORI_OUTSIDE:
            nHIndex |= 0x00000300;
            break;
        case HORI_CENTER:
            nHIndex |= 0x00000400;
            break;
        case HORI_NONE:
            nHIndex |= 0x00000500;
            break;
        default:
        //  nHIndex |= 0x00000000; // HORI_LEFT
            break;
    }

    switch( eVRel )
    {
        case FRAME:
        //  nVIndex |= 0x00000000;
            break;
        case PRTAREA:
            nVIndex |= 0x00010000;
            break;
        case REL_CHAR:
            nVIndex |= 0x00020000;
            break;
        default:
            nVIndex |= 0x00030000; // PRTAREA
            break;
    }

    switch( eVOri )
    {
        case VERT_TOP:
        //  nVIndex |= 0x00000000;
            break;
        case VERT_BOTTOM:
            nVIndex |= 0x00000100;
            break;
        case VERT_CENTER:
            nVIndex |= 0x00000200;
            break;
        case VERT_NONE:
            nVIndex |= 0x00000300;
            break;
        case VERT_CHAR_TOP:
            nVIndex |= 0x00000400;
            break;
        case VERT_CHAR_CENTER:
            nVIndex |= 0x00000500;
            break;
        case VERT_CHAR_BOTTOM:
            nVIndex |= 0x00000600;
            break;
        case VERT_LINE_TOP:
            nVIndex |= 0x00000700;
            break;
        case VERT_LINE_CENTER:
            nVIndex |= 0x00000800;
            break;
        case VERT_LINE_BOTTOM:
            nVIndex |= 0x00000900;
            break;
        default:
        //  nVIndex |= 0x00000000; // VERT_TOP
            break;
    }

/*
    Note: the following table MUST be sorted in ascendent order!

        nXAlign - abs. Position, Left,  Centered,  Right,  Inside, Outside
        nYAlign - abs. Position, Top,   Centered,  Bottom, Inside, Outside

        nXRelTo - Page printable area, Page,  Column,    Character
        nYRelTo - Page printable area, Page,  Paragraph, Line

        Match:  0x99 99 99 9 9
                   |  |  | | |
                   |  |  | | +-- ord of nXRelTo
                   |  |  | +---- ord of nXAlign
                   |  |  |
                   |  |  +------ SwHoriOrient
                   |  +--------- SwRelationOrient (horizontal)
                   +------------ RndStdIds
*/
    static const UINT32 aHVMatcher [] = {

//     H O R I Z O N T A L    SwHoriOrient:   HORI_LEFT, HORI_INSIDE, HORI_RIGHT, HORI_OUTSIDE, HORI_CENTER, HORI_NONE
//                                                0          1            2           3             4            5

    // RndStdIds: FLY_PAGE: 0

    // SwRelationOrient: REL_PG_LEFT: 2
    //               |
                0x00020011,  // SwHoriOrient: HORI_LEFT
                0x00020111,  //               HORI_INSIDE
                0x00020211,  //               HORI_RIGHT
                0x00020311,  //               HORI_OUTSIDE
                0x00020411,  //               HORI_CENTER
                0x00020511,  //               HORI_NONE
    // SwRelationOrient: REL_PG_RIGHT: 3
    //               |
                0x00030031,
                0x00030131,
                0x00030231,
                0x00030331,
                0x00030431,
                0x00030531,
    // SwRelationOrient: REL_PG_FRAME: 6
    //               |
                0x00060011,
                0x00060141,
                0x00060231,
                0x00060351,
                0x00060421,
                0x00060501,
    // SwRelationOrient: REL_PG_PRTAREA: 7
    //               |
                0x00070010,
                0x00070140,
                0x00070230,
                0x00070350,
                0x00070420,
                0x00070500,

    // RndStdIds: FLY_AT_CNTNT: 1
    //
    // SwRelationOrient: FRAME: 0
    //               |
                0x01000012,
                0x01000112,
                0x01000232,
                0x01000332,
                0x01000422,
                0x01000502,
    // SwRelationOrient: PRTAREA: 1
    //               |
                0x01010012,
                0x01010112,
                0x01010232,
                0x01010332,
                0x01010422,
                0x01010502,
    // SwRelationOrient: REL_PG_LEFT: 2
    //               |
                0x01020011,
                0x01020111,
                0x01020211,
                0x01020311,
                0x01020411,
                0x01020511,
    // SwRelationOrient: REL_PG_RIGHT: 3
    //               |
                0x01030031,
                0x01030131,
                0x01030231,
                0x01030331,
                0x01030431,
                0x01030531,
    // SwRelationOrient: REL_FRM_LEFT: 4
    //               |
                0x01040012,
                0x01040112,
                0x01040212,
                0x01040312,
                0x01040412,
                0x01040512,
    // SwRelationOrient: REL_FRM_RIGHT: 5
    //               |
                0x01050032,
                0x01050132,
                0x01050232,
                0x01050332,
                0x01050432,
                0x01050532,
    // SwRelationOrient: REL_PG_FRAME: 6
    //               |
                0x01060011,
                0x01060141,
                0x01060231,
                0x01060351,
                0x01060421,
                0x01060501,
    // SwRelationOrient: REL_PG_PRTAREA: 7
    //               |
                0x01070010,
                0x01070140,
                0x01070230,


                0x01070350,
                0x01070420,
                0x01070500,

    // i2916
    // RndStdIds: FLY_AUTO_CNTNT: 1
    //
    // As for FLY_AT_CNTNT with the addition
    // of following.
    //
    // SwRelationOrient: REL_CHAR: 8
    //               |
                0x01080013,
                0x01080113,
                0x01080233,
                0x01080333,
                0x01080423,
                0x01080503,


    // RndStdIds: FLY_IN_CNTNT: 2
    //
    // SwRelationOrient: FRAME: 0
    //               |
                0x02000012,
                0x02000112,
                0x02000232,
                0x02000332,
                0x02000422,
                0x02000502,
    // SwRelationOrient: PRTAREA: 1
    //               |
                0x02010012,
                0x02010112,
                0x02010232,
                0x02010332,
                0x02010422,
                0x02010502,
    // SwRelationOrient: REL_PG_LEFT: 2
    //               |
                0x02020011,
                0x02020111,
                0x02020211,
                0x02020311,
                0x02020411,
                0x02020511,
    // SwRelationOrient: REL_PG_RIGHT: 3
    //               |
                0x02030031,
                0x02030131,
                0x02030231,
                0x02030331,
                0x02030431,
                0x02030531,
    // SwRelationOrient: REL_FRM_LEFT: 4
    //               |
                0x02040012,
                0x02040112,
                0x02040212,
                0x02040312,
                0x02040412,
                0x02040512,
    // SwRelationOrient: REL_FRM_RIGHT: 5
    //               |
                0x02050032,
                0x02050132,
                0x02050232,
                0x02050332,
                0x02050432,
                0x02050532,
    // SwRelationOrient: REL_PG_FRAME: 6
    //               |
                0x02060011,
                0x02060141,
                0x02060231,
                0x02060351,
                0x02060421,
                0x02060501,
    // SwRelationOrient: REL_PG_PRTAREA: 7
    //               |
                0x02070010,
                0x02070140,
                0x02070230,
                0x02070350,
                0x02070420,
                0x02070500,
    // SwRelationOrient: REL_CHAR: 8
    //               |
                0x02080013,
                0x02080113,
                0x02080233,
                0x02080333,
                0x02080423,
                0x02080503,

//     V E R T I C A L   SwVertOrient:   VERT_TOP, VERT_BOTTOM, VERT_CENTER, VERT_NONE, VERT_CHAR_TOP, VERT_CHAR_CENTER, VERT_CHAR_BOTTOM, VERT_LINE_TOP, VERT_LINE_CENTER, VERT_LINE_BOTTOM
//                                           0         1            2            3          4              5                 6 == "below"      7              8                 9

    // RndStdIds: FLY_PAGE: 0x10
    //
    // SwRelationOrient: REL_PG_FRAME (or FRAME resp.): 0
    //               |
                0x10000011,  // SwVertOrient: VERT_TOP
                0x10000131,  //               VERT_BOTTOM
                0x10000221,  //               VERT_CENTER
                0x10000301,  //               VERT_NONE
    // SwRelationOrient: REL_PG_PRTAREA (or PRTAREA resp.): 1
    //               |
                0x10010010,  // SwVertOrient: VERT_TOP
                0x10010130,  //               VERT_BOTTOM
                0x10010220,  //               VERT_CENTER
                0x10010300,  //               VERT_NONE

    // RndStdIds: FLY_AT_CNTNT: 0x11
    //
    // SwRelationOrient: FRAME: 0
    //               |
                0x11000013,  // SwVertOrient: VERT_TOP
                0x11000133,  //               VERT_BOTTOM
                0x11000223,  //               VERT_CENTER
                0x11000302,  //               VERT_NONE
    // SwRelationOrient: PRTAREA: 1
    //               |
                0x11010013,  // SwVertOrient: VERT_TOP
                0x11010133,  //               VERT_BOTTOM
                0x11010223,  //               VERT_CENTER
                0x11010302,  //               VERT_NONE

    // RndStdIds: "to character" == FLY_AUTO_CNTNT: 0x12
    //
    // SwRelationOrient: "Margin" == FRAME: 0
    //               |
                0x12000013,  // SwVertOrient: VERT_TOP
                0x12000133,  //               VERT_BOTTOM
                0x12000223,  //               VERT_CENTER
                0x12000302,  //               VERT_NONE
    // SwRelationOrient: "Textarea" == PRTAREA: 1
    //               |
                0x12010013,  // SwVertOrient: VERT_TOP
                0x12010133,  //               VERT_BOTTOM
                0x12010223,  //               VERT_CENTER
                0x12010302,  //               VERT_NONE
    // SwRelationOrient: "Character" == REL_CHAR: 2
    //               |
                0x12020013,  // SwVertOrient: VERT_TOP
                0x12020133,  //               VERT_BOTTOM
                0x12020223,  //               VERT_CENTER
                0x12020302,  //               VERT_NONE
                0x12020633,  //               VERT_CHAR_BOTTOM (value: 6)

    // RndStdIds: "as character" == FLY_IN_CNTNT: 0x13
    //
    // SwRelationOrient: FRAME: 0
    //               |
                0x13000013,  // SwVertOrient: VERT_TOP        (baseline)
                0x13000133,  //               VERT_BOTTOM
                0x13000223,  //               VERT_CENTER
                0x13000302,  //               VERT_NONE        == "from bottom"

                0x13000413,  //               VERT_CHAR_TOP   (character)
                0x13000533,  //               VERT_CHAR_CENTER
                0x13000623,  //               VERT_CHAR_BOTTOM == "below"

                0x13000713,  //               VERT_LINE_TOP   (row)
                0x13000813,  //               VERT_LINE_CENTER
                0x13000923,  //               VERT_LINE_BOTTOM
        };

    // find horizontal values
    UINT32* pFound = (UINT32*)bsearch( (const void*) &nHIndex,
        (const void*) aHVMatcher, sizeof(aHVMatcher) / sizeof(aHVMatcher[0]),
        sizeof(aHVMatcher[0]), CompUINT32 );
    if( !pFound )
        pFound = (UINT32*)aHVMatcher; // take Element #0 if none found
    nXAlign = (*pFound & 0x000000F0) >> 4;
    nXRelTo = (*pFound & 0x0000000F);

    // find vertical values
    pFound= (UINT32*)bsearch( (const void*) &nVIndex, (void*) aHVMatcher,
        sizeof(aHVMatcher) / sizeof(aHVMatcher[0]), sizeof(aHVMatcher[0]),
        CompUINT32 );
    if( !pFound )
        pFound = (UINT32*)aHVMatcher; // take Element #0 if none found
    nYAlign = (*pFound & 0x000000F0) >> 4;
    nYRelTo = (*pFound & 0x0000000F);
}

void SwEscherEx::WriteFrmExtraData( const SwFrmFmt& rFmt )
{
    aWinwordAnchoring.SetAnchoring(rFmt);
    aWinwordAnchoring.WriteData(*this);

    AddAtom(4, ESCHER_ClientAnchor);
    GetStream() << 0L;

    AddAtom(4, ESCHER_ClientData);
    GetStream() << 1L;
}

INT32 SwEscherEx::WriteFlyFrm(const SwFrmFmt& rFmt, UINT32 &rShapeId,
    short nDirection)
{
    // check for textflyframe and if it is the first in a Chain
    INT32 nBorderThick = 0;
    const SwNodeIndex* pNdIdx = rFmt.GetCntnt().GetCntntIdx();
    if( pNdIdx )
    {
        SwNodeIndex aIdx( *pNdIdx, 1 );
        switch( aIdx.GetNode().GetNodeType() )
        {
        case ND_GRFNODE:
            nBorderThick = WriteGrfFlyFrame( rFmt, rShapeId = GetShapeID() );
            break;
        case ND_OLENODE:
            nBorderThick = WriteOLEFlyFrame( rFmt, rShapeId = GetShapeID() );
            break;
        default:
            if (const SdrObject* pObj = rFmt.FindRealSdrObject())
            {
                // check for the first in a Chain
                UINT32 nTxtId;
                USHORT nOff = 0;
                const SwFrmFmt* pFmt = &rFmt, *pPrev;
                while( 0 != ( pPrev = pFmt->GetChain().GetPrev() ))
                {
                    ++nOff;
                    pFmt = pPrev;
                }

                rShapeId = GetFlyShapeId( rFmt );
                if( !nOff )
                {
                    void* p = (void*)pObj;
                    nTxtId = pTxtBxs->GetPos( p );
                    if( USHRT_MAX == nTxtId )
                    {
                        pTxtBxs->Append( *pObj, rShapeId );
                        nTxtId = pTxtBxs->Count();
                    }
                    else
                        ++nTxtId;
                }
                else
                {
                    const SdrObject* pPrevObj = pFmt->FindRealSdrObject();
                    void* p = (void*)pPrevObj;
                    nTxtId = pTxtBxs->GetPos( p );
                    if( USHRT_MAX == nTxtId )
                    {
                        UINT32 nPrevShapeId = GetFlyShapeId( *pFmt );
                        pTxtBxs->Append( *pPrevObj, nPrevShapeId );
                        nTxtId = pTxtBxs->Count();
                    }
                    else
                        ++nTxtId;
                }
                nTxtId *= 0x10000;
                nTxtId += nOff;

                nBorderThick = WriteTxtFlyFrame(rFmt, rShapeId, nTxtId,
                    nDirection);
            }
        }
    }
    return nBorderThick;
}

INT32 SwEscherEx::WriteTxtFlyFrame(const SwFrmFmt& rFmt, UINT32 nShapeId,
    UINT32 nTxtBox, short nDirection)
{
    INT32 nBorderThick=0;
    OpenContainer( ESCHER_SpContainer );

    AddShape( ESCHER_ShpInst_TextBox, 0xa00, nShapeId );
    EscherPropertyContainer aPropOpt;
    aPropOpt.AddOpt( ESCHER_Prop_lTxid, nTxtBox );
    const VoidPtr pNext = rFmt.GetChain().GetNext();
    if( pNext )
    {
        USHORT nPos = aSortFmts.GetPos( pNext );
        if( USHRT_MAX != nPos && aFollowShpIds[ nPos ] )
            aPropOpt.AddOpt( ESCHER_Prop_hspNext, aFollowShpIds[ nPos ] );
    }
    nBorderThick = WriteFlyFrameAttr( rFmt, mso_sptTextBox, aPropOpt );

    MSO_TextFlow nFlow;

    switch (nDirection)
    {
        default:
            ASSERT(!this, "unknown direction type");
        case FRMDIR_HORI_LEFT_TOP:
            nFlow=mso_txflHorzN;
        break;
        case FRMDIR_HORI_RIGHT_TOP:
            nFlow=mso_txflHorzN;
        break;
        case FRMDIR_VERT_TOP_LEFT: //not really possible in word
        case FRMDIR_VERT_TOP_RIGHT:
            nFlow=mso_txflTtoBA;
        break;
    }
    aPropOpt.AddOpt( ESCHER_Prop_txflTextFlow, nFlow );

    aPropOpt.Commit( GetStream() );

    // store anchor attribute
    WriteFrmExtraData( rFmt );

    AddAtom( 4, ESCHER_ClientTextbox ); GetStream() << nTxtBox;

    CloseContainer();   // ESCHER_SpContainer
    return nBorderThick;
}

void SwEscherEx::WriteOCXControl( const SwFrmFmt& rFmt, UINT32 nShapeId )
{
    if (const SdrObject* pSdrObj = rFmt.FindRealSdrObject())
    {
        OpenContainer( ESCHER_SpContainer );

        AddShape( ESCHER_ShpInst_PictureFrame, 0xa10, nShapeId );

        EscherPropertyContainer aPropOpt;
        Size aSz( pSdrObj->GetLogicRect().GetSize() );
        aSz.Width() = DrawModelToEmu( aSz.Width() );
        aSz.Height() = DrawModelToEmu( aSz.Height() );

        SetPicId(*pSdrObj, nShapeId, aPropOpt);

        aPropOpt.AddOpt( ESCHER_Prop_pictureActive, 0x10000 );
        WriteFlyFrameAttr( rFmt, mso_sptPictureFrame , aPropOpt );
        aPropOpt.Commit( GetStream() );

        // store anchor attribute
        WriteFrmExtraData( rFmt );

        CloseContainer();   // ESCHER_SpContainer
    }
}

/*
 I actually want to use EMF not PNG but until issue #i2192# is resolved then I
 can't risk having a math object using starsymbol exported to word as it'll
 not render correctly :-(

 Optionally I would prefer to detect if a GDIMetafile is using
 {Open|Star}Symbol and if it is then use PNG, and if not use EMF. That would
 be a very acceptable compromise in my view.
*/
Graphic wwUtility::MakeSafeGDIMetaFile(SvInPlaceObjectRef xObj)
{
    Graphic aGraphic;
    GDIMetaFile aGDIMtf;

    if (xObj.Is())
    {
        VirtualDevice aVDev;
        const MapMode aMap100(MAP_100TH_MM);
        const Size& rSize = xObj->GetVisArea().GetSize();

        aVDev.SetMapMode(aMap100);
        aGDIMtf.Record(&aVDev);

        xObj->DoDraw(&aVDev, Point(), rSize, JobSetup());

        aGDIMtf.Stop();
        aGDIMtf.WindStart();
        aGDIMtf.SetPrefMapMode(aMap100);
        aGDIMtf.SetPrefSize(rSize);
        aGraphic = Graphic(aGDIMtf);
    }

    BitmapEx aBmpEx(aGraphic.GetBitmap(0));
    aBmpEx.SetPrefMapMode(aGDIMtf.GetPrefMapMode());
    aBmpEx.SetPrefSize(aGDIMtf.GetPrefSize());
    return Graphic(aBmpEx);
}

void SwEscherEx::MakeZOrderArrAndFollowIds(
    const ::std::vector<DrawObj>& rSrcArr)
{
    if (aSortFmts.Count())
        aSortFmts.Remove( 0, aSortFmts.Count() );

    USHORT n, nPos, nCnt = rSrcArr.size();
    SvULongsSort aSort( 255 < nCnt ? 255 : nCnt, 255 );
    ASSERT(maDirections.empty(), "Impossible");
    maDirections.resize(nCnt);
    for( n = 0; n < nCnt; ++n )
    {
        ULONG nOrdNum = rWrt.GetSdrOrdNum(rSrcArr[n].mrCntnt);
        aSort.Insert( nOrdNum, nPos );
        void* p = (void *)(&(rSrcArr[n].mrCntnt));
        aSortFmts.Insert( p, nPos );
        maDirections[nPos] = rSrcArr[n].mnDirection;
    }

    if (aFollowShpIds.Count())
        aFollowShpIds.Remove(0, aFollowShpIds.Count());

    ULONG nShapeId;
    const SwFmtChain* pChain;
    for( n = 0; n < nCnt; ++n )
    {
        const SwFrmFmt* pFmt = (const SwFrmFmt*)aSortFmts[ n ];

        if( RES_FLYFRMFMT == pFmt->Which() &&
            ( ( pChain = &pFmt->GetChain())->GetPrev() ||
                pChain->GetNext() ) )
        {
            // the format needs a shapeid
            nShapeId = GetShapeID();
        }
        else
            nShapeId = 0;
        aFollowShpIds.Insert( nShapeId, n );
    }
}


UINT32 SwEscherEx::GetFlyShapeId( const SwFrmFmt& rFmt )
{
    const VoidPtr pFmt = (void*)&rFmt;
    USHORT nPos = aSortFmts.GetPos( pFmt );
    UINT32 nShapeId;
    if( USHRT_MAX != nPos )
    {
        if( 0 == ( nShapeId = aFollowShpIds[ nPos ] ))
        {
            nShapeId = GetShapeID();
            aFollowShpIds[ nPos ] = nShapeId;
        }
    }
    else
        nShapeId = GetShapeID();
    return nShapeId;
}

UINT32 SwEscherEx::QueryTextID(
    const uno::Reference< drawing::XShape>& xXShapeRef, UINT32 nShapeId )
{
    UINT32 nId = 0;
    if (SdrObject* pObj = GetSdrObjectFromXShape(xXShapeRef))
    {
        pTxtBxs->Append( *pObj, nShapeId );
        nId = pTxtBxs->Count();
        nId *= 0x10000;
    }
    return nId;
}

bool SwMSConvertControls::ExportControl(Writer &rWrt, const SdrObject *pObj)
{
    SwWW8Writer& rWW8Wrt = (SwWW8Writer&)rWrt;

    if (!rWW8Wrt.bWrtWW8)
        return false;

    SdrUnoObj *pFormObj = PTR_CAST(SdrUnoObj,pObj);
    uno::Reference< awt::XControlModel > xControlModel =
    pFormObj->GetUnoControlModel();

    //Why oh lord do we use so many different units ?
    //I think I painted myself into a little bit of a
    //corner by trying to use the uno interface for
    //controls export
    Size aTempSize=pFormObj->GetLogicRect().GetSize();
    awt::Size aSize;
    aSize.Width = TWIPS_TO_MM(aTempSize.A());
    aSize.Height = TWIPS_TO_MM(aTempSize.B());

    //Open the ObjectPool
    SvStorageRef xObjPool = rWW8Wrt.GetStorage().OpenStorage(
        CREATE_CONST_ASC(SL::aObjectPool), STREAM_READWRITE |
        STREAM_SHARE_DENYALL);

    //Create a destination storage for the microsoft control
    String sStorageName('_');
    sStorageName += String::CreateFromInt32((UINT32)pObj);
    SvStorageRef xOleStg = xObjPool->OpenStorage(sStorageName,
                 STREAM_READWRITE|STREAM_SHARE_DENYALL);

    if (!xOleStg.Is())
        return false;

    String sName;
    if (!WriteOCXStream(xOleStg,xControlModel,aSize,sName))
        return false;

    BYTE aSpecOLE[] =
    {
        0x03, 0x6a, 0xFF, 0xFF, 0xFF, 0xFF, // sprmCPicLocation
        0x0a, 0x08, 1,                  // sprmCFOLE2
        0x55, 0x08, 1,                  // sprmCFSpec
        0x56, 0x08, 1                   // sprmCFObj
    };
    //Set the obj id into the sprmCPicLocation
    BYTE *pData = aSpecOLE+2;
    Set_UInt32(pData,(UINT32)pObj);

    sName.InsertAscii(" CONTROL Forms.",0);
    sName.APPEND_CONST_ASC(".1 \\s ");

    rWW8Wrt.OutField(0,87,sName,
        WRITEFIELD_START|WRITEFIELD_CMD_START|WRITEFIELD_CMD_END);

    rWW8Wrt.pChpPlc->AppendFkpEntry(rWW8Wrt.Strm().Tell(),sizeof(aSpecOLE),
        aSpecOLE);
    rWW8Wrt.WriteChar( 0x1 );
    rWW8Wrt.OutField( 0, 87, aEmptyStr, WRITEFIELD_END | WRITEFIELD_CLOSE );
    return true;
}