You've already forked lazarus-ccr
ChemText: Extended syntax for more flexible sub- and superscripts.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7976 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -24,6 +24,16 @@ interface
|
||||
uses
|
||||
LclIntf, LCLType, LCLVersion, Types, SysUtils, Classes, Graphics, StdCtrls;
|
||||
|
||||
const
|
||||
DEFAULT_SMALLFONT_SIZE = 67;
|
||||
DEFAULT_SUBSCRIPT_OFFSET = 50;
|
||||
DEFAULT_SUPERSCRIPT_OFFSET = 25;
|
||||
|
||||
var
|
||||
SmallFontSizePercent: Integer = DEFAULT_SMALLFONT_SIZE;
|
||||
SubscriptFontOffsetPercent: Integer = DEFAULT_SUBSCRIPT_OFFSET;
|
||||
SuperscriptFontOffsetPercent: Integer = DEFAULT_SUPERSCRIPT_OFFSET;
|
||||
|
||||
type
|
||||
TChemArrow = (
|
||||
caASCIISingle, caASCIIDouble, caUTF8, caUTF8Single, caUTF8Double, caUTF8Half
|
||||
@ -129,11 +139,15 @@ type
|
||||
TArrowDir = (adLeft, adRight, adBoth);
|
||||
|
||||
const
|
||||
SUBFONT_SIZE_MULTIPLIER = 75;
|
||||
SUBFONT_OFFSET_MULTIPLIER = 50;
|
||||
SUBFONT_DIVISOR = 100;
|
||||
ARROW_LINE: array[boolean] of char = ('-', '=');
|
||||
SUBFONT_DIVISOR = 100;
|
||||
|
||||
ESCAPE_CHAR = '\';
|
||||
SAVE_CURRENT_POS = '@';
|
||||
RETURN_TO_POS = '|';
|
||||
SUPERSCRIPT_CHAR = '^';
|
||||
SUBSCRIPT_CHAR = '_';
|
||||
|
||||
HYDRATE_DOT = #$E2#$80#$A2;
|
||||
|
||||
function ChemTextHeight(ACanvas: TCanvas; const AText: String;
|
||||
@ -172,8 +186,8 @@ var
|
||||
begin
|
||||
h := ACanvas.Font.Height;
|
||||
try
|
||||
ACanvas.Font.Height := MulDiv(h, SUBFONT_SIZE_MULTIPLIER, SUBFONT_DIVISOR);
|
||||
yoff := abs(MulDiv(h, SUBFONT_OFFSET_MULTIPLIER, SUBFONT_DIVISOR));
|
||||
ACanvas.Font.Height := MulDiv(h, SmallFontSizePercent, 100);
|
||||
yoff := abs(MulDiv(h, SubscriptFontOffsetPercent, 100));
|
||||
if not Measure then
|
||||
ACanvas.TextOut(x, y + yoff, s);
|
||||
x := x + ACanvas.TextWidth(s);
|
||||
@ -186,12 +200,14 @@ var
|
||||
procedure DrawSup(var x: Integer; y: Integer; const s: String);
|
||||
var
|
||||
h: Integer;
|
||||
yoff: Integer;
|
||||
begin
|
||||
h := ACanvas.Font.Height;
|
||||
try
|
||||
ACanvas.Font.Height := MulDiv(h, SUBFONT_SIZE_MULTIPLIER, SUBFONT_DIVISOR);
|
||||
ACanvas.Font.Height := MulDiv(h, SmallFontSizePercent, 100);
|
||||
yoff := abs(MulDiv(h, SuperscriptFontOffsetPercent, 100));
|
||||
if not Measure then
|
||||
ACanvas.TextOut(x, y - 1, s);
|
||||
ACanvas.TextOut(x, y - yoff div 2, s);
|
||||
inc(x, ACanvas.TextWidth(s));
|
||||
finally
|
||||
ACanvas.Font.Height := h;
|
||||
@ -239,6 +255,7 @@ var
|
||||
s: string;
|
||||
subNos: boolean; // "subscript numbers"
|
||||
escaping: Boolean;
|
||||
savedX: Integer;
|
||||
begin
|
||||
Result := Size(0, 0);
|
||||
if AText = '' then
|
||||
@ -324,11 +341,29 @@ begin
|
||||
ESCAPE_CHAR:
|
||||
escaping := true;
|
||||
|
||||
SAVE_CURRENT_POS:
|
||||
savedX := X;
|
||||
|
||||
RETURN_TO_POS:
|
||||
X := savedX;
|
||||
|
||||
SUPERSCRIPT_CHAR:
|
||||
begin
|
||||
inc(i);
|
||||
DrawSup(X, Y, AText[i]);
|
||||
end;
|
||||
|
||||
SUBSCRIPT_CHAR:
|
||||
begin
|
||||
inc(i);
|
||||
DrawSub(X, Y, AText[i]);
|
||||
end;
|
||||
|
||||
else
|
||||
begin
|
||||
j := i+1;
|
||||
while (j <= Length(AText)) and
|
||||
not (AText[j] in ['0'..'9', '+', '-', '<', '.', ESCAPE_CHAR])
|
||||
not (AText[j] in ['0'..'9', '+', '-', '<', '.', ESCAPE_CHAR, SAVE_CURRENT_POS, RETURN_TO_POS, SUPERSCRIPT_CHAR, SUBSCRIPT_CHAR])
|
||||
do
|
||||
inc(j);
|
||||
s := Copy(AText, i, j-i);
|
||||
|
Reference in New Issue
Block a user