Skip to content

Commit

Permalink
express FontSize using Measure
Browse files Browse the repository at this point in the history
  • Loading branch information
bergey committed Mar 16, 2014
1 parent 74b5fee commit 09adc82
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/Diagrams/TwoD/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Diagrams.Core.Types (RTree)
import Diagrams.TwoD.Arrow
import Diagrams.TwoD.Attributes
import Diagrams.TwoD.Size (SizeSpec2D, sizePair)
import Diagrams.TwoD.Text
import Diagrams.TwoD.Types (R2)

-- | Take a getter, a setter, and two scaling terms, return a function
Expand Down Expand Up @@ -48,4 +49,5 @@ toOutput ns gs = mapRTreeStyle f
where
f = modifyStyle getLineWidth lineWidth ns gs .
modifyStyle getHeadSize headSize ns gs .
modifyStyle getTailSize tailSize ns gs
modifyStyle getTailSize tailSize ns gs .
modifyStyle getFontSize fontSize ns gs
13 changes: 6 additions & 7 deletions src/Diagrams/TwoD/Text.hs
Original file line number Diff line number Diff line change
Expand Up @@ -164,23 +164,22 @@ font = applyAttr . Font . Last
-- Font size

-- | The @FontSize@ attribute specifies the size of a font's
-- em-square, measured with respect to the current local vector space.
-- Inner @FontSize@ attributes override outer ones.
newtype FontSize = FontSize (Last Double)
deriving (Typeable, Semigroup, Eq)
-- em-square. Inner @FontSize@ attributes override outer ones.
newtype FontSize = FontSize (Last (Measure Double))
deriving (Typeable, Semigroup)
instance AttributeClass FontSize

instance Default FontSize where
def = FontSize (Last 1)
def = FontSize (Last (Local 1))

-- | Extract the size from a @FontSize@ attribute.
getFontSize :: FontSize -> Double
getFontSize :: FontSize -> Measure Double
getFontSize (FontSize (Last s)) = s

-- | Set the font size, that is, the size of the font's em-square as
-- measured within the current local vector space. The default size
-- is @1@.
fontSize :: HasStyle a => Double -> a -> a
fontSize :: HasStyle a => Measure Double -> a -> a
fontSize = applyAttr . FontSize . Last

-- | Apply a 'FontSize' attribute.
Expand Down

6 comments on commit 09adc82

@jeffreyrosenbluth
Copy link
Member

Choose a reason for hiding this comment

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

For this to work (for the SVG backend at least) we need an instance of Show for Measure a that just shows thea.

@byorgey
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need a Show instance for the SVG backend?

@jeffreyrosenbluth
Copy link
Member

Choose a reason for hiding this comment

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

@bergey
Copy link
Member Author

@bergey bergey commented on 09adc82 Mar 16, 2014

Choose a reason for hiding this comment

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

Clearly we should have the backend explicitly match on the Output constructor, rather than have a Show instance that violates show . read === id.

@byorgey
Copy link
Member

Choose a reason for hiding this comment

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

Yes, I agree with @bergey .

@jeffreyrosenbluth
Copy link
Member

Choose a reason for hiding this comment

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

me too

Please sign in to comment.