1 /************************************************************************/
2 /*									*/
3 /*  Map unicodes to alternatives.					*/
4 /*									*/
5 /*  The purpose is not to reject a font because it misses a few glyphs	*/
6 /*  and resonable alternatives are available.				*/
7 /*									*/
8 /************************************************************************/
9 
10 #   include	"textEncodingConfig.h"
11 
12 #   include	"uniAlternatives.h"
13 #   include	<appDebugon.h>
14 
15 typedef struct AlternativeChar
16     {
17     int		acFrom;
18     int		acWith;
19     } AlternativeChar;
20 
21 static const AlternativeChar alternatives[] =
22 {
23     { 0x00a6,	0x007c }, /*  broken bar -> bar.	*/
24     { 0x00ac,	0x007e }, /*  logical not -> tilde.	*/
25     { 0x00ad,	0x002d }, /*  soft hyphen -> minus	*/
26     { 0x00b7,	0x2022 }, /*  .centered -> bullet.	*/
27     { 0x00ff,	0x0079 }, /*  ydieresis -> y		*/
28     { 0x0394,	0x2206 }, /*  Delta -> Increment.	*/
29     { 0x03a9,	0x2126 }, /*  Omega -> Ohm sign.	*/
30     { 0x03bc,	0x00b5 }, /*  mu -> micro sign.		*/
31     { 0x20ac,	0x0045 }, /*  Euro -> E			*/
32     { 0x2215,	0x002f }, /*  fraction -> slash.	*/
33 };
34 
35 /************************************************************************/
36 /*									*/
37 /*  Map a unicode value to an alternative.				*/
38 /*									*/
39 /************************************************************************/
40 
uniGetAlternative(int unicode)41 int uniGetAlternative(	int unicode )
42     {
43     int		l= 0;
44     int		r= sizeof(alternatives)/sizeof(AlternativeChar);
45     int		m= ( l+ r )/ 2;
46 
47     while( m != l )
48 	{
49 	if  ( alternatives[m].acFrom > unicode )
50 	    { r= m;	}
51 	else{ l= m;	}
52 
53 	m= ( l+ r )/ 2;
54 	}
55 
56     if  ( alternatives[m].acFrom == unicode )
57 	{ return alternatives[m].acWith;	}
58 
59     return -1;
60     }
61 
62 /************************************************************************/
63 /*									*/
64 /*  Extend a set with those values that it has alternatives for.	*/
65 /*									*/
66 /************************************************************************/
67 
uniIncludeWithAlternatives(IndexSet * is)68 int uniIncludeWithAlternatives(	IndexSet *		is )
69     {
70     int		i;
71 
72     for ( i= 0; i < sizeof(alternatives)/sizeof(AlternativeChar); i++ )
73 	{
74 	if  (   utilIndexSetContains( is, alternatives[i].acWith )	&&
75 	      ! utilIndexSetContains( is, alternatives[i].acFrom )	&&
76 	      utilIndexSetAdd( is, alternatives[i].acFrom )		)
77 	    { LDEB(alternatives[i].acFrom); return -1;	}
78 	}
79 
80     return 0;
81     }
82 
83 /************************************************************************/
84 /*									*/
85 /*  Extend a mapping such that unmapped values are mapped to their	*/
86 /*  alternatives.							*/
87 /*									*/
88 /************************************************************************/
89 
uniMapToAlternatives(IndexMapping * im)90 int uniMapToAlternatives(	IndexMapping *		im )
91     {
92     int		i;
93 
94     for ( i= 0; i < sizeof(alternatives)/sizeof(AlternativeChar); i++ )
95 	{
96 	int	f= utilIndexMappingGet( im, alternatives[i].acFrom );
97 	int	w;
98 
99 	if  ( f >= 0 )
100 	    { continue;	}
101 
102 	w= utilIndexMappingGet( im, alternatives[i].acWith );
103 	if  ( w < 0 )
104 	    { continue;	}
105 
106 	if  ( utilIndexMappingPut( im, alternatives[i].acFrom, w ) )
107 	    { LLDEB(alternatives[i].acFrom,w); return -1;	}
108 	}
109 
110     return 0;
111     }
112 
113