Browse Source

+ initial attempt at defining an enhanced video cell record for the Unicode support in the video unit

git-svn-id: branches/unicodekvm@48465 -
nickysn 4 years ago
parent
commit
b8dfa1b8e6
2 changed files with 94 additions and 0 deletions
  1. 67 0
      packages/rtl-console/src/inc/video.inc
  2. 27 0
      packages/rtl-console/src/inc/videoh.inc

+ 67 - 0
packages/rtl-console/src/inc/video.inc

@@ -11,6 +11,73 @@
 
 
  **********************************************************************}
  **********************************************************************}
 
 
+{ TEnhancedVideoCell }
+
+function TEnhancedVideoCell.GetAttribute: Byte;
+begin
+  GetAttribute := Byte(FAttributes);
+end;
+
+procedure TEnhancedVideoCell.SetAttribute(Attr: Byte);
+begin
+  FAttributes := (FAttributes and $FF00) or Attr;
+end;
+
+function TEnhancedVideoCell.GetExtendedGraphemeCluster: WideString;
+begin
+  if (FAttributes and $8000) = 0 then
+    GetExtendedGraphemeCluster := EGC_SingleChar
+  else
+    GetExtendedGraphemeCluster := WideString(EGC_WideStr);
+end;
+
+procedure TEnhancedVideoCell.SetExtendedGraphemeCluster(const AExtendedGraphemeCluster: WideString);
+begin
+  if Length(AExtendedGraphemeCluster) = 1 then
+  begin
+    if (FAttributes and $8000) <> 0 then
+    begin
+      FAttributes := FAttributes and $7FFF;
+      WideString(EGC_WideStr) := '';
+    end;
+    EGC_SingleChar := AExtendedGraphemeCluster[1];
+  end
+  else
+  begin
+    if (FAttributes and $8000) = 0 then
+    begin
+      FAttributes := FAttributes or $8000;
+      EGC_WideStr := nil;
+    end;
+    WideString(EGC_WideStr) := AExtendedGraphemeCluster;
+  end;
+end;
+
+class operator TEnhancedVideoCell.Initialize(var evc: TEnhancedVideoCell);
+begin
+  evc.FAttributes := 0;
+end;
+
+class operator TEnhancedVideoCell.Finalize(var evc: TEnhancedVideoCell);
+begin
+  if (evc.FAttributes and $8000) <> 0 then
+    WideString(evc.EGC_WideStr) := '';
+end;
+
+procedure fpc_WideStr_Incr_Ref(var S: Pointer); external name 'FPC_WIDESTR_INCR_REF';
+
+class operator TEnhancedVideoCell.AddRef(var evc: TEnhancedVideoCell);
+begin
+  if (evc.FAttributes and $8000) <> 0 then
+    fpc_WideStr_Incr_Ref(evc.EGC_WideStr);
+end;
+
+class operator TEnhancedVideoCell.Copy(constref aSrc: TEnhancedVideoCell; var aDst: TEnhancedVideoCell);
+begin
+  aDst.ExtendedGraphemeCluster := aSrc.ExtendedGraphemeCluster;
+  aDst.FAttributes := aSrc.FAttributes;
+end;
+
 Const
 Const
   LockUpdateScreen : Integer = 0;
   LockUpdateScreen : Integer = 0;
 
 

+ 27 - 0
packages/rtl-console/src/inc/videoh.inc

@@ -11,6 +11,9 @@
 
 
  **********************************************************************}
  **********************************************************************}
 
 
+{$mode objfpc}
+{$modeswitch advancedrecords}
+
 type
 type
   PVideoMode = ^TVideoMode;
   PVideoMode = ^TVideoMode;
   TVideoMode = record
   TVideoMode = record
@@ -25,6 +28,30 @@ type
   TVideoBuf = array[0..{$ifdef CPU16}16382{$else}32759{$endif}] of TVideoCell;
   TVideoBuf = array[0..{$ifdef CPU16}16382{$else}32759{$endif}] of TVideoCell;
   PVideoBuf = ^TVideoBuf;
   PVideoBuf = ^TVideoBuf;
 
 
+  TEnhancedVideoCell = record
+  private
+    class operator Initialize(var evc: TEnhancedVideoCell);
+    class operator Finalize(var evc: TEnhancedVideoCell);
+    class operator AddRef(var evc: TEnhancedVideoCell);
+    class operator Copy(constref aSrc: TEnhancedVideoCell; var aDst: TEnhancedVideoCell);
+    function GetExtendedGraphemeCluster: WideString;
+    procedure SetExtendedGraphemeCluster(const AExtendedGraphemeCluster: WideString);
+    function GetAttribute: Byte;
+    procedure SetAttribute(Attr: Byte);
+  public
+    property ExtendedGraphemeCluster: WideString read GetExtendedGraphemeCluster write SetExtendedGraphemeCluster;
+    property Attribute: Byte read GetAttribute write SetAttribute;
+
+  private
+    FAttributes: Word;
+    case integer of
+      0: (EGC_SingleChar: WideChar);
+      1: (EGC_WideStr: Pointer);
+  end;
+  PEnhancedVideoCell = ^TEnhancedVideoCell;
+
+  TEnhancedVideoBuf = array of TEnhancedVideoCell;
+
   TVideoDriver = Record
   TVideoDriver = Record
     InitDriver        : Procedure;
     InitDriver        : Procedure;
     DoneDriver        : Procedure;
     DoneDriver        : Procedure;