summaryrefslogtreecommitdiff
path: root/docview/components/richtext
diff options
context:
space:
mode:
authorPhilippe Lévi <Philippe@quarta.com.br>2015-08-22 09:02:18 +0100
committerGraeme Geldenhuys <graemeg@gmail.com>2015-08-22 09:03:25 +0100
commit7a840bd1da714ff057995bebf5240602e25a772d (patch)
treec752b25a70c01b51f40e71cdecdab812cbdfb6a6 /docview/components/richtext
parent2e3c7d9c21ccb8dfe1dd0de621a3a92c76eefd66 (diff)
downloadfpGUI-7a840bd1da714ff057995bebf5240602e25a772d.tar.xz
richview: fix bug where varied size fonts didn't start on baseline.
Diffstat (limited to 'docview/components/richtext')
-rw-r--r--docview/components/richtext/CanvasFontManager.pas6
-rw-r--r--docview/components/richtext/RichTextDisplayUnit.pas4
-rw-r--r--docview/components/richtext/RichTextLayoutUnit.pas7
3 files changed, 16 insertions, 1 deletions
diff --git a/docview/components/richtext/CanvasFontManager.pas b/docview/components/richtext/CanvasFontManager.pas
index 71e6d2fa..fe9606e6 100644
--- a/docview/components/richtext/CanvasFontManager.pas
+++ b/docview/components/richtext/CanvasFontManager.pas
@@ -44,6 +44,7 @@ type
constructor Create(ACanvas: TfpgCanvas; AWidget: TfpgWidget); reintroduce;
destructor Destroy; override;
function AverageCharWidth: longint;
+ function CharAscender: longint;
function CharDescender: longint;
function CharHeight: longint;
function CharWidth( const C: TfpgChar ): longint; // Retrieve the width of the given char, in the current font
@@ -314,6 +315,11 @@ begin
Result := FCanvas.Font.TextWidth('c');
end;
+function TCanvasFontManager.CharAscender: longint;
+begin
+ Result := FCanvas.Font.Ascent;
+end;
+
function TCanvasFontManager.MaximumCharWidth: longint;
begin
Result := FCanvas.Font.TextWidth('W');
diff --git a/docview/components/richtext/RichTextDisplayUnit.pas b/docview/components/richtext/RichTextDisplayUnit.pas
index 613dba84..cfdd20a7 100644
--- a/docview/components/richtext/RichTextDisplayUnit.pas
+++ b/docview/components/richtext/RichTextDisplayUnit.pas
@@ -122,6 +122,7 @@ Procedure DrawRichTextLine( var FontManager: TCanvasFontManager;
Line: TLayoutLine; Start: TPoint );
var
X, Y: longint;
+ YBaseLine: longint;
Element: TTextElement;
StartedDrawing: boolean;
Style: TTextDrawStyle;
@@ -180,7 +181,7 @@ ProfileEvent('DEBUG: DrawRichTextLine >>>');
TextBlockStart := P;
- Y := Start.Y; // + Line.MaxDescender; // co-ordinates are from top/left, so do we need descender? [Graeme]
+ YBaseLine := Start.Y + Line.MaxAscender;
while P < EndP do
begin
@@ -209,6 +210,7 @@ ProfileEvent('DEBUG: DrawRichTextLine >>>');
StartedDrawing := true;
end;
+ Y := YBaseLine - FontManager.CharAscender;
// Now do the drawing
if Element.ElementType = teImage then
begin
diff --git a/docview/components/richtext/RichTextLayoutUnit.pas b/docview/components/richtext/RichTextLayoutUnit.pas
index f5efe08a..8e39d65f 100644
--- a/docview/components/richtext/RichTextLayoutUnit.pas
+++ b/docview/components/richtext/RichTextLayoutUnit.pas
@@ -23,6 +23,7 @@ Type
Length: longint;
Height: longint;
Width: longint;
+ MaxAscender: longint;
MaxDescender: longint;
MaxTextHeight: longint; // maximum height of text, doesn't include images
LinkIndex: longint; // link index at start of line, if any
@@ -240,8 +241,10 @@ Procedure TRichTextLayout.CheckFontHeights( Var Line: TLayoutLine );
var
FontHeight: longint;
Descender: longint;
+ Ascender: longint;
begin
FontHeight := FFontManager.CharHeight;
+ Ascender := FFontManager.CharAscender;
Descender := FFontManager.CharDescender;
if FontHeight > Line.Height then
@@ -252,6 +255,9 @@ begin
if Descender > Line.MaxDescender then
Line.MaxDescender := Descender;
+
+ if Ascender > Line.MaxAscender then
+ Line.MaxAscender := Ascender;
end;
function TRichTextLayout.IsValidBitmapIndex( Index: longint ): boolean;
@@ -297,6 +303,7 @@ Var
CurrentLine := TLayoutLine.Create;
CurrentLine.Style := Style;
CurrentLine.Height := 0;
+ CurrentLine.MaxAscender := 0;
CurrentLine.MaxDescender := 0;
CurrentLine.MaxTextHeight := 0;
CurrentLine.Width := 0;