summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGraeme Geldenhuys <graemeg@gmail.com>2013-05-16 12:18:46 +0100
committerGraeme Geldenhuys <graemeg@gmail.com>2013-05-16 12:18:46 +0100
commit55ddef26ee20f21fcae48b2589a93ce95773bebc (patch)
treec974aa1b4b3c3f298258d2fd9ebbc72e8e1dd414
parent7ab28a23510d698c2036e4baf81275010bb87a9b (diff)
downloadfpGUI-55ddef26ee20f21fcae48b2589a93ce95773bebc.tar.xz
aggcanvas: adds preliminary font support
- moved fpg_fontcache unit to corelib/render/software/ - added fpg_fontcache unit to x11 fpgui_toolkit.lpk package - translates FontDesc to FontCache item. Tested under X11 only.
-rw-r--r--src/corelib/render/software/Agg2D.pas26
-rw-r--r--src/corelib/render/software/agg_platform_x11.inc81
-rw-r--r--src/corelib/render/software/fpg_fontcache.pas (renamed from src/corelib/fpg_fontcache.pas)0
-rw-r--r--src/corelib/x11/fpgui_toolkit.lpk6
-rw-r--r--src/corelib/x11/fpgui_toolkit.pas2
5 files changed, 103 insertions, 12 deletions
diff --git a/src/corelib/render/software/Agg2D.pas b/src/corelib/render/software/Agg2D.pas
index d729e4fb..13860ffd 100644
--- a/src/corelib/render/software/Agg2D.pas
+++ b/src/corelib/render/software/Agg2D.pas
@@ -2670,7 +2670,7 @@ begin
m_fontEngine.hinting_(m_textHints );
if cache = AGG_VectorFontCache then
- m_fontEngine.height_(height )
+ m_fontEngine.height_(height{ * 1.3333} ) // 9pt = ~12px so that is a ration of 1.3333
else
m_fontEngine.height_(worldToScreen(height ) );
{$ENDIF}
@@ -3555,18 +3555,24 @@ begin
end;
procedure TAgg2D.DoSetFontRes(fntres: TfpgFontResourceBase);
+{$IFDEF WINDOWS}
begin
- {$NOTE This is only temporary until I can correctly query font names }
- {$IFDEF WINDOWS}
Font('Arial', 13);
- {$ELSE}
- {$IFDEF BSD}
- Font('/usr/local/lib/X11/fonts/Liberation/LiberationSans-Regular.ttf', 13);
- {$ELSE}
- Font('/usr/share/fonts/truetype/ttf-liberation/LiberationSans-Regular.ttf', 13);
- {$ENDIF}
- {$ENDIF}
end;
+{$ENDIF}
+{$IFDEF UNIX}
+var
+ s: TfpgString;
+ i: integer;
+ fnt: TFontCacheItem;
+ lSize: double;
+begin
+ fnt := FontCacheItemFromFontDesc(TfpgFontResource(fntres).FontDesc, lSize);
+ i := gFontCache.Find(fnt);
+ if i > 0 then
+ Font(gFontCache.Items[i].FileName, lSize, fnt.IsBold, fnt.IsItalic);
+end;
+{$ENDIF}
procedure TAgg2D.DoSetTextColor(cl: TfpgColor);
var
diff --git a/src/corelib/render/software/agg_platform_x11.inc b/src/corelib/render/software/agg_platform_x11.inc
index 331b572e..0b070713 100644
--- a/src/corelib/render/software/agg_platform_x11.inc
+++ b/src/corelib/render/software/agg_platform_x11.inc
@@ -18,6 +18,7 @@
{$ifdef uses_implementation}
fpg_x11,
+ fpg_fontcache,
{$endif}
@@ -27,6 +28,86 @@ type
// to get access to protected methods (seeing that FPC doesn't support Friend-classes)
TImageHack = class(TfpgImage);
+function FontCacheItemFromFontDesc(const desc: string; var asize: double): TFontCacheItem;
+var
+ facename: string;
+ cp: integer;
+ c: char;
+ token: string;
+ prop, propval: string;
+
+ function NextC: char;
+ begin
+ Inc(cp);
+ if cp > length(desc) then
+ c := #0
+ else
+ c := desc[cp];
+ Result := c;
+ end;
+
+ procedure NextToken;
+ begin
+ token := '';
+ while (c <> #0) and (c in [' ', 'a'..'z', 'A'..'Z', '_', '0'..'9']) do
+ begin
+ token := token + c;
+ NextC;
+ end;
+ end;
+
+begin
+ Result := TFontCacheItem.Create('');
+
+ cp := 0;
+ NextC;
+ NextToken;
+
+ facename := token;
+ // Add known substites
+ if lowercase(facename) = 'times' then
+ facename := 'Times New Roman'
+ else if lowercase(facename) = 'courier' then
+ facename := 'Courier New'
+ else if lowercase(facename) = 'monospace' then
+ facename := 'Courier New';
+ Result.FamilyName := facename;
+
+ if c = '-' then
+ begin
+ NextC;
+ NextToken;
+ asize := StrToIntDef(token, 0);
+ end;
+
+ while c = ':' do
+ begin
+ NextC;
+ NextToken;
+
+ prop := UpperCase(token);
+ propval := '';
+
+ if c = '=' then
+ begin
+ NextC;
+ NextToken;
+ propval := UpperCase(token);
+ end;
+
+ if prop = 'BOLD' then
+ Result.IsBold := True
+ else if prop = 'ITALIC' then
+ Result.IsItalic := True;
+// else if prop = 'ANTIALIAS' then
+// if propval = 'FALSE' then
+// lf.lfQuality := NONANTIALIASED_QUALITY else
+// if propval = 'DEFAULT' then
+// lf.lfQuality := DEFAULT_QUALITY;
+ end;
+end;
+
+
procedure TAgg2D.DoPutBufferToScreen(x, y, w, h: TfpgCoord);
var
drawgc: Tgc;
diff --git a/src/corelib/fpg_fontcache.pas b/src/corelib/render/software/fpg_fontcache.pas
index 46681938..46681938 100644
--- a/src/corelib/fpg_fontcache.pas
+++ b/src/corelib/render/software/fpg_fontcache.pas
diff --git a/src/corelib/x11/fpgui_toolkit.lpk b/src/corelib/x11/fpgui_toolkit.lpk
index 4616f7c4..d3d468b9 100644
--- a/src/corelib/x11/fpgui_toolkit.lpk
+++ b/src/corelib/x11/fpgui_toolkit.lpk
@@ -29,7 +29,7 @@
<Description Value="fpGUI Toolkit"/>
<License Value="LGPL 2 with static linking exception."/>
<Version Major="1"/>
- <Files Count="101">
+ <Files Count="102">
<Item1>
<Filename Value="../stdimages.inc"/>
<Type Value="Include"/>
@@ -434,6 +434,10 @@
<Filename Value="../fpg_dbugmsg.pas"/>
<UnitName Value="fpg_dbugmsg"/>
</Item101>
+ <Item102>
+ <Filename Value="../render/software/fpg_fontcache.pas"/>
+ <UnitName Value="fpg_fontcache"/>
+ </Item102>
</Files>
<LazDoc Paths="../../../docs/xml/corelib;../../../docs/xml/corelib/x11;../../../docs/xml/corelib/gdi;../../../docs/xml/gui"/>
<RequiredPkgs Count="1">
diff --git a/src/corelib/x11/fpgui_toolkit.pas b/src/corelib/x11/fpgui_toolkit.pas
index 65239b89..bdbe1a3f 100644
--- a/src/corelib/x11/fpgui_toolkit.pas
+++ b/src/corelib/x11/fpgui_toolkit.pas
@@ -22,7 +22,7 @@ uses
fpg_stylemanager, fpg_style_win2k, fpg_style_motif, fpg_style_clearlooks,
fpg_style_bluecurve, fpg_style_bitmap, fpg_readonly, fpg_imgfmt_png,
U_Command, U_Pdf, U_Report, U_ReportImages, U_Visu, fpg_trayicon, Agg2D,
- fpg_dbugintf, fpg_dbugmsg;
+ fpg_dbugintf, fpg_dbugmsg, fpg_fontcache;
implementation