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

« back to all changes in this revision

Viewing changes to cuneiform_src/Kern/rstr/src/corners.c

  • 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
 
 
58
 
 
59
/*********************************************************************/
 
60
/*                                                                   */
 
61
/*     module CORNERS - studies corners of the component(s)          */
 
62
/*                                                                   */
 
63
/*********************************************************************/
 
64
#include <stdlib.h>
 
65
#include <stdio.h>
 
66
#include <string.h>
 
67
#include "nt_types.h"
 
68
#include "struct.h"
 
69
#include "cutstr.h"
 
70
#include "func.h"
 
71
#include "embbox.h"
 
72
 
 
73
#define  CONST_PLUS 10      // this constant is added abris values in order
 
74
                            // to avoid negative values caused by shifting
 
75
#define AVOID_PRYSCH 3
 
76
 
 
77
/************** all function prototypes ***********************************/
 
78
INT u_around_bl_corner ( s_glue * );
 
79
INT n_around_ur_corner ( s_glue * );
 
80
void comp_row_col( s_glue * );
 
81
static void comp_parms( BYTE );
 
82
// static INT bottom_right_corner (PBYTE, BYTE, BYTE, BYTE);
 
83
static INT bottom_left_corner (PBYTE, BYTE, BYTE, BYTE);
 
84
static INT upper_right_corner (PBYTE, BYTE, BYTE, BYTE);
 
85
//static INT upper_left_corner (PBYTE, BYTE, BYTE, BYTE);
 
86
static BOOL is_italic();
 
87
static void compare_corners_mass();
 
88
static void make_straight_abris (s_glue *, PBYTE, PBYTE);
 
89
static INT func_mode_val( PBYTE func, BYTE from, BYTE to);
 
90
static INT left_right_dist();
 
91
/*************************************************************************/
 
92
 
 
93
extern servBOX SBOX;
 
94
BYTE str_left[128];
 
95
BYTE str_right[128];
 
96
 
 
97
BYTE l_tab_shift[128];       // the tables of shifts ( avoiding italic
 
98
BYTE r_tab_shift[128];       //  and oblique )
 
99
 
 
100
#define ST_PEN_NUM 5
 
101
static INT pen_for_staires[ST_PEN_NUM+1] = { 0, 14, 36, 60, 72, 120 };
 
102
#define LRD_PEN_NUM 7
 
103
static INT pen_for_left_right_dist[LRD_PEN_NUM+1] =
 
104
                                     { 0, 0, 12, 46, 80, 120, 160, 220 };
 
105
static BYTE comp_h, un_code;
 
106
static BYTE num_st, beg_zone, end_zone;
 
107
static INT pen_u, pen_n;
 
108
static INT maxrow, maxcol, minrow, mincol;
 
109
 
 
110
 
 
111
#define Let_n   2
 
112
#define Let_u   4
 
113
void discrim_un( cell *GC, s_glue *GL, INT cod_let )
 
114
{
 
115
INT wi;
 
116
 
 
117
 memset ( l_tab_shift, 0, sizeof (l_tab_shift) );
 
118
 memset ( r_tab_shift, 0, sizeof (r_tab_shift) );
 
119
 
 
120
 pen_u = 0; pen_n = 0; un_code = (BYTE)cod_let;
 
121
 
 
122
 comp_row_col( GL );          // compute coordinates of the composed box
 
123
 // check italic incline of the component
 
124
 wi = letincl(GC);
 
125
 
 
126
 if ( ((GC->font|GC->font_new) & c_fp_it) && (GL->ncell == 1) )  return;
 
127
 
 
128
 make_straight_abris( GL, l_tab_shift, r_tab_shift );
 
129
 
 
130
 if (GL->ncell > 1)
 
131
  {
 
132
    if ( is_italic() )
 
133
     { compare_corners_mass();   goto ApplyPenalty;}
 
134
    else return;
 
135
  }
 
136
 if ( cod_let & Let_n )
 
137
  {
 
138
   pen_n = n_around_ur_corner(GL); // study right upper corner against arounding
 
139
   pen_n += left_right_dist();
 
140
  }
 
141
 if ( cod_let & Let_u )
 
142
   pen_u = u_around_bl_corner(GL); // study left bottom corner against arounding
 
143
 
 
144
ApplyPenalty:
 
145
 if ( pen_u )
 
146
  {
 
147
   cell_bonus_let(GC, 'u', (INT)(-(pen_u)) );
 
148
   sort_vers( GC );
 
149
  }
 
150
 if ( pen_n )
 
151
  {
 
152
   cell_bonus_let(GC, 'n', (INT)(-(pen_n)) );
 
153
   sort_vers( GC );
 
154
  }
 
155
}
 
156
 
 
157
static void make_straight_abris (s_glue *GL, PBYTE left_shift, PBYTE right_shift)
 
158
{
 
159
    INT             i, j, y;
 
160
    BYTE            beg, end;
 
161
    interval        *cur_int;
 
162
    lnhead          *Line;
 
163
    cell            *WC;
 
164
 
 
165
  // initialize both arraies
 
166
  memset (str_left,  255, sizeof (str_left));
 
167
  memset (str_right, 255, sizeof (str_right));
 
168
  j = 0;
 
169
 
 
170
  while ( (WC=GL->celist[j]) != NULL )
 
171
  {
 
172
    // set address of the first line
 
173
    Line = (lnhead *)(((PBYTE) (WC -> env)) + WC -> env -> lines + sizeof (INT));
 
174
 
 
175
    while ( Line -> lth )        // loop for all lines
 
176
    {
 
177
        y = maxrow - WC->row - (Line -> row) - 1; // uppermost y-coordinate
 
178
        cur_int = (interval *)(Line + 1);           // first interval
 
179
 
 
180
        for ( i = y; (cur_int -> l > 0 ); i--)     // loop for all intervals
 
181
        {
 
182
            beg = cur_int->e - cur_int->l + CONST_PLUS;
 
183
            beg = WC->col - mincol + ( beg - left_shift[i] );
 
184
            if ( beg < str_left[i] )
 
185
              str_left[i] = beg;
 
186
 
 
187
            end = maxcol - WC->col - ( cur_int->e + right_shift[i] );
 
188
            if ( end < str_right[i] )
 
189
              str_right[i] = end;
 
190
 
 
191
            cur_int++;
 
192
        }
 
193
        Line = (lnhead *)( (PBYTE)Line + Line->lth );
 
194
    }
 
195
   j++;
 
196
  }
 
197
}
 
198
 
 
199
/*********************
 
200
static INT upper_left_corner (PBYTE s_left, BYTE from, BYTE to, BYTE minst)
 
201
{
 
202
    INT  dif;
 
203
    INT  st, prev, cur;
 
204
 
 
205
 for ( st=0, cur=to-1, prev=to; ( cur>=from && st<minst ); prev--, cur-- )
 
206
  {
 
207
    if ( s_left[prev] - s_left[cur] > AVOID_PRYSCH )
 
208
     { st = 0; continue; }
 
209
    dif = s_left[cur] - s_left[prev];
 
210
    if ( dif > 0 )
 
211
     {
 
212
      if ( dif > 1 )
 
213
        { st = 0;  break; }
 
214
       else
 
215
        { st --; continue; }
 
216
      }
 
217
    if ( dif == 0 ) continue;
 
218
    st ++;
 
219
  }
 
220
 return st;
 
221
}
 
222
*******************/
 
223
 
 
224
static INT upper_right_corner (PBYTE s_right, BYTE from, BYTE to, BYTE minst)
 
225
{
 
226
    INT dif;
 
227
    INT st, prev, cur;
 
228
 
 
229
 for ( st=0, cur=to-1, prev=to; ( cur>=from && st<minst ); prev--, cur-- )
 
230
  {
 
231
    if ( s_right[prev] - s_right[cur] > AVOID_PRYSCH )
 
232
     { st = 0; continue; }
 
233
    dif = s_right[cur] - s_right[prev];
 
234
    if ( dif > 0 )
 
235
     { if ( dif > 1 )
 
236
        { st = 0;  break; }
 
237
       else
 
238
        { st --; continue; }
 
239
     }
 
240
    if ( dif == 0 ) continue;
 
241
    st ++;
 
242
  }
 
243
 return st;
 
244
}
 
245
 
 
246
 
 
247
static INT bottom_left_corner (PBYTE s_left, BYTE from, BYTE to, BYTE minst)
 
248
{
 
249
    INT  dif;
 
250
    INT  st, prev, cur;
 
251
 
 
252
 for ( st=0, cur=from+1, prev=from; ( cur <= to && st<minst ); prev++, cur++ )
 
253
  {
 
254
    if ( s_left[prev] - s_left[cur] > AVOID_PRYSCH )
 
255
     { st = 0; continue; }
 
256
    dif = s_left[cur] - s_left[prev];
 
257
    if ( dif > 0 )
 
258
     {
 
259
      if ( dif > 1 )
 
260
        { st = 0;  break; }
 
261
       else
 
262
        { st --; continue; }
 
263
      }
 
264
    if ( dif == 0 ) continue;
 
265
    st ++;
 
266
  }
 
267
 return st;
 
268
}
 
269
 
 
270
 
 
271
/*****************
 
272
static INT bottom_right_corner (PBYTE s_right, BYTE from, BYTE to, BYTE minst)
 
273
{
 
274
    INT  dif;
 
275
    INT  st, prev, cur;
 
276
 
 
277
 for ( st=0, cur=from+1, prev=from; ( cur <= to && st<minst ); prev++, cur++ )
 
278
  {
 
279
    if ( s_right[prev] - s_right[cur] > AVOID_PRYSCH )
 
280
     { st = 0; continue; }
 
281
    dif = s_right[cur] - s_right[prev];
 
282
    if ( dif > 0 )
 
283
     {
 
284
      if ( dif > 1 )
 
285
        { st = 0;  break; }
 
286
       else
 
287
        { st --; continue; }
 
288
      }
 
289
    if ( dif == 0 ) continue;
 
290
    st ++;
 
291
  }
 
292
 return st;
 
293
}
 
294
******************/
 
295
 
 
296
static void comp_parms( BYTE fullh )
 
297
{
 
298
 
 
299
  if ( (fullh < 40) && (fullh > 24) )
 
300
   { num_st = 4; beg_zone = 0; end_zone = (fullh)/3; }
 
301
  if ( (fullh <= 24) && (fullh >15) )
 
302
   { num_st = 3; beg_zone = 0; end_zone = (fullh)/3 + 1; }
 
303
  if ( fullh <= 15 )
 
304
   { num_st = 2; beg_zone = 0; end_zone = (fullh)/3; }
 
305
  if ( fullh >= 40 )
 
306
   { num_st = 5; beg_zone = 1; end_zone =(fullh)/3;  }
 
307
}
 
308
 
 
309
void comp_row_col( s_glue *GL )
 
310
{
 
311
cell * curc;
 
312
INT j;
 
313
 
 
314
  maxrow = maxcol = -32000;
 
315
  minrow = mincol = 32767;
 
316
  j = 0;
 
317
 
 
318
  while ( (curc = GL->celist[j]) != NULL )
 
319
  {
 
320
   if (mincol > curc->col) mincol=curc->col;
 
321
   if (minrow > curc->row) minrow=curc->row;
 
322
   if (maxrow < (curc->row + curc->h)) maxrow=curc->row+curc->h;
 
323
   if (maxcol < (curc->col+curc->w)) maxcol=curc->col+curc->w;
 
324
   j++;
 
325
  }
 
326
 GL->height = maxrow - minrow;
 
327
 comp_h = (BYTE)GL->height;
 
328
 GL->width = maxcol - mincol;
 
329
}
 
330
 
 
331
INT n_around_ur_corner ( s_glue *GL )
 
332
{
 
333
 BYTE from, to, np;
 
334
 INT ret_pen;
 
335
 
 
336
  ret_pen = 0;
 
337
  comp_parms ( (BYTE)GL->height );
 
338
  from = GL->height - end_zone + 1;
 
339
  to = GL->height - 1 - beg_zone;
 
340
 
 
341
  ret_pen = upper_right_corner( str_right, from, to, num_st );
 
342
  np = num_st - ret_pen;
 
343
  if ( np > ST_PEN_NUM ) np = ST_PEN_NUM;
 
344
  ret_pen = pen_for_staires[np];
 
345
  return ret_pen;
 
346
}
 
347
 
 
348
INT u_around_bl_corner ( s_glue *GL )
 
349
{
 
350
 BYTE from, to, np;
 
351
 INT ret_pen;
 
352
 
 
353
  comp_parms ( (BYTE)GL->height );
 
354
  from = beg_zone;
 
355
  to = end_zone;
 
356
 
 
357
  ret_pen = bottom_left_corner( str_left, from, to, num_st );
 
358
  np = num_st - ret_pen;
 
359
  if ( np > ST_PEN_NUM ) np = ST_PEN_NUM;
 
360
  ret_pen = pen_for_staires[np];
 
361
 
 
362
  return ret_pen;
 
363
 
 
364
}
 
365
 
 
366
static BOOL is_italic()
 
367
{
 
368
BYTE h14, i;
 
369
INT lmax, xmax;
 
370
 
 
371
 h14 =(comp_h>>2);
 
372
 for ( xmax=h14, lmax=0, i=h14; i < comp_h - 2; i++ )
 
373
  {
 
374
   if ( str_left[i+1] - str_left[i] > 3 )   // big gap to right is forbidden
 
375
      return FALSE;
 
376
   if ( lmax < str_left[i] )
 
377
    { lmax = str_left[i]; xmax = i; }
 
378
  }
 
379
 
 
380
 if ( str_left[xmax] - str_left[h14] > 2 )
 
381
  return TRUE;
 
382
 if ( str_left[xmax] - str_left[h14] == 0 )
 
383
  return FALSE;
 
384
 for ( i=h14; i <= xmax; i++ )
 
385
  {
 
386
   if ( str_left[i] > str_left[i+1] )
 
387
     return FALSE;
 
388
  }
 
389
 return TRUE;
 
390
}
 
391
 
 
392
static void compare_corners_mass()
 
393
{
 
394
INT  d;
 
395
 
 
396
 d = mBOX[2] - mBOX[12];
 
397
 if ( d > 0 )
 
398
  {
 
399
   if ( un_code & Let_u )
 
400
    pen_u += ( (d+1)>>1 ) & 0xfe;
 
401
  }
 
402
 else
 
403
  {
 
404
   if ( un_code & Let_n )
 
405
    pen_n += ( (abs(d)+1)>>1 ) & 0xfe;
 
406
  }
 
407
}
 
408
 
 
409
static INT left_right_dist()
 
410
{
 
411
INT lmd, rmd, h14;
 
412
BYTE j;
 
413
 
 
414
   h14 = (comp_h >> 2);
 
415
   lmd = func_mode_val( str_left, (BYTE)h14, (BYTE)(comp_h - h14));
 
416
   lmd -= CONST_PLUS;
 
417
   rmd = func_mode_val( str_right, (BYTE)h14, (BYTE)(comp_h - h14));
 
418
   j = abs(lmd - rmd);
 
419
   if ( j > LRD_PEN_NUM ) j = LRD_PEN_NUM;
 
420
   return pen_for_left_right_dist[j];
 
421
}
 
422
 
 
423
static INT func_mode_val( PBYTE func, BYTE from, BYTE to)
 
424
{
 
425
INT ans;
 
426
INT i, j, maxv;
 
427
BYTE counts[128];
 
428
 
 
429
  memset ( counts, 0, sizeof( counts ) );
 
430
 
 
431
  for ( maxv=0, i=from; i < to; i++ )
 
432
   {
 
433
    j = func[i];
 
434
    counts[j] ++;
 
435
    if ( maxv < j ) maxv = j;
 
436
   }
 
437
  for ( ans=0, j=0, i=0; i <= maxv; i++ )
 
438
   {
 
439
     if ( j < counts[i] )
 
440
       { j = counts[i]; ans = i; }
 
441
   }
 
442
  return ans;
 
443
}