[gnome-sudoku/mcatanzaro/print-rtl] Use pango to format sudoku titles when printing
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-sudoku/mcatanzaro/print-rtl] Use pango to format sudoku titles when printing
- Date: Thu, 22 Jul 2021 20:43:57 +0000 (UTC)
commit 7007b9beba09aea8ec31b5c123e8476ee9a4c3bd
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
src/sudoku-printer.vala | 29 ++++++++++++++++++++++++-----
1 file changed, 24 insertions(+), 5 deletions(-)
---
diff --git a/src/sudoku-printer.vala b/src/sudoku-printer.vala
index 7b5fcbf..ff205b4 100644
--- a/src/sudoku-printer.vala
+++ b/src/sudoku-printer.vala
@@ -72,6 +72,14 @@ public class SudokuPrinter : GLib.Object {
operation.set_n_pages (pages);
}
+ private void configure_font_options (Pango.Context context)
+ {
+ var screen = Gdk.Screen.get_default ();
+ unowned Cairo.FontOptions font_options = screen.get_font_options ();
+
+ Pango.cairo_context_set_font_options (context, font_options);
+ }
+
private void draw_page_cb (PrintOperation operation, PrintContext context, int page_nr)
{
Cairo.Context cr = context.get_cairo_context ();
@@ -93,18 +101,29 @@ public class SudokuPrinter : GLib.Object {
uint index = 0;
+ var pango_context = Pango.cairo_create_context (cr);
+ configure_font_options (pango_context);
+
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 12"));
+ 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;
+// FIXME off by a little here somewhow
+warning ("width=%d height=%d", layout_width, layout_height);
+ cr.move_to (left + (best_square_size - layout_width) / 2, top - layout_height / 2);
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]