~jaro/balkon

5284d48e30e967eb10ab157b8616c191c3fe01e8 — Jaro 1 year, 6 months ago 123c047
Prepare for test modules sharing font options.
2 files changed, 25 insertions(+), 23 deletions(-)

M test/Data/Text/ParagraphLayout/FontLoader.hs
M test/Data/Text/ParagraphLayoutSpec.hs
M test/Data/Text/ParagraphLayout/FontLoader.hs => test/Data/Text/ParagraphLayout/FontLoader.hs +24 -1
@@ 4,21 4,26 @@ module Data.Text.ParagraphLayout.FontLoader
    , latinFont
    , loadFont
    , writeFontInfo
    , testingOptions
    , demoOptions
    )
where

import Data.ByteString (readFile)
import Data.List (concat, (++))
import Data.Maybe (Maybe (Just))
import Data.Text.Glyphize
    ( Font
    , FontOptions
    , FontOptions (optionPPEm, optionScale)
    , createFace
    , createFontWithOptions
    , defaultFontOptions
    , faceIndex
    , fontFace
    , fontPPEm
    , fontScale
    )

import Data.Word (Word)
import Prelude (return, show, ($))
import System.FilePath (FilePath, (</>))


@@ 52,3 57,21 @@ writeFontInfo outputPath fontPath font = writeFile outputPath info
        pixelSize = let (x, y) = fontPPEm font in (show x) ++ "," ++ (show y)
        scale = let (x, y) = fontScale font in (show x) ++ "," ++ (show y)
        face = fontFace font

-- | Font options to be used for high precision testing (1000 units per EM).
-- Hinting should behave as if the font size were 24px.
-- TODO: Test hinting.
testingOptions :: FontOptions
testingOptions = defaultFontOptions {
    optionPPEm = Just (24, 24),
    optionScale = Just (1000, 1000)
}

-- | 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.
demoOptions :: FontOptions
demoOptions = defaultFontOptions {
    optionPPEm = Just (32, 32),
    optionScale = Just (32, 32)
}

M test/Data/Text/ParagraphLayoutSpec.hs => test/Data/Text/ParagraphLayoutSpec.hs +1 -22
@@ 1,10 1,6 @@
module Data.Text.ParagraphLayoutSpec (spec) where

import Data.Text.Glyphize
    ( Font
    , FontOptions (optionPPEm, optionScale)
    , defaultFontOptions
    )
import Data.Text.Glyphize (Font)

import Test.Hspec
import Test.Hspec.Golden


@@ 197,23 193,6 @@ emptyLayout = ParagraphLayout (Rect 0 0 0 0) []
emptySpanLayout :: ParagraphLayout
emptySpanLayout = ParagraphLayout (Rect 0 0 0 0) [SpanLayout []]

-- Test primarily with a high level of detail (1000 units per EM).
-- Hinting should behave as if the font size were 24px.
-- TODO: Test hinting.
testingOptions :: FontOptions
testingOptions = defaultFontOptions {
    optionPPEm = Just (24, 24),
    optionScale = Just (1000, 1000)
}

-- For the demo, use a 32px font size with exactly one scale unit per pixel.
-- This makes 20em equal 640px, which is the width of the demo window.
demoOptions :: FontOptions
demoOptions = defaultFontOptions {
    optionPPEm = Just (32, 32),
    optionScale = Just (32, 32)
}

-- | Test shaped runs against an expected value, and write metadata about the
-- used font afterwards.
shapedRunsSpecWithFont ::