1/*
2 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
3 *
4 * This is part of HarfBuzz, an OpenType Layout engine library.
5 *
6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that the
9 * above copyright notice and the following two paragraphs appear in
10 * all copies of this software.
11 *
12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
16 * DAMAGE.
17 *
18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23 */
24
25#include <harfbuzz-external.h>
26#include <Qt/private/qunicodetables_p.h>
27#include <QLibrary>
28#include <QTextCodec>
29
30extern "C" {
31
32HB_LineBreakClass HB_GetLineBreakClass(HB_UChar32 ch)
33{
34#if QT_VERSION >= 0x040300
35    return (HB_LineBreakClass)QUnicodeTables::lineBreakClass(ch);
36#else
37#error "This test currently requires Qt >= 4.3"
38#endif
39}
40
41void HB_GetUnicodeCharProperties(HB_UChar32 ch, HB_CharCategory *category, int *combiningClass)
42{
43    *category = (HB_CharCategory)QChar::category(ch);
44    *combiningClass = QChar::combiningClass(ch);
45}
46
47HB_CharCategory HB_GetUnicodeCharCategory(HB_UChar32 ch)
48{
49    return (HB_CharCategory)QChar::category(ch);
50}
51
52int HB_GetUnicodeCharCombiningClass(HB_UChar32 ch)
53{
54    return QChar::combiningClass(ch);
55}
56
57HB_UChar16 HB_GetMirroredChar(HB_UChar16 ch)
58{
59    return QChar::mirroredChar(ch);
60}
61
62HB_WordClass HB_GetWordClass(HB_UChar32 ch)
63{
64    const QUnicodeTables::Properties *prop = QUnicodeTables::properties(ch);
65    return (HB_WordClass) prop->wordBreak;
66}
67
68
69HB_SentenceClass HB_GetSentenceClass(HB_UChar32 ch)
70{
71    const QUnicodeTables::Properties *prop = QUnicodeTables::properties(ch);
72    return (HB_SentenceClass) prop->sentenceBreak;
73}
74
75void HB_GetGraphemeAndLineBreakClass(HB_UChar32 ch, HB_GraphemeClass *grapheme, HB_LineBreakClass *lineBreak)
76{
77    const QUnicodeTables::Properties *prop = QUnicodeTables::properties(ch);
78    *grapheme = (HB_GraphemeClass) prop->graphemeBreak;
79    *lineBreak = (HB_LineBreakClass) prop->line_break_class;
80}
81
82void *HB_Library_Resolve(const char *library, const char *symbol)
83{
84    return QLibrary::resolve(library, symbol);
85}
86
87void *HB_TextCodecForMib(int mib)
88{
89    return QTextCodec::codecForMib(mib);
90}
91
92char *HB_TextCodec_ConvertFromUnicode(void *codec, const HB_UChar16 *unicode, hb_uint32 length, hb_uint32 *outputLength)
93{
94    QByteArray data = reinterpret_cast<QTextCodec *>(codec)->fromUnicode((const QChar *)unicode, length);
95    // ### suboptimal
96    char *output = (char *)malloc(data.length() + 1);
97    memcpy(output, data.constData(), data.length() + 1);
98    if (outputLength)
99        *outputLength = data.length();
100    return output;
101}
102
103void HB_TextCodec_FreeResult(char *string)
104{
105    free(string);
106}
107
108}
109