BiDi text not displayed properly in Delphi 7 when using RTL BiDi mode? -
in delphi 7, drop tmemo
on form , in form's oncreate
handler enable rtl bidimode
this:
syslocale.middleeast := true; application.bidimode := bdrighttoleft;
if load text file containing bidi text tmemo
using lines.loadfromfile
, text not displayed correctly.
let's have following text in text file (this proper way display it, example when displayed notepad++ or ms word):
!ד asd אב!ג text... text2...
here's how it's incorrectly displayed in tmemo
:
אב!ג asd ד! ...text... text2
here's how text stored in text file:
21 e3 20 61 73 64 20 e0 e1 21 e2 0d 0a 74 65 78 74 2e 2e 2e 20 74 65 78 74 32 2e 2e 2e
here's visualization of how it's stored (the text never rendered way anywhere, illustration):
!ד asd ג!בא text... text2...
so, bidi text saved in alternating "blocks": (rtl block)(ltr block)(rtl block)(ltr block) etc. storing order of blocks left right same order of blocks way see them (from left right) when rendered. storing order of characters in every rtl block reverse of viewing order of characters in blocks when displayed (see alef, bet, exclamation mark, gimel block).
the text rendered when rtl bidimode
not enabled (if value of syslocale.middleeast
false
or value of bidimode
bdlefttoright
).
this incorrect rendering happens in other controls tested (tlabel
, tcheckbox
, tradiobutton
, etc.).
looking @ incorrectly displayed text in tmemo
when rtl bidimode
enabled, i'm seeing order of blocks reversed. also, leading neutral characters (like !
, ?
, .
, etc.) become trailing ones , vice versa (e.g. 3 dots after text text2
).
looking problem, believe issue lies in windows' drawtext
function , dt_rtlreading
flag used when bidi text rendered. if i'm not mistaken, function used render text in controls. indeed, if render bidi text on canvas using drawtext
dt_rtlreading
flag, rendered in same incorrect way, , if don't use dt_rtlreading
, rendered correctly.
i made descendant class of tlabel
, overriding it's paint
procedure never use dt_rtlreading
when rendering text , fix issue. however, fixing issue windows controls tcheckbox
, tradiobutton
, , tbutton
not easy.
i tried using drawtextex
- issue remains. tried using utf8 text file , ttntmemo
(which uses drawtextw
) - issue remains.
so, questions are: known issue? why happening? if is, there fix it? or doing wrong here?
Comments
Post a Comment