-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | A true type file format loader
--   
--   A haskell Truetype file parser.
--   
--   You can load a font file and extract some curves to be drawed with a
--   library like Rasterific .
@package FontyFruity
@version 0.5.3.4


-- | This module provide internal access to many structure, not exported by
--   default. The stability of this module is absolutely not insured.
module Graphics.Text.TrueType.Internal

-- | Type representing a font.
data Font
Font :: !OffsetTable -> ![(ByteString, ByteString)] -> Maybe NameTable -> Maybe FontHeader -> Maybe MaxpTable -> Maybe CharacterMaps -> Maybe (Vector Glyph) -> Maybe (Vector Word32) -> Maybe HorizontalHeader -> Maybe HorizontalMetricsTable -> Font

-- | Field discribing various offsets/positions of table inside the font
--   file. Not available for reading.
[_fontOffsetTable] :: Font -> !OffsetTable
[_fontTables] :: Font -> ![(ByteString, ByteString)]
[_fontNames] :: Font -> Maybe NameTable
[_fontHeader] :: Font -> Maybe FontHeader
[_fontMaxp] :: Font -> Maybe MaxpTable
[_fontMap] :: Font -> Maybe CharacterMaps
[_fontGlyph] :: Font -> Maybe (Vector Glyph)
[_fontLoca] :: Font -> Maybe (Vector Word32)
[_fontHorizontalHeader] :: Font -> Maybe HorizontalHeader
[_fontHorizontalMetrics] :: Font -> Maybe HorizontalMetricsTable

-- | Font header
data FontHeader
FontHeader :: !Fixed -> !Fixed -> !Word32 -> !Word32 -> !HeaderFlags -> !Word16 -> !Word64 -> !Word64 -> !FWord -> !FWord -> !FWord -> !FWord -> !FontStyle -> !Word16 -> !Int16 -> !Int16 -> !Int16 -> FontHeader

-- | Table version number 0x00010000 for version 1.0.
[_fHdrVersionNumber] :: FontHeader -> !Fixed

-- | fontRevision Set by font manufacturer.
[_fHdrFontRevision] :: FontHeader -> !Fixed

-- | To compute: set it to 0, sum the entire font as ULONG, then store
--   0xB1B0AFBA - sum.
[_fHdrChecksumAdjust] :: FontHeader -> !Word32

-- | Should be equal to 0x5F0F3CF5.
[_fHdrMagicNumber] :: FontHeader -> !Word32
[_fHdrFlags] :: FontHeader -> !HeaderFlags

-- | Valid range is from 16 to 16384
[_fUnitsPerEm] :: FontHeader -> !Word16

-- | International date (8-byte field).
[_fHdrCreateTime] :: FontHeader -> !Word64

-- | International date (8-byte field).
[_fHdrModificationTime] :: FontHeader -> !Word64

-- | For all glyph bounding boxes.
[_fHdrxMin] :: FontHeader -> !FWord

-- | For all glyph bounding boxes.
[_fHdrYMin] :: FontHeader -> !FWord

-- | For all glyph bounding boxes.
[_fHdrXMax] :: FontHeader -> !FWord

-- | For all glyph bounding boxes.
[_fHdrYMax] :: FontHeader -> !FWord

-- | Bit 0 bold (if set to 1); Bit 1 italic (if set to 1)
[_fHdrMacStyle] :: FontHeader -> !FontStyle

-- | Smallest readable size in pixels.
[_fHdrLowestRecPPEM] :: FontHeader -> !Word16

-- | 0 Fully mixed directional glyphs; 1 Only strongly left to right; 2
--   Like 1 but also contains neutrals ; -1 Only strongly right to left; -2
--   Like -1 but also contains neutrals.
[_fHdrFontDirectionHint] :: FontHeader -> !Int16

-- | 0 for short offsets, 1 for long.
[_fHdrIndexToLocFormat] :: FontHeader -> !Int16

-- | 0 for current format.
[_fHdrGlyphDataFormat] :: FontHeader -> !Int16

-- | Header flags.
data HeaderFlags
HeaderFlags :: !Bool -> !Bool -> !Bool -> !Bool -> !Bool -> HeaderFlags

-- | Bit 0 - baseline for font at y=0;
[_hfBaselineY0] :: HeaderFlags -> !Bool

-- | Bit 1 - left sidebearing at x=0;
[_hfLeftSideBearing] :: HeaderFlags -> !Bool

-- | Bit 2 - instructions may depend on point size;
[_hfInstrDependPointSize] :: HeaderFlags -> !Bool

-- | Bit 3 - force ppem to integer values for all internal scaler math; may
--   use fractional ppem sizes if this bit is clear;
[_hfForcePPEM] :: HeaderFlags -> !Bool

-- | Bit 4 - instructions may alter advance width (the advance widths might
--   not scale linearly);
[_hfAlterAdvance] :: HeaderFlags -> !Bool

-- | Describe the "hhea" TrueType table.
data HorizontalHeader
HorizontalHeader :: {-# UNPACK #-} !FWord -> {-# UNPACK #-} !FWord -> {-# UNPACK #-} !FWord -> {-# UNPACK #-} !FWord -> {-# UNPACK #-} !FWord -> {-# UNPACK #-} !FWord -> {-# UNPACK #-} !FWord -> {-# UNPACK #-} !Int16 -> {-# UNPACK #-} !Int16 -> {-# UNPACK #-} !FWord -> {-# UNPACK #-} !Int16 -> {-# UNPACK #-} !Word16 -> HorizontalHeader

-- | Distance from baseline of highest ascender
[_hheaAscent] :: HorizontalHeader -> {-# UNPACK #-} !FWord

-- | Distance from baseline of lowest descender
[_hheaDescent] :: HorizontalHeader -> {-# UNPACK #-} !FWord

-- | typographic line gap
[_hheaLineGap] :: HorizontalHeader -> {-# UNPACK #-} !FWord

-- | must be consistent with horizontal metrics
[_hheaAdvanceWidthMax] :: HorizontalHeader -> {-# UNPACK #-} !FWord

-- | must be consistent with horizontal metrics
[_hheaMinLeftSideBearing] :: HorizontalHeader -> {-# UNPACK #-} !FWord

-- | must be consistent with horizontal metrics
[_hheaMinRightSideBearing] :: HorizontalHeader -> {-# UNPACK #-} !FWord

-- | max(lsb + (xMax-xMin))
[_hheaXmaxExtent] :: HorizontalHeader -> {-# UNPACK #-} !FWord

-- | used to calculate the slope of the caret (rise/run) set to 1 for
--   vertical caret
[_hheaCaretSlopeRise] :: HorizontalHeader -> {-# UNPACK #-} !Int16

-- | 0 for vertical
[_hheaCaretSlopeRun] :: HorizontalHeader -> {-# UNPACK #-} !Int16

-- | set value to 0 for non-slanted fonts
[_hheaCaretOffset] :: HorizontalHeader -> {-# UNPACK #-} !FWord

-- | 0 for current format
[_hheaMetricDataFormat] :: HorizontalHeader -> {-# UNPACK #-} !Int16

-- | number of advance widths in metrics table
[_hheaLongHorMetricCount] :: HorizontalHeader -> {-# UNPACK #-} !Word16

-- | Information of horizontal advance.
data HorizontalMetric
HorizontalMetric :: {-# UNPACK #-} !Word16 -> {-# UNPACK #-} !Int16 -> HorizontalMetric
[_hmtxAdvanceWidth] :: HorizontalMetric -> {-# UNPACK #-} !Word16
[_hmtxLeftSideBearing] :: HorizontalMetric -> {-# UNPACK #-} !Int16

-- | For every glyph (indexed by the glyph index), provide horizontal
--   information.
data HorizontalMetricsTable
HorizontalMetricsTable :: !Vector HorizontalMetric -> HorizontalMetricsTable
[_glyphMetrics] :: HorizontalMetricsTable -> !Vector HorizontalMetric
data MaxpTable
MaxpTable :: !Fixed -> !Word16 -> !Word16 -> !Word16 -> !Word16 -> !Word16 -> !Word16 -> !Word16 -> !Word16 -> !Word16 -> !Word16 -> !Word16 -> !Word16 -> !Word16 -> !Word16 -> MaxpTable

-- | version number 0x00010000 for version 1.0.
[_maxpTableVersion] :: MaxpTable -> !Fixed

-- | The number of glyphs in the font.
[_maxpnumGlyphs] :: MaxpTable -> !Word16

-- | Maximum points in a non-composite glyph.
[_maxpmaxPoints] :: MaxpTable -> !Word16

-- | Maximum contours in a non-composite glyph.
[_maxpmaxContours] :: MaxpTable -> !Word16

-- | Maximum points in a composite glyph.
[_maxpmaxCompositePoints] :: MaxpTable -> !Word16

-- | Maximum contours in a composite glyph.
[_maxpmaxCompositeContours] :: MaxpTable -> !Word16

-- | 1 if instructions do not use the twilight zone (Z0), or 2 if
--   instructions do use Z0; should be set to 2 in most cases.
[_maxpmaxZones] :: MaxpTable -> !Word16

-- | Maximum points used in Z0.
[_maxpmaxTwilightPoints] :: MaxpTable -> !Word16

-- | Number of Storage Area locations.
[_maxpmaxStorage] :: MaxpTable -> !Word16

-- | Number of FDEFs.
[_maxpmaxFunctionDefs] :: MaxpTable -> !Word16

-- | Number of IDEFs.
[_maxpmaxInstructionDefs] :: MaxpTable -> !Word16

-- | Maximum stack depth .
[_maxpmaxStackElements] :: MaxpTable -> !Word16

-- | Maximum byte count for glyph instructions.
[_maxpmaxSizeOfInstructions] :: MaxpTable -> !Word16

-- | Maximum number of components referenced at "top level" for any
--   composite glyph.
[_maxpmaxComponentElements] :: MaxpTable -> !Word16

-- | Maximum levels of recursion; 1 for simple components.
[_maxpmaxComponentDepth] :: MaxpTable -> !Word16
newtype FWord
FWord :: Word16 -> FWord
data Fixed
Fixed :: Word16 -> Word16 -> Fixed


-- | Module in charge of loading fonts.
module Graphics.Text.TrueType

-- | Decode a in-memory true type file.
decodeFont :: ByteString -> Either String Font

-- | Load a font file, the file path must be pointing to the true type file
--   (.ttf)
loadFontFile :: FilePath -> IO (Either String Font)

-- | Extract a list of outlines for every char in the string. The given
--   curves are in an image like coordinate system, with the origin point
--   in the upper left corner.
getStringCurveAtPoint :: Dpi -> (Float, Float) -> [(Font, PointSize, String)] -> [[Vector (Float, Float)]]

-- | Return the number of pixels relative to the point size.
unitsPerEm :: Font -> Word16

-- | True if the character is not present in the font, therefore it will
--   appear as a placeholder in renderings.
isPlaceholder :: Font -> Char -> Bool

-- | Retrive the glyph contours and associated transformations. The
--   coordinate system is assumed to be the TTF one (y upward). No
--   transformation is performed.
getCharacterGlyphsAndMetrics :: Font -> Char -> (Float, Vector RawGlyph)

-- | This function return the list of all contour for all char with the
--   given font in a string. All glyph are at the same position, they are
--   not placed like with <a>getStringCurveAtPoint</a>. It is a function
--   helpful to extract the glyph geometry for further external
--   manipulation.
getGlyphForStrings :: Dpi -> [(Font, PointSize, String)] -> [[Vector (Float, Float)]]

-- | Compute the bounding box of a string displayed with a font at a given
--   size. The resulting coordinate represent the width and the height in
--   pixels.
stringBoundingBox :: Font -> Dpi -> PointSize -> String -> BoundingBox

-- | This function will scan the system's font folder to find a font with
--   the desired properties. Favor using a FontCache to speed up the lookup
--   process.
findFontOfFamily :: String -> FontStyle -> IO (Maybe FilePath)
pointInPixelAtDpi :: PointSize -> Dpi -> Float
pixelSizeInPointAtDpi :: Float -> Dpi -> PointSize

-- | A font cache is a cache listing all the found fonts on the system,
--   allowing faster font lookup once created
--   
--   FontCache is an instance of binary, to get okish performance you
--   should save it in a file somewhere instead of rebuilding it everytime!
--   
--   The font cache is dependent on the version of rasterific, you must
--   rebuild it for every version.
data FontCache

-- | A font descriptor is a key used to find a font in a font cache.
data FontDescriptor
FontDescriptor :: !Text -> !FontStyle -> FontDescriptor

-- | The family name of the font
[_descriptorFamilyName] :: FontDescriptor -> !Text

-- | The desired style
[_descriptorStyle] :: FontDescriptor -> !FontStyle

-- | Font cache with no pre-existing fonts in it.
emptyFontCache :: FontCache

-- | Try to find a font with the given properties in the font cache.
findFontInCache :: FontCache -> FontDescriptor -> Maybe FilePath

-- | This function will search in the system for truetype files and index
--   them in a cache for further fast search.
buildCache :: IO FontCache

-- | Returns a list of descriptors of fonts stored in the given cache.
enumerateFonts :: FontCache -> [FontDescriptor]

-- | If possible, returns a descriptor of the Font.
descriptorOf :: Font -> Maybe FontDescriptor

-- | Type representing a font.
data Font

-- | Describe the basic stylistic properties of a font.
data FontStyle
FontStyle :: !Bool -> !Bool -> FontStyle

-- | If the font is bold.
[_fontStyleBold] :: FontStyle -> !Bool

-- | If the font is italic.
[_fontStyleItalic] :: FontStyle -> !Bool

-- | This type represent unscaled glyph information, everything is still in
--   its raw form.
data RawGlyph
RawGlyph :: ![CompositeScaling] -> !Int -> ![Vector (Int16, Int16)] -> RawGlyph

-- | List of transformations to apply to the contour in order to get their
--   correct placement.
[_rawGlyphCompositionScale] :: RawGlyph -> ![CompositeScaling]

-- | Glyph index in the current font.
[_rawGlyphIndex] :: RawGlyph -> !Int

-- | Real Geometry of glyph, each vector contain one contour.
[_rawGlyphContour] :: RawGlyph -> ![Vector (Int16, Int16)]

-- | Express device resolution in dot per inch.
type Dpi = Int

-- | Font size expressed in points. You must convert size expressed in
--   pixels to point using the DPI information. See pixelSizeInPointAtDpi
newtype PointSize
PointSize :: Float -> PointSize
[getPointSize] :: PointSize -> Float

-- | Transformation matrix used to transform composite glyph
--   
--   <pre>
--   | a b |
--   | c d |
--   </pre>
data CompositeScaling
CompositeScaling :: {-# UNPACK #-} !Int16 -> {-# UNPACK #-} !Int16 -> {-# UNPACK #-} !Int16 -> {-# UNPACK #-} !Int16 -> CompositeScaling

-- | a coeff.
[_a] :: CompositeScaling -> {-# UNPACK #-} !Int16

-- | b coeff.
[_b] :: CompositeScaling -> {-# UNPACK #-} !Int16

-- | c coeff.
[_c] :: CompositeScaling -> {-# UNPACK #-} !Int16

-- | d coeff.
[_d] :: CompositeScaling -> {-# UNPACK #-} !Int16

-- | String bounding box. with value for min/max.
data BoundingBox
BoundingBox :: {-# UNPACK #-} !Float -> {-# UNPACK #-} !Float -> {-# UNPACK #-} !Float -> {-# UNPACK #-} !Float -> {-# UNPACK #-} !Float -> BoundingBox
[_xMin] :: BoundingBox -> {-# UNPACK #-} !Float
[_yMin] :: BoundingBox -> {-# UNPACK #-} !Float
[_xMax] :: BoundingBox -> {-# UNPACK #-} !Float
[_yMax] :: BoundingBox -> {-# UNPACK #-} !Float

-- | Should be 0 most of the times.
[_baselineHeight] :: BoundingBox -> {-# UNPACK #-} !Float
instance GHC.Classes.Eq Graphics.Text.TrueType.BoundingBox
instance GHC.Show.Show Graphics.Text.TrueType.PointSize
instance GHC.Classes.Eq Graphics.Text.TrueType.PointSize
