Skip to content
Snippets Groups Projects
Commit 43803cef authored by tag2y19's avatar tag2y19 Committed by Tom Greig
Browse files

Add options for font face and size

Size sets the base font size for ticks.  Axis labels are 1.5×, graph
titles are 2× and bold.
parent f2088850
No related branches found
No related tags found
No related merge requests found
...@@ -46,9 +46,15 @@ struct context { ...@@ -46,9 +46,15 @@ struct context {
struct timespec start_time; struct timespec start_time;
GtkWidget* plot; GtkWidget* plot;
PangoFontDescription* font_description;
char* font_name;
int font_size;
PangoFontDescription* title_font_description;
char* title; char* title;
PangoLayout* title_layout; PangoLayout* title_layout;
PangoFontDescription* label_font_description;
char* xlab; char* xlab;
PangoLayout* xlab_layout; PangoLayout* xlab_layout;
char* yllab; char* yllab;
...@@ -56,6 +62,8 @@ struct context { ...@@ -56,6 +62,8 @@ struct context {
char* yrlab; char* yrlab;
PangoLayout* yrlab_layout; PangoLayout* yrlab_layout;
PangoFontDescription* tick_font_description;
double margins[4]; double margins[4];
char* xaxis; char* xaxis;
...@@ -119,8 +127,7 @@ int main( int argc, char** argv ) { ...@@ -119,8 +127,7 @@ int main( int argc, char** argv ) {
context->read_buffer_len = 512; context->read_buffer_len = 512;
context->xfit = true; context->xfit = true;
context->xfollow = true; context->xfollow = true;
context->font_description = context->font_size = 12;
pango_font_description_from_string( "Sans 12px" );
static const char* colours[] = { static const char* colours[] = {
"#005C84", "#FCBC00", "#0C838C", "#E63037", "#005C84", "#FCBC00", "#0C838C", "#E63037",
...@@ -166,6 +173,22 @@ int main( int argc, char** argv ) { ...@@ -166,6 +173,22 @@ int main( int argc, char** argv ) {
.description = "Do not plot the data in column " .description = "Do not plot the data in column "
"(can be given multiple times)", "(can be given multiple times)",
.arg_description = "column" .arg_description = "column"
}, {
.long_name = "font",
.short_name = 'f',
.flags = G_OPTION_FLAG_IN_MAIN,
.arg = G_OPTION_ARG_STRING,
.arg_data = &( context->font_name ),
.description = "Font for graph text",
.arg_description = "font",
}, {
.long_name = "font-size",
.short_name = 's',
.flags = G_OPTION_FLAG_IN_MAIN,
.arg = G_OPTION_ARG_INT,
.arg_data = &( context->font_size ),
.description = "Base font size (px)",
.arg_description = "size",
}, { }, {
.long_name = "title", .long_name = "title",
.short_name = 't', .short_name = 't',
...@@ -843,10 +866,17 @@ static void plot_draw( GtkDrawingArea* plot, ...@@ -843,10 +866,17 @@ static void plot_draw( GtkDrawingArea* plot,
double margin_reqs[4] = { 5., 5., 5., 5. }; double margin_reqs[4] = { 5., 5., 5., 5. };
char font_desc_string[512];
if ( NULL == context->title_layout && NULL != context->title ) { if ( NULL == context->title_layout && NULL != context->title ) {
context->title_layout = pango_cairo_create_layout( cr ); context->title_layout = pango_cairo_create_layout( cr );
sprintf( font_desc_string, "%s Bold %dpx",
NULL == context->font_name ? "Sans" : context->font_name,
2 * context->font_size );
context->title_font_description =
pango_font_description_from_string( font_desc_string );
pango_layout_set_font_description( context->title_layout, pango_layout_set_font_description( context->title_layout,
context->font_description ); context->title_font_description );
pango_layout_set_text( pango_layout_set_text(
context->title_layout, context->title, -1 ); context->title_layout, context->title, -1 );
} }
...@@ -857,10 +887,15 @@ static void plot_draw( GtkDrawingArea* plot, ...@@ -857,10 +887,15 @@ static void plot_draw( GtkDrawingArea* plot,
margin_reqs[2] += height + 3; margin_reqs[2] += height + 3;
} }
sprintf( font_desc_string, "%s %dpx",
NULL == context->font_name ? "Sans" : context->font_name,
(int) ( 1.5 * context->font_size ) );
context->label_font_description =
pango_font_description_from_string( font_desc_string );
if ( NULL == context->xlab_layout && NULL != context->xlab ) { if ( NULL == context->xlab_layout && NULL != context->xlab ) {
context->xlab_layout = pango_cairo_create_layout( cr ); context->xlab_layout = pango_cairo_create_layout( cr );
pango_layout_set_font_description( context->xlab_layout, pango_layout_set_font_description( context->xlab_layout,
context->font_description ); context->label_font_description );
pango_layout_set_text( pango_layout_set_text(
context->xlab_layout, context->xlab, -1 ); context->xlab_layout, context->xlab, -1 );
} }
...@@ -874,7 +909,7 @@ static void plot_draw( GtkDrawingArea* plot, ...@@ -874,7 +909,7 @@ static void plot_draw( GtkDrawingArea* plot,
if ( NULL == context->yllab_layout && NULL != context->yllab ) { if ( NULL == context->yllab_layout && NULL != context->yllab ) {
context->yllab_layout = pango_cairo_create_layout( cr ); context->yllab_layout = pango_cairo_create_layout( cr );
pango_layout_set_font_description( context->yllab_layout, pango_layout_set_font_description( context->yllab_layout,
context->font_description ); context->label_font_description );
pango_layout_set_text( pango_layout_set_text(
context->yllab_layout, context->yllab, -1 ); context->yllab_layout, context->yllab, -1 );
} }
...@@ -888,7 +923,7 @@ static void plot_draw( GtkDrawingArea* plot, ...@@ -888,7 +923,7 @@ static void plot_draw( GtkDrawingArea* plot,
if ( NULL == context->yrlab_layout && NULL != context->yrlab ) { if ( NULL == context->yrlab_layout && NULL != context->yrlab ) {
context->yrlab_layout = pango_cairo_create_layout( cr ); context->yrlab_layout = pango_cairo_create_layout( cr );
pango_layout_set_font_description( context->yrlab_layout, pango_layout_set_font_description( context->yrlab_layout,
context->font_description ); context->label_font_description );
pango_layout_set_text( pango_layout_set_text(
context->yrlab_layout, context->yrlab, -1 ); context->yrlab_layout, context->yrlab, -1 );
} }
...@@ -899,6 +934,12 @@ static void plot_draw( GtkDrawingArea* plot, ...@@ -899,6 +934,12 @@ static void plot_draw( GtkDrawingArea* plot,
margin_reqs[3] += height + 3; margin_reqs[3] += height + 3;
} }
sprintf( font_desc_string, "%s %dpx",
NULL == context->font_name ? "Sans" : context->font_name,
context->font_size );
context->tick_font_description =
pango_font_description_from_string( font_desc_string );
/* Clear */ /* Clear */
cairo_save( cr ); cairo_save( cr );
...@@ -1043,7 +1084,7 @@ static void plot_draw( GtkDrawingArea* plot, ...@@ -1043,7 +1084,7 @@ static void plot_draw( GtkDrawingArea* plot,
pango_cairo_create_layout( cr ); pango_cairo_create_layout( cr );
pango_layout_set_font_description( pango_layout_set_font_description(
context->xtick_layouts.layouts[i], context->xtick_layouts.layouts[i],
context->font_description ); context->tick_font_description );
} }
sprintf( tick_buffer, "%.3g", sprintf( tick_buffer, "%.3g",
xrange[0] + ( (double) i ) / ( xdivs - 1 ) * ( xrange[1] - xrange[0] ) ); xrange[0] + ( (double) i ) / ( xdivs - 1 ) * ( xrange[1] - xrange[0] ) );
...@@ -1075,7 +1116,7 @@ static void plot_draw( GtkDrawingArea* plot, ...@@ -1075,7 +1116,7 @@ static void plot_draw( GtkDrawingArea* plot,
pango_cairo_create_layout( cr ); pango_cairo_create_layout( cr );
pango_layout_set_font_description( pango_layout_set_font_description(
context->yltick_layouts.layouts[i], context->yltick_layouts.layouts[i],
context->font_description ); context->tick_font_description );
} }
sprintf( tick_buffer, "%.3g", ylrange[0] + sprintf( tick_buffer, "%.3g", ylrange[0] +
( (double) i ) / ( yldivs - 1 ) * ( ylrange[1] - ylrange[0] ) ); ( (double) i ) / ( yldivs - 1 ) * ( ylrange[1] - ylrange[0] ) );
...@@ -1107,7 +1148,7 @@ static void plot_draw( GtkDrawingArea* plot, ...@@ -1107,7 +1148,7 @@ static void plot_draw( GtkDrawingArea* plot,
pango_cairo_create_layout( cr ); pango_cairo_create_layout( cr );
pango_layout_set_font_description( pango_layout_set_font_description(
context->yrtick_layouts.layouts[i], context->yrtick_layouts.layouts[i],
context->font_description ); context->tick_font_description );
} }
sprintf( tick_buffer, "%.3g", yrrange[0] + sprintf( tick_buffer, "%.3g", yrrange[0] +
( (double) i ) / ( yrdivs - 1 ) * ( yrrange[1] - yrrange[0] ) ); ( (double) i ) / ( yrdivs - 1 ) * ( yrrange[1] - yrrange[0] ) );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment