Article Preview
Buy Now
FEATURE
Fun with Fonts
Working with Cocoa fonts in Xojo
Issue: 14.2 (March/April 2016)
Author: Marc Zeedar
Author Bio: Marc taught himself programming in high school when he bought his first computer but had no money for software. He's had fun learning ever since.
Article Description: No description available.
Article Length (in bytes): 36,335
Starting Page Number: 16
Article Number: 14203
Resource File(s):
14203project.zip Updated: 2016-03-01 13:41:37
Related Link(s): None
Excerpt of article text...
Recently I returned to work on a major project I haven't focused on for a while. (I thought it had only been a year, but I was shocked to discover most of my files were dated 2013. Granted it was December, but still. Time sure flies when you're not watching!) Anyway, I opened the file in the latest version of Xojo and ran it just to see how well things worked.
My own bugs and an incomplete project aside, I soon discovered a major issue with fonts. Now I worked with fonts quite a bit back in the day when I did my Z-Write word processor, but it's been a while. I haven't done much with them since the transition from Carbon to Cocoa. And I discovered that frankly, fonts are completely broken in Xojo.
It's not like I'm building a font editor—all I want to do is assign a particular font to items programmatically. (In brief, my program allows users to create pictures via Xojoscript, and that involves specifying fonts by name for text drawing.) This means I can't use a user interface and I
must specify the font's exact name. That's where the problem comes in, because you can no longer do that in Xojo!Font Messiness
Under Carbon, to specify a font, you could say something like
aFont = "Helvetica Bold Oblique"
and it would work. However, under Cocoa, fonts work differently. There are now two parts to fonts, thefamily and the style (technically themember in Cocoa lingo). In the above example, "Helvetica" would be the family and "Bold Oblique" would be the style.Under Carbon the OS was smart enough to even guess at which style was "bold" or "italic" when you specified bold or italic (and it could even simulate a bold or italic if the font family didn't have a real bold or italic). From a typography perspective that isn't ideal, and the behavior is unpredictable, but it was how things worked and it meant that you could specify the font as
aFont = "Helvetica"
and then programmatically set Xojo'sbold
oritalic
settings totrue
.
...End of Excerpt. Please purchase the magazine to read the full article.