freetype-commit
[Top][All Lists]
Advanced

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

[Git][freetype/freetype-demos][master] [ftgrid] Revert to standard handl


From: Alexei Podtelezhnikov (@apodtele)
Subject: [Git][freetype/freetype-demos][master] [ftgrid] Revert to standard handling of floats.
Date: Fri, 13 Dec 2024 00:40:05 +0000

Alexei Podtelezhnikov pushed to branch master at FreeType / FreeType Demo Programs

Commits:

  • 630e2676
    by Alexei Podtelezhnikov (Алексей Подтележников) at 2024-12-12T19:35:49-05:00
    [ftgrid] Revert to standard handling of floats.
    
    * src/ftgrid.c (write_header, event_grid_zoom): Use frexpf/ldexpf.
    

1 changed file:

Changes:

  • src/ftgrid.c
    ... ... @@ -18,6 +18,7 @@
    18 18
     #include "output.h"
    
    19 19
     #include "mlgetopt.h"
    
    20 20
     #include <stdlib.h>
    
    21
    +#include <math.h>
    
    21 22
     
    
    22 23
     #include <freetype/ftdriver.h>
    
    23 24
     #include <freetype/ftlcdfil.h>
    
    ... ... @@ -1071,18 +1072,18 @@
    1071 1072
       static void
    
    1072 1073
       event_grid_zoom( int  step )
    
    1073 1074
       {
    
    1074
    -    FT_Int32*  scale = (FT_Int32*)&status.scale;  /* 32-bit float */
    
    1075
    -    FT_Int32   delta = 1 << 21;
    
    1075
    +    int  frc, exp;
    
    1076 1076
     
    
    1077
    +    /* The floating scale is reversibly adjusted after decomposing it into */
    
    1078
    +    /* fraction and exponent. Direct bit manipulation is less portable.    */
    
    1079
    +    frc = (int)( 8.0f * frexpf( status.scale, &exp ) );
    
    1077 1080
     
    
    1078
    -    *scale += step * delta;  /* adjust float */
    
    1081
    +    frc += step;
    
    1082
    +    exp += ( frc >> 2 ) - 1;
    
    1083
    +    frc  = ( frc  & 3 ) | 4;
    
    1079 1084
     
    
    1080
    -    if ( status.scale > 256.0f )
    
    1081
    -      status.scale = 256.0f;
    
    1082
    -    if ( status.scale < 0.00390625f )
    
    1083
    -      status.scale = 0.00390625f;
    
    1084
    -
    
    1085
    -    *scale &= -delta;        /* round  float */
    
    1085
    +    if ( -8 < exp && exp <= 8 )
    
    1086
    +      status.scale = ldexpf( 0.125f * frc , exp );
    
    1086 1087
       }
    
    1087 1088
     
    
    1088 1089
     
    
    ... ... @@ -1608,8 +1609,7 @@
    1608 1609
     
    
    1609 1610
         if ( handle->current_font->num_indices )
    
    1610 1611
         {
    
    1611
    -      int       x;
    
    1612
    -      FT_Int32  frc, exp;
    
    1612
    +      int  x, frc, exp;
    
    1613 1613
     
    
    1614 1614
     
    
    1615 1615
           x = snprintf( status.header_buffer, BUFSIZE,
    
    ... ... @@ -1623,9 +1623,8 @@
    1623 1623
                              display->bitmap->rows - GR_FONT_SIZE,
    
    1624 1624
                              status.header_buffer, display->fore_color );
    
    1625 1625
     
    
    1626
    -      frc = *(FT_Int32*)&status.scale;  /* rounded 32-bit float */
    
    1627
    -      exp = ( ( frc >> 23 ) & 255 ) - 129;
    
    1628
    -      frc = ( ( frc >> 21 ) & 3   ) + 4;
    
    1626
    +      frc  = (int)( 8.0f * frexpf( status.scale, &exp ) );
    
    1627
    +      exp -= 3;
    
    1629 1628
           while ( ~frc & 1 )
    
    1630 1629
           {
    
    1631 1630
             frc >>= 1;
    


  • reply via email to

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