1 /* Copyright (C) 2000-2008 by George Williams */
2 /*
3  * Redistribution and use in source and binary forms, with or without
4  * modification, are permitted provided that the following conditions are met:
5 
6  * Redistributions of source code must retain the above copyright notice, this
7  * list of conditions and the following disclaimer.
8 
9  * Redistributions in binary form must reproduce the above copyright notice,
10  * this list of conditions and the following disclaimer in the documentation
11  * and/or other materials provided with the distribution.
12 
13  * The name of the author may not be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15 
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19  * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 #include "fontforgevw.h"
28 #include <chardata.h>
29 #include <math.h>
30 #include <utype.h>
31 #include <ustring.h>
32 
33 int accent_offset = 6;
34 int GraveAcuteCenterBottom = 1;
35 int PreferSpacingAccents = true;
36 int CharCenterHighest = 1;
37 
38 #define BottomAccent	0x300
39 #define TopAccent	0x345
40 
41 /* for accents between 0x300 and 345 these are some synonyms */
42 /* type1 wants accented chars built with accents in the 0x2c? range */
43 /*  except for grave and acute which live in iso8859-1 range */
44 /*  this table is ordered on a best try basis */
45 static const unichar_t accents[][4] = {
46     { 0x2cb, 0x300, 0x60 },	/* grave */
47     { 0x2ca, 0x301, 0xb4 },	/* acute */
48     { 0x2c6, 0x302, 0x5e },	/* circumflex */
49     { 0x2dc, 0x303, 0x7e },	/* tilde */
50     { 0x2c9, 0x304, 0xaf },	/* macron */
51     { 0x305, 0xaf },		/* overline, (macron is suggested as a syn, but it's not quite right) */
52     { 0x2d8, 0x306 },		/* breve */
53     { 0x2d9, 0x307, '.' },	/* dot above */
54     { 0xa8,  0x308 },		/* diaeresis */
55     { 0x2c0 },			/* hook above */
56     { 0x2da, 0xb0 },		/* ring above */
57     { 0x2dd },			/* real acute */
58     { 0x2c7 },			/* caron */
59     { 0x2c8, 0x384, 0x30d, '\''  },	/* vertical line, tonos */
60     { 0x30e, '"' },		/* real vertical line */
61     { 0 },			/* real grave */
62     { 0 },			/* cand... */		/* 310 */
63     { 0 },			/* inverted breve */
64     { 0x2bb },			/* turned comma */
65     { 0x2bc, 0x313, ',' },	/* comma above */
66     { 0x2bd },			/* reversed comma */
67     { 0x2bc, 0x315, ',' },	/* comma above right */
68     { 0x316, 0x60, 0x2cb },	/* grave below */
69     { 0x317, 0xb4, 0x2ca },	/* acute below */
70     { 0 },			/* left tack */
71     { 0 },			/* right tack */
72     { 0 },			/* left angle */
73     { 0 },			/* horn, sometimes comma but only if nothing better */
74     { 0 },			/* half ring */
75     { 0x2d4 },			/* up tack */
76     { 0x2d5 },			/* down tack */
77     { 0x2d6, 0x31f, '+' },	/* plus below */
78     { 0x2d7, 0x320, '-' },	/* minus below */	/* 320 */
79     { 0x2b2 },			/* hook */
80     { 0 },			/* back hook */
81     { 0x323, 0x2d9, '.' },	/* dot below */
82     { 0x324, 0xa8 },		/* diaeresis below */
83     { 0x325, 0x2da, 0xb0 },	/* ring below */
84     { 0x326, 0x2bc, ',' },	/* comma below */
85     { 0xb8 },			/* cedilla */
86     { 0x2db },			/* ogonek */		/* 0x328 */
87     { 0x329, 0x2c8, 0x384, '\''  },	/* vertical line below */
88     { 0 },			/* bridge below */
89     { 0 },			/* real arch below */
90     { 0x32c, 0x2c7 },		/* caron below */
91     { 0x32d, 0x2c6, 0x52 },	/* circumflex below */
92     { 0x32e, 0x2d8 },		/* breve below */
93     { 0 },			/* inverted breve below */
94     { 0x330, 0x2dc, 0x7e },	/* tilde below */	/* 0x330 */
95     { 0x331, 0xaf, 0x2c9 },	/* macron below */
96     { 0x332, '_' },		/* low line */
97     { 0 },			/* real low line */
98     { 0x334, 0x2dc, 0x7e },	/* tilde overstrike */
99     { 0x335, '-' },		/* line overstrike */
100     { 0x336, '_' },		/* long line overstrike */
101     { 0x337, '/' },		/* short solidus overstrike */
102     { 0x338, '/' },		/* long solidus overstrike */	/* 0x338 */
103     { 0 },
104     { 0 },
105     { 0 },
106     { 0 },
107     { 0 },
108     { 0 },
109     { 0 },
110     { 0x340, 0x60, 0x2cb },	/* tone mark, left of circumflex */ /* 0x340 */
111     { 0x341, 0xb4, 0x2ca },	/* tone mark, right of circumflex */
112     { 0x342, 0x2dc, 0x7e },	/* perispomeni (tilde) */
113     { 0x343, 0x2bc, ',' },	/* koronis */
114     { 0 },			/* dialytika tonos (two accents) */
115     { 0x37a },			/* ypogegrammeni */
116     { 0xffff }
117 };
118 
CanonicalCombiner(int uni)119 int CanonicalCombiner(int uni) {
120     /* Translate spacing accents to combiners */
121     int j,k;
122 
123     /* The above table will use these occasionally, but we don't want to */
124     /*  translate them. They aren't accents */
125     if ( uni==',' || uni=='\'' || uni=='"' || uni=='~' || uni=='^' || uni=='-' ||
126 	    uni=='+' || uni=='.' )
127 return( uni );
128 
129     for ( j=0; accents[j][0]!=0xffff; ++j ) {
130 	for ( k=0; k<4 && accents[j][k]!=0; ++k ) {
131 	    if ( uni==(int)accents[j][k] ) {
132 		uni = 0x300+j;
133 	break;
134 	    }
135 	}
136 	if ( uni>=0x300 && uni<0x370 )
137     break;
138     }
139 return( uni );
140 }
141 
142 
143 
isaccent(int uni)144 int isaccent(int uni) {
145 
146     if ( uni<0x10000 && iscombining(uni) )
147 return( true );
148     if ( uni>=0x2b0 && uni<0x2ff )
149 return( true );
150     if ( uni=='.' || uni==',' || uni==0x60 || uni==0x5e || uni==0x7e ||
151 	    uni==0xa8 || uni==0xaf || uni==0xb8 || uni==0x384 || uni==0x385 ||
152 	    (uni>=0x1fbd && uni<=0x1fc1) ||
153 	    (uni>=0x1fcd && uni<=0x1fcf) ||
154 	    (uni>=0x1fed && uni<=0x1fef) ||
155 	    (uni>=0x1ffd && uni<=0x1fff) )
156 return( true );
157 
158 return( false );
159 }
160 
161