~jaro/balkon

4c1db0da368a4d8a2a33ab0d37deef45e99a54d2 — Jaro 11 months ago ebfdbbd
Test layout with mixed font sizes.
A .golden/richParagraphLayout/mixedSizes.golden => .golden/richParagraphLayout/mixedSizes.golden +68 -0
@@ 0,0 1,68 @@
ParagraphLayout
    { paragraphRect = Rect {x_origin = 0, y_origin = 0, x_size = 8634, y_size = -1121}
    , paragraphFragments =
        [ Fragment
            { fragmentUserData = "bigText1"
            , fragmentLine = 1
            , fragmentRect = Rect {x_origin = 0, y_origin = 0, x_size = 1651, y_size = -1121}
            , fragmentPen = (0, -932)
            , fragmentGlyphs =
                [ (GlyphInfo {codepoint = 69, cluster = 6, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 589, y_advance = 0, x_offset = 0, y_offset = 0})
                , (GlyphInfo {codepoint = 76, cluster = 7, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 253, y_advance = 0, x_offset = 0, y_offset = 0})
                , (GlyphInfo {codepoint = 74, cluster = 8, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 578, y_advance = 0, x_offset = 0, y_offset = 0})
                , (GlyphInfo {codepoint = 3, cluster = 9, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 231, y_advance = 0, x_offset = 0, y_offset = 0})
                ]
            }
        , Fragment
            { fragmentUserData = "smallText1"
            , fragmentLine = 1
            , fragmentRect = Rect {x_origin = 1651, y_origin = 0, x_size = 1956, y_size = -841}
            , fragmentPen = (0, -699)
            , fragmentGlyphs =
                [ (GlyphInfo {codepoint = 86, cluster = 10, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 335, y_advance = 0, x_offset = 0, y_offset = 0})
                , (GlyphInfo {codepoint = 80, cluster = 11, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 646, y_advance = 0, x_offset = 0, y_offset = 0})
                , (GlyphInfo {codepoint = 68, cluster = 12, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 392, y_advance = 0, x_offset = 0, y_offset = 0})
                , (GlyphInfo {codepoint = 79, cluster = 13, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 205, y_advance = 0, x_offset = 0, y_offset = 0})
                , (GlyphInfo {codepoint = 79, cluster = 14, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 205, y_advance = 0, x_offset = 0, y_offset = 0})
                , (GlyphInfo {codepoint = 3, cluster = 15, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 173, y_advance = 0, x_offset = 0, y_offset = 0})
                ]
            }
        , Fragment
            { fragmentUserData = "bigText2"
            , fragmentLine = 1
            , fragmentRect = Rect {x_origin = 3607, y_origin = 0, x_size = 1651, y_size = -1121}
            , fragmentPen = (0, -932)
            , fragmentGlyphs =
                [ (GlyphInfo {codepoint = 69, cluster = 16, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 589, y_advance = 0, x_offset = 0, y_offset = 0})
                , (GlyphInfo {codepoint = 76, cluster = 17, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 253, y_advance = 0, x_offset = 0, y_offset = 0})
                , (GlyphInfo {codepoint = 74, cluster = 18, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 578, y_advance = 0, x_offset = 0, y_offset = 0})
                , (GlyphInfo {codepoint = 3, cluster = 19, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 231, y_advance = 0, x_offset = 0, y_offset = 0})
                ]
            }
        , Fragment
            { fragmentUserData = "smallText2"
            , fragmentLine = 1
            , fragmentRect = Rect {x_origin = 5258, y_origin = 0, x_size = 1956, y_size = -841}
            , fragmentPen = (0, -699)
            , fragmentGlyphs =
                [ (GlyphInfo {codepoint = 86, cluster = 20, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 335, y_advance = 0, x_offset = 0, y_offset = 0})
                , (GlyphInfo {codepoint = 80, cluster = 21, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 646, y_advance = 0, x_offset = 0, y_offset = 0})
                , (GlyphInfo {codepoint = 68, cluster = 22, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 392, y_advance = 0, x_offset = 0, y_offset = 0})
                , (GlyphInfo {codepoint = 79, cluster = 23, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 205, y_advance = 0, x_offset = 0, y_offset = 0})
                , (GlyphInfo {codepoint = 79, cluster = 24, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 205, y_advance = 0, x_offset = 0, y_offset = 0})
                , (GlyphInfo {codepoint = 3, cluster = 25, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 173, y_advance = 0, x_offset = 0, y_offset = 0})
                ]
            }
        , Fragment
            { fragmentUserData = "bigText3"
            , fragmentLine = 1
            , fragmentRect = Rect {x_origin = 7214, y_origin = 0, x_size = 1420, y_size = -1121}
            , fragmentPen = (0, -932)
            , fragmentGlyphs =
                [ (GlyphInfo {codepoint = 69, cluster = 26, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 589, y_advance = 0, x_offset = 0, y_offset = 0})
                , (GlyphInfo {codepoint = 76, cluster = 27, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 253, y_advance = 0, x_offset = 0, y_offset = 0})
                , (GlyphInfo {codepoint = 74, cluster = 28, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False}, GlyphPos {x_advance = 578, y_advance = 0, x_offset = 0, y_offset = 0})
                ]
            }
        ]
    }

M test/Data/Text/ParagraphLayout/FontLoader.hs => test/Data/Text/ParagraphLayout/FontLoader.hs +8 -0
@@ 5,6 5,7 @@ module Data.Text.ParagraphLayout.FontLoader
    , loadFont
    , writeFontInfo
    , testingOptions
    , testingOptionsSmall
    , demoOptions
    )
where


@@ 67,6 68,13 @@ testingOptions = defaultFontOptions {
    optionScale = Just (1000, 1000)
}

-- | Like `testingOptions` with font size proportionally changed to 18px.
testingOptionsSmall :: FontOptions
testingOptionsSmall = defaultFontOptions {
    optionPPEm = Just (18, 18),
    optionScale = Just (750, 750)
}

-- | Font options to be used to be used for easy visual testing in a demo app
-- (32 units per EM, 1 unit per pixel).
-- This makes 20em equal 640px, which is the width of the demo window.

M test/Data/Text/ParagraphLayout/Rich/ParagraphData.hs => test/Data/Text/ParagraphLayout/Rich/ParagraphData.hs +21 -0
@@ 1,5 1,6 @@
module Data.Text.ParagraphLayout.Rich.ParagraphData
    ( loremIpsumParagraph
    , mixedSizesParagraph
    , nestedBoxesParagraph
    )
where


@@ 41,6 42,26 @@ loremIpsumParagraph font = constructParagraph
    where
        t = t_ { textFont = font, textLanguage = "zxx" }

mixedSizesParagraph :: (Font, Font) -> ParagraphOptions -> Paragraph String
mixedSizesParagraph (bigFont, smallFont) = constructParagraph
    (pack "prefix")
    (rootBox tBig
        [ text "bigText1" "big "
        , box "smallBox1" b_ tSmall
            [ text "smallText1" "small "
            ]
        , text "bigText2" "big "
        , box "smallBox2" b_ tSmall
            [ text "smallText2" "small "
            ]
        , text "bigText3" "big"
        ]
    )
    (pack "suffix")
    where
        tBig = t_ { textFont = bigFont, textLanguage = "en" }
        tSmall = t_ { textFont = smallFont, textLanguage = "en" }

nestedBoxesParagraph :: Font -> ParagraphOptions -> Paragraph String
nestedBoxesParagraph font = constructParagraph
    (pack "prefix")

M test/Data/Text/ParagraphLayout/RichSpec.hs => test/Data/Text/ParagraphLayout/RichSpec.hs +7 -0
@@ 20,6 20,7 @@ spec = do

        describe "with Latin font" $ do
            font <- runIO $ loadFont latinFont 0 testingOptions
            fontSmall <- runIO $ loadFont latinFont 0 testingOptionsSmall

            it "wraps lorem ipsum at 20em" $ do
                let opts = defaultParagraphOptions { paragraphMaxWidth = 20000 }


@@ 27,6 28,12 @@ spec = do
                let result = layoutRich input
                result `shouldBeGolden` "loremIpsum20em"

            it "handles mixed sizes" $ do
                let opts = defaultParagraphOptions
                let input = mixedSizesParagraph (font, fontSmall) opts
                let result = layoutRich input
                result `shouldBeGolden` "mixedSizes"

            it "handles nested boxes" $ do
                let opts = defaultParagraphOptions
                let input = nestedBoxesParagraph font opts