none
how to find exact location point() of characters in mixed language sentence

    Question

  • hi

    location of character in mixing  laguage (e.g.  farsi & english) sentence are different in memory and display , you can check it with point() 

    all  Instructions as LEFT ,RIGHT ,MID not work  correctly when using it on the mix language
    sentence
    also GetPositionFromCharIndex(I) also not get position of the char user see on display...
    i need to have exact location point() of display character (from left or right side of text box)

    Tuesday, April 10, 2012 8:32 PM

All replies

  • I don't understand. Can you please give an example?

    Armin

    Wednesday, April 11, 2012 12:01 AM
  • Hi Armin

    in quick basic String is a literal of character and in vb.net sting is an output of function which act on array of character , and if this character are mix language then made a sentence according complex instruction  out of hand of programer !!

    Sentence: The World دنیا در 23/01/91 زیباترست

    "د" is the farthest and "T"  is first character from left of above sentence

    if get index , you find   "د"  on index  11 and poin.x 89 ....

    this means function point take location of "د" form memory not from farthest as can seen on display,i need to find point.x=281  for chrarcter "د"      not 89 ,how to find it ?

    Wednesday, April 11, 2012 6:50 AM
  • You say "mix language". The String does not care about the language. In VB.Net, Strings are a sequence of UTF-16 encoded Unicode characters. Every Char object is an unsigned 16 bit value. The value is the Unicode code point of the character. Therefore, the number of Char objects is usually equal to the number of characters in the String.

    There is an exception if the Unicode code point >=0x10000. In this case, two Char objects are used to represent one Unicode character. They are then called surrogates (low- and high-surrogate).

    Anyway, I must admit that I was not aware of this special String handling. I know that you can change the RightToLeftDirection for a control, but I didn't know the direction can change within a String itself. Therefore, thank you for the example. Again I've learned something interesting. However, this does not help you. As this is a feature of the function String.GetPositionFromCharIndex, the best place to ask is in a .Net Framework forum because it affects all .Net Framework programmers, not only VB. There you might also find more specialists about it.

    Though I will continue research on how this is handled and will report later.


    Armin

    Wednesday, April 11, 2012 11:26 AM
  • For illustration:

    The Panel at the bottom shows the characters at the location as it is returned from String.GetPositionFromCharIndex. I've scaled the X value by 5 because characters cover each other. Below each character, you see the index within the String. I'm using three lines for the index because some indexes cover each other (like 18 and 26). 

    Regarding your question: I understand now. Character "د" is at index 10 (not 11 because it starts with zero), but in the panel it is shown in a different location than in the Textbox above. That means, GetPositionFromCharIndex returns the wrong value. This seems to be a bug.

    There is a central place where we can report bugs: https://connect.microsoft.com/VisualStudio

    I have searched for GetPositionFromCharIndex and got two results. None of them covers this problem. Therefore I suggest you open a new bug report. There you can also point to this thread. Good luck with it!

    EDIT: For better readbility, open the picture above in a new tab or window as it's scaled down within the message.


    Armin


    Wednesday, April 11, 2012 11:50 AM
  • As GetPositionFromCharIndex is a wrapper for sending EM_POSFROMCHAR, I've tried the latter, too. It returns the same values as the method. So it is also not a Framework issue, it's a problem in Windows itself.

    EDIT: Yarmini, I will ask your question at 

    http://social.msdn.microsoft.com/Forums/en-US/windowsuidevelopment/threads

    providing the information I already have.


    Armin


    Wednesday, April 11, 2012 1:21 PM
  • hi Armin
    you forgot to advise problem about Left, Mid ,and Right these instruction is very important for text control program ,but all of them not work in mixed laguage text
    in your example you should drow  char according  index not acording point
    point is incorrect ! ,for better drow you should using courier font 
    Armin your date is reverse !

    Microsoft should design getcharposition at render time not at string making point ! to solve these problem

    Armin ,am yarmini , not a guy !!

    Thursday, April 12, 2012 9:05 PM
    • "you forgot to advise problem about Left, Mid ,and Right "

    I did not forget it. I focused on one problem at a time. EDIT: In the windows ui forum, they don't care about Left, Mid and Right.

    • "in your example you should drow  char according  index not acording point point is incorrect !"

    Of course it is wrong. That's the purpose of the example. You have described it in words, but for better understanding, I've visualized it.

    • "Armin your date is reverse !"

    I have copied your sample text from the browser to the Textbox. It looks equal. The drawing in the panel is also equal (only the "2" is at the wrong location, but that's the problem). This is a screenshot from your message straight from the browser.

    If you compare it to the screenshot from my test application, the Textbox looks equal. Therefore I don't know what "your date is reverse" means.


    Armin



    Thursday, April 12, 2012 9:43 PM
  • The problem has been identified previously in this place.  I can't now find the item, but as far as I can remember there was no solution provided at that time (other than don't mix you left/right strings!)
    Thursday, April 12, 2012 10:03 PM
  • Regarding Left, Mid, Right, I don't know what you consider the right result. This is the order of the chars as returned from the Mid function, the String's Chars property and the String's SubString method: (All three functions return the same result)

    00: 0054 T
    01: 0068 h
    02: 0065 e
    03: 0020  
    04: 0057 W
    05: 006F o
    06: 0072 r
    07: 006C l
    08: 0064 d
    09: 0020  
    10: 062F د
    11: 0646 ن
    12: 06CC ی
    13: 0627 ا
    14: 0020  
    15: 062F د
    16: 0631 ر
    17: 0020  
    18: 0032 2
    19: 0033 3
    20: 002F /
    21: 0030 0
    22: 0031 1
    23: 002F /
    24: 0039 9
    25: 0031 1
    26: 0020  
    27: 0632 ز
    28: 06CC ی
    29: 0628 ب
    30: 0627 ا
    31: 062A ت
    32: 0631 ر
    33: 0633 س
    34: 062A ت
    
    The second column is the character code.


    Armin

    Thursday, April 12, 2012 10:08 PM
  • hi Armin

    Dim Jk As String = "The World دنیا در 23/01/91 زیباترست "

    Dim JkL As String = Left(Jk, 15) 'The World دنیا

    Dim JkR As String = Right(Jk, 8) 'دنیا د 

    Dim JkM As String = mid(Jk,10, 8) 'زیباترست

    as you can see Jk is main sentence ,TkL is left JkM is mid and JKR is right side

    i write result after ' all of result is incorrect
    with left i should see "The World اترست"
    with Mid i should see "ترست"
    with right  i should see "دنیا در"
    i explained  you befor all function act on string in memory
    char arranged  in  memory  according its law ,(which design by unicode consortium)
    date means solar date (formal date of iran 91/01/23)
    if  you are not familiar with farsi ,how you read my sentence !!  

    yarmini


    • Edited by yarmini Saturday, April 14, 2012 12:48 AM
    Friday, April 13, 2012 11:12 PM
  • if  you are not familiar with farsi ,how you read my sentence !!  

    Yarmini,

    I'm not sure what this means. No, I'm not familiar with Farsi, though I think I helped illustrating the problem and narrowing it down to not being VB or Framework specific. Am I right? In addition, I'm interested in issues that are new for me in order to learn something, in this case from a different culture. I think it helps understanding each other better.

    Further more, I was trying to understand the problem you have with the Mid/Left/Right statements which was not clear right away. I think many people are not familiar with the question you have, so every step into clearing it up should be helpful. It makes it easier also for other members to jump into the discussion and give support. Don't you agree?

    I'm sorry if you didn't get the final solution you were asking for.


    Armin

    Saturday, April 14, 2012 12:24 AM
  • Hi Acamar (Mcc)

    i don't mix ,my customer try to use mix language and our  books have many mix sentence , you should solve problem ...
    i am wrote editor for farsi(ansi)20 years ago ,in that editor ,user only change font key ,My app  automaticaly write right to left (for farsi))and   write left to right (for english)  on a line  , (without separating  english and farsi, mix ) , it is  working very well without any problem ,because in Dos mode String is a literal of character inside "" mark,in vb.net  string is a complex function, if i have ability to using string as a literal character(not as a complex function),not difficult to write editor for unicode , please send my suggestion to proper division ,i am ready to do

    Saturday, April 14, 2012 12:41 AM
  • Mid/left/right does not refer to the location on the screen, if that was your question. That's by design.

    Armin

    Saturday, April 14, 2012 12:57 AM
  • IMO, you can use the caret(the vertical txt inersion point) to position the char you want to locate by using the SelectionStart property of TextBox.  And if you want the point of the char relative to the entire screen, you can use this method called PointToScreen().  As for the point value, you must first obtain the point value of char and then use that method to get its screen location instead of the location in the client app.

    I don't know if this can help you, hope it helps.


    My blog: http://soho-hsh.blogspot.com

    Saturday, April 14, 2012 6:40 AM
  • Hi horngsh,

    "you must first obtain the point value of char"

    thought about that too, but it requires GetPositionFromCharIndex to work correctly. Unfortunately it doesn't (IMO).


    Armin

    Saturday, April 14, 2012 10:20 AM
  • Dear  Armin

    that was  a joke only , because you want to contribute to solve the problem carefully, sorry , my English is not so good, however I thank your side! 
    correct date is 91/01/23 not 23/01/91
    you can see the problem during  manipulating(fetch) a word from a sentence in mix language
    left\right\mis not work correctly

    Saturday, April 14, 2012 10:42 AM
  • Yarmini,

    thanks a lot for the clarification. :-) My English is also not the very best, so misunderstanding can be from my own deficiencies.

    Unfortunatelly, I'm unable to give further help from this point as my knowledge is limitted in this area. Anyway, good luck for you!


    Armin

    Saturday, April 14, 2012 11:12 AM
  • hi Horngsh
    point to screen  is using for coloring some char on the client screen ,i need to chang or modifing any word of sentence befor showing it to client screen ,this is a location of sentence which ready to send to screen ?
    this location is not location of string in memory ? and all of  statement (left/right/mid/point) should use pointer  to that location not pointer  to string location ,i suggest naming that location as string output location!!

     yarmni

    Saturday, April 14, 2012 11:50 AM
  • Hi yarmini:

    I don't know farsi language at all.  Besides it is read from right to left. Is there anything else special that we should pay attention to?  Actually I am not quite getting what your question means a little bit.  Could you elaborate a little bit?


    My blog: http://soho-hsh.blogspot.com

    Monday, April 16, 2012 1:01 PM
  • hi Horngsh
    english is LTR and farsi is RTL ,also  farsi digit is LTR ,unicode string no problem

    if you write sentence  completly  english (LTR) or writing completly Farsi (RTL)

    but in actual ,  you need to write in a sentence  include Farsi word(RTL) and farsi digit(LTR) or you may want to add english word (LTR) inside that sentence

    arangement of these word (we say complex sentence) on screen is different with memory !!

     you can read carefully my detail explanation history above ...
    are you know why char arangement are different in display and memory ,if you know please give me refernce document ?
    if you know string ouput location(i mentioned before)  ,please give me refernce document

    Yarmini

    Wednesday, April 18, 2012 12:39 AM
  • are you know why char arangement are different in display and memory ,if you know please give me refernce document ?

    You wrote yourself that the order must be mixed on the screen (LTR/RTL) so that you have readable text. If the order on the screen was equal to the order in memory, you probably couldn't read the text on the screen.


    Armin


    • Edited by Armin Zingler Wednesday, April 18, 2012 1:35 AM grammar
    Wednesday, April 18, 2012 1:34 AM
  • hi  Armin ,I hope you comeback

    this means have a function reading memory and making readable text ,then writing to display...
    in Msdos display area start from  &HB800 ,we need to access the display area in windows!!

    ,may in this area can find correct char sequence 

    ,I named it: string out put ,if available !

    yarmini

    Wednesday, April 18, 2012 11:28 PM
  • I understand what you mean. This is not available in Windows. You must admit that even in MSDOS, you did not store the characters in screen memory. You stored text somewhere else in memory before output to the screen. In which order has it been stored? In which order are characters stored in a file? I guess they are not stored in the  same order as they appear on the screen.

    In my opinion, the character order within a String is correct. Also, screen output is correct.

    The only (big) problem is that GetPositionFromCharIndex does not work correctly. I'm afraid, I can not solve it. Unfortunatelly, there was no answer in the Windows forum yet. I do not know to whom to address this issue.


    Armin

    Wednesday, April 18, 2012 11:49 PM
  • Hi Armin
    i request a new way to solve issue ,during refresh of display any element reproducing

    this means text elements sequentially made and sending to display location 

    during refresh can save a copy of text element in the char array ? !
    this Means can redirecting text element to array not to display

    yarmini 

    Thursday, April 19, 2012 8:27 PM
  • Hi Yarmini,

    I'm afraid, I see no way to do this.


    Armin

    Friday, April 20, 2012 12:05 AM
  • Friday, April 20, 2012 12:23 AM
  • Hi armin
    thanks

    i read all you reference ,but you know ,i am vb.net developer ,if i try to using that ,i must be going to learn   C++ first !!

    how can using  "GetTextExtentExPoint " in vb ?
    I known  many thing  abot font and glyph (i designed farsi font for Dos ,20 years ago)...
    at current time i need help for vb.net ,anyway

    i ask another way for solving issue
    we can get char array of string ...
    have a function to rearrange elements of this array  according the sequence of char of "WYSIWYG " ?

    yarmini

    Friday, April 20, 2012 10:52 PM
  • Hi Yarmini,

    if you read the topics before and after the linked one, you get more information. I think you have to read it all to understand it completely (I didn't do it) and find the appropriate functions. I'm pretty sure there will be a way to find it out. Uniscribe looks promising.

    For using the functions, you don't need C++. Just Declare the functions (see VB's Declare statement).


    Armin

    Saturday, April 21, 2012 12:43 AM
  • --------------------------------------------------------------------------------
    Hi Armin congratulation
    never afraid ! i find solution in anther planet (in he unicode site ) goto this address

    http://unicode.org/cldr/utility/bidi.jsp?a=The+World+%D8%AF%D9%86%DB%8C%D8%A7%D8%AF%D8%B1+23%2F02%2F91+%D8%B2%DB%8C%D8%A8%D8%A7%D8%AA%D8%B1%D8%B3%D8%AA&p=Auto

    this usable for you not for me ! as you know i need this ability inside visual studio environment ,because i need it ability to using functions MID LEFT RIGHT working correct ,Now ball in your ground !!
    thanks Yarmini

    Saturday, May 12, 2012 10:05 AM
  • Hi Armin
    i don't know who mark this thread as answer ?!!
    not yet answer ,i looking microsoft engineer to solve this problem ,anyway not answer ,i only show you a roadmap !!, to staring preparing answer

    best regard

    yarmini

    Sunday, May 13, 2012 12:07 AM