From 2e079971838b7c0073bcf38ac0d5df56a5a6dbc5 Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Fri, 11 Feb 2022 15:58:56 +1300 Subject: [PATCH] Draft pure-functional Harfbuzz API. --- ChangeLog.md | 5 +++ Data/Text/Glyphize.hs | 13 +++++++ Data/Text/Glyphize/Buffer.hs | 48 ++++++++++++++++++++++++ Data/Text/Glyphize/Font.hs | 33 +++++++++++++++++ LICENSE | 20 ++++++++++ Setup.hs | 2 + cabal.sandbox.config | 26 +++++++++++++ harfbuzz-pure.cabal | 71 ++++++++++++++++++++++++++++++++++++ 8 files changed, 218 insertions(+) create mode 100644 ChangeLog.md create mode 100644 Data/Text/Glyphize.hs create mode 100644 Data/Text/Glyphize/Buffer.hs create mode 100644 Data/Text/Glyphize/Font.hs create mode 100644 LICENSE create mode 100644 Setup.hs create mode 100644 cabal.sandbox.config create mode 100644 harfbuzz-pure.cabal diff --git a/ChangeLog.md b/ChangeLog.md new file mode 100644 index 0000000..34341ce --- /dev/null +++ b/ChangeLog.md @@ -0,0 +1,5 @@ +# Revision history for harfbuzz-pure + +## 0.1.0.0 -- YYYY-mm-dd + +* First version. Released on an unsuspecting world. diff --git a/Data/Text/Glyphize.hs b/Data/Text/Glyphize.hs new file mode 100644 index 0000000..c86b05b --- /dev/null +++ b/Data/Text/Glyphize.hs @@ -0,0 +1,13 @@ +module Data.Text.Glyphize where + +import Data.Text.Glyphize.Buffer +import Data.Text.Glyphize.Font + +-- Don't think I'll implement shapeplans at this stage... +-- shape :: Font -> Buffer -> [(GlyphInfo, GlyphPos)] + +-- Defer implementing font features... + +-- version :: (Int, Int, Int) +-- versionAtLeast :: (Int, Int, Int) -> Bool +-- versionString :: ShortString diff --git a/Data/Text/Glyphize/Buffer.hs b/Data/Text/Glyphize/Buffer.hs new file mode 100644 index 0000000..3c074e6 --- /dev/null +++ b/Data/Text/Glyphize/Buffer.hs @@ -0,0 +1,48 @@ +module Data.Text.Glyphize.Buffer where + +import Data.Text.Lazy as Lazy +import Data.ByteString.Lazy as Lazy +import Data.Text.Short + +data Buffer = Buffer { + text :: Either Lazy.Text Lazy.ByteString, + contentType :: Maybe ContentType, + direction :: Maybe Direction, + script :: Maybe ShortText, + language :: Maybe ShortText, + beginsText :: Bool, + endsText :: Bool, + preserveDefaultIgnorables :: Bool, + removeDefaultIgnorables :: Bool, + don'tInsertDottedCircle :: Bool, + clusterLevel :: ClusterLevel, + invisibleGlyph :: Char, + notFoundGlyph :: Char, + replacementCodepoint :: Char +} + +data ContentType = ContentTypeUnicode | ContentTypeGlyphs deriving (Eq, Show) +data Direction = DirLTR | DirRTL | DirTTB | DirBTT deriving (Eq, Show) +data ClusterLevel = ClusterMonotoneGraphemes | ClusterMonotoneChars | ClusterChars deriving (Eq, Show) + +data GlyphInfo = GlyphInfo { + codepoint :: Int, + cluster :: Int +} +data GlyphPos = GlyphPos { + x_advance :: Int, y_advance :: Int, + x_offset :: Int, y_offset :: Int +} + +-- guessSegmentProperties :: Buffer -> Buffer +-- glyphInfo & glyphPositions to be zipped & return from shape function +-- scriptHorizontalDir :: ShortText -> Direction + +dirReverse DirLTR = DirRTL +dirReverse DirRTL = DirLTR +dirReverse DirTTB = DirBTT +dirReverse DirBTT = DirTTB +dirBackward dir = dir `Prelude.elem` [DirRTL, DirBTT] +dirForward dir = dir `Prelude.elem` [DirLTR, DirTTB] +dirHorizontal dir = dir `Prelude.elem` [DirLTR, DirRTL] +dirVertical dir = dir `Prelude.elem` [DirTTB, DirBTT] diff --git a/Data/Text/Glyphize/Font.hs b/Data/Text/Glyphize/Font.hs new file mode 100644 index 0000000..3bb12b3 --- /dev/null +++ b/Data/Text/Glyphize/Font.hs @@ -0,0 +1,33 @@ +module Data.Text.Glyphize.Font where + +import Data.ByteString +import Data.Text.Short + +data Face = Face -- TODO Define + +-- countFace :: ByteString -> Int +-- createFace :: ByteString -> Int -> Face +-- emptyFace :: Face +-- faceGlyphCount :: Face -> Int +-- faceIndex :: Face -> Int +-- faceUpem :: Face -> Int +-- Defer implementation of other functions + +data Font = Font -- TODO Define +data FontOptions = FontOptions { + x_ppem :: Int, y_ppem :: Int, + ptem :: Int, + x_scale :: Int, y_scale :: Int, + slant :: Float + -- Support variations? Variation coordinates? +} + +-- createFont :: Face -> FontOptions -> Font +-- emptyFont :: Font +-- fontFace :: Font -> Face +-- fontGlyph :: Font -> Char -> Maybe Char -> Maybe Int +-- fontString2Glyph :: Font -> ShortText -> Maybe Int +-- fontGlyph2String :: Font -> Int -> ShortText +-- Defer implementation of other functions + +-- Do we need FontFuncs? diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1a79030 --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2022 Adrian Cochrane + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/Setup.hs b/Setup.hs new file mode 100644 index 0000000..9a994af --- /dev/null +++ b/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/cabal.sandbox.config b/cabal.sandbox.config new file mode 100644 index 0000000..9571933 --- /dev/null +++ b/cabal.sandbox.config @@ -0,0 +1,26 @@ +-- This is a Cabal package environment file. +-- THIS FILE IS AUTO-GENERATED. DO NOT EDIT DIRECTLY. +-- Please create a 'cabal.config' file in the same directory +-- if you want to change the default settings for this sandbox. + + +local-repo: /home/alcinnz/Projects/browser-engine/harfbuzz-pure/.cabal-sandbox/packages +logs-dir: /home/alcinnz/Projects/browser-engine/harfbuzz-pure/.cabal-sandbox/logs +world-file: /home/alcinnz/Projects/browser-engine/harfbuzz-pure/.cabal-sandbox/world +user-install: False +package-db: /home/alcinnz/Projects/browser-engine/harfbuzz-pure/.cabal-sandbox/x86_64-linux-ghc-8.0.2-packages.conf.d +build-summary: /home/alcinnz/Projects/browser-engine/harfbuzz-pure/.cabal-sandbox/logs/build.log + +install-dirs + prefix: /home/alcinnz/Projects/browser-engine/harfbuzz-pure/.cabal-sandbox + bindir: $prefix/bin + libdir: $prefix/lib + libsubdir: $abi/$libname + dynlibdir: $libdir/$abi + libexecdir: $prefix/libexec + datadir: $prefix/share + datasubdir: $abi/$pkgid + docdir: $datadir/doc/$abi/$pkgid + htmldir: $docdir/html + haddockdir: $htmldir + sysconfdir: $prefix/etc diff --git a/harfbuzz-pure.cabal b/harfbuzz-pure.cabal new file mode 100644 index 0000000..584bd26 --- /dev/null +++ b/harfbuzz-pure.cabal @@ -0,0 +1,71 @@ +-- Initial harfbuzz-pure.cabal generated by cabal init. For further +-- documentation, see http://haskell.org/cabal/users-guide/ + +-- The name of the package. +name: harfbuzz-pure + +-- The package version. See the Haskell package versioning policy (PVP) +-- for standards guiding when and how versions should be incremented. +-- https://wiki.haskell.org/Package_versioning_policy +-- PVP summary: +-+------- breaking API changes +-- | | +----- non-breaking API additions +-- | | | +--- code changes with no API change +version: 0.1.0.0 + +-- A short (one-line) description of the package. +synopsis: Pure-functional Harfbuzz language bindings + +-- A longer description of the package. +description: HarfBuzz is a text shaping library. Using the HarfBuzz library allows programs to convert a sequence of Unicode input into properly formatted and positioned glyph output—for any writing system and language. + +-- URL for the project homepage or repository. +homepage: https://harfbuzz.github.io/ + +-- The license under which the package is released. +license: MIT + +-- The file containing the license text. +license-file: LICENSE + +-- The package author(s). +author: Adrian Cochrane + +-- An email address to which users can send suggestions, bug reports, and +-- patches. +maintainer: opensource@openwork.nz + +-- A copyright notice. +-- copyright: + +category: Text + +build-type: Simple + +-- Extra files to be distributed with the package, such as examples or a +-- README. +extra-source-files: ChangeLog.md + +-- Constraint on the version of Cabal needed to build this package. +cabal-version: >=1.10 + + +library + -- Modules exported by the library. + exposed-modules: Data.Text.Glyphize, Data.Text.Glyphize.Buffer, Data.Text.Glyphize.Font + + -- Modules included in this library but not exported. + -- other-modules: + + -- LANGUAGE extensions used by modules in this package. + -- other-extensions: + + -- Other library packages from which modules are imported. + build-depends: base >=4.9 && <4.10, bytestring, text, text-short + extra-libraries: harfbuzz + + -- Directories containing source files. + -- hs-source-dirs: + + -- Base language which the package is written in. + default-language: Haskell2010 + -- 2.30.2