Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Tk, fonts and resolution

by Chuma (Scribe)
on Dec 09, 2017 at 16:51 UTC ( [id://1205224]=perlquestion: print w/replies, xml ) Need Help??

Chuma has asked for the wisdom of the Perl Monks concerning the following question:

Hello!

I've been trying to learn Tk by making a little retro game, and now I'm starting to feel like it finally doesn't look terrible. But one thing still does: the fonts. I can't figure out how to get the ordinary system fonts to work, and the built-in fonts are all so badly pixellated they look awkward even for my 90s-style game.

I'm using ActivePerl 5.20, on a Macbook Pro from 2015. I think part of the reason is the "Retina display"; if I understand it right, the latest high-res mac screens are basically pretending to be a much lower resolution, so that old programs won't look tiny, but they also don't benefit from the increased resolution. This affects all my Tk programs, effectively making the resolution a fraction of what it could be, which is of course pretty annoying generally. But there has to be some other reason the fonts look so awful. They also don't seem to be using any anti-aliasing; that could be part of the reason.

So I'd like to:

  • ideally make my Tk programs use the actual resolution, not the nerfed Retina-thing
  • get Tk to use other fonts, ideally specified with a font file
  • figure out why the fonts look so bad and what else can be done about it
if anyone could help me with any of those. Thanks!

Replies are listed 'Best First'.
Re: Tk, fonts and resolution (Tk and Retina display)
by Discipulus (Canon) on Dec 09, 2017 at 23:04 UTC
    Hello Chuma,

    waiting for your retro game to be announced here.. ;=)

    About the problem you are facing i must first admit i know nothing about mac nor retina stuff, but I'd verify the following:

    • the font test of the tk installation looks the same? all fonts ugly? If you have Mastering Perl Tk in the chapter 3.4. Using Fonts Dynamically there is an useful program to choose fonts. Try it to see/confirm all fonts are pixellated.
    • the program runs fine on other osses?
    • if the problem seems to be in the conjuction of Tk and your OS you can read carefully this bug report that seems very close to your. This lead to this page where some solution seems to lay, but where users also complains about lost display..

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re: Tk, fonts and resolution
by Chuma (Scribe) on Dec 10, 2017 at 20:46 UTC

    I've tested all the fonts, and it seems that some are more broken than others; as far as I can tell, some look like proportional fonts that are just using a lower resolution, whereas others don't scale up at all, so large font sizes end up using "pixels" the size of peas.

    As for other OSes, I haven't had a chance to test that – so far, I'm having enough trouble getting things to run on one system. But if anyone wants to try it on their system, this should be a working example:

    use Tk; $mainWin=MainWindow->new; for(10,20,40,80,200){ $mainWin->fontCreate("font$_",-family =>'lucidabright',-size=> +$_); $mainWin->messageBox(-message=>"$_ The Quick Brown Fox Jumped +Over The Lazy Dog",-type=>'Ok',-font=>"font$_"); }

    In this case, 'lucidabright' is an example of the bad kind of font, whereas 'utopia' is a similar-looking font of the less bad kind.

    As I understand the discussion in the link, they're basically disabling the Retina thing to set the resolution higher. That would probably more or less solve the problem, although it would be a little inconvenient to have to change the resolution every time I run the program. I suppose there's some system command for doing that, too. Bit of a workaround, and of course the guy who says his screen died also doesn't inspire confidence. But I'll look into that.

    Someone else had similar problems in this thread. They didn't find any solution, and the OP says they eventually gave up using text and replaced it with pre-rendered images, but I'm hoping I won't have to do that.

    I also tried getting the modules "Img" and "tkpng", hoping they might help with the PNG issue, but frankly I can't figure out how to install them. One is a long list of "dylib" files, the other is the usual Unix mess with "configure" and "makefile", but running "make" gives fatal error: 'X11/Xlib.h' file not found, so I'm stumped again. I'm not very good at all that unix hacking. I'm a Mac user, I just want to click an app...

      That code doesn't run :/ bad option "-font": must be -default, -icon, -message, -parent, -title, or -type

Re: Tk, fonts and resolution
by herveus (Prior) on Dec 11, 2017 at 13:23 UTC
    Howdy!

    I use Tk on my Macbook Pro with Retina display. I am not displaying graphic files, but my applications that I wrote over fifteen years ago display fine with no weirdness.

    The native resolution of that display is 2880x1800 with pixels that are difficult to resolve with your eyes at normal viewing distances. That's about 220 ppi. So fine details don't pixelate as readily.

    yours,
    Michael
Re: Tk, fonts and resolution
by Anonymous Monk on Dec 09, 2017 at 17:21 UTC
Re: Tk, fonts and resolution
by Anonymous Monk on Dec 10, 2017 at 15:46 UTC
Re: Tk, fonts and resolution
by Chuma (Scribe) on Dec 09, 2017 at 17:51 UTC
    Okay, I'll give that a try... It seems to have trouble with PNG files – what do I use instead of Tk::PNG?
      Talking to me? Tcl..Ptk has no issues with png afaik. Although im awwy from keyboard
Re: Tk, fonts and resolution
by Chuma (Scribe) on Dec 09, 2017 at 18:39 UTC
    Well, with use Tk the program works, but requires use Tk::PNG as well. With use Tcl::pTk instead, I get the error couldn't recognize data in image file (...) Widget.pm line 332. So I assumed it doesn't have built-in PNG support either, just like the plain Tk. But I don't know, maybe I've done something else wrong.
Re: Tk, fonts and resolution
by Chuma (Scribe) on Dec 09, 2017 at 19:45 UTC
    Not sure if I'm missing something else, or maybe something is outdated. Now I get: image file format "png" is not supported
Re: Tk, fonts and resolution
by Chuma (Scribe) on Dec 11, 2017 at 13:33 UTC
    Okay, so, fonts look fine on your screen? If you try the example program I posted above, you don't have any problems?
      Howdy!

      I have not had any opportunity to try your example program. I will try to remember to give that a shot this evening.

      yours,
      Michael

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1205224]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-18 05:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found