-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompose.m
125 lines (112 loc) · 3.42 KB
/
compose.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
% COMPOSE Compose an array of codes into a character
%
% Usage
% code_char = compose(code);
%
% Input
% code: An array of size 4-by-n where each of the four elements in each
% column corresponding to a different direction (up, right, down, and
% left) which can take one of the values 1 (empty), 2 (thin) or 3
% (thick), 4 (thin dashed) and 5 (thick dashed).
%
% Output
% code_char: An array of size 1-by-n containing the Unicode code point
% values that correspond to the inputs. For example [1 2 1 2] gives a
% horizontal line while [3 2 3 2] gives a thin horizontal line crossed
% by a thick vertical one.
function code_char = compose(code)
chars = cell(3,3,3,3);
chars{1,1,1,2} = '74';
chars{2,1,1,1} = '75';
chars{1,2,1,1} = '76';
chars{1,1,2,1} = '77';
chars{1,1,1,3} = '78';
chars{3,1,1,1} = '79';
chars{1,3,1,1} = '7a';
chars{1,1,3,1} = '7b';
chars{1,2,1,2} = '00';
chars{1,3,1,3} = '01';
chars{2,1,2,1} = '02';
chars{3,1,3,1} = '03';
chars{1,3,1,2} = '7c';
chars{2,1,3,1} = '7d';
chars{1,2,1,3} = '7e';
chars{3,1,2,1} = '7f';
chars{1,2,2,1} = '0c';
chars{1,3,2,1} = '0d';
chars{1,2,3,1} = '0e';
chars{1,3,3,1} = '0f';
chars{1,1,2,2} = '10';
chars{1,1,2,3} = '11';
chars{1,1,3,2} = '12';
chars{1,1,3,3} = '13';
chars{2,2,1,1} = '14';
chars{2,3,1,1} = '15';
chars{3,2,1,1} = '16';
chars{3,3,1,1} = '17';
chars{2,1,1,2} = '18';
chars{2,1,1,3} = '19';
chars{3,1,1,2} = '1a';
chars{3,1,1,3} = '1b';
chars{2,2,2,1} = '1c';
chars{2,3,2,1} = '1d';
chars{3,2,2,1} = '1e';
chars{2,2,3,1} = '1f';
chars{3,2,3,1} = '20';
chars{3,3,2,1} = '21';
chars{2,3,3,1} = '22';
chars{3,3,3,1} = '23';
chars{2,1,2,2} = '24';
chars{2,1,2,3} = '25';
chars{3,1,2,2} = '26';
chars{2,1,3,2} = '27';
chars{3,1,3,2} = '28';
chars{3,1,2,3} = '29';
chars{2,1,3,3} = '2a';
chars{3,1,3,3} = '2b';
chars{1,2,2,2} = '2c';
chars{1,2,2,3} = '2d';
chars{1,3,2,2} = '2e';
chars{1,3,2,3} = '2f';
chars{1,2,3,2} = '30';
chars{1,2,3,3} = '31';
chars{1,3,3,2} = '32';
chars{1,3,3,3} = '33';
chars{2,2,1,2} = '34';
chars{2,2,1,3} = '35';
chars{2,3,1,2} = '36';
chars{2,3,1,3} = '37';
chars{3,2,1,2} = '38';
chars{3,2,1,3} = '39';
chars{3,3,1,2} = '3a';
chars{3,3,1,3} = '3b';
chars{2,2,2,2} = '3c';
chars{2,2,2,3} = '3d';
chars{2,3,2,2} = '3e';
chars{2,3,2,3} = '3f';
chars{3,2,2,2} = '40';
chars{2,2,3,2} = '41';
chars{3,2,3,2} = '42';
chars{3,2,2,3} = '43';
chars{3,3,2,2} = '44';
chars{2,2,3,3} = '45';
chars{2,3,3,2} = '46';
chars{3,3,2,3} = '47';
chars{2,3,3,3} = '48';
chars{3,2,3,3} = '49';
chars{3,3,3,2} = '4a';
chars{3,3,3,3} = '4b';
chars{1,1,1,1} = '73';
chars = hex2dec('2500') + cellfun(@hex2dec, chars);
chars(1,1,1,1) = 32;
mask1 = all(bsxfun(@eq, [4 1 4 1]', code), 1);
mask2 = all(bsxfun(@eq, [1 4 1 4]', code), 1);
mask3 = all(bsxfun(@eq, [5 1 5 1]', code), 1);
mask4 = all(bsxfun(@eq, [1 5 1 5]', code), 1);
mask = mask1|mask2|mask3|mask4;
code_char(mask1) = hex2dec('254e');
code_char(mask2) = hex2dec('254c');
code_char(mask3) = hex2dec('254f');
code_char(mask4) = hex2dec('254d');
code_char(~mask) = chars(1+3.^[0:3]*(feval(@(x,y)(x(y)), [1 2 3 2 3]', code(:,~mask))-1));
end