[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2-demos] master ec7731e: [ftlint] Examine the outline shape com
From: |
Werner Lemberg |
Subject: |
[freetype2-demos] master ec7731e: [ftlint] Examine the outline shape complexity. |
Date: |
Sat, 25 Mar 2023 22:46:22 -0400 (EDT) |
branch: master
commit ec7731ecf6dd86ae73243eb383ac878c3110abf9
Author: Alexei Podtelezhnikov <apodtele@gmail.com>
Commit: Alexei Podtelezhnikov <apodtele@gmail.com>
[ftlint] Examine the outline shape complexity.
Measured as a ratio of the outline half-perimeter to the sum of its
control box dimensions, the shape complexity is a useful metric.
For example, an `I` and an `M` would have complexities of about
1.0 and 2.0, respectively.
* src/ftlint.c (Examine): Implement the shape complexity calculation.
(main) Report the shape complexity.
* man/ftlint.1: Add a brief explanation.
---
man/ftlint.1 | 2 ++
src/ftlint.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 60 insertions(+), 3 deletions(-)
diff --git a/man/ftlint.1 b/man/ftlint.1
index 85406e4..e7a02ee 100644
--- a/man/ftlint.1
+++ b/man/ftlint.1
@@ -18,6 +18,8 @@ ftlint \- simple font tester
.
.B ftlint
opens the given font(s), loads and renders glyphs at the given ppem value.
+The shape complexity of outline glyphs are examined based on their taxicab
+perimeters: the higher the number, the more complex the shape.
For successfully rendered glyphs, it calculates the bitmap MD5 checksum
for regression testing as well as horizontal (X) and vertical (Y) acutances
for quality assessment. The acutance is equal to 2.0 for monochrome bitmap
diff --git a/src/ftlint.c b/src/ftlint.c
index 30ec0e6..b314b4d 100644
--- a/src/ftlint.c
+++ b/src/ftlint.c
@@ -15,6 +15,7 @@
#include <ft2build.h>
#include <freetype/freetype.h>
+#include <freetype/ftoutln.h>
#include <freetype/ftbitmap.h>
@@ -84,6 +85,58 @@
}
+ static void
+ Examine( FT_GlyphSlot slot )
+ {
+ unsigned long format = slot->format;
+ FT_Outline* outline = &slot->outline;
+ short c, p, first, last;
+ FT_Vector u, v;
+ FT_Pos taxi;
+ FT_BBox cbox;
+
+
+ if ( format != FT_GLYPH_FORMAT_OUTLINE )
+ {
+ putchar( ' ' );
+ putchar( ( format >> 24 ) & 0xFF );
+ putchar( ( format >> 16 ) & 0xFF );
+ putchar( ( format >> 8 ) & 0xFF );
+ putchar( ( format ) & 0xFF );
+ putchar( ' ' );
+ return;
+ }
+
+ taxi = 0;
+ last = -1;
+ for ( c = 0; c < outline->n_contours; c++ )
+ {
+ first = last + 1;
+ last = outline->contours[c];
+
+ u = outline->points[last];
+ for ( p = first; p <= last; p++ )
+ {
+ v = outline->points[p];
+
+ taxi += v.x > u.x ? v.x - u.x : u.x - v.x;
+ taxi += v.y > u.y ? v.y - u.y : u.y - v.y;
+
+ u = v;
+ }
+ }
+
+ if ( taxi )
+ {
+ FT_Outline_Get_CBox( outline, &cbox );
+ printf( "%5.2f ", 0.5 * taxi /
+ ( cbox.xMax - cbox.xMin + cbox.yMax - cbox.yMin ) );
+ }
+ else
+ printf( " void " );
+ }
+
+
/* Analyze X- and Y-acutance; bitmap should have positive pitch */
static void
Analyze( FT_Bitmap* bitmap )
@@ -281,9 +334,9 @@
if ( !quiet )
{
- /* "NNNNN AAAxBBBB X.XXXX Y.YYYY
MMDD55MMDD55MMDD55MMDD55MMDD55MM" */
- printf( "\n GID imgsize Xacut Yacut MD5 hashsum" );
- printf(
"\n-------------------------------------------------------------\n" );
+ /* "NNNNN SS.SS WWWxHHHH X.XXXX Y.YYYY
MMDD55MMDD55MMDD55MMDD55MMDD55MM" */
+ printf( "\n GID shape imgsize Xacut Yacut MD5 hashsum" );
+ printf(
"\n-------------------------------------------------------------------\n" );
}
Fail = 0;
@@ -309,6 +362,8 @@
printf( "%5u ", id );
+ Examine( face->glyph );
+
error = FT_Render_Glyph( face->glyph, render_mode );
if ( error && error != FT_Err_Cannot_Render_Glyph )
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2-demos] master ec7731e: [ftlint] Examine the outline shape complexity.,
Werner Lemberg <=