[gnome-sudoku/gnome-40] Use pango to format sudoku titles when printing
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-sudoku/gnome-40] Use pango to format sudoku titles when printing
- Date: Fri, 23 Jul 2021 16:14:15 +0000 (UTC)
commit 1a51b34ef37c144da1d15ff2c556d5cc4e5a34b9
Author: Michael Catanzaro <mcatanzaro redhat com>
Date: Thu Jul 22 15:35:31 2021 -0500
Use pango to format sudoku titles when printing
Currently they are printed using cairo's toy text API, which is good
enough to print individual numbers in our Sudoku grid, but not nearly
good enough to handle internationalized complex text. We can fix this by
switching to Pango instead.
Fixes #52
(cherry picked from commit dc2f3588dc6c44a4ba2206a91e250dc716400c0d)
src/sudoku-printer.vala | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
---
diff --git a/src/sudoku-printer.vala b/src/sudoku-printer.vala
index 7b5fcbf..5f20e44 100644
--- a/src/sudoku-printer.vala
+++ b/src/sudoku-printer.vala
@@ -93,18 +93,27 @@ public class SudokuPrinter : GLib.Object {
uint index = 0;
+ var pango_context = Pango.cairo_create_context (cr);
+ Pango.cairo_context_set_font_options (pango_context, Gdk.Screen.get_default ().get_font_options ());
+
foreach (SudokuBoard sudoku in sudokus_on_page)
{
double left = margin_x + (index % n_across) * (best_square_size + margin_x);
double top = margin_y + label_extents.height + (index / n_across) * (best_square_size + margin_y
+ label_extents.height);
var label = sudoku.difficulty_category.to_string ();
- set_label_font (cr);
+ var layout = new Pango.Layout (pango_context);
+ layout.set_font_description (Pango.FontDescription.from_string ("Sans Bold 9"));
+ layout.set_text (label, -1);
+
+ int layout_width;
+ int layout_height;
+ layout.get_size (out layout_width, out layout_height);
+ layout_width /= Pango.SCALE;
+ layout_height /= Pango.SCALE;
+ cr.move_to (left + (best_square_size - layout_width) / 2, top - layout_height);
cr.set_source_rgb (0, 0, 0);
- Cairo.TextExtents extents;
- cr.text_extents (label, out extents);
- cr.move_to (left + (best_square_size - extents.width) / 2, top - extents.height / 2);
- cr.show_text (label);
+ Pango.cairo_show_layout (cr, layout);
draw_sudoku (cr, sudoku, best_square_size, left, top);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]