From 32b72756c1091aa577d901c167315b0138cd5626 Mon Sep 17 00:00:00 2001 From: mattias Date: Thu, 10 Dec 2009 19:06:46 +0000 Subject: [PATCH] aggpas: started pango in agglcl git-svn-id: trunk@23074 - --- components/aggpas/lazarus/example/unit3.pas | 35 ++++----------------- components/aggpas/src/agg_lcl.pas | 26 +++++++++++++++ 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/components/aggpas/lazarus/example/unit3.pas b/components/aggpas/lazarus/example/unit3.pas index 7abc26e1ce..838fd72057 100644 --- a/components/aggpas/lazarus/example/unit3.pas +++ b/components/aggpas/lazarus/example/unit3.pas @@ -6,7 +6,7 @@ interface uses Classes, SysUtils, LCLProc, FileUtil, LResources, Forms, Controls, Graphics, - Dialogs, FPimage, agg_fpimage, Agg_LCL, pango, LCLType, GTKProc, GtkDef, gtk2; + Dialogs, FPimage, agg_fpimage, Agg_LCL; type @@ -20,7 +20,6 @@ type public AggLCLCanvas: TAggLCLCanvas; Bitmap1: TBitmap; - procedure CreatePangoFont(AggFont: TAggLCLFont); end; var @@ -32,8 +31,6 @@ implementation procedure TForm1.FormCreate(Sender: TObject); var - HasFont: Boolean; - FontFilename: String; s: String; TxtW: integer; TxtH: integer; @@ -46,17 +43,16 @@ begin Image.PixelFormat:=afpimRGBA32; Image.SetSize(500,500); end; - HasFont:=true; // paint to agg canvas with AggLCLCanvas do begin - if HasFont then begin + {if HasFont then begin FontFilename:=SetDirSeparators('../../verdana.ttf'); if not FileExists(FontFilename) then raise Exception.Create('file not found: '+FontFilename+' CurDir='+GetCurrentDirUTF8); - Font.LoadFromFile(FontFilename); - Font.Size:=10; - Font.Color:=clBlack; - end; + Font.LoadFromFile(FontFilename);} + Font.Size:=10; + Font.Color:=clBlack; + Font.LoadViaPango; // solid white background Brush.Color:=clWhite; @@ -72,7 +68,6 @@ begin TxtY:=40; FillRect(TxtX,TxtY,TxtX+TxtW,TxtY+TxtH); TextOut(TxtX,TxtY,s); - end; // convert to LCL native pixel format @@ -107,24 +102,6 @@ begin Canvas.Draw(0,0,Bitmap1); end; -procedure TForm1.CreatePangoFont(AggFont: TAggLCLFont); -var - FullString: String; - PangoDesc: PPangoFontDescription; - PangoLayout: PPangoLayout; -begin - FullString := AggFont.Name+' '+IntToStr(AggFont.Size); - PangoDesc := pango_font_description_from_string(PChar(FullString)); - if AggFont.Bold then - pango_font_description_set_weight(PangoDesc, FW_BOLD); - if AggFont.Italic then - pango_font_description_set_style(PangoDesc, PANGO_STYLE_ITALIC); - pango_font_description_set_size(PangoDesc, AggFont.Size*PANGO_SCALE); - PangoLayout:=gtk_widget_create_pango_layout(GetStyleWidget(lgsdefault), nil); - pango_layout_set_font_description(PangoLayout,PangoDesc); - -end; - initialization {$I unit3.lrs} diff --git a/components/aggpas/src/agg_lcl.pas b/components/aggpas/src/agg_lcl.pas index 8a4053adbf..0646aa3654 100644 --- a/components/aggpas/src/agg_lcl.pas +++ b/components/aggpas/src/agg_lcl.pas @@ -12,6 +12,9 @@ uses Windows , {$ENDIF} Classes ,Graphics, LCLProc, types, IntfGraphics, GraphType, FPimage, FPCanvas, + {$IFDEF LCLGtk2} + pango, LCLType, GTKProc, GtkDef, gtk2, + {$ENDIF} agg_arc, GraphMath, agg_fpimage, agg_basics; type @@ -66,6 +69,9 @@ type constructor Create; override; function AggHeightToSize(const h: double): double; override; function SizeToAggHeight(const s: double): double; override; + {$IFDEF LCLGtk2} + procedure LoadViaPango; + {$ENDIF} property Color: TColor read FColor write SetColor; property PixelsPerInch: Integer read FPixelsPerInch write FPixelsPerInch; end; @@ -801,6 +807,26 @@ begin Result:=s*FPixelsPerInch / 72; end; +{$IFDEF LCLGtk2} +procedure TAggLCLFont.LoadViaPango; +var + FullString: String; + PangoDesc: PPangoFontDescription; + PangoLayout: PPangoLayout; +begin + FullString := Name+' '+IntToStr(Size); + PangoDesc := pango_font_description_from_string(PChar(FullString)); + if Bold then + pango_font_description_set_weight(PangoDesc, FW_BOLD); + if Italic then + pango_font_description_set_style(PangoDesc, PANGO_STYLE_ITALIC); + pango_font_description_set_size(PangoDesc, Size*PANGO_SCALE); + PangoLayout:=gtk_widget_create_pango_layout(GetStyleWidget(lgsdefault), nil); + pango_layout_set_font_description(PangoLayout,PangoDesc); + +end; +{$ENDIF} + { TAggLCLImage } procedure TAggLCLImage.ReallocData;