0

I've tried to extract a single character into a char varible from a string but the result always was an isolated form of the character! e.g. I have a string like "سیب", and if I want to extract the second character, the usual codes give me the isolate form of it like "ی", but I want to have the middle form of it, so is there any clear function like windows api functions that I can use it for this problem?

specifically, I want to measure width of each character of my string at its position. In other cases, I've always used this codes:

var 
S: string;
W: integer;
Begin
S := 'Abc';
W := canvas.textwidth(S[1]);
end;

But, in Farsi or Arabic strings, when I measure, it always returns width of isolated form of the specific character. I hope I could explain my problem clearly.

  • 1
    TLDR; I don't think you can. The character itself has the same unicode representation in both cases. It is the unicode rendering layer that is applying the ligature transformations to the character depending on where it is located within the string. – J... Mar 07 '20 at 16:11
  • Thanks, so did you mean, I have to write some functions for each language that I want my program be able to work with it?!! – mehdi sedehi Mar 07 '20 at 16:30
  • 1
    There may be libraries that could help. To you use the approach you're suggesting would require extracting the character, then translating the general form (ie: [0x6CC](http://www.fileformat.info/info/unicode/char/06cc/index.htm)) to the appropriate presentation form (eg: the medial [0xFBFF](http://www.fileformat.info/info/unicode/char/fbff/index.htm)) based on *where you found the letter in the string*. I believe `.TextWidth` should probably return the correct width if you give it the explicit presentation form you're trying to measure. – J... Mar 08 '20 at 14:20
  • Thanks alot, just I was wondering if I could find a specific function for the translation, Something like getRenderForm(string), and I know I can write the function, but it was great if there was a windows pre created function. – mehdi sedehi Mar 09 '20 at 07:04
  • There are libraries out there that provide such functions - that would be the place to start. I don't believe the WinAPI will help you out here. The presentation forms exist in Unicode only to serve certain [specific legacy needs](https://stackoverflow.com/a/57151351/327083) for converting text from older encodings. Not all characters have available isolate presentation forms available. It's probably a minor research project to compile a complete list for whatever languages you're interested in. Library code would be a good place to start. – J... Mar 09 '20 at 14:03

0 Answers0