MythTV  master
lang.cpp
Go to the documentation of this file.
1 #include <array>
2 #include <cstddef>
3 #include <cstring>
4 #include "vt.h"
5 #include "lang.h"
6 
7 int isLatin1 = -1;
8 
9 static std::array<uint8_t,256> lang_char;
10 
11 /* Yankable latin charset :-)
12  !"#$%&'()*+,-./0123456789:;<=>?
13  @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_
14  `abcdefghijklmnopqrstuvwxyz{|}~
15  ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿
16  ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞß
17  àáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ
18 */
19 
20 
21 
22 struct mark { const std::string m_g0, m_latin1, m_latin2; };
23 static const std::array<const mark,16> marks =
24 {{
25  /* none */ { "#",
26  "\xA4", /* ¤ */
27  "$" },
28  /* grave - ` */ { " aeiouAEIOU", /* `àèìòùÀÈÌÒÙ */
29  "`\xE0\xE8\xEC\xF2\xF9\xC0\xC8\xCC\xD2\xD9",
30  "`aeiouAEIOU" },
31  /* acute - ' */ { " aceilnorsuyzACEILNORSUYZ",
32  "'\xE1\x63\xE9\xEDln\xF3rs\xFA\xFDz\xC1\x43\xC9\xCDLN\xD3RS\xDA\xDDZ", /* 'ácéílnórsúýzÁCÉÍLNÓRSÚÝZ */
33  "'\xE1\xE6\xE9\xED\xE5\xF1\xF3\xE0\xB6\xFA\xFD\xBC\xC1\xC6\xC9\xCD\xC5\xD1\xD3\xC0\xA6\xDAݬ" /* 'áæéíåñóà¶úý¼ÁÆÉÍÅÑÓÀ¦Úݬ */ },
34  /* cirumflex - ^ */ { " aeiouAEIOU",
35  "^\xE2\xEA\xEE\xF4\xFB\xC2\xCA\xCE\xD4\xDB", /* ^âêîôûÂÊÎÔÛ */
36  "^\xE2\x65\xEE\xF4\x75\xC2\x45\xCE\xD4\x55" }, /* ^âeîôuÂEÎÔU */
37  /* tilde - ~ */ { " anoANO",
38  "~\xE3\xF1\xF5\xC3\xD1\xD5", /* ~ãñõÃÑÕ */
39  "~anoANO" },
40  /* ??? - <AF> */ { "",
41  "",
42  "" },
43  /* breve - u */ { "aA",
44  "aA",
45  "\xE3\xC3" /* ãà */ },
46  /* abovedot - · */ { "zZ",
47  "zZ",
48  "\xBF\xAF" /* ¿¯ */ },
49  /* diaeresis ¨ */ { "aeiouAEIOU",
50  "\xE4\xEB\xEF\xF6\xFC\xC4\xCB\xCF\xD6\xDC", /* äëïöüÄËÏÖÜ */
51  "\xE4\xEB\x69\xF6\xFC\xC4\xCB\x49\xD6\xDC" /* äëiöüÄËIÖÜ */},
52  /* ??? - . */ { "",
53  "",
54  "" },
55  /* ringabove - ° */ { " auAU",
56  "\xB0\xE5\x75\xC5\x55", /* °åuÅU */
57  "\xB0\x61\xF9\x41\xD9" /* °aùAÙ */ },
58  /* cedilla - ¸ */ { "cstCST",
59  "\xE7\x73\x74\xC7\x53\x54", /* çstÇST */
60  "\xE7\xBA\xFE\xC7\xAA\xDE" /* çºþÇªÞ */ },
61  /* ??? - _ */ { " ",
62  "_",
63  "_" },
64  /* dbl acute - " */ { " ouOU",
65  "\"ouOU",
66  "\x22\xF5\xFB\xD5\xDB" /* \"õûÕÛ */ },
67  /* ogonek - \, */ { "aeAE",
68  "aeAE",
69  "\xB1\xEA\xA1\xCA" /* ±ê¡Ê */ },
70  /* caron - v */ { "cdelnrstzCDELNRSTZ",
71  "cdelnrstzCDELNRSTZ",
72  "\xE8\xEF\xEC\xB5\xF2\xF8\xB9\xBB\xBE\xC8\xCF̥\xD2ة\xAB\xAE" /* èïìµòø¹»¾ÈÏÌ¥ÒØ©«® */ },
73 }};
74 
75 static const std::string g2map_latin1 =
76  /*0123456789abcdef*/
77  "\x20\xA1\xA2\xA3\x24\xA5\x23\xA7\xA4\x27\x22\xAB\x20\x20\x20\x20" /* ¡¢£$¥#§¤'\"« */
78  "\xB0\xB1\xB2\xB3\xD7\xB5\xB6\xB7\xF7\x27\x22\xBB\xBC\xBD\xBE\xBF" /* °±²³×µ¶·÷'\"»¼½¾¿ */
79  "\x20\x60\xB4\x5E\x7E\x20\x20\x20\xA8\x2e\xB0\xB8\x5F\x22\x20\x20" /* `´^~ ¨.°¸_\" */
80  "\x5F\xB9\xAE\xA9\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" /* _¹®© */
81  "\x20\xC6\xD0\xAA\x48\x20\x49\x4C\x4C\xD8\x20\xBA\xDE\x54\x4E\x6E" /* ÆЪH ILLØ ºÞTNn */
82  "\x4B\xE6\x64\xF0\x68\x69\x69\x6C\x6C\xF8\x20\xDF\xFE\x74\x6E\x7f"; /* Kædðhiillø ßþtn\x7f" */
83 
84 static const std::string g2map_latin2 =
85  /*0123456789abcdef*/
86  "\x20\x69\x63\x4C\x24\x59\x23\xA7\xA4\x27\x22\x3C\x20\x20\x20\x20" /* icL$Y#§¤'\"< */
87  "\xB0\x20\x20\x20\xD7\x75\x20\x20\xF7\x27\x22\x3E\x20\x20\x20\x20" /* ° ×u ÷'\"> */
88  "\x20\x60\xB4\x5E\x7E\x20\xA2\xFF\xA8\x2E\xB0\xB8\x5F\xBD\xB2\xB7" /* `´^~ ¢ÿ¨.°¸_½²· */
89  "\x2D\x20\x52\x43\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" /* - RC */
90  "\x20\x20\xD0\x61\x48\x20\x69\x4C\xA3\x4F\x20\x6F\x70\x54\x4E\x6e" /* ÐaH iL£O opTNn */
91  "\x4B\x20\xF0\x64\x68\x69\x69\x6C\xB3\x6F\x20\xDF\x70\x74\x6e\x7f"; /* K ðdhiil³o ßptn\x7f" */
92 
93 
94 
95 void
96 lang_init(void)
97 {
98  int i = 0;
99 
100  lang_char.fill(0);
101  for (i = 1; i <= 13; i++)
102  lang_char[(unsigned char)(lang_chars[0][i])] = i;
103 }
104 
105 
106 void
107 conv2latin(unsigned char *p, int n, int lang)
108 {
109  int gfx = 0;
110 
111  while (n--)
112  {
113  int c = 0;
114  if (lang_char[c = *p])
115  {
116  if (! gfx || (c & 0xa0) != 0x20)
117  *p = lang_chars[lang + 1][lang_char[c]];
118  }
119  else if ((c & 0xe8) == 0)
120  gfx = c & 0x10;
121  p++;
122  }
123 }
124 
125 
126 
127 void
129 {
130  eh->next_des = 0;
131 }
132 
133 void
134 add_enhance(struct enhance *eh, int dcode, std::array<unsigned int,13>& data)
135 {
136  if (dcode == eh->next_des)
137  {
138  memcpy(eh->trip + static_cast<ptrdiff_t>(dcode) * 13,
139  data.cbegin(), data.size() * sizeof(unsigned int));
140  eh->next_des++;
141  }
142  else
143  eh->next_des = -1;
144 }
145 
146 void
147 do_enhancements(struct enhance *eh, struct vt_page *vtp)
148 {
149  int8_t row = 0;
150 
151  if (eh->next_des < 1)
152  return;
153 
154  for (unsigned int *p = eh->trip, *e = p + static_cast<ptrdiff_t>(eh->next_des) * 13; p < e; p++)
155  {
156  if (*p % 2048 != 2047)
157  {
158  int8_t adr = *p % 64;
159  int8_t mode = *p / 64 % 32;
160  int8_t data = *p / 2048 % 128;
161 
162  //printf("%2x,%d,%d ", mode, adr, data);
163  if (adr < 40)
164  {
165  // col functions
166  switch (mode)
167  {
168  case 15: // char from G2 set
169  if (adr < VT_WIDTH && row < VT_HEIGHT)
170  {
171  if (isLatin1)
172  vtp->data[row][adr] = g2map_latin1[data-32];
173  else
174  vtp->data[row][adr] = g2map_latin2[data-32];
175  }
176  break;
177  case 16 ... 31: // char from G0 set with diacritical mark
178  if (adr < VT_WIDTH && row < VT_HEIGHT)
179  {
180  const struct mark *mark = &marks[mode - 16];
181  size_t index = mark->m_g0.find(data);
182  if (index != std::string::npos)
183  {
184  if (isLatin1)
185  data = mark->m_latin1[index];
186  else
187  data = mark->m_latin2[index];
188  }
189  vtp->data[row][adr] = data;
190  }
191  break;
192  }
193  }
194  else
195  {
196  // row functions
197  if ((adr -= 40) == 0)
198  adr = 24;
199 
200  switch (mode)
201  {
202  case 1: // full row color
203  case 4: // set active position
204  row = adr;
205  break;
206  case 7: // address row 0 (+ full row color)
207  if (adr == 23)
208  row = 0;
209  break;
210  }
211  }
212  }
213  }
214  //printf("\n");
215 }
216 
lang_char
static std::array< uint8_t, 256 > lang_char
Definition: lang.cpp:9
vt.h
enhance
Definition: lang.h:9
g2map_latin2
static const std::string g2map_latin2
Definition: lang.cpp:84
mark::m_latin2
const std::string m_latin2
Definition: lang.cpp:22
enhance::next_des
int next_des
Definition: lang.h:11
isLatin1
int isLatin1
Definition: lang.cpp:7
lang_chars
const std::array< const std::array< const uint8_t, 16 >, 1+8+8 > lang_chars
Definition: vbilut.cpp:4
vt_page
Definition: vt.h:36
mark::m_latin1
const std::string m_latin1
Definition: lang.cpp:22
VT_WIDTH
#define VT_WIDTH
Definition: vt.h:4
VT_HEIGHT
#define VT_HEIGHT
Definition: vt.h:5
do_enhancements
void do_enhancements(struct enhance *eh, struct vt_page *vtp)
Definition: lang.cpp:147
hardwareprofile.config.p
p
Definition: config.py:33
mark
Definition: lang.cpp:22
conv2latin
void conv2latin(unsigned char *p, int n, int lang)
Definition: lang.cpp:107
init_enhance
void init_enhance(struct enhance *eh)
Definition: lang.cpp:128
lang_init
void lang_init(void)
Definition: lang.cpp:96
g2map_latin1
static const std::string g2map_latin1
Definition: lang.cpp:75
lang.h
mark::m_g0
const std::string m_g0
Definition: lang.cpp:22
marks
static const std::array< const mark, 16 > marks
Definition: lang.cpp:23
enhance::trip
unsigned int trip[13 *16]
Definition: lang.h:12
vt_page::data
unsigned char data[VT_HEIGHT][VT_WIDTH]
Definition: vt.h:43
add_enhance
void add_enhance(struct enhance *eh, int dcode, std::array< unsigned int, 13 > &data)
Definition: lang.cpp:134