FROM : Ricky Sharp
DATE : Sat Aug 26 15:23:45 2006
On Aug 26, 2006, at 7:41 AM, Keith Blount wrote:
> My application has a corkboard view which displays a
> number of index cards. Each index card has a title,
> text, label and status associated with it. The title
> and text are the index card's contents, and the label
> is a colour associated with it that is drawn as a
> coloured pin.
>
> One of my users has just made the rather excellent
> suggestion that the status should be displayed as a
> "stamp", that is, transparent red text drawn
> diagonally across the index card. I would like to
> implement this, but have a couple of questions on how
> to go about it.
>
> Presumably, I am going to use NSAffineTransform to
> rotate the drawing and then draw my string in the
> usual way. That part should be fine. What I am
> confused about is how to calculate the size of the
> string when it has to be drawn diagonally - this part
> is probably just a maths failing on my part. Obviously
> I can calculate the diagonal size of my index card,
> but it has to take into account the height of the
> string, too. What is the best way to do this?
>
> More importantly, the strings drawn can be of varying
> lengths, but they should always be shrunk to fit into
> the card diagonally. How can I get the diagonal size
> for my string and then shrink the string to make sure
> that the font is of just the right size so that the
> whole string can be drawn?
It's just math, as you've stated. If the text had a height that was
zero, it's width would be the length of the card's diagonal.
What I'd do in your case is to just hand-draw things out. Perhaps
start out by inscribing a rectangle within a square. Note that the
height of the rectangle (text height) will drive things. I would
pick the font size that you would not want to go below and use that
as an initial rectangle height. You may also want to pick a maximum
font size to use as well.
Using trig, you can then compute the width of the rectangle (string
width) that will fit within your square. If this width is less than
the actual text width at the current font size, pick a new font
size. Perhaps use a binary search here to converge on the font size.
When you get that all worked out, it will be a simple extension to
apply the equations to a card that has unequal width/height (i.e. not
a square).
I would imagine you could google for the equations; perhaps search on
"inscribe rectangle".
___________________________________________________________
Ricky A. Sharp mailto:<email_removed>
Instant Interactive(tm) http://www.instantinteractive.com
DATE : Sat Aug 26 15:23:45 2006
On Aug 26, 2006, at 7:41 AM, Keith Blount wrote:
> My application has a corkboard view which displays a
> number of index cards. Each index card has a title,
> text, label and status associated with it. The title
> and text are the index card's contents, and the label
> is a colour associated with it that is drawn as a
> coloured pin.
>
> One of my users has just made the rather excellent
> suggestion that the status should be displayed as a
> "stamp", that is, transparent red text drawn
> diagonally across the index card. I would like to
> implement this, but have a couple of questions on how
> to go about it.
>
> Presumably, I am going to use NSAffineTransform to
> rotate the drawing and then draw my string in the
> usual way. That part should be fine. What I am
> confused about is how to calculate the size of the
> string when it has to be drawn diagonally - this part
> is probably just a maths failing on my part. Obviously
> I can calculate the diagonal size of my index card,
> but it has to take into account the height of the
> string, too. What is the best way to do this?
>
> More importantly, the strings drawn can be of varying
> lengths, but they should always be shrunk to fit into
> the card diagonally. How can I get the diagonal size
> for my string and then shrink the string to make sure
> that the font is of just the right size so that the
> whole string can be drawn?
It's just math, as you've stated. If the text had a height that was
zero, it's width would be the length of the card's diagonal.
What I'd do in your case is to just hand-draw things out. Perhaps
start out by inscribing a rectangle within a square. Note that the
height of the rectangle (text height) will drive things. I would
pick the font size that you would not want to go below and use that
as an initial rectangle height. You may also want to pick a maximum
font size to use as well.
Using trig, you can then compute the width of the rectangle (string
width) that will fit within your square. If this width is less than
the actual text width at the current font size, pick a new font
size. Perhaps use a binary search here to converge on the font size.
When you get that all worked out, it will be a simple extension to
apply the equations to a card that has unequal width/height (i.e. not
a square).
I would imagine you could google for the equations; perhaps search on
"inscribe rectangle".
___________________________________________________________
Ricky A. Sharp mailto:<email_removed>
Instant Interactive(tm) http://www.instantinteractive.com
| Related mails | Author | Date |
|---|---|---|
| Keith Blount | Aug 26, 14:41 | |
| Ricky Sharp | Aug 26, 15:23 | |
| Wagner Truppel | Aug 27, 00:42 | |
| Wagner Truppel | Aug 27, 04:55 |






Cocoa mail archive

