From b905dfda780c79e6a840fa81ed8338dfedde4c5d Mon Sep 17 00:00:00 2001 From: dmitry Date: Mon, 23 Aug 2010 07:01:12 +0000 Subject: [PATCH] carbon: use ThemeSystemFont instead of ATSU font as default font git-svn-id: trunk@27169 - --- lcl/interfaces/carbon/carbongdiobjects.pp | 22 ++++++++++-------- lcl/interfaces/carbon/carbonproc.pp | 28 +++++++++++++++++++++-- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/lcl/interfaces/carbon/carbongdiobjects.pp b/lcl/interfaces/carbon/carbongdiobjects.pp index c07b5c7129..86afcc366a 100644 --- a/lcl/interfaces/carbon/carbongdiobjects.pp +++ b/lcl/interfaces/carbon/carbongdiobjects.pp @@ -1158,7 +1158,7 @@ end; constructor TCarbonFont.Create(AGlobal: Boolean); begin inherited Create(AGlobal); - + FStyle := DefaultTextStyle; FLineRotation := 0; end; @@ -1195,6 +1195,7 @@ var S: ByteCount; A: ATSUAttributeValuePtr; ID: ATSUFontID; + H: Integer; const SSetAttrs = 'ATSUSetAttributes'; SName = 'CreateStyle'; @@ -1216,15 +1217,16 @@ begin SSetAttrs, 'kATSUFontTag'); end; - if ALogFont.lfHeight <> 0 then - begin - Attr := kATSUSizeTag; - M := Abs(ALogFont.lfHeight) shl 16; - A := @M; - S := SizeOf(M); - OSError(ATSUSetAttributes(Result, 1, @Attr, @S, @A), Self, SName, - SSetAttrs, 'kATSUSizeTag'); - end; + if ALogFont.lfHeight = 0 + then H := CarbonDefaultFontSize + else H := ALogFont.lfHeight; + + Attr := kATSUSizeTag; + M := Abs(ALogFont.lfHeight) shl 16; + A := @M; + S := SizeOf(M); + OSError(ATSUSetAttributes(Result, 1, @Attr, @S, @A), Self, SName, + SSetAttrs, 'kATSUSizeTag'); if ALogFont.lfWeight > FW_NORMAL then begin diff --git a/lcl/interfaces/carbon/carbonproc.pp b/lcl/interfaces/carbon/carbonproc.pp index fb258364e9..2500b676bd 100644 --- a/lcl/interfaces/carbon/carbonproc.pp +++ b/lcl/interfaces/carbon/carbonproc.pp @@ -64,6 +64,10 @@ var HIViewClassID: CFStringRef; // class CFString for HIView CustomControlClassID: CFStringRef; // class CFString for custom control +var + CarbonDefaultFont : AnsiString = ''; + CarbonDefaultFontSize : Integer = 0; + {$I mackeycodes.inc} function VirtualKeyCodeToMac(AKey: Word): Word; @@ -494,13 +498,19 @@ end; Returns: Carbon font ID of font with the specified name ------------------------------------------------------------------------------} function FindCarbonFontID(const FontName: String): ATSUFontID; +var + fn : String; begin Result := 0; //DebugLn('FindCarbonFontID ' + FontName); - if (FontName <> '') and not SameText(FontName, 'default') then + + if SameText(FontName, 'default') + then fn:=CarbonDefaultFont + else fn:=FontName; + if (FontName <> '') then begin - OSError(ATSUFindFontFromName(@FontName[1], Length(FontName), + OSError(ATSUFindFontFromName(@fn[1], Length(fn), kFontFullName, kFontMacintoshPlatform, kFontRomanScript, kFontEnglishLanguage, Result), 'FindCarbonFontID', 'ATSUFindFontFromName'); @@ -1317,6 +1327,18 @@ begin end; end; +procedure InitDefaultFont; +var + s : Str255; + st : MacOSAll.Style; + sz : SInt16; +begin + //Note: the GetThemeFont is deprecated in 10.5. CoreText functions should be used! + MacOSAll.GetThemeFont(kThemeSystemFont, GetApplicationScript, @s, sz, st); + CarbonDefaultFont := s; + CarbonDefaultFontSize := sz; +end; + var EventSpec: Array [0..8] of EventTypeSpec; CustomControlHandlerUPP: EventHandlerUPP; @@ -1357,6 +1379,8 @@ initialization CustomControlHandlerUPP, Length(EventSpec), @EventSpec[0], nil, nil), 'CarbonProc.initialization', 'HIObjectRegisterSubclass'); + InitDefaultFont; + finalization FreeCFString(CustomControlClassID);