You've already forked lazarus-ccr
jvcllaz: TJvMarkupLabel|Viewer support sub- and superscripts.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8277 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -457,8 +457,7 @@ object MainForm: TMainForm
|
|||||||
'<br><font size="6">small text</font> and <font size="20">large</font> text'
|
'<br><font size="6">small text</font> and <font size="20">large</font> text'
|
||||||
'<br>A different font face: <font face="Times" size="14">Times</font>'
|
'<br>A different font face: <font face="Times" size="14">Times</font>'
|
||||||
'<br>HTML entities: & ™ √α β γ δ 90°'
|
'<br>HTML entities: & ™ √α β γ δ 90°'
|
||||||
'<br>Subscripts and superscripts are not supported:'
|
'<br>Subscripts and superscripts: 10 cm<sup>3</sup> H<sub>2</sub>O '
|
||||||
'10 cm<sup>3</sup> H<sub>2</sub>O '
|
|
||||||
)
|
)
|
||||||
VisibleSpecialChars = [vscSpace, vscTabAtLast]
|
VisibleSpecialChars = [vscSpace, vscTabAtLast]
|
||||||
SelectedColor.BackPriority = 50
|
SelectedColor.BackPriority = 50
|
||||||
|
@ -35,6 +35,8 @@ uses
|
|||||||
Controls, Graphics, SysUtils, Classes;
|
Controls, Graphics, SysUtils, Classes;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
TJvHTMLTextPos = (tpNormal, tpSubScript, tpSuperScript);
|
||||||
|
|
||||||
TJvHTMLElement = class(TObject)
|
TJvHTMLElement = class(TObject)
|
||||||
private
|
private
|
||||||
FFontSize: Integer;
|
FFontSize: Integer;
|
||||||
@ -49,6 +51,7 @@ type
|
|||||||
FSolText: string;
|
FSolText: string;
|
||||||
FEolText: string;
|
FEolText: string;
|
||||||
FBreakLine: Boolean;
|
FBreakLine: Boolean;
|
||||||
|
FPosition: TJvHTMLTextPos;
|
||||||
procedure SetFontName(const Value: string);
|
procedure SetFontName(const Value: string);
|
||||||
procedure SetFontSize(const Value: Integer);
|
procedure SetFontSize(const Value: Integer);
|
||||||
procedure SetFontStyle(const Value: TFontStyles);
|
procedure SetFontStyle(const Value: TFontStyles);
|
||||||
@ -75,6 +78,7 @@ type
|
|||||||
property Width: Integer read FWidth write SetWidth;
|
property Width: Integer read FWidth write SetWidth;
|
||||||
property Ascent: Integer read FAscent write SetAscent;
|
property Ascent: Integer read FAscent write SetAscent;
|
||||||
property BreakLine: Boolean read FBreakLine write SetBreakLine;
|
property BreakLine: Boolean read FBreakLine write SetBreakLine;
|
||||||
|
property Position: TJvHtmlTextPos read FPosition write FPosition;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TJvHTMLElementStack = class(TList)
|
TJvHTMLElementStack = class(TList)
|
||||||
|
@ -215,6 +215,7 @@ var
|
|||||||
lName: string;
|
lName: string;
|
||||||
lSize: Integer;
|
lSize: Integer;
|
||||||
lBreakLine: Boolean;
|
lBreakLine: Boolean;
|
||||||
|
lPosition: TJvHtmlTextPos;
|
||||||
AColor, lColor: TColor;
|
AColor, lColor: TColor;
|
||||||
Element: TJvHTMLElement;
|
Element: TJvHTMLElement;
|
||||||
|
|
||||||
@ -283,6 +284,7 @@ var
|
|||||||
Element.FontSize := lSize;
|
Element.FontSize := lSize;
|
||||||
Element.FontStyle := lStyle;
|
Element.FontStyle := lStyle;
|
||||||
Element.FontColor := lColor;
|
Element.FontColor := lColor;
|
||||||
|
Element.Position := lPosition;
|
||||||
Element.BreakLine := lBreakLine;
|
Element.BreakLine := lBreakLine;
|
||||||
lBreakLine := False;
|
lBreakLine := False;
|
||||||
FElementStack.Push(Element);
|
FElementStack.Push(Element);
|
||||||
@ -350,7 +352,16 @@ var
|
|||||||
PushTag
|
PushTag
|
||||||
else
|
else
|
||||||
if ATag = '/font' then
|
if ATag = '/font' then
|
||||||
PopTag;
|
PopTag
|
||||||
|
else
|
||||||
|
if ATag = 'sub' then
|
||||||
|
lPosition := tpSubscript
|
||||||
|
else
|
||||||
|
if ATag = 'sup' then
|
||||||
|
lPosition := tpSuperscript
|
||||||
|
else if (ATag = '/sub') or (ATag = '/sup') then
|
||||||
|
lPosition := tpNormal
|
||||||
|
else
|
||||||
if HaveParams then
|
if HaveParams then
|
||||||
begin
|
begin
|
||||||
repeat
|
repeat
|
||||||
@ -393,6 +404,7 @@ begin
|
|||||||
lSize := Font.Size;
|
lSize := Font.Size;
|
||||||
lColor := Font.Color;
|
lColor := Font.Color;
|
||||||
lBreakLine := False;
|
lBreakLine := False;
|
||||||
|
lPosition := tpNormal;
|
||||||
repeat
|
repeat
|
||||||
P := Pos('<', S);
|
P := Pos('<', S);
|
||||||
if P = 0 then
|
if P = 0 then
|
||||||
@ -447,15 +459,40 @@ var
|
|||||||
var
|
var
|
||||||
SS: string;
|
SS: string;
|
||||||
WW: Integer;
|
WW: Integer;
|
||||||
|
yy: Integer;
|
||||||
|
oldFontHeight: Integer;
|
||||||
|
fd: TFontData;
|
||||||
begin
|
begin
|
||||||
SetFont(EE);
|
SetFont(EE);
|
||||||
if EE.SolText <> '' then
|
if EE.SolText <> '' then
|
||||||
begin
|
begin
|
||||||
|
oldFontHeight := Canvas.Font.Height;
|
||||||
|
|
||||||
SS := TrimLeft(EE.SolText);
|
SS := TrimLeft(EE.SolText);
|
||||||
|
|
||||||
|
case EE.Position of
|
||||||
|
tpNormal:
|
||||||
|
yy := Y + BaseLine - EE.Ascent;
|
||||||
|
tpSubscript:
|
||||||
|
begin
|
||||||
|
fd := GetFontData(Canvas.Font.Reference.Handle);
|
||||||
|
Canvas.Font.Height := fd.Height * 7 div 10;
|
||||||
|
yy := Y + MaxHeight - abs(fd.Height);
|
||||||
|
end;
|
||||||
|
tpSuperscript:
|
||||||
|
begin
|
||||||
|
fd := GetFontData(Canvas.Font.Reference.Handle);
|
||||||
|
Canvas.Font.Height := fd.Height * 7 div 10;
|
||||||
|
yy := Y;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
WW := Canvas.TextWidth(SS);
|
WW := Canvas.TextWidth(SS);
|
||||||
if not Test then
|
if not Test then
|
||||||
Canvas.TextOut(X, Y + BaseLine - EE.Ascent, SS);
|
Canvas.TextOut(X, yy, SS);
|
||||||
X := X + WW;
|
X := X + WW;
|
||||||
|
|
||||||
|
if EE.Position <> tpNormal then
|
||||||
|
Canvas.Font.Height := oldFontHeight;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -222,6 +222,7 @@ var
|
|||||||
FName: string;
|
FName: string;
|
||||||
FSize: Integer;
|
FSize: Integer;
|
||||||
LBreakLine: Boolean;
|
LBreakLine: Boolean;
|
||||||
|
LPosition: TJvHtmlTextpos;
|
||||||
AColor, FColor: TColor;
|
AColor, FColor: TColor;
|
||||||
Element: TJvHTMLElement;
|
Element: TJvHTMLElement;
|
||||||
|
|
||||||
@ -282,6 +283,7 @@ var
|
|||||||
Element.FontSize := FSize;
|
Element.FontSize := FSize;
|
||||||
Element.FontStyle := FStyle;
|
Element.FontStyle := FStyle;
|
||||||
Element.FontColor := FColor;
|
Element.FontColor := FColor;
|
||||||
|
Element.Position := LPosition;
|
||||||
Element.BreakLine := LBreakLine;
|
Element.BreakLine := LBreakLine;
|
||||||
LBreakLine := False;
|
LBreakLine := False;
|
||||||
FElementStack.Push(Element);
|
FElementStack.Push(Element);
|
||||||
@ -349,7 +351,17 @@ var
|
|||||||
PushTag
|
PushTag
|
||||||
else
|
else
|
||||||
if LTag = '/font' then
|
if LTag = '/font' then
|
||||||
PopTag;
|
PopTag
|
||||||
|
else
|
||||||
|
if LTag = 'sub' then
|
||||||
|
LPosition := tpSubscript
|
||||||
|
else
|
||||||
|
if LTag = 'sup' then
|
||||||
|
LPosition := tpSuperscript
|
||||||
|
else
|
||||||
|
if (LTag = '/sub') or (LTag = '/sup') then
|
||||||
|
LPosition := tpNormal
|
||||||
|
else
|
||||||
if HavePar then
|
if HavePar then
|
||||||
begin
|
begin
|
||||||
repeat
|
repeat
|
||||||
@ -391,6 +403,7 @@ begin
|
|||||||
FName := Font.Name;
|
FName := Font.Name;
|
||||||
FSize := Font.Size;
|
FSize := Font.Size;
|
||||||
FColor := Font.Color;
|
FColor := Font.Color;
|
||||||
|
LPosition := tpNormal;
|
||||||
LBreakLine := False;
|
LBreakLine := False;
|
||||||
repeat
|
repeat
|
||||||
p := Pos('<', s);
|
p := Pos('<', s);
|
||||||
@ -433,14 +446,20 @@ var
|
|||||||
PendingBreak: Boolean;
|
PendingBreak: Boolean;
|
||||||
|
|
||||||
procedure SetFont(AElem: TJvHTMLElement);
|
procedure SetFont(AElem: TJvHTMLElement);
|
||||||
|
var
|
||||||
|
fd: TFontData;
|
||||||
begin
|
begin
|
||||||
with FBmp.Canvas do
|
with FBmp.Canvas do
|
||||||
begin
|
begin
|
||||||
if SameText(AElem.FontName, 'default') then
|
if SameText(AElem.FontName, 'default') then
|
||||||
Font.Name := Screen.MenuFont.Name else
|
Font.Name := Screen.MenuFont.Name
|
||||||
|
else
|
||||||
Font.Name := AElem.FontName;
|
Font.Name := AElem.FontName;
|
||||||
if AElem.FontSize = 0 then
|
if AElem.FontSize = 0 then
|
||||||
Font.Size := 10 else
|
begin
|
||||||
|
fd := GetFontData(Font.Reference.Handle);
|
||||||
|
Font.Height := fd.Height;
|
||||||
|
end else
|
||||||
Font.Size := AElem.FontSize;
|
Font.Size := AElem.FontSize;
|
||||||
Font.Style := AElem.FontStyle;
|
Font.Style := AElem.FontStyle;
|
||||||
Font.Color := AElem.FontColor;
|
Font.Color := AElem.FontColor;
|
||||||
@ -451,14 +470,35 @@ var
|
|||||||
var
|
var
|
||||||
SS: string;
|
SS: string;
|
||||||
w: Integer;
|
w: Integer;
|
||||||
|
yy: Integer;
|
||||||
|
oldFontSize: Integer;
|
||||||
begin
|
begin
|
||||||
SetFont(ee);
|
SetFont(ee);
|
||||||
if ee.SolText <> '' then
|
if ee.SolText <> '' then
|
||||||
begin
|
begin
|
||||||
|
oldFontSize := FBmp.Canvas.Font.Size;
|
||||||
SS := ee.SolText;
|
SS := ee.SolText;
|
||||||
|
case ee.Position of
|
||||||
|
tpNormal:
|
||||||
|
begin
|
||||||
|
yy := Y + Baseline - ee.Ascent - FrameTop;
|
||||||
|
end;
|
||||||
|
tpSubscript:
|
||||||
|
begin
|
||||||
|
FBmp.Canvas.Font.Height := FBmp.Canvas.Font.Height * 7 div 10;
|
||||||
|
yy := Y + MaxHeight - abs(FBmp.Canvas.Font.Height) - FrameTop;
|
||||||
|
end;
|
||||||
|
tpSuperscript:
|
||||||
|
begin
|
||||||
|
yy := Y - FrameTop;
|
||||||
|
FBmp.Canvas.Font.Height := FBmp.Canvas.Font.Height * 7 div 10;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
w := FBmp.Canvas.TextWidth(SS);
|
w := FBmp.Canvas.TextWidth(SS);
|
||||||
FBmp.Canvas.TextOut(X, Y + BaseLine - ee.Ascent - FrameTop, SS);
|
FBmp.Canvas.TextOut(X, yy, SS);
|
||||||
X := X + w;
|
X := X + w;
|
||||||
|
if ee.Position <> tpNormal then
|
||||||
|
FBmp.Canvas.Font.Size := oldFontSize;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user