Recent

Author Topic: Hebrew entries  (Read 11748 times)

rick2691

  • Sr. Member
  • ****
  • Posts: 375
Hebrew entries
« on: August 17, 2016, 08:01:18 pm »
This is an OnKeyPress procedure to enter Hebrew UTF8 characters. It does the entries for a few consonants and vowels.... Consonants: ', b, g, d, and Vowels: i, e, a.

I have tried various methods but this is the only one that works. Its problem is that the cursor does not move with the entires. Nothing that I do can move it. I have have tried OnKeyDown, OnKeyUp, and Windows Widgets.

Apparently it does nothing until the procedure exits, and then it does all of the standing entries. It treats OnKeyUp as an extension of OnKeyDown and OnKeyPress, not doing any thin until all events have finished, and using only the standing settings.

It also does an illogical left-arrow and right-arrow. Left should be left, and right should be right. When moving by arrow keys it also gets lost on where it should be.

Additionally, I cannot enter a period, space, nor any other character that would separate words. It treats them as English and garbages the natural Right-to-Left flow.

Code: Pascal  [Select]
  1. procedure TCmdForm.CheckLanguage(Sender: TObject; var Key: char);
  2. var Hkey, HebrewOn: boolean;
  3. begin
  4.   HebrewOn:= true;  // this normally set globally
  5.   if HebrewOn then
  6.      begin
  7.      LastCursorPos:= PageMemo.SelStart;
  8.      Hkey:= false;
  9.      Case Key of
  10.        {'}#39 : begin PageMemo.SelText:= UnicodeToUTF8(1488); Hkey:= true; end; // alf
  11.           'b' : begin PageMemo.SelText:= UnicodeToUTF8(1489); Hkey:= true; end; // bth
  12.           'g' : begin PageMemo.SelText:= UnicodeToUTF8(1490); Hkey:= true; end; // gml
  13.           'd' : begin PageMemo.SelText:= UnicodeToUTF8(1491); Hkey:= true; end; // dlt
  14.          
  15.           'i' : begin PageMemo.SelText:= UnicodeToUTF8(1460); Hkey:= true; end;  // xrk
  16.           'e' : begin PageMemo.SelText:= UnicodeToUTF8(1462); Hkey:= true; end;  // sgl
  17.           'a' : begin PageMemo.SelText:= UnicodeToUTF8(1463); Hkey:= true; end;  // ptx
  18.  
  19.           '.' : begin PageMemo.SelText:= '.'; Hkey:= true; end;
  20.           ' ' : begin PageMemo.SelText:= ' '; Hkey:= true; end;
  21.           end;
  22.      if Hkey then
  23.         begin
  24.          Key:= #0;
  25.          PageMemo.SelStart:= PageMemo.SelStart+1;
  26.          PageMemo.SelLength:= 0;
  27.          PageMemo.setfocus;
  28.         end;
  29.      end;
  30. end;
  31.  

I have searched for methods that might apply, and nothing is applicable.

Rick
« Last Edit: August 17, 2016, 08:08:18 pm by rick2691 »
Windows 10, LAZ 1.6.4, FPC 3.0.2, SVN 54278, i386-win32-win32/win64, forms use windows unit

rick2691

  • Sr. Member
  • ****
  • Posts: 375
Re: Hebrew entries
« Reply #1 on: August 17, 2016, 08:21:59 pm »
I think I should add that I understand Hebrew and Syiac/Aramaic. Long ago I built a Hebrew/English editor with Turbo Pascal and the CPM operating system. Doing so I had to construct all of the character glyphs, and manage the natural flow of both languages, and perform mixed language word wrapping. It was flawless.

But with this I seem to be fighting the FCL, Windows, and the Font builders. They want to handle handle it but they don't seem to know how it is supposed to happen.

Rick
Windows 10, LAZ 1.6.4, FPC 3.0.2, SVN 54278, i386-win32-win32/win64, forms use windows unit

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2282
    • havefunsoft.com
Re: Hebrew entries
« Reply #2 on: August 17, 2016, 08:40:12 pm »
Hmm... A quick test - how does it work for you in Wordpad and Notepad ?
---added---
It seems like WordPad is faulty.
Notepad can work properly, but only if Text itself is set RTL mode.
« Last Edit: August 17, 2016, 08:47:04 pm by skalogryz »
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2282
    • havefunsoft.com
Re: Hebrew entries
« Reply #3 on: August 17, 2016, 08:58:57 pm »
try to change BidiMode property of RichMemo to bdRightToLeft.

It might produce the results you'd like to see, but could be bad for mixed (LTR/RTL) texts.
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

rick2691

  • Sr. Member
  • ****
  • Posts: 375
Re: Hebrew entries
« Reply #4 on: August 18, 2016, 01:20:05 pm »
I had already tried BidiMode. All it does is place the scrollbar on the left side. Nothing to do with typing.
Windows 10, LAZ 1.6.4, FPC 3.0.2, SVN 54278, i386-win32-win32/win64, forms use windows unit

rick2691

  • Sr. Member
  • ****
  • Posts: 375
Re: Hebrew entries
« Reply #5 on: August 18, 2016, 01:48:29 pm »
With Windows XP, Notepad and WordPad do not have any language modes, except when you activate a language keyboard at the system level... uggh!

I have noticed the arrow-key behavior with mixed left and right texts documents. That is why professional "mixed left and right" programs don't normally use the Windows functions. They have to be overridden. I suspect that the FCL might be too helpful as well.

Rick
Windows 10, LAZ 1.6.4, FPC 3.0.2, SVN 54278, i386-win32-win32/win64, forms use windows unit

rick2691

  • Sr. Member
  • ****
  • Posts: 375
Re: Hebrew entries
« Reply #6 on: August 18, 2016, 02:24:40 pm »
It seems to me that all "events" are operating on a "wait until exit" mode. Nothing gets done sequentially. Only the final commands are executed. So you can't set a cursor position in several places during an assumed serial process. It is the same way that CutToClipboard can't be coded into a serial process. It waits for an "everything is done" signal, which is a user interaction.

Maybe things could work if that signal could be coded... and doing so didn't make you exit the code.

Rick
Windows 10, LAZ 1.6.4, FPC 3.0.2, SVN 54278, i386-win32-win32/win64, forms use windows unit

rick2691

  • Sr. Member
  • ****
  • Posts: 375
Re: Hebrew entries
« Reply #7 on: August 18, 2016, 02:51:34 pm »
OK. I did find a way to simulate what is happening with WordPad. I did a series of ALT-1489, ALT-1490, etc. It inserted the characters in a right-to-left manner, and did not advance the cursor. So it is either a Windows issue or the Windows RichEdit server.

I simply need to be able to code a cursor position. Then there is the issue of it not thinking that Hebrew can have a space, period, slash etc. as separation characters.
Windows 10, LAZ 1.6.4, FPC 3.0.2, SVN 54278, i386-win32-win32/win64, forms use windows unit

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2282
    • havefunsoft.com
Re: Hebrew entries
« Reply #8 on: August 18, 2016, 02:59:07 pm »
I had already tried BidiMode. All it does is place the scrollbar on the left side. Nothing to do with typing.
Besides of switching the layout, it should also adjust the navigation rules.
Thus left will become left again and right will become right... of RTL text of course.

I have noticed the arrow-key behavior with mixed left and right texts documents. That is why professional "mixed left and right" programs don't normally use the Windows functions. They have to be overridden.
If you'd ask me, it's lack of information on what the "expected" behavior would be.
It might be that Windows RichEdit has proper APIs to make the text to behave properly.

I suspect that the FCL might be too helpful as well.
What's FCL?

Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

rick2691

  • Sr. Member
  • ****
  • Posts: 375
Re: Hebrew entries
« Reply #9 on: August 18, 2016, 03:37:53 pm »
Quote
What's FCL?

Sorry, I am abbreviations challenged. It's all alphabet soup to me... I think I meant FPC, as in the Lazarus compiler.

I came across this method by a keyboard layout user... "place an invisible mark at the end of your paragraph identifying your text as RTL. To do so, use the “End” key to move to the end of the line, and press ALT+CTRL 9. This sets an invisible RTL code at the end of the line, so periods and other punctuation should now display correctly."

Is this something that RichMemo will recognize? If so, will it work for the end of an RTL string series (as embedded within an LTR paragraph)? Likewise, can it be coded into the document?

Rick

Windows 10, LAZ 1.6.4, FPC 3.0.2, SVN 54278, i386-win32-win32/win64, forms use windows unit

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2282
    • havefunsoft.com
Re: Hebrew entries
« Reply #10 on: August 18, 2016, 04:01:59 pm »
To do so, use the “End” key to move to the end of the line, and press ALT+CTRL 9. This sets an invisible RTL code at the end of the line, so periods and other punctuation should now display correctly."
I don't think richedit recognizes Alt+ctrl 9 as a shortcut.
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2282
    • havefunsoft.com
Re: Hebrew entries
« Reply #11 on: August 18, 2016, 04:07:30 pm »
You might want to try this code. It changes a current (where SelStart is) paragraph to RTL (or LTR). It didn't give my any good results though.

Code: Pascal  [Select]
  1. uses ...Windows , richedit ..
  2. ...
  3.  
  4. procedure MakeRTLPara(rm: TRichMemo; isRTL: Boolean);
  5. var
  6.   p: PARAFORMAT2;
  7.   res: Integer;
  8. const
  9.   RTLFlag : array [Boolean] of word = (0, PFE_RTLPARA);
  10. begin
  11.   FillChar(p, sizeof(p), 0);
  12.   p.cbSize:=sizeof(p);
  13.   p.dwMask:=p.dwMask or PFM_RTLPARA;
  14.   p.wEffects:=p.wEffects or RTLFlag[isRTL];
  15.   res:=SendMessage(rm.Handle, EM_SETPARAFORMAT, 0, LPARAM(@P));
  16. end;  
  17.  
  18.  
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2282
    • havefunsoft.com
Re: Hebrew entries
« Reply #12 on: August 18, 2016, 04:18:38 pm »
Btw, if you take a Hebrew text and copy/paste it (i.e. from wikipedia), the punctuation there is recognized as RTL.
I'm wondering if RichEdit is forcing the direction based of the input method, rather than punctuation environment.
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

rick2691

  • Sr. Member
  • ****
  • Posts: 375
Re: Hebrew entries
« Reply #13 on: August 18, 2016, 04:57:07 pm »
I have made it work with the following three routines. The first being the RichEdit code that you posted...

Code: Pascal  [Select]
  1. procedure TCmdForm.MakeRTLPara(rm: TRichMemo; isRTL: Boolean);
  2. var
  3.   p: PARAFORMAT2;
  4.   res: Integer;
  5. const
  6.   RTLFlag : array [Boolean] of word = (0, PFE_RTLPARA);
  7. begin
  8.   FillChar(p, sizeof(p), 0);
  9.   p.cbSize:=sizeof(p);
  10.   p.dwMask:=p.dwMask or PFM_RTLPARA;
  11.   p.wEffects:=p.wEffects or RTLFlag[isRTL];
  12.   res:=SendMessage(rm.Handle, EM_SETPARAFORMAT, 0, LPARAM(@P));
  13. end;  
  14.  
  15. procedure TCmdForm.MnuHebrewClick(Sender: TObject);
  16. begin
  17.   EnglishOn:= false;
  18.   HebrewOn:= true;
  19.   SyriacOn:= false;
  20.   GreekOn:= false;
  21.   CmdForm.caption:= 'CmdMemo - Hebrew Mode';
  22.   MakeRTLPara(PageMemo,true);  // set false for english
  23. end;  
  24.  
  25. procedure TCmdForm.MemoUTF8KeyPress(Sender: TObject; var UTF8Key: TUTF8Char);
  26. var cHit: boolean;
  27. begin
  28.      Case UTF8Key of
  29.             #39 : UTF8Key:= UnicodeToUTF8(1488); // alf (#39=')
  30.             'b'   : UTF8Key:= UnicodeToUTF8(1489);  // bth
  31.             'g'   : UTF8Key:= UnicodeToUTF8(1490); // gml
  32.             'd'   : UTF8Key:= UnicodeToUTF8(1491);  // dlt
  33.             end;
  34. end;
  35.  

It does everything... allows punctuation, advances LTR, moves the cursor.

Unfortunately, however, it only works with the paragraph being RTL. If it isn't RTL it will make it RTL. So you can't do inline quotes from Hebrew within an English paragraph. You would only be able to that by copy/paste.

I can probably live with that... but professional editors aren't that way. They can do inline.

Quote
I'm wondering if RichEdit is forcing the direction based of the input method, rather than punctuation environment.

I think so.

Rick
Windows 10, LAZ 1.6.4, FPC 3.0.2, SVN 54278, i386-win32-win32/win64, forms use windows unit

rick2691

  • Sr. Member
  • ****
  • Posts: 375
Re: Hebrew entries
« Reply #14 on: August 18, 2016, 05:18:23 pm »
skalogryz,

I left in a hurry. I forgot to say thanks. I would never have found that RichEdit code. I didn't even know that there was a RichEdit unit in Lazarus.

Rick
Windows 10, LAZ 1.6.4, FPC 3.0.2, SVN 54278, i386-win32-win32/win64, forms use windows unit