module Data.Text.ParagraphLayout.Internal.VerticalOffsets ( VerticalOffsets (..) , alignBaseline , alignLayoutTop , shift ) where import Data.Int (Int32) -- | Metrics used for vertical alignment of text fragments. data VerticalOffsets = VerticalOffsets { layoutTop :: Int32 -- ^ Y coordinate of the top edge of the fragment, -- including half-leading. , fontTop :: Int32 -- ^ Y coordinate of the font's ascender. , baseline :: Int32 -- ^ Y coordinate of the font's baseline. , fontBottom :: Int32 -- ^ Y coordinate of the font's descender. , layoutBottom :: Int32 -- ^ Y coordinate of the bottom edge of the fragment, -- including half-leading. } deriving (Eq, Show) -- | Add a constant to each of the coordinates, effectively moving them -- up by the given amount while preserving distances between them. shift :: Int32 -> VerticalOffsets -> VerticalOffsets shift d vo = vo { layoutTop = layoutTop vo + d , fontTop = fontTop vo + d , baseline = baseline vo + d , fontBottom = fontBottom vo + d , layoutBottom = layoutBottom vo + d } -- | Set `layoutTop` to the given value and update all other coordinates -- so that distances are preserved. alignLayoutTop :: Int32 -> VerticalOffsets -> VerticalOffsets alignLayoutTop x vo = shift (x - layoutTop vo) vo -- | Set `baseline` to the given value and update all other coordinates -- so that distances are preserved. alignBaseline :: Int32 -> VerticalOffsets -> VerticalOffsets alignBaseline x vo = shift (x - baseline vo) vo