├── CREDITS ├── tests ├── 001.phpt ├── 003.phpt ├── 004.phpt ├── 005.phpt └── 002.phpt ├── config.w32 ├── config.m4 ├── php_fribidi.h ├── package.xml ├── README ├── fribidi.dsp └── fribidi.c /CREDITS: -------------------------------------------------------------------------------- 1 | GNU FriBidi 2 | Onn Ben-Zvi 3 | Tal Peer 4 | Behnam Esfahbod 5 | -------------------------------------------------------------------------------- /tests/001.phpt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/php/pecl-internationalization-fribidi/master/tests/001.phpt -------------------------------------------------------------------------------- /config.w32: -------------------------------------------------------------------------------- 1 | // $Id$ 2 | // vim:ft=javascript 3 | 4 | ARG_WITH("fribidi", "FRIBIDI support", "no"); 5 | 6 | if (PHP_FRIBIDI != "no") { 7 | 8 | if (CHECK_HEADER_ADD_INCLUDE("fribidi/fribidi.h", "CFLAGS_FRIBIDI", PHP_FRIBIDI) && 9 | CHECK_LIB("fribidi.lib", "fribidi", PHP_FRIBIDI)) { 10 | EXTENSION('fribidi', 'fribidi.c'); 11 | AC_DEFINE('HAVE_FRIBIDI', 1); 12 | AC_DEFINE('DONT_HAVE_FRIBIDI_UNICODE_VERSION_H', 1); 13 | } else { 14 | WARNING("fribidi not enabled; libraries and headers not found"); 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /tests/003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | fribidi_log2vis() [UTF-8 file] 3 | --SKIPIF-- 4 | 5 | --POST-- 6 | --GET-- 7 | --FILE-- 8 | 18 | --EXPECT-- 19 | array(3) { 20 | [0]=> 21 | string(26) "biggest EHT SI dog 123 EHT" 22 | [1]=> 23 | string(26) "THE dog 123 IS THE biggest" 24 | [2]=> 25 | string(44) "ﻪﻤﻫ ﯼﺍﺮﺑ ﺪﮐ‌ﯽﻧﻮﯾ" 26 | } 27 | -------------------------------------------------------------------------------- /tests/004.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | fribidi_log2vis() [non-strings and empty strings] 3 | --SKIPIF-- 4 | 5 | --POST-- 6 | --GET-- 7 | --FILE-- 8 | 21 | --EXPECT-- 22 | array(7) { 23 | [0]=> 24 | string(0) "" 25 | [1]=> 26 | string(0) "" 27 | [2]=> 28 | string(1) "1" 29 | [3]=> 30 | string(1) "0" 31 | [4]=> 32 | string(1) "1" 33 | [5]=> 34 | string(0) "" 35 | [6]=> 36 | string(0) "" 37 | } 38 | -------------------------------------------------------------------------------- /config.m4: -------------------------------------------------------------------------------- 1 | dnl 2 | dnl $Id$ 3 | dnl 4 | 5 | PHP_ARG_WITH(fribidi, for FriBidi support, 6 | [ --with-fribidi[=DIR] Include FriBidi support (requires FriBidi >= 0.19.1).]) 7 | 8 | if test "$PHP_FRIBIDI" != "no"; then 9 | AC_PATH_PROG(FRIBIDI_PKG_CONFIG,pkg-config,,[/usr/local/bin:$PATH]) 10 | 11 | if test ! -x "$FRIBIDI_PKG_CONFIG"; then 12 | AC_MSG_ERROR([pkg-config not found.]) 13 | fi 14 | 15 | if test "$PHP_FRIBIDI" = "yes"; then 16 | FRIBIDI_PKG_CONFIG_CMD="$FRIBIDI_PKG_CONFIG fribidi" 17 | else 18 | FRIBIDI_PKG_CONFIG_CMD="$FRIBIDI_PKG_CONFIG $PHP_FRIBIDI/lib/pkgconfig/fribidi.pc" 19 | fi 20 | 21 | dnl check for fribidi version 22 | AC_MSG_CHECKING([for FriBidi version]) 23 | 24 | fribidi_version_full=`$FRIBIDI_PKG_CONFIG_CMD --modversion` 25 | fribidi_version=`echo ${fribidi_version_full} | awk 'BEGIN { FS = "."; } { printf "%d", ($1 * 1000 + $2) * 1000 + $3;}'` 26 | 27 | if test "$fribidi_version" -ge 19001; then 28 | AC_MSG_RESULT([$fribidi_version_full]) 29 | else 30 | AC_MSG_ERROR([FriBidi version 0.19.1 or later required.]) 31 | fi 32 | 33 | dnl Get the paths 34 | FRIBIDI_LIBS=`$FRIBIDI_PKG_CONFIG_CMD --libs` 35 | FRIBIDI_INCS=`$FRIBIDI_PKG_CONFIG_CMD --cflags` 36 | 37 | if test -n "$FRIBIDI_INCS" && test -n "$FRIBIDI_LIBS"; then 38 | PHP_EVAL_INCLINE($FRIBIDI_INCS) 39 | PHP_EVAL_LIBLINE($FRIBIDI_LIBS, FRIBIDI_SHARED_LIBADD) 40 | 41 | PHP_NEW_EXTENSION(fribidi, fribidi.c, $ext_shared) 42 | PHP_SUBST(FRIBIDI_SHARED_LIBADD) 43 | AC_DEFINE(HAVE_FRIBIDI, 1, [ ]) 44 | else 45 | AC_MSG_ERROR([Could not find the required paths. Please check your FriBidi installation.]) 46 | fi 47 | fi 48 | -------------------------------------------------------------------------------- /tests/005.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | fribidi_log2vis() [Paragraph directions] 3 | --SKIPIF-- 4 | 5 | --POST-- 6 | --GET-- 7 | --FILE-- 8 | 33 | --EXPECT-- 34 | array(5) { 35 | [0]=> 36 | string(7) "def CBA" 37 | [1]=> 38 | string(7) "CBA def" 39 | [2]=> 40 | string(7) "def CBA" 41 | [3]=> 42 | string(7) "def CBA" 43 | [4]=> 44 | string(7) "def CBA" 45 | } 46 | array(5) { 47 | [0]=> 48 | string(7) "abc FED" 49 | [1]=> 50 | string(7) "abc FED" 51 | [2]=> 52 | string(7) "FED abc" 53 | [3]=> 54 | string(7) "abc FED" 55 | [4]=> 56 | string(7) "abc FED" 57 | } 58 | array(5) { 59 | [0]=> 60 | string(7) "123 456" 61 | [1]=> 62 | string(7) "123 456" 63 | [2]=> 64 | string(7) "456 123" 65 | [3]=> 66 | string(7) "123 456" 67 | [4]=> 68 | string(7) "456 123" 69 | } 70 | -------------------------------------------------------------------------------- /php_fribidi.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 5 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2013 The PHP Group | 6 | +----------------------------------------------------------------------+ 7 | | This source file is subject to version 3.01 of the PHP license, | 8 | | that is bundled with this package in the file LICENSE, and is | 9 | | available through the world-wide-web at the following url: | 10 | | http://www.php.net/license/3_01.txt | 11 | | If you did not receive a copy of the PHP license and are unable to | 12 | | obtain it through the world-wide-web, please send a note to | 13 | | license@php.net so we can mail you a copy immediately. | 14 | +----------------------------------------------------------------------+ 15 | | Author: Onn Ben-Zvi | 16 | +----------------------------------------------------------------------+ 17 | */ 18 | 19 | #ifndef PHP_FRIBIDI_H 20 | #define PHP_FRIBIDI_H 21 | 22 | #if HAVE_FRIBIDI 23 | 24 | #include 25 | 26 | extern zend_module_entry fribidi_module_entry; 27 | #define phpext_fribidi_ptr &fribidi_module_entry 28 | 29 | #define PHP_FRIBIDI_VERSION "1.2" 30 | 31 | #ifdef PHP_WIN32 32 | #define PHP_FRIBIDI_API __declspec(dllexport) 33 | #else 34 | #define PHP_FRIBIDI_API 35 | #endif 36 | 37 | PHP_MINIT_FUNCTION(fribidi); 38 | PHP_MSHUTDOWN_FUNCTION(fribidi); 39 | PHP_RINIT_FUNCTION(fribidi); 40 | PHP_RSHUTDOWN_FUNCTION(fribidi); 41 | PHP_MINFO_FUNCTION(fribidi); 42 | 43 | PHP_FUNCTION(fribidi_log2vis); 44 | PHP_FUNCTION(fribidi_charset_info); 45 | PHP_FUNCTION(fribidi_get_charsets); 46 | 47 | #ifdef ZTS 48 | #define FRIBIDIG(v) TSRMG(fribidi_globals_id, php_fribidi_globals *, v) 49 | #else 50 | #define FRIBIDIG(v) (fribidi_globals.v) 51 | #endif 52 | 53 | #else 54 | 55 | #define phpext_fribidi_ptr NULL 56 | 57 | #endif 58 | 59 | #endif /* PHP_FRIBIDI_H */ 60 | 61 | /* 62 | * Local variables: 63 | * tab-width: 4 64 | * c-basic-offset: 4 65 | * End: 66 | */ 67 | -------------------------------------------------------------------------------- /package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | fribidi 4 | pecl.php.net 5 | Implementation of the Unicode Bidirectional Algorithm (bidi) 6 | A PHP frontend to the GNU FriBidi library: an implementation of 7 | the Unicode Bidirectional Algorithm (BDA), provides means for handling 8 | right-to-left text. 9 | 10 | Tal Peer 11 | tal 12 | tal@php.net 13 | yes 14 | 15 | 16 | Behnam Esfahbod 17 | behnam 18 | behnam@php.net 19 | yes 20 | 21 | 2013-05-27 22 | 23 | 24 | 1.2 25 | 1.0 26 | 27 | 28 | stable 29 | stable 30 | 31 | PHP 32 | Requires GNU FriBidi version 0.19.1 or later. 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 5.0.0 54 | 55 | 56 | 1.4.0b1 57 | 58 | 59 | 60 | fribidi 61 | 62 | 63 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | 2 | PECL FriBidi 3 | ============ 4 | 5 | PHP Extension for GNU FriBidi, an implementation of the Unicode Bidirectional Algorithm (bidi) 6 | 7 | 8 | Purpose 9 | ------- 10 | 11 | This extension is basically a wrapper for the GNU FriBidi implementation 12 | of the Unicode Bidirectional algorithm. The need for such an algorithm 13 | rises from the bidirectional language usage done by applications. 14 | Arabic/Hebrew embedded within English is such a case. 15 | 16 | 17 | Usage 18 | ----- 19 | 20 | The only function used is fribidi_log2vis (logical [non-reversed] to visual [reversed]). 21 | 22 | Input: 23 | 1) The Logical string. 24 | 2) Base direction of application. Possible values: 25 | * FRIBIDI_AUTO (autodetect the base direction) 26 | * FRIBIDI_LTR (left to right 27 | * FRIBIDI_RTL (right to left) 28 | * FRIBIDI_WLTR (weak left to right) 29 | * FRIBIDI_WRTL (weak right to left) 30 | 3) The char code being used, which can be one of the following constants: 31 | * FRIBIDI_CHARSET_UTF8 (Unicode) 32 | * FRIBIDI_CHARSET_8859_6 (ISO-8859-6 - Arabic) 33 | * FRIBIDI_CHARSET_8859_8 (ISO-8859-8 - Hebrew) 34 | * FRIBIDI_CHARSET_CP1255 (MS Codepage 1255 - Hebrew/Yiddish) 35 | * FRIBIDI_CHARSET_CP1256 (MS Codepage 1256 - Arabic) 36 | * FRIBIDI_CHARSET_CAP_RTL (Used for test purposes, will treat CAPS as non-English letters) 37 | 38 | Note: Currently, GNU FriBidi supports the above Character Codes alone. 39 | 40 | Output: The visual string, on success, false, otherwise. 41 | 42 | 43 | Compiling 44 | --------- 45 | 46 | 1) Static - ./configure --with-fribidi=base-directory-of-FriBidi-installation-path 47 | (defaults to /usr/local). 48 | 49 | 2) dl - same, just add shared, to get .... --with-fribidi=shared,base.... 50 | 51 | 52 | Prerequisites 53 | ------------- 54 | 55 | 1) GNU FriBidi version 0.19.1 or later must be installed. 56 | Latest version can be obtained thru http://fribidi.org/ 57 | 58 | 59 | Notes 60 | ----- 61 | 62 | The function fribidi_log2vis computes three more arrays which are currently not passed back as output. 63 | These arrays are: 64 | 1) mapping from the logical to the visual string. 65 | 2) mapping from the visual to the logical string. 66 | 3) embedding level of characters as figured out by the bidi algorithm. 67 | 68 | The extension needs further implementation to support this. 69 | p.s. - If you don't understand this, you probably don't need it. 70 | 71 | -------------------------------------------------------------------------------- /tests/002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | fribidi_get_charsets() and fribidi_charset_info() 3 | --SKIPIF-- 4 | 5 | --POST-- 6 | --GET-- 7 | --FILE-- 8 | $name) { 20 | print_r(fribidi_charset_info($code)); 21 | } 22 | ?> 23 | --EXPECT-- 24 | 1 25 | 4 26 | 3 27 | 5 28 | 6 29 | 2 30 | Array 31 | ( 32 | [name] => UTF-8 33 | [title] => UTF-8 (Unicode) 34 | ) 35 | Array 36 | ( 37 | [name] => ISO8859-6 38 | [title] => ISO8859-6 (Arabic) 39 | ) 40 | Array 41 | ( 42 | [name] => ISO8859-8 43 | [title] => ISO8859-8 (Hebrew) 44 | ) 45 | Array 46 | ( 47 | [name] => CP1255 48 | [title] => CP1255 (MS Hebrew/Yiddish) 49 | ) 50 | Array 51 | ( 52 | [name] => CP1256 53 | [title] => CP1256 (MS Arabic) 54 | ) 55 | Array 56 | ( 57 | [name] => CapRTL 58 | [title] => CapRTL (Test) 59 | [desc] => CapRTL is a character set for testing with the reference 60 | implementation, with explicit marks escape strings, and 61 | the property that contains all unicode character types in 62 | ASCII range 1-127. 63 | 64 | Warning: CapRTL character types are subject to change. 65 | 66 | CapRTL's character types: 67 | 68 | * 0x00 ^@ ON * 0x01 ^A ON * 0x02 ^B ON * 0x03 ^C ON 69 | * 0x04 ^D LTR * 0x05 ^E RTL * 0x06 ^F ON * 0x07 ^G ON 70 | * 0x08 ^H ON * 0x09 ^I ON * 0x0a ^J ON * 0x0b ^K ON 71 | * 0x0c ^L ON * 0x0d ^M BS * 0x0e ^N RLO * 0x0f ^O RLE 72 | * 0x10 ^P LRO * 0x11 ^Q LRE * 0x12 ^R PDF * 0x13 ^S WS 73 | * 0x14 ^T ON * 0x15 ^U ON * 0x16 ^V ON * 0x17 ^W ON 74 | * 0x18 ^X ON * 0x19 ^Y ON * 0x1a ^Z ON * 0x1b ^[ ON 75 | * 0x1c ^\ ON * 0x1d ^] ON * 0x1e ^^ ON * 0x1f ^_ ON 76 | * 0x20 WS * 0x21 ! ON * 0x22 " ON * 0x23 # ON 77 | * 0x24 $ ET * 0x25 % ON * 0x26 & ON * 0x27 ' ON 78 | * 0x28 ( ON * 0x29 ) ON * 0x2a * ON * 0x2b + ET 79 | * 0x2c , CS * 0x2d - ON * 0x2e . ES * 0x2f / ES 80 | * 0x30 0 EN * 0x31 1 EN * 0x32 2 EN * 0x33 3 EN 81 | * 0x34 4 EN * 0x35 5 EN * 0x36 6 AN * 0x37 7 AN 82 | * 0x38 8 AN * 0x39 9 AN * 0x3a : CS * 0x3b ; ON 83 | * 0x3c < ON * 0x3d = ON * 0x3e > ON * 0x3f ? ON 84 | * 0x40 @ RTL * 0x41 A AL * 0x42 B AL * 0x43 C AL 85 | * 0x44 D AL * 0x45 E AL * 0x46 F AL * 0x47 G RTL 86 | * 0x48 H RTL * 0x49 I RTL * 0x4a J RTL * 0x4b K RTL 87 | * 0x4c L RTL * 0x4d M RTL * 0x4e N RTL * 0x4f O RTL 88 | * 0x50 P RTL * 0x51 Q RTL * 0x52 R RTL * 0x53 S RTL 89 | * 0x54 T RTL * 0x55 U RTL * 0x56 V RTL * 0x57 W RTL 90 | * 0x58 X RTL * 0x59 Y RTL * 0x5a Z RTL * 0x5b [ ON 91 | * 0x5c \ BS * 0x5d ] ON * 0x5e ^ BN * 0x5f _ ON 92 | * 0x60 ` NSM * 0x61 a LTR * 0x62 b LTR * 0x63 c LTR 93 | * 0x64 d LTR * 0x65 e LTR * 0x66 f LTR * 0x67 g LTR 94 | * 0x68 h LTR * 0x69 i LTR * 0x6a j LTR * 0x6b k LTR 95 | * 0x6c l LTR * 0x6d m LTR * 0x6e n LTR * 0x6f o LTR 96 | * 0x70 p LTR * 0x71 q LTR * 0x72 r LTR * 0x73 s LTR 97 | * 0x74 t LTR * 0x75 u LTR * 0x76 v LTR * 0x77 w LTR 98 | * 0x78 x LTR * 0x79 y LTR * 0x7a z LTR * 0x7b { ON 99 | * 0x7c | SS * 0x7d } ON * 0x7e ~ WS * 0x7f ON 100 | 101 | Escape sequences: 102 | Character `_' is used to escape explicit marks. The list is: 103 | * _> LRM 104 | * _< RLM 105 | * _l LRE 106 | * _r RLE 107 | * _L LRO 108 | * _R RLO 109 | * _o PDF 110 | * __ `_' itself 111 | 112 | 113 | ) 114 | -------------------------------------------------------------------------------- /fribidi.dsp: -------------------------------------------------------------------------------- 1 | # Microsoft Developer Studio Project File - Name="fribidi" - Package Owner=<4> 2 | # Microsoft Developer Studio Generated Build File, Format Version 6.00 3 | # ** DO NOT EDIT ** 4 | 5 | # TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 6 | 7 | CFG=fribidi - Win32 Debug_TS 8 | !MESSAGE This is not a valid makefile. To build this project using NMAKE, 9 | !MESSAGE use the Export Makefile command and run 10 | !MESSAGE 11 | !MESSAGE NMAKE /f "fribidi.mak". 12 | !MESSAGE 13 | !MESSAGE You can specify a configuration when running NMAKE 14 | !MESSAGE by defining the macro CFG on the command line. For example: 15 | !MESSAGE 16 | !MESSAGE NMAKE /f "fribidi.mak" CFG="fribidi - Win32 Debug_TS" 17 | !MESSAGE 18 | !MESSAGE Possible choices for configuration are: 19 | !MESSAGE 20 | !MESSAGE "fribidi - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library") 21 | !MESSAGE "fribidi - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library") 22 | !MESSAGE 23 | 24 | # Begin Project 25 | # PROP AllowPerConfigDependencies 0 26 | # PROP Scc_ProjName "" 27 | # PROP Scc_LocalPath "" 28 | CPP=cl.exe 29 | MTL=midl.exe 30 | RSC=rc.exe 31 | 32 | !IF "$(CFG)" == "fribidi - Win32 Release_TS" 33 | 34 | # PROP BASE Use_MFC 0 35 | # PROP BASE Use_Debug_Libraries 0 36 | # PROP BASE Output_Dir "Release_TS" 37 | # PROP BASE Intermediate_Dir "Release_TS" 38 | # PROP BASE Ignore_Export_Lib 0 39 | # PROP BASE Target_Dir "" 40 | # PROP Use_MFC 0 41 | # PROP Use_Debug_Libraries 0 42 | # PROP Output_Dir "Release_TS" 43 | # PROP Intermediate_Dir "Release_TS" 44 | # PROP Ignore_Export_Lib 0 45 | # PROP Target_Dir "" 46 | # ADD BASE CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "FRIBIDI_EXPORTS" /YX /FD /c 47 | # ADD CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\TSRM" /I "..\..\..\php_build" /D ZEND_DEBUG=0 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "COMPILE_DL_FRIBIDI" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_FRIBIDI=1 /D "PHP_FRIBIDI_EXPORTS" /FR /YX /FD /c 48 | # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 49 | # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 50 | # ADD BASE RSC /l 0x407 /d "NDEBUG" 51 | # ADD RSC /l 0x407 /d "NDEBUG" 52 | BSC32=bscmake.exe 53 | # ADD BASE BSC32 /nologo 54 | # ADD BSC32 /nologo 55 | LINK32=link.exe 56 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 57 | # ADD LINK32 fribidi.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php4ts.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS/php_fribidi.dll" /libpath:"..\..\Release_TS" /libpath:"..\..\Release_TS_Inline" /libpath:"..\..\..\php_build\release" 58 | 59 | !ELSEIF "$(CFG)" == "fribidi - Win32 Debug_TS" 60 | 61 | # PROP BASE Use_MFC 0 62 | # PROP BASE Use_Debug_Libraries 1 63 | # PROP BASE Output_Dir "Debug_TS" 64 | # PROP BASE Intermediate_Dir "Debug_TS" 65 | # PROP BASE Target_Dir "" 66 | # PROP Use_MFC 0 67 | # PROP Use_Debug_Libraries 1 68 | # PROP Output_Dir "Debug_TS" 69 | # PROP Intermediate_Dir "Debug_TS" 70 | # PROP Ignore_Export_Lib 0 71 | # PROP Target_Dir "" 72 | # ADD BASE CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "FRIBIDI_EXPORTS" /YX /FD /GZ /c 73 | # ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\TSRM" /I "..\..\..\php_build" /D ZEND_DEBUG=1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "COMPILE_DL_FRIBIDI" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_FRIBIDI=1 /D "PHP_FRIBIDI_EXPORTS" /YX /FD /GZ /c 74 | # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 75 | # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 76 | # ADD BASE RSC /l 0x407 /d "_DEBUG" 77 | # ADD RSC /l 0x407 /d "_DEBUG" 78 | BSC32=bscmake.exe 79 | # ADD BASE BSC32 /nologo 80 | # ADD BSC32 /nologo 81 | LINK32=link.exe 82 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept 83 | # ADD LINK32 php4ts_debug.lib fribidi.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"..\..\Debug_TS/php_fribidi.dll" /pdbtype:sept /libpath:"..\..\Debug_TS" /libpath:"..\..\..\php_build\release" 84 | 85 | !ENDIF 86 | 87 | # Begin Target 88 | 89 | # Name "fribidi - Win32 Release_TS" 90 | # Name "fribidi - Win32 Debug_TS" 91 | # Begin Group "Source Files" 92 | 93 | # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" 94 | # Begin Source File 95 | 96 | SOURCE=.\fribidi.c 97 | # End Source File 98 | # End Group 99 | # Begin Group "Header Files" 100 | 101 | # PROP Default_Filter "h;hpp;hxx;hm;inl" 102 | # Begin Source File 103 | 104 | SOURCE=.\php_fribidi.h 105 | # End Source File 106 | # End Group 107 | # End Target 108 | # End Project 109 | -------------------------------------------------------------------------------- /fribidi.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 5 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2013 The PHP Group | 6 | +----------------------------------------------------------------------+ 7 | | This source file is subject to version 3.01 of the PHP license, | 8 | | that is bundled with this package in the file LICENSE, and is | 9 | | available through the world-wide-web at the following url: | 10 | | http://www.php.net/license/3_01.txt | 11 | | If you did not receive a copy of the PHP license and are unable to | 12 | | obtain it through the world-wide-web, please send a note to | 13 | | license@php.net so we can mail you a copy immediately. | 14 | +----------------------------------------------------------------------+ 15 | | Authors: Onn Ben-Zvi | 16 | | Tal Peer | 17 | | Behnam Esfahbod | 18 | +----------------------------------------------------------------------+ 19 | */ 20 | 21 | /* $Id$ */ 22 | 23 | #ifdef HAVE_CONFIG_H 24 | #include "config.h" 25 | #endif 26 | 27 | #include "php.h" 28 | #include "php_fribidi.h" 29 | 30 | #if HAVE_FRIBIDI 31 | 32 | #include "ext/standard/info.h" 33 | #include 34 | 35 | zend_function_entry fribidi_functions[] = { 36 | PHP_FE(fribidi_log2vis, NULL) 37 | PHP_FE(fribidi_charset_info, NULL) 38 | PHP_FE(fribidi_get_charsets, NULL) 39 | {NULL, NULL, NULL} 40 | }; 41 | 42 | zend_module_entry fribidi_module_entry = { 43 | STANDARD_MODULE_HEADER, 44 | "fribidi", 45 | fribidi_functions, 46 | PHP_MINIT(fribidi), 47 | PHP_MSHUTDOWN(fribidi), 48 | NULL, 49 | NULL, 50 | PHP_MINFO(fribidi), 51 | PHP_FRIBIDI_VERSION, 52 | STANDARD_MODULE_PROPERTIES 53 | }; 54 | 55 | #ifdef COMPILE_DL_FRIBIDI 56 | ZEND_GET_MODULE(fribidi) 57 | #endif 58 | 59 | /* {{{ PHP_MINIT_FUNCTION 60 | */ 61 | PHP_MINIT_FUNCTION(fribidi) 62 | { 63 | /* Charsets */ 64 | REGISTER_LONG_CONSTANT("FRIBIDI_CHARSET_UTF8", FRIBIDI_CHAR_SET_UTF8, CONST_CS | CONST_PERSISTENT); 65 | REGISTER_LONG_CONSTANT("FRIBIDI_CHARSET_8859_6", FRIBIDI_CHAR_SET_ISO8859_6, CONST_CS | CONST_PERSISTENT); 66 | REGISTER_LONG_CONSTANT("FRIBIDI_CHARSET_8859_8", FRIBIDI_CHAR_SET_ISO8859_8, CONST_CS | CONST_PERSISTENT); 67 | REGISTER_LONG_CONSTANT("FRIBIDI_CHARSET_CP1255", FRIBIDI_CHAR_SET_CP1255, CONST_CS | CONST_PERSISTENT); 68 | REGISTER_LONG_CONSTANT("FRIBIDI_CHARSET_CP1256", FRIBIDI_CHAR_SET_CP1256, CONST_CS | CONST_PERSISTENT); 69 | REGISTER_LONG_CONSTANT("FRIBIDI_CHARSET_CAP_RTL", FRIBIDI_CHAR_SET_CAP_RTL, CONST_CS | CONST_PERSISTENT); 70 | 71 | /* Directions */ 72 | REGISTER_LONG_CONSTANT("FRIBIDI_AUTO", FRIBIDI_PAR_ON, CONST_CS | CONST_PERSISTENT); 73 | REGISTER_LONG_CONSTANT("FRIBIDI_LTR", FRIBIDI_PAR_LTR, CONST_CS | CONST_PERSISTENT); 74 | REGISTER_LONG_CONSTANT("FRIBIDI_RTL", FRIBIDI_PAR_RTL, CONST_CS | CONST_PERSISTENT); 75 | REGISTER_LONG_CONSTANT("FRIBIDI_WLTR", FRIBIDI_PAR_WLTR, CONST_CS | CONST_PERSISTENT); 76 | REGISTER_LONG_CONSTANT("FRIBIDI_WRTL", FRIBIDI_PAR_WRTL, CONST_CS | CONST_PERSISTENT); 77 | 78 | return SUCCESS; 79 | } 80 | /* }}} */ 81 | 82 | /* {{{ PHP_MSHUTDOWN_FUNCTION 83 | */ 84 | PHP_MSHUTDOWN_FUNCTION(fribidi) 85 | { 86 | return SUCCESS; 87 | } 88 | /* }}} */ 89 | 90 | /* {{{ PHP_MINFO_FUNCTION 91 | */ 92 | PHP_MINFO_FUNCTION(fribidi) 93 | { 94 | php_info_print_table_start(); 95 | php_info_print_table_header(2, "FriBidi support", "enabled"); 96 | php_info_print_table_row(2, "FriBidi version", FRIBIDI_VERSION); 97 | php_info_print_table_row(2, "Extension version", PHP_FRIBIDI_VERSION); 98 | php_info_print_table_end(); 99 | } 100 | /* }}} */ 101 | 102 | /* {{{ internal helper funcations 103 | */ 104 | 105 | static inline zend_bool 106 | _direction_is_validate(direction) 107 | { 108 | switch (direction) { 109 | case FRIBIDI_PAR_ON: 110 | case FRIBIDI_PAR_LTR: 111 | case FRIBIDI_PAR_RTL: 112 | case FRIBIDI_PAR_WLTR: 113 | case FRIBIDI_PAR_WRTL: 114 | return 1; 115 | } 116 | return 0; 117 | } 118 | 119 | #define _validate_direction(direction) \ 120 | { \ 121 | if (!_direction_is_validate(direction)) { \ 122 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown direction."); \ 123 | RETURN_FALSE; \ 124 | } \ 125 | } 126 | 127 | static inline zend_bool 128 | _charset_is_validate(charset) 129 | { 130 | switch (charset) { 131 | case FRIBIDI_CHAR_SET_UTF8: 132 | case FRIBIDI_CHAR_SET_ISO8859_6: 133 | case FRIBIDI_CHAR_SET_ISO8859_8: 134 | case FRIBIDI_CHAR_SET_CP1255: 135 | case FRIBIDI_CHAR_SET_CP1256: 136 | case FRIBIDI_CHAR_SET_CAP_RTL: 137 | return 1; 138 | } 139 | return 0; 140 | } 141 | 142 | #define _validate_charset(charset) \ 143 | { \ 144 | if (!_charset_is_validate(charset)) { \ 145 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown charset."); \ 146 | RETURN_FALSE; \ 147 | } \ 148 | } 149 | 150 | /* }}} */ 151 | 152 | /* 153 | + -----------------------------------------------------------+ 154 | | Name: fribidi_log2vis | 155 | | Purpose: convert a logical string to a visual one | 156 | | Input: 1) The logical string. | 157 | | 2) Base direction - | 158 | | Possible values: | 159 | | FRIBIDI_AUTO - autodetected by the Unicode | 160 | | Bidirection Algorithm (UBA). | 161 | | FRIBIDI_LTR - left to right. | 162 | | FRIBIDI_RTL - right to left. | 163 | | FRIBIDI_WLTR - week left to right. | 164 | | FRIBIDI_WRTL - week right to left. | 165 | | 3) Character code being used - | 166 | | Possible values (i.e., charsets supported) | 167 | | FRIBIDI_CHARSET_UTF8 | 168 | | FRIBIDI_CHARSET_8859_6 | 169 | | FRIBIDI_CHARSET_8859_8 | 170 | | FRIBIDI_CHARSET_CP1255 | 171 | | FRIBIDI_CHARSET_CP1256 | 172 | | FRIBIDI_CHARSET_CAP_RTL | 173 | | | 174 | | Output: on success: The visual string. | 175 | | on failure: false | 176 | +------------------------------------------------------------+ 177 | */ 178 | 179 | /* {{{ proto string fribidi_log2vis(string logical_str, long direction, long charset) 180 | Convert a logical string to a visual one */ 181 | PHP_FUNCTION(fribidi_log2vis) 182 | { 183 | char *logical_str, *visual_str; 184 | long charset, direction; 185 | int logical_str_len, visual_str_len, ustr_len; 186 | FriBidiParType base_direction; 187 | FriBidiLevel status; 188 | FriBidiChar *logical_ustr, *visual_ustr; 189 | 190 | // Read and validate parameters 191 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sll", &logical_str, &logical_str_len, &direction, &charset) == FAILURE) 192 | WRONG_PARAM_COUNT; 193 | _validate_direction(direction); 194 | _validate_charset(charset); 195 | 196 | // Convert input string to internal Unicode 197 | logical_ustr = (FriBidiChar*) emalloc(sizeof(FriBidiChar) * logical_str_len); 198 | ustr_len = fribidi_charset_to_unicode(charset, logical_str, logical_str_len, logical_ustr); 199 | 200 | // Visualize the Unicode string 201 | base_direction = direction; 202 | visual_ustr = (FriBidiChar*) emalloc(sizeof(FriBidiChar) * ustr_len); 203 | status = fribidi_log2vis(logical_ustr, ustr_len, &base_direction, visual_ustr, NULL, NULL, NULL); 204 | efree(logical_ustr); 205 | 206 | // Return false if FriBidi failed 207 | if (status == 0) { 208 | efree(visual_ustr); 209 | RETURN_FALSE; 210 | } 211 | 212 | // Convert back from internal Unicode to original character set 213 | visual_str_len = 4 * ustr_len; // FriBidi doesn't generate UTF-8 chars longer than 4 bytes 214 | visual_str = (char *) emalloc(sizeof(char) * visual_str_len); 215 | visual_str_len = fribidi_unicode_to_charset(charset, visual_ustr, ustr_len, visual_str); 216 | efree(visual_ustr); 217 | 218 | // Return the result 219 | RETURN_STRINGL(visual_str, visual_str_len, 0); 220 | } 221 | /* }}} */ 222 | 223 | /* {{{ proto array fribidi_charset_info(int charset) 224 | Returns an array containing information about the specified charset */ 225 | PHP_FUNCTION(fribidi_charset_info) 226 | { 227 | long charset; 228 | 229 | // Read and validate parameters 230 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &charset) == FAILURE) 231 | WRONG_PARAM_COUNT; 232 | _validate_charset(charset); 233 | 234 | // Return the result 235 | array_init(return_value); 236 | add_assoc_string(return_value, "name", 237 | (char *)fribidi_char_set_name(charset), 1); 238 | add_assoc_string(return_value, "title", 239 | (char *)fribidi_char_set_title(charset), 1); 240 | if (fribidi_char_set_desc(charset)) 241 | add_assoc_string(return_value, "desc", 242 | (char *)fribidi_char_set_desc(charset), 1); 243 | } 244 | /* }}} */ 245 | 246 | /* {{{ proto array fribidi_get_charsets() 247 | Returns an array containing available charsets */ 248 | PHP_FUNCTION(fribidi_get_charsets) 249 | { 250 | array_init(return_value); 251 | add_index_string(return_value, FRIBIDI_CHAR_SET_UTF8, "FRIBIDI_CHARSET_UTF8", 1); 252 | add_index_string(return_value, FRIBIDI_CHAR_SET_ISO8859_6, "FRIBIDI_CHARSET_8859_6", 1); 253 | add_index_string(return_value, FRIBIDI_CHAR_SET_ISO8859_8, "FRIBIDI_CHARSET_8859_8", 1); 254 | add_index_string(return_value, FRIBIDI_CHAR_SET_CP1255, "FRIBIDI_CHARSET_CP1255", 1); 255 | add_index_string(return_value, FRIBIDI_CHAR_SET_CP1256, "FRIBIDI_CHARSET_CP1256", 1); 256 | add_index_string(return_value, FRIBIDI_CHAR_SET_CAP_RTL, "FRIBIDI_CHARSET_CAP_RTL", 1); 257 | } 258 | /* }}} */ 259 | 260 | #endif /* HAVE_FRIBIDI */ 261 | 262 | /* 263 | * Local variables: 264 | * tab-width: 4 265 | * c-basic-offset: 4 266 | * End: 267 | * vim600: sw=4 ts=4 fdm=marker 268 | * vim<600: sw=4 ts=4 269 | */ 270 | --------------------------------------------------------------------------------