Skip to content

Fonts don't have crispness (looks very ghostly) and thickness varies between browsers #2459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ghost opened this issue Nov 18, 2014 · 7 comments · Fixed by #3263
Closed

Fonts don't have crispness (looks very ghostly) and thickness varies between browsers #2459

ghost opened this issue Nov 18, 2014 · 7 comments · Fixed by #3263

Comments

@ghost
Copy link

ghost commented Nov 18, 2014

I've been trying to fix the quality of fonts for a while now. I'm using CCLabelTTF and the font thickness seems to vary a lot between browsers as well. Here's an example of MuseoSans_100.ttf:
Safari:

screen shot 2014-11-17 at 7 50 48 pm

Chrome:

screen shot 2014-11-17 at 7 48 40 pm

FireFox:

screen shot 2014-11-17 at 7 51 13 pm

I tried loading other fonts as well and the light weight ones look very ghostly.I looked at a lot of articles online for this and none of them seem to fix this issue. The version of Cocos I'm using is 2.2.2 but this seems to happen for V3.1 as well. I tried looking at a few other cocos2d html5 games out there and they all seem to have a very similar font quality.

@hsdk123
Copy link

hsdk123 commented Nov 20, 2014

@dingpinglv @pandamicro I'm having the same issue as well. The font doesn't display as crisp as compared to ex. when I render text using c++.

@ghost
Copy link
Author

ghost commented Jan 8, 2015

@dingpinglv @pandamicro any fixes for this? We're looking to create a lot of games using this engine but the font quality would be a big deal breaker. We are also going to have the text localized in many languages and need many different fonts.

@hsdk123
Copy link

hsdk123 commented Jan 15, 2015

@dingpinglv @pandamicro As pointed in the comment above, it's past about 2 months since the original post - has there been any updates to this? This is especially really important for games with a lot of narrative.

@dingpinglv dingpinglv self-assigned this Jan 16, 2015
@dingpinglv
Copy link
Contributor

Hi @hsdk123 and @sjayadevan ,
I'm sorry for reply late.
About the fonts look very ghostly, do you set the labelTTF's scale? Because WebGL haven't Drawing text API, so we use canvas to draw text and use it as texture on WebGL. On canvas Mode, we use the same mechanism to draw text, the reason is that it's very expensive to call fillText on mobile browser.

About font effect varies between browsers, I have no idea, because this issue is incompatibility between the browser vendors.

My suggestion is that:

  1. don't scale labelTTF, and use bold font
  2. Use LabelBMFont, if there aren't a lot of text displayed

Best regards
David

@dingpinglv
Copy link
Contributor

Here is a contradistinction between scaled and unscaled:
Scaled code:

        this.helloLabel = new cc.LabelTTF("Hello World", "Arial", 30);
        this.helloLabel.setScale(2);

Chrome:
image
firefox:
image

IE:
image

Safari:
image

unscaled code:
this.helloLabel = new cc.LabelTTF("Hello World", "Arial", 60);
chrome:
image

firefox:
image

IE:
image

Safari:
image

@ghost
Copy link
Author

ghost commented Jan 20, 2015

@dingpinglv Thanks for replying!

  1. I'm not scaling the labels.
  2. We need to use 20 pt font sizes not 60 as shown in your example.
  3. Your unscaled code examples still show blurry text. They're not crisp and you have aliasing issues on them.

With a heavier font weight of Museo Sans I get the following:

Chrome (Museo Sans 300):

screen shot 2015-01-20 at 11 30 24 am

Safari (Museo Sans 500):

screen shot 2015-01-20 at 11 29 29 am

As you can see none of them are crisp. It's also interesting that lighter weight font in Chrome is much thicker than heavier weight font in Safari

@ntrrgc
Copy link
Contributor

ntrrgc commented Apr 5, 2016

This looks very much like a premultiplied alpha issue.

From GIMP documentation:

Premultiplied alpha is just a different way of representing alphified pixels. If the separate alpha pixel is (r, g, b, a), then the premultiplied alpha pixel is (ar, ag, ab, a).

The reason why it's interesting is that linear combinations of pixels (i.e. a1p1 + a2p2) work better in premultiplied alpha space than in separate alpha space.

For example, taking the 50/50 blend of white and transparent works like this: White is (1, 1, 1, 1) and transparent is (0, 0, 0, 0) in both spaces. So the 50/50 blend is (0.5, 0.5, 0.5, 0.5). In separated space, that's half-transparent gray, but in premultiplied space, that's half-transparent white, which is what you expect.

Linear combinations of pixels occur in a lot of contexts, including:

  1. layer compositing
  2. blurring and sharpening
  3. interpolation
  4. scaling
  5. rotation, perspective, and other transformations

and probably one or two others.

The symptom of getting alpha wrong is gray fringes when you work with transparent layers.

Here is also a video demonstration of how not using premultiplied alpha causes these artifacts: https://www.youtube.com/watch?v=dU9AXzCabiM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants