Commits:
-
cff03bba
by Alexei Podtelezhnikov (Алексей Подтележников) at 2024-12-10T20:55:00-05:00
* src/ftcommon.c (FTDemo_Draw_Header): Adjust format string.
-
903ebdad
by Alexei Podtelezhnikov (Алексей Подтележников) at 2024-12-10T21:22:49-05:00
[ftgrid] Always display scale and simplify its adjustment.
We switch to direct bit manipulations, considering that IEEE 754
and its 32-bit floats are quite portable.
* src/ftgrid.c (write_header): Show scale in the bottom-left corner.
(event_grid_zoom): Use simpler algorithm.
2 changed files:
Changes:
src/ftcommon.c
... |
... |
@@ -1196,9 +1196,9 @@ |
1196
|
1196
|
|
1197
|
1197
|
strbuf_reset( buf );
|
1198
|
1198
|
if ( res == 72 )
|
1199
|
|
- strbuf_format( buf, "%.4g ppem", ppem / 64.0 );
|
|
1199
|
+ strbuf_format( buf, "%.5g ppem", ppem / 64.0 );
|
1200
|
1200
|
else
|
1201
|
|
- strbuf_format( buf, "%g pt at %d dpi, %.4g ppem",
|
|
1201
|
+ strbuf_format( buf, "%g pt at %d dpi, %.5g ppem",
|
1202
|
1202
|
ptsize / 64.0, res, ppem / 64.0 );
|
1203
|
1203
|
|
1204
|
1204
|
if ( face->face_index >> 16 )
|
src/ftgrid.c
... |
... |
@@ -18,7 +18,6 @@ |
18
|
18
|
#include "output.h"
|
19
|
19
|
#include "mlgetopt.h"
|
20
|
20
|
#include <stdlib.h>
|
21
|
|
-#include <math.h>
|
22
|
21
|
|
23
|
22
|
#include <freetype/ftdriver.h>
|
24
|
23
|
#include <freetype/ftlcdfil.h>
|
... |
... |
@@ -1072,34 +1071,18 @@ |
1072
|
1071
|
static void
|
1073
|
1072
|
event_grid_zoom( int step )
|
1074
|
1073
|
{
|
1075
|
|
- int frc, exp;
|
|
1074
|
+ FT_Int32* scale = (FT_Int32*)&status.scale; /* 32-bit float */
|
|
1075
|
+ FT_Int32 delta = 1 << 21;
|
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 * frexpf( status.scale, &exp ) );
|
1080
|
1077
|
|
1081
|
|
- frc = ( frc & 3 ) | ( exp << 2 );
|
1082
|
|
- frc += step;
|
1083
|
|
- exp = frc >> 2;
|
1084
|
|
- frc = ( frc & 3 ) | 4;
|
|
1078
|
+ *scale += step * delta; /* adjust float */
|
1085
|
1079
|
|
1086
|
|
- status.scale = ldexpf( frc / 8.0f, exp );
|
|
1080
|
+ if ( status.scale > 256.0f )
|
|
1081
|
+ status.scale = 256.0f;
|
|
1082
|
+ if ( status.scale < 0.00390625f )
|
|
1083
|
+ status.scale = 0.00390625f;
|
1087
|
1084
|
|
1088
|
|
- exp -= 3;
|
1089
|
|
- while ( ~frc & 1 )
|
1090
|
|
- {
|
1091
|
|
- frc >>= 1;
|
1092
|
|
- exp ++;
|
1093
|
|
- }
|
1094
|
|
-
|
1095
|
|
- if ( exp >= 0 )
|
1096
|
|
- snprintf( status.header_buffer, sizeof ( status.header_buffer ),
|
1097
|
|
- "zoom scale %d:1", frc << exp );
|
1098
|
|
- else
|
1099
|
|
- snprintf( status.header_buffer, sizeof ( status.header_buffer ),
|
1100
|
|
- "zoom scale %d:%d", frc, 1 << -exp );
|
1101
|
|
-
|
1102
|
|
- status.header = (const char *)status.header_buffer;
|
|
1085
|
+ *scale &= -delta; /* round float */
|
1103
|
1086
|
}
|
1104
|
1087
|
|
1105
|
1088
|
|
... |
... |
@@ -1625,7 +1608,8 @@ |
1625
|
1608
|
|
1626
|
1609
|
if ( handle->current_font->num_indices )
|
1627
|
1610
|
{
|
1628
|
|
- int x;
|
|
1611
|
+ int x;
|
|
1612
|
+ FT_Int32 frc, exp;
|
1629
|
1613
|
|
1630
|
1614
|
|
1631
|
1615
|
x = snprintf( status.header_buffer, BUFSIZE,
|
... |
... |
@@ -1638,6 +1622,26 @@ |
1638
|
1622
|
display->bitmap->width - 8 * x,
|
1639
|
1623
|
display->bitmap->rows - GR_FONT_SIZE,
|
1640
|
1624
|
status.header_buffer, display->fore_color );
|
|
1625
|
+
|
|
1626
|
+ frc = *(FT_Int32*)&status.scale; /* rounded 32-bit float */
|
|
1627
|
+ exp = ( ( frc >> 23 ) & 255 ) - 129;
|
|
1628
|
+ frc = ( ( frc >> 21 ) & 3 ) + 4;
|
|
1629
|
+ while ( ~frc & 1 )
|
|
1630
|
+ {
|
|
1631
|
+ frc >>= 1;
|
|
1632
|
+ exp ++;
|
|
1633
|
+ }
|
|
1634
|
+
|
|
1635
|
+ if ( exp >= 0 )
|
|
1636
|
+ snprintf( status.header_buffer, sizeof ( status.header_buffer ),
|
|
1637
|
+ "%d:1", frc << exp );
|
|
1638
|
+ else
|
|
1639
|
+ snprintf( status.header_buffer, sizeof ( status.header_buffer ),
|
|
1640
|
+ "%d:%d", frc, 1 << -exp );
|
|
1641
|
+
|
|
1642
|
+ grWriteCellString( display->bitmap,
|
|
1643
|
+ 0, display->bitmap->rows - GR_FONT_SIZE,
|
|
1644
|
+ status.header_buffer, display->fore_color );
|
1641
|
1645
|
}
|
1642
|
1646
|
|
1643
|
1647
|
if ( status.mm )
|
|