TAChart: Fix text positioning in FPVectorial drawer. Move FPVectorial files to separate folder to avoid compilation errors.

git-svn-id: trunk@55519 -
This commit is contained in:
wp 2017-07-17 16:06:36 +00:00
parent e329b91495
commit 5c697f33b9
6 changed files with 69 additions and 20 deletions

6
.gitattributes vendored
View File

@ -4497,6 +4497,9 @@ components/tachart/fpdoc/talegend.xml svneol=native#text/plain
components/tachart/fpdoc/taseries.xml svneol=native#text/plain
components/tachart/fpdoc/tasources.xml svneol=native#text/plain
components/tachart/fpdoc/tatypes.xml svneol=native#text/plain
components/tachart/fpvectorial/tachartfpvectorial.lpk svneol=native#text/plain
components/tachart/fpvectorial/tachartfpvectorial.pas svneol=native#text/pascal
components/tachart/fpvectorial/tadrawerfpvectorial.pas svneol=native#text/pascal
components/tachart/icons/makeicons.bat svneol=native#text/plain
components/tachart/icons/tcalculatedchartsource.png -text svneol=unset#images/png
components/tachart/icons/tchart.png -text svneol=unset#images/png
@ -4537,8 +4540,6 @@ components/tachart/tachartbgra.lpk svneol=native#text/pascal
components/tachart/tachartbgra.pas svneol=native#text/pascal
components/tachart/tachartcombos.pas svneol=native#text/plain
components/tachart/tachartextentlink.pas svneol=native#text/pascal
components/tachart/tachartfpvectorial.lpk svneol=native#text/plain
components/tachart/tachartfpvectorial.pas svneol=native#text/pascal
components/tachart/tachartimagelist.pas svneol=native#text/pascal
components/tachart/tachartlazaruspkg.lpk svneol=native#text/plain
components/tachart/tachartlazaruspkg.pas svneol=native#text/plain
@ -4561,7 +4562,6 @@ components/tachart/tadiagramlayout.pas svneol=native#text/pascal
components/tachart/tadrawerbgra.pas svneol=native#text/pascal
components/tachart/tadrawercanvas.pas svneol=native#text/pascal
components/tachart/tadrawerfpcanvas.pas svneol=native#text/pascal
components/tachart/tadrawerfpvectorial.pas svneol=native#text/pascal
components/tachart/tadraweropengl.pas svneol=native#text/pascal
components/tachart/tadrawersvg.pas svneol=native#text/pascal
components/tachart/tadrawerwmf.pas svneol=native#text/pascal

View File

@ -1,21 +1,17 @@
<?xml version="1.0"?>
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<Package Version="3">
<Package Version="4">
<PathDelim Value="\"/>
<Name Value="TAChartFPVectorial"/>
<Type Value="RunAndDesignTime"/>
<AddToProjectUsesSection Value="True"/>
<Author Value="Alexander Klenin"/>
<CompilerOptions>
<Version Value="10"/>
<Version Value="11"/>
<PathDelim Value="\"/>
<SearchPaths>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)\$(LCLWidgetType)"/>
</SearchPaths>
<Other>
<CompilerMessages>
<UseMsgFile Value="True"/>
</CompilerMessages>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
<Description Value="FPVectorial drawing back-end for TAChart"/>
<Version Major="1"/>
@ -25,7 +21,6 @@
<UnitName Value="TADrawerFPVectorial"/>
</Item1>
</Files>
<Type Value="RunAndDesignTime"/>
<RequiredPkgs Count="3">
<Item1>
<PackageName Value="TAChartLazarusPkg"/>

View File

@ -14,7 +14,8 @@ unit TADrawerFPVectorial;
interface
uses
Graphics, Classes, FPCanvas, FPImage, FPVectorial, TAChartUtils, TADrawUtils;
SysUtils, Graphics, Classes, FPCanvas, FPImage, EasyLazFreeType, FPVectorial,
TAFonts, TAChartUtils, TADrawUtils;
type
@ -27,6 +28,8 @@ type
FBrushStyle: TFPBrushStyle;
FCanvas: TvVectorialPage;
FFont: TvFont;
FFTFont: TFreeTypefont;
FFontHeight: Integer;
FPenColor: TFPColor;
FPenStyle: TFPPenStyle;
FPenWidth: Integer;
@ -141,6 +144,7 @@ end;
constructor TFPVectorialDrawer.Create(ACanvas: TvVectorialPage);
begin
inherited Create;
InitFonts;
FCanvas := ACanvas;
FGetFontOrientationFunc := @SVGGetFontOrientationFunc;
FChartColorToFPColorFunc := @SVGChartColorToFPColor;
@ -178,7 +182,7 @@ end;
function TFPVectorialDrawer.GetFontAngle: Double;
begin
Result := FFont.Orientation;
Result := DegToRad(FFont.Orientation);
end;
function TFPVectorialDrawer.GetFontcolor: TFPColor;
@ -359,8 +363,14 @@ begin
end;
procedure TFPVectorialDrawer.SetFont(AFont: TFPCustomFont);
var
style: TFreeTypeStyles;
begin
FFont.Name := AFont.Name;
// *** FPVectorial font ***
if SameText(AFont.Name, 'default') then
FFont.Name := 'Arial' // FIXME: Find font in FreeType FontCollection
else
FFont.Name := AFont.Name;
FFont.Size := IfThen(AFont.Size = 0, DEFAULT_FONT_SIZE, AFont.Size);
FFont.Color := AFont.FPColor;
FFont.Orientation := FGetFontOrientationFunc(AFont);
@ -368,6 +378,30 @@ begin
FFont.Italic := AFont.Italic;
FFont.Underline := AFont.Underline;
FFont.Strikethrough := AFont.Strikethrough;
// *** FreeType Font (for metrics only) ***
style := [];
if AFont.Bold then Include(style, ftsBold);
if AFont.Italic then Include(style, ftsItalic);
// create a new freetype font if not yet loaded.
if (FFTFont = nil) or (FFTFont.Family <> AFont.Name) or (FFTFont.Style <> style) then
begin
FreeAndNil(FFTFont);
FFTFont := LoadFont(FFont.Name, style);
end;
if FFTFont <> nil then begin
// Set the requested font attributes
FFTFont.SizeInPixels := IfThen(AFont.Size = 0, DEFAULT_FONT_SIZE, AFont.Size);
// This should be "SizeInPoints" - but then the font is too small... Strange...
FFTFont.UnderlineDecoration := AFont.Underline;
FFTFont.StrikeoutDecoration := AFont.StrikeThrough;
FFTFont.Hinted := true;
FFTFont.Quality := grqHighQuality;
FFontHeight := round(FFTFont.TextHeight('Tg'));
end else
FFontHeight := FFont.Size;
end;
procedure TFPVectorialDrawer.SetPen(APen: TFPCustomPen);
@ -389,18 +423,33 @@ end;
function TFPVectorialDrawer.SimpleTextExtent(const AText: String): TPoint;
begin
Result.X := FFont.Size * Length(AText) * 2 div 3;
Result.Y := FFont.Size;
if FFTFont <> nil then
begin
Result.X := Round(FFTFont.TextWidth(AText));
Result.Y := FFontHeight;
end else
begin
Result.X := FFont.Size * Length(AText) * 2 div 3;
Result.Y := FFont.Size;
end;
end;
type
TFreeTypeFontOpener = class(TFreeTypeFont);
procedure TFPVectorialDrawer.SimpleTextOut(
AX, AY: Integer; const AText: String);
var
txt: TvText;
p: TPoint;
dy: Integer;
begin
// FPVectorial uses lower-left instead of upper-left corner as text start.
p := RotatePoint(Point(0, -FFont.Size), DegToRad(FFont.Orientation)) + Point(AX, InvertY(AY));
if FFTFont <> nil then
dy := round(TFreeTypeFontOpener(FFTFont).GetAscent)
else
dy := FFont.Size;
p := RotatePoint(Point(0, -dy), DegToRad(FFont.Orientation)) + Point(AX, InvertY(AY));
txt := FCanvas.AddText(p.X, p.Y, 0, AText);
txt.Font := FFont;
end;

View File

@ -23,6 +23,11 @@
<RangeChecks Value="True"/>
</Checks>
</CodeGeneration>
<Linking>
<Debugging>
<UseExternalDbgSyms Value="True"/>
</Debugging>
</Linking>
</CompilerOptions>
<Description Value="TeeChart compatible graph component"/>
<License Value=" See the file COPYING.modifiedLGPL, included in this distribution,

View File

@ -513,7 +513,7 @@ end;
function TSVGDrawer.SimpleTextExtent(const AText: String): TPoint;
begin
Result.X :=Round(FFont.TextWidth(AText));
Result.X := Round(FFont.TextWidth(AText));
Result.Y := FFontHeight;
end;