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