Skip to content

Commit

Permalink
text experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreyrosenbluth committed Mar 31, 2014
1 parent d9bdc90 commit 2145e8b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Diagrams/TwoD/Text.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ data Text = Text T2 TextAlignment String
type instance V Text = R2

instance Transformable Text where
transform t (Text tt a s) = Text (t <> tt) a s
transform t (Text tt a s) = Text (t <> tt <> t') a s
where
t' = scaling (1 / avgScale t)

instance HasOrigin Text where
moveOriginTo p = translate (origin .-. p)
Expand Down

8 comments on commit 2145e8b

@jeffreyrosenbluth
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One possible idea?
fontSize Local transforms with scales and all.
The other measures have their transforms normalized by the avgScale, so for example
a scaleX 2, would be scaleX 2 . scale 1/(sqrt 2).

@byorgey
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha! Yes, I think this is a good way to do it.

Oh, one minor snag: if the text is not centered then scaling it is going to cause the text to move closer to the local origin in addition to being scaled. I would have to try some examples but I think this is a problem. To solve it we would have to do something like store a separate affine transformation and translation vector, and decompose incoming transformations into those components as well, only applying the inverse of the avgScale to the affine part.

@jeffreyrosenbluth
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have enough control over alignment to test it in SVG or do we need to implement units in Cairo or Rasterific?

@byorgey
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not about alignment. Just translate some text, like text "foo" # translateX 5.

@jeffreyrosenbluth
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll run some tests tonight.

@jeffreyrosenbluth
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've played around with this a bit and I'm not sure whether or not this is a problem.
Part of the problem is that I'm not sure of what semantics something like:

example = text "Hello World!" # fontSizeO 25 # translateX 2 # scaleX 2 <> rect 8 1 # lwO 1 # showOrigin

should have.
Can you take a look at the diagram this generates and tell me how the desired diagram should look?

@byorgey
Copy link
Member

@byorgey byorgey commented on 2145e8b Apr 1, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I played around with it and it seems to have exactly the semantics I expect: namely, the location of the text is affected normally by any transformations; it's just the text itself which is prevented from scaling. This puzzled me until I looked at the code again and realized I had not properly understood the cleverness of writing (t <> tt <> t'): first we undo any effects of t's scaling; then we do any existing transformations tt (which might include translations), and finally we do the new transformation t! So when we do someText # transform t1 # transform t2 # transform t3 we ultimately end up with the transformation t3 <> t2 <> t1 <> t1' <> t2' <> t3' where the primed versions are all uniform scalings counteracting the avgScale of the other three. Since they happen first they don't affect any translations contained in t1 .. t3.

So, to be clear, I am quite happy with this code!

@jeffreyrosenbluth
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent, so all that remains is to decide on what Measure to use as a default.

Please sign in to comment.