Skip to content

Commit 23a7783

Browse files
committed
By EbraSha
1 parent d03dee1 commit 23a7783

5 files changed

Lines changed: 42 additions & 65 deletions

File tree

README.fa.md

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010

1111
## 📖 درباره پروژه
1212

13-
**Abdal Phpian Render** یک پکیج جامع PHP برای اصلاح و بهبود نمایش متون فارسی و عربی در محیط‌های گرافیکی است. این پکیج مشکلات رایج نمایش متن در کتابخانه‌هایی مانند GD Library، FPDF و TCPDF را حل می‌کند و پشتیبانی کامل از راست‌به‌چپ (RTL) را فراهم می‌آورد.
13+
**Abdal Phpian Render** یک پکیج جامع PHP برای اصلاح و بهبود نمایش متون فارسی در محیط‌های گرافیکی است. این پکیج مشکلات رایج نمایش متن در کتابخانه‌هایی مانند GD Library، FPDF و TCPDF را حل می‌کند و پشتیبانی کامل از راست‌به‌چپ (RTL) را فراهم می‌آورد.
1414

1515
### 🎯 چرا این نرم‌افزار ساخته شد؟
1616

17-
هنگام کار با متون فارسی و عربی در محیط‌های گرافیکی PHP، مشکلات متعددی وجود دارد:
17+
هنگام کار با متون فارسی در محیط‌های گرافیکی PHP، مشکلات متعددی وجود دارد:
1818

19-
- **مشکل نمایش حروف**: حروف فارسی/عربی به صورت جداگانه و بدون اتصال نمایش داده می‌شوند
19+
- **مشکل نمایش حروف**: حروف فارسی به صورت جداگانه و بدون اتصال نمایش داده می‌شوند
2020
- **مشکل ترتیب نمایش**: در متون ترکیبی (فارسی + انگلیسی) ترتیب کلمات به درستی نمایش داده نمی‌شود
2121
- **مشکل اعداد**: اعداد انگلیسی در متن فارسی ظاهر می‌شوند
2222
- **مشکل علائم نگارشی**: پرانتز، براکت و سایر علائم در جهت اشتباه نمایش داده می‌شوند
23-
- **از دست رفتن اعراب**: اعراب عربی در فرآیند پردازش از بین می‌روند
23+
- **از دست رفتن اعراب**: اعراب فارسی در فرآیند پردازش از بین می‌روند
2424

2525
این پکیج تمام این مشکلات را حل می‌کند و یک راه‌حل کامل و استاندارد برای رندر متون RTL ارائه می‌دهد.
2626

@@ -30,7 +30,7 @@
3030

3131
- ✅ تبدیل حروف به اشکال چهارگانه (isolated, final, initial, medial)
3232
- ✅ پشتیبانی کامل از حروف اختصاصی فارسی (پ، چ، گ، ژ)
33-
- ✅ پشتیبانی از ترکیبات خاص عربی (لا، لآ، لأ، لإ)
33+
- ✅ پشتیبانی از ترکیبات Lam-Alef فارسی (لا، لآ)
3434
- ✅ حفظ اعراب در فرآیند reshaping
3535

3636
### 🔄 الگوریتم BiDi (Bidirectional)
@@ -42,8 +42,7 @@
4242
### 🔢 تبدیل اعداد (Number Converter)
4343

4444
- ✅ تبدیل اعداد انگلیسی به فارسی
45-
- ✅ تبدیل اعداد انگلیسی به عربی
46-
- ✅ تبدیل خودکار اعداد فارسی/عربی به انگلیسی (برای محاسبات)
45+
- ✅ تبدیل خودکار اعداد فارسی به انگلیسی (برای محاسبات)
4746

4847
### 🔣 مدیریت اعراب (Diacritics Handler)
4948

@@ -80,7 +79,7 @@ composer require abdal/phpian-render
8079
```json
8180
{
8281
"require": {
83-
"abdal/phpian-render": "^1.3"
82+
"abdal/phpian-render": "^1.4"
8483
}
8584
}
8685
```
@@ -121,7 +120,7 @@ $processed = $renderer->process($text, [
121120
'reshape' => true, // فعال‌سازی reshaping
122121
'bidi' => true, // فعال‌سازی bidirectional
123122
'convertNumbers' => true, // تبدیل اعداد
124-
'numberLocale' => 'persian', // 'persian' یا 'arabic'
123+
'numberLocale' => 'persian', // فقط 'persian' پشتیبانی می‌شود
125124
'preserveDiacritics' => true, // حفظ اعراب
126125
'clean' => false, // پاکسازی کاراکترهای نامرئی
127126
]);
@@ -156,10 +155,6 @@ $renderer = new PhpianRender();
156155
$text = 'عدد 123 است';
157156
$persian = $renderer->convertNumbers($text, 'persian');
158157
echo $persian; // خروجی: عدد ۱۲۳ است
159-
160-
// تبدیل به عربی
161-
$arabic = $renderer->convertNumbers($text, 'arabic');
162-
echo $arabic; // خروجی: عدد ١٢٣ است
163158
```
164159

165160
### پردازش BiDi برای متون ترکیبی
@@ -236,7 +231,7 @@ $processed = PhpianRender::processStatic($text, [
236231
'reshape' => true, // فعال‌سازی reshaping
237232
'bidi' => true, // فعال‌سازی bidirectional
238233
'convertNumbers' => true, // تبدیل اعداد
239-
'numberLocale' => 'persian', // 'persian' یا 'arabic'
234+
'numberLocale' => 'persian', // فقط 'persian' پشتیبانی می‌شود
240235
'preserveDiacritics' => true, // حفظ اعراب
241236
'clean' => false, // پاکسازی کاراکترهای نامرئی
242237
'reverse' => true, // معکوس کردن متن برای نمایش RTL

README.md

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010

1111
## 📖 About the Project
1212

13-
**Abdal Phpian Render** is a comprehensive PHP package for fixing and improving the display of Persian and Arabic texts in graphical environments. This package solves common text display issues in libraries such as GD Library, FPDF, and TCPDF, providing full Right-to-Left (RTL) support.
13+
**Abdal Phpian Render** is a comprehensive PHP package for fixing and improving the display of Persian texts in graphical environments. This package solves common text display issues in libraries such as GD Library, FPDF, and TCPDF, providing full Right-to-Left (RTL) support.
1414

1515
### 🎯 Why This Software Was Created?
1616

17-
When working with Persian and Arabic texts in PHP graphical environments, several problems arise:
17+
When working with Persian texts in PHP graphical environments, several problems arise:
1818

19-
- **Character Display Issues**: Persian/Arabic letters are displayed separately without proper connection
19+
- **Character Display Issues**: Persian letters are displayed separately without proper connection
2020
- **Display Order Problems**: In mixed texts (Persian + English), word order is not displayed correctly
2121
- **Number Issues**: English numbers appear in Persian text
2222
- **Punctuation Problems**: Parentheses, brackets, and other marks are displayed in the wrong direction
23-
- **Loss of Diacritics**: Arabic diacritics are lost during processing
23+
- **Loss of Diacritics**: Persian diacritics are lost during processing
2424

2525
This package solves all these problems and provides a complete and standard solution for rendering RTL texts.
2626

@@ -30,7 +30,7 @@ This package solves all these problems and provides a complete and standard solu
3030

3131
- ✅ Convert characters to four forms (isolated, final, initial, medial)
3232
- ✅ Full support for Persian-specific characters (پ, چ, گ, ژ)
33-
- ✅ Support for special Arabic combinations (لا, لآ, لأ, لإ)
33+
- ✅ Support for Persian Lam-Alef combinations (لا, لآ)
3434
- ✅ Preserve diacritics during reshaping
3535

3636
### 🔄 BiDi (Bidirectional) Algorithm
@@ -42,8 +42,7 @@ This package solves all these problems and provides a complete and standard solu
4242
### 🔢 Number Converter
4343

4444
- ✅ Convert English numbers to Persian
45-
- ✅ Convert English numbers to Arabic
46-
- ✅ Automatic conversion of Persian/Arabic numbers to English (for calculations)
45+
- ✅ Automatic conversion of Persian numbers to English (for calculations)
4746

4847
### 🔣 Diacritics Handler
4948

@@ -80,7 +79,7 @@ Or add to `composer.json`:
8079
```json
8180
{
8281
"require": {
83-
"abdal/phpian-render": "^1.3"
82+
"abdal/phpian-render": "^1.4"
8483
}
8584
}
8685
```
@@ -121,7 +120,7 @@ $processed = $renderer->process($text, [
121120
'reshape' => true, // Enable reshaping
122121
'bidi' => true, // Enable bidirectional
123122
'convertNumbers' => true, // Convert numbers
124-
'numberLocale' => 'persian', // 'persian' or 'arabic'
123+
'numberLocale' => 'persian', // Only 'persian' is supported
125124
'preserveDiacritics' => true, // Preserve diacritics
126125
'clean' => false, // Clean invisible characters
127126
]);
@@ -156,10 +155,6 @@ $renderer = new PhpianRender();
156155
$text = 'عدد 123 است';
157156
$persian = $renderer->convertNumbers($text, 'persian');
158157
echo $persian; // Output: عدد ۱۲۳ است
159-
160-
// Convert to Arabic
161-
$arabic = $renderer->convertNumbers($text, 'arabic');
162-
echo $arabic; // Output: عدد ١٢٣ است
163158
```
164159

165160
### BiDi Processing for Mixed Texts
@@ -236,7 +231,7 @@ $processed = PhpianRender::processStatic($text, [
236231
'reshape' => true, // Enable reshaping
237232
'bidi' => true, // Enable bidirectional
238233
'convertNumbers' => true, // Convert numbers
239-
'numberLocale' => 'persian', // 'persian' or 'arabic'
234+
'numberLocale' => 'persian', // Only 'persian' is supported
240235
'preserveDiacritics' => true, // Preserve diacritics
241236
'clean' => false, // Clean invisible characters
242237
'reverse' => true, // Reverse text for RTL display

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "abdal/phpian-render",
33
"description": "Comprehensive PHP package for Persian/Arabic text rendering in graphical environments with RTL support",
44
"type": "library",
5-
"version": "1.4.0",
5+
"version": "1.4.1",
66
"keywords": [
77
"persian",
88
"arabic",

src/Reshaper.php

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class Reshaper
5858
"\u{063A}" => ["\u{FECD}", "\u{FECE}", "\u{FECF}", "\u{FED0}"], // غ
5959
"\u{0641}" => ["\u{FED1}", "\u{FED2}", "\u{FED3}", "\u{FED4}"], // ف
6060
"\u{0642}" => ["\u{FED5}", "\u{FED6}", "\u{FED7}", "\u{FED8}"], // ق
61-
"\u{06A9}" => ["\u{FED9}", "\u{FEDA}", "\u{FEDB}", "\u{FEDC}"], // ک (Persian Kaf)
61+
"\u{06A9}" => ["\u{FB8E}", "\u{FB8F}", "\u{FB90}", "\u{FB91}"], // ک (Persian Kaf)
6262
"\u{0644}" => ["\u{FEDD}", "\u{FEDE}", "\u{FEDF}", "\u{FEE0}"], // ل
6363
"\u{0645}" => ["\u{FEE1}", "\u{FEE2}", "\u{FEE3}", "\u{FEE4}"], // م
6464
"\u{0646}" => ["\u{FEE5}", "\u{FEE6}", "\u{FEE7}", "\u{FEE8}"], // ن
@@ -74,9 +74,9 @@ class Reshaper
7474
// Persian Yeh (ی)
7575
// Format: [isolated, final, initial, medial]
7676
// U+06CC: Persian Yeh (ی)
77-
// Based on PersianRender.php: 'ی' => ['ی', 'ی', 'ی'] which means all forms are filled
78-
// All forms are filled to allow proper connection to other characters
79-
"\u{06CC}" => ["\u{06CC}", "\u{06CC}", "\u{06CC}", "\u{06CC}"], // ی (Persian Yeh) - all forms filled for connection
77+
// Correct Unicode Presentation Forms-B for Persian Yeh:
78+
// Isolated: FBFC, Final: FBFD, Initial: FBFE, Medial: FBFF
79+
"\u{06CC}" => ["\u{FBFC}", "\u{FBFD}", "\u{FBFE}", "\u{FBFF}"], // ی (Persian Yeh)
8080
];
8181

8282
/**
@@ -208,10 +208,9 @@ private function separateDiacritics(array $chars): array
208208

209209
/**
210210
* Determine the form of a character (isolated, final, initial, medial)
211-
* Based on correct logic similar to PersianRender.php:
212-
* - Check if previous character can connect forward (has initial form)
213-
* - Check if current character can connect forward (has initial form)
214-
* - Check if next character can connect backward (has final form)
211+
* Simplified and corrected logic:
212+
* - Check if current character can connect to next (has initial form and next is valid)
213+
* - Check if previous character can connect to current (prev has initial form and current has final form)
215214
*
216215
* @param string $char Current character
217216
* @param string|null $prevChar Previous character
@@ -220,39 +219,27 @@ private function separateDiacritics(array $chars): array
220219
*/
221220
private function determineForm(string $char, ?string $prevChar, ?string $nextChar): int
222221
{
223-
$result = 0;
224-
225-
// Based on PersianRender.php logic:
226222
// Check if current character can connect forward (to next character)
227-
// Current character must have initial form (index 2) and next character must have final form (index 1)
228-
// In PersianRender: checks if char[2] exists and next[0] exists
229-
// In our format [isolated, final, initial, medial]: checks if char[2] exists and next[1] exists
230-
if ($nextChar !== null &&
231-
isset(self::CHARACTER_FORMS[$char]) &&
232-
isset(self::CHARACTER_FORMS[$nextChar]) &&
233-
self::CHARACTER_FORMS[$char][2] !== '' && // Current char has initial form (not empty)
234-
self::CHARACTER_FORMS[$nextChar][1] !== '') { // Next char has final form (not empty)
235-
$result += 4; // Can connect forward (initial)
236-
}
223+
// Current character must have initial form (index 2) and next character must be valid
224+
$connectsAfter = $nextChar !== null &&
225+
isset(self::CHARACTER_FORMS[$char]) &&
226+
isset(self::CHARACTER_FORMS[$nextChar]) &&
227+
self::CHARACTER_FORMS[$char][2] !== ''; // Current char has initial form
237228

238229
// Check if previous character can connect forward (to current character)
239230
// Previous character must have initial form (index 2) and current character must have final form (index 1)
240-
// In PersianRender: checks if char[0] exists and prev[2] exists
241-
// In our format: checks if char[1] exists and prev[2] exists
242-
if ($prevChar !== null &&
243-
isset(self::CHARACTER_FORMS[$prevChar]) &&
244-
isset(self::CHARACTER_FORMS[$char]) &&
245-
self::CHARACTER_FORMS[$prevChar][2] !== '' && // Previous char has initial form (not empty)
246-
self::CHARACTER_FORMS[$char][1] !== '') { // Current char has final form (not empty)
247-
$result += 2; // Can connect from previous (final)
248-
}
249-
250-
// Determine form based on result
251-
if ($result === 6) {
231+
$connectsBefore = $prevChar !== null &&
232+
isset(self::CHARACTER_FORMS[$prevChar]) &&
233+
isset(self::CHARACTER_FORMS[$char]) &&
234+
self::CHARACTER_FORMS[$prevChar][2] !== '' && // Previous char has initial form
235+
self::CHARACTER_FORMS[$char][1] !== ''; // Current char has final form
236+
237+
// Determine form based on connections
238+
if ($connectsBefore && $connectsAfter) {
252239
return 3; // Medial (connected from both sides)
253-
} elseif ($result === 4) {
240+
} elseif ($connectsAfter) {
254241
return 2; // Initial (connects to next)
255-
} elseif ($result === 2) {
242+
} elseif ($connectsBefore) {
256243
return 1; // Final (connected from previous)
257244
} else {
258245
return 0; // Isolated (no connections)

src/Version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Version
3131
* MINOR: New features (backward compatible)
3232
* PATCH: Bug fixes
3333
*/
34-
public const VERSION = '1.4.0';
34+
public const VERSION = '1.4.1';
3535

3636
/**
3737
* Get current version

0 commit comments

Comments
 (0)