1b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/* 2b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru ****************************************************************************** 3b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 4fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius * Copyright (C) 2000-2014, International Business Machines 5b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Corporation and others. All Rights Reserved. 6b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 7b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru ****************************************************************************** 8103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * file name: ushape.cpp 9b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * encoding: US-ASCII 10b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * tab size: 8 (not used) 11b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * indentation:4 12b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 13b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * created on: 2000jun29 14b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * created by: Markus W. Scherer 15b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 16b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Arabic letter shaping implemented by Ayman Roshdy 17b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 18b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 19b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/utypes.h" 20b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/uchar.h" 21b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/ustring.h" 22b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/ushape.h" 23b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "cmemory.h" 24b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "putilimp.h" 25b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "ustr_imp.h" 26b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "ubidi_props.h" 27103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius#include "uassert.h" 28b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 29103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius/* 30103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * This implementation is designed for 16-bit Unicode strings. 31103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * The main assumption is that the Arabic characters and their 32103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * presentation forms each fit into a single UChar. 33103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * With UTF-8, they occupy 2 or 3 bytes, and more than the ASCII 34103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * characters. 35103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius */ 36b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 37b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/* 38b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * ### TODO in general for letter shaping: 39b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * - the letter shaping code is UTF-16-unaware; needs update 40b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * + especially invertBuffer()?! 41b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * - needs to handle the "Arabic Tail" that is used in some legacy codepages 42b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * as a glyph fragment of wide-glyph letters 43b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * + IBM Unicode conversion tables map it to U+200B (ZWSP) 44b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * + IBM Egypt has proposed to encode the tail in Unicode among Arabic Presentation Forms 458393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius * + Unicode 3.2 added U+FE73 ARABIC TAIL FRAGMENT 46b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 47b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 48b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/* definitions for Arabic letter shaping ------------------------------------ */ 49b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 50b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#define IRRELEVANT 4 51b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#define LAMTYPE 16 52b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#define ALEFTYPE 32 53b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#define LINKR 1 54b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#define LINKL 2 55b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#define APRESENT 8 56b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#define SHADDA 64 57b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#define CSHADDA 128 58b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#define COMBINE (SHADDA+CSHADDA) 59b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 60b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru#define HAMZAFE_CHAR 0xfe80 61b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru#define HAMZA06_CHAR 0x0621 62b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru#define YEH_HAMZA_CHAR 0x0626 63b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru#define YEH_HAMZAFE_CHAR 0xFE89 64b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru#define LAMALEF_SPACE_SUB 0xFFFF 65b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru#define TASHKEEL_SPACE_SUB 0xFFFE 66b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru#define NEW_TAIL_CHAR 0xFE73 67b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru#define OLD_TAIL_CHAR 0x200B 68b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru#define LAM_CHAR 0x0644 69b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru#define SPACE_CHAR 0x0020 70b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru#define SHADDA_CHAR 0xFE7C 71b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru#define TATWEEL_CHAR 0x0640 72b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru#define SHADDA_TATWEEL_CHAR 0xFE7D 7354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius#define SHADDA06_CHAR 0x0651 74b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 75b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru#define SHAPE_MODE 0 76b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru#define DESHAPE_MODE 1 77b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 7854dcd9b6a06071f647dac967e9e267abb9410720Craig Corneliusstruct uShapeVariables { 7954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UChar tailChar; 8054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius uint32_t uShapeLamalefBegin; 8154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius uint32_t uShapeLamalefEnd; 8254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius uint32_t uShapeTashkeelBegin; 8354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius uint32_t uShapeTashkeelEnd; 8454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius int spacesRelativeToTextBeginEnd; 8554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius}; 86b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 87b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Querustatic const uint8_t tailFamilyIsolatedFinal[] = { 88b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* FEB1 */ 1, 89b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* FEB2 */ 1, 90b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* FEB3 */ 0, 91b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* FEB4 */ 0, 92b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* FEB5 */ 1, 93b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* FEB6 */ 1, 94b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* FEB7 */ 0, 95b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* FEB8 */ 0, 96b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* FEB9 */ 1, 97b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* FEBA */ 1, 98b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* FEBB */ 0, 99b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* FEBC */ 0, 100b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* FEBD */ 1, 101b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* FEBE */ 1 102b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru}; 103b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 104b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Querustatic const uint8_t tashkeelMedial[] = { 105b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* FE70 */ 0, 106b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* FE71 */ 1, 107b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* FE72 */ 0, 108b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* FE73 */ 0, 109b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* FE74 */ 0, 110b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* FE75 */ 0, 111b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* FE76 */ 0, 112b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* FE77 */ 1, 113b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* FE78 */ 0, 114b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* FE79 */ 1, 115b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* FE7A */ 0, 116b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* FE7B */ 1, 117b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* FE7C */ 0, 118b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* FE7D */ 1, 119b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* FE7E */ 0, 120b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* FE7F */ 1 121b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru}; 122b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 123b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Querustatic const UChar yehHamzaToYeh[] = 124b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru{ 125b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru/* isolated*/ 0xFEEF, 126b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru/* final */ 0xFEF0 127b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru}; 128b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 129c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Querustatic const uint8_t IrrelevantPos[] = { 130b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x0, 0x2, 0x4, 0x6, 131b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 0x8, 0xA, 0xC, 0xE 132b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}; 133b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 134b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 135b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic const UChar convertLamAlef[] = 136b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{ 137b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FEF5*/ 0x0622, 138b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FEF6*/ 0x0622, 139b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FEF7*/ 0x0623, 140b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FEF8*/ 0x0623, 141b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FEF9*/ 0x0625, 142b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FEFA*/ 0x0625, 143b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FEFB*/ 0x0627, 144b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FEFC*/ 0x0627 145b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}; 146b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 147b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic const UChar araLink[178]= 148b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{ 149b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 32 + 256 * 0x11,/*0x0622*/ 150b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 32 + 256 * 0x13,/*0x0623*/ 151b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 256 * 0x15,/*0x0624*/ 152b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 32 + 256 * 0x17,/*0x0625*/ 153b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 2 + 256 * 0x19,/*0x0626*/ 154b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 32 + 256 * 0x1D,/*0x0627*/ 155b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 2 + 256 * 0x1F,/*0x0628*/ 156b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 256 * 0x23,/*0x0629*/ 157b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 2 + 256 * 0x25,/*0x062A*/ 158b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 2 + 256 * 0x29,/*0x062B*/ 159b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 2 + 256 * 0x2D,/*0x062C*/ 160b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 2 + 256 * 0x31,/*0x062D*/ 161b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 2 + 256 * 0x35,/*0x062E*/ 162b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 256 * 0x39,/*0x062F*/ 163b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 256 * 0x3B,/*0x0630*/ 164b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 256 * 0x3D,/*0x0631*/ 165b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 256 * 0x3F,/*0x0632*/ 166b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 2 + 256 * 0x41,/*0x0633*/ 167b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 2 + 256 * 0x45,/*0x0634*/ 168b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 2 + 256 * 0x49,/*0x0635*/ 169b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 2 + 256 * 0x4D,/*0x0636*/ 170b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 2 + 256 * 0x51,/*0x0637*/ 171b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 2 + 256 * 0x55,/*0x0638*/ 172b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 2 + 256 * 0x59,/*0x0639*/ 173b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 2 + 256 * 0x5D,/*0x063A*/ 174b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0, 0, 0, 0, 0, /*0x063B-0x063F*/ 175b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 2, /*0x0640*/ 176b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 2 + 256 * 0x61,/*0x0641*/ 177b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 2 + 256 * 0x65,/*0x0642*/ 178b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 2 + 256 * 0x69,/*0x0643*/ 179b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 2 + 16 + 256 * 0x6D,/*0x0644*/ 180b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 2 + 256 * 0x71,/*0x0645*/ 181b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 2 + 256 * 0x75,/*0x0646*/ 182b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 2 + 256 * 0x79,/*0x0647*/ 183b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 256 * 0x7D,/*0x0648*/ 184b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 256 * 0x7F,/*0x0649*/ 185b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 2 + 256 * 0x81,/*0x064A*/ 186b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 4 + 256 * 1, /*0x064B*/ 187b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 4 + 128 + 256 * 1, /*0x064C*/ 188b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 4 + 128 + 256 * 1, /*0x064D*/ 189b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 4 + 128 + 256 * 1, /*0x064E*/ 190b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 4 + 128 + 256 * 1, /*0x064F*/ 191b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 4 + 128 + 256 * 1, /*0x0650*/ 192b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 4 + 64 + 256 * 3, /*0x0651*/ 193b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 4 + 256 * 1, /*0x0652*/ 194b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 4 + 256 * 7, /*0x0653*/ 195b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 4 + 256 * 8, /*0x0654*/ 196103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 4 + 256 * 8, /*0x0655*/ 197b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 4 + 256 * 1, /*0x0656*/ 198b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0, 0, 0, 0, 0, /*0x0657-0x065B*/ 199b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 256 * 0x85,/*0x065C*/ 200b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 256 * 0x87,/*0x065D*/ 201b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 256 * 0x89,/*0x065E*/ 202b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 256 * 0x8B,/*0x065F*/ 203b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0, 0, 0, 0, 0, /*0x0660-0x0664*/ 204b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0, 0, 0, 0, 0, /*0x0665-0x0669*/ 205b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0, 0, 0, 0, 0, 0, /*0x066A-0x066F*/ 206b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 4 + 256 * 6, /*0x0670*/ 207b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 8 + 256 * 0x00,/*0x0671*/ 208b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 32, /*0x0672*/ 209b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 32, /*0x0673*/ 210b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0, /*0x0674*/ 211b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1 + 32, /*0x0675*/ 212b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1, 1, /*0x0676-0x0677*/ 21359d709d503bab6e2b61931737e662dd293b40578ccornelius 1 + 2, /*0x0678*/ 21459d709d503bab6e2b61931737e662dd293b40578ccornelius 1 + 2 + 8 + 256 * 0x16,/*0x0679*/ 21559d709d503bab6e2b61931737e662dd293b40578ccornelius 1 + 2 + 8 + 256 * 0x0E,/*0x067A*/ 21659d709d503bab6e2b61931737e662dd293b40578ccornelius 1 + 2 + 8 + 256 * 0x02,/*0x067B*/ 21759d709d503bab6e2b61931737e662dd293b40578ccornelius 1+2, 1+2, /*0x67C-0x067D*/ 218b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1+2+8+256 * 0x06, 1+2, 1+2, 1+2, 1+2, 1+2, /*0x067E-0x0683*/ 219b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1+2, 1+2, 1+2+8+256 * 0x2A, 1+2, /*0x0684-0x0687*/ 22059d709d503bab6e2b61931737e662dd293b40578ccornelius 1 + 8 + 256 * 0x38,/*0x0688*/ 22159d709d503bab6e2b61931737e662dd293b40578ccornelius 1, 1, 1, /*0x0689-0x068B*/ 22259d709d503bab6e2b61931737e662dd293b40578ccornelius 1 + 8 + 256 * 0x34,/*0x068C*/ 22359d709d503bab6e2b61931737e662dd293b40578ccornelius 1 + 8 + 256 * 0x32,/*0x068D*/ 22459d709d503bab6e2b61931737e662dd293b40578ccornelius 1 + 8 + 256 * 0x36,/*0x068E*/ 22559d709d503bab6e2b61931737e662dd293b40578ccornelius 1, 1, /*0x068F-0x0690*/ 22659d709d503bab6e2b61931737e662dd293b40578ccornelius 1 + 8 + 256 * 0x3C,/*0x0691*/ 227b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1, 1, 1, 1, 1, 1, 1+8+256 * 0x3A, 1, /*0x0692-0x0699*/ 228b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1+2, 1+2, 1+2, 1+2, 1+2, 1+2, /*0x069A-0x06A3*/ 229b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1+2, 1+2, 1+2, 1+2, /*0x069A-0x06A3*/ 230b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1+2, 1+2, 1+2, 1+2, 1+2, 1+2+8+256 * 0x3E, /*0x06A4-0x06AD*/ 231b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1+2, 1+2, 1+2, 1+2, /*0x06A4-0x06AD*/ 232b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1+2, 1+2+8+256 * 0x42, 1+2, 1+2, 1+2, 1+2, /*0x06AE-0x06B7*/ 233b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1+2, 1+2, 1+2, 1+2, /*0x06AE-0x06B7*/ 23459d709d503bab6e2b61931737e662dd293b40578ccornelius 1+2, 1+2, /*0x06B8-0x06B9*/ 23559d709d503bab6e2b61931737e662dd293b40578ccornelius 1 + 8 + 256 * 0x4E,/*0x06BA*/ 23659d709d503bab6e2b61931737e662dd293b40578ccornelius 1 + 2 + 8 + 256 * 0x50,/*0x06BB*/ 23759d709d503bab6e2b61931737e662dd293b40578ccornelius 1+2, 1+2, /*0x06BC-0x06BD*/ 23859d709d503bab6e2b61931737e662dd293b40578ccornelius 1 + 2 + 8 + 256 * 0x5A,/*0x06BE*/ 23959d709d503bab6e2b61931737e662dd293b40578ccornelius 1+2, /*0x06BF*/ 24059d709d503bab6e2b61931737e662dd293b40578ccornelius 1 + 8 + 256 * 0x54,/*0x06C0*/ 24159d709d503bab6e2b61931737e662dd293b40578ccornelius 1 + 2 + 8 + 256 * 0x56,/*0x06C1*/ 24259d709d503bab6e2b61931737e662dd293b40578ccornelius 1, 1, 1, /*0x06C2-0x06C4*/ 24359d709d503bab6e2b61931737e662dd293b40578ccornelius 1 + 8 + 256 * 0x90,/*0x06C5*/ 24459d709d503bab6e2b61931737e662dd293b40578ccornelius 1 + 8 + 256 * 0x89,/*0x06C6*/ 24559d709d503bab6e2b61931737e662dd293b40578ccornelius 1 + 8 + 256 * 0x87,/*0x06C7*/ 24659d709d503bab6e2b61931737e662dd293b40578ccornelius 1 + 8 + 256 * 0x8B,/*0x06C8*/ 24759d709d503bab6e2b61931737e662dd293b40578ccornelius 1 + 8 + 256 * 0x92,/*0x06C9*/ 24859d709d503bab6e2b61931737e662dd293b40578ccornelius 1, /*0x06CA*/ 24959d709d503bab6e2b61931737e662dd293b40578ccornelius 1 + 8 + 256 * 0x8E,/*0x06CB*/ 25059d709d503bab6e2b61931737e662dd293b40578ccornelius 1 + 2 + 8 + 256 * 0xAC,/*0x06CC*/ 251b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1, /*0x06CD*/ 25259d709d503bab6e2b61931737e662dd293b40578ccornelius 1+2, 1+2, /*0x06CE-0x06CF*/ 25359d709d503bab6e2b61931737e662dd293b40578ccornelius 1 + 2 + 8 + 256 * 0x94,/*0x06D0*/ 25459d709d503bab6e2b61931737e662dd293b40578ccornelius 1+2, /*0x06D1*/ 25559d709d503bab6e2b61931737e662dd293b40578ccornelius 1 + 8 + 256 * 0x5E,/*0x06D2*/ 25659d709d503bab6e2b61931737e662dd293b40578ccornelius 1 + 8 + 256 * 0x60 /*0x06D3*/ 257b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}; 258b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 259c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Querustatic const uint8_t presALink[] = { 260b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/***********0*****1*****2*****3*****4*****5*****6*****7*****8*****9*****A*****B*****C*****D*****E*****F*/ 261b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FB5*/ 0, 1, 0, 0, 0, 0, 0, 1, 2,1 + 2, 0, 0, 0, 0, 0, 0, 262b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FB6*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 263b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FB7*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2,1 + 2, 0, 0, 264b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FB8*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 265b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FB9*/ 2,1 + 2, 0, 1, 2,1 + 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 266b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FBA*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 267b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FBB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 268b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FBC*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 269b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FBD*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 270b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FBE*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 271b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FBF*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2,1 + 2, 272b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FC0*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 273b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FC1*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 274b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FC2*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 275b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FC3*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 276b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FC4*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 277b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FC5*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 278b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FC6*/ 4, 4, 4 279b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}; 280b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 281c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Querustatic const uint8_t presBLink[]= 282b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{ 283b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/***********0*****1*****2*****3*****4*****5*****6*****7*****8*****9*****A*****B*****C*****D*****E*****F*/ 284103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius/*FE7*/1 + 2,1 + 2,1 + 2, 0,1 + 2, 0,1 + 2,1 + 2,1 + 2,1 + 2,1 + 2,1 + 2,1 + 2,1 + 2,1 + 2,1 + 2, 285b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FE8*/ 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 2,1 + 2, 0, 1, 0, 286b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FE9*/ 1, 2,1 + 2, 0, 1, 0, 1, 2,1 + 2, 0, 1, 2,1 + 2, 0, 1, 2, 287103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius/*FEA*/1 + 2, 0, 1, 2,1 + 2, 0, 1, 2,1 + 2, 0, 1, 0, 1, 0, 1, 0, 288b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FEB*/ 1, 0, 1, 2,1 + 2, 0, 1, 2,1 + 2, 0, 1, 2,1 + 2, 0, 1, 2, 289b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FEC*/1 + 2, 0, 1, 2,1 + 2, 0, 1, 2,1 + 2, 0, 1, 2,1 + 2, 0, 1, 2, 290b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FED*/1 + 2, 0, 1, 2,1 + 2, 0, 1, 2,1 + 2, 0, 1, 2,1 + 2, 0, 1, 2, 291b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FEE*/1 + 2, 0, 1, 2,1 + 2, 0, 1, 2,1 + 2, 0, 1, 2,1 + 2, 0, 1, 0, 292b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FEF*/ 1, 0, 1, 2,1 + 2, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0 293b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}; 294b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 295b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic const UChar convertFBto06[] = 296b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{ 297b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/***********0******1******2******3******4******5******6******7******8******9******A******B******C******D******E******F***/ 29859d709d503bab6e2b61931737e662dd293b40578ccornelius/*FB5*/ 0x671, 0x671, 0x67B, 0x67B, 0x67B, 0x67B, 0x67E, 0x67E, 0x67E, 0x67E, 0, 0, 0, 0, 0x67A, 0x67A, 29959d709d503bab6e2b61931737e662dd293b40578ccornelius/*FB6*/ 0x67A, 0x67A, 0, 0, 0, 0, 0x679, 0x679, 0x679, 0x679, 0, 0, 0, 0, 0, 0, 300b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FB7*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x686, 0x686, 0x686, 0x686, 0, 0, 30159d709d503bab6e2b61931737e662dd293b40578ccornelius/*FB8*/ 0, 0, 0x68D, 0x68D, 0x68C, 0x68C, 0x68E, 0x68E, 0x688, 0x688, 0x698, 0x698, 0x691, 0x691, 0x6A9, 0x6A9, 30259d709d503bab6e2b61931737e662dd293b40578ccornelius/*FB9*/ 0x6A9, 0x6A9, 0x6AF, 0x6AF, 0x6AF, 0x6AF, 0, 0, 0, 0, 0, 0, 0, 0, 0x6BA, 0x6BA, 30359d709d503bab6e2b61931737e662dd293b40578ccornelius/*FBA*/ 0x6BB, 0x6BB, 0x6BB, 0x6BB, 0x6C0, 0x6C0, 0x6C1, 0x6C1, 0x6C1, 0x6C1, 0x6BE, 0x6BE, 0x6BE, 0x6BE, 0x6d2, 0x6D2, 30459d709d503bab6e2b61931737e662dd293b40578ccornelius/*FBB*/ 0x6D3, 0x6D3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 305b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FBC*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30659d709d503bab6e2b61931737e662dd293b40578ccornelius/*FBD*/ 0, 0, 0, 0, 0, 0, 0, 0x6C7, 0x6C7, 0x6C6, 0x6C6, 0x6C8, 0x6C8, 0, 0x6CB, 0x6CB, 30759d709d503bab6e2b61931737e662dd293b40578ccornelius/*FBE*/ 0x6C5, 0x6C5, 0x6C9, 0x6C9, 0x6D0, 0x6D0, 0x6D0, 0x6D0, 0, 0, 0, 0, 0, 0, 0, 0, 308b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FBF*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x6CC, 0x6CC, 0x6CC, 0x6CC 309b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}; 310b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 311b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic const UChar convertFEto06[] = 312b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{ 313b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/***********0******1******2******3******4******5******6******7******8******9******A******B******C******D******E******F***/ 314b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FE7*/ 0x64B, 0x64B, 0x64C, 0x64C, 0x64D, 0x64D, 0x64E, 0x64E, 0x64F, 0x64F, 0x650, 0x650, 0x651, 0x651, 0x652, 0x652, 315b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FE8*/ 0x621, 0x622, 0x622, 0x623, 0x623, 0x624, 0x624, 0x625, 0x625, 0x626, 0x626, 0x626, 0x626, 0x627, 0x627, 0x628, 316b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FE9*/ 0x628, 0x628, 0x628, 0x629, 0x629, 0x62A, 0x62A, 0x62A, 0x62A, 0x62B, 0x62B, 0x62B, 0x62B, 0x62C, 0x62C, 0x62C, 317b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FEA*/ 0x62C, 0x62D, 0x62D, 0x62D, 0x62D, 0x62E, 0x62E, 0x62E, 0x62E, 0x62F, 0x62F, 0x630, 0x630, 0x631, 0x631, 0x632, 318b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FEB*/ 0x632, 0x633, 0x633, 0x633, 0x633, 0x634, 0x634, 0x634, 0x634, 0x635, 0x635, 0x635, 0x635, 0x636, 0x636, 0x636, 319b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FEC*/ 0x636, 0x637, 0x637, 0x637, 0x637, 0x638, 0x638, 0x638, 0x638, 0x639, 0x639, 0x639, 0x639, 0x63A, 0x63A, 0x63A, 320b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FED*/ 0x63A, 0x641, 0x641, 0x641, 0x641, 0x642, 0x642, 0x642, 0x642, 0x643, 0x643, 0x643, 0x643, 0x644, 0x644, 0x644, 321b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FEE*/ 0x644, 0x645, 0x645, 0x645, 0x645, 0x646, 0x646, 0x646, 0x646, 0x647, 0x647, 0x647, 0x647, 0x648, 0x648, 0x649, 322b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*FEF*/ 0x649, 0x64A, 0x64A, 0x64A, 0x64A, 0x65C, 0x65C, 0x65D, 0x65D, 0x65E, 0x65E, 0x65F, 0x65F 323b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}; 324b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 325c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Querustatic const uint8_t shapeTable[4][4][4]= 326b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{ 327b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { {0,0,0,0}, {0,0,0,0}, {0,1,0,3}, {0,1,0,1} }, 328b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { {0,0,2,2}, {0,0,1,2}, {0,1,1,2}, {0,1,1,3} }, 329b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { {0,0,0,0}, {0,0,0,0}, {0,1,0,3}, {0,1,0,3} }, 330b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { {0,0,1,2}, {0,0,1,2}, {0,1,1,2}, {0,1,1,3} } 331b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}; 332b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 333b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/* 334b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * This function shapes European digits to Arabic-Indic digits 335b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * in-place, writing over the input characters. 336b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Since we know that we are only looking for BMP code points, 337b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * we can safely just work with code units (again, at least UTF-16). 338b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 339b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void 340b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru_shapeToArabicDigitsWithContext(UChar *s, int32_t length, 341b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar digitBase, 342b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UBool isLogical, UBool lastStrongWasAL) { 343b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru const UBiDiProps *bdp; 344b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t i; 345b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar c; 346b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 34727f654740f2a26ad62a5c155af9199af9e69b889claireho bdp=ubidi_getSingleton(); 348b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru digitBase-=0x30; 349b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 350b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* the iteration direction depends on the type of input */ 351b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(isLogical) { 352b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru for(i=0; i<length; ++i) { 353b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru c=s[i]; 354b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru switch(ubidi_getClass(bdp, c)) { 355b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru case U_LEFT_TO_RIGHT: /* L */ 356b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru case U_RIGHT_TO_LEFT: /* R */ 357b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru lastStrongWasAL=FALSE; 358b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru break; 359b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru case U_RIGHT_TO_LEFT_ARABIC: /* AL */ 360b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru lastStrongWasAL=TRUE; 361b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru break; 362b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru case U_EUROPEAN_NUMBER: /* EN */ 363b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(lastStrongWasAL && (uint32_t)(c-0x30)<10) { 364b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru s[i]=(UChar)(digitBase+c); /* digitBase+(c-0x30) - digitBase was modified above */ 365b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 366b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru break; 367b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru default : 368b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru break; 369b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 370b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 371b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else { 372b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru for(i=length; i>0; /* pre-decrement in the body */) { 373b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru c=s[--i]; 374b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru switch(ubidi_getClass(bdp, c)) { 375b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru case U_LEFT_TO_RIGHT: /* L */ 376b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru case U_RIGHT_TO_LEFT: /* R */ 377b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru lastStrongWasAL=FALSE; 378b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru break; 379b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru case U_RIGHT_TO_LEFT_ARABIC: /* AL */ 380b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru lastStrongWasAL=TRUE; 381b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru break; 382b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru case U_EUROPEAN_NUMBER: /* EN */ 383b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(lastStrongWasAL && (uint32_t)(c-0x30)<10) { 384b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru s[i]=(UChar)(digitBase+c); /* digitBase+(c-0x30) - digitBase was modified above */ 385b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 386b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru break; 387b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru default : 388b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru break; 389b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 390b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 391b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 392b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 393b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 394b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/* 395b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *Name : invertBuffer 396b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *Function : This function inverts the buffer, it's used 397b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * in case the user specifies the buffer to be 398b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * U_SHAPE_TEXT_DIRECTION_LOGICAL 399b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 40027f654740f2a26ad62a5c155af9199af9e69b889clairehostatic void 401103e9ffba2cba345d0078eb8b8db33249f81840aCraig CorneliusinvertBuffer(UChar *buffer, int32_t size, uint32_t /*options*/, int32_t lowlimit, int32_t highlimit) { 402b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar temp; 403b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t i=0,j=0; 404b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru for(i=lowlimit,j=size-highlimit-1;i<j;i++,j--) { 405b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru temp = buffer[i]; 406b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru buffer[i] = buffer[j]; 407b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru buffer[j] = temp; 408b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 409b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 410b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 411b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/* 412b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *Name : changeLamAlef 413b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *Function : Converts the Alef characters into an equivalent 414b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * LamAlef location in the 0x06xx Range, this is an 415b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * intermediate stage in the operation of the program 416b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * later it'll be converted into the 0xFExx LamAlefs 417b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * in the shaping function. 418b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 419103e9ffba2cba345d0078eb8b8db33249f81840aCraig Corneliusstatic inline UChar 420b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruchangeLamAlef(UChar ch) { 421b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru switch(ch) { 422b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru case 0x0622 : 423b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return 0x065C; 424b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru case 0x0623 : 425b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return 0x065D; 426b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru case 0x0625 : 427b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return 0x065E; 428b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru case 0x0627 : 429b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return 0x065F; 430b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 431b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return 0; 432b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 433b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 434b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/* 435b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *Name : getLink 436b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *Function : Resolves the link between the characters as 437b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Arabic characters have four forms : 438b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Isolated, Initial, Middle and Final Form 439b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 440b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic UChar 441b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QuerugetLink(UChar ch) { 442b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(ch >= 0x0622 && ch <= 0x06D3) { 443b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return(araLink[ch-0x0622]); 444b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else if(ch == 0x200D) { 445b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return(3); 446b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else if(ch >= 0x206D && ch <= 0x206F) { 447b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return(4); 448b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru }else if(ch >= 0xFB50 && ch <= 0xFC62) { 449b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return(presALink[ch-0xFB50]); 450b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else if(ch >= 0xFE70 && ch <= 0xFEFC) { 451b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return(presBLink[ch-0xFE70]); 452b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru }else { 453b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return(0); 454b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 455b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 456b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 457b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/* 458b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *Name : countSpaces 459b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *Function : Counts the number of spaces 460b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * at each end of the logical buffer 461b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 462b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void 463103e9ffba2cba345d0078eb8b8db33249f81840aCraig CorneliuscountSpaces(UChar *dest, int32_t size, uint32_t /*options*/, int32_t *spacesCountl, int32_t *spacesCountr) { 464b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t i = 0; 465b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t countl = 0,countr = 0; 466103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius while((dest[i] == SPACE_CHAR) && (countl < size)) { 467b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru countl++; 468b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru i++; 469b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 470103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius if (countl < size) { /* the entire buffer is not all space */ 471103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius while(dest[size-1] == SPACE_CHAR) { 472103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius countr++; 473103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius size--; 474103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius } 475b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 476b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *spacesCountl = countl; 477b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *spacesCountr = countr; 478b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 479b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 480b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/* 481b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *Name : isTashkeelChar 482b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru *Function : Returns 1 for Tashkeel characters in 06 range else return 0 483b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 484103e9ffba2cba345d0078eb8b8db33249f81840aCraig Corneliusstatic inline int32_t 485b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruisTashkeelChar(UChar ch) { 486b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return (int32_t)( ch>=0x064B && ch<= 0x0652 ); 487b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 488b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 489b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/* 490b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru *Name : isTashkeelCharFE 491b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru *Function : Returns 1 for Tashkeel characters in FE range else return 0 492b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru */ 493103e9ffba2cba345d0078eb8b8db33249f81840aCraig Corneliusstatic inline int32_t 494b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste QueruisTashkeelCharFE(UChar ch) { 495b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return (int32_t)( ch>=0xFE70 && ch<= 0xFE7F ); 496b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru} 497b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 498b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru/* 499b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *Name : isAlefChar 500b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *Function : Returns 1 for Alef characters else return 0 501b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 502103e9ffba2cba345d0078eb8b8db33249f81840aCraig Corneliusstatic inline int32_t 503b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruisAlefChar(UChar ch) { 504b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return (int32_t)( (ch==0x0622)||(ch==0x0623)||(ch==0x0625)||(ch==0x0627) ); 505b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 506b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 507b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/* 508b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *Name : isLamAlefChar 509b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *Function : Returns 1 for LamAlef characters else return 0 510b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 511103e9ffba2cba345d0078eb8b8db33249f81840aCraig Corneliusstatic inline int32_t 512b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruisLamAlefChar(UChar ch) { 513b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return (int32_t)((ch>=0xFEF5)&&(ch<=0xFEFC) ); 514b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru} 515b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 516b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru/*BIDI 517b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru *Name : isTailChar 518103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius *Function : returns 1 if the character matches one of the tail characters (0xfe73 or 0x200b) otherwise returns 0 519b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru */ 520b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 521103e9ffba2cba345d0078eb8b8db33249f81840aCraig Corneliusstatic inline int32_t 522b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste QueruisTailChar(UChar ch) { 523b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(ch == OLD_TAIL_CHAR || ch == NEW_TAIL_CHAR){ 524b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return 1; 525b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru }else{ 526b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return 0; 527b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 528b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru} 529b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 530b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru/*BIDI 531b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru *Name : isSeenTailFamilyChar 532103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius *Function : returns 1 if the character is a seen family isolated character 533b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * in the FE range otherwise returns 0 534b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru */ 535b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 536103e9ffba2cba345d0078eb8b8db33249f81840aCraig Corneliusstatic inline int32_t 537b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste QueruisSeenTailFamilyChar(UChar ch) { 538b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(ch >= 0xfeb1 && ch < 0xfebf){ 539b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return tailFamilyIsolatedFinal [ch - 0xFEB1]; 540b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru }else{ 541b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return 0; 542b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 543b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru} 544b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 545b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* Name : isSeenFamilyChar 546b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * Function : returns 1 if the character is a seen family character in the Unicode 547b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * 06 range otherwise returns 0 548b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru */ 549b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 550103e9ffba2cba345d0078eb8b8db33249f81840aCraig Corneliusstatic inline int32_t 551b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste QueruisSeenFamilyChar(UChar ch){ 552b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(ch >= 0x633 && ch <= 0x636){ 553b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return 1; 554b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru }else { 555b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return 0; 556b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 557b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 558b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 559b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru/*Start of BIDI*/ 560b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru/* 561b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru *Name : isAlefMaksouraChar 562103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius *Function : returns 1 if the character is a Alef Maksoura Final or isolated 563103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * otherwise returns 0 564b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru */ 565103e9ffba2cba345d0078eb8b8db33249f81840aCraig Corneliusstatic inline int32_t 566b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste QueruisAlefMaksouraChar(UChar ch) { 567b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return (int32_t)( (ch == 0xFEEF) || ( ch == 0xFEF0) || (ch == 0x0649)); 568103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius} 569b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 570b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru/* 571b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * Name : isYehHamzaChar 572b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * Function : returns 1 if the character is a yehHamza isolated or yehhamza 573103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * final is found otherwise returns 0 574b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru */ 575103e9ffba2cba345d0078eb8b8db33249f81840aCraig Corneliusstatic inline int32_t 576b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste QueruisYehHamzaChar(UChar ch) { 577b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if((ch==0xFE89)||(ch==0xFE8A)){ 578b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return 1; 579b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru }else{ 580b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return 0; 581b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 582103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius} 583b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 584103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius /* 585b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * Name: isTashkeelOnTatweelChar 586103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * Function: Checks if the Tashkeel Character is on Tatweel or not,if the 587103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * Tashkeel on tatweel (FE range), it returns 1 else if the 588103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * Tashkeel with shadda on tatweel (FC range)return 2 otherwise 589b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * returns 0 590b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru */ 591103e9ffba2cba345d0078eb8b8db33249f81840aCraig Corneliusstatic inline int32_t 592b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste QueruisTashkeelOnTatweelChar(UChar ch){ 593b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(ch >= 0xfe70 && ch <= 0xfe7f && ch != NEW_TAIL_CHAR && ch != 0xFE75 && ch != SHADDA_TATWEEL_CHAR) 594b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru { 595b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return tashkeelMedial [ch - 0xFE70]; 596b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru }else if( (ch >= 0xfcf2 && ch <= 0xfcf4) || (ch == SHADDA_TATWEEL_CHAR)) { 597b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return 2; 598b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru }else{ 599b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return 0; 600b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 601b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru} 602b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 603b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru/* 604b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * Name: isIsolatedTashkeelChar 605103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * Function: Checks if the Tashkeel Character is in the isolated form 606103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * (i.e. Unicode FE range) returns 1 else if the Tashkeel 607b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * with shadda is in the isolated form (i.e. Unicode FC range) 608b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * returns 2 otherwise returns 0 609b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru */ 610103e9ffba2cba345d0078eb8b8db33249f81840aCraig Corneliusstatic inline int32_t 611b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste QueruisIsolatedTashkeelChar(UChar ch){ 612b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(ch >= 0xfe70 && ch <= 0xfe7f && ch != NEW_TAIL_CHAR && ch != 0xFE75){ 613b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return (1 - tashkeelMedial [ch - 0xFE70]); 614b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru }else if(ch >= 0xfc5e && ch <= 0xfc63){ 615b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return 1; 616b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru }else{ 617b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return 0; 618b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 619b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru} 620b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 621b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 622b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 623b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 624b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/* 625b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *Name : calculateSize 626103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius *Function : This function calculates the destSize to be used in preflighting 627b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * when the destSize is equal to 0 628103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * It is used also to calculate the new destsize in case the 629b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * destination buffer will be resized. 630b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 631b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 632b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic int32_t 633b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QuerucalculateSize(const UChar *source, int32_t sourceLength, 634103e9ffba2cba345d0078eb8b8db33249f81840aCraig Corneliusint32_t destSize,uint32_t options) { 635b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t i = 0; 636103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 637b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru int lamAlefOption = 0; 638b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru int tashkeelOption = 0; 639b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 640b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru destSize = sourceLength; 641103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 642b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if (((options&U_SHAPE_LETTERS_MASK) == U_SHAPE_LETTERS_SHAPE || 643b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru ((options&U_SHAPE_LETTERS_MASK) == U_SHAPE_LETTERS_SHAPE_TASHKEEL_ISOLATED )) && 644b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru ((options&U_SHAPE_LAMALEF_MASK) == U_SHAPE_LAMALEF_RESIZE )){ 645b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru lamAlefOption = 1; 646b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 647b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if((options&U_SHAPE_LETTERS_MASK) == U_SHAPE_LETTERS_SHAPE && 648b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru ((options&U_SHAPE_TASHKEEL_MASK) == U_SHAPE_TASHKEEL_RESIZE ) ){ 649b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru tashkeelOption = 1; 650b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 651103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 652b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(lamAlefOption || tashkeelOption){ 653b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if((options&U_SHAPE_TEXT_DIRECTION_MASK)==U_SHAPE_TEXT_DIRECTION_VISUAL_LTR) { 654b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru for(i=0;i<sourceLength;i++) { 655b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if( ((isAlefChar(source[i]))&& (i<(sourceLength-1)) &&(source[i+1] == LAM_CHAR)) || (isTashkeelCharFE(source[i])) ) { 656b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru destSize--; 657b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 658b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 659b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru }else if((options&U_SHAPE_TEXT_DIRECTION_MASK)==U_SHAPE_TEXT_DIRECTION_LOGICAL) { 660b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru for(i=0;i<sourceLength;i++) { 661b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if( ( (source[i] == LAM_CHAR) && (i<(sourceLength-1)) && (isAlefChar(source[i+1]))) || (isTashkeelCharFE(source[i])) ) { 662b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru destSize--; 663b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 664b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 665b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 666b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 667103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 668b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if ((options&U_SHAPE_LETTERS_MASK) == U_SHAPE_LETTERS_UNSHAPE){ 669b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if ( (options&U_SHAPE_LAMALEF_MASK) == U_SHAPE_LAMALEF_RESIZE){ 670b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru for(i=0;i<sourceLength;i++) { 671b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(isLamAlefChar(source[i])) 672b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru destSize++; 673b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 674b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 675b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 676b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 677b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return destSize; 678b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 679b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 680b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/* 681b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru *Name : handleTashkeelWithTatweel 682103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius *Function : Replaces Tashkeel as following: 683103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * Case 1 :if the Tashkeel on tatweel, replace it with Tatweel. 684103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * Case 2 :if the Tashkeel aggregated with Shadda on Tatweel, replace 685b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * it with Shadda on Tatweel. 686b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * Case 3: if the Tashkeel is isolated replace it with Space. 687b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * 688b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru */ 689b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Querustatic int32_t 690b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste QueruhandleTashkeelWithTatweel(UChar *dest, int32_t sourceLength, 691103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius int32_t /*destSize*/, uint32_t /*options*/, 692103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius UErrorCode * /*pErrorCode*/) { 693b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru int i; 694b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru for(i = 0; i < sourceLength; i++){ 695b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if((isTashkeelOnTatweelChar(dest[i]) == 1)){ 696b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru dest[i] = TATWEEL_CHAR; 697b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru }else if((isTashkeelOnTatweelChar(dest[i]) == 2)){ 698b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru dest[i] = SHADDA_TATWEEL_CHAR; 699b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru }else if(isIsolatedTashkeelChar(dest[i]) && dest[i] != SHADDA_CHAR){ 700b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru dest[i] = SPACE_CHAR; 701b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 702b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 703b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return sourceLength; 704b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru} 705b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 706b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 707b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 708b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru/* 709b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru *Name : handleGeneratedSpaces 710b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *Function : The shapeUnicode function converts Lam + Alef into LamAlef + space, 711103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * and Tashkeel to space. 712103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * handleGeneratedSpaces function puts these generated spaces 713b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * according to the options the user specifies. LamAlef and Tashkeel 714103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * spaces can be replaced at begin, at end, at near or decrease the 715b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * buffer size. 716b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * 717b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * There is also Auto option for LamAlef and tashkeel, which will put 718103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * the spaces at end of the buffer (or end of text if the user used 719b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * the option U_SHAPE_SPACES_RELATIVE_TO_TEXT_BEGIN_END). 720b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * 721103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * If the text type was visual_LTR and the option 722103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * U_SHAPE_SPACES_RELATIVE_TO_TEXT_BEGIN_END was selected the END 723b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * option will place the space at the beginning of the buffer and 724103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * BEGIN will place the space at the end of the buffer. 725b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 726b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 727b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic int32_t 728b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste QueruhandleGeneratedSpaces(UChar *dest, int32_t sourceLength, 729b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t destSize, 73059d709d503bab6e2b61931737e662dd293b40578ccornelius uint32_t options, 73154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UErrorCode *pErrorCode,struct uShapeVariables shapeVars ) { 732b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 733b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t i = 0, j = 0; 734b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t count = 0; 735b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar *tempbuffer=NULL; 736b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 737b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru int lamAlefOption = 0; 738b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru int tashkeelOption = 0; 739b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru int shapingMode = SHAPE_MODE; 740b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 741b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if (shapingMode == 0){ 742b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if ( (options&U_SHAPE_LAMALEF_MASK) == U_SHAPE_LAMALEF_RESIZE ){ 743b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru lamAlefOption = 1; 744b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 745b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if ( (options&U_SHAPE_TASHKEEL_MASK) == U_SHAPE_TASHKEEL_RESIZE ){ 746b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru tashkeelOption = 1; 747b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 748b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 749b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 75054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius tempbuffer = (UChar *)uprv_malloc((sourceLength+1)*U_SIZEOF_UCHAR); 75154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius /* Test for NULL */ 75254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if(tempbuffer == NULL) { 75354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius *pErrorCode = U_MEMORY_ALLOCATION_ERROR; 75454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius return 0; 75554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius } 756b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 75754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius 75854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if (lamAlefOption || tashkeelOption){ 759b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uprv_memset(tempbuffer, 0, (sourceLength+1)*U_SIZEOF_UCHAR); 760b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 761b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru i = j = 0; count = 0; 762b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru while(i < sourceLength) { 763b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if ( (lamAlefOption && dest[i] == LAMALEF_SPACE_SUB) || 764103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius (tashkeelOption && dest[i] == TASHKEEL_SPACE_SUB) ){ 765b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru j--; 766b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru count++; 767b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } else { 768b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru tempbuffer[j] = dest[i]; 769b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 770b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru i++; 771b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru j++; 772b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 773b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 774b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru while(count >= 0) { 775b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru tempbuffer[i] = 0x0000; 776b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru i--; 777b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru count--; 778b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 779b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 780b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uprv_memcpy(dest, tempbuffer, sourceLength*U_SIZEOF_UCHAR); 781b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru destSize = u_strlen(dest); 782b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 783b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 784b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru lamAlefOption = 0; 785b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 786b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if (shapingMode == 0){ 78759d709d503bab6e2b61931737e662dd293b40578ccornelius if ( (options&U_SHAPE_LAMALEF_MASK) == U_SHAPE_LAMALEF_NEAR ){ 788b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru lamAlefOption = 1; 789b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 790b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 791103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 792b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if (lamAlefOption){ 793b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* Lam+Alef is already shaped into LamAlef + FFFF */ 794b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru i = 0; 795b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru while(i < sourceLength) { 796b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(lamAlefOption&&dest[i] == LAMALEF_SPACE_SUB){ 797b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru dest[i] = SPACE_CHAR; 798b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 799b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru i++; 800b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 801b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru destSize = sourceLength; 802b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 803b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru lamAlefOption = 0; 804b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru tashkeelOption = 0; 805b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 806b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if (shapingMode == 0) { 80754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if ( ((options&U_SHAPE_LAMALEF_MASK) == shapeVars.uShapeLamalefBegin) || 808b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru (((options&U_SHAPE_LAMALEF_MASK) == U_SHAPE_LAMALEF_AUTO ) 80954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius && (shapeVars.spacesRelativeToTextBeginEnd==1)) ) { 810b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru lamAlefOption = 1; 811b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 81254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if ( (options&U_SHAPE_TASHKEEL_MASK) == shapeVars.uShapeTashkeelBegin ) { 813b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru tashkeelOption = 1; 814b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 815b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 816b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 817b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(lamAlefOption || tashkeelOption){ 818b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uprv_memset(tempbuffer, 0, (sourceLength+1)*U_SIZEOF_UCHAR); 81954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius 820b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru i = j = sourceLength; count = 0; 82154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius 822b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru while(i >= 0) { 823b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if ( (lamAlefOption && dest[i] == LAMALEF_SPACE_SUB) || 824b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru (tashkeelOption && dest[i] == TASHKEEL_SPACE_SUB) ){ 825b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru j++; 826b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru count++; 827b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru }else { 828b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru tempbuffer[j] = dest[i]; 829b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 830b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru i--; 831b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru j--; 832b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 833103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 834b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru for(i=0 ;i < count; i++){ 835b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru tempbuffer[i] = SPACE_CHAR; 836b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 837103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 838b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uprv_memcpy(dest, tempbuffer, sourceLength*U_SIZEOF_UCHAR); 839b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru destSize = sourceLength; 840b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 841b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 84227f654740f2a26ad62a5c155af9199af9e69b889claireho 84327f654740f2a26ad62a5c155af9199af9e69b889claireho 844b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru lamAlefOption = 0; 845b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru tashkeelOption = 0; 846b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 847b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if (shapingMode == 0) { 84854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if ( ((options&U_SHAPE_LAMALEF_MASK) == shapeVars.uShapeLamalefEnd) || 849b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru (((options&U_SHAPE_LAMALEF_MASK) == U_SHAPE_LAMALEF_AUTO ) 85054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius && (shapeVars.spacesRelativeToTextBeginEnd==0)) ) { 851b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru lamAlefOption = 1; 852b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 85354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if ( (options&U_SHAPE_TASHKEEL_MASK) == shapeVars.uShapeTashkeelEnd ){ 854b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru tashkeelOption = 1; 855b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 856b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 857103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 858b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(lamAlefOption || tashkeelOption){ 859b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uprv_memset(tempbuffer, 0, (sourceLength+1)*U_SIZEOF_UCHAR); 860b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 861b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru i = j = 0; count = 0; 862b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru while(i < sourceLength) { 863b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if ( (lamAlefOption && dest[i] == LAMALEF_SPACE_SUB) || 864b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru (tashkeelOption && dest[i] == TASHKEEL_SPACE_SUB) ){ 865b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru j--; 866b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru count++; 867b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru }else { 868b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru tempbuffer[j] = dest[i]; 869b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 870b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru i++; 871b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru j++; 872b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 873b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 874b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru while(count >= 0) { 875b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru tempbuffer[i] = SPACE_CHAR; 876b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru i--; 877b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru count--; 878b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 879b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 880b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uprv_memcpy(dest,tempbuffer, sourceLength*U_SIZEOF_UCHAR); 881b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru destSize = sourceLength; 882b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 883b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 884103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 885b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(tempbuffer){ 886b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uprv_free(tempbuffer); 887b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 888b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 889b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return destSize; 890b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 891b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 892b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/* 893b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru *Name :expandCompositCharAtBegin 894b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru *Function :Expands the LamAlef character to Lam and Alef consuming the required 895103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * space from beginning of the buffer. If the text type was visual_LTR 896b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * and the option U_SHAPE_SPACES_RELATIVE_TO_TEXT_BEGIN_END was selected 897b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * the spaces will be located at end of buffer. 898b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * If there are no spaces to expand the LamAlef, an error 899103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * will be set to U_NO_SPACE_AVAILABLE as defined in utypes.h 900b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 901b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 902b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Querustatic int32_t 903b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste QueruexpandCompositCharAtBegin(UChar *dest, int32_t sourceLength, int32_t destSize,UErrorCode *pErrorCode) { 904b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t i = 0,j = 0; 905b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t countl = 0; 906b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar *tempbuffer=NULL; 907103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 908b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru tempbuffer = (UChar *)uprv_malloc((sourceLength+1)*U_SIZEOF_UCHAR); 909b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 910b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* Test for NULL */ 911b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(tempbuffer == NULL) { 912b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru *pErrorCode = U_MEMORY_ALLOCATION_ERROR; 913b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return 0; 914b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 915b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 916b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uprv_memset(tempbuffer, 0, (sourceLength+1)*U_SIZEOF_UCHAR); 917b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 918b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru i = 0; 919b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru while(dest[i] == SPACE_CHAR) { 920b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru countl++; 921b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru i++; 922b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 923b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 924b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru i = j = sourceLength-1; 925103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 926b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru while(i >= 0 && j >= 0) { 927b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if( countl>0 && isLamAlefChar(dest[i])) { 928b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru tempbuffer[j] = LAM_CHAR; 929103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius /* to ensure the array index is within the range */ 930103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius U_ASSERT(dest[i] >= 0xFEF5u 931103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius && dest[i]-0xFEF5u < sizeof(convertLamAlef)/sizeof(convertLamAlef[0])); 932b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru tempbuffer[j-1] = convertLamAlef[ dest[i] - 0xFEF5 ]; 933b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru j--; 934b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru countl--; 935b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru }else { 936b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if( countl == 0 && isLamAlefChar(dest[i]) ) { 937b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *pErrorCode=U_NO_SPACE_AVAILABLE; 938b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 939b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru tempbuffer[j] = dest[i]; 940b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 941b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru i--; 942b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru j--; 943b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 944b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uprv_memcpy(dest, tempbuffer, sourceLength*U_SIZEOF_UCHAR); 945103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 946b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru uprv_free(tempbuffer); 947103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 948b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru destSize = sourceLength; 949b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return destSize; 950b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru} 951b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 952b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru/* 953b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru *Name : expandCompositCharAtEnd 954103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius *Function : Expands the LamAlef character to Lam and Alef consuming the 955b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * required space from end of the buffer. If the text type was 956b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * Visual LTR and the option U_SHAPE_SPACES_RELATIVE_TO_TEXT_BEGIN_END 957103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * was used, the spaces will be consumed from begin of buffer. If 958b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * there are no spaces to expand the LamAlef, an error 959103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * will be set to U_NO_SPACE_AVAILABLE as defined in utypes.h 960b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru */ 961b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 962b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Querustatic int32_t 963b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste QueruexpandCompositCharAtEnd(UChar *dest, int32_t sourceLength, int32_t destSize,UErrorCode *pErrorCode) { 964b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru int32_t i = 0,j = 0; 965b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 966b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru int32_t countr = 0; 967b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru int32_t inpsize = sourceLength; 968b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 969b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru UChar *tempbuffer=NULL; 970b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru tempbuffer = (UChar *)uprv_malloc((sourceLength+1)*U_SIZEOF_UCHAR); 971b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 972b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* Test for NULL */ 973b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(tempbuffer == NULL) { 974b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru *pErrorCode = U_MEMORY_ALLOCATION_ERROR; 975b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return 0; 976b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 977103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 978b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru uprv_memset(tempbuffer, 0, (sourceLength+1)*U_SIZEOF_UCHAR); 979103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 980b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru while(dest[inpsize-1] == SPACE_CHAR) { 981b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru countr++; 982b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru inpsize--; 983b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 984103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 985b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru i = sourceLength - countr - 1; 986b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru j = sourceLength - 1; 987103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 988b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru while(i >= 0 && j >= 0) { 989b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if( countr>0 && isLamAlefChar(dest[i]) ) { 990b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru tempbuffer[j] = LAM_CHAR; 991b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru tempbuffer[j-1] = convertLamAlef[ dest[i] - 0xFEF5 ]; 992b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru j--; 993b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru countr--; 994b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru }else { 995b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if ((countr == 0) && isLamAlefChar(dest[i]) ) { 996b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru *pErrorCode=U_NO_SPACE_AVAILABLE; 997b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 998b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru tempbuffer[j] = dest[i]; 999b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 1000b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru i--; 1001b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru j--; 1002b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 1003103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 1004b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(countr > 0) { 1005b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru uprv_memmove(tempbuffer, tempbuffer+countr, sourceLength*U_SIZEOF_UCHAR); 1006b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(u_strlen(tempbuffer) < sourceLength) { 1007b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru for(i=sourceLength-1;i>=sourceLength-countr;i--) { 1008b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru tempbuffer[i] = SPACE_CHAR; 1009b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 1010b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 1011b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 1012b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru uprv_memcpy(dest, tempbuffer, sourceLength*U_SIZEOF_UCHAR); 1013b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1014b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru uprv_free(tempbuffer); 1015103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 1016b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru destSize = sourceLength; 1017b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return destSize; 1018b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru} 1019b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 1020b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru/* 1021b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru *Name : expandCompositCharAtNear 1022b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru *Function : Expands the LamAlef character into Lam + Alef, YehHamza character 1023103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * into Yeh + Hamza, SeenFamily character into SeenFamily character 1024103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * + Tail, while consuming the space next to the character. 1025b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * If there are no spaces next to the character, an error 1026103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * will be set to U_NO_SPACE_AVAILABLE as defined in utypes.h 1027b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru */ 1028b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 1029b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Querustatic int32_t 1030b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste QueruexpandCompositCharAtNear(UChar *dest, int32_t sourceLength, int32_t destSize,UErrorCode *pErrorCode, 103154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius int yehHamzaOption, int seenTailOption, int lamAlefOption, struct uShapeVariables shapeVars) { 1032b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru int32_t i = 0; 1033b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 1034b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 1035b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru UChar lamalefChar, yehhamzaChar; 1036b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1037b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru for(i = 0 ;i<=sourceLength-1;i++) { 1038b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if (seenTailOption && isSeenTailFamilyChar(dest[i])) { 1039b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if ((i>0) && (dest[i-1] == SPACE_CHAR) ) { 104054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius dest[i-1] = shapeVars.tailChar; 1041b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru }else { 1042b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru *pErrorCode=U_NO_SPACE_AVAILABLE; 1043b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1044b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru }else if(yehHamzaOption && (isYehHamzaChar(dest[i])) ) { 1045b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if ((i>0) && (dest[i-1] == SPACE_CHAR) ) { 1046b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru yehhamzaChar = dest[i]; 1047b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru dest[i] = yehHamzaToYeh[yehhamzaChar - YEH_HAMZAFE_CHAR]; 1048b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru dest[i-1] = HAMZAFE_CHAR; 1049b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru }else { 1050103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 1051b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru *pErrorCode=U_NO_SPACE_AVAILABLE; 1052b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 1053b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru }else if(lamAlefOption && isLamAlefChar(dest[i+1])) { 1054b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(dest[i] == SPACE_CHAR){ 1055b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru lamalefChar = dest[i+1]; 1056b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru dest[i+1] = LAM_CHAR; 1057b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru dest[i] = convertLamAlef[ lamalefChar - 0xFEF5 ]; 1058b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru }else { 1059b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru *pErrorCode=U_NO_SPACE_AVAILABLE; 1060b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1061b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1062b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 1063b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru destSize = sourceLength; 1064b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return destSize; 1065b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru} 1066103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius /* 1067b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * Name : expandCompositChar 1068103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * Function : LamAlef, need special handling, since it expands from one 1069103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * character into two characters while shaping or deshaping. 1070b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * In order to expand it, near or far spaces according to the 1071b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * options user specifies. Also buffer size can be increased. 1072b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * 1073b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * For SeenFamily characters and YehHamza only the near option is 1074b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * supported, while for LamAlef we can take spaces from begin, end, 1075b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * near or even increase the buffer size. 1076103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * There is also the Auto option for LamAlef only, which will first 1077b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * search for a space at end, begin then near, respectively. 1078103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * If there are no spaces to expand these characters, an error will be set to 1079103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius * U_NO_SPACE_AVAILABLE as defined in utypes.h 1080b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru */ 1081103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 1082b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Querustatic int32_t 1083b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste QueruexpandCompositChar(UChar *dest, int32_t sourceLength, 1084103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius int32_t destSize,uint32_t options, 108554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UErrorCode *pErrorCode, int shapingMode,struct uShapeVariables shapeVars) { 1086b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1087b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru int32_t i = 0,j = 0; 1088b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 1089b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru UChar *tempbuffer=NULL; 1090b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru int yehHamzaOption = 0; 1091b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru int seenTailOption = 0; 1092b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru int lamAlefOption = 0; 1093103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 1094b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if (shapingMode == 1){ 1095b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if ( (options&U_SHAPE_LAMALEF_MASK) == U_SHAPE_LAMALEF_AUTO){ 1096103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 109754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if(shapeVars.spacesRelativeToTextBeginEnd == 0) { 1098b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru destSize = expandCompositCharAtEnd(dest, sourceLength, destSize, pErrorCode); 1099103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 1100b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(*pErrorCode == U_NO_SPACE_AVAILABLE) { 1101b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru *pErrorCode = U_ZERO_ERROR; 1102b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru destSize = expandCompositCharAtBegin(dest, sourceLength, destSize, pErrorCode); 1103b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 1104b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru }else { 1105b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru destSize = expandCompositCharAtBegin(dest, sourceLength, destSize, pErrorCode); 1106103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 1107b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(*pErrorCode == U_NO_SPACE_AVAILABLE) { 1108b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru *pErrorCode = U_ZERO_ERROR; 1109b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru destSize = expandCompositCharAtEnd(dest, sourceLength, destSize, pErrorCode); 1110b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1111b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1112103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 1113b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(*pErrorCode == U_NO_SPACE_AVAILABLE) { 1114b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru *pErrorCode = U_ZERO_ERROR; 1115103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius destSize = expandCompositCharAtNear(dest, sourceLength, destSize, pErrorCode, yehHamzaOption, 111654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius seenTailOption, 1,shapeVars); 1117b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 1118b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 1119b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 1120b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1121b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if (shapingMode == 1){ 112254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if ( (options&U_SHAPE_LAMALEF_MASK) == shapeVars.uShapeLamalefEnd){ 1123b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru destSize = expandCompositCharAtEnd(dest, sourceLength, destSize, pErrorCode); 1124b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 1125b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 1126b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1127b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if (shapingMode == 1){ 112854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if ( (options&U_SHAPE_LAMALEF_MASK) == shapeVars.uShapeLamalefBegin){ 1129b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru destSize = expandCompositCharAtBegin(dest, sourceLength, destSize, pErrorCode); 1130b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 1131b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 1132103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 1133b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if (shapingMode == 0){ 1134b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if ((options&U_SHAPE_YEHHAMZA_MASK) == U_SHAPE_YEHHAMZA_TWOCELL_NEAR){ 1135b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru yehHamzaOption = 1; 1136b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 1137b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if ((options&U_SHAPE_SEEN_MASK) == U_SHAPE_SEEN_TWOCELL_NEAR){ 1138b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru seenTailOption = 1; 1139b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 1140b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 1141b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if (shapingMode == 1) { 1142b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if ( (options&U_SHAPE_LAMALEF_MASK) == U_SHAPE_LAMALEF_NEAR) { 1143b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru lamAlefOption = 1; 1144b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 1145b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1146b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1147b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1148b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if (yehHamzaOption || seenTailOption || lamAlefOption){ 1149103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius destSize = expandCompositCharAtNear(dest, sourceLength, destSize, pErrorCode, yehHamzaOption, 115054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius seenTailOption,lamAlefOption,shapeVars); 1151b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 1152103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 1153103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 1154b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if (shapingMode == 1){ 1155b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if ( (options&U_SHAPE_LAMALEF_MASK) == U_SHAPE_LAMALEF_RESIZE){ 1156b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru destSize = calculateSize(dest,sourceLength,destSize,options); 1157b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru tempbuffer = (UChar *)uprv_malloc((destSize+1)*U_SIZEOF_UCHAR); 1158103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 1159b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* Test for NULL */ 1160b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(tempbuffer == NULL) { 1161b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru *pErrorCode = U_MEMORY_ALLOCATION_ERROR; 1162b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return 0; 1163b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 1164103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 1165b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru uprv_memset(tempbuffer, 0, (destSize+1)*U_SIZEOF_UCHAR); 1166103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 1167b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru i = j = 0; 1168b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru while(i < destSize && j < destSize) { 1169b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(isLamAlefChar(dest[i]) ) { 1170b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru tempbuffer[j] = convertLamAlef[ dest[i] - 0xFEF5 ]; 1171b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru tempbuffer[j+1] = LAM_CHAR; 1172b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru j++; 1173b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru }else { 1174b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru tempbuffer[j] = dest[i]; 1175b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 1176b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru i++; 1177b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru j++; 1178b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 1179103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 1180b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru uprv_memcpy(dest, tempbuffer, destSize*U_SIZEOF_UCHAR); 1181b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 1182b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 1183103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 1184b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(tempbuffer) { 1185b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru uprv_free(tempbuffer); 1186b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 1187b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return destSize; 1188b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 1189b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1190b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/* 1191b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *Name : shapeUnicode 1192b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *Function : Converts an Arabic Unicode buffer in 06xx Range into a shaped 1193b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * arabic Unicode buffer in FExx Range 1194b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 1195b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic int32_t 1196b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QuerushapeUnicode(UChar *dest, int32_t sourceLength, 1197103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius int32_t destSize,uint32_t options, 1198b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UErrorCode *pErrorCode, 119954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius int tashkeelFlag, struct uShapeVariables shapeVars) { 1200b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1201b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t i, iend; 1202b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t step; 1203b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t lastPos,Nx, Nw; 1204b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru unsigned int Shape; 1205b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t lamalef_found = 0; 1206b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru int32_t seenfamFound = 0, yehhamzaFound =0, tashkeelFound = 0; 1207b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar prevLink = 0, lastLink = 0, currLink, nextLink = 0; 1208b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar wLamalef; 1209b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1210b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* 1211b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Converts the input buffer from FExx Range into 06xx Range 1212b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * to make sure that all characters are in the 06xx range 1213b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * even the lamalef is converted to the special region in 1214b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * the 06xx range 1215b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 1216b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if ((options & U_SHAPE_PRESERVE_PRESENTATION_MASK) == U_SHAPE_PRESERVE_PRESENTATION_NOOP) { 1217b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru for (i = 0; i < sourceLength; i++) { 1218b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar inputChar = dest[i]; 1219b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if ( (inputChar >= 0xFB50) && (inputChar <= 0xFBFF)) { 1220b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar c = convertFBto06 [ (inputChar - 0xFB50) ]; 1221b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (c != 0) 1222b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru dest[i] = c; 1223b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else if ( (inputChar >= 0xFE70) && (inputChar <= 0xFEFC)) { 1224b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru dest[i] = convertFEto06 [ (inputChar - 0xFE70) ] ; 1225b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else { 1226b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru dest[i] = inputChar ; 1227b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1228b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1229b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1230b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1231b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 1232b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* sets the index to the end of the buffer, together with the step point to -1 */ 1233b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru i = sourceLength - 1; 1234b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru iend = -1; 1235b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru step = -1; 1236b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1237b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* 1238b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * This function resolves the link between the characters . 1239b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Arabic characters have four forms : 1240b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Isolated Form, Initial Form, Middle Form and Final Form 1241b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 1242b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru currLink = getLink(dest[i]); 1243b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1244b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru lastPos = i; 1245b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru Nx = -2, Nw = 0; 1246b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1247b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru while (i != iend) { 1248b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* If high byte of currLink > 0 then more than one shape */ 1249b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if ((currLink & 0xFF00) > 0 || (getLink(dest[i]) & IRRELEVANT) != 0) { 1250b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru Nw = i + step; 1251b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru while (Nx < 0) { /* we need to know about next char */ 1252b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(Nw == iend) { 1253b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru nextLink = 0; 1254b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru Nx = 3000; 1255b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else { 1256b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru nextLink = getLink(dest[Nw]); 1257b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if((nextLink & IRRELEVANT) == 0) { 1258b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru Nx = Nw; 1259b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else { 1260b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru Nw = Nw + step; 1261b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1262b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1263b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1264b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1265b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if ( ((currLink & ALEFTYPE) > 0) && ((lastLink & LAMTYPE) > 0) ) { 1266b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru lamalef_found = 1; 1267b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru wLamalef = changeLamAlef(dest[i]); /*get from 0x065C-0x065f */ 1268b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if ( wLamalef != 0) { 1269b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru dest[i] = LAMALEF_SPACE_SUB; /* The default case is to drop the Alef and replace */ 1270b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru dest[lastPos] =wLamalef; /* it by LAMALEF_SPACE_SUB which is the last character in the */ 1271b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru i=lastPos; /* unicode private use area, this is done to make */ 1272b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } /* sure that removeLamAlefSpaces() handles only the */ 1273b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru lastLink = prevLink; /* spaces generated during lamalef generation. */ 1274b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru currLink = getLink(wLamalef); /* LAMALEF_SPACE_SUB is added here and is replaced by spaces */ 1275b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } /* in removeLamAlefSpaces() */ 1276103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 127754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if ((i > 0) && (dest[i-1] == SPACE_CHAR)){ 127854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if ( isSeenFamilyChar(dest[i])) { 1279b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru seenfamFound = 1; 1280b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } else if (dest[i] == YEH_HAMZA_CHAR) { 1281b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru yehhamzaFound = 1; 1282b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 128354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius } 128454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius else if(i==0){ 128554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if ( isSeenFamilyChar(dest[i])){ 1286b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru seenfamFound = 1; 1287b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } else if (dest[i] == YEH_HAMZA_CHAR) { 1288b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru yehhamzaFound = 1; 1289b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 129054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius } 1291b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 1292103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius /* 1293b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * get the proper shape according to link ability of neighbors 1294b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * and of character; depends on the order of the shapes 1295b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * (isolated, initial, middle, final) in the compatibility area 1296b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 1297b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru Shape = shapeTable[nextLink & (LINKR + LINKL)] 1298b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru [lastLink & (LINKR + LINKL)] 1299103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius [currLink & (LINKR + LINKL)]; 1300b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1301b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if ((currLink & (LINKR+LINKL)) == 1) { 1302b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru Shape &= 1; 1303b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else if(isTashkeelChar(dest[i])) { 1304b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if( (lastLink & LINKL) && (nextLink & LINKR) && (tashkeelFlag == 1) && 1305b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru dest[i] != 0x064C && dest[i] != 0x064D ) 1306b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 1307103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius Shape = 1; 1308b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if( (nextLink&ALEFTYPE) == ALEFTYPE && (lastLink&LAMTYPE) == LAMTYPE ) { 1309103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius Shape = 0; 1310b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 131154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius } else if(tashkeelFlag == 2 && dest[i] == SHADDA06_CHAR){ 131254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius Shape = 1; 131354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius } else { 1314b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru Shape = 0; 1315b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1316b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1317b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if ((dest[i] ^ 0x0600) < 0x100) { 1318b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if ( isTashkeelChar(dest[i]) ){ 131954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if (tashkeelFlag == 2 && dest[i] != SHADDA06_CHAR){ 1320b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru dest[i] = TASHKEEL_SPACE_SUB; 1321b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru tashkeelFound = 1; 1322103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius } else { 1323103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius /* to ensure the array index is within the range */ 1324103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius U_ASSERT(dest[i] >= 0x064Bu 1325103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius && dest[i]-0x064Bu < sizeof(IrrelevantPos)/sizeof(IrrelevantPos[0])); 1326103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius dest[i] = 0xFE70 + IrrelevantPos[(dest[i] - 0x064B)] + Shape; 1327b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 1328b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru }else if ((currLink & APRESENT) > 0) { 1329b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru dest[i] = (UChar)(0xFB50 + (currLink >> 8) + Shape); 1330b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru }else if ((currLink >> 8) > 0 && (currLink & IRRELEVANT) == 0) { 1331b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru dest[i] = (UChar)(0xFE70 + (currLink >> 8) + Shape); 1332b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 1333b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1334b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1335b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1336b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* move one notch forward */ 1337b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if ((currLink & IRRELEVANT) == 0) { 1338b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru prevLink = lastLink; 1339b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru lastLink = currLink; 1340b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru lastPos = i; 1341b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1342b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1343b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru i = i + step; 1344b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (i == Nx) { 1345b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru currLink = nextLink; 1346b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru Nx = -2; 1347b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else if(i != iend) { 1348b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru currLink = getLink(dest[i]); 1349b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1350b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1351b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru destSize = sourceLength; 1352b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if ( (lamalef_found != 0 ) || (tashkeelFound != 0) ){ 135354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius destSize = handleGeneratedSpaces(dest,sourceLength,destSize,options,pErrorCode, shapeVars); 1354b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 1355b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1356b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if ( (seenfamFound != 0) || (yehhamzaFound != 0) ) { 135754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius destSize = expandCompositChar(dest, sourceLength,destSize,options,pErrorCode, SHAPE_MODE,shapeVars); 1358b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 1359b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return destSize; 1360b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 1361b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1362b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/* 1363b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *Name : deShapeUnicode 1364b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *Function : Converts an Arabic Unicode buffer in FExx Range into unshaped 1365b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * arabic Unicode buffer in 06xx Range 1366b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 1367b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic int32_t 1368b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QuerudeShapeUnicode(UChar *dest, int32_t sourceLength, 1369103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius int32_t destSize,uint32_t options, 137054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UErrorCode *pErrorCode, struct uShapeVariables shapeVars) { 1371b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t i = 0; 1372b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t lamalef_found = 0; 1373b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru int32_t yehHamzaComposeEnabled = 0; 1374b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru int32_t seenComposeEnabled = 0; 1375b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 1376b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru yehHamzaComposeEnabled = ((options&U_SHAPE_YEHHAMZA_MASK) == U_SHAPE_YEHHAMZA_TWOCELL_NEAR) ? 1 : 0; 1377b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru seenComposeEnabled = ((options&U_SHAPE_SEEN_MASK) == U_SHAPE_SEEN_TWOCELL_NEAR)? 1 : 0; 1378b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1379b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* 1380b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *This for loop changes the buffer from the Unicode FE range to 1381b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *the Unicode 06 range 1382b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 1383103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 1384b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru for(i = 0; i < sourceLength; i++) { 1385b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar inputChar = dest[i]; 1386b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if ( (inputChar >= 0xFB50) && (inputChar <= 0xFBFF)) { /* FBxx Arabic range */ 1387b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar c = convertFBto06 [ (inputChar - 0xFB50) ]; 1388b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (c != 0) 1389b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru dest[i] = c; 1390103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius } else if( (yehHamzaComposeEnabled == 1) && ((inputChar == HAMZA06_CHAR) || (inputChar == HAMZAFE_CHAR)) 1391b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru && (i < (sourceLength - 1)) && isAlefMaksouraChar(dest[i+1] )) { 1392b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru dest[i] = SPACE_CHAR; 1393b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru dest[i+1] = YEH_HAMZA_CHAR; 1394103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius } else if ( (seenComposeEnabled == 1) && (isTailChar(inputChar)) && (i< (sourceLength - 1)) 1395b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru && (isSeenTailFamilyChar(dest[i+1])) ) { 1396b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru dest[i] = SPACE_CHAR; 1397b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else if (( inputChar >= 0xFE70) && (inputChar <= 0xFEF4 )) { /* FExx Arabic range */ 1398b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru dest[i] = convertFEto06 [ (inputChar - 0xFE70) ]; 1399b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else { 1400b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru dest[i] = inputChar ; 1401b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1402b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 1403b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if( isLamAlefChar(dest[i]) ) 1404b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru lamalef_found = 1; 1405b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1406103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 1407b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru destSize = sourceLength; 1408b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if (lamalef_found != 0){ 140954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius destSize = expandCompositChar(dest,sourceLength,destSize,options,pErrorCode,DESHAPE_MODE, shapeVars); 1410b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 1411b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return destSize; 1412b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 1413b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1414103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius/* 1415b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru **************************************** 1416b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * u_shapeArabic 1417b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru **************************************** 1418103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius */ 1419b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 1420b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruU_CAPI int32_t U_EXPORT2 1421b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruu_shapeArabic(const UChar *source, int32_t sourceLength, 1422b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar *dest, int32_t destCapacity, 142359d709d503bab6e2b61931737e662dd293b40578ccornelius uint32_t options, 142427f654740f2a26ad62a5c155af9199af9e69b889claireho UErrorCode *pErrorCode) { 1425b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1426b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t destLength; 142754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius struct uShapeVariables shapeVars = { OLD_TAIL_CHAR,U_SHAPE_LAMALEF_BEGIN,U_SHAPE_LAMALEF_END,U_SHAPE_TASHKEEL_BEGIN,U_SHAPE_TASHKEEL_END,0}; 1428b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1429b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* usual error checking */ 1430b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) { 1431b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return 0; 1432b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1433b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1434b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* make sure that no reserved options values are used; allow dest==NULL only for preflighting */ 1435b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if( source==NULL || sourceLength<-1 || (dest==NULL && destCapacity!=0) || destCapacity<0 || 1436b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru (((options&U_SHAPE_TASHKEEL_MASK) > 0) && 1437b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru ((options&U_SHAPE_LETTERS_SHAPE_TASHKEEL_ISOLATED) == U_SHAPE_LETTERS_SHAPE_TASHKEEL_ISOLATED) ) || 1438b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru (((options&U_SHAPE_TASHKEEL_MASK) > 0) && 1439b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru ((options&U_SHAPE_LETTERS_MASK) == U_SHAPE_LETTERS_UNSHAPE)) || 1440b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru (options&U_SHAPE_DIGIT_TYPE_RESERVED)==U_SHAPE_DIGIT_TYPE_RESERVED || 1441b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru (options&U_SHAPE_DIGITS_MASK)==U_SHAPE_DIGITS_RESERVED || 1442b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru ((options&U_SHAPE_LAMALEF_MASK) != U_SHAPE_LAMALEF_RESIZE && 1443b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru (options&U_SHAPE_AGGREGATE_TASHKEEL_MASK) != 0) || 1444b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru ((options&U_SHAPE_AGGREGATE_TASHKEEL_MASK) == U_SHAPE_AGGREGATE_TASHKEEL && 1445b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru (options&U_SHAPE_LETTERS_SHAPE_TASHKEEL_ISOLATED) != U_SHAPE_LETTERS_SHAPE_TASHKEEL_ISOLATED) 1446103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius ) 1447b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru { 1448b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; 1449b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return 0; 1450b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 145154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius /* Validate lamalef options */ 145254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if(((options&U_SHAPE_LAMALEF_MASK) > 0)&& 1453b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru !(((options & U_SHAPE_LAMALEF_MASK)==U_SHAPE_LAMALEF_BEGIN) || 1454b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru ((options & U_SHAPE_LAMALEF_MASK)==U_SHAPE_LAMALEF_END ) || 1455b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru ((options & U_SHAPE_LAMALEF_MASK)==U_SHAPE_LAMALEF_RESIZE )|| 1456b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru ((options & U_SHAPE_LAMALEF_MASK)==U_SHAPE_LAMALEF_AUTO) || 1457b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru ((options & U_SHAPE_LAMALEF_MASK)==U_SHAPE_LAMALEF_NEAR))) 145854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius { 145954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; 1460b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return 0; 146154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius } 146254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius /* Validate Tashkeel options */ 146354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if(((options&U_SHAPE_TASHKEEL_MASK) > 0)&& 1464b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru !(((options & U_SHAPE_TASHKEEL_MASK)==U_SHAPE_TASHKEEL_BEGIN) || 1465b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru ((options & U_SHAPE_TASHKEEL_MASK)==U_SHAPE_TASHKEEL_END ) 1466b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru ||((options & U_SHAPE_TASHKEEL_MASK)==U_SHAPE_TASHKEEL_RESIZE )|| 146754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius ((options & U_SHAPE_TASHKEEL_MASK)==U_SHAPE_TASHKEEL_REPLACE_BY_TATWEEL))) 146854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius { 146954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; 1470b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return 0; 147154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius } 1472b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* determine the source length */ 1473b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(sourceLength==-1) { 1474b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru sourceLength=u_strlen(source); 1475b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1476b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(sourceLength<=0) { 1477b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return u_terminateUChars(dest, destCapacity, 0, pErrorCode); 1478b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1479b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1480b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* check that source and destination do not overlap */ 1481b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if( dest!=NULL && 1482b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru ((source<=dest && dest<source+sourceLength) || 1483b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru (dest<=source && source<dest+destCapacity))) { 1484b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; 1485b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return 0; 1486b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1487103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 1488b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* Does Options contain the new Seen Tail Unicode code point option */ 1489b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if ( (options&U_SHAPE_TAIL_TYPE_MASK) == U_SHAPE_TAIL_NEW_UNICODE){ 149054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius shapeVars.tailChar = NEW_TAIL_CHAR; 1491b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru }else { 149254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius shapeVars.tailChar = OLD_TAIL_CHAR; 1493b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 1494b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1495b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if((options&U_SHAPE_LETTERS_MASK)!=U_SHAPE_LETTERS_NOOP) { 1496b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar buffer[300]; 1497b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar *tempbuffer, *tempsource = NULL; 1498b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t outputSize, spacesCountl=0, spacesCountr=0; 1499b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1500b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if((options&U_SHAPE_AGGREGATE_TASHKEEL_MASK)>0) { 1501b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t logical_order = (options&U_SHAPE_TEXT_DIRECTION_MASK) == U_SHAPE_TEXT_DIRECTION_LOGICAL; 1502103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius int32_t aggregate_tashkeel = 1503103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius (options&(U_SHAPE_AGGREGATE_TASHKEEL_MASK+U_SHAPE_LETTERS_SHAPE_TASHKEEL_ISOLATED)) == 1504b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru (U_SHAPE_AGGREGATE_TASHKEEL+U_SHAPE_LETTERS_SHAPE_TASHKEEL_ISOLATED); 1505b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int step=logical_order?1:-1; 1506b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int j=logical_order?-1:2*sourceLength; 1507b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int i=logical_order?-1:sourceLength; 1508b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int end=logical_order?sourceLength:-1; 1509b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int aggregation_possible = 1; 1510b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar prev = 0; 1511b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar prevLink, currLink = 0; 1512b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int newSourceLength = 0; 1513b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru tempsource = (UChar *)uprv_malloc(2*sourceLength*U_SIZEOF_UCHAR); 1514b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(tempsource == NULL) { 1515b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *pErrorCode = U_MEMORY_ALLOCATION_ERROR; 1516b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return 0; 1517b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1518b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1519b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru while ((i+=step) != end) { 1520b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru prevLink = currLink; 1521b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru currLink = getLink(source[i]); 1522b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (aggregate_tashkeel && ((prevLink|currLink)&COMBINE) == COMBINE && aggregation_possible) { 1523103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius aggregation_possible = 0; 1524b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru tempsource[j] = (prev<source[i]?prev:source[i])-0x064C+0xFC5E; 1525b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru currLink = getLink(tempsource[j]); 1526b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else { 1527b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru aggregation_possible = 1; 1528b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru tempsource[j+=step] = source[i]; 1529b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru prev = source[i]; 1530b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru newSourceLength++; 1531b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1532b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1533b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru source = tempsource+(logical_order?0:j); 1534b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru sourceLength = newSourceLength; 1535b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1536b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1537b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* calculate destination size */ 1538b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* TODO: do we ever need to do this pure preflighting? */ 1539103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius if(((options&U_SHAPE_LAMALEF_MASK)==U_SHAPE_LAMALEF_RESIZE) || 1540b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru ((options&U_SHAPE_TASHKEEL_MASK)==U_SHAPE_TASHKEEL_RESIZE)) { 1541b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru outputSize=calculateSize(source,sourceLength,destCapacity,options); 1542b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else { 1543b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru outputSize=sourceLength; 1544b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1545b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 1546b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(outputSize>destCapacity) { 1547b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *pErrorCode=U_BUFFER_OVERFLOW_ERROR; 1548b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (tempsource != NULL) uprv_free(tempsource); 1549b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return outputSize; 1550b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1551b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1552b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* 1553b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * need a temporary buffer of size max(outputSize, sourceLength) 1554b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * because at first we copy source->temp 1555b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 1556b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(sourceLength>outputSize) { 1557b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru outputSize=sourceLength; 1558b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1559b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1560b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* Start of Arabic letter shaping part */ 1561f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius if(outputSize<=UPRV_LENGTHOF(buffer)) { 1562f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius outputSize=UPRV_LENGTHOF(buffer); 1563b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru tempbuffer=buffer; 1564b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else { 1565b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru tempbuffer = (UChar *)uprv_malloc(outputSize*U_SIZEOF_UCHAR); 1566b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1567b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /*Test for NULL*/ 1568b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(tempbuffer == NULL) { 1569b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *pErrorCode = U_MEMORY_ALLOCATION_ERROR; 1570b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (tempsource != NULL) uprv_free(tempsource); 1571b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return 0; 1572b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1573b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1574b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uprv_memcpy(tempbuffer, source, sourceLength*U_SIZEOF_UCHAR); 1575b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if (tempsource != NULL){ 1576b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru uprv_free(tempsource); 1577b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 1578b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 1579b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(sourceLength<outputSize) { 1580b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uprv_memset(tempbuffer+sourceLength, 0, (outputSize-sourceLength)*U_SIZEOF_UCHAR); 1581b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1582b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1583b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if((options&U_SHAPE_TEXT_DIRECTION_MASK) == U_SHAPE_TEXT_DIRECTION_LOGICAL) { 1584b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru countSpaces(tempbuffer,sourceLength,options,&spacesCountl,&spacesCountr); 1585b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru invertBuffer(tempbuffer,sourceLength,options,spacesCountl,spacesCountr); 1586b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1587b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1588b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if((options&U_SHAPE_TEXT_DIRECTION_MASK) == U_SHAPE_TEXT_DIRECTION_VISUAL_LTR) { 1589b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if((options&U_SHAPE_SPACES_RELATIVE_TO_TEXT_MASK) == U_SHAPE_SPACES_RELATIVE_TO_TEXT_BEGIN_END) { 159054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius shapeVars.spacesRelativeToTextBeginEnd = 1; 159154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius shapeVars.uShapeLamalefBegin = U_SHAPE_LAMALEF_END; 159254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius shapeVars.uShapeLamalefEnd = U_SHAPE_LAMALEF_BEGIN; 159354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius shapeVars.uShapeTashkeelBegin = U_SHAPE_TASHKEEL_END; 159454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius shapeVars.uShapeTashkeelEnd = U_SHAPE_TASHKEEL_BEGIN; 1595b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 1596b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 1597b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 1598b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru switch(options&U_SHAPE_LETTERS_MASK) { 1599b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru case U_SHAPE_LETTERS_SHAPE : 1600103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius if( (options&U_SHAPE_TASHKEEL_MASK)> 0 1601b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru && ((options&U_SHAPE_TASHKEEL_MASK) !=U_SHAPE_TASHKEEL_REPLACE_BY_TATWEEL)) { 1602b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* Call the shaping function with tashkeel flag == 2 for removal of tashkeel */ 160354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius destLength = shapeUnicode(tempbuffer,sourceLength,destCapacity,options,pErrorCode,2,shapeVars); 1604b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru }else { 1605b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* default Call the shaping function with tashkeel flag == 1 */ 160654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius destLength = shapeUnicode(tempbuffer,sourceLength,destCapacity,options,pErrorCode,1,shapeVars); 1607b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 1608b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /*After shaping text check if user wants to remove tashkeel and replace it with tatweel*/ 1609b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if( (options&U_SHAPE_TASHKEEL_MASK) == U_SHAPE_TASHKEEL_REPLACE_BY_TATWEEL){ 1610b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru destLength = handleTashkeelWithTatweel(tempbuffer,destLength,destCapacity,options,pErrorCode); 1611b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 1612b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 1613b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru break; 1614b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru case U_SHAPE_LETTERS_SHAPE_TASHKEEL_ISOLATED : 1615b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* Call the shaping function with tashkeel flag == 0 */ 161654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius destLength = shapeUnicode(tempbuffer,sourceLength,destCapacity,options,pErrorCode,0,shapeVars); 1617b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru break; 1618b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 1619b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru case U_SHAPE_LETTERS_UNSHAPE : 1620b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* Call the deshaping function */ 162154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius destLength = deShapeUnicode(tempbuffer,sourceLength,destCapacity,options,pErrorCode,shapeVars); 1622b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru break; 1623b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru default : 1624b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* will never occur because of validity checks above */ 1625b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru destLength = 0; 1626b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru break; 1627b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1628b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1629b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* 1630b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * TODO: (markus 2002aug01) 1631b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * For as long as we always preflight the outputSize above 1632b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * we should U_ASSERT(outputSize==destLength) 1633b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * except for the adjustment above before the tempbuffer allocation 1634b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 1635b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1636b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if((options&U_SHAPE_TEXT_DIRECTION_MASK) == U_SHAPE_TEXT_DIRECTION_LOGICAL) { 1637b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru countSpaces(tempbuffer,destLength,options,&spacesCountl,&spacesCountr); 1638b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru invertBuffer(tempbuffer,destLength,options,spacesCountl,spacesCountr); 1639b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1640b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uprv_memcpy(dest, tempbuffer, uprv_min(destLength, destCapacity)*U_SIZEOF_UCHAR); 1641b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1642b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(tempbuffer!=buffer) { 1643b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uprv_free(tempbuffer); 1644b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1645b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1646b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(destLength>destCapacity) { 1647b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *pErrorCode=U_BUFFER_OVERFLOW_ERROR; 1648b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return destLength; 1649b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1650b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1651b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* End of Arabic letter shaping part */ 1652b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else { 1653b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* 1654b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * No letter shaping: 1655b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * just make sure the destination is large enough and copy the string. 1656b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 1657b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(destCapacity<sourceLength) { 1658b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* this catches preflighting, too */ 1659b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *pErrorCode=U_BUFFER_OVERFLOW_ERROR; 1660b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return sourceLength; 1661b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1662b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uprv_memcpy(dest, source, sourceLength*U_SIZEOF_UCHAR); 1663b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru destLength=sourceLength; 1664b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1665b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1666b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* 1667b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Perform number shaping. 1668b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * With UTF-16 or UTF-32, the length of the string is constant. 1669b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * The easiest way to do this is to operate on the destination and 1670b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * "shape" the digits in-place. 1671b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 1672b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if((options&U_SHAPE_DIGITS_MASK)!=U_SHAPE_DIGITS_NOOP) { 1673b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar digitBase; 1674b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t i; 1675b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1676b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* select the requested digit group */ 1677b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru switch(options&U_SHAPE_DIGIT_TYPE_MASK) { 1678b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru case U_SHAPE_DIGIT_TYPE_AN: 1679b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru digitBase=0x660; /* Unicode: "Arabic-Indic digits" */ 1680b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru break; 1681b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru case U_SHAPE_DIGIT_TYPE_AN_EXTENDED: 1682b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru digitBase=0x6f0; /* Unicode: "Eastern Arabic-Indic digits (Persian and Urdu)" */ 1683b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru break; 1684b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru default: 1685b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* will never occur because of validity checks above */ 1686b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru digitBase=0; 1687b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru break; 1688b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1689b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1690b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* perform the requested operation */ 1691b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru switch(options&U_SHAPE_DIGITS_MASK) { 1692b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru case U_SHAPE_DIGITS_EN2AN: 1693b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* add (digitBase-'0') to each European (ASCII) digit code point */ 1694b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru digitBase-=0x30; 1695b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru for(i=0; i<destLength; ++i) { 1696b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(((uint32_t)dest[i]-0x30)<10) { 1697b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru dest[i]+=digitBase; 1698b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1699b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1700b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru break; 1701b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru case U_SHAPE_DIGITS_AN2EN: 1702b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* subtract (digitBase-'0') from each Arabic digit code point */ 1703b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru for(i=0; i<destLength; ++i) { 1704b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(((uint32_t)dest[i]-(uint32_t)digitBase)<10) { 1705b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru dest[i]-=digitBase-0x30; 1706b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1707b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1708b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru break; 1709b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru case U_SHAPE_DIGITS_ALEN2AN_INIT_LR: 1710b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru _shapeToArabicDigitsWithContext(dest, destLength, 1711b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru digitBase, 1712b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru (UBool)((options&U_SHAPE_TEXT_DIRECTION_MASK)==U_SHAPE_TEXT_DIRECTION_LOGICAL), 1713b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru FALSE); 1714b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru break; 1715b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru case U_SHAPE_DIGITS_ALEN2AN_INIT_AL: 1716b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru _shapeToArabicDigitsWithContext(dest, destLength, 1717b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru digitBase, 1718b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru (UBool)((options&U_SHAPE_TEXT_DIRECTION_MASK)==U_SHAPE_TEXT_DIRECTION_LOGICAL), 1719b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TRUE); 1720b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru break; 1721b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru default: 1722b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* will never occur because of validity checks above */ 1723b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru break; 1724b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1725b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1726b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1727b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return u_terminateUChars(dest, destCapacity, destLength, pErrorCode); 1728b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 1729