A request regarding to fonts. (not ImageFonts)

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
ZenX2
Citizen
Posts: 89
Joined: Wed Nov 17, 2010 5:35 am

A request regarding to fonts. (not ImageFonts)

Post by ZenX2 »

(This does not apply to ImageFonts or have anything to do with them at all.)

I've recently been troubled by fonts. I'm attempting to use a pixelly font, but they always end up looking crappy, like this:

Image

As you can see, the linear filtering really messes us the crispness and makes it look like someone couldn't keep down their alphabet soup.
Annoyed by this and the lack of a way to solve it in my code, I request that you add the option to choose the types of filtering for a font.

I've read through the source code and I have found that Graphics->newFont can accept filtering options, but in the wrapper's newFont1 function, you completely ignore it and force all fonts created with love.graphics.newFont to use linear filtering.

I suggest you alter it to something like this:

Code: Select all

int w_newFont1(lua_State * L)
        {
                Data * font_data = NULL;
                // Convert to File, if necessary.
                if (lua_isstring(L, 1))
                        luax_convobj(L, 1, "filesystem", "newFile");

                // Convert to Data, if necessary.
                if (luax_istype(L, 1, FILESYSTEM_FILE_T))
                {
                        love::filesystem::File * f = luax_checktype<love::filesystem::File>(L, 1, "File", FILESYSTEM_FILE_T);
                        try
                        {
                                font_data = f->read();
                        }
                        catch (love::Exception & e)
                        {
                                return luaL_error(L, e.what());
                        }
                        lua_remove(L, 1); // get rid of the file
                        luax_newtype(L, "Data", DATA_T, (void*)font_data);
                        lua_insert(L, 1); // put it at the bottom of the stack
                }

                // Convert to Rasterizer, if necessary.
                if (luax_istype(L, 1, DATA_T))
                {
                        int idxs[] = {1, 2};
                        luax_convobj(L, idxs, 2, "font", "newRasterizer");
                }

                if (font_data)
                        font_data->release();

                love::font::Rasterizer * rasterizer = luax_checktype<love::font::Rasterizer>(L, 1, "Rasterizer", FONT_RASTERIZER_T);

                Image::Filter filter;
                Image::FilterMode min;
                Image::FilterMode mag;
                const char * minstr = luaL_checkstring(L, 2);
                const char * magstr = luaL_checkstring(L, 3);
                if (!Image::getConstant(minstr, min))
                        return luaL_error(L, "Invalid filter mode: %s", minstr);
                if (!Image::getConstant(magstr, mag))
                        return luaL_error(L, "Invalid filter mode: %s", magstr);

                filter.min = min;
                filter.mag = mag;

                // Create the font.
                Font * font = instance->newFont(rasterizer, filter);

                if (font == 0)
                        return luaL_error(L, "Could not load font.");

                // Push the type.
                luax_newtype(L, "Font", GRAPHICS_FONT_T, (void*)font);

                return 1;
        }
I don't have much (any :v) experience with the Lua C API so I don't think that will actually compile, but I think it should get the idea across.
Last edited by ZenX2 on Mon Apr 30, 2012 5:46 am, edited 1 time in total.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: A request regarding to fonts.

Post by Jasoco »

I think it's just because simply using love.graphics.scale() doesn't have a smoothing option. To get around this I just draw everything to a Canvas and scale the canvas. But then it ends up alienating certain users who can't support Canvas. But it works as a workaround. I know I've been asking for a Nearest Neighbor scaling option for just plain love.graphics.scale() forever but it hasn't been implemented yet. It would be nice if we could treat the window plane like we can images and Canvases.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: A request regarding to fonts.

Post by kikito »

I like this. I recommend putting it on the issue tracker as a feature request.
When I write def I mean function.
User avatar
richapple
Citizen
Posts: 65
Joined: Sun Dec 25, 2011 10:25 am

Re: A request regarding to fonts.

Post by richapple »

ZenX2 wrote:I've recently been troubled by fonts. I'm attempting to use a pixelly font, but they always end up looking crappy
I know that feel, bro.

You can try to tweak font sizes if you haven't already (you probably did)
or try to make ImageFont from programs like this, this or this(recommended). But in result I had messed up kerning and had to implement my own print function.

I recommend ImageFont because you can set filtering of the font image to "nearest" and then make an ImageFont from it.
User avatar
ZenX2
Citizen
Posts: 89
Joined: Wed Nov 17, 2010 5:35 am

Re: A request regarding to fonts.

Post by ZenX2 »

I created a ticket on the issue tracker because this is sorely needed.
EyeGem
Prole
Posts: 1
Joined: Sat Apr 28, 2012 2:26 pm

Re: A request regarding to fonts.

Post by EyeGem »

Hi. You can first create image from file (img = love.graphics.newImage), then set min/mag filters for this image (img:setFilter), then create bitmap font with myFont = love.graphics.newImageFont( img, "...glyphs..." ). This way it works with Love 0.8.0.
User avatar
ZenX2
Citizen
Posts: 89
Joined: Wed Nov 17, 2010 5:35 am

Re: A request regarding to fonts.

Post by ZenX2 »

It's not images, it's true type fonts.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 48 guests