~jaro/balkon

93f749d4c6ce8a505762333b9a800ebc114222de — Jaro 1 year, 9 months ago bb814c4
Make paragraphRect origin always 0,0.

This convention should make it easier for the caller to properly place
the paragraph within a document.
M .golden/arabicFiller20em/golden => .golden/arabicFiller20em/golden +1 -1
@@ 1,4 1,4 @@
ParagraphLayout {paragraphRect = Rect {x_origin = 0, y_origin = -6000, x_size = 19439, y_size = 6000}, spanLayouts = [
ParagraphLayout {paragraphRect = Rect {x_origin = 0, y_origin = 0, x_size = 19439, y_size = -6000}, spanLayouts = [
    SpanLayout [Fragment {fragmentRect = Rect {x_origin = 0, y_origin = 0, x_size = 17430, y_size = -1500}, fragmentPen = (0,-1085), fragmentGlyphs =
        [(GlyphInfo {codepoint = 3, cluster = 80, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False},GlyphPos {x_advance = 236, y_advance = 0, x_offset = 0, y_offset = 0}),
        (GlyphInfo {codepoint = 535, cluster = 78, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False},GlyphPos {x_advance = 714, y_advance = 0, x_offset = 0, y_offset = 0}),

M .golden/czechHelloParagraph/golden => .golden/czechHelloParagraph/golden +1 -1
@@ 1,4 1,4 @@
ParagraphLayout {paragraphRect = Rect {x_origin = 0, y_origin = -1121, x_size = 5274, y_size = 1121}, spanLayouts = [
ParagraphLayout {paragraphRect = Rect {x_origin = 0, y_origin = 0, x_size = 5274, y_size = -1121}, spanLayouts = [
    SpanLayout [Fragment {fragmentRect = Rect {x_origin = 0, y_origin = 0, x_size = 5274, y_size = -1121}, fragmentPen = (0,-932), fragmentGlyphs =
        [(GlyphInfo {codepoint = 36, cluster = 5, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False},GlyphPos {x_advance = 663, y_advance = 0, x_offset = 0, y_offset = 0}),
        (GlyphInfo {codepoint = 75, cluster = 6, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False},GlyphPos {x_advance = 571, y_advance = 0, x_offset = 0, y_offset = 0}),

M .golden/czechHelloParagraphUltraNarrow/golden => .golden/czechHelloParagraphUltraNarrow/golden +1 -1
@@ 1,4 1,4 @@
ParagraphLayout {paragraphRect = Rect {x_origin = 0, y_origin = -13452, x_size = 663, y_size = 13452}, spanLayouts = [
ParagraphLayout {paragraphRect = Rect {x_origin = 0, y_origin = 0, x_size = 663, y_size = -13452}, spanLayouts = [
    SpanLayout [Fragment {fragmentRect = Rect {x_origin = 0, y_origin = 0, x_size = 663, y_size = -1121}, fragmentPen = (0,-932), fragmentGlyphs =
        [(GlyphInfo {codepoint = 36, cluster = 5, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False},GlyphPos {x_advance = 663, y_advance = 0, x_offset = 0, y_offset = 0})]
    }, Fragment {fragmentRect = Rect {x_origin = 0, y_origin = -1121, x_size = 571, y_size = -1121}, fragmentPen = (0,-932), fragmentGlyphs =

M .golden/lineHeightLarger/golden => .golden/lineHeightLarger/golden +1 -1
@@ 1,4 1,4 @@
ParagraphLayout {paragraphRect = Rect {x_origin = 0, y_origin = -1600, x_size = 522, y_size = 1600}, spanLayouts = [
ParagraphLayout {paragraphRect = Rect {x_origin = 0, y_origin = 0, x_size = 522, y_size = -1600}, spanLayouts = [
    SpanLayout [Fragment {fragmentRect = Rect {x_origin = 0, y_origin = 0, x_size = 522, y_size = -1600}, fragmentPen = (0,-1172), fragmentGlyphs =
        [(GlyphInfo {codepoint = 68, cluster = 3, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False},GlyphPos {x_advance = 522, y_advance = 0, x_offset = 0, y_offset = 0})]
    }]

M .golden/lineHeightNormal/golden => .golden/lineHeightNormal/golden +1 -1
@@ 1,4 1,4 @@
ParagraphLayout {paragraphRect = Rect {x_origin = 0, y_origin = -1121, x_size = 522, y_size = 1121}, spanLayouts = [
ParagraphLayout {paragraphRect = Rect {x_origin = 0, y_origin = 0, x_size = 522, y_size = -1121}, spanLayouts = [
    SpanLayout [Fragment {fragmentRect = Rect {x_origin = 0, y_origin = 0, x_size = 522, y_size = -1121}, fragmentPen = (0,-932), fragmentGlyphs =
        [(GlyphInfo {codepoint = 68, cluster = 3, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False},GlyphPos {x_advance = 522, y_advance = 0, x_offset = 0, y_offset = 0})]
    }]

M .golden/lineHeightSmaller/golden => .golden/lineHeightSmaller/golden +1 -1
@@ 1,4 1,4 @@
ParagraphLayout {paragraphRect = Rect {x_origin = 0, y_origin = -599, x_size = 522, y_size = 599}, spanLayouts = [
ParagraphLayout {paragraphRect = Rect {x_origin = 0, y_origin = 0, x_size = 522, y_size = -599}, spanLayouts = [
    SpanLayout [Fragment {fragmentRect = Rect {x_origin = 0, y_origin = 0, x_size = 522, y_size = -599}, fragmentPen = (0,-671), fragmentGlyphs =
        [(GlyphInfo {codepoint = 68, cluster = 3, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False},GlyphPos {x_advance = 522, y_advance = 0, x_offset = 0, y_offset = 0})]
    }]

M .golden/loremIpsum100em/golden => .golden/loremIpsum100em/golden +1 -1
@@ 1,4 1,4 @@
ParagraphLayout {paragraphRect = Rect {x_origin = 0, y_origin = -3363, x_size = 99185, y_size = 3363}, spanLayouts = [
ParagraphLayout {paragraphRect = Rect {x_origin = 0, y_origin = 0, x_size = 99185, y_size = -3363}, spanLayouts = [
    SpanLayout [Fragment {fragmentRect = Rect {x_origin = 0, y_origin = 0, x_size = 95643, y_size = -1121}, fragmentPen = (0,-932), fragmentGlyphs =
        [(GlyphInfo {codepoint = 47, cluster = 4, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False},GlyphPos {x_advance = 507, y_advance = 0, x_offset = 0, y_offset = 0}),
        (GlyphInfo {codepoint = 82, cluster = 5, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False},GlyphPos {x_advance = 590, y_advance = 0, x_offset = 0, y_offset = 0}),

M .golden/loremIpsum20em/golden => .golden/loremIpsum20em/golden +1 -1
@@ 1,4 1,4 @@
ParagraphLayout {paragraphRect = Rect {x_origin = 0, y_origin = -12331, x_size = 19525, y_size = 12331}, spanLayouts = [
ParagraphLayout {paragraphRect = Rect {x_origin = 0, y_origin = 0, x_size = 19525, y_size = -12331}, spanLayouts = [
    SpanLayout [Fragment {fragmentRect = Rect {x_origin = 0, y_origin = 0, x_size = 18541, y_size = -1121}, fragmentPen = (0,-932), fragmentGlyphs =
        [(GlyphInfo {codepoint = 47, cluster = 4, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False},GlyphPos {x_advance = 507, y_advance = 0, x_offset = 0, y_offset = 0}),
        (GlyphInfo {codepoint = 82, cluster = 5, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False},GlyphPos {x_advance = 590, y_advance = 0, x_offset = 0, y_offset = 0}),

M .golden/mixedLanguageLTRParagraph/golden => .golden/mixedLanguageLTRParagraph/golden +1 -1
@@ 1,4 1,4 @@
ParagraphLayout {paragraphRect = Rect {x_origin = 0, y_origin = -1121, x_size = 6113, y_size = 1121}, spanLayouts = [
ParagraphLayout {paragraphRect = Rect {x_origin = 0, y_origin = 0, x_size = 6113, y_size = -1121}, spanLayouts = [
    SpanLayout [Fragment {fragmentRect = Rect {x_origin = 0, y_origin = 0, x_size = 4837, y_size = -1121}, fragmentPen = (0,-932), fragmentGlyphs =
        [(GlyphInfo {codepoint = 77, cluster = 4, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False},GlyphPos {x_advance = 253, y_advance = 0, x_offset = 0, y_offset = 0}),
        (GlyphInfo {codepoint = 86, cluster = 5, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False},GlyphPos {x_advance = 446, y_advance = 0, x_offset = 0, y_offset = 0}),

M .golden/mixedScriptWordsParagraph/golden => .golden/mixedScriptWordsParagraph/golden +1 -1
@@ 1,4 1,4 @@
ParagraphLayout {paragraphRect = Rect {x_origin = 0, y_origin = -6726, x_size = 5678, y_size = 6726}, spanLayouts = [
ParagraphLayout {paragraphRect = Rect {x_origin = 0, y_origin = 0, x_size = 5678, y_size = -6726}, spanLayouts = [
    SpanLayout [Fragment {fragmentRect = Rect {x_origin = 0, y_origin = 0, x_size = 777, y_size = -1121}, fragmentPen = (0,-932), fragmentGlyphs =
        [(GlyphInfo {codepoint = 77, cluster = 7, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False},GlyphPos {x_advance = 262, y_advance = 0, x_offset = 0, y_offset = 0}),
        (GlyphInfo {codepoint = 77, cluster = 8, unsafeToBreak = False, unsafeToConcat = False, safeToInsertTatweel = False},GlyphPos {x_advance = 262, y_advance = 0, x_offset = 0, y_offset = 0}),

M src/Data/Text/ParagraphLayout/Rect.hs => src/Data/Text/ParagraphLayout/Rect.hs +9 -8
@@ 53,15 53,16 @@ y_max r = y_origin r `max` y_terminus r
-- rectangles.
--
-- The origin of the resulting rectangle will be the corner with the lowest
-- X and Y coordinates, regardless of the origin of the input rectangles.
-- X coordinate and the highest Y coordinate, regardless of the origin of the
-- input rectangles.
union :: (Num a, Ord a) => Rect a -> Rect a -> Rect a
union a b = Rect x1 y1 dx dy where
    x1 = x_min a `min` x_min b
    y1 = y_min a `min` y_min b
    x2 = x_max a `max` x_max b
    y2 = y_max a `max` y_max b
    dx = x2 - x1
    dy = y2 - y1
union a b = Rect x_low y_high dx (-dy) where
    x_low = x_min a `min` x_min b
    y_low = y_min a `min` y_min b
    x_high = x_max a `max` x_max b
    y_high = y_max a `max` y_max b
    dx = x_high - x_low
    dy = y_high - y_low

instance (Num a, Ord a) => Semigroup (Rect a) where
    (<>) = union

M test/Data/Text/ParagraphLayout/RectSpec.hs => test/Data/Text/ParagraphLayout/RectSpec.hs +12 -12
@@ 6,24 6,24 @@ import Test.Hspec
import Data.Text.ParagraphLayout.Rect

positiveRect :: Rect Int32
positiveRect = Rect 50 60 10 10
positiveRect = Rect 50 (-70) 10 10

negativeRect :: Rect Int32
negativeRect = Rect 80 90 (-15) (-15)
negativeRect = Rect 80 (-75) (-15) (-15)

spec :: Spec
spec = do
    describe "union of two rects" $ do
        let r = union positiveRect negativeRect
        it "has origin at 50,60" $
            (x_origin r, y_origin r) `shouldBe` (50, 60)
        it "has minimum coordinates at at 50,60" $
            (x_min r, y_min r) `shouldBe` (50, 60)
        it "has terminus at 80,90" $
            (x_terminus r, y_terminus r) `shouldBe` (80, 90)
        it "has maximum coordinates at 80,90" $
            (x_max r, y_max r) `shouldBe` (80, 90)
        it "has size 30,30" $
            (x_size r, y_size r) `shouldBe` (30, 30)
        it "has origin at 50,-60" $
            (x_origin r, y_origin r) `shouldBe` (50, -60)
        it "has minimum coordinates at at 50,-90" $
            (x_min r, y_min r) `shouldBe` (50, -90)
        it "has terminus at 80,-90" $
            (x_terminus r, y_terminus r) `shouldBe` (80, -90)
        it "has maximum coordinates at 80,-60" $
            (x_max r, y_max r) `shouldBe` (80, -60)
        it "has size 30,-30" $
            (x_size r, y_size r) `shouldBe` (30, -30)
        it "has absolute size 30,30" $
            (width r, height r) `shouldBe` (30, 30)