2

I'm looking to implement something like the famous "letterpress" effect in my application. Here's what I'm talking about: (just a quick example made in PShop) Letterpress effect

As you can see, it looks like it's pressed into the background. I wonder if it's possible to do something like this on the Mac dynamically. Is there a way? Thanks!

sudo rm -rf
  • 29,408
  • 19
  • 102
  • 161
  • If you really need this effect, and there is no other solution available, you can always use separate PNG files for every character and merge them together. Ugly, but it works :) – Anne Feb 22 '11 at 18:02
  • @Anne: I was thinking I could make a custom font to do the job, but I don't really know how I'd go about it. – sudo rm -rf Feb 22 '11 at 18:34

2 Answers2

3

You can do the gradient fill portion of the text using the code I provide in this answer. Check the coordinate space first, because I described that for the iPhone, which has an inverted Y axis when compared to the Mac's normal Quartz coordinates.

The text is first used to create a clipping path, and the gradient is drawn within that path.

As far as the internal shadow, you might be able to draw this after the gradient is drawn by using CGContextSetShadowWithColor() with an appropriate downward offset and black color, then drawing the text again using just the stroke of the text. deanWombourne has some sample code for a similar task in his answer here.

Community
  • 1
  • 1
Brad Larson
  • 170,088
  • 45
  • 397
  • 571
1
  1. Draw the text with a normal font to create a black and white bitmap of the text.
  2. Draw another image that is is the same size and completely filled with the gray-to-white gradient you have above.
  3. Create a completely white image with the same size as your other images.
  4. Draw your back and white text image (1) onto the white image (3) with NSCompositeDestinationOut.

This gives you a white image with your text cut out.

Draw the white image with the text cut out on top of the gradient image and apply a shadow while drawing.

Jon Hess
  • 14,237
  • 1
  • 47
  • 51
  • That seems intense. I'll probably pass on it for now unless there is an easier way, as it seems like overkill and processor-intensive for just displaying text. – sudo rm -rf Feb 24 '11 at 04:05
  • It is definitely a PITA but it isn't really processor intensive. – sosborn Feb 24 '11 at 04:21