From 5284d48e30e967eb10ab157b8616c191c3fe01e8 Mon Sep 17 00:00:00 2001 From: Jaro Date: Tue, 18 Apr 2023 08:14:57 +0200 Subject: [PATCH] Prepare for test modules sharing font options. --- test/Data/Text/ParagraphLayout/FontLoader.hs | 25 +++++++++++++++++++- test/Data/Text/ParagraphLayoutSpec.hs | 23 +----------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/test/Data/Text/ParagraphLayout/FontLoader.hs b/test/Data/Text/ParagraphLayout/FontLoader.hs index bfd24ed..3dbb4cb 100644 --- a/test/Data/Text/ParagraphLayout/FontLoader.hs +++ b/test/Data/Text/ParagraphLayout/FontLoader.hs @@ -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) +} diff --git a/test/Data/Text/ParagraphLayoutSpec.hs b/test/Data/Text/ParagraphLayoutSpec.hs index d3a135d..8ab1b46 100644 --- a/test/Data/Text/ParagraphLayoutSpec.hs +++ b/test/Data/Text/ParagraphLayoutSpec.hs @@ -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 :: -- 2.30.2