freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[freetype2-demos] master 630e2676: [ftgrid] Revert to standard handling


From: Werner Lemberg
Subject: [freetype2-demos] master 630e2676: [ftgrid] Revert to standard handling of floats.
Date: Thu, 12 Dec 2024 19:40:15 -0500 (EST)

branch: master
commit 630e2676d06045fe2e2ce1f94e87cff02e55b8f6
Author: Alexei Podtelezhnikov (Алексей Подтележников) <apodtele@gmail.com>
Commit: Alexei Podtelezhnikov (Алексей Подтележников) <apodtele@gmail.com>

    [ftgrid] Revert to standard handling of floats.
    
    * src/ftgrid.c (write_header, event_grid_zoom): Use frexpf/ldexpf.
---
 src/ftgrid.c | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/src/ftgrid.c b/src/ftgrid.c
index d4b65221..d529bcc2 100644
--- a/src/ftgrid.c
+++ b/src/ftgrid.c
@@ -18,6 +18,7 @@
 #include "output.h"
 #include "mlgetopt.h"
 #include <stdlib.h>
+#include <math.h>
 
 #include <freetype/ftdriver.h>
 #include <freetype/ftlcdfil.h>
@@ -1071,18 +1072,18 @@
   static void
   event_grid_zoom( int  step )
   {
-    FT_Int32*  scale = (FT_Int32*)&status.scale;  /* 32-bit float */
-    FT_Int32   delta = 1 << 21;
+    int  frc, exp;
 
+    /* The floating scale is reversibly adjusted after decomposing it into */
+    /* fraction and exponent. Direct bit manipulation is less portable.    */
+    frc = (int)( 8.0f * frexpf( status.scale, &exp ) );
 
-    *scale += step * delta;  /* adjust float */
+    frc += step;
+    exp += ( frc >> 2 ) - 1;
+    frc  = ( frc  & 3 ) | 4;
 
-    if ( status.scale > 256.0f )
-      status.scale = 256.0f;
-    if ( status.scale < 0.00390625f )
-      status.scale = 0.00390625f;
-
-    *scale &= -delta;        /* round  float */
+    if ( -8 < exp && exp <= 8 )
+      status.scale = ldexpf( 0.125f * frc , exp );
   }
 
 
@@ -1608,8 +1609,7 @@
 
     if ( handle->current_font->num_indices )
     {
-      int       x;
-      FT_Int32  frc, exp;
+      int  x, frc, exp;
 
 
       x = snprintf( status.header_buffer, BUFSIZE,
@@ -1623,9 +1623,8 @@
                          display->bitmap->rows - GR_FONT_SIZE,
                          status.header_buffer, display->fore_color );
 
-      frc = *(FT_Int32*)&status.scale;  /* rounded 32-bit float */
-      exp = ( ( frc >> 23 ) & 255 ) - 129;
-      frc = ( ( frc >> 21 ) & 3   ) + 4;
+      frc  = (int)( 8.0f * frexpf( status.scale, &exp ) );
+      exp -= 3;
       while ( ~frc & 1 )
       {
         frc >>= 1;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]