Procházet zdrojové kódy

* fixed tab handling

master
Bergmann89 před 10 roky
rodič
revize
47bb93569a
2 změnil soubory, kde provedl 19 přidání a 33 odebrání
  1. +1
    -0
      examples/PostProcess/PostProcess.lpi
  2. +18
    -33
      utsTextSuite.pas

+ 1
- 0
examples/PostProcess/PostProcess.lpi Zobrazit soubor

@@ -43,6 +43,7 @@
<ComponentName Value="MainForm"/> <ComponentName Value="MainForm"/>
<HasResources Value="True"/> <HasResources Value="True"/>
<ResourceBaseClass Value="Form"/> <ResourceBaseClass Value="Form"/>
<UnitName Value="uMainForm"/>
</Unit1> </Unit1>
</Units> </Units>
</ProjectOptions> </ProjectOptions>


+ 18
- 33
utsTextSuite.pas Zobrazit soubor

@@ -140,9 +140,7 @@ type
fChars: array[Byte] of PtsFontCharArray; fChars: array[Byte] of PtsFontCharArray;
fCreateChars: Boolean; fCreateChars: Boolean;


//function HasChar(const aCharCode: WideChar): Boolean;
function GetChar(const aCharCode: WideChar): TtsChar; function GetChar(const aCharCode: WideChar): TtsChar;
//function GetCharCreate(const aCharCode: WideChar): TtsChar;
procedure AddChar(const aCharCode: WideChar; const aChar: TtsChar); overload; procedure AddChar(const aCharCode: WideChar; const aChar: TtsChar); overload;
protected protected
{%H-}constructor Create(const aRenderer: TtsRenderer; const aGenerator: TtsFontGenerator; const aProperties: TtsFontProperties); {%H-}constructor Create(const aRenderer: TtsRenderer; const aGenerator: TtsFontGenerator; const aProperties: TtsFontProperties);
@@ -266,6 +264,9 @@ type
tsItemTypeSpacing: ( tsItemTypeSpacing: (
Spacing: Integer; Spacing: Integer;
); );
tsItemTypeTab: (
TabWidth: Integer; // with of tab (in pixel)
);
end; end;


TtsLineFlag = ( TtsLineFlag = (
@@ -977,14 +978,6 @@ end;


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TtsFont/////////////////////////////////////////////////////////////////////////////////////////////////////////////// //TtsFont///////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
{
function TtsFont.HasChar(const aCharCode: WideChar): Boolean;
begin
result := Assigned(GetChar(aCharCode));
end;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TtsFont.GetChar(const aCharCode: WideChar): TtsChar; function TtsFont.GetChar(const aCharCode: WideChar): TtsChar;
var var
@@ -997,16 +990,6 @@ begin
result := nil; result := nil;
end; end;


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
{
function TtsFont.GetCharCreate(const aCharCode: WideChar): TtsChar;
begin
result := GetChar(aCharCode);
if not Assigned(result) then
result := AddChar(aCharCode);
end;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TtsFont.AddChar(const aCharCode: WideChar; const aChar: TtsChar); procedure TtsFont.AddChar(const aCharCode: WideChar; const aChar: TtsChar);
var var
@@ -1036,7 +1019,7 @@ begin
fGenerator := aGenerator; fGenerator := aGenerator;
fProperties := aProperties; fProperties := aProperties;
fCharSpacing := 0; fCharSpacing := 0;
fTabWidth := 0;
fTabWidth := 1;
fLineSpacing := 0.0; fLineSpacing := 0.0;
fCreateChars := true; fCreateChars := true;
fGenerator.RegisterFont(self); fGenerator.RegisterFont(self);
@@ -1550,6 +1533,8 @@ begin
fLastLine^.meta.Width := fLastLine^.meta.Width + aItem^.TextWidth; fLastLine^.meta.Width := fLastLine^.meta.Width + aItem^.TextWidth;
tsItemTypeSpacing: tsItemTypeSpacing:
fLastLine^.meta.Width := fLastLine^.meta.Width + aItem^.Spacing; fLastLine^.meta.Width := fLastLine^.meta.Width + aItem^.Spacing;
tsItemTypeTab:
fLastLine^.meta.Width := fLastLine^.meta.Width + aItem^.TabWidth;
end; end;
result := true; result := true;
end; end;
@@ -1646,9 +1631,8 @@ var


case State of case State of
tsItemTypeText, tsItemTypeSpace: begin tsItemTypeText, tsItemTypeSpace: begin
p^.Text := tsStrAlloc(TextLength);
TextLength := 0;
Text := p^.Text;
p^.Text := tsStrAlloc(TextLength);
Text := p^.Text;
while (TextBegin <> aText) do begin while (TextBegin <> aText) do begin
Text^ := TextBegin^; Text^ := TextBegin^;
inc(Text, 1); inc(Text, 1);
@@ -1657,18 +1641,15 @@ var
AddItem(p); AddItem(p);
end; end;


tsItemTypeLineBreak: begin
AddItem(p);
TextBegin := aText;
end;

tsItemTypeTab: begin
tsItemTypeLineBreak, tsItemTypeTab: begin
AddItem(p); AddItem(p);
end; end;


else else
Dispose(p); Dispose(p);
end; end;
TextBegin := aText;
TextLength := 0;
end; end;


begin begin
@@ -1702,8 +1683,7 @@ begin


// tabulator // tabulator
#$0009: begin #$0009: begin
if (State <> tsItemTypeTab) then
ExtractWord;
ExtractWord;
State := tsItemTypeTab; State := tsItemTypeTab;
end; end;


@@ -1725,6 +1705,7 @@ end;
function TtsTextBlock.SplitIntoLines(aItem: PtsLineItem): Boolean; function TtsTextBlock.SplitIntoLines(aItem: PtsLineItem): Boolean;
var var
p: PtsLineItem; p: PtsLineItem;
tab: Integer;
begin begin
result := false; result := false;
if not Assigned(fCurrentFont) then if not Assigned(fCurrentFont) then
@@ -1779,6 +1760,8 @@ begin
end; end;


tsItemTypeTab: begin tsItemTypeTab: begin
tab := fCurrentFont.TabWidth * fCurrentFont.Properties.Size;
p^.TabWidth := (1 + fLastLine^.meta.Width div tab) * tab - fLastLine^.meta.Width;
if not PushLineItem(p) then if not PushLineItem(p) then
FreeLineItem(p); FreeLineItem(p);
end; end;
@@ -2102,7 +2085,9 @@ var
// get current x pos and round it to TabWidth // get current x pos and round it to TabWidth
pos := GetDrawPos; pos := GetDrawPos;
tab := font.TabWidth * font.Properties.Size; tab := font.TabWidth * font.Properties.Size;
pos.x := Ceil(pos.x * tab) div tab;
if (tab = 0) then
tab := 1;
pos.x := aBlock.Left + (1 + (pos.x - aBlock.Left) div tab) * tab;
SetDrawPos(pos.x, pos.y); SetDrawPos(pos.x, pos.y);
end; end;




Načítá se…
Zrušit
Uložit