src/corelib/tools/qharfbuzz.cpp
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtCore module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include "qunicodetables_p.h"
       
    43 #include "qlibrary.h"
       
    44 #include "qtextcodec.h"
       
    45 
       
    46 #include "qharfbuzz_p.h"
       
    47 
       
    48 QT_USE_NAMESPACE
       
    49 
       
    50 extern "C" {
       
    51 
       
    52 HB_GraphemeClass HB_GetGraphemeClass(HB_UChar32 ch)
       
    53 {
       
    54     const QUnicodeTables::Properties *prop = QUnicodeTables::properties(ch);
       
    55     return (HB_GraphemeClass) prop->graphemeBreak;
       
    56 }
       
    57 
       
    58 HB_WordClass HB_GetWordClass(HB_UChar32 ch)
       
    59 {
       
    60     const QUnicodeTables::Properties *prop = QUnicodeTables::properties(ch);
       
    61     return (HB_WordClass) prop->wordBreak;
       
    62 }
       
    63 
       
    64 HB_SentenceClass HB_GetSentenceClass(HB_UChar32 ch)
       
    65 {
       
    66     const QUnicodeTables::Properties *prop = QUnicodeTables::properties(ch);
       
    67     return (HB_SentenceClass) prop->sentenceBreak;
       
    68 }
       
    69 
       
    70 HB_LineBreakClass HB_GetLineBreakClass(HB_UChar32 ch)
       
    71 {
       
    72     return (HB_LineBreakClass)QUnicodeTables::lineBreakClass(ch);
       
    73 }
       
    74 
       
    75 
       
    76 void HB_GetGraphemeAndLineBreakClass(HB_UChar32 ch, HB_GraphemeClass *grapheme, HB_LineBreakClass *lineBreak)
       
    77 {
       
    78     const QUnicodeTables::Properties *prop = QUnicodeTables::properties(ch);
       
    79     *grapheme = (HB_GraphemeClass) prop->graphemeBreak;
       
    80     *lineBreak = (HB_LineBreakClass) prop->line_break_class;
       
    81 }
       
    82 
       
    83 void HB_GetUnicodeCharProperties(HB_UChar32 ch, HB_CharCategory *category, int *combiningClass)
       
    84 {
       
    85     const QUnicodeTables::Properties *prop = QUnicodeTables::properties(ch);
       
    86     *category = (HB_CharCategory)prop->category;
       
    87     *combiningClass = prop->combiningClass;
       
    88 }
       
    89 
       
    90 HB_CharCategory HB_GetUnicodeCharCategory(HB_UChar32 ch)
       
    91 {
       
    92     return (HB_CharCategory)QChar::category(ch);
       
    93 }
       
    94 
       
    95 int HB_GetUnicodeCharCombiningClass(HB_UChar32 ch)
       
    96 {
       
    97     return QChar::combiningClass(ch);
       
    98 }
       
    99 
       
   100 HB_UChar16 HB_GetMirroredChar(HB_UChar16 ch)
       
   101 {
       
   102     return QChar::mirroredChar(ch);
       
   103 }
       
   104 
       
   105 void *HB_Library_Resolve(const char *library, const char *symbol)
       
   106 {
       
   107 #ifdef QT_NO_LIBRARY
       
   108     return 0;
       
   109 #else
       
   110     return QLibrary::resolve(QLatin1String(library), symbol);
       
   111 #endif
       
   112 }
       
   113 
       
   114 void *HB_TextCodecForMib(int mib)
       
   115 {
       
   116 #ifndef QT_NO_TEXTCODEC
       
   117     return QTextCodec::codecForMib(mib);
       
   118 #else
       
   119     return 0;
       
   120 #endif
       
   121 }
       
   122 
       
   123 char *HB_TextCodec_ConvertFromUnicode(void *codec, const HB_UChar16 *unicode, hb_uint32 length, hb_uint32 *outputLength)
       
   124 {
       
   125 #ifndef QT_NO_TEXTCODEC
       
   126     QByteArray data = reinterpret_cast<QTextCodec *>(codec)->fromUnicode((const QChar *)unicode, length);
       
   127     // ### suboptimal
       
   128     char *output = (char *)malloc(data.length() + 1);
       
   129     Q_CHECK_PTR(output);
       
   130     memcpy(output, data.constData(), data.length() + 1);
       
   131     if (outputLength)
       
   132         *outputLength = data.length();
       
   133     return output;
       
   134 #else
       
   135     return 0;
       
   136 #endif
       
   137 }
       
   138 
       
   139 void HB_TextCodec_FreeResult(char *string)
       
   140 {
       
   141     free(string);
       
   142 }
       
   143 
       
   144 } // extern "C"
       
   145 
       
   146 QT_BEGIN_NAMESPACE
       
   147 
       
   148 HB_Bool qShapeItem(HB_ShaperItem *item)
       
   149 {
       
   150     return HB_ShapeItem(item);
       
   151 }
       
   152 
       
   153 HB_Face qHBNewFace(void *font, HB_GetFontTableFunc tableFunc)
       
   154 {
       
   155     return HB_NewFace(font, tableFunc);
       
   156 }
       
   157 
       
   158 void qHBFreeFace(HB_Face face)
       
   159 {
       
   160     HB_FreeFace(face);
       
   161 }
       
   162 
       
   163 void qGetCharAttributes(const HB_UChar16 *string, hb_uint32 stringLength,
       
   164                         const HB_ScriptItem *items, hb_uint32 numItems,
       
   165                         HB_CharAttributes *attributes)
       
   166 {
       
   167     HB_GetCharAttributes(string, stringLength, items, numItems, attributes);
       
   168 }
       
   169 
       
   170 QT_END_NAMESPACE