character pairs such as parenthesis in Farsi (a patch)

2007-06-20 Thread Mostafa Vahedi
Currently (only) Unicode is used for Farsi as the input encoding. Moreover in 
Unicode the openning parenthesis is always the left one (independent of the 
language) I have modified the code to reverse the direction of the 
character-pairs when it wants to display the characters whenever the language 
is Arabic or Farsi. Maybe the direction should be changed only when the 
language is Farsi (not Arabic), but only one parameter, i.e. bool Arabic, is 
sent to the function). 

Mostafa

Index: rowpainter.cpp

===

--- rowpainter.cpp(revision 18837)

+++ rowpainter.cpp(working copy)

@@ -302,6 +302,46 @@

 }
 
 
+char_type reverseCharPair(char_type ch)
+{
+char_type uc = ch;
+
+switch (ch) {
+case '(':
+uc = ')';
+break;
+case ')':
+uc = '(';
+break;
+case '[':
+uc = ']';
+break;
+case ']':
+uc = '[';
+break;
+case '{':
+uc = '}';
+break;
+case '}':
+uc = '{';
+break;
+case '<':
+uc = '>';
+break;
+case '>':
+uc = '<';
+break;
+case 187:
+uc = 171;
+break;
+case 171:
+uc = 187;
+break;
+}
+
+return uc;
+}
+
 void RowPainter::paintChars(pos_type & vpos, Font const & font,
 bool hebrew, bool arabic)
 {
@@ -318,10 +358,7 @@

 
 if (arabic) {
 char_type c = str[0];
-if (c == '(')
-c = ')';
-else if (c == ')')
-c = '(';
+c = reverseCharPair(c);
 str[0] = par_.transformChar(c, pos);
 }
 
@@ -366,10 +403,7 @@

 */
 
 if (arabic) {
-if (c == '(')
-c = ')';
-else if (c == ')')
-c = '(';
+c = reverseCharPair(c);
 c = par_.transformChar(c, pos);
 /* see comment in hebrew, explaining why we break */
 break;

   
-
Boardwalk for $500? In 2007? Ha! 
Play Monopoly Here and Now (it's updated for today's economy) at Yahoo! Games.

Re: character pairs such as parenthesis in Farsi (a patch)

2007-06-21 Thread Dov Feldstern

Mostafa Vahedi wrote:
Currently (only) Unicode is used for Farsi as the input encoding. Moreover in Unicode the openning parenthesis is always the left one (independent of the language) I have modified the code to reverse the direction of the character-pairs when it wants to display the characters whenever the language is Arabic or Farsi. Maybe the direction should be changed only when the language is Farsi (not Arabic), but only one parameter, i.e. bool Arabic, is sent to the function). 


Mostafa


Hi Mostafa!

This patch looks good, but I'm not sure that it should be applied for 
Arabic. Currently (before applying your patch, but with what you 
previously put in already in place) I'm getting backwards parentheses in 
Arabic. As I see it, there are two ways to go about solving this:


1) If the parentheses really do need to be reversed when using Unicode 
input (I'm not set up for Unicode input, I don't think, so I can't test 
this), then the patch *should* be applied also for arabic. Then, 
however, when using the keymap, parentheses are backwards --- but we can 
just fix that in the keymap itself, by adding


\kmap ( )
\kmap ) (

2) If for Arabic Unicode the patch should not be applied, then it should 
be applied only for farsi.


Either way, it probably wouldn't be a bad idea to add a separate bool 
variable for farsi --- there's no real reason why farsi and arabic 
should share the variable...


(I haven't tried your patch, because I'm having trouble with the spacing 
copying it from the email. Could you attach it --- or one modified 
according to the above suggestions -- as an attachment next time, then 
I'll test it.)


Dov



Re: character pairs such as parenthesis in Farsi (a patch)

2007-06-22 Thread Mostafa Vahedi

Mostafa Vahedi wrote:
>> Currently (only) Unicode is used for Farsi as the input 
>> encoding. Moreover in Unicode the openning parenthesis 
>> is always the left one (independent of the language) 
>> I have modified the code to reverse the direction of 
>> the character-pairs when it wants to display the 
>> characters whenever the language is Arabic or Farsi. 
>> Maybe the direction should be changed only when the 
>> language is Farsi (not Arabic), but only one parameter, 
>> i.e. bool Arabic, is sent to the function).  
> Mostafa

> Hi Mostafa!

> This patch looks good, but I'm not sure that it 
> should be applied for Arabic. Currently (before 
> applying your patch, but with what you previously 
> put in already in place) I'm getting backwards 
> parentheses in Arabic. As I see it, there are two 
> ways to go about solving this:

> 1) If the parentheses really do need to be reversed 
> when using Unicode input (I'm not set up for Unicode 
> input, I don't think, so I can't test this), then 
> the patch *should* be applied also for arabic. Then, 
> however, when using the keymap, parentheses are 
> backwards --- but we can just fix that in the keymap 
> itself, by adding

> \kmap ( )
> \kmap ) (

> 2) If for Arabic Unicode the patch should not be 
> applied, then it should be applied only for farsi.

> Either way, it probably wouldn't be a bad idea to 
> add a separate bool variable for farsi --- there's 
> no real reason why farsi and arabic should share 
> the variable...

> (I haven't tried your patch, because I'm having 
> trouble with the spacing copying it from the email. 
> Could you attach it --- or one modified according 
> to the above suggestions -- as an attachment next 
> time, then I'll test it.)

> Dov

Dear Dov,

The problem is independent of the language, rather
it depends on the encoding. In other
words it does not depend on Arabic or Farsi
but it depends on the encoding we would like to save
our texts.
First we should make it clear for ourselves what the
internal encoding of the LyX file (not the LaTeX file) 
is. 
If it is Unicode then we should obey the unicode 
rules. In Unicode we always use the LATIN-left 
paranthesis as the opening one but during the 
representation or display we consider the context 
and display the correct one.

Clearly there is some sort of encoding mapping during
the generation of the LaTeX file. In my opinion
there we should change the direction of the 
paranthesis in case it is needed.

What is the internal encoding of a LyX file? Where is
the point at which we can consider reversing the 
direction of the character pairs when converting a LyX 
file to a LaTeX file in case it is needed?



   
-
Moody friends. Drama queens. Your life? Nope! - their life, your story.
 Play Sims Stories at Yahoo! Games. 

rowpainter.diff
Description: 990053006-rowpainter.diff


Re: character pairs such as parenthesis in Farsi (a patch)

2007-06-22 Thread Dov Feldstern

Mostafa Vahedi wrote:

Mostafa Vahedi wrote:
Currently (only) Unicode is used for Farsi as the input 
encoding. Moreover in Unicode the openning parenthesis 
is always the left one (independent of the language) 
I have modified the code to reverse the direction of 
the character-pairs when it wants to display the 
characters whenever the language is Arabic or Farsi. 


 Maybe the direction should be changed
 only when the 
language is Farsi (not Arabic), but only one parameter, 
i.e. bool Arabic, is sent to the function).  

Mostafa



Hi Mostafa!


This patch looks good, but I'm not sure that it 
should be applied for Arabic. Currently (before 
applying your patch, but with what you previously 
put in already in place) I'm getting backwards 
parentheses in Arabic. As I see it, there are two 
ways to go about solving this:


1) If the parentheses really do need to be reversed 
when using Unicode input (I'm not set up for Unicode 
input, I don't th
 ink, so I can't test this), then 

the patch *should* be applied also for arabic.
 Then, 
however, when using the keymap, parentheses are 
backwards --- but we can just fix that in the keymap 
itself, by adding



\kmap ( )
\kmap ) (


2) If for Arabic Unicode the patch should not be 
applied, then it should be applied only for farsi.


Either way, it probably wouldn't be a bad idea to 
add a separate bool variable for farsi --- there's 
no real reason why farsi and arabic should share 
the variable...


(I haven't tried your patch, because I'm having 
trouble with the spacing copying it from the email. 
Could you attach it --- or one modified according 
to the above suggestions -- as an attachment next 
time, then I'll test it.)



Dov


Dear Dov,

The problem is independent of the language, rather
it depends on
  the encoding. In other
words it does not depend on Arabic or Farsi
but it depends
 on the encoding we would like to save
our texts.
First we should make it clear for ourselves what the
internal encoding of the LyX file (not the LaTeX file) 
is. 
If it is Unicode then we should obey the unicode 
rules. In Unicode we always use the LATIN-left 
paranthesis as the opening one but during the 
representation or display we consider the context 
and display the correct one.


Clearly there is some sort of encoding mapping during
the generation of the LaTeX file. In my opinion
there we should change the direction of the 
paranthesis in case it is needed.


What is the internal encoding of a LyX file? Where is
the point at which we can consider reversing the 
direction of the character pairs when converting a LyX 
file to a LaTeX file in case it is needed?




Mostafa, your explanation sounds good. I don't really know enough about 
this to be helpful (as the whole ArabTeX business shows :( ). If you 
send in patches, I will test them and let you know if they are OK in 
terms of the user experience as it seems to me that it should be.


Currently, the user experience in Hebrew is good, in Arabic (both 
ArabTeX and Arabi) it is not (in both cases, using *keymap* input). Your 
patch I like in terms of the code, but of course it doesn't change the 
user experience in Arabic. Hebrew remains untouched, which is good. If 
you are able to solve this for Arabic, then probably it should be 
applied to Hebrew as well. Again, I'll test patches.


Dov



Re: character pairs such as parenthesis in Farsi (a patch)

2007-06-23 Thread Abdelrazak Younes

Mostafa Vahedi wrote:


What is the internal encoding of a LyX file?


UTF8, in any case and whatever encoding is used for LateX. UTF32 (aka 
ucs4) is used internally.


Abdel.