[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2-demos] GSoC-2020-anuj 8169d8c 2/5: [ftsdf] Added all the even
From: |
Anuj Verma |
Subject: |
[freetype2-demos] GSoC-2020-anuj 8169d8c 2/5: [ftsdf] Added all the events. |
Date: |
Sat, 22 Aug 2020 01:37:48 -0400 (EDT) |
branch: GSoC-2020-anuj
commit 8169d8c0aecc374b8f9e3d365b555c60da8d13bd
Author: Anuj Verma <anujv@iitbhilai.ac.in>
Commit: Anuj Verma <anujv@iitbhilai.ac.in>
[ftsdf] Added all the events.
* src/ftsdf.c (event_): Added all the events that are triggered during the
demo.
---
src/ftsdf.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 116 insertions(+)
diff --git a/src/ftsdf.c b/src/ftsdf.c
index d1726b6..3f1d50b 100644
--- a/src/ftsdf.c
+++ b/src/ftsdf.c
@@ -72,4 +72,120 @@
/* edge */ 0.2f
};
+ static FT_Error
+ event_font_update()
+ {
+ /* This event is triggered when the prooperties of the rasterizer */
+ /* is updated or the glyph index / size is updated. */
+ FT_Error error = FT_Err_Ok;
+ clock_t start, end;
+
+ /* Set various properties of the renderers. */
+ FT_CALL( FT_Property_Set( handle->library, "bsdf", "spread",
&status.spread ) );
+ FT_CALL( FT_Property_Set( handle->library, "sdf", "spread", &status.spread
) );
+ FT_CALL( FT_Property_Set( handle->library, "sdf", "overlaps",
&status.overlaps ) );
+
+ /* Set pixel size and load the glyph index. */
+ FT_CALL( FT_Set_Pixel_Sizes( status.face, 0, status.ptsize ) );
+ FT_CALL( FT_Load_Glyph( status.face, status.glyph_index, FT_LOAD_DEFAULT )
);
+
+ /* This is just to measure the generation time. */
+ start = clock();
+
+ /* Finally render the glyph. To force the `bsdf' renderer (i.e. to */
+ /* generate SDF from bitmap) we must render the glyph first using */
+ /* the smooth or the monochrome FreeType rasterizer. */
+ if ( status.use_bitmap )
+ FT_CALL( FT_Render_Glyph( status.face->glyph, FT_RENDER_MODE_NORMAL ) );
+ FT_CALL( FT_Render_Glyph( status.face->glyph, FT_RENDER_MODE_SDF ) );
+
+ /* Compute and print the generation time. */
+ end = clock();
+
+ status.generation_time = ( (float)( end - start ) / (float)CLOCKS_PER_SEC
) * 1000.0f;
+
+ printf( "Generation Time: %.0f ms\n", status.generation_time );
+
+ Exit:
+ return error;
+ }
+
+ static void
+ event_color_change()
+ {
+ /* This event is triggered when we create a new display, */
+ /* in this event we set various colors for the display */
+ /* buffer. */
+ display->back_color = grFindColor( display->bitmap, 0, 0, 0, 0xff );
+ display->fore_color = grFindColor( display->bitmap, 255, 255, 255, 0xff );
+ display->warn_color = grFindColor( display->bitmap, 0, 255, 255, 0xff );
+ }
+
+ static void
+ event_help()
+ {
+ /* This event is triggered when the user presses the help */
+ /* screen button that is either '?' or F1. It basically */
+ /* prints the list of keys along with thier usage to the */
+ /* display window. */
+
+ grEvent dummy;
+
+ /* For help screen we use a slightly gray color instead of */
+ /* completely black background. */
+ display->back_color = grFindColor( display->bitmap, 30, 30, 30, 0xff );
+ FTDemo_Display_Clear( display );
+ display->back_color = grFindColor( display->bitmap, 0, 0, 0, 0xff );
+
+ /* Set some properties. */
+ grSetLineHeight( 10 );
+ grGotoxy( 0, 0 );
+ grSetMargin( 2, 1 );
+
+ /* Set the text color. (kind of purple) */
+ grGotobitmapColor( display->bitmap, 204, 153, 204, 255 );
+
+ /* Print the keys and usage. */
+ grWriteln( "Signed Distnace Field Viewer" );
+ grLn();
+ grWriteln( "Use the following keys:" );
+ grWriteln( "-----------------------" );
+ grLn();
+ grWriteln( " F1 or ? or / : display this help screen" );
+ grLn();
+ grWriteln( " b : Toggle between bitmap/outline to be
used for generating" );
+ grLn();
+ grWriteln( " z, x : Zoom/Scale Up and Down" );
+ grLn();
+ grWriteln( " Up, Down Arrow : Adjust glyph's point size by 1" );
+ grWriteln( " PgUp, PgDn : Adjust glyph's point size by 25" );
+ grLn();
+ grWriteln( " Left, Right Arrow : Adjust glyph index by 1" );
+ grWriteln( " F5, F6 : Adjust glyph index by 50" );
+ grWriteln( " F7, F8 : Adjust glyph index by 500" );
+ grLn();
+ grWriteln( " o, l : Adjust spread size by 1" );
+ grLn();
+ grWriteln( " w, s : Move glyph Up/Down" );
+ grWriteln( " a, d : Move glyph Left/right" );
+ grLn();
+ grWriteln( " f : Toggle between bilinear/nearest
filtering" );
+ grLn();
+ grWriteln( " m : Toggle overlapping support" );
+ grLn();
+ grWriteln( "Reconstructing Image from SDF" );
+ grWriteln( "-----------------------------" );
+ grWriteln( " r : Toggle between reconstruction/raw view"
);
+ grWriteln( " i, k : Adjust width by 1 (makes the text
bolder/thinner)" );
+ grWriteln( " u, j : Adjust edge by 1 (makes the text
smoother/sharper)" );
+ grLn();
+ grWriteln( "press any key to exit this help screen" );
+
+ /* Now wait till any key press, otherwise the help screen */
+ /* will only blink and disappear. */
+ grRefreshSurface( display->surface );
+ grListenSurface( display->surface, gr_event_key, &dummy );
+ }
+
+
/* END */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2-demos] GSoC-2020-anuj 8169d8c 2/5: [ftsdf] Added all the events.,
Anuj Verma <=