CPFont improvements

6 views
Skip to first unread message

luddep

unread,
Sep 6, 2009, 9:43:45 PM9/6/09
to Cappuccino & Objective-J Development List
Hello,

CPFont is lacking some things which are quite vital since we are on
the web and thus multiple platforms.

First of all, multiple font families:

All platforms don't have the same fonts or they are named a bit
differently (such as Lucida Grande on OS X vs Lucida Sans Unicode on
Windows), which you solve in CSS by specifying multiple font-families,
for example:

"font-family: Helvetica, sans-serif"; which gives Helvetica for
everyone that's got access to it but gracefully degrades to a sans-
serif font rather than the default font, which usually is a serif
font.

I've got a local version of Cappuccino which extends CPFont a tiny bit
by to handle multiple fonts just by comma separating them: [CPFont
fontWithName:@"Lucida Grande, Lucida Sans Unicode"]; - which currently
isn't possible with the way some small parts of CPFont works.

I've also added so that there's a fallback to _CPFontSystemFontFace at
the end of the css string - so that you don't get any unexpected
browser-default serif fonts which in most cases makes your app quite
ugly and seem quite amateurish.

---

Now, I'd love to hear what everyone thinks about this - and there's
probably a better way of doing it - both API wise & the actual code,
but I felt I needed to get the ball rolling on this since I'm more of
a designer at heart than a coder, and this is quite important for me
(I can't stand using only Arial!).

View the diff of CPFont at github:
http://github.com/luddep/cappuccino/commit/0126418a11bc1b278ea0433ffe46b818ff619c87

.. and now I'd love to get some feedback :)

Thanks!

Ross Boucher

unread,
Sep 20, 2009, 2:04:43 PM9/20/09
to objecti...@googlegroups.com
Seems like a good idea.

As far as code feedback is concered, this struck me as interesting:

// We add the system font face as a fall back,
// for systems that doesn't support any previous fonts.
if (![aString isEqualToString:_CPFontSystemFontFace])
fontFamilies.push(_CPFontSystemFontFace);

In particular, this check only does anything when there is precisely
one font named which is the system font. Is that intentional?

I don't believe there's any actual harm in having the same font in a
font list more than once, so unconditionally adding it to the end
doesn't strike me as problematic. Anyone disagree?

-Ross

Oh, p.s., this screams for being made a separate #define since its
used twice.

_CPFonts[(isBold ? @"bold " : @"") + ROUND(aSize) + @"px " +
parseFontFamilies(aName)]

luddep

unread,
Sep 20, 2009, 3:14:31 PM9/20/09
to Cappuccino & Objective-J Development List
Hello,

I've since then revised the code and cleaned it up a bit:
http://github.com/luddep/cappuccino/commit/387c3f2129695fd166f661bd1b88c9a58a3d8684

You're right, it might be a bit over the top to check if the
systemfont actually should be appended or not.

I actually started out with writing it as a multiline #define, but
after struggling to get it to work - I just replaced it with a
function so that I could actually add the feature, rather than
struggling with parse errors. If it's a requirement to get it
committed, I'll give it another go!
> >http://github.com/luddep/cappuccino/commit/0126418a11bc1b278ea0433ffe...

luddep

unread,
Sep 20, 2009, 3:20:11 PM9/20/09
to Cappuccino & Objective-J Development List
Also, I forgot to add - I'd of course like to write some tests for
this as well - but haven't actually done so yet regarding the possible
ojunit/ojspec switch, would love some clarification on what to use for
future tests.

On Sep 20, 9:14 pm, luddep <lud...@gmail.com> wrote:
> Hello,
>
> I've since then revised the code and cleaned it up a bit:http://github.com/luddep/cappuccino/commit/387c3f2129695fd166f661bd1b...
Reply all
Reply to author
Forward
0 new messages