TypeError: expected a float for size, got

125 Views Asked by At

I'm trying to run the code to generate font model as below:

import pygame
from pygame import freetype
from text_utils import FontState
import numpy as np
import matplotlib.pyplot as plt
import _pickle as cp

pygame.init()

ys = np.arange(8, 200)
A = np.c_[ys, np.ones_like(ys)]

xs = []
models = {}  # linear model

FS = FontState()
# plt.figure()
# plt.hold(True)
for i in range(len(FS.fonts)):
    font = freetype.Font(FS.fonts[i], size=12)
    h = []
    for y in ys:
        h.append(font.get_sized_glyph_height(y))
    h = np.array(h)
    m, _, _, _ = np.linalg.lstsq(A, h)
    models[font.name] = m
    print("{}:\t{}".format(i, font.name))
    xs.append(h)

with open('font_px2pt.cp', 'w') as f:
    cp.dump(models, f)
# plt.plot(xs,ys[i])

And when I ran I got the error:

enter image description here

Please help me!

1

There are 1 best solutions below

0
On

As a firtst try you might try to explcitely cast the value of y to float (as stated by the error message) by using float(y).