fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / tools / source / reversemap / bestreversemap.cxx
blobe5112c81983cfeb82e9722035ed649f65633b2ce
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <sal/config.h>
11 #include <rtl/textcvt.h>
13 #include <stdio.h>
15 struct Encoder
17 rtl_UnicodeToTextConverter m_aConverter;
18 bool m_bCapable;
19 rtl_TextEncoding m_nEncoding;
20 const char *m_pEncoding;
21 Encoder(rtl_TextEncoding nEncoding, const char *pEncoding)
22 : m_bCapable(true)
23 , m_nEncoding(nEncoding)
24 , m_pEncoding(pEncoding)
26 m_aConverter = rtl_createUnicodeToTextConverter(m_nEncoding);
28 ~Encoder()
30 rtl_destroyUnicodeToTextConverter(m_aConverter);
32 void checkSupports(sal_Unicode c)
34 sal_Char aTempArray[8];
35 sal_Size nTempSize;
36 sal_uInt32 nCvtInfo;
38 sal_Size nChars = rtl_convertUnicodeToText(m_aConverter,
39 NULL, &c, 1, aTempArray, sizeof(aTempArray),
40 RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR,
41 &nCvtInfo, &nTempSize);
42 m_bCapable = nChars > 0;
44 void reset()
46 m_bCapable = true;
48 bool isOK() const
50 return m_bCapable;
52 const char* getName() const
54 return m_pEncoding;
59 int main()
61 # define EXP(x) Encoder(x, #x)
63 Encoder aConverters[15] =
65 EXP(RTL_TEXTENCODING_MS_1361),
66 EXP(RTL_TEXTENCODING_MS_950),
67 EXP(RTL_TEXTENCODING_MS_949),
68 EXP(RTL_TEXTENCODING_MS_936),
69 EXP(RTL_TEXTENCODING_MS_932),
70 EXP(RTL_TEXTENCODING_MS_874),
71 EXP(RTL_TEXTENCODING_MS_1258),
72 EXP(RTL_TEXTENCODING_MS_1257),
73 EXP(RTL_TEXTENCODING_MS_1256),
74 EXP(RTL_TEXTENCODING_MS_1255),
75 EXP(RTL_TEXTENCODING_MS_1254),
76 EXP(RTL_TEXTENCODING_MS_1253),
77 EXP(RTL_TEXTENCODING_MS_1251),
78 EXP(RTL_TEXTENCODING_MS_1250),
79 EXP(RTL_TEXTENCODING_MS_1252)
82 printf("//Do not edit manually, generated from bestreversemap.cxx\n");
83 printf("#include <rtl/textenc.h>\n");
84 printf("#include <tools/tenccvt.hxx>\n");
85 printf("rtl_TextEncoding getBestMSEncodingByChar(sal_Unicode c)\n");
86 printf("{\n");
88 sal_Unicode c = 0;
89 while (c < 0xFFFF)
91 for (size_t i = 0; i < SAL_N_ELEMENTS(aConverters); ++i)
92 aConverters[i].reset();
94 int nMostCapable = -1;
96 while(c < 0xFFFF)
98 bool bSomethingCapable = false;
99 for (size_t i = 0; i < SAL_N_ELEMENTS(aConverters); ++i)
101 if (aConverters[i].isOK())
102 aConverters[i].checkSupports(c);
103 if (aConverters[i].isOK())
105 bSomethingCapable = true;
106 nMostCapable = i;
109 if (!bSomethingCapable)
110 break;
111 ++c;
113 sal_Unicode cEnd = c;
114 printf(" if (c < 0x%x)\n", c);
115 printf(" return %s;\n", aConverters[nMostCapable].getName());
116 while(c < 0xFFFF)
118 bool bNothingCapable = true;
119 for (size_t i = 0; i < SAL_N_ELEMENTS(aConverters); ++i)
121 aConverters[i].checkSupports(c);
122 if (aConverters[i].isOK())
124 bNothingCapable = false;
125 break;
128 if (!bNothingCapable)
129 break;
130 ++c;
132 if (cEnd != c)
134 if (c < 0xFFFF)
136 printf(" if (c < 0x%x)\n", c);
137 printf(" return RTL_TEXTENCODING_DONTKNOW;\n");
139 else
140 printf(" return RTL_TEXTENCODING_DONTKNOW;\n");
144 printf("}\n");
145 fflush(stdout);
147 return EXIT_SUCCESS;
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */