Page 1 of 1

A request regarding to fonts. (not ImageFonts)

Posted: Wed Apr 25, 2012 1:08 am
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.

Re: A request regarding to fonts.

Posted: Wed Apr 25, 2012 4:41 am
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.

Re: A request regarding to fonts.

Posted: Wed Apr 25, 2012 6:55 am
by kikito
I like this. I recommend putting it on the issue tracker as a feature request.

Re: A request regarding to fonts.

Posted: Wed Apr 25, 2012 12:02 pm
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.

Re: A request regarding to fonts.

Posted: Fri Apr 27, 2012 1:48 am
by ZenX2
I created a ticket on the issue tracker because this is sorely needed.

Re: A request regarding to fonts.

Posted: Sat Apr 28, 2012 2:34 pm
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.

Re: A request regarding to fonts.

Posted: Mon Apr 30, 2012 5:44 am
by ZenX2
It's not images, it's true type fonts.