sudo rm -rf
sudo rm -rf

Reputation: 29524

How to create letterpress effect?

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!

Upvotes: 2

Views: 1407

Answers (2)

Brad Larson
Brad Larson

Reputation: 170317

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.

Upvotes: 3

Jon Hess
Jon Hess

Reputation: 14257

  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.

Upvotes: 1

Related Questions