From 3839df757904f0cfeb6d479b62da3f1193049a8c Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Thu, 16 May 2019 19:12:04 +0300
Subject: [PATCH] svg : better resize.

---
 kcardgame/binding-example/kcardgame.cpp | 9 +++++++++
 kcardgame/binding-example/kcardgame.hpp | 2 ++
 pysollib/ui/tktile/svg.py               | 9 +++++++--
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/kcardgame/binding-example/kcardgame.cpp b/kcardgame/binding-example/kcardgame.cpp
index 925e3549..e6ef0d02 100644
--- a/kcardgame/binding-example/kcardgame.cpp
+++ b/kcardgame/binding-example/kcardgame.cpp
@@ -15,6 +15,15 @@ MyKCardDeck::MyKCardDeck(QString theme_name)
     d->setDeckContents(ids);
     d->setCardWidth(150);
 }
+void MyKCardDeck::set_card_height(int i)
+{
+    d->setCardHeight(i);
+}
+void MyKCardDeck::set_card_width(int i)
+{
+    d->setCardWidth(i);
+}
+
 QPixmap *MyKCardDeck::get_card_pixmap(int i)
 {
     auto ret = new QPixmap(d->cardPixmap(i, true));
diff --git a/kcardgame/binding-example/kcardgame.hpp b/kcardgame/binding-example/kcardgame.hpp
index a55a5733..ad4eecef 100644
--- a/kcardgame/binding-example/kcardgame.hpp
+++ b/kcardgame/binding-example/kcardgame.hpp
@@ -13,4 +13,6 @@ class Q_DECL_EXPORT MyKCardDeck : public QObject
     explicit MyKCardDeck(QString);
   public slots:
     Q_DECL_EXPORT QPixmap *get_card_pixmap(int i);
+    Q_DECL_EXPORT void set_card_height(int i);
+    Q_DECL_EXPORT void set_card_width(int i);
 };
diff --git a/pysollib/ui/tktile/svg.py b/pysollib/ui/tktile/svg.py
index 2e6061aa..2d2b4e01 100644
--- a/pysollib/ui/tktile/svg.py
+++ b/pysollib/ui/tktile/svg.py
@@ -48,9 +48,15 @@ class SVGManager:
     def render_fragment(self, rank, suit, width, height):
         if not self.d:
             return None
+        d = self.d
+        # d.set_card_width(width)
+        d.set_card_width(150)
+        # d.set_card_height(height)
         image = Image.fromqpixmap(
-            self.d.get_card_pixmap(
+            d.get_card_pixmap(
                 rank + 1 + {'c': 0, 'd': 1, 'h': 2, 's': 3}[suit]*0x100))
+        return image.resize((width, height), Image.LANCZOS)
+        return image
         if 0:
             id__ = '#' + "queen_heart"
             """docstring for render_"""
@@ -68,4 +74,3 @@ class SVGManager:
                 image = Image.frombuffer('RGBA', (width_, height_), buf,
                                          'raw', 'BGRA', 0, 1)
             image = self.pixbuf2image(pix)
-        return image.resize((width, height))