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/taseries.xml svneol=native#text/plain
components/tachart/fpdoc/tasources.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/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/makeicons.bat svneol=native#text/plain
components/tachart/icons/tcalculatedchartsource.png -text svneol=unset#images/png components/tachart/icons/tcalculatedchartsource.png -text svneol=unset#images/png
components/tachart/icons/tchart.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/tachartbgra.pas svneol=native#text/pascal
components/tachart/tachartcombos.pas svneol=native#text/plain components/tachart/tachartcombos.pas svneol=native#text/plain
components/tachart/tachartextentlink.pas svneol=native#text/pascal 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/tachartimagelist.pas svneol=native#text/pascal
components/tachart/tachartlazaruspkg.lpk svneol=native#text/plain components/tachart/tachartlazaruspkg.lpk svneol=native#text/plain
components/tachart/tachartlazaruspkg.pas 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/tadrawerbgra.pas svneol=native#text/pascal
components/tachart/tadrawercanvas.pas svneol=native#text/pascal components/tachart/tadrawercanvas.pas svneol=native#text/pascal
components/tachart/tadrawerfpcanvas.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/tadraweropengl.pas svneol=native#text/pascal
components/tachart/tadrawersvg.pas svneol=native#text/pascal components/tachart/tadrawersvg.pas svneol=native#text/pascal
components/tachart/tadrawerwmf.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> <CONFIG>
<Package Version="3"> <Package Version="4">
<PathDelim Value="\"/> <PathDelim Value="\"/>
<Name Value="TAChartFPVectorial"/> <Name Value="TAChartFPVectorial"/>
<Type Value="RunAndDesignTime"/>
<AddToProjectUsesSection Value="True"/>
<Author Value="Alexander Klenin"/> <Author Value="Alexander Klenin"/>
<CompilerOptions> <CompilerOptions>
<Version Value="10"/> <Version Value="11"/>
<PathDelim Value="\"/> <PathDelim Value="\"/>
<SearchPaths> <SearchPaths>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)\$(LCLWidgetType)"/> <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)\$(LCLWidgetType)"/>
</SearchPaths> </SearchPaths>
<Other>
<CompilerMessages>
<UseMsgFile Value="True"/>
</CompilerMessages>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions> </CompilerOptions>
<Description Value="FPVectorial drawing back-end for TAChart"/> <Description Value="FPVectorial drawing back-end for TAChart"/>
<Version Major="1"/> <Version Major="1"/>
@ -25,7 +21,6 @@
<UnitName Value="TADrawerFPVectorial"/> <UnitName Value="TADrawerFPVectorial"/>
</Item1> </Item1>
</Files> </Files>
<Type Value="RunAndDesignTime"/>
<RequiredPkgs Count="3"> <RequiredPkgs Count="3">
<Item1> <Item1>
<PackageName Value="TAChartLazarusPkg"/> <PackageName Value="TAChartLazarusPkg"/>

View File

@ -14,7 +14,8 @@ unit TADrawerFPVectorial;
interface interface
uses uses
Graphics, Classes, FPCanvas, FPImage, FPVectorial, TAChartUtils, TADrawUtils; SysUtils, Graphics, Classes, FPCanvas, FPImage, EasyLazFreeType, FPVectorial,
TAFonts, TAChartUtils, TADrawUtils;
type type
@ -27,6 +28,8 @@ type
FBrushStyle: TFPBrushStyle; FBrushStyle: TFPBrushStyle;
FCanvas: TvVectorialPage; FCanvas: TvVectorialPage;
FFont: TvFont; FFont: TvFont;
FFTFont: TFreeTypefont;
FFontHeight: Integer;
FPenColor: TFPColor; FPenColor: TFPColor;
FPenStyle: TFPPenStyle; FPenStyle: TFPPenStyle;
FPenWidth: Integer; FPenWidth: Integer;
@ -141,6 +144,7 @@ end;
constructor TFPVectorialDrawer.Create(ACanvas: TvVectorialPage); constructor TFPVectorialDrawer.Create(ACanvas: TvVectorialPage);
begin begin
inherited Create; inherited Create;
InitFonts;
FCanvas := ACanvas; FCanvas := ACanvas;
FGetFontOrientationFunc := @SVGGetFontOrientationFunc; FGetFontOrientationFunc := @SVGGetFontOrientationFunc;
FChartColorToFPColorFunc := @SVGChartColorToFPColor; FChartColorToFPColorFunc := @SVGChartColorToFPColor;
@ -178,7 +182,7 @@ end;
function TFPVectorialDrawer.GetFontAngle: Double; function TFPVectorialDrawer.GetFontAngle: Double;
begin begin
Result := FFont.Orientation; Result := DegToRad(FFont.Orientation);
end; end;
function TFPVectorialDrawer.GetFontcolor: TFPColor; function TFPVectorialDrawer.GetFontcolor: TFPColor;
@ -359,8 +363,14 @@ begin
end; end;
procedure TFPVectorialDrawer.SetFont(AFont: TFPCustomFont); procedure TFPVectorialDrawer.SetFont(AFont: TFPCustomFont);
var
style: TFreeTypeStyles;
begin 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.Size := IfThen(AFont.Size = 0, DEFAULT_FONT_SIZE, AFont.Size);
FFont.Color := AFont.FPColor; FFont.Color := AFont.FPColor;
FFont.Orientation := FGetFontOrientationFunc(AFont); FFont.Orientation := FGetFontOrientationFunc(AFont);
@ -368,6 +378,30 @@ begin
FFont.Italic := AFont.Italic; FFont.Italic := AFont.Italic;
FFont.Underline := AFont.Underline; FFont.Underline := AFont.Underline;
FFont.Strikethrough := AFont.Strikethrough; 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; end;
procedure TFPVectorialDrawer.SetPen(APen: TFPCustomPen); procedure TFPVectorialDrawer.SetPen(APen: TFPCustomPen);
@ -389,18 +423,33 @@ end;
function TFPVectorialDrawer.SimpleTextExtent(const AText: String): TPoint; function TFPVectorialDrawer.SimpleTextExtent(const AText: String): TPoint;
begin begin
Result.X := FFont.Size * Length(AText) * 2 div 3; if FFTFont <> nil then
Result.Y := FFont.Size; 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; end;
type
TFreeTypeFontOpener = class(TFreeTypeFont);
procedure TFPVectorialDrawer.SimpleTextOut( procedure TFPVectorialDrawer.SimpleTextOut(
AX, AY: Integer; const AText: String); AX, AY: Integer; const AText: String);
var var
txt: TvText; txt: TvText;
p: TPoint; p: TPoint;
dy: Integer;
begin begin
// FPVectorial uses lower-left instead of upper-left corner as text start. // 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 := FCanvas.AddText(p.X, p.Y, 0, AText);
txt.Font := FFont; txt.Font := FFont;
end; end;

View File

@ -23,6 +23,11 @@
<RangeChecks Value="True"/> <RangeChecks Value="True"/>
</Checks> </Checks>
</CodeGeneration> </CodeGeneration>
<Linking>
<Debugging>
<UseExternalDbgSyms Value="True"/>
</Debugging>
</Linking>
</CompilerOptions> </CompilerOptions>
<Description Value="TeeChart compatible graph component"/> <Description Value="TeeChart compatible graph component"/>
<License Value=" See the file COPYING.modifiedLGPL, included in this distribution, <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; function TSVGDrawer.SimpleTextExtent(const AText: String): TPoint;
begin begin
Result.X :=Round(FFont.TextWidth(AText)); Result.X := Round(FFont.TextWidth(AText));
Result.Y := FFontHeight; Result.Y := FFontHeight;
end; end;