Skip to content

Commit

Permalink
All tests working
Browse files Browse the repository at this point in the history
  • Loading branch information
milenkoviclazar committed Sep 27, 2018
1 parent 23e17dc commit bc5468d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 17 deletions.
4 changes: 2 additions & 2 deletions pygame/__init__.js
Original file line number Diff line number Diff line change
Expand Up @@ -1209,8 +1209,8 @@ var init$1 = function $__init__123$(self, size, fullscreen = false, main = false

function fillBlack(ctx, w, h) {
ctx.beginPath();
ctx.rect(0, 0, w, h);
ctx.fillStyle = "rgba(0, 0, 0, 0.01)";
ctx.rect(0, 0, w-1, h-1);
ctx.fillStyle = "rgba(0, 0, 0, 0.0)";
ctx.fill();
}

Expand Down
9 changes: 5 additions & 4 deletions pygame/font.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function fontSize(self, text) {
// Create a dummy canvas in order to exploit its measureText() method
var t = Sk.builtin.tuple([w, h]);
var s = Sk.misceval.callsim(PygameLib.SurfaceType, t, false);
var ctx = s.main_canvas.getContext("2d");
var ctx = s.offscreen_canvas.getContext("2d");
ctx.font = fontName;
return new Sk.builtin.tuple([ctx.measureText(msg).width, h]);
}
Expand All @@ -127,18 +127,18 @@ function renderFont(self, text, antialias, color, background) {
// Create a dummy canvas in order to exploit its measureText() method
var t = Sk.builtin.tuple([w, h]);
var s = Sk.misceval.callsim(PygameLib.SurfaceType, t, false);
var ctx = s.main_canvas.getContext("2d");
var ctx = s.offscreen_canvas.getContext("2d");
ctx.font = fontName;
w = ctx.measureText(msg).width;

t = Sk.builtin.tuple([w, h]);
s = Sk.misceval.callsim(PygameLib.SurfaceType, t, false);
ctx = s.main_canvas.getContext("2d");
ctx = s.offscreen_canvas.getContext("2d");
if (background !== undefined) {
var background_js = PygameLib.extract_color(background);
ctx.fillStyle = 'rgba(' + background_js[0] + ', ' + background_js[1] + ', ' + background_js[2] + ', '
+ background_js[3] + ')';
ctx.fillRect(0, 0, s.main_canvas.width, s.main_canvas.height);
ctx.fillRect(0, 0, s.offscreen_canvas.width, s.offscreen_canvas.height);
}
ctx.font = fontName;
var color_js = PygameLib.extract_color(color);
Expand All @@ -147,6 +147,7 @@ function renderFont(self, text, antialias, color, background) {
if (underline) {
ctx.strokeStyle = 'rgba(' + color_js[0] + ', ' + color_js[1] + ', ' + color_js[2] + ', ' + color_js[3] + ')';
ctx.lineWidth = 1;
ctx.beginPath();
ctx.moveTo(0, h - 1);
ctx.lineTo(w, h - 1);
ctx.stroke();
Expand Down
10 changes: 0 additions & 10 deletions test/font.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
# -*- acsection: general-init -*-
import pygame as pg

# uključivanje rada biblioteke PyGame
pg.init()

# podešavamo naslov prozora
pg.display.set_caption("Zdravo svete!")
# otvaramo prozor dimenzije 300x300
(sirina, visina) = (600, 600)
prozor = pg.display.set_mode((sirina, visina))
# -*- acsection: main -*-

# bojimo pozadinu prozora u belo
prozor.fill(pg.Color("white"))

# font kojim će biti prikazan tekst
font = pg.font.SysFont("consolas", 40)
font.set_underline(True)

# poruka koja će se ispisivati
poruka = "Zdravo svete!"
# gradimo sličicu koja predstavlja tu poruku ispisanu crnom bojom
tekst = font.render(poruka, True, pg.Color("yellow"))

# određujemo veličinu tog teksta (da bismo mogli da ga centriramo)
Expand Down
2 changes: 1 addition & 1 deletion test/surface_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
poruka = "Zdravo svete!"
tekst1 = font.render(poruka, True, pg.Color("black"))
tekst2 = font.render(poruka, True, pg.Color("yellow"))
tekst2.convert_alpha()
# tekst2.convert_alpha()
tekst3 = tekst2.copy()
tekst1.blit(tekst3, (0, 0))
tekst1.set_at((1, 1), pg.Color("yellow"))
Expand Down

0 comments on commit bc5468d

Please sign in to comment.