{-# LANGUAGE OverloadedStrings #-}
{-
Copyright (C) 2014 Matthew Pickering <matthewtpickering@gmail.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-}

{- |
   Module      : Text.TeXMath.Unicode.Fonts
   Copyright   : Copyright (C) 2014 Matthew Pickering
   License     : GNU GPL, version 2 or above

   Maintainer  : Matthew Pickering <matthewtpickering@gmail.com>
   Stability   : alpha
   Portability : portable

Utilities to convert between MS font codepoints and unicode characters.
-}
module Text.TeXMath.Unicode.Fonts (getUnicode, Font(..), textToFont) where
import qualified Data.Map as M
import qualified Data.Text as T

-- | Enumeration of recognised fonts
data Font = Symbol -- ^ <http://en.wikipedia.org/wiki/Symbol_(typeface) Adobe Symbol>
          deriving (Int -> Font -> ShowS
[Font] -> ShowS
Font -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Font] -> ShowS
$cshowList :: [Font] -> ShowS
show :: Font -> String
$cshow :: Font -> String
showsPrec :: Int -> Font -> ShowS
$cshowsPrec :: Int -> Font -> ShowS
Show, Font -> Font -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Font -> Font -> Bool
$c/= :: Font -> Font -> Bool
== :: Font -> Font -> Bool
$c== :: Font -> Font -> Bool
Eq)

-- | Parse font name into Font if possible.
textToFont :: T.Text -> Maybe Font
textToFont :: Text -> Maybe Font
textToFont Text
"Symbol" = forall a. a -> Maybe a
Just Font
Symbol
textToFont Text
_ = forall a. Maybe a
Nothing

-- | Given a font and codepoint, returns the corresponding unicode
-- character
getUnicode :: Font -> Char -> Maybe Char
getUnicode :: Font -> Char -> Maybe Char
getUnicode Font
Symbol Char
c = forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Char
c Map Char Char
symbol

-- Generated from lib/fonts/symbol.txt
symbol :: M.Map Char Char
symbol :: Map Char Char
symbol = forall k a. Ord k => [(k, a)] -> Map k a
M.fromList
  [ (Char
' ',Char
' ')
  , (Char
' ',Char
'\160')
  , (Char
'!',Char
'!')
  , (Char
'"',Char
'\8704')
  , (Char
'#',Char
'#')
  , (Char
'$',Char
'\8707')
  , (Char
'%',Char
'%')
  , (Char
'&',Char
'&')
  , (Char
'\'',Char
'\8715')
  , (Char
'(',Char
'(')
  , (Char
')',Char
')')
  , (Char
'*',Char
'\8727')
  , (Char
'+',Char
'+')
  , (Char
',',Char
',')
  , (Char
'-',Char
'\8722')
  , (Char
'.',Char
'.')
  , (Char
'/',Char
'/')
  , (Char
'0',Char
'0')
  , (Char
'1',Char
'1')
  , (Char
'2',Char
'2')
  , (Char
'3',Char
'3')
  , (Char
'4',Char
'4')
  , (Char
'5',Char
'5')
  , (Char
'6',Char
'6')
  , (Char
'7',Char
'7')
  , (Char
'8',Char
'8')
  , (Char
'9',Char
'9')
  , (Char
':',Char
':')
  , (Char
';',Char
';')
  , (Char
'<',Char
'<')
  , (Char
'=',Char
'=')
  , (Char
'>',Char
'>')
  , (Char
'?',Char
'?')
  , (Char
'@',Char
'\8773')
  , (Char
'A',Char
'\913')
  , (Char
'B',Char
'\914')
  , (Char
'C',Char
'\935')
  , (Char
'D',Char
'\916')
  , (Char
'D',Char
'\8710')
  , (Char
'E',Char
'\917')
  , (Char
'F',Char
'\934')
  , (Char
'G',Char
'\915')
  , (Char
'H',Char
'\919')
  , (Char
'I',Char
'\921')
  , (Char
'J',Char
'\977')
  , (Char
'K',Char
'\922')
  , (Char
'L',Char
'\923')
  , (Char
'M',Char
'\924')
  , (Char
'N',Char
'\925')
  , (Char
'O',Char
'\927')
  , (Char
'P',Char
'\928')
  , (Char
'Q',Char
'\920')
  , (Char
'R',Char
'\929')
  , (Char
'S',Char
'\931')
  , (Char
'T',Char
'\932')
  , (Char
'U',Char
'\933')
  , (Char
'V',Char
'\962')
  , (Char
'W',Char
'\937')
  , (Char
'W',Char
'\8486')
  , (Char
'X',Char
'\926')
  , (Char
'Y',Char
'\936')
  , (Char
'Z',Char
'\918')
  , (Char
'[',Char
'[')
  , (Char
'\\',Char
'\8756')
  , (Char
']',Char
']')
  , (Char
'^',Char
'\8869')
  , (Char
'_',Char
'_')
  , (Char
'`',Char
'\63717')
  , (Char
'a',Char
'\945')
  , (Char
'b',Char
'\946')
  , (Char
'c',Char
'\967')
  , (Char
'd',Char
'\948')
  , (Char
'e',Char
'\949')
  , (Char
'f',Char
'\966')
  , (Char
'g',Char
'\947')
  , (Char
'h',Char
'\951')
  , (Char
'i',Char
'\953')
  , (Char
'j',Char
'\981')
  , (Char
'k',Char
'\954')
  , (Char
'l',Char
'\955')
  , (Char
'm',Char
'\181')
  , (Char
'm',Char
'\956')
  , (Char
'n',Char
'\957')
  , (Char
'o',Char
'\959')
  , (Char
'p',Char
'\960')
  , (Char
'q',Char
'\952')
  , (Char
'r',Char
'\961')
  , (Char
's',Char
'\963')
  , (Char
't',Char
'\964')
  , (Char
'u',Char
'\965')
  , (Char
'v',Char
'\982')
  , (Char
'w',Char
'\969')
  , (Char
'x',Char
'\958')
  , (Char
'y',Char
'\968')
  , (Char
'z',Char
'\950')
  , (Char
'{',Char
'{')
  , (Char
'|',Char
'|')
  , (Char
'}',Char
'}')
  , (Char
'~',Char
'\8764')
  , (Char
'\160',Char
'\8364')
  , (Char
'\161',Char
'\978')
  , (Char
'\162',Char
'\8242')
  , (Char
'\163',Char
'\8804')
  , (Char
'\164',Char
'\8260')
  , (Char
'\164',Char
'\8725')
  , (Char
'\165',Char
'\8734')
  , (Char
'\166',Char
'\402')
  , (Char
'\167',Char
'\9827')
  , (Char
'\168',Char
'\9830')
  , (Char
'\169',Char
'\9829')
  , (Char
'\170',Char
'\9824')
  , (Char
'\171',Char
'\8596')
  , (Char
'\172',Char
'\8592')
  , (Char
'\173',Char
'\8593')
  , (Char
'\174',Char
'\8594')
  , (Char
'\175',Char
'\8595')
  , (Char
'\176',Char
'\176')
  , (Char
'\177',Char
'\177')
  , (Char
'\178',Char
'\8243')
  , (Char
'\179',Char
'\8805')
  , (Char
'\180',Char
'\215')
  , (Char
'\181',Char
'\8733')
  , (Char
'\182',Char
'\8706')
  , (Char
'\183',Char
'\8226')
  , (Char
'\184',Char
'\247')
  , (Char
'\185',Char
'\8800')
  , (Char
'\186',Char
'\8801')
  , (Char
'\187',Char
'\8776')
  , (Char
'\188',Char
'\8230')
  , (Char
'\189',Char
'\63718')
  , (Char
'\190',Char
'\63719')
  , (Char
'\191',Char
'\8629')
  , (Char
'\192',Char
'\8501')
  , (Char
'\193',Char
'\8465')
  , (Char
'\194',Char
'\8476')
  , (Char
'\195',Char
'\8472')
  , (Char
'\196',Char
'\8855')
  , (Char
'\197',Char
'\8853')
  , (Char
'\198',Char
'\8709')
  , (Char
'\199',Char
'\8745')
  , (Char
'\200',Char
'\8746')
  , (Char
'\201',Char
'\8835')
  , (Char
'\202',Char
'\8839')
  , (Char
'\203',Char
'\8836')
  , (Char
'\204',Char
'\8834')
  , (Char
'\205',Char
'\8838')
  , (Char
'\206',Char
'\8712')
  , (Char
'\207',Char
'\8713')
  , (Char
'\208',Char
'\8736')
  , (Char
'\209',Char
'\8711')
  , (Char
'\210',Char
'\63194')
  , (Char
'\211',Char
'\63193')
  , (Char
'\212',Char
'\63195')
  , (Char
'\213',Char
'\8719')
  , (Char
'\214',Char
'\8730')
  , (Char
'\215',Char
'\8901')
  , (Char
'\216',Char
'\172')
  , (Char
'\217',Char
'\8743')
  , (Char
'\218',Char
'\8744')
  , (Char
'\219',Char
'\8660')
  , (Char
'\220',Char
'\8656')
  , (Char
'\221',Char
'\8657')
  , (Char
'\222',Char
'\8658')
  , (Char
'\223',Char
'\8659')
  , (Char
'\224',Char
'\9674')
  , (Char
'\225',Char
'\9001')
  , (Char
'\226',Char
'\63720')
  , (Char
'\227',Char
'\63721')
  , (Char
'\228',Char
'\63722')
  , (Char
'\229',Char
'\8721')
  , (Char
'\230',Char
'\63723')
  , (Char
'\231',Char
'\63724')
  , (Char
'\232',Char
'\63725')
  , (Char
'\233',Char
'\63726')
  , (Char
'\234',Char
'\63727')
  , (Char
'\235',Char
'\63728')
  , (Char
'\236',Char
'\63729')
  , (Char
'\237',Char
'\63730')
  , (Char
'\238',Char
'\63731')
  , (Char
'\239',Char
'\63732')
  , (Char
'\241',Char
'\9002')
  , (Char
'\242',Char
'\8747')
  , (Char
'\243',Char
'\8992')
  , (Char
'\244',Char
'\63733')
  , (Char
'\245',Char
'\8993')
  , (Char
'\246',Char
'\63734')
  , (Char
'\247',Char
'\63735')
  , (Char
'\248',Char
'\63736')
  , (Char
'\249',Char
'\63737')
  , (Char
'\250',Char
'\63738')
  , (Char
'\251',Char
'\63739')
  , (Char
'\252',Char
'\63740')
  , (Char
'\253',Char
'\63741')
  , (Char
'\254',Char
'\63742')]