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:
parent
cfc2b047b4
commit
07955e5cb4
3 changed files with 32 additions and 19 deletions
|
@ -6,7 +6,16 @@ MyKCardDeck::MyKCardDeck()
|
||||||
int argc = 1;
|
int argc = 1;
|
||||||
char * argv[2]={"pysol",NULL};
|
char * argv[2]={"pysol",NULL};
|
||||||
app = new QGuiApplication(argc, argv);
|
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)
|
QPixmap *MyKCardDeck::get_card_pixmap(int i)
|
||||||
{
|
{
|
||||||
|
|
|
@ -84,7 +84,8 @@ class Images:
|
||||||
if rec and 'suit' in rec:
|
if rec and 'suit' in rec:
|
||||||
# img = PIL_Image(image=self.svg.render_fragment("6_heart"))
|
# img = PIL_Image(image=self.svg.render_fragment("6_heart"))
|
||||||
img = self.svg.render_fragment(
|
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)
|
img = PIL_Image(image=img)
|
||||||
else:
|
else:
|
||||||
if not os.path.exists(f):
|
if not os.path.exists(f):
|
||||||
|
|
|
@ -42,21 +42,24 @@ class SVGManager:
|
||||||
img = Image.frombytes(mode, (w, h), data, "raw", mode, stride)
|
img = Image.frombytes(mode, (w, h), data, "raw", mode, stride)
|
||||||
return img
|
return img
|
||||||
|
|
||||||
def render_fragment(self, id_, width, height):
|
def render_fragment(self, rank, suit, width, height):
|
||||||
return Image.fromqpixmap(self.d.get_card_pixmap(6))
|
image = Image.fromqpixmap(
|
||||||
id__ = '#' + id_
|
self.d.get_card_pixmap(
|
||||||
"""docstring for render_"""
|
rank + 1 + {'c': 0, 'd': 1, 'h': 2, 's': 3}[suit]*0x100))
|
||||||
dims = self.svg.get_dimensions_sub(id__)[1]
|
if 0:
|
||||||
width_, height_ = dims.width, dims.height
|
id__ = '#' + "queen_heart"
|
||||||
pix = self.svg.get_pixbuf_sub(id__)
|
"""docstring for render_"""
|
||||||
if False:
|
dims = self.svg.get_dimensions_sub(id__)[1]
|
||||||
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32,
|
width_, height_ = dims.width, dims.height
|
||||||
int(width_), int(height_))
|
pix = self.svg.get_pixbuf_sub(id__)
|
||||||
context = cairo.Context(surface)
|
if False:
|
||||||
# context.scale(width_, height_)
|
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32,
|
||||||
assert self.svg.render_cairo_sub(context, id__)
|
int(width_), int(height_))
|
||||||
buf = bytes(surface.get_data())
|
context = cairo.Context(surface)
|
||||||
image = Image.frombuffer('RGBA', (width_, height_), buf,
|
# context.scale(width_, height_)
|
||||||
'raw', 'BGRA', 0, 1)
|
assert self.svg.render_cairo_sub(context, id__)
|
||||||
image = self.pixbuf2image(pix)
|
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))
|
return image.resize((width, height))
|
||||||
|
|
Loading…
Add table
Reference in a new issue