~ubuntu-branches/debian/experimental/cuneiform/experimental

« back to all changes in this revision

Viewing changes to cuneiform_src/Kern/ced/sources/main/ced_func.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2009-07-10 17:58:10 UTC
  • Revision ID: james.westby@ubuntu.com-20090710175810-rqc89d2i3tki9m89
Tags: upstream-0.7.0+dfsg
ImportĀ upstreamĀ versionĀ 0.7.0+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright (c) 1993-2008, Cognitive Technologies
 
3
All rights reserved.
 
4
 
 
5
ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ ļæ½ ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½,
 
6
ļæ½ļæ½ļæ½ ļæ½ ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½, ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½, ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½:
 
7
 
 
8
      * ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½
 
9
        ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½, ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½
 
10
        ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½.
 
11
      * ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½/ļæ½ļæ½ļæ½ ļæ½
 
12
        ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½, ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½, ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½
 
13
        ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½, ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½
 
14
        ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½.
 
15
      * ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ Cognitive Technologies, ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½
 
16
        ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½/ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½
 
17
        ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½, ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½, ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½
 
18
        ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½.
 
19
 
 
20
ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ ļæ½/ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ "ļæ½ļæ½ļæ½
 
21
ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½" ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½-ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½, ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½,
 
22
ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½, ļæ½ļæ½ ļæ½ļæ½
 
23
ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½. ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ ļæ½ ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½, ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½
 
24
ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½/ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½, ļæ½ļæ½ ļæ½ ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½
 
25
ļæ½ļæ½ŃØļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½, ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½, ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½, ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½
 
26
ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½, ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½
 
27
ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ (ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½, ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½,
 
28
ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½, ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½/ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½, ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½-ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½
 
29
ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ ļæ½/ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½,
 
30
ļæ½ļæ½ ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½), ļæ½ļæ½ ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½, ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½
 
31
ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½ ļæ½ ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½.
 
32
 
 
33
Redistribution and use in source and binary forms, with or without modification,
 
34
are permitted provided that the following conditions are met:
 
35
 
 
36
    * Redistributions of source code must retain the above copyright notice,
 
37
      this list of conditions and the following disclaimer.
 
38
    * Redistributions in binary form must reproduce the above copyright notice,
 
39
      this list of conditions and the following disclaimer in the documentation
 
40
      and/or other materials provided with the distribution.
 
41
    * Neither the name of the Cognitive Technologies nor the names of its
 
42
      contributors may be used to endorse or promote products derived from this
 
43
      software without specific prior written permission.
 
44
 
 
45
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 
46
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 
47
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
48
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
 
49
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 
50
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 
51
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 
52
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 
53
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
54
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
55
*/
 
56
 
 
57
#include <string.h>
 
58
#include "stdafx.h"
 
59
 
 
60
#include "ced_struct.h"
 
61
#include "cedint.h"
 
62
#include "resource.h"
 
63
//#include "cfio.h"
 
64
//#include "edfile.h"
 
65
//#include "edext.h"
 
66
//#include "ced_struct.h"
 
67
 
 
68
//First of all, we define all .dib as metafiles since word does not know about .dib
 
69
static CEDPage * mainPage;
 
70
static CEDLine * curEdLine;
 
71
static edBox            refBox;
 
72
static int              font,kegl,lang;
 
73
static int foregroundColor,backgroundColor,fontNum;
 
74
static char * verInfo;
 
75
 
 
76
static void ExtDataProc(Word8* _ptr, Word32 lth);
 
77
void NewFormattedSDD(const sheet_disk_descr* pt);
 
78
void NewFormattedFDD(const fragm_disk_descr* pt);
 
79
void NewFormattedTR(const text_ref* pt);
 
80
//void NewFormattedFD(const fragm_disk* pt);
 
81
void NewFormattedLB(const line_beg* pt);
 
82
void NewFormattedL(const letter* pt,const Word32 alternatives);
 
83
void NewFormattedBMR(const bit_map_ref * pt);
 
84
void NewFormattedFK(const font_kegl * pt);
 
85
void NewFormattedE(const edExtention* pt,const void* ptExt);
 
86
void NewFormattedENew(const edExtentionNew* pt,const void* ptExt);
 
87
void NewFormattedLang(const EdTagLanguage* pt);
 
88
 
 
89
void CED_DeleteTree(CEDPage * pg)
 
90
{
 
91
        delete pg;
 
92
}
 
93
 
 
94
void RepairStructure();
 
95
 
 
96
CEDPage * CED_FormattedLoad (char * file,Bool32 readFromFile, Word32 bufLen)
 
97
{
 
98
        CED_SetRawDataProc(ExtDataProc);
 
99
        if (CED_IsEdFile(file,readFromFile,bufLen)==96)
 
100
        {
 
101
                return 0;
 
102
//              return Formattedload_96(char * file,Bool32 readFromFile, Word32 bufLen);
 
103
        }
 
104
        else if (CED_IsEdFile(file,readFromFile,bufLen)!=2000)
 
105
                return 0;
 
106
        CED_SheetDiskDescr=NewFormattedSDD;
 
107
        CED_TextRef=NewFormattedTR;
 
108
//      CED_FragmDiskDescr=FormattedFDD;
 
109
//      CED_FragmDisk=NewFormattedFD;
 
110
        CED_LineBeg=NewFormattedLB;
 
111
        CED_Letter=NewFormattedL;
 
112
        CED_BitmapRef=NewFormattedBMR;
 
113
        CED_FontKegl=NewFormattedFK;
 
114
        CED_Extention=NewFormattedE;
 
115
        CED_ExtentionNew=NewFormattedENew;
 
116
        CED_EdTagLanguage=NewFormattedLang;
 
117
        mainPage=new(CEDPage);
 
118
        refBox.x=refBox.y=refBox.h=refBox.w=0;
 
119
        font=kegl=lang=-1;
 
120
        foregroundColor=backgroundColor=fontNum=-1;
 
121
        verInfo=0;
 
122
        CED_ReadED(file,readFromFile,bufLen);
 
123
        if (verInfo&&strcmp(verInfo,"CuneiForm2000 file format")==0)
 
124
        {
 
125
                RepairStructure();
 
126
                delete[] verInfo;
 
127
        }
 
128
        else
 
129
                return 0;
 
130
        return mainPage;
 
131
}
 
132
 
 
133
//Put non-recognized codes to the corresponding field of extData
 
134
void ExtDataProc(Word8* _ptr, Word32 lth)
 
135
{}
 
136
 
 
137
void NewFormattedSDD(const sheet_disk_descr* pt)
 
138
{
 
139
        mainPage->dpi.cx=mainPage->dpi.cy=pt->resolution;
 
140
        mainPage->pageNumber=pt->sheet_numb;
 
141
        mainPage->turn=pt->incline;
 
142
        mainPage->NumberOfParagraphs=pt->quant_fragm;
 
143
        mainPage->turn=pt->incline;
 
144
}
 
145
 
 
146
void NewFormattedE(const edExtention* pt,const void* ptExt)
 
147
{
 
148
        switch(pt->Ecode)
 
149
        {
 
150
        case EDEXT_VERSION:
 
151
                verInfo=new char[pt->length-sizeof(edExtention)];
 
152
                memcpy(verInfo,ptExt,pt->length-sizeof(edExtention));
 
153
                break;
 
154
        case EDEXT_FONTS:
 
155
        {
 
156
                fontDiscr *fond=(fontDiscr *)ptExt;
 
157
                while((char*)fond-(char*)ptExt<signed (pt->length-sizeof(edExtention)))
 
158
                {
 
159
                mainPage->CreateFont(fond->fontNumber,fond->fontPitchAndFamily, fond->fontCharset,
 
160
                                (char*)fond+sizeof(fontDiscr));
 
161
                fond=(fontDiscr *)((char*)fond+fond->size);
 
162
                }
 
163
                break;
 
164
        }
 
165
        case EDEXT_BORDERS:
 
166
        {
 
167
                pageDescr* pd=(pageDescr*)ptExt;
 
168
                mainPage->pageSizeInTwips.cx=        pd->paperw;
 
169
                mainPage->pageSizeInTwips.cy=        pd->paperh;
 
170
                mainPage->pageBordersInTwips.top=    pd->margt;
 
171
                mainPage->pageBordersInTwips.left=   pd->margl;
 
172
                mainPage->pageBordersInTwips.bottom= pd->margb;
 
173
                mainPage->pageBordersInTwips.right=  pd->margr;
 
174
                mainPage->resizeToFit=               pd->resizeToFit;
 
175
                //for backward compatibility
 
176
                if ( unsigned( (&(pd->recogLang)) - ((BYTE*)pd) )<pt->length-sizeof(edExtention))
 
177
                        mainPage->recogLang=pd->recogLang;
 
178
                break;
 
179
        }
 
180
        case EDEXT_TIFF_DESC:
 
181
        {
 
182
                originalImageDesc* fond=(originalImageDesc*)ptExt;
 
183
                mainPage->sizeOfImage.cy=fond->height;
 
184
                mainPage->sizeOfImage.cx=fond->width;
 
185
                mainPage->pageNumber=    fond->pageNum;
 
186
                mainPage->turn=          fond->inclune;
 
187
                mainPage->dpi.cx=  fond->resolutionX;
 
188
                mainPage->dpi.cy=  fond->resolutionY;
 
189
                mainPage->unrecogChar=   fond->unrecogSymbol;
 
190
                mainPage->imageName=strdup((char*)ptExt+sizeof(originalImageDesc));
 
191
                break;
 
192
        }
 
193
/*      case EDEXT_PICS:
 
194
        {
 
195
                pictDescr *picd=(pictDescr *)ptExt;
 
196
                while((char*)picd-(char*)ptExt<pt->length-sizeof(edExtention))
 
197
                {
 
198
                        mainPage->CreatePicture(picd->pictNumber, picd->pictSize, picd->pictGoal, picd->pictAlign, picd->type, (char*)picd+sizeof(pictDescr),picd->len);
 
199
                        picd=(pictDescr *)(char*)picd+picd->size;
 
200
                }
 
201
                break;
 
202
        }
 
203
*/      case EDEXT_SECTION:
 
204
        {
 
205
                CEDSection * sect=mainPage->InsertSection();
 
206
                sectParams1* sp=(sectParams1*)ptExt;
 
207
                sect->borders.bottom=sp->bottomMargin   ;
 
208
                sect->borders.top=   sp->topMargin      ;
 
209
                sect->borders.left=  sp->leftMargin     ;
 
210
                sect->borders.right= sp->rightMargin    ;
 
211
                sect->numberOfColumns=0;//  sp->columns         ;
 
212
                sect->colInterval=   sp->colInterval    ;
 
213
                sect->numSnakeCols=  sp->numSnakeCols;
 
214
                sect->colInfo=new EDCOL[sect->numSnakeCols];
 
215
                char * c=(char*)ptExt+sizeof(sectParams1);
 
216
                int i;
 
217
                for(i=0;i<sect->numSnakeCols;i++)
 
218
                {
 
219
                        sect->colInfo[i].width=*((Int32*)c);
 
220
                        c+=4;
 
221
                }
 
222
                for(i=0;i<sect->numSnakeCols;i++)
 
223
                {
 
224
                        sect->colInfo[i].space=*((Int32*)c);
 
225
                        c+=4;
 
226
                }
 
227
                sectParams2* sp2=(sectParams2*)c;
 
228
                sect->footerY=      sp2->footerY                ;
 
229
                sect->headerY=      sp2->headerY                ;
 
230
                sect->width=        sp2->width          ;
 
231
                sect->height=       sp2->height         ;
 
232
                sect->orientation=  sp2->orientation    ;
 
233
                sect->sectionBreak= sp2->sectionBreak;
 
234
                //for backward compatibility
 
235
                if ( unsigned( (&(sp2->lineBetCol)) - ((BYTE*)sp) )<pt->length-sizeof(edExtention))
 
236
                        sect->lineBetCol=sp2->lineBetCol;
 
237
                break;
 
238
        }
 
239
        case EDEXT_PARAGRAPH:
 
240
        {
 
241
                paraParams * pard=(paraParams *)ptExt;
 
242
                CEDParagraph* hPara=mainPage->GetCurSection()->GetCurParagraph();
 
243
                hPara->color=                (signed short)pard->color;
 
244
                hPara->interval.cx=          pard->spaceBefore;
 
245
                hPara->interval.cy=          pard->spaceAfter;
 
246
                hPara->alignment=            pard->alignment;
 
247
                hPara->indent.top=           pard->firstIndent;
 
248
                hPara->indent.left=          pard->leftIndent;
 
249
                hPara->indent.right=         pard->rightIndent;
 
250
                hPara->keep=                 pard->keep;
 
251
                hPara->shading=              (signed short)pard->shading;
 
252
                hPara->spaceBetweenLines=    pard->spaceBetweenLines;
 
253
                hPara->spcBtwLnsMult=        pard->spcBtwLnsMult;
 
254
                hPara->userNumber=           (signed short)pard->userNum;
 
255
                //for backward compatibility
 
256
                if ( unsigned( (&(pard->topBrdrType)) - ((BYTE*)pard) )<pt->length-sizeof(edExtention))
 
257
                        hPara->topBrdrType=pard->topBrdrType            ;
 
258
                if ( unsigned( (BYTE*)(&(pard->topBrdrWidth)) - ((BYTE*)pard) )<pt->length-sizeof(edExtention))
 
259
                        hPara->topBrdrWidth=    pard->topBrdrWidth      ;
 
260
                if ( unsigned( (&(pard->bottomBrdrType)) - ((BYTE*)pard) )<pt->length-sizeof(edExtention))
 
261
                        hPara->bottomBrdrType=  pard->bottomBrdrType    ;
 
262
                if ( unsigned( (BYTE*)(&(pard->bottomBrdrWidth)) - ((BYTE*)pard) )<pt->length-sizeof(edExtention))
 
263
                        hPara->bottomBrdrWidth= pard->bottomBrdrWidth   ;
 
264
                if ( unsigned( (&(pard->leftBrdrType)) - ((BYTE*)pard) )<pt->length-sizeof(edExtention))
 
265
                        hPara->leftBrdrType=    pard->leftBrdrType      ;
 
266
                if ( unsigned( (BYTE*)(&(pard->leftBrdrWidth)) - ((BYTE*)pard) )<pt->length-sizeof(edExtention))
 
267
                        hPara->leftBrdrWidth=   pard->leftBrdrWidth     ;
 
268
                if ( unsigned( (&(pard->rightBrdrType)) - ((BYTE*)pard) )<pt->length-sizeof(edExtention))
 
269
                        hPara->rightBrdrType=   pard->rightBrdrType     ;
 
270
                if ( unsigned( (BYTE*)(&(pard->rightBrdrWidth)) - ((BYTE*)pard) )<pt->length-sizeof(edExtention))
 
271
                        hPara->rightBrdrWidth=  pard->rightBrdrWidth    ;
 
272
 
 
273
                break;
 
274
        }
 
275
        case EDEXT_TABLE_ROW:
 
276
        {
 
277
                CEDParagraph *hPara=mainPage->GetCurSection()->GetCurParagraph();
 
278
                edRowDescr *rd=(edRowDescr*)(hPara)->descriptor;
 
279
                rowParam* rp=(rowParam*)ptExt;
 
280
                rd->topBrdrType=     rp->topBrdrType            ;
 
281
                rd->topBrdrWidth=    rp->topBrdrWidth   ;
 
282
                rd->bottomBrdrType=  rp->bottomBrdrType ;
 
283
                rd->bottomBrdrWidth= rp->bottomBrdrWidth        ;
 
284
                rd->leftBrdrType=    rp->leftBrdrType   ;
 
285
                rd->leftBrdrWidth=   rp->leftBrdrWidth  ;
 
286
                rd->rightBrdrType=   rp->rightBrdrType  ;
 
287
                rd->rightBrdrWidth=  rp->rightBrdrWidth ;
 
288
                rd->gaph=            rp->gaph                   ;
 
289
                rd->header=          rp->header                 ;
 
290
                rd->header=          rp->left                   ;
 
291
                rd->position=        rp->position               ;
 
292
                rd->rowHeight=       rp->rowHeight              ;
 
293
                rd->left=                        rp->left               ;
 
294
                break;
 
295
        }
 
296
        case EDEXT_TABLE_CELL:
 
297
        {
 
298
                CEDParagraph *hPara=mainPage->GetCurSection()->GetCurParagraph();
 
299
                cellParam *cp=(cellParam *)ptExt;
 
300
                edCellDescr *cd=(edCellDescr*)(hPara)->descriptor;
 
301
                cd->topBrdrType=     cp->topBrdrType            ;
 
302
                cd->topBrdrWidth=    cp->topBrdrWidth   ;
 
303
                cd->bottomBrdrType=  cp->bottomBrdrType ;
 
304
                cd->bottomBrdrWidth= cp->bottomBrdrWidth        ;
 
305
                cd->leftBrdrType=    cp->leftBrdrType   ;
 
306
                cd->leftBrdrWidth=   cp->leftBrdrWidth  ;
 
307
                cd->rightBrdrType=   cp->rightBrdrType  ;
 
308
                cd->rightBrdrWidth=  cp->rightBrdrWidth ;
 
309
                cd->cellX=           cp->cellX                  ;
 
310
                cd->color=           (signed short)cp->color                    ;
 
311
                cd->shading=         (signed short)cp->shading                  ;
 
312
                cd->merging=         cp->merging                        ;
 
313
                cd->vertTextAlign=       cp->vertTextAlign;
 
314
                //for backward compatibility
 
315
                if ( unsigned( (&(cp->flag)) - ((BYTE*)cp) )<pt->length-sizeof(edExtention))
 
316
                        cd->flag=cp->flag;
 
317
                break;
 
318
        }
 
319
        case EDEXT_FRAME:
 
320
        {
 
321
                CEDParagraph *hPara=mainPage->GetCurSection()->GetCurParagraph();
 
322
                edFrameDescr *fd=(edFrameDescr*)(hPara)->descriptor;
 
323
                frameParam* fp=(frameParam*)ptExt;
 
324
                fd->rec.x=      fp->posx                ;
 
325
                fd->rec.y=      fp->posy                ;
 
326
                fd->rec.w=      fp->absw                ;
 
327
                fd->rec.h=      fp->absh                ;
 
328
                fd->borderSpace=fp->borderSpace ;
 
329
                fd->dxfrtextx=  fp->dxfrtextx   ;
 
330
                fd->dxfrtexty=  fp->dxfrtexty   ;
 
331
                fd->position=   fp->position;
 
332
                //for backward compatiility
 
333
                if ( unsigned( (&(fp->flag)) - ((BYTE*)fp) )<pt->length-sizeof(edExtention))
 
334
                        fd->flag=fp->flag;
 
335
                break;
 
336
        }
 
337
        case EDEXT_CHAR:
 
338
        {
 
339
                charParams* chp=(charParams*)ptExt;
 
340
                fontNum=chp->fontNumber;
 
341
                foregroundColor=chp->foregroundColor;
 
342
                //for backward compatibility
 
343
                if ( unsigned( (BYTE*)(&(chp->backgroundColor)) - ((BYTE*)chp) )<pt->length-sizeof(edExtention))
 
344
                        backgroundColor=chp->backgroundColor;
 
345
                else
 
346
                        backgroundColor=-1;
 
347
                break;
 
348
        }
 
349
        }
 
350
}
 
351
void NewFormattedENew(const edExtentionNew* pt,const void* ptExt)
 
352
{
 
353
        switch(pt->Ecode)
 
354
        {
 
355
        case EDEXT_PICS:
 
356
        {
 
357
                pictDescr *picd=(pictDescr *)ptExt;
 
358
                while((char*)picd-(char*)ptExt<signed (pt->length-sizeof(edExtentionNew)))
 
359
                {
 
360
                        mainPage->CreatePicture(picd->pictNumber, picd->pictSize, picd->pictGoal, picd->pictAlign, picd->type, (char*)picd+sizeof(pictDescr),picd->len);
 
361
                        picd=(pictDescr *)((char*)picd+picd->size);
 
362
                }
 
363
                break;
 
364
        }
 
365
        }
 
366
}
 
367
void NewFormattedTR(const text_ref* pt)
 
368
{
 
369
        switch (pt->type)
 
370
        {
 
371
        case SSR_FRAG_TYPE:
 
372
        {
 
373
                CEDParagraph * para=mainPage->GetCurSection()->InsertParagraph();
 
374
                switch (pt->object)
 
375
                {
 
376
                case TP_MCOL_BEG:
 
377
                        para->type=COLUMN_BEGIN;
 
378
                        para->descriptor=malloc(sizeof(EDCOLDESCR));
 
379
                        break;
 
380
                case TP_NEW_COL:
 
381
                        para->type=COLUMN_BEGIN;
 
382
                        para->descriptor=malloc(sizeof(EDCOLDESCR));
 
383
                        break;
 
384
                case TP_MCOL_END:
 
385
                        para->type=LAST_IN_COLUMN;
 
386
                        break;
 
387
                case TP_NEW_TAB_BEG:
 
388
                        para->type=TAB_BEGIN;
 
389
                        para->descriptor=malloc(sizeof(EDTABDESCR));
 
390
                        break;
 
391
                case TP_NEW_ROW_BEG:
 
392
                        para->type=TAB_ROW_BEGIN;
 
393
                        para->descriptor=malloc(sizeof(EDROWDESCR));
 
394
                        break;
 
395
                case TP_NEW_CELL_BEG:
 
396
                        para->type=TAB_CELL_BEGIN;
 
397
                        para->descriptor=malloc(sizeof(EDCELLDESCR));
 
398
                        break;
 
399
                case TP_NEW_TAB_END:
 
400
                        para->type=TAB_END;
 
401
                        break;
 
402
                case TP_FRAME_BEG:
 
403
                        para->type=FRAME_BEGIN;
 
404
                        para->descriptor=malloc(sizeof(EDFRAMEDESCR));
 
405
                        break;
 
406
                case TP_FRAME_END:
 
407
                        para->type=FRAME_END;
 
408
                        break;
 
409
                }
 
410
                break;
 
411
        }
 
412
        case SSR_LINE_FN:
 
413
        {
 
414
                CEDParagraph *hPara=mainPage->GetParagraph(pt->object);
 
415
                curEdLine=hPara->InsertLine();
 
416
                break;
 
417
        }
 
418
        }
 
419
}
 
420
 
 
421
void NewFormattedLB(const line_beg* pt)
 
422
{
 
423
        curEdLine->defChrFontHeight=pt->height;
 
424
        curEdLine->hardBreak=!pt->base_line;
 
425
}
 
426
 
 
427
void NewFormattedBMR(const bit_map_ref * pt)
 
428
{
 
429
        refBox.h=pt->height;
 
430
        refBox.w=pt->width;
 
431
        refBox.x=pt->col;
 
432
        refBox.y=pt->row;
 
433
}
 
434
 
 
435
void NewFormattedFK(const font_kegl * pt)
 
436
{
 
437
        font=pt->new_font;
 
438
        kegl=pt->new_kegl;
 
439
}
 
440
 
 
441
void NewFormattedLang(const EdTagLanguage* pt)
 
442
{
 
443
        lang=pt->language;
 
444
}
 
445
void NewFormattedL(const letter* pt,const Word32 alternatives)
 
446
{
 
447
        if (!curEdLine)
 
448
                return;
 
449
        CEDLine *lin=curEdLine;
 
450
/*      if(!mainPage->GetCurSection())
 
451
                mainPage->InsertSection()->CreateColumn();//In case of wrong 'ed', such that symbols are before the definition of fragment
 
452
        CEDLine * lin=mainPage->GetCurSection()->GetCurParagraph()->GetCurLine();
 
453
        if (!lin)
 
454
                lin=mainPage->GetCurSection()->GetCurParagraph()->InsertLine();//In case of wrong 'ed', such that symbols are before the definition of line
 
455
*/      CEDChar *chr=lin->InsertChar();
 
456
        letterEx * lpData = new letterEx[alternatives];
 
457
        memcpy(lpData,(void*)pt,alternatives*sizeof(letterEx));
 
458
        chr->alternatives=/*(letter*)*/lpData;
 
459
        chr->numOfAltern=alternatives;
 
460
        chr->layout.left=refBox.x;
 
461
        chr->layout.top=refBox.y;
 
462
        chr->layout.right=refBox.x+refBox.w;
 
463
        chr->layout.bottom=refBox.y+refBox.h;
 
464
//      memcpy(&(chr->layout),&refBox,sizeof(edBox));
 
465
        chr->fontHeight=kegl;
 
466
        chr->fontAttribs=font;
 
467
        chr->fontNum=fontNum;
 
468
        chr->fontLang=lang;
 
469
        chr->backgroundColor=backgroundColor;
 
470
        chr->foregroundColor=foregroundColor;
 
471
}
 
472
 
 
473
void RepairStructure()
 
474
{
 
475
        CEDParagraph * tabBeg=0,*rowBeg=0,*cellBeg=0,*colBeg=0,*frmBeg=0;
 
476
        CEDParagraph *hPara=mainPage->GetParagraph(0);
 
477
        while (hPara)
 
478
        {
 
479
        switch (hPara->type)
 
480
        {
 
481
                case TAB_BEGIN:
 
482
                {
 
483
                        //Memorized beginning of table
 
484
                        tabBeg=hPara;
 
485
                        EDTABDESCR *td=(EDTABDESCR*)(tabBeg->descriptor);
 
486
                        td->numOfRows=0;
 
487
                        td->cur=hPara;
 
488
                        td->next=hPara;
 
489
                        td->table=0;
 
490
                        break;
 
491
                }
 
492
                case TAB_ROW_BEGIN:
 
493
                {
 
494
                        //If it is not a first line - refer to the current one
 
495
                        if (rowBeg)
 
496
                        {
 
497
                                EDROWDESCR *rd=(EDROWDESCR*)(rowBeg->descriptor);
 
498
                                rd->last=hPara;
 
499
                        }
 
500
                        //In a table of lines+1
 
501
                        if (tabBeg)
 
502
                        {
 
503
                                EDTABDESCR *td=(EDTABDESCR*)(tabBeg->descriptor);
 
504
                                td->numOfRows++;
 
505
                                //If it is a first line
 
506
                                if (!rowBeg)
 
507
                                        td->next=hPara;
 
508
                                td->cur=hPara;
 
509
                        }
 
510
                        rowBeg=hPara;
 
511
                        EDROWDESCR *rd=(EDROWDESCR*)(rowBeg->descriptor);
 
512
                        rd->numOfCells=0;
 
513
                        rd->next=hPara;
 
514
                        rd->cur=hPara;
 
515
                        cellBeg=0;
 
516
                        break;
 
517
                }
 
518
                case TAB_CELL_BEGIN:
 
519
                {
 
520
                        if (cellBeg)
 
521
                        {
 
522
                                EDCELLDESCR *cd=(EDCELLDESCR*)(cellBeg->descriptor);
 
523
                                cd->next=hPara;
 
524
                        }
 
525
                        if (rowBeg)
 
526
                        {
 
527
                                EDROWDESCR *rd=(EDROWDESCR*)(rowBeg->descriptor);
 
528
                                rd->numOfCells++;
 
529
                                if (!cellBeg)
 
530
                                        rd->next=hPara;
 
531
                                rd->cur=hPara;
 
532
                        }
 
533
                        cellBeg=hPara;
 
534
                        break;
 
535
                }
 
536
                case TAB_END:
 
537
                {
 
538
                        if (rowBeg)
 
539
                        {
 
540
                                EDROWDESCR *rd=(EDROWDESCR*)(rowBeg->descriptor);
 
541
                                rd->last=hPara;
 
542
                        }
 
543
                        if (tabBeg)
 
544
                        {
 
545
                                EDTABDESCR *td=(EDTABDESCR*)(tabBeg->descriptor);
 
546
                                td->last=hPara;
 
547
                        }
 
548
                        if (cellBeg)
 
549
                        {
 
550
                                EDCELLDESCR *cd=(EDCELLDESCR*)(cellBeg->descriptor);
 
551
                                cd->next=hPara;
 
552
                        }
 
553
                        cellBeg=tabBeg=rowBeg=0;
 
554
                        break;
 
555
                }
 
556
                case FRAME_BEGIN:
 
557
                {
 
558
                        frmBeg=hPara;
 
559
                        break;
 
560
                }
 
561
                case FRAME_END:
 
562
                {
 
563
                        EDFRAMEDESCR *fd=(EDFRAMEDESCR*)(frmBeg->descriptor);
 
564
                        fd->last=hPara;
 
565
                        frmBeg=0;
 
566
                        break;
 
567
                }
 
568
                case COLUMN_BEGIN:
 
569
                {
 
570
                        CEDSection * sec=mainPage->GetSection(hPara->parentNumber);
 
571
                        if(colBeg)
 
572
                        {
 
573
                                EDCOLDESCR *cd=(EDCOLDESCR*)(colBeg->descriptor);
 
574
                                cd->next=hPara;
 
575
                        }
 
576
                        else
 
577
                                sec->columnsBeg=hPara;
 
578
                        colBeg=hPara;
 
579
                        sec->numberOfColumns++;
 
580
                        sec->columnsCur=hPara;
 
581
                        break;
 
582
                }
 
583
                case LAST_IN_COLUMN:
 
584
                {
 
585
                        if(colBeg)
 
586
                        {
 
587
                                EDCOLDESCR *cd=(EDCOLDESCR*)(colBeg->descriptor);
 
588
                                cd->next=hPara;
 
589
                        }
 
590
                        colBeg=0;
 
591
                        mainPage->GetSection(hPara->parentNumber)->columnsEnd=hPara;
 
592
                        break;
 
593
                }
 
594
        }
 
595
        hPara=hPara->next;
 
596
        }
 
597
}
 
598
 
 
599
#ifdef _DEBUG
 
600
void PrintPara(FILE *stream,Handle para);
 
601
void CED_ShowTree(char * name, Handle hEdPage)
 
602
{
 
603
//      CEDPage * page=(CEDPage *)hEdPage;
 
604
        Bool32 inFrm=FALSE, inTbl=FALSE;
 
605
        Handle frm;
 
606
        Handle tblRow;
 
607
        unsigned int tblRowNum=0,tblCellNum=0;
 
608
        FILE *stream = fopen( name, "w" );
 
609
        fprintf(stream,"Page,dpi=%i,imName=%s,\ntw.x=%i,tw.y=%i,sz.x=%i,sz.y=%i,turn=%i,char=%c\n",
 
610
                CED_GetPageDpi(hEdPage).cx,CED_GetPageImageName(hEdPage),CED_GetPageSize(hEdPage).cx,
 
611
                CED_GetPageSize(hEdPage).cy,CED_GetPageImageSize(hEdPage).cx,
 
612
                CED_GetPageImageSize(hEdPage).cy,CED_GetPageTurn(hEdPage),CED_GetPageUnrecogChar(hEdPage));
 
613
        fprintf(stream,"\nTable of pictures:\nTotal pictures:%d",CED_GetNumOfPics(hEdPage));
 
614
        for (unsigned int p=0;p<CED_GetNumOfPics(hEdPage);p++)
 
615
        {
 
616
                int pictNumber, pictAlign , type,length;
 
617
                EDSIZE pictSize, pictGoal;
 
618
                CED_GetPicture(hEdPage,p, &pictNumber, &pictSize, &pictGoal, &pictAlign , &type, 0, &length);
 
619
                fprintf(stream,"\npictNumber=%d, type=%d, length=%d, pictSize.x=%d, pictSize.y=%d,\npictGoal.x=%d, pictGoal.y=%d, pictAlign=%d\n",
 
620
                        pictNumber, type, length, pictSize.cx,pictSize.cy, pictGoal.cx,pictGoal.cy, pictAlign);
 
621
        }
 
622
 
 
623
        for (unsigned int i=0;i<CED_GetCountSection(hEdPage);i++)
 
624
        {
 
625
                Handle sect=CED_GetSection(hEdPage,i);
 
626
                fprintf(stream,"\nSection %i,borders:l=%i,r=%i,t=%i,b=%i\n",i,
 
627
                        CED_GetSectionBorder(sect).left,CED_GetSectionBorder(sect).right,
 
628
                        CED_GetSectionBorder(sect).top,CED_GetSectionBorder(sect).bottom);
 
629
                fprintf(stream,"\ncolumns:");
 
630
                for (unsigned int c=0;c<CED_GetNumSnakeCols(sect);c++)
 
631
                        fprintf(stream,"\ncolumn %i,wd=%i,sp=%i",c,
 
632
                                        CED_GetSnakeColumnWidth(sect,c),CED_GetSnakeColumnSpacing(sect,c));
 
633
 
 
634
                for (unsigned int j=0;j<CED_GetCountColumn(sect);j++)
 
635
                {
 
636
                        Handle col=CED_GetColumn(sect,j);
 
637
                        if (!col)
 
638
                        {
 
639
                                printf("Internal error in CED_GetColumn");
 
640
                                continue;
 
641
                        }
 
642
                        fprintf(stream,"\nNewCol");
 
643
                        Handle para=CED_GetFirstObject(col);
 
644
                        while (para)
 
645
                        {
 
646
                                if (!CED_IsParagraph(para))
 
647
                                {
 
648
                                        if (CED_IsTable(para))
 
649
                                        {
 
650
                                                fprintf(stream,"\nHere goes a table!!!!!!!!!!!!!!!!!!!!!!\n");
 
651
                                                for (tblRowNum=0;tblRowNum<CED_GetCountRow(para);tblRowNum++)
 
652
                                                {
 
653
                                                        tblRow=CED_GetTableRow(para,tblRowNum);
 
654
                                                        int left,heig,lb,rb,tb,bb,gp,pos;
 
655
                                                        CED_GetTableRowParams(tblRow,&left,&heig,&lb,0,&rb,0,&tb,0,&bb,0,&gp,&pos,0);
 
656
                                                        fprintf(stream,"\nRow: left=%d,heig=%d,lb=%d,rb=%d,tb=%d,bb=%d,gp=%d,pos=%d",left,heig,lb,rb,tb,bb,gp,pos);
 
657
                                                        for (tblCellNum=0;tblCellNum<CED_GetCountCell(tblRow);tblCellNum++)
 
658
                                                        {
 
659
                                                                Handle hPara=CED_GetCell(tblRow,tblCellNum);
 
660
                                                                int cx,mg,va;
 
661
                                                                CED_GetCellParams(hPara,&cx,&mg,&va,0,0,0,0,0,0,0,0,0,0,0);
 
662
                                                                int flag=CED_GetCellFlag(hPara);
 
663
                                                                char ss[100];
 
664
                                                                ss[0]=0;
 
665
                                                                if (flag&ED_TDIR_UP)
 
666
                                                                        strcpy(ss,",ED_TDIR_UP");
 
667
                                                                if (flag&ED_TDIR_DOWN)
 
668
                                                                        strcpy(ss,",ED_TDIR_DOWN");
 
669
                                                                fprintf(stream,"\nCellX:%d,mrg:%d,vAlign:%d%s",cx,mg,va,ss);
 
670
                                                                Handle para1=CED_GetFirstObject(hPara);
 
671
                                                                while (para1)
 
672
                                                                {
 
673
                                                                        PrintPara(stream,para1);
 
674
                                                                        para1=CED_GetNextObject(para1);
 
675
                                                                }
 
676
                                                                fprintf(stream,"\nHere is end of cell--------------------");
 
677
                                                        }
 
678
                                                        fprintf(stream,"\nHere is end of row========================");
 
679
                                                }
 
680
                                                fprintf(stream,"\nHere is end of table!!!!!!!!!!!!!!!!!!!!\n");
 
681
                                                para=CED_GetNextObject(para);
 
682
                                        }
 
683
                                        else
 
684
                                                if (CED_IsFrame(para))
 
685
                                                {
 
686
                                                        inFrm=TRUE;
 
687
                                                        frm=para;
 
688
                                                        EDBOX bx=CED_GetFrameRect(para);
 
689
                                                        fprintf(stream,"\nHere is a frame,x=%d,y=%d,w=%d,h=%d,pos=%x,dx=%d,dy=%d!!!!!!!!!\n",bx.x,bx.y,bx.w,bx.h,CED_GetFramePosition(para),CED_GetFrameDxfrtextx(para),CED_GetFrameDxfrtexty(para));
 
690
                                                        para=CED_GetFirstObject(frm);
 
691
                                                }
 
692
                                }
 
693
                                else
 
694
                                {
 
695
                                        PrintPara(stream,para);
 
696
                                        para=CED_GetNextObject(para);
 
697
                                }
 
698
                                if (!para&&inFrm)
 
699
                                {
 
700
                                        para=CED_GetNextObject(frm);
 
701
                                        inFrm=FALSE;
 
702
                                        fprintf(stream,"Here is end of frame!!!!!!!!!!!!!!!!!!!!\n");
 
703
                                }
 
704
                        }
 
705
                }
 
706
        }
 
707
        fclose( stream );
 
708
}
 
709
 
 
710
void PrintPara(FILE *stream,Handle para)
 
711
{
 
712
                                fprintf(stream,"\nparagraph,alig=%i,FInd=%d,LInd=%i,RInd=%d",
 
713
                                        CED_GetAlignment(para),CED_GetIndent(para).top,CED_GetIndent(para).left,CED_GetIndent(para).right);
 
714
                                fprintf(stream,",usNum=%i,sb=%i,sa=%i\n",CED_GetUserNumber(para),CED_GetInterval(para).cx,CED_GetInterval(para).cy);
 
715
                                for (unsigned l=0;l<CED_GetCountLine(para);l++)
 
716
                                {
 
717
                                        Handle line=CED_GetLine(para,l);
 
718
                                        for (unsigned c=0;c<CED_GetCountChar(line);c++)
 
719
                                        {
 
720
                                                Handle chr=CED_GetChar(line,c);
 
721
                                                if (!CED_IsPicture(chr))
 
722
                                                        fprintf(stream,"%c",CED_GetAlternatives(chr)[0].alternative);
 
723
                                                else
 
724
                                                        fprintf(stream,"\\pict%d\\",CED_GetCharFontNum(chr)-ED_PICT_BASE);
 
725
                                        }
 
726
                                        fprintf(stream,"\n");
 
727
                                }
 
728
 
 
729
}
 
730
#endif
 
731
 
 
732
Bool32 WriteRemark(HANDLE hFile,int type, int object);
 
733
Bool32 WriteExtCode(HANDLE hFile,int Ecode, void* object, int lenOfObj, int etraLen=0);
 
734
Bool32 WriteFontTable(HANDLE hFile, CEDPage *page);
 
735
Bool32 WriteTiffDescr(HANDLE hFile, CEDPage* page);
 
736
Bool32 WritePictTable(HANDLE hFile, CEDPage* page);
 
737
Bool32 WritePara(HANDLE hFile,CEDParagraph* hPara);
 
738
 
 
739
Bool32  CED_FormattedWrite(char * fileName, CEDPage *page)
 
740
{
 
741
        int ret;
 
742
        int fn;
 
743
        int sec;
 
744
        CEDChar *tmpChr;
 
745
        HANDLE hFile=Open(0, (PInt8)fileName,OSF_CREATE|OSF_BINARY|OSF_WRITE);
 
746
        if (!hFile)
 
747
        {
 
748
                SetReturnCode_ced(CFIO_GetReturnCode());
 
749
                return FALSE;
 
750
        }
 
751
        //Write header
 
752
        sheet_disk_descr sdd;
 
753
        sdd.code=SS_SHEET_DESCR;
 
754
        sdd.quant_fragm=1;
 
755
        sdd.sheet_numb=page->pageNumber;
 
756
        sdd.descr_lth=sizeof(sdd)+sizeof(fragm_disk_descr);
 
757
        sdd.resolution=(Word16)page->dpi.cx;
 
758
        sdd.incline=page->turn;
 
759
        sdd.version=2000;
 
760
        if (!Write(hFile,(PInt8)&sdd,sizeof(sdd))) goto ED_WRITE_END;
 
761
        fragm_disk_descr fdd;
 
762
        memset((void*)&fdd,0,sizeof(fdd));
 
763
        fdd.code=SS_FRAGMENT;
 
764
        if (!Write(hFile,(PInt8)&fdd,sizeof(fdd))) goto ED_WRITE_END;
 
765
        //Write text description of version
 
766
        if (!WriteExtCode(hFile,EDEXT_VERSION,(void*)"CuneiForm2000 file format",strlen("CuneiForm2000 file format")+1)) goto ED_WRITE_END;
 
767
        //Write table of fonts
 
768
        if (!WriteFontTable(hFile,page)) goto ED_WRITE_END;
 
769
        //Write the boundaries of the page
 
770
        pageDescr pd;
 
771
        pd.paperw=page->pageSizeInTwips.cx;
 
772
        pd.paperh=page->pageSizeInTwips.cy;
 
773
        pd.margt=page->pageBordersInTwips.top;
 
774
        pd.margl=page->pageBordersInTwips.left;
 
775
        pd.margb=page->pageBordersInTwips.bottom;
 
776
        pd.margr=page->pageBordersInTwips.right;
 
777
        pd.resizeToFit=BYTE(page->resizeToFit);
 
778
        pd.recogLang=page->recogLang;
 
779
        if (!WriteExtCode(hFile,EDEXT_BORDERS, &pd,sizeof(pd))) goto ED_WRITE_END;
 
780
        //Write parameters of .tif
 
781
        if (!WriteTiffDescr(hFile,page)) goto ED_WRITE_END;
 
782
        //Write all available pictures
 
783
        if (!WritePictTable(hFile, page)) goto ED_WRITE_END;
 
784
        //Write descriptions of sections and paragraphs.
 
785
        for (sec=0;sec<page->GetNumberOfSections();sec++)
 
786
        {
 
787
                CEDSection * sect=page->GetSection(sec);
 
788
                int i;
 
789
                sectParams1     sp;
 
790
                sp.bottomMargin=sect->borders.bottom;
 
791
                sp.topMargin=sect->borders.top;
 
792
                sp.leftMargin=sect->borders.left;
 
793
                sp.rightMargin=sect->borders.right;
 
794
                sp.columns=sect->numberOfColumns;
 
795
                sp.colInterval=sect->colInterval;
 
796
                sp.numSnakeCols=sect->numSnakeCols;
 
797
                if (!WriteExtCode(hFile,EDEXT_SECTION,&sp,sizeof(sp),sizeof(sectParams2)+sect->numSnakeCols*8)) goto ED_WRITE_END;
 
798
                for (i=0;i<sect->numSnakeCols;i++)
 
799
                        if (!Write(hFile,(PInt8)&(sect->colInfo[i].width),4)) goto ED_WRITE_END;
 
800
                for (i=0;i<sect->numSnakeCols;i++)
 
801
                        if (!Write(hFile,(PInt8)&(sect->colInfo[i].space),4)) goto ED_WRITE_END;
 
802
                sectParams2     sp2;
 
803
                sp2.footerY=sect->footerY;
 
804
                sp2.headerY=sect->headerY;
 
805
                sp2.width=sect->width;
 
806
                sp2.height=sect->height;
 
807
                sp2.orientation=sect->orientation;
 
808
                sp2.sectionBreak=sect->sectionBreak;
 
809
                sp2.lineBetCol=sect->lineBetCol;
 
810
                if (!Write(hFile,(PInt8)&sp2,sizeof(sp2))) goto ED_WRITE_END;
 
811
                if (!WriteRemark(hFile,SSR_FRAG_TYPE,TP_MCOL_BEG)) goto ED_WRITE_END;
 
812
                if (!WriteRemark(hFile,SSR_FRAG_PNUM,MIN(sect->numberOfColumns,1))) goto ED_WRITE_END;
 
813
                //Write headers of paragraphs in rows
 
814
                Bool32 fisrtCol=TRUE;//In order for it not to write NEW_COL in the beginning og first column
 
815
                CEDParagraph* hPara=sect->paragraphs;
 
816
                while (hPara&&hPara->parentNumber==sec)
 
817
                {
 
818
                        rowParam rp;
 
819
                        edRowDescr *rd;
 
820
                        cellParam cp;
 
821
                        edCellDescr *cd;
 
822
                        edFrameDescr *fd;
 
823
                        frameParam fp;
 
824
                        switch (hPara->type)
 
825
                        {
 
826
                        default:
 
827
                                if (!WritePara(hFile,hPara)) goto ED_WRITE_END;
 
828
                                break;
 
829
                        case TAB_BEGIN:
 
830
                                if (!WriteRemark(hFile,SSR_FRAG_TYPE,TP_NEW_TAB_BEG)) goto ED_WRITE_END;
 
831
                                break;
 
832
                        case TAB_ROW_BEGIN:
 
833
                                if (!WriteRemark(hFile,SSR_FRAG_TYPE,TP_NEW_ROW_BEG)) goto ED_WRITE_END;
 
834
                                rd=(edRowDescr*)(hPara)->descriptor;
 
835
                                rp.topBrdrType=rd->topBrdrType;
 
836
                                rp.topBrdrWidth=rd->topBrdrWidth;
 
837
                                rp.bottomBrdrType=rd->bottomBrdrType;
 
838
                                rp.bottomBrdrWidth=rd->bottomBrdrWidth;
 
839
                                rp.leftBrdrType=rd->leftBrdrType;
 
840
                                rp.leftBrdrWidth=rd->leftBrdrWidth;
 
841
                                rp.rightBrdrType=rd->rightBrdrType;
 
842
                                rp.rightBrdrWidth=rd->rightBrdrWidth;
 
843
                                rp.gaph=rd->gaph;
 
844
                                rp.header=BYTE(rd->header);
 
845
                                rp.left=rd->header;
 
846
                                rp.position=rd->position;
 
847
                                rp.rowHeight=rd->rowHeight;
 
848
                                rp.left=rd->left;
 
849
 
 
850
                                if (!WriteExtCode(hFile,EDEXT_TABLE_ROW,&rp,sizeof(rp))) goto ED_WRITE_END;
 
851
                                break;
 
852
 
 
853
                        case TAB_CELL_BEGIN:
 
854
                                if (!WriteRemark(hFile,SSR_FRAG_TYPE,TP_NEW_CELL_BEG)) goto ED_WRITE_END;
 
855
                                cd=(edCellDescr*)(hPara)->descriptor;
 
856
                                cp.topBrdrType=cd->topBrdrType;
 
857
                                cp.topBrdrWidth=cd->topBrdrWidth;
 
858
                                cp.bottomBrdrType=cd->bottomBrdrType;
 
859
                                cp.bottomBrdrWidth=cd->bottomBrdrWidth;
 
860
                                cp.leftBrdrType=cd->leftBrdrType;
 
861
                                cp.leftBrdrWidth=cd->leftBrdrWidth;
 
862
                                cp.rightBrdrType=cd->rightBrdrType;
 
863
                                cp.rightBrdrWidth=cd->rightBrdrWidth;
 
864
                                cp.cellX=cd->cellX;
 
865
                                cp.color=cd->color;
 
866
                                cp.shading=cd->shading;
 
867
                                cp.merging=cd->merging;
 
868
                                cp.vertTextAlign=cd->vertTextAlign;
 
869
                                cp.flag=cd->flag;
 
870
                                memcpy(&(cp.layout),&(cd->layout),sizeof(edBox));
 
871
                                if (!WriteExtCode(hFile,EDEXT_TABLE_CELL,&cp,sizeof(cp))) goto ED_WRITE_END;
 
872
                                break;
 
873
 
 
874
                        case TAB_END:
 
875
                                if (!WriteRemark(hFile,SSR_FRAG_TYPE,TP_NEW_TAB_END)) goto ED_WRITE_END;
 
876
                                break;
 
877
 
 
878
                        case FRAME_BEGIN:
 
879
                                if (!WriteRemark(hFile,SSR_FRAG_TYPE,TP_FRAME_BEG)) goto ED_WRITE_END;
 
880
                                fd=(edFrameDescr*)(hPara)->descriptor;
 
881
                                fp.posx=fd->rec.x;
 
882
                                fp.posy=fd->rec.y;
 
883
                                fp.absw=fd->rec.w;
 
884
                                fp.absh=fd->rec.h;
 
885
                                fp.borderSpace=fd->borderSpace;
 
886
                                fp.dxfrtextx=fd->dxfrtextx;
 
887
                                fp.dxfrtexty=fd->dxfrtexty;
 
888
                                fp.position=fd->position;
 
889
                                fp.flag=fd->flag;
 
890
                                if (!WriteExtCode(hFile,EDEXT_FRAME,&fp,sizeof(fp),0)) goto ED_WRITE_END;
 
891
                                break;
 
892
 
 
893
                        case FRAME_END:
 
894
                                if (!WriteRemark(hFile,SSR_FRAG_TYPE,TP_FRAME_END)) goto ED_WRITE_END;
 
895
                                break;
 
896
 
 
897
                        case COLUMN_BEGIN:
 
898
                                if(!fisrtCol)
 
899
                                        if (!WriteRemark(hFile,SSR_FRAG_TYPE,TP_NEW_COL)) goto ED_WRITE_END;
 
900
                                fisrtCol=FALSE;
 
901
                                break;
 
902
                        case LAST_IN_COLUMN:
 
903
                                break;
 
904
                        }
 
905
                        hPara=hPara->next;
 
906
                }
 
907
                if (!WriteRemark(hFile,SSR_FRAG_TYPE,TP_MCOL_END)) goto ED_WRITE_END;
 
908
        }
 
909
 
 
910
        if (!WriteRemark(hFile,SSR_FRAG_END,0)) goto ED_WRITE_END;
 
911
 
 
912
        //Write the file itself
 
913
        tmpChr=page->GetChar(0);
 
914
        if (tmpChr)
 
915
        {
 
916
                font_kegl fk;
 
917
                fk.code=SS_FONT_KEGL;
 
918
                font=fk.new_font=tmpChr->fontAttribs;
 
919
                kegl=fk.new_kegl=tmpChr->fontHeight;
 
920
                if (!Write(hFile,(PInt8)&fk,sizeof(fk))) goto ED_WRITE_END;
 
921
                charParams chp;
 
922
                chp.fontNumber=fontNum=tmpChr->fontNum;
 
923
                chp.foregroundColor=foregroundColor=tmpChr->foregroundColor;
 
924
                chp.backgroundColor=backgroundColor=tmpChr->backgroundColor;
 
925
                if (!WriteExtCode(hFile,EDEXT_CHAR,&chp,sizeof(chp))) goto ED_WRITE_END;
 
926
                EdTagLanguage fl;
 
927
                fl.code=SS_LANGUAGE;
 
928
                fl.language=lang=tmpChr->fontLang;
 
929
                if (!Write(hFile,(PInt8)&fl,sizeof(fl))) goto ED_WRITE_END;
 
930
        }
 
931
        else
 
932
                font=kegl=0;
 
933
        fn=0;
 
934
 
 
935
        CEDLine *line;
 
936
        if(line=page->GetLine(0))
 
937
        {
 
938
                do
 
939
                {
 
940
                        //Write(hFile,(char*)&lb,sizeof(lb));
 
941
                        if (!WriteRemark(hFile,SSR_LINE_FN,line->parentNumber)) goto ED_WRITE_END;
 
942
                        if(line->SetCurChar(0))
 
943
                        {
 
944
                                CEDChar *chr=line->GetCurChar();
 
945
                                do
 
946
                                {
 
947
                                        line->SetCurChar(chr);
 
948
                                        bit_map_ref bmr;
 
949
                                        bmr.code=SS_BITMAP_REF;
 
950
                                        bmr.col=(Word16)chr->layout.left;
 
951
                                        bmr.row=(Word16)chr->layout.top;
 
952
                                        bmr.height=(Word16)(chr->layout.bottom-chr->layout.top);
 
953
                                        bmr.width=Word16(chr->layout.right-chr->layout.left);
 
954
                                        if (!Write(hFile,(PInt8)(&bmr),sizeof(bmr))) goto ED_WRITE_END;
 
955
                                        if(chr->fontHeight!=kegl||chr->fontAttribs!=font)
 
956
                                        {
 
957
                                                font_kegl fk;
 
958
                                                fk.code=SS_FONT_KEGL;
 
959
                                                font=fk.new_font=chr->fontAttribs;
 
960
                                                kegl=fk.new_kegl=chr->fontHeight;
 
961
                                                if (!Write(hFile,(PInt8)&fk,sizeof(fk))) goto ED_WRITE_END;
 
962
                                        }
 
963
                                        if(chr->fontNum!=fontNum||chr->foregroundColor!=foregroundColor||chr->backgroundColor!=backgroundColor)
 
964
                                        {
 
965
                                                charParams chp;
 
966
                                                chp.fontNumber=fontNum=chr->fontNum;
 
967
                                                chp.foregroundColor=foregroundColor=chr->foregroundColor;
 
968
                                                chp.backgroundColor=backgroundColor=chr->backgroundColor;
 
969
                                                if (!WriteExtCode(hFile,EDEXT_CHAR,&chp,sizeof(chp))) goto ED_WRITE_END;
 
970
                                        }
 
971
                                        if(chr->fontLang!=lang)
 
972
                                        {
 
973
                                                EdTagLanguage fl;
 
974
                                                fl.code=SS_LANGUAGE;
 
975
                                                fl.language=lang=chr->fontLang;
 
976
                                                if (!Write(hFile,(PInt8)&fl,sizeof(fl))) goto ED_WRITE_END;
 
977
                                        }
 
978
                                        if (chr->alternatives)
 
979
                                        {
 
980
                                                if (!Write(hFile,(PInt8)chr->alternatives,chr->numOfAltern*sizeof(letterEx))) goto ED_WRITE_END;
 
981
                                        }
 
982
                                        else
 
983
                                        {
 
984
                                                letterEx l;
 
985
                                                l.alternative=' ';
 
986
                                                l.probability=254;
 
987
                                                if (!Write(hFile,(PInt8)&l,sizeof(letterEx))) goto ED_WRITE_END;
 
988
                                        }
 
989
                                        chr=line->NextChar(FALSE);
 
990
                                }while(chr);
 
991
                        }
 
992
                        if (line->hardBreak||line->defChrFontHeight>0)
 
993
                        {
 
994
                                line_beg lb;
 
995
                                lb.code=SS_LINE_BEG;
 
996
                                lb.base_line=!line->hardBreak;
 
997
                                lb.height=line->defChrFontHeight;
 
998
                                if (!Write(hFile,(PInt8)&lb,sizeof(line_beg))) goto ED_WRITE_END;
 
999
                        }
 
1000
                        line=line->next;//para->NextLine(FALSE);
 
1001
                }while(line);
 
1002
        }
 
1003
 
 
1004
        SetReturnCode_ced(IDS_ERR_NO);
 
1005
        ret=TRUE;
 
1006
        goto FINAL;
 
1007
ED_WRITE_END:
 
1008
        SetReturnCode_ced(CFIO_GetReturnCode());
 
1009
        ret=FALSE;
 
1010
FINAL:
 
1011
        Close(hFile,CSF_SAVEDISK);
 
1012
        return ret;
 
1013
}
 
1014
 
 
1015
Bool32 WriteFontTable(HANDLE hFile, CEDPage* page)
 
1016
{
 
1017
        char* ch=0;
 
1018
        //define the sum of lengths of all names of fonts
 
1019
        int len=0;
 
1020
        int q;
 
1021
        if (!(page->fontsUsed))
 
1022
                return TRUE;
 
1023
        for (q=0;q<page->fontsUsed;q++)
 
1024
        {
 
1025
                page->GetFont(q,0,0,0,&ch);
 
1026
                if (ch)
 
1027
                        len+=strlen(ch)+1;
 
1028
        }
 
1029
        if (!WriteExtCode(hFile,EDEXT_FONTS,0,0,len+sizeof(fontDiscr)*page->fontsUsed)) return FALSE;
 
1030
 
 
1031
        fontDiscr fond;
 
1032
        for (q=0;q<page->fontsUsed;q++)
 
1033
        {
 
1034
                page->GetFont(q,&(fond.fontNumber),&(fond.fontPitchAndFamily),
 
1035
                        &(fond.fontCharset),&ch);
 
1036
                fond.size=strlen(ch)+1+sizeof(fontDiscr);
 
1037
                //write info about font
 
1038
                if (!Write(hFile,(PInt8)&fond,sizeof(fontDiscr))) return FALSE;
 
1039
                //write font's name
 
1040
                if (!Write(hFile,(PInt8)ch,strlen(ch)+1)) return FALSE;
 
1041
        }
 
1042
        return TRUE;
 
1043
}
 
1044
 
 
1045
Bool32 WriteTiffDescr(HANDLE hFile, CEDPage* page)
 
1046
{
 
1047
        originalImageDesc fond;
 
1048
        fond.height=page->sizeOfImage.cy;
 
1049
        fond.width=page->sizeOfImage.cx;
 
1050
        fond.pageNum=page->pageNumber;
 
1051
        fond.inclune=page->turn;
 
1052
        fond.resolutionX=(WORD)page->dpi.cx;
 
1053
        fond.resolutionY=(WORD)page->dpi.cy;
 
1054
        fond.unrecogSymbol=page->unrecogChar;
 
1055
        if (!WriteExtCode(hFile,EDEXT_TIFF_DESC,&fond,sizeof(fond),strlen(page->imageName)+1)) return FALSE;
 
1056
        if (!Write(hFile,(PInt8)page->imageName,strlen(page->imageName)+1)) return FALSE;
 
1057
        return TRUE;
 
1058
}
 
1059
 
 
1060
Bool32 WritePictTable(HANDLE hFile, CEDPage* page)
 
1061
{
 
1062
        //define sum of lengths of all pictures
 
1063
        int len=0;
 
1064
        int q;
 
1065
        if (!(page->picsUsed))
 
1066
                return TRUE;
 
1067
        for (q=0;q<page->picsUsed;q++)
 
1068
        {
 
1069
                len+=page->picsTable[q].len;
 
1070
        }
 
1071
        if (!WriteExtCode(hFile,EDEXT_PICS,0,0,len+sizeof(pictDescr)*page->picsUsed)) return FALSE;
 
1072
 
 
1073
        pictDescr picd;
 
1074
        for (q=0;q<page->picsUsed;q++)
 
1075
        {
 
1076
                picd.pictAlign=page->picsTable[q].pictAlign;
 
1077
                picd.pictGoal.cx=page->picsTable[q].pictGoal.cx;
 
1078
                picd.pictGoal.cy=page->picsTable[q].pictGoal.cy;
 
1079
                picd.pictNumber=page->picsTable[q].pictNumber;
 
1080
                picd.pictSize.cx=page->picsTable[q].pictSize.cx;
 
1081
                picd.pictSize.cy=page->picsTable[q].pictSize.cy;
 
1082
                picd.len=page->picsTable[q].len;
 
1083
                picd.type=page->picsTable[q].type;
 
1084
                picd.size=page->picsTable[q].len+sizeof(picd);
 
1085
                //write picture info.
 
1086
                if (!Write(hFile,(PInt8)&picd,sizeof(picd))) return FALSE;
 
1087
                //write picture
 
1088
                if (!Write(hFile,(PInt8)page->picsTable[q].data,page->picsTable[q].len)) return FALSE;
 
1089
        }
 
1090
        return TRUE;
 
1091
}
 
1092
 
 
1093
Bool32 WritePara(HANDLE hFile,CEDParagraph* hPara)
 
1094
{
 
1095
        paraParams pard;
 
1096
        if (!WriteRemark(hFile,SSR_FRAG_TYPE,hPara->alignment)) return FALSE;
 
1097
        pard.color=hPara->color;
 
1098
        pard.spaceBefore=hPara->interval.cx;
 
1099
        pard.spaceAfter=hPara->interval.cy;
 
1100
        pard.alignment=hPara->alignment;
 
1101
        pard.firstIndent=hPara->indent.top;
 
1102
        pard.leftIndent=hPara->indent.left;
 
1103
        pard.rightIndent=hPara->indent.right;
 
1104
        pard.keep=hPara->keep;
 
1105
        pard.shading=hPara->shading;
 
1106
        pard.spaceBetweenLines=hPara->spaceBetweenLines;
 
1107
        pard.spcBtwLnsMult=hPara->spcBtwLnsMult;
 
1108
        pard.userNum=hPara->userNumber;
 
1109
        pard.topBrdrType=hPara->topBrdrType;
 
1110
        pard.topBrdrWidth=hPara->topBrdrWidth;
 
1111
        pard.bottomBrdrType=hPara->bottomBrdrType;
 
1112
        pard.bottomBrdrWidth=hPara->bottomBrdrWidth;
 
1113
        pard.leftBrdrType=hPara->leftBrdrType;
 
1114
        pard.leftBrdrWidth=hPara->leftBrdrWidth;
 
1115
        pard.rightBrdrType=hPara->rightBrdrType;
 
1116
        pard.rightBrdrWidth=hPara->rightBrdrWidth;
 
1117
        pard.brdrBtw=hPara->brdrBtw;
 
1118
        if (!WriteExtCode(hFile,EDEXT_PARAGRAPH,&pard,sizeof(pard))) return FALSE;
 
1119
        return TRUE;
 
1120
}
 
1121
 
 
1122
//write lenOfObj+extraLen to the field corresponding to length
 
1123
Bool32 WriteExtCode(HANDLE hFile,int Ecode, void* object, int lenOfObj, int extraLen)
 
1124
{
 
1125
        if (!(Ecode&0x8000))
 
1126
        {
 
1127
                edExtention ext;
 
1128
                ext.code=SS_EXTENTION;
 
1129
                ext.Ecode=Ecode;
 
1130
                ext.length=lenOfObj+extraLen+sizeof(ext);
 
1131
                if (!Write(hFile,(PInt8)&ext,sizeof(ext))) return FALSE;
 
1132
        }
 
1133
        else
 
1134
        {
 
1135
                edExtentionNew ext;
 
1136
                ext.code=SS_EXTENTION;
 
1137
                ext.Ecode=Ecode;
 
1138
                ext.length=lenOfObj+extraLen+sizeof(ext);
 
1139
                if (!Write(hFile,(PInt8)&ext,sizeof(ext))) return FALSE;
 
1140
        }
 
1141
                if (lenOfObj)
 
1142
                        if (!Write(hFile,(PInt8)object,lenOfObj)) return FALSE;
 
1143
        return TRUE;
 
1144
}
 
1145
 
 
1146
Bool32 WriteRemark(HANDLE hFile,int type, int object)
 
1147
{
 
1148
        text_ref tr;
 
1149
        tr.code=SS_REMARK;
 
1150
        tr.type=type;
 
1151
        tr.object=object;
 
1152
        if (!Write(hFile,(PInt8)&tr,sizeof(tr))) return FALSE;
 
1153
        return TRUE;
 
1154
}
 
1155
 
 
1156
 
 
1157
Word32 CED_IsEdFile (char * file,Bool32 readFromFile, Word32 bufLen)
 
1158
{
 
1159
        HANDLE PedHandle;
 
1160
        Word32 len;
 
1161
        PWord8 start;
 
1162
 
 
1163
        if (readFromFile)
 
1164
        {
 
1165
                len=MemFromFile((PInt8)file,&PedHandle);
 
1166
                if (len==0)
 
1167
                        return 0;
 
1168
                start = (PWord8)Lock(PedHandle);
 
1169
                if ( !start )
 
1170
                {
 
1171
                        Unlock(PedHandle);
 
1172
                        Free(PedHandle);
 
1173
                        return 0;
 
1174
                }
 
1175
        }
 
1176
        else
 
1177
        {
 
1178
                start =(Word8*)file;
 
1179
                len=bufLen;
 
1180
        }
 
1181
        Bool32 ret=96;
 
1182
        if (len<sizeof(sheet_disk_descr)+sizeof(fragm_disk_descr)+1)
 
1183
        {
 
1184
                ret= 0;
 
1185
                goto END;
 
1186
        }
 
1187
        if (start[0]!=0x0a)
 
1188
        {
 
1189
                ret= 0;
 
1190
                goto END;
 
1191
        }
 
1192
        if (start[sizeof(sheet_disk_descr)]!=0x0b)
 
1193
        {
 
1194
                ret= 0;
 
1195
                goto END;
 
1196
        }
 
1197
        if (start[sizeof(sheet_disk_descr)+sizeof(fragm_disk_descr)]>=0x20)
 
1198
        {
 
1199
                ret= 0;
 
1200
                goto END;
 
1201
        }
 
1202
        if (((sheet_disk_descr*)start)->version=2000)
 
1203
                ret=2000;
 
1204
END:
 
1205
        if (readFromFile)
 
1206
        {
 
1207
                Unlock(PedHandle);
 
1208
                Free(PedHandle);
 
1209
        }
 
1210
        return ret;
 
1211
}
 
1212