1 /****************************************************************************\
2  Part of the XeTeX typesetting system
3  Copyright (c) 2010-2014 by Han The Thanh
4 
5 Permission is hereby granted, free of charge, to any person obtaining
6 a copy of this software and associated documentation files (the
7 "Software"), to deal in the Software without restriction, including
8 without limitation the rights to use, copy, modify, merge, publish,
9 distribute, sublicense, and/or sell copies of the Software, and to
10 permit persons to whom the Software is furnished to do so, subject to
11 the following conditions:
12 
13 The above copyright notice and this permission notice shall be
14 included in all copies or substantial portions of the Software.
15 
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE
20 FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
21 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 
24 Except as contained in this notice, the name of the copyright holders
25 shall not be used in advertising or otherwise to promote the sale,
26 use or other dealings in this Software without prior written
27 authorization from the copyright holders.
28 \****************************************************************************/
29 
30 #include <w2c/config.h>
31 
32 #include "XeTeX_web.h"
33 
34 #include <map>
35 #include <iostream>
36 #include <assert.h>
37 using namespace std;
38 
39 typedef pair<int, unsigned int> GlyphId;
40 typedef map<GlyphId, int>  ProtrusionFactor;
41 ProtrusionFactor leftProt, rightProt;
42 
set_cp_code(int fontNum,unsigned int code,int side,int value)43 void set_cp_code(int fontNum, unsigned int code, int side, int value)
44 {
45     GlyphId id(fontNum, code);
46     switch (side) {
47     case LEFT_SIDE:
48         leftProt[id] = value;
49         break;
50     case RIGHT_SIDE:
51         rightProt[id] = value;
52         break;
53     default:
54         assert(0); // we should not reach here
55     }
56 }
57 
get_cp_code(int fontNum,unsigned int code,int side)58 int get_cp_code(int fontNum, unsigned int code, int side)
59 {
60     GlyphId id(fontNum, code);
61     ProtrusionFactor* container;
62     switch (side) {
63     case LEFT_SIDE:
64         container = &leftProt;
65         break;
66     case RIGHT_SIDE:
67         container = &rightProt;
68         break;
69     default:
70         assert(0); // we should not reach here
71     }
72     ProtrusionFactor::iterator it = container->find(id);
73     if (it == container->end())
74         return 0;
75     return it->second;
76 }
77 
78