📄 shapearabic.c
字号:
/********************************************************************************* Copyright (C) 2000-2004, International Business Machines* Corporation and others. All Rights Reserved.* Copyright (C) 2007 Apple Inc. All rights reserved.** Permission is hereby granted, free of charge, to any person obtaining a copy of this* software and associated documentation files (the "Software"), to deal in the Software* without restriction, including without limitation the rights to use, copy, modify,* merge, publish, distribute, and/or sell copies of the Software, and to permit persons* to whom the Software is furnished to do so, provided that the above copyright notice(s)* and this permission notice appear in all copies of the Software and that both the above* copyright notice(s) and this permission notice appear in supporting documentation.** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR* PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER* OR HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR* CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.** Except as contained in this notice, the name of a copyright holder shall not be used in* advertising or otherwise to promote the sale, use or other dealings in this Software* without prior written authorization of the copyright holder.********************************************************************************* Arabic letter shaping implemented by Ayman Roshdy*/#include "config.h"#if USE(ATSUI)#include "ShapeArabic.h"#include <unicode/utypes.h>#include <unicode/uchar.h>#include <unicode/ustring.h>#include <unicode/ushape.h>#include <wtf/Assertions.h>/* * ### TODO in general for letter shaping: * - the letter shaping code is UTF-16-unaware; needs update * + especially invertBuffer()?! * - needs to handle the "Arabic Tail" that is used in some legacy codepages * as a glyph fragment of wide-glyph letters * + IBM Unicode conversion tables map it to U+200B (ZWSP) * + IBM Egypt has proposed to encode the tail in Unicode among Arabic Presentation Forms *//* definitions for Arabic letter shaping ------------------------------------ */#define IRRELEVANT 4#define LAMTYPE 16#define ALEFTYPE 32#define LINKR 1#define LINKL 2static const UChar IrrelevantPos[] = { 0x0, 0x2, 0x4, 0x6, 0x8, 0xA, 0xC, 0xE,};static const UChar araLink[178]={ 1 + 32 + 256 * 0x11,/*0x0622*/ 1 + 32 + 256 * 0x13,/*0x0623*/ 1 + 256 * 0x15,/*0x0624*/ 1 + 32 + 256 * 0x17,/*0x0625*/ 1 + 2 + 256 * 0x19,/*0x0626*/ 1 + 32 + 256 * 0x1D,/*0x0627*/ 1 + 2 + 256 * 0x1F,/*0x0628*/ 1 + 256 * 0x23,/*0x0629*/ 1 + 2 + 256 * 0x25,/*0x062A*/ 1 + 2 + 256 * 0x29,/*0x062B*/ 1 + 2 + 256 * 0x2D,/*0x062C*/ 1 + 2 + 256 * 0x31,/*0x062D*/ 1 + 2 + 256 * 0x35,/*0x062E*/ 1 + 256 * 0x39,/*0x062F*/ 1 + 256 * 0x3B,/*0x0630*/ 1 + 256 * 0x3D,/*0x0631*/ 1 + 256 * 0x3F,/*0x0632*/ 1 + 2 + 256 * 0x41,/*0x0633*/ 1 + 2 + 256 * 0x45,/*0x0634*/ 1 + 2 + 256 * 0x49,/*0x0635*/ 1 + 2 + 256 * 0x4D,/*0x0636*/ 1 + 2 + 256 * 0x51,/*0x0637*/ 1 + 2 + 256 * 0x55,/*0x0638*/ 1 + 2 + 256 * 0x59,/*0x0639*/ 1 + 2 + 256 * 0x5D,/*0x063A*/ 0, 0, 0, 0, 0, /*0x063B-0x063F*/ 1 + 2, /*0x0640*/ 1 + 2 + 256 * 0x61,/*0x0641*/ 1 + 2 + 256 * 0x65,/*0x0642*/ 1 + 2 + 256 * 0x69,/*0x0643*/ 1 + 2 + 16 + 256 * 0x6D,/*0x0644*/ 1 + 2 + 256 * 0x71,/*0x0645*/ 1 + 2 + 256 * 0x75,/*0x0646*/ 1 + 2 + 256 * 0x79,/*0x0647*/ 1 + 256 * 0x7D,/*0x0648*/ 1 + 256 * 0x7F,/*0x0649*/ 1 + 2 + 256 * 0x81,/*0x064A*/ 4, 4, 4, 4, /*0x064B-0x064E*/ 4, 4, 4, 4, /*0x064F-0x0652*/ 4, 4, 4, 0, 0, /*0x0653-0x0657*/ 0, 0, 0, 0, /*0x0658-0x065B*/ 1 + 256 * 0x85,/*0x065C*/ 1 + 256 * 0x87,/*0x065D*/ 1 + 256 * 0x89,/*0x065E*/ 1 + 256 * 0x8B,/*0x065F*/ 0, 0, 0, 0, 0, /*0x0660-0x0664*/ 0, 0, 0, 0, 0, /*0x0665-0x0669*/ 0, 0, 0, 0, 0, 0, /*0x066A-0x066F*/ 4, /*0x0670*/ 0, /*0x0671*/ 1 + 32, /*0x0672*/ 1 + 32, /*0x0673*/ 0, /*0x0674*/ 1 + 32, /*0x0675*/ 1, 1, /*0x0676-0x0677*/ 1+2, /*0x0678*/ 1+2 + 256 * 0x16,/*0x0679*/ 1+2 + 256 * 0x0E,/*0x067A*/ 1+2 + 256 * 0x02,/*0x067B*/ 1+2, 1+2, /*0x067C-0x067D*/ 1+2 + 256 * 0x06,/*0x067E*/ 1+2 + 256 * 0x12,/*0x067F*/ 1+2 + 256 * 0x0A,/*0x0680*/ 1+2, 1+2, /*0x0681-0x0682*/ 1+2 + 256 * 0x26,/*0x0683*/ 1+2 + 256 * 0x22,/*0x0684*/ 1+2, /*0x0685*/ 1+2 + 256 * 0x2A,/*0x0686*/ 1+2 + 256 * 0x2E,/*0x0687*/ 1 + 256 * 0x38,/*0x0688*/ 1, 1, 1, /*0x0689-0x068B*/ 1 + 256 * 0x34,/*0x068C*/ 1 + 256 * 0x32,/*0x068D*/ 1 + 256 * 0x36,/*0x068E*/ 1, 1, /*0x068F-0x0690*/ 1 + 256 * 0x3C,/*0x0691*/ 1, 1, 1, 1, 1, 1, /*0x0692-0x0697*/ 1 + 256 * 0x3A,/*0x0698*/ 1, /*0x0699*/ 1+2, 1+2, 1+2, 1+2, 1+2, 1+2, /*0x069A-0x069F*/ 1+2, 1+2, 1+2, 1+2, /*0x06A0-0x06A3*/ 1+2 + 256 * 0x2E,/*0x06A4*/ 1+2, /*0x06A5*/ 1+2 + 256 * 0x1E,/*0x06A6*/ 1+2, 1+2, /*0x06A7-0x06A8*/ 1+2 + 256 * 0x3E,/*0x06A9*/ 1+2, 1+2, 1+2, /*0x06AA-0x06AC*/ 1+2 + 256 * 0x83,/*0x06AD*/ 1+2, /*0x06AE*/ 1+2 + 256 * 0x42,/*0x06AF*/ 1+2, /*0x06B0*/ 1+2 + 256 * 0x4A,/*0x06B1*/ 1+2, /*0x06B2*/ 1+2 + 256 * 0x46,/*0x06B3*/ 1+2, 1+2, 1+2, 1+2, 1+2, 1+2, /*0x06B4-0x06B9*/ 1+2, /*0x06BA*/ // FIXME: Seems to have a final form 1+2 + 256 * 0x50,/*0x06BB*/ 1+2, 1+2, /*0x06BC-0x06BD*/ 1+2 + 256 * 0x5A,/*0x06BE*/ 1+2, /*0x06BF*/ 1, /*0x06C0*/ 1+2 + 256 * 0x56,/*0x06C1*/ 1+2, /*0x06C2*/ 1, 1, /*0x06C3-0x06C4*/ 1 + 256 * 0x90,/*0x06C5*/ 1 + 256 * 0x89,/*0x06C6*/ 1 + 256 * 0x87,/*0x06C7*/ 1 + 256 * 0x8B,/*0x06C8*/ 1 + 256 * 0x92,/*0x06C9*/ 1, /*0x06CA*/ 1 + 256 * 0x8E,/*0x06CB*/ 1+2 + 256 * 0xAC,/*0x06CC*/ 1, /*0x06CD*/ 1+2, /*0x06CE*/ 1, /*0x06CF*/ 1+2 + 256 * 0x94,/*0x06D0*/ 1+2, /*0x06D1*/ 1 + 256 * 0x5E,/*0x06D2*/ 1 + 256 * 0x60 /*0x06D3*/};static const UChar presLink[141]={ 1 + 2, /*0xFE70*/ 1 + 2, /*0xFE71*/ 1 + 2, 0, 1+ 2, 0, 1+ 2, /*0xFE72-0xFE76*/ 1 + 2, /*0xFE77*/ 1+ 2, 1 + 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6-0xFEF9*/ 1, 0, 1, 0, /*0xFEFA-0xFEFD*/ 1, 0, 1, 0, 1};static const UChar convertFEto06[] ={/***********0******1******2******3******4******5******6******7******8******9******A******B******C******D******E******F***//*FE7*/ 0x64B, 0x64B, 0x64C, 0x64C, 0x64D, 0x64D, 0x64E, 0x64E, 0x64F, 0x64F, 0x650, 0x650, 0x651, 0x651, 0x652, 0x652,/*FE8*/ 0x621, 0x622, 0x622, 0x623, 0x623, 0x624, 0x624, 0x625, 0x625, 0x626, 0x626, 0x626, 0x626, 0x627, 0x627, 0x628,/*FE9*/ 0x628, 0x628, 0x628, 0x629, 0x629, 0x62A, 0x62A, 0x62A, 0x62A, 0x62B, 0x62B, 0x62B, 0x62B, 0x62C, 0x62C, 0x62C,/*FEA*/ 0x62C, 0x62D, 0x62D, 0x62D, 0x62D, 0x62E, 0x62E, 0x62E, 0x62E, 0x62F, 0x62F, 0x630, 0x630, 0x631, 0x631, 0x632,/*FEB*/ 0x632, 0x633, 0x633, 0x633, 0x633, 0x634, 0x634, 0x634, 0x634, 0x635, 0x635, 0x635, 0x635, 0x636, 0x636, 0x636,/*FEC*/ 0x636, 0x637, 0x637, 0x637, 0x637, 0x638, 0x638, 0x638, 0x638, 0x639, 0x639, 0x639, 0x639, 0x63A, 0x63A, 0x63A,/*FED*/ 0x63A, 0x641, 0x641, 0x641, 0x641, 0x642, 0x642, 0x642, 0x642, 0x643, 0x643, 0x643, 0x643, 0x644, 0x644, 0x644,/*FEE*/ 0x644, 0x645, 0x645, 0x645, 0x645, 0x646, 0x646, 0x646, 0x646, 0x647, 0x647, 0x647, 0x647, 0x648, 0x648, 0x649,/*FEF*/ 0x649, 0x64A, 0x64A, 0x64A, 0x64A, 0x65C, 0x65C, 0x65D, 0x65D, 0x65E, 0x65E, 0x65F, 0x65F};static const UChar shapeTable[4][4][4]={ { {0,0,0,0}, {0,0,0,0}, {0,1,0,3}, {0,1,0,1} }, { {0,0,2,2}, {0,0,1,2}, {0,1,1,2}, {0,1,1,3} }, { {0,0,0,0}, {0,0,0,0}, {0,1,0,3}, {0,1,0,3} }, { {0,0,1,2}, {0,0,1,2}, {0,1,1,2}, {0,1,1,3} }};/* *Name : changeLamAlef *Function : Converts the Alef characters into an equivalent * LamAlef location in the 0x06xx Range, this is an * intermediate stage in the operation of the program * later it'll be converted into the 0xFExx LamAlefs * in the shaping function. */static UCharchangeLamAlef(UChar ch) { switch(ch) { case 0x0622 : return(0x065C); break; case 0x0623 : return(0x065D); break; case 0x0625 : return(0x065E); break; case 0x0627 : return(0x065F); break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -