chemtext: Add escaping of characters with special treatment

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5963 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2017-06-26 07:56:14 +00:00
parent 0202c3c2af
commit 8afa81832f
3 changed files with 93 additions and 78 deletions

View File

@ -83,17 +83,17 @@ object Form1: TForm1
Width = 17
Shape = bsSpacer
end
object Label1: TLabel
object Label3: TChemLabel
AnchorSideRight.Control = Spacer
Left = 103
Left = 16
Height = 18
Top = 40
Width = 67
Top = 96
Width = 154
Anchors = [akTop, akRight]
Caption = 'Propanol:'
Caption = 'Ion\-molecule reaction:'
ParentColor = False
end
object Label2: TLabel
object Label2: TChemLabel
AnchorSideRight.Control = Spacer
Left = 40
Height = 18
@ -103,14 +103,14 @@ object Form1: TForm1
Caption = 'Chemical reaction:'
ParentColor = False
end
object Label3: TLabel
object Label1: TChemLabel
AnchorSideRight.Control = Spacer
Left = 19
Left = 103
Height = 18
Top = 96
Width = 151
Top = 40
Width = 67
Anchors = [akTop, akRight]
Caption = 'Ion-molecule reaction:'
Caption = 'Propanol:'
ParentColor = False
end
end

View File

@ -11,17 +11,17 @@ type
{ TForm1 }
TForm1 = class(TForm)
Label1: TChemLabel;
Label2: TChemLabel;
Label3: TChemLabel;
Label4: TLabel;
Spacer: TBevel;
ChemLabel1: TChemLabel;
ChemLabel2: TChemLabel;
ChemLabel3: TChemLabel;
ChemLabel4: TChemLabel;
ChemLabel5: TChemLabel;
Edit1: TEdit;
ChemLabel4: TChemLabel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Panel1: TPanel;
procedure Edit1Change(Sender: TObject);
private

View File

@ -133,6 +133,7 @@ const
SUBFONT_OFFSET_MULTIPLIER = 50;
SUBFONT_DIVISOR = 100;
ARROW_LINE: array[boolean] of char = ('-', '=');
ESCAPE_CHAR = '\';
function ChemTextHeight(ACanvas: TCanvas; const AText: String;
Arrow: TChemArrow = caAsciiSingle): Integer;
@ -236,6 +237,7 @@ var
i, j: integer;
s: string;
subNos: boolean; // "subscript numbers"
escaping: Boolean;
begin
Result := Size(0, 0);
if AText = '' then
@ -249,8 +251,14 @@ begin
x0 := X;
subNos := false;
escaping := false;
i := 1;
while i <= Length(AText) do begin
if escaping then
begin
DrawNormal(X, Y, AText[i]);
escaping := false;
end else
case AText[i] of
'0'..'9':
begin
@ -292,6 +300,7 @@ begin
end;
'-':
begin
begin
j := i+1;
while (j <= Length(AText)) and (AText[j] = '-') do inc(j);
@ -301,13 +310,19 @@ begin
i := j;
end else // superscript -
DrawSup(X, Y, '-');
end;
subNos := false;
end;
ESCAPE_CHAR:
escaping := true;
else
begin
j := i+1;
while (j <= Length(AText)) and not (AText[j] in ['0'..'9', '+', '-', '<']) do
while (j <= Length(AText)) and
not (AText[j] in ['0'..'9', '+', '-', '<', ESCAPE_CHAR])
do
inc(j);
s := Copy(AText, i, j-i);
DrawNormal(X, Y, s);