Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give the test component a dependency on base #5

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions Opentype/Fileformat/Cmap.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import Opentype.Fileformat.Types
import Data.Binary
import Data.Binary.Put
import Data.List (sort, mapAccumL, foldl')
import Data.Either (either)
import Control.Monad
import Data.Traversable (for)
import Data.Foldable (for_, traverse_)
Expand Down Expand Up @@ -135,7 +134,7 @@ readCmapTable :: Strict.ByteString -> Either String CmapTable
readCmapTable bs = do
version <- index16 bs 0
when (version /= 0) $
fail "unsupported cmap version."
Left "unsupported cmap version."
n <- index16 bs 1
entries <- for [0..n-1] $ \i -> do
pfID <- toPf =<< (index16 bs $ 2 + i*4)
Expand Down Expand Up @@ -166,16 +165,15 @@ readCmap bs_ = do
c <- index16 bs_ 0
let bs | (c >= 8 && c < 14) = Strict.drop 8 bs_
| otherwise = Strict.drop 4 bs_
either fail return $
case c of
0 -> getMap0 bs
2 -> getMap2 bs
4 -> getMap4 bs
6 -> getMap6 bs
8 -> getMap8 bs
10 -> getMap10 bs
12 -> getMap12 bs
i -> fail $ "unsupported map encoding " ++ show i
case c of
0 -> getMap0 bs
2 -> getMap2 bs
4 -> getMap4 bs
6 -> getMap6 bs
8 -> getMap8 bs
10 -> getMap10 bs
12 -> getMap12 bs
i -> Left $ "unsupported map encoding " ++ show i

subIntMap :: Word32 -> Word32 -> WordMap GlyphID -> WordMap GlyphID
subIntMap from to intMap =
Expand Down Expand Up @@ -259,7 +257,7 @@ putMap2 cmap = do
(fromIntegral hb `shift` 8 .|. 0xff) $
glyphMap cmap
(fstCode, lstCode)
| M.null subMap = (0, -1)
| M.null subMap = (0, maxBound)
| otherwise = (fst $ M.findMin subMap,
fst $ M.findMax subMap)
ec = lstCode - fstCode + 1
Expand Down
6 changes: 3 additions & 3 deletions Opentype/Fileformat/Name.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ putNameTable (NameTable records_) = do
readNameTable :: Strict.ByteString -> Either String NameTable
readNameTable bs = do
version <- index16 bs 0
when (version > 0) $ fail "Unsupported name table format."
when (version > 0) $ Left "Unsupported name table format."
len <- index16 bs 1
storage <- index16 bs 2
records <- for [0..len-1] $ \i -> do
Expand All @@ -97,8 +97,8 @@ readNameTable bs = do
Right (offset, len2, NameRecord pf enc lang nID)
records2 <- for records $
\(offset, len2, r) ->
if storage+offset+len2 > fromIntegral (Strict.length bs)
then Left "string storage bounds exceeded"
if fromIntegral (storage+offset+len2) > Strict.length bs
then Left $ "overflow error: name record in storage at (" <> show storage <> ") at offset (" <> show offset <> ") with length (" <> show len2 <> ") exceeds input length (" <> show (Strict.length bs) <> ")"
else Right $ r (Strict.take (fromIntegral len2) $
Strict.drop (fromIntegral $ offset+storage) bs)
return $ NameTable records2
1 change: 1 addition & 0 deletions opentype.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ test-suite test
main-is: test.hs
buildable: True
hs-source-dirs: tests
build-depends: base
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only change from this particular PR.