summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGraeme Geldenhuys <graeme@mastermaths.co.za>2010-02-24 09:10:40 +0200
committerGraeme Geldenhuys <graeme@mastermaths.co.za>2010-02-24 09:10:40 +0200
commit76d8bf9a89b71f6739d5171866f0650d221ab51d (patch)
tree6feed31b81f19309b75d75721f9a69e3eb16fe51
parent9457acbd0c9627a8a4a5509d21d161d30dcf40dc (diff)
parent43d97cb2d661aafa8a35ca1cf6b7d47278f9f9ce (diff)
downloadfpGUI-76d8bf9a89b71f6739d5171866f0650d221ab51d.tar.xz
Merge branch 'master' of ssh://fpgui.git.sourceforge.net/gitroot/fpgui/fpgui
-rw-r--r--docview/components/richtext/CanvasFontManager.pas49
-rw-r--r--docview/components/richtext/RichTextDisplayUnit.pas18
-rw-r--r--docview/components/richtext/RichTextLayoutUnit.pas25
-rw-r--r--docview/components/richtext/RichTextView.pas34
4 files changed, 53 insertions, 73 deletions
diff --git a/docview/components/richtext/CanvasFontManager.pas b/docview/components/richtext/CanvasFontManager.pas
index 86a52b9d..c182ba91 100644
--- a/docview/components/richtext/CanvasFontManager.pas
+++ b/docview/components/richtext/CanvasFontManager.pas
@@ -540,14 +540,17 @@ begin
FCanvas := Canvas;
FWidget := AWidget;
FLogicalFonts := TList.Create;
- FCurrentFontSpec.FaceName := 'Arial';
- FCurrentFont := nil;
- FAllowBitmapFonts := AllowBitmapFonts;
+
// get system default font spec
// as default default ;)
FPGuiFontToFontSpec( fpgApplication.DefaultFont, FDefaultFontSpec );
if FDefaultFontSpec.FaceName = '' then
raise Exception.Create('For some reason we could not create a FDefaultFontSpec instance');
+
+ // FCurrentFontSpec.FaceName := 'Arial';
+ FCurrentFontSpec.FaceName := FDefaultFontSpec.FaceName;
+ FCurrentFont := nil;
+ FAllowBitmapFonts := AllowBitmapFonts;
end;
// Destructor
@@ -935,7 +938,7 @@ ProfileEvent('DEBUG: TCanvasFontManager.SetFont >>>>');
// ack! Pfffbt! Couldn't find the font.
// Try to get the default font
- writeln('---------- here goes nothing -------------');
+// writeln('---------- here goes nothing -------------');
Font := GetFont( FDefaultFontSpec );
if Font = nil then
begin
@@ -978,17 +981,7 @@ begin
// allocate memory for storing the char widths
GetMem( FCurrentFont.pCharWidthArray, sizeof( TCharWidthArray ) );
- //if not GpiQueryWidthTable( FCanvas.Handle,
- // 0, 256,
- // FCurrentFont.pCharWidthArray^[ #0 ] ) then
- //begin
- // raise Exception.Create( 'Error getting character width table: '
- // + 'GpiQueryWidthTable error '
- // + IntToStr( WinGetLastError( AppHandle ) ) );
- //end;
-
- // Convert all widths to positive!
- // For unknown reason, sometimes GPI returns negative values...
+
for TheChar := #0 to #255 do
begin
FCurrentFont.pCharWidthArray^[ TheChar ] := Abs( FCurrentFont.pCharWidthArray^[ TheChar ] );
@@ -1003,19 +996,9 @@ begin
// For bitmap fonts, multiply by 256 manually
for TheChar := #0 to #255 do
begin
- FCurrentFont.pCharWidthArray^[ TheChar ] :=
- FCurrentFont.pCharWidthArray^[ TheChar ]
- * FontWidthPrecisionFactor;
+ FCurrentFont.pCharWidthArray^[ TheChar ] := FCurrentFont.pCharWidthArray^[ TheChar ];
end;
end;
-
- //GpiQueryFontMetrics( FCanvas.Handle,
- // sizeof( fm ),
- // fm );
- //FCurrentFont.lMaxbaseLineExt := fm.lMaxbaselineExt;
- //FCurrentFont.lAveCharWidth := fm.lAveCharWidth;
- //FCurrentFont.lMaxCharInc := fm.lMaxCharInc;
- //FCurrentFont.lMaxDescender := fm.lMaxDescender;
end;
procedure TCanvasFontManager.EnsureMetricsLoaded;
@@ -1028,12 +1011,16 @@ begin
end;
function TCanvasFontManager.CharWidth( const C: Char ): longint;
+var
+ f: TfpgFont;
begin
- EnsureMetricsLoaded;
- Result := FCurrentFont.pCharWidthArray^[ C ];
- { TODO -ograemeg -chard-coded result : This is a temporary hard-code }
-// result := fpgApplication.DefaultFont.TextWidth(C);
- Result := FCurrentFont.lAveCharWidth;
+// EnsureMetricsLoaded;
+// Result := FCurrentFont.pCharWidthArray^[ C ];
+
+ { TODO -ograeme : This needs improvement: what about font attributes, and performance. }
+ f := fpgGetFont(FCurrentFont.FaceName + '-' + IntToStr(FCurrentFont.PointSize));
+ Result := f.TextWidth(C);
+ f.Free;
end;
function TCanvasFontManager.AverageCharWidth: longint;
diff --git a/docview/components/richtext/RichTextDisplayUnit.pas b/docview/components/richtext/RichTextDisplayUnit.pas
index 5d16ab54..4c0b5dde 100644
--- a/docview/components/richtext/RichTextDisplayUnit.pas
+++ b/docview/components/richtext/RichTextDisplayUnit.pas
@@ -304,17 +304,21 @@ ProfileEvent('DEBUG: DrawRichTextLayout >>>');
Y := StartPoint.Y + Layout.FRichTextSettings.Margins.Top;
LineIndex := 0;
+ // debug only to show Margins.
+ //FontManager.Canvas.Color:= clBlue;
+ //FontManager.Canvas.DrawLine(0, y, 300, y);
+
repeat
Line := Layout.FLines^[ LineIndex ];
- BottomOfLine := Y {+ Line.Height} + 1; // bottom pixel row is top + height + 1
+ BottomOfLine := Y;
if // the line is in the range to be drawn
( LineIndex >= StartLine )
and ( LineIndex <= EndLine )
// and the line is within the cliprect
- and ( BottomOfLine < FontManager.Canvas.GetClipRect.Bottom )
- and ( Y >= FontManager.Canvas.GetClipRect.Top ) then
+ and ( BottomOfLine < FontManager.Canvas.GetClipRect.Bottom ) // -> so we can see partial lines at bottom scroll into the screen
+ and ( Y >= FontManager.Canvas.GetClipRect.Top - Line.Height) then // -> so we can see partial lines at top scroll off the screen
begin
// draw it. First decided whether selection is started or not.
DrawRichTextLine( FontManager,
@@ -322,7 +326,7 @@ ProfileEvent('DEBUG: DrawRichTextLayout >>>');
SelectionStart,
SelectionEnd,
Line,
- Point( StartPoint.X, BottomOfLine ) );
+ Point(StartPoint.X, Y) );
end;
inc( Y, Line.Height );
@@ -367,13 +371,9 @@ begin
// no text to draw
exit;
- Y := StartY
- - Layout.FRichTextSettings.Margins.Top;
-
+ Y := StartY - Layout.FRichTextSettings.Margins.Top;
Selected := false; // it's not going to change.
-
LinesPrinted := 0;
-
LineIndex := StartLine;
repeat
diff --git a/docview/components/richtext/RichTextLayoutUnit.pas b/docview/components/richtext/RichTextLayoutUnit.pas
index 97ffa131..4c6cf427 100644
--- a/docview/components/richtext/RichTextLayoutUnit.pas
+++ b/docview/components/richtext/RichTextLayoutUnit.pas
@@ -100,10 +100,10 @@ Type
Function GetCharIndex( P: PChar ): longint;
Function GetTextEnd: longint;
Public
- constructor Create( Text: PChar; Images: TfpgImageList; RichTextSettings: TRichTextSettings; FontManager: TCanvasFontManager; Width: longint );
- Destructor Destroy; Override;
- property TextEnd: longint read GetTextEnd;
+ constructor Create(Text: PChar; Images: TfpgImageList; RichTextSettings: TRichTextSettings; FontManager: TCanvasFontManager; AWidth: longint);
+ destructor Destroy; Override;
function LinkFromIndex( const CharIndexToFind: longint): string;
+ property TextEnd: longint read GetTextEnd;
property Images: TfpgImageList read FImages;
property Width: longint read FWidth;
property Height: longint read FHeight;
@@ -134,12 +134,12 @@ end;
// Create a layout of the specified rich text.
constructor TRichTextLayout.Create(Text: PChar; Images: TfpgImageList;
RichTextSettings: TRichTextSettings; FontManager: TCanvasFontManager;
- Width: longint);
+ AWidth: longint);
var
DefaultFontSpec: TFontSpec;
Begin
ProfileEvent('DEBUG: TRichTextLayout.Create >>>>');
- Inherited Create;
+ inherited Create;
FRichTextSettings := RichTextSettings;
FImages := Images;
FText := Text;
@@ -150,7 +150,7 @@ ProfileEvent('DEBUG: TRichTextLayout.Create 1 of 4');
FLinks := TStringList.Create;
FLinks.Duplicates := dupIgnore;
FFontManager := FontManager;
- FLayoutWidth := Width;
+ FLayoutWidth := AWidth;
ProfileEvent('DEBUG: TRichTextLayout.Create 2');
FHorizontalImageScale := 1;
FVerticalImageScale := 1;
@@ -287,7 +287,7 @@ Var
CurrentLine.Wrapped := false;
assert( CurrentLinkIndex >= -1 );
assert( CurrentLinkIndex < FLinks.Count );
- WordStartX := Style.LeftMargin{ * FontWidthPrecisionFactor};
+ WordStartX := Style.LeftMargin;
// next line
// reset words completed count
LineWordsCompleted := 0;
@@ -311,9 +311,9 @@ ProfileEvent('DEBUG: TRichTextLayout.Layout >>>>');
CurrentLine.Width := 0;
CurrentLine.LinkIndex := -1;
CurrentLine.Wrapped := false;
- WordStartX := Style.LeftMargin{ * FontWidthPrecisionFactor};
+ WordStartX := Style.LeftMargin;
WordX := 0;
- WrapX := FLayoutWidth - (FRichTextSettings.Margins.Right{ * FontWidthPrecisionFactor});
+ WrapX := FLayoutWidth - FRichTextSettings.Margins.Right;
LineWordsCompleted := 0;
WordStarted := false;
DisplayedCharsSinceFontChange := false;
@@ -362,7 +362,7 @@ ProfileEvent('DEBUG: TRichTextLayout.Layout >>>>');
if IsValidBitmapIndex( BitmapIndex ) then
begin
Bitmap := FImages.Item[BitmapIndex].Image;
- CurrentCharWidth := Trunc(Bitmap.Width * FontWidthPrecisionFactor * FHorizontalImageScale);
+ CurrentCharWidth := Trunc(Bitmap.Width * FHorizontalImageScale);
WordStarted := true;
BitmapHeight := Trunc(Bitmap.Height * FVerticalImageScale);
end;
@@ -396,7 +396,7 @@ ProfileEvent('DEBUG: TRichTextLayout.Layout >>>>');
ttSetLeftMargin: // SPECIAL CASE... could affect display immediately
begin
PerformStyleTag( CurrentElement.Tag, Style, WordstartX + WordX );
- if Style.LeftMargin {* FontWidthPrecisionFactor} < WordStartX then
+ if Style.LeftMargin < WordStartX then
begin
// we're already past the margin being set
if pos( 'breakifpast', CurrentElement.Tag.Arguments ) > 0 then
@@ -421,8 +421,7 @@ ProfileEvent('DEBUG: TRichTextLayout.Layout >>>>');
end;
// skip across to the new margin
- CurrentCharWidth := (Style.LeftMargin {* FontWidthPrecisionFactor})
- - WordStartX - WordX;
+ CurrentCharWidth := Style.LeftMargin - WordStartX - WordX;
// BUT! Don't treat it as a space, because you would not
// expect wrapping to take place in a margin change...
// at least not for IPF :)
diff --git a/docview/components/richtext/RichTextView.pas b/docview/components/richtext/RichTextView.pas
index 5272eee3..e50f2b62 100644
--- a/docview/components/richtext/RichTextView.pas
+++ b/docview/components/richtext/RichTextView.pas
@@ -206,9 +206,9 @@ Type
// Rectangle (GetClientRect) minus scrollbars (if they are enabled)
Function GetDrawRect: TfpgRect;
// Rectangle minus scrollbars (GetDrawRect), minus extra 2px border all round
- Function GetTextAreaRect: TfpgRect;
- Function GetTextAreaHeight: longint;
- Function GetTextAreaWidth: longint;
+ function GetTextAreaRect: TfpgRect;
+ function GetTextAreaHeight: longint;
+ function GetTextAreaWidth: longint;
// Queries
procedure GetFirstVisibleLine( Var LineIndex: longint; Var Offset: longint );
@@ -687,7 +687,7 @@ ProfileEvent('DEBUG: TRichTextView.HandlePaint 4');
if not Debug then
Draw( 0, FLayout.FNumLines )
else
- Canvas.DrawText(8, 8, GetTextAreaWidth-FScrollbarWidth, 1000, FText, [txtLeft, txtTop, txtWrap]);
+ Canvas.DrawText(8, 8, GetTextAreaWidth, 1000, FText, [txtLeft, txtTop, txtWrap]);
ProfileEvent('DEBUG: TRichTextView.HandlePaint 5');
Canvas.ClearClipRect;
@@ -1012,7 +1012,7 @@ ProfileEvent('DEBUG: TRichTextView.Layout 4');
FImages,
FRichTextSettings,
FFontManager,
- DrawWidth-(FScrollbarWidth*6) );
+ DrawWidth-(FScrollbarWidth{*6}) );
ProfileEvent('DEBUG: TRichTextView.Layout 5');
@@ -1159,20 +1159,14 @@ begin
InflateRect(Result, -2, -2);
end;
-Function TRichTextView.GetTextAreaHeight: longint;
-var
- TextArea: TfpgRect;
+function TRichTextView.GetTextAreaHeight: longint;
begin
- TextArea := GetTextAreaRect;
- Result := TextArea.Height;
+ Result := GetTextAreaRect.Height;
end;
-Function TRichTextView.GetTextAreaWidth: longint;
+function TRichTextView.GetTextAreaWidth: longint;
begin
- Result := Width;
- //if FBorderStyle <> bsNone then
- dec( Result, 4 ); // borders of component
- dec( Result, FScrollBarWidth ); // always allow space for vscrollbar
+ Result := GetTextAreaRect.Width;
end;
Procedure TRichTextView.SetupScrollbars;
@@ -1180,15 +1174,15 @@ var
AvailableWidth: longint;
MaxDisplayWidth: longint;
AvailableHeight: longint;
-Begin
+begin
+ // Reset to defaults
+ FNeedVScroll := false;
+ FNeedHScroll := false;
+
// Calculate used and available width
AvailableWidth := GetTextAreaWidth;
MaxDisplayWidth := FLayout.Width;
- // Defaults
- FNeedVScroll := false;
- FNeedHScroll := false;
-
// Horizontal scroll setup
if MaxDisplayWidth > AvailableWidth then
FNeedHScroll := true;