Browse Source

* New way encoding insertChar produces better results

mazen 21 years ago
parent
commit
ec8c55a03c
1 changed files with 11 additions and 38 deletions
  1. 11 38
      rtl/objpas/freebidi.pp

+ 11 - 38
rtl/objpas/freebidi.pp

@@ -276,51 +276,24 @@ end;
 
 
 function InsertChar(Src:TCharacter; var Dest:TString; vp:Integer; pDir:TDirection):Integer;
 function InsertChar(Src:TCharacter; var Dest:TString; vp:Integer; pDir:TDirection):Integer;
 var
 var
-  v2l:TVisualToLogical;
-  lp:Integer;
-  c:TCharacter;
+  vSrc,vDest:TString;
 begin
 begin
-  v2l := VisualToLogical(Dest, pDir);
-  Result := v2l[0];
-  if vp > Result
-  then
-    begin
-      lp := Length(Dest) + 1;
-      vp := Result;
-    end
-  else
-    lp := v2l[vp];
-  c := Dest[lp];
-  Result := vp;
-  case DirectionOf(c) of
+  vSrc := VStr(Src,pDir);
+  vDest := VStr(Dest,pDir);
+  Insert(vSrc, vDest, vp);
+  Dest := VStr(vDest, pDir);
+  case DirectionOf(Src) of
   drRTL:
   drRTL:
-    begin
-      lp += Length(c);
-      if DirectionOf(Src) <> drRTL
-      then
-        begin
-          while (Result <= Length(Dest)) and (DirectionOf(Dest[v2l[Result]]) <> drLTR) do
-            Result += 1;
-          while (Result > vp) and (DirectionOf(Dest[v2l[Result]]) <> drRTL) do
-            Result -= 1;
-          Result += 2;
-        end;
-    end;
+    Result := vp;
   drLTR:
   drLTR:
-    Result += 1;
+    Result := vp + 1;
   else
   else
-    if DirectionOf(Src) = drRTL
+    if(vp < Length(vDest)) and (DirectionOf(vDest[vp + 1]) = drRTL)
     then
     then
-      begin
-        while (Result > 0) and (DirectionOf(Dest[v2l[Result]]) <> drLTR) do
-          Result -= 1;
-        while (Result < vp) and (DirectionOf(Dest[v2l[Result]]) <> drRTL) do
-          Result += 1;
-      end
+      Result := vp
     else
     else
-      Result += 1;
+      Result := vp + 1;
   end;
   end;
-  Insert(Src, Dest, lp);
 end;
 end;
 
 
 procedure VInsert(const Src:TString;var Dest:TString; vp:Integer; pDir:TDirection);
 procedure VInsert(const Src:TString;var Dest:TString; vp:Integer; pDir:TDirection);