1
0
Fork 0
mirror of https://github.com/shlomif/PySolFC.git synced 2025-04-05 00:02:29 -04:00

got the svg cards to work as a PoC.

See https://github.com/shlomif/PySolFC/issues/3 .
This commit is contained in:
Shlomi Fish 2019-04-28 20:34:28 +03:00
parent cfc2b047b4
commit 07955e5cb4
3 changed files with 32 additions and 19 deletions

View file

@ -6,7 +6,16 @@ MyKCardDeck::MyKCardDeck()
int argc = 1;
char * argv[2]={"pysol",NULL};
app = new QGuiApplication(argc, argv);
d = new KCardDeck( KCardTheme(), nullptr);
d = new KCardDeck( KCardTheme("svg-ancient-egyptians"), nullptr);
unsigned int number = 0;
QList<quint32> ids;
for ( int i = 0; i < 1; ++i )
foreach ( const KCardDeck::Rank & r, KCardDeck::standardRanks() )
foreach ( const KCardDeck::Suit & s, KCardDeck::standardSuits() )
ids << KCardDeck::getId( s, r, number++ );
d->setDeckContents(ids);
d->setCardWidth(150);
}
QPixmap *MyKCardDeck::get_card_pixmap(int i)
{

View file

@ -84,7 +84,8 @@ class Images:
if rec and 'suit' in rec:
# img = PIL_Image(image=self.svg.render_fragment("6_heart"))
img = self.svg.render_fragment(
id_="queen_heart", width=self.CARDW, height=self.CARDH)
rank=rec['rank'], suit=rec['suit'],
width=self.CARDW, height=self.CARDH)
img = PIL_Image(image=img)
else:
if not os.path.exists(f):

View file

@ -42,21 +42,24 @@ class SVGManager:
img = Image.frombytes(mode, (w, h), data, "raw", mode, stride)
return img
def render_fragment(self, id_, width, height):
return Image.fromqpixmap(self.d.get_card_pixmap(6))
id__ = '#' + id_
"""docstring for render_"""
dims = self.svg.get_dimensions_sub(id__)[1]
width_, height_ = dims.width, dims.height
pix = self.svg.get_pixbuf_sub(id__)
if False:
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32,
int(width_), int(height_))
context = cairo.Context(surface)
# context.scale(width_, height_)
assert self.svg.render_cairo_sub(context, id__)
buf = bytes(surface.get_data())
image = Image.frombuffer('RGBA', (width_, height_), buf,
'raw', 'BGRA', 0, 1)
image = self.pixbuf2image(pix)
def render_fragment(self, rank, suit, width, height):
image = Image.fromqpixmap(
self.d.get_card_pixmap(
rank + 1 + {'c': 0, 'd': 1, 'h': 2, 's': 3}[suit]*0x100))
if 0:
id__ = '#' + "queen_heart"
"""docstring for render_"""
dims = self.svg.get_dimensions_sub(id__)[1]
width_, height_ = dims.width, dims.height
pix = self.svg.get_pixbuf_sub(id__)
if False:
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32,
int(width_), int(height_))
context = cairo.Context(surface)
# context.scale(width_, height_)
assert self.svg.render_cairo_sub(context, id__)
buf = bytes(surface.get_data())
image = Image.frombuffer('RGBA', (width_, height_), buf,
'raw', 'BGRA', 0, 1)
image = self.pixbuf2image(pix)
return image.resize((width, height))