[Lazarus] Character spacing doubled in R58529 on MacOSX/Cocoa

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[Lazarus] Character spacing doubled in R58529 on MacOSX/Cocoa

Free Pascal - Lazarus mailing list

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


--
_______________________________________________
Lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Character spacing doubled in R58529 on MacOSX/Cocoa

Free Pascal - Lazarus mailing list
You need to use 58531

On Sunday, July 15, 2018, Michael Ring via Lazarus <[hidden email]> wrote:

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


--
_______________________________________________
Lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Character spacing doubled in R58529 on MacOSX/Cocoa

Free Pascal - Lazarus mailing list

Problem fixed, thank you very much!

Michael


Am 15.07.18 um 16:24 schrieb Dmitry Boyarintsev:
You need to use 58531

On Sunday, July 15, 2018, Michael Ring via Lazarus <[hidden email]> wrote:

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



--
_______________________________________________
Lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus