[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2-demos] master c6cf8eb: [ftgrid, ftview, ftstring] Implement P
From: |
Alexei Podtelezhnikov |
Subject: |
[freetype2-demos] master c6cf8eb: [ftgrid, ftview, ftstring] Implement PNG printing. |
Date: |
Mon, 3 Jun 2019 23:00:11 -0400 (EDT) |
branch: master
commit c6cf8eb2887c3a7ab47bdb5fe2563b335514c396
Author: Alexei Podtelezhnikov <address@hidden>
Commit: Alexei Podtelezhnikov <address@hidden>
[ftgrid,ftview,ftstring] Implement PNG printing.
* src/ftcommon.[hc] (FT_Display_Print): New function.
* src/{ftgrid,ftview,ftstring}.c (Process_Event): New event.
* Makefile: Compile with appropriate <ftoption.h> so that
FT_CONFIG_OPTION_USE_PNG status is inherited from the library build
and based on the libPNG avalability.
---
ChangeLog | 11 ++++++
Makefile | 1 +
src/ftcommon.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/ftcommon.h | 6 +++
src/ftgrid.c | 11 ++++++
src/ftstring.c | 13 +++++++
src/ftview.c | 13 ++++++-
7 files changed, 171 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index 3f55f0a..2bd5741 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2019-06-03 Alexei Podtelezhnikov <address@hidden>
+
+ [ftgrid,ftview,ftstring] Implement PNG printing.
+
+ * src/ftcommon.[hc] (FT_Display_Print): New function.
+ * src/{ftgrid,ftview,ftstring}.c (Process_Event): New event.
+
+ * Makefile: Compile with appropriate <ftoption.h> so that
+ FT_CONFIG_OPTION_USE_PNG status is inherited from the library build
+ and based on the libPNG avalability.
+
2019-06-01 Alexei Podtelezhnikov <address@hidden>
[ftgrid,ftview,ftstring] Consolidate versioning.
diff --git a/Makefile b/Makefile
index dd88cbe..4c91e17 100644
--- a/Makefile
+++ b/Makefile
@@ -131,6 +131,7 @@ else
$(CFLAGS) \
$(ANSIFLAGS) \
$(INCLUDES:%=$I%) \
+ $DFT_CONFIG_OPTIONS_H="<ftoption.h>" \
$DFT_CONFIG_MODULES_H="<ftmodule.h>"
# Enable C99 for gcc to avoid warnings.
diff --git a/src/ftcommon.c b/src/ftcommon.c
index 4336ea9..61e7a59 100644
--- a/src/ftcommon.c
+++ b/src/ftcommon.c
@@ -39,6 +39,10 @@
#include <string.h>
#include <stdarg.h>
+#ifdef FT_CONFIG_OPTION_USE_PNG
+#include <png.h>
+#endif
+
#ifdef _WIN32
#define strcasecmp _stricmp
@@ -186,6 +190,119 @@
}
+ int
+ FTDemo_Display_Print( FTDemo_Display* display,
+ FT_String* filename,
+ FT_String* ver_str )
+ {
+#ifdef FT_CONFIG_OPTION_USE_PNG
+ grBitmap* bit = display->bitmap;
+ int width = bit->width;
+ int height = bit->rows;
+ int color_type;
+
+ int code = 1;
+ FILE *fp = NULL;
+ png_structp png_ptr = NULL;
+ png_infop info_ptr = NULL;
+ png_bytep row = NULL;
+
+
+ /* Set color_type */
+ switch ( bit-> mode )
+ {
+ case gr_pixel_mode_gray:
+ color_type = PNG_COLOR_TYPE_GRAY;
+ break;
+ case gr_pixel_mode_rgb24:
+ color_type = PNG_COLOR_TYPE_RGB;
+ break;
+ case gr_pixel_mode_rgb32:
+ color_type = PNG_COLOR_TYPE_RGB_ALPHA;
+ break;
+ default:
+ fprintf( stderr, "Unsupported color type\n" );
+ goto Exit0;
+ }
+
+ /* Open file for writing (binary mode) */
+ fp = fopen( filename, "wb" );
+ if ( fp == NULL )
+ {
+ fprintf( stderr, "Could not open file %s for writing\n", filename );
+ goto Exit0;
+ }
+
+ /* Initialize write structure */
+ png_ptr = png_create_write_struct( PNG_LIBPNG_VER_STRING, NULL, NULL, NULL
);
+ if ( png_ptr == NULL )
+ {
+ fprintf( stderr, "Could not allocate write struct\n" );
+ goto Exit1;
+ }
+
+ /* Initialize info structure */
+ info_ptr = png_create_info_struct( png_ptr );
+ if ( info_ptr == NULL )
+ {
+ fprintf( stderr, "Could not allocate info struct\n" );
+ goto Exit2;
+ }
+
+ /* Set up exception handling */
+ if ( setjmp( png_jmpbuf( png_ptr ) ) )
+ {
+ fprintf( stderr, "Error during png creation\n" );
+ goto Exit2;
+ }
+
+ png_init_io( png_ptr, fp );
+
+ /* Write header (8 bit colour depth) */
+ png_set_IHDR( png_ptr, info_ptr, width, height,
+ 8, color_type, PNG_INTERLACE_NONE,
+ PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE );
+
+ /* Record version string */
+ if ( ver_str != NULL )
+ {
+ png_text text;
+
+
+ text.compression = PNG_TEXT_COMPRESSION_NONE;
+ text.key = "Software";
+ text.text = ver_str;
+ png_set_text( png_ptr, info_ptr, &text, 1 );
+ }
+
+ /* Set gamma */
+ png_set_gAMA( png_ptr, info_ptr, 1.0 / display->gamma );
+
+ png_write_info( png_ptr, info_ptr );
+
+ /* Write image rows */
+ row = bit->buffer;
+ if ( bit->pitch < 0 )
+ row -= ( bit->rows - 1 ) * bit->pitch;
+ while ( height-- )
+ {
+ png_write_row( png_ptr, row );
+ row += bit->pitch;
+ }
+
+ /* End write */
+ png_write_end( png_ptr, NULL );
+ code = 0;
+
+ Exit2:
+ png_destroy_write_struct( &png_ptr, &info_ptr );
+ Exit1:
+ fclose( fp );
+ Exit0:
+ return code;
+#endif /* FT_CONFIG_OPTION_USE_PNG */
+ }
+
/*************************************************************************/
/*************************************************************************/
/***** *****/
diff --git a/src/ftcommon.h b/src/ftcommon.h
index e58b8b3..af7efe2 100644
--- a/src/ftcommon.h
+++ b/src/ftcommon.h
@@ -99,6 +99,12 @@
FTDemo_Display_Clear( FTDemo_Display* display );
+ /* dump display image in PNG format */
+ int
+ FTDemo_Display_Print( FTDemo_Display* display,
+ FT_String* filename,
+ FT_String* ver_str );
+
/*************************************************************************/
/*************************************************************************/
/***** *****/
diff --git a/src/ftgrid.c b/src/ftgrid.c
index 2b4dac8..fefe8e8 100644
--- a/src/ftgrid.c
+++ b/src/ftgrid.c
@@ -919,6 +919,7 @@
grWriteln( " anti-aliasing modes F3, F4 adjust
current axis by " );
grWriteln( "L cycle through LCD 1/50th of
its range " );
grWriteln( " filters
" );
+ grWriteln( " P print PNG
file " );
grWriteln( "g, v adjust gamma value q, ESC quit
ftgrid " );
/* |----------------------------------|
|----------------------------------| */
grLn();
@@ -1394,6 +1395,16 @@
event_help();
break;
+ case grKEY( 'P' ):
+ {
+ FT_String str[64] = "ftgrid (FreeType) ";
+
+
+ FTDemo_Version( handle, str );
+ FTDemo_Display_Print( display, "ftgrid.png", str );
+ }
+ break;
+
case grKEY( 'f' ):
handle->autohint = !handle->autohint;
status.header = handle->autohint ? "forced auto-hinting is now on"
diff --git a/src/ftstring.c b/src/ftstring.c
index 10d3a2e..2635620 100644
--- a/src/ftstring.c
+++ b/src/ftstring.c
@@ -242,6 +242,9 @@
grWriteln( " F7 : big rotate counter-clockwise" );
grWriteln( " F8 : big rotate clockwise" );
grLn();
+ grWriteln( " P : print PNG file" );
+ grWriteln( " q,ESC : quit" );
+ grLn();
grWriteln( "press any key to exit this help screen" );
grRefreshSurface( display->surface );
@@ -465,6 +468,16 @@
event_help();
goto Exit;
+ case grKEY( 'P' ):
+ {
+ FT_String str[64] = "ftstring (FreeType) ";
+
+
+ FTDemo_Version( handle, str );
+ FTDemo_Display_Print( display, "ftstring.png", str );
+ }
+ goto Exit;
+
case grKEY( 'b' ):
handle->use_sbits = !handle->use_sbits;
status.header = handle->use_sbits
diff --git a/src/ftview.c b/src/ftview.c
index da6edc0..b1d6903 100644
--- a/src/ftview.c
+++ b/src/ftview.c
@@ -849,7 +849,7 @@
grWriteln( " engines (if available)
" );
grWriteln( "f toggle forced auto- Tab cycle
through charmaps " );
grWriteln( " hinting (if hinting)
" );
- grWriteln( "w toggle warping
" );
+ grWriteln( "w toggle warping P print PNG
file " );
grWriteln( " (if available) q, ESC quit
ftview " );
/* |----------------------------------|
|----------------------------------| */
grLn();
@@ -1164,6 +1164,17 @@
status.update = 1;
break;
+ case grKEY( 'P' ):
+ {
+ FT_String str[64] = "ftview (FreeType) ";
+
+
+ FTDemo_Version( handle, str );
+ FTDemo_Display_Print( display, "ftview.png", str );
+ }
+ status.update = 0;
+ break;
+
case grKEY( 'b' ):
handle->use_sbits = !handle->use_sbits;
FTDemo_Update_Current_Flags( handle );
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2-demos] master c6cf8eb: [ftgrid, ftview, ftstring] Implement PNG printing.,
Alexei Podtelezhnikov <=