mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-11 20:39:15 +02:00
gtk2:
- enable GetObject for HFont - use MulDiv in font size calculation instead of *, div (as in font.inc) (Grzegorz Zakrzewski) - use PixelsPerInchY instead of PixelsPerInchX (Grzegorz Zakrzewski) - minor formatting git-svn-id: trunk@13985 -
This commit is contained in:
parent
4de32f3116
commit
dff1565eb1
@ -598,7 +598,7 @@ constructor TFont.Create;
|
|||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
FColor := clWindowText;
|
FColor := clWindowText;
|
||||||
FPixelsPerInch := ScreenInfo.PixelsPerInchX;
|
FPixelsPerInch := ScreenInfo.PixelsPerInchY;
|
||||||
FPitch := DefFontData.Pitch;
|
FPitch := DefFontData.Pitch;
|
||||||
FCharSet := DefFontData.CharSet;
|
FCharSet := DefFontData.CharSet;
|
||||||
DelayAllocate := True;
|
DelayAllocate := True;
|
||||||
|
@ -1685,7 +1685,7 @@ var
|
|||||||
{$IFDEF DebugGDK}EndGDKErrorTrap;{$ENDIF}
|
{$IFDEF DebugGDK}EndGDKErrorTrap;{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Procedure EnsureAsColor;
|
procedure EnsureAsColor;
|
||||||
begin
|
begin
|
||||||
AllocGDIColor(DC, GDIColor);
|
AllocGDIColor(DC, GDIColor);
|
||||||
//DebugLn('EnsureAsColor ',DbgS(GDIColor^.ColorRef),' AsBackground=',AsBackground);
|
//DebugLn('EnsureAsColor ',DbgS(GDIColor^.ColorRef),' AsBackground=',AsBackground);
|
||||||
|
@ -5389,15 +5389,11 @@ begin
|
|||||||
end;
|
end;
|
||||||
gdiFont:
|
gdiFont:
|
||||||
begin
|
begin
|
||||||
{$IfDef GTK2}
|
|
||||||
Assert(False, 'Trace:TODO: [TGtkWidgetSet.GetObject] gdiFont(PANGO)');
|
|
||||||
{$Else}
|
|
||||||
if Buf = nil
|
if Buf = nil
|
||||||
then begin
|
then begin
|
||||||
Result := SizeOf(GDIObject^.LogFont);
|
Result := SizeOf(GDIObject^.LogFont);
|
||||||
Exit;
|
Exit;
|
||||||
End;
|
end;
|
||||||
|
|
||||||
if BufSize >= SizeOf(GDIObject^.LogFont)
|
if BufSize >= SizeOf(GDIObject^.LogFont)
|
||||||
then begin
|
then begin
|
||||||
PLogfont(Buf)^ := GDIObject^.LogFont;
|
PLogfont(Buf)^ := GDIObject^.LogFont;
|
||||||
@ -5408,7 +5404,6 @@ begin
|
|||||||
Move(GDIObject^.LogFont,Buf^,BufSize);
|
Move(GDIObject^.LogFont,Buf^,BufSize);
|
||||||
Result:=BufSize;
|
Result:=BufSize;
|
||||||
end;
|
end;
|
||||||
{$EndIf}
|
|
||||||
end;
|
end;
|
||||||
gdiPen:
|
gdiPen:
|
||||||
begin
|
begin
|
||||||
|
@ -153,18 +153,20 @@ begin
|
|||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
with LogFont do begin
|
with LogFont do
|
||||||
|
begin
|
||||||
if lfFaceName[0] = #0
|
if lfFaceName[0] = #0
|
||||||
then begin
|
then begin
|
||||||
Assert(false,'ERROR: [Tgt2kObject.CreateFontIndirectEx] No fontname');
|
Assert(false,'ERROR: [Tgt2kObject.CreateFontIndirectEx] No fontname');
|
||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if (lfHeight=0) and (CompareText(lfFacename,'default')=0) then begin
|
if (lfHeight = 0) and (lfEscapement = 0) and (CompareText(lfFacename, 'default') = 0) then
|
||||||
|
begin
|
||||||
{$IFDEF VerboseFonts}
|
{$IFDEF VerboseFonts}
|
||||||
DebugLn(['TGtk2WidgetSet.CreateFontIndirectEx Creating default font']);
|
DebugLn(['TGtk2WidgetSet.CreateFontIndirectEx Creating default font']);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
GdiObject:=CreateDefaultFont;
|
GdiObject := CreateDefaultFont;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -194,21 +196,22 @@ begin
|
|||||||
PangoDesc := pango_font_description_from_string(PChar(FullString));
|
PangoDesc := pango_font_description_from_string(PChar(FullString));
|
||||||
|
|
||||||
if lfWeight <> FW_DONTCARE then
|
if lfWeight <> FW_DONTCARE then
|
||||||
pango_font_description_set_weight(PangoDesc,lfWeight);
|
pango_font_description_set_weight(PangoDesc, lfWeight);
|
||||||
|
|
||||||
if lfItalic <> 0 then
|
if lfItalic <> 0 then
|
||||||
pango_font_description_set_style(PangoDesc,PANGO_STYLE_ITALIC);
|
pango_font_description_set_style(PangoDesc, PANGO_STYLE_ITALIC);
|
||||||
|
|
||||||
if (aSize=0) and (lfHeight<>0) then begin
|
if (aSize=0) and (lfHeight<>0) then
|
||||||
|
begin
|
||||||
// a size is not specified, try to calculate one based on lfHeight
|
// a size is not specified, try to calculate one based on lfHeight
|
||||||
// and use this value not in the font name but set this value appart
|
// and use this value not in the font name but set this value appart
|
||||||
// NOTE: in gtk2.8 is possible to use pango_font_description_set_absolute_size
|
// NOTE: in gtk2.8 is possible to use pango_font_description_set_absolute_size
|
||||||
// which would be great with the given lfheight value, but older gtk2 version
|
// which would be great with the given lfheight value, but older gtk2 version
|
||||||
// doesn't have this funtion
|
// doesn't have this funtion
|
||||||
if lfHeight<0 then
|
if lfHeight<0 then
|
||||||
aSize:= (abs(lfheight) * 72 * PANGO_SCALE) div ScreenInfo.PixelsPerInchX
|
aSize := -MulDiv(lfheight, 72, ScreenInfo.PixelsPerInchY) * PANGO_SCALE
|
||||||
else
|
else
|
||||||
aSize:=lfHeight*PANGO_SCALE;
|
aSize := lfHeight * PANGO_SCALE;
|
||||||
pango_font_description_set_size(PangoDesc, aSize);
|
pango_font_description_set_size(PangoDesc, aSize);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -221,31 +224,34 @@ begin
|
|||||||
|
|
||||||
pango_layout_set_font_description(CurFont,PangoDesc);
|
pango_layout_set_font_description(CurFont,PangoDesc);
|
||||||
|
|
||||||
if (LogFont.lfUnderline<>0) or (LogFont.lfStrikeOut<>0) then begin
|
if (LogFont.lfUnderline<>0) or (LogFont.lfStrikeOut<>0) then
|
||||||
|
begin
|
||||||
AttrListTemporary := false;
|
AttrListTemporary := false;
|
||||||
AttrList := pango_layout_get_attributes(CurFont);
|
AttrList := pango_layout_get_attributes(CurFont);
|
||||||
if (AttrList = nil) then begin
|
if (AttrList = nil) then
|
||||||
|
begin
|
||||||
AttrList := pango_attr_list_new();
|
AttrList := pango_attr_list_new();
|
||||||
AttrListTemporary := true;
|
AttrListTemporary := True;
|
||||||
end;
|
end;
|
||||||
if LogFont.lfUnderline<>0 then
|
if LogFont.lfUnderline <> 0 then
|
||||||
Attr := pango_attr_underline_new(PANGO_UNDERLINE_SINGLE)
|
Attr := pango_attr_underline_new(PANGO_UNDERLINE_SINGLE)
|
||||||
else
|
else
|
||||||
Attr := pango_attr_underline_new(PANGO_UNDERLINE_NONE);
|
Attr := pango_attr_underline_new(PANGO_UNDERLINE_NONE);
|
||||||
pango_attr_list_change(AttrList,Attr);
|
pango_attr_list_change(AttrList, Attr);
|
||||||
|
|
||||||
Attr := pango_attr_strikethrough_new(LogFont.lfStrikeOut<>0);
|
Attr := pango_attr_strikethrough_new(LogFont.lfStrikeOut<>0);
|
||||||
pango_attr_list_change(AttrList,Attr);
|
pango_attr_list_change(AttrList, Attr);
|
||||||
|
|
||||||
if AttrListTemporary then
|
if AttrListTemporary then
|
||||||
pango_attr_list_unref(AttrList);
|
pango_attr_list_unref(AttrList);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
pango_layout_set_single_paragraph_mode(CurFont, TRUE);
|
pango_layout_set_single_paragraph_mode(CurFont, True);
|
||||||
pango_layout_set_width(CurFont, -1);
|
pango_layout_set_width(CurFont, -1);
|
||||||
pango_layout_set_alignment(CurFont, PANGO_ALIGN_LEFT);
|
pango_layout_set_alignment(CurFont, PANGO_ALIGN_LEFT);
|
||||||
|
|
||||||
if (lfEscapement<>0) then begin
|
if (lfEscapement <> 0) then
|
||||||
|
begin
|
||||||
DebugLn(['TGtk2WidgetSet.CreateFontIndirectEx rotating font is not implemented yet, because it needs pango 1.16: lfEscapement=',lfEscapement]);
|
DebugLn(['TGtk2WidgetSet.CreateFontIndirectEx rotating font is not implemented yet, because it needs pango 1.16: lfEscapement=',lfEscapement]);
|
||||||
{DebugLn(['TGtk2WidgetSet.CreateFontIndirectEx ',pango_version_check(1,16,0)]);
|
{DebugLn(['TGtk2WidgetSet.CreateFontIndirectEx ',pango_version_check(1,16,0)]);
|
||||||
if pango_version_check(1,16,0)<>null then begin
|
if pango_version_check(1,16,0)<>null then begin
|
||||||
@ -255,13 +261,14 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
finally
|
finally
|
||||||
if (CachedFont=nil)
|
if (CachedFont = nil) and (GdiObject<>nil) and (GdiObject^.GDIFontObject <> nil) then
|
||||||
and (GdiObject<>nil) and (GdiObject^.GDIFontObject <> nil) then begin
|
begin
|
||||||
// add to cache
|
// add to cache
|
||||||
CachedFont:=FontCache.Add(GdiObject^.GDIFontObject,LogFont,LongFontName);
|
CachedFont := FontCache.Add(GdiObject^.GDIFontObject, LogFont, LongFontName);
|
||||||
if CachedFont<>nil then begin
|
if CachedFont <> nil then
|
||||||
CachedFont.PangoFontDescription:=PangoDesc;
|
begin
|
||||||
PangoDesc:=nil;
|
CachedFont.PangoFontDescription := PangoDesc;
|
||||||
|
PangoDesc := nil;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
{$IFDEF VerboseFonts}
|
{$IFDEF VerboseFonts}
|
||||||
|
Loading…
Reference in New Issue
Block a user