Browse Source

* The text functions can now convert the character sets of the given
strings. By default, for GO32V2 there is no conversion, and for all
other platforms the strings are converted from ANSI to DOS-ASCII.

sg 25 years ago
parent
commit
de9fead4bd
2 changed files with 93 additions and 10 deletions
  1. 57 1
      rtl/inc/graph/graphh.inc
  2. 36 9
      rtl/inc/graph/gtext.inc

+ 57 - 1
rtl/inc/graph/graphh.inc

@@ -591,6 +591,57 @@ VAR
   RestoreVideoState: RestoreStateProc;
   RestoreVideoState: RestoreStateProc;
   ExitSave: pointer;
   ExitSave: pointer;
 
 
+
+type
+  TCharsetTransTable = array[Char] of Char;
+  PCharsetTransTable = ^TCharsetTransTable;
+
+const
+
+  { The following table can be used for translating characters from the
+    Ansi charset (ISO8859-1) to the DOS ASCII charset (CP437) }
+
+  AnsiToASCIITransTable: TCharsetTransTable =
+    (#$00, #$01, #$02, #$03, #$04, #$05, #$06, #$07,   // $00 - $07
+     #$08, #$09, #$0a, #$0b, #$0c, #$0d, #$0e, #$0f,   // $08 - $0f
+     #$10, #$11, #$12, #$13, #$14, #$15, #$16, #$17,   // $10 - $17
+     #$18, #$19, #$1a, #$1b, #$1c, #$1d, #$1e, #$1f,   // $18 - $1f
+     #$20, #$21, #$22, #$23, #$24, #$25, #$26, #$27,   // $20 - $27
+     #$28, #$29, #$2a, #$2b, #$2c, #$2d, #$2e, #$2f,   // $28 - $2f
+     #$30, #$31, #$32, #$33, #$34, #$35, #$36, #$37,   // $30 - $37
+     #$38, #$39, #$3a, #$3b, #$3c, #$3d, #$3e, #$3f,   // $38 - $3f
+     #$40, #$41, #$42, #$43, #$44, #$45, #$46, #$47,   // $40 - $47
+     #$48, #$49, #$4a, #$4b, #$4c, #$4d, #$4e, #$4f,   // $48 - $4f
+     #$50, #$51, #$52, #$53, #$54, #$55, #$56, #$57,   // $50 - $57
+     #$58, #$59, #$5a, #$5b, #$5c, #$5d, #$5e, #$5f,   // $58 - $5f
+     #$60, #$61, #$62, #$63, #$64, #$65, #$66, #$67,   // $60 - $67
+     #$68, #$69, #$6a, #$6b, #$6c, #$6d, #$6e, #$6f,   // $68 - $6f
+     #$70, #$71, #$72, #$73, #$74, #$75, #$76, #$77,   // $70 - $77
+     #$78, #$79, #$7a, #$7b, #$7c, #$7d, #$7e, #$7f,   // $78 - $7f
+     '?' , '?' , '?' , '?' , '?' , '?' , '?' , '?' ,   // $80 - $87
+     '?' , '?' , '?' , '?' , '?' , '?' , '?' , '?' ,   // $88 - $8f
+     '?' , '?' , '?' , '?' , '?' , '?' , '?' , '?' ,   // $90 - $97
+     '?' , '?' , '?' , '?' , '?' , '?' , '?' , '?' ,   // $98 - $9f
+     #$ff, #$ad, #$9b, #$9c, '?' , #$9d, '?' , '?' ,   // $a0 - $a7
+     '?' , '?' , #$a6, #$ae, #$aa, '?' , '?' , '?' ,   // $a8 - $af
+     #$f8, #$f1, #$fd, '?' , '?' , #$e6, '?' , #$fa,   // $b0 - $b7
+     '?' , '?' , #$a7, #$af, #$ac, #$ab, '?' , #$a8,   // $b8 - $bf
+     '?' , '?' , '?' , '?' , #$8e, #$8f, #$92, #$80,   // $c0 - $c7
+     '?' , #$90, '?' , '?' , '?' , '?' , '?' , '?' ,   // $c8 - $cf
+     '?' , #$a5, '?' , '?' , '?' , '?' , #$99, '?' ,   // $d0 - $d7
+     '?' , '?' , '?' , '?' , #$9a, '?' , '?' , #$e1,   // $d8 - $df
+     #$85, #$a0, #$83, '?' , #$84, #$86, #$91, #$87,   // $e0 - $e7
+     #$8a, #$82, #$88, #$89, #$8d, #$a1, #$8c, #$8b,   // $e8 - $ef
+     '?' , #$a4, #$95, #$a2, #$93, '?' , #$94, #$f6,   // $f0 - $f7
+     '?' , #$97, #$a3, #$96, #$81, '?' , '?' , #$98);  // $f8 - $ff
+
+{$IFDEF GO32V2}
+  GraphStringTransTable: PCharsetTransTable = nil;
+{$ELSE}
+  GraphStringTransTable: PCharsetTransTable = @AnsiToASCIITransTable;
+{$ENDIF}
+
+
 function queryadapterinfo : pmodeinfo;
 function queryadapterinfo : pmodeinfo;
 
 
 Procedure Closegraph;
 Procedure Closegraph;
@@ -680,7 +731,12 @@ Function GetDriverName: string;
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.3  2000-04-02 12:13:36  florian
+  Revision 1.4  2000-06-16 17:06:08  sg
+  * The text functions can now convert the character sets of the given
+    strings. By default, for GO32V2 there is no conversion, and for all
+    other platforms the strings are converted from ANSI to DOS-ASCII.
+
+  Revision 1.3  2000/04/02 12:13:36  florian
     * some more procedures can be now hooked by the OS specific implementation
     * some more procedures can be now hooked by the OS specific implementation
 
 
   Revision 1.2  2000/03/24 18:16:33  florian
   Revision 1.2  2000/03/24 18:16:33  florian

+ 36 - 9
rtl/inc/graph/gtext.inc

@@ -93,6 +93,24 @@
 {                         Internal support routines                         }
 {                         Internal support routines                         }
 {***************************************************************************}
 {***************************************************************************}
 
 
+
+function ConvertString(const OrigString: String): String;
+var
+  i: Integer;
+  ConvResult: String;
+begin
+  if GraphStringTransTable = nil then
+    ConvertString := OrigString
+  else
+  begin
+    SetLength(ConvResult, Length(OrigString));
+    for i := 1 to Length(OrigString) do
+      ConvResult[i] := GraphStringTransTable^[OrigString[i]];
+    ConvertString := ConvResult;
+  end;
+end;
+
+
     function testfont(p : pchar) : boolean;
     function testfont(p : pchar) : boolean;
 
 
       begin
       begin
@@ -332,6 +350,7 @@
     function TextWidth(const TextString : string) : word;
     function TextWidth(const TextString : string) : word;
       var i,x : smallint;
       var i,x : smallint;
           c   : byte;
           c   : byte;
+	  s   : String;
       begin
       begin
          x := 0;
          x := 0;
          { if this is the default font ... }
          { if this is the default font ... }
@@ -339,9 +358,10 @@
             TextWidth:=length(TextString)*8*CurrentTextInfo.CharSize
             TextWidth:=length(TextString)*8*CurrentTextInfo.CharSize
          { This is a stroked font ... }
          { This is a stroked font ... }
             else begin
             else begin
-               for i:=1 to length(TextString) do
+	       s := ConvertString(TextString);
+               for i:=1 to length(s) do
                 begin
                 begin
-                   c:=byte(textstring[i]);
+                   c:=byte(s[i]);
 {                   dec(c,fonts[Currenttextinfo.font].header.first_char);}
 {                   dec(c,fonts[Currenttextinfo.font].header.first_char);}
                    if (c-fonts[Currenttextinfo.font].header.first_char>=
                    if (c-fonts[Currenttextinfo.font].header.first_char>=
                        fonts[Currenttextinfo.font].header.nr_chars) then
                        fonts[Currenttextinfo.font].header.nr_chars) then
@@ -359,6 +379,7 @@
          X,Y: smallint;
          X,Y: smallint;
        end;
        end;
       var
       var
+         ConvString    : String;
          i,j,k,c       : longint;
          i,j,k,c       : longint;
          xpos,ypos     : longint;
          xpos,ypos     : longint;
          counter       : longint;
          counter       : longint;
@@ -381,10 +402,11 @@
          X:=X-XPos; Y:=Y+YPos;
          X:=X-XPos; Y:=Y+YPos;
          XPos:=X; YPos:=Y;
          XPos:=X; YPos:=Y;
 
 
+	 ConvString := ConvertString(TextString);
          CharSize := CurrentTextInfo.Charsize;
          CharSize := CurrentTextInfo.Charsize;
          if Currenttextinfo.font=DefaultFont then
          if Currenttextinfo.font=DefaultFont then
          begin
          begin
-           c:=length(textstring);
+           c:=length(ConvString);
            if CurrentTextInfo.direction=HorizDir then
            if CurrentTextInfo.direction=HorizDir then
            { Horizontal direction }
            { Horizontal direction }
              begin
              begin
@@ -394,7 +416,7 @@
                      { we copy the character bitmap before accessing it }
                      { we copy the character bitmap before accessing it }
                      { this improves speed on non optimizing compilers  }
                      { this improves speed on non optimizing compilers  }
                      { since it is one less address calculation.        }
                      { since it is one less address calculation.        }
-                     Fontbitmap:=TBitmapChar(DefaultFontData[TextString[i+1]]);
+                     Fontbitmap:=TBitmapChar(DefaultFontData[ConvString[i+1]]);
                      { no scaling }
                      { no scaling }
                      if CharSize = 1 then
                      if CharSize = 1 then
                       Begin
                       Begin
@@ -439,7 +461,7 @@
               for i:=0 to c-1 do
               for i:=0 to c-1 do
               begin
               begin
 
 
-                chr := TextString[i+1];
+                chr := ConvString[i+1];
                 Fontbitmap:=TBitmapChar(DefaultFontData[chr]);
                 Fontbitmap:=TBitmapChar(DefaultFontData[chr]);
                 ypos := y-(i shl 3)*CharSize;
                 ypos := y-(i shl 3)*CharSize;
 
 
@@ -489,14 +511,14 @@
               { reset line style to defaults }
               { reset line style to defaults }
               setlinestyle(solidln,oldvalues.pattern,normwidth);
               setlinestyle(solidln,oldvalues.pattern,normwidth);
               if Currenttextinfo.direction=vertdir then
               if Currenttextinfo.direction=vertdir then
-                 xpos:=xpos + Textheight(textstring);
+                 xpos:=xpos + Textheight(ConvString);
               CurX2:=xpos; xpos2 := curX2; x2 := xpos2;
               CurX2:=xpos; xpos2 := curX2; x2 := xpos2;
               CurY2:=ypos; ypos2 := curY2; y2 := ypos2;
               CurY2:=ypos; ypos2 := curY2; y2 := ypos2;
 {              x:=xpos; y:=ypos;}
 {              x:=xpos; y:=ypos;}
 
 
-              for i:=1 to length(textstring) do
+              for i:=1 to length(ConvString) do
                 begin
                 begin
-                   c:=byte(textstring[i]);
+                   c:=byte(ConvString[i]);
 {                   Stroke_Count[c] := }
 {                   Stroke_Count[c] := }
                    unpack( fonts[CurrentTextInfo.font].instr,
                    unpack( fonts[CurrentTextInfo.font].instr,
                      fonts[CurrentTextInfo.font].Offsets[c], Strokes );
                      fonts[CurrentTextInfo.font].Offsets[c], Strokes );
@@ -755,7 +777,12 @@
 
 
 {
 {
 $Log$
 $Log$
-Revision 1.18  2000-04-16 08:45:48  jonas
+Revision 1.19  2000-06-16 17:06:08  sg
+* The text functions can now convert the character sets of the given
+  strings. By default, for GO32V2 there is no conversion, and for all
+  other platforms the strings are converted from ANSI to DOS-ASCII.
+
+Revision 1.18  2000/04/16 08:45:48  jonas
   * fixed registerbgifont (webbug 847)
   * fixed registerbgifont (webbug 847)
 
 
 Revision 1.17  2000/04/02 12:13:36  florian
 Revision 1.17  2000/04/02 12:13:36  florian