【问题标题】:Changing default TextSettings Font Family / Size (XE7)更改默认 TextSettings 字体系列/大小 (XE7)
【发布时间】:2014-11-19 17:50:56
【问题描述】:

我目前正在为 Windows 8.1 和 OSX Yosemite 开发应用程序。

Firemonkey 使用 Segoe UI (12) 和 Helvetica (13) 作为默认字体系列和大小。

是否有人知道更改这些默认设置或完全停用它们的方法:

由于默认字体具有不同的字体大小(12 和 13),因此很难获得相同的外观和感觉。

正如您所见,除了默认尺寸外,其他尺寸看起来都差不多。

如果您想在 OSX 中显示文本大小为 12 的字体,您必须在运行时执行此操作。那是因为如果您在设计器中设置文本大小 12,它会自动切换到(默认)并在为 mac 编译时将其更改为 13。

【问题讨论】:

    标签: delphi ide firemonkey


    【解决方案1】:

    您可以通过替换 IFMXSystemFontService 来更改默认字体和大小:

    unit My.FontService;
    
    interface
    
    uses
      FMX.Platform;
    
    type
      TmyFMXSystemFontService = class(TInterfacedObject, IFMXSystemFontService)
      public
        function GetDefaultFontFamilyName: string;
        function GetDefaultFontSize: Single;
      end;
    
    implementation  
    
    function TmyFMXSystemFontService.GetDefaultFontFamilyName: string;
    begin
      Result := 'Lato';
    end;
    
    function TmyFMXSystemFontService.GetDefaultFontSize: Single;
    begin
      Result := 12;
    end;
    
    procedure InitFont;
    begin
      if TPlatformServices.Current.SupportsPlatformService(IFMXSystemFontService) then
        TPlatformServices.Current.RemovePlatformService(IFMXSystemFontService);
    
      TPlatformServices.Current.AddPlatformService(IFMXSystemFontService, TmyFMXSystemFontService.Create);
    end;
    
    initialization
    
    InitFont;
    
    end.
    

    默认字体大小(XE10,XE7不知道)是

    • 对于 Windows:12(请参阅 FMX.Platform.Win.pas 中的 DefaultWindowsFontSize)
    • 对于 iOS:14(请参阅 FMX.Platform.iOS.pas 中的 DefaultiOSFontSize)
    • 对于 OS X:13(请参阅 FMX.Platform.Mac.pas 中的 DefaultMacFontSize)

    【讨论】:

      【解决方案2】:

      我希望默认意味着它使用样式中的设置。您可以在工具菜单上的位图样式设计器中打开样式,进行任何更改并保存为 FireMonkey 样式。

      不过,我不确定是否有一种简单的方法可以更改默认值。这可能意味着单独更改每种字体。

      【讨论】:

        【解决方案3】:

        解决方法:

        var
          Settings: ITextSettings;
          Instance: TComponent;
          i: integer;
        begin
        
          for i := 0 to ComponentCount - 1 do
          begin
            Instance := Components[i];
        
            if IInterface(Instance).QueryInterface(ITextSettings, Settings) = S_OK then
            begin
              Settings.TextSettings.BeginUpdate;
              try
                Settings.DefaultTextSettings.Font.Size := 12;
                Settings.DefaultTextSettings.Font.Family := 'Comic Sans MS';
              finally
                Settings.TextSettings.EndUpdate;
              end;
            end;
          end;
        

        【讨论】:

        • 这个解决方案的问题是 TStyleBook 组件,在运行时,他的属性 ComponentCount 始终为零。此外,对于找到的每个 TStyleBook 组件,程序应执行相同的操作(对于 i := 0 到 StyleBook.ComponentCount - 1 do...)。请参阅我的解决方案建议。我认为两者结合,可以解决这个问题。
        【解决方案4】:

        真正的问题是,该属性的默认值使用不当。 这是Embarcadero的错误。当然!

        我的解决方案是在 TStyleBooks 组件中设置一个接近 12 但不是 12 的值。

        具体来说,我使用“11.9”。 Delphi 属性编辑器不将此值假定为默认值。但是当您运行程序时,系统会将其正确转换为字体大小的 12。在 Mac OS X 和 Windows 中也是如此。

        【讨论】:

          猜你喜欢
          • 2012-06-12
          • 2018-10-13
          • 1970-01-01
          • 2013-07-29
          • 1970-01-01
          • 2010-12-28
          • 1970-01-01
          • 2011-12-10
          • 2011-05-26
          相关资源
          最近更新 更多