Michael Ring via Lazarus
2018-07-15 14:04:22 UTC
I today build Lazarus MacOSX/Cocoa**from svn and realized that all
characters in the editor seem to have an extra space between each character.
I did a little compiling of older SVN's and found out that the problem
appeared first in revision 58529.
This change in 58529 seems to kill the cat:
Index: lcl/interfaces/cocoa/cocoagdiobjects.pas
===================================================================
--- lcl/interfaces/cocoa/cocoagdiobjects.pas   (revision 58528)
+++ lcl/interfaces/cocoa/cocoagdiobjects.pas   (working copy)
@@ -559,6 +559,7 @@
  Win32Weight, LoopCount: Integer;
  CocoaWeight: NSInteger;
  FTmpFont: NSFont;
+Â IsDefault: Boolean;
 begin
  inherited Create(AGlobal);
@@ -570,7 +571,18 @@
    // because otherwise the result is wrong in Mac OS X 10.11, see
bug 30300
    // Code used for 10.10 or inferior:
    // FName := NSStringToString(NSFont.systemFontOfSize(0).familyName);
-Â Â Â if IsFontNameDefault(FName) then
+Â Â Â //
+Â Â Â // There's a differnet issue with not using systemFont.
+Â Â Â // NSComboBox, if assigned a manually created font have an odd
ascending-offset
+Â Â Â // (easily seen in Xcode interface builder as well). systemFonts()
+Â Â Â // don't have such issue at all. see bug 33626
+Â Â Â // the fix below (detecting "default" font and use systemFont()) is
a potential
+Â Â Â // regression for bug 30300.
+Â Â Â //
+Â Â Â // There might font properties (i.e. Transform Matrix) to adjust
the position of
+Â Â Â // the font. But at this time, it's safer to use systemFont() method
+Â Â Â IsDefault := IsFontNameDefault(FName);
+Â Â Â if not IsDefault then
    begin
      FTmpFont :=
NSFont.fontWithName_size(NSFont.systemFontOfSize(0).fontDescriptor.postscriptName,
0);
      FName := NSStringToString(FTmpFont.familyName);
@@ -594,14 +606,14 @@
      include(FStyle, cfs_StrikeOut);
    // If this is not a "systemFont" Create the font ourselves
-Â Â Â FontName := NSStringUTF8(FName);
-Â Â Â Attributes := NSDictionary.dictionaryWithObjectsAndKeys(
-Â Â Â Â Â Â Â Â Â FontName, NSFontFamilyAttribute,
-Â Â Â Â Â Â Â Â Â NSNumber.numberWithFloat(FSize), NSFontSizeAttribute,
-Â Â Â Â Â Â Â Â Â nil);
-Â Â Â FontName.release;
-Â Â Â Descriptor :=
NSFontDescriptor.fontDescriptorWithFontAttributes(Attributes);
-Â Â Â FFont := NSFont.fontWithDescriptor_textTransform(Descriptor, nil);
+Â Â Â if IsDefault then
+Â Â Â begin
+Â Â Â Â Â FFont := NSFont.systemFontOfSize( FSize );
+Â Â Â end else begin
+Â Â Â Â Â FontName := NSStringUTF8(FName);
+Â Â Â Â Â FFont := NSFont.fontWithName_size(FontName, FSize);
+Â Â Â Â Â FontName.release;
+Â Â Â end;
    if FFont = nil then
    begin
@@ -620,7 +632,6 @@
        exit;
      end;
    end;
-
    // we could use NSFontTraitsAttribute to request the desired font
style (Bold/Italic)
    // but in this case we may get NIL as result. This way is safer.
    if cfs_Italic in Style then
characters in the editor seem to have an extra space between each character.
I did a little compiling of older SVN's and found out that the problem
appeared first in revision 58529.
This change in 58529 seems to kill the cat:
Index: lcl/interfaces/cocoa/cocoagdiobjects.pas
===================================================================
--- lcl/interfaces/cocoa/cocoagdiobjects.pas   (revision 58528)
+++ lcl/interfaces/cocoa/cocoagdiobjects.pas   (working copy)
@@ -559,6 +559,7 @@
  Win32Weight, LoopCount: Integer;
  CocoaWeight: NSInteger;
  FTmpFont: NSFont;
+Â IsDefault: Boolean;
 begin
  inherited Create(AGlobal);
@@ -570,7 +571,18 @@
    // because otherwise the result is wrong in Mac OS X 10.11, see
bug 30300
    // Code used for 10.10 or inferior:
    // FName := NSStringToString(NSFont.systemFontOfSize(0).familyName);
-Â Â Â if IsFontNameDefault(FName) then
+Â Â Â //
+Â Â Â // There's a differnet issue with not using systemFont.
+Â Â Â // NSComboBox, if assigned a manually created font have an odd
ascending-offset
+Â Â Â // (easily seen in Xcode interface builder as well). systemFonts()
+Â Â Â // don't have such issue at all. see bug 33626
+Â Â Â // the fix below (detecting "default" font and use systemFont()) is
a potential
+Â Â Â // regression for bug 30300.
+Â Â Â //
+Â Â Â // There might font properties (i.e. Transform Matrix) to adjust
the position of
+Â Â Â // the font. But at this time, it's safer to use systemFont() method
+Â Â Â IsDefault := IsFontNameDefault(FName);
+Â Â Â if not IsDefault then
    begin
      FTmpFont :=
NSFont.fontWithName_size(NSFont.systemFontOfSize(0).fontDescriptor.postscriptName,
0);
      FName := NSStringToString(FTmpFont.familyName);
@@ -594,14 +606,14 @@
      include(FStyle, cfs_StrikeOut);
    // If this is not a "systemFont" Create the font ourselves
-Â Â Â FontName := NSStringUTF8(FName);
-Â Â Â Attributes := NSDictionary.dictionaryWithObjectsAndKeys(
-Â Â Â Â Â Â Â Â Â FontName, NSFontFamilyAttribute,
-Â Â Â Â Â Â Â Â Â NSNumber.numberWithFloat(FSize), NSFontSizeAttribute,
-Â Â Â Â Â Â Â Â Â nil);
-Â Â Â FontName.release;
-Â Â Â Descriptor :=
NSFontDescriptor.fontDescriptorWithFontAttributes(Attributes);
-Â Â Â FFont := NSFont.fontWithDescriptor_textTransform(Descriptor, nil);
+Â Â Â if IsDefault then
+Â Â Â begin
+Â Â Â Â Â FFont := NSFont.systemFontOfSize( FSize );
+Â Â Â end else begin
+Â Â Â Â Â FontName := NSStringUTF8(FName);
+Â Â Â Â Â FFont := NSFont.fontWithName_size(FontName, FSize);
+Â Â Â Â Â FontName.release;
+Â Â Â end;
    if FFont = nil then
    begin
@@ -620,7 +632,6 @@
        exit;
      end;
    end;
-
    // we could use NSFontTraitsAttribute to request the desired font
style (Bold/Italic)
    // but in this case we may get NIL as result. This way is safer.
    if cfs_Italic in Style then