1 /*
2  * Copyright 2014 Adobe Systems Incorporated (http://www.adobe.com/).
3  * All Rights Reserved.
4  *
5  * This software is licensed as OpenSource, under the Apache License, Version
6  * 2.0.
7  * This license is available at: http://opensource.org/licenses/Apache-2.0.
8  */
9 
10 #include "ac.h"
11 
12 /* number of default entries in counter hint glyph list. */
13 #define COUNTERDEFAULTENTRIES 4
14 #define COUNTERLISTSIZE 20
15 
16 char* gVHintList[] = { "m",  "M",  "T",  "ellipsis", NULL, NULL, NULL,
17                        NULL, NULL, NULL, NULL,       NULL, NULL, NULL,
18                        NULL, NULL, NULL, NULL,       NULL, NULL };
19 char* gHHintList[] = { "element", "equivalence", "notelement", "divide", NULL,
20                        NULL,      NULL,          NULL,         NULL,     NULL,
21                        NULL,      NULL,          NULL,         NULL,     NULL,
22                        NULL,      NULL,          NULL,         NULL,     NULL };
23 
24 static char* UpperSpecialGlyphs[] = { "questiondown", "exclamdown", "semicolon",
25                                       NULL };
26 
27 static char* LowerSpecialGlyphs[] = { "question", "exclam", "colon", NULL };
28 
29 static char* NoBlueList[] = { "at",       "bullet",     "copyright",
30                               "currency", "registered", NULL };
31 
32 bool
FindNameInList(char * nm,char ** lst)33 FindNameInList(char* nm, char** lst)
34 {
35     char** l = lst;
36     while (true) {
37         char* lnm = *l;
38         if (lnm == NULL)
39             return false;
40         if (strcmp(lnm, nm) == 0)
41             return true;
42         l++;
43     }
44 }
45 
46 /* Adds specified glyphs to CounterHintList array. */
47 int
AddCounterHintGlyphs(char * charlist,char * HintList[])48 AddCounterHintGlyphs(char* charlist, char* HintList[])
49 {
50     const char* setList = "(), \t\n\r";
51     char* token;
52     bool firstTime = true;
53     int16_t ListEntries = COUNTERDEFAULTENTRIES;
54 
55     while (true) {
56         if (firstTime) {
57             token = (char*)strtok(charlist, setList);
58             firstTime = false;
59         } else
60             token = (char*)strtok(NULL, setList);
61         if (token == NULL)
62             break;
63         if (FindNameInList(token, HintList))
64             continue;
65         /* Currently, HintList must end with a NULL pointer. */
66         if (ListEntries == (COUNTERLISTSIZE - 1)) {
67             LogMsg(WARNING, OK,
68                    "Exceeded counter hints list size. (maximum is %d.) "
69                    "Cannot add %s or subsequent characters.",
70                    (int)COUNTERLISTSIZE, token);
71             break;
72         }
73         HintList[ListEntries] =
74           AllocateMem(1, strlen(token) + 1, "counter hints list");
75         strcpy(HintList[ListEntries++], token);
76     }
77     return (ListEntries - COUNTERDEFAULTENTRIES);
78 }
79 
80 int32_t
SpecialGlyphType(void)81 SpecialGlyphType(void)
82 {
83     /* 1 = upper; -1 = lower; 0 = neither */
84     if (FindNameInList(gGlyphName, UpperSpecialGlyphs))
85         return 1;
86     if (FindNameInList(gGlyphName, LowerSpecialGlyphs))
87         return -1;
88     return 0;
89 }
90 
91 bool
HHintGlyph(void)92 HHintGlyph(void)
93 {
94     return FindNameInList(gGlyphName, gHHintList);
95 }
96 
97 bool
VHintGlyph(void)98 VHintGlyph(void)
99 {
100     return FindNameInList(gGlyphName, gVHintList);
101 }
102 
103 bool
NoBlueGlyph(void)104 NoBlueGlyph(void)
105 {
106     return FindNameInList(gGlyphName, NoBlueList);
107 }
108 
109 bool
MoveToNewHints(void)110 MoveToNewHints(void)
111 {
112     return strcmp(gGlyphName, "percent") == 0 ||
113            strcmp(gGlyphName, "perthousand") == 0;
114 }
115