From 866ea3d2d38b232014081d67c198a73620f1414c Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Tue, 31 Jan 2023 10:47:02 +1300 Subject: [PATCH] Start implementing a seperate bridge module to Harfbuzz. --- fontconfig-harfbuzz/CHANGELOG.md | 5 ++ .../Data/Text/Glyphize/Choose.hs | 23 +++++ fontconfig-harfbuzz/LICENSE | 20 +++++ fontconfig-harfbuzz/Setup.hs | 2 + {app => fontconfig-harfbuzz/app}/Main.hs | 1 + fontconfig-harfbuzz/fontconfig-harfbuzz.cabal | 88 +++++++++++++++++++ fontconfig-pure.cabal | 8 -- 7 files changed, 139 insertions(+), 8 deletions(-) create mode 100644 fontconfig-harfbuzz/CHANGELOG.md create mode 100644 fontconfig-harfbuzz/Data/Text/Glyphize/Choose.hs create mode 100644 fontconfig-harfbuzz/LICENSE create mode 100644 fontconfig-harfbuzz/Setup.hs rename {app => fontconfig-harfbuzz/app}/Main.hs (97%) create mode 100644 fontconfig-harfbuzz/fontconfig-harfbuzz.cabal diff --git a/fontconfig-harfbuzz/CHANGELOG.md b/fontconfig-harfbuzz/CHANGELOG.md new file mode 100644 index 0000000..784d04e --- /dev/null +++ b/fontconfig-harfbuzz/CHANGELOG.md @@ -0,0 +1,5 @@ +# Revision history for fontconfig-harfbuzz + +## 0.1.0.0 -- YYYY-mm-dd + +* First version. Released on an unsuspecting world. diff --git a/fontconfig-harfbuzz/Data/Text/Glyphize/Choose.hs b/fontconfig-harfbuzz/Data/Text/Glyphize/Choose.hs new file mode 100644 index 0000000..13680e0 --- /dev/null +++ b/fontconfig-harfbuzz/Data/Text/Glyphize/Choose.hs @@ -0,0 +1,23 @@ +module Data.Text.Glyphize.Choose where + +import Data.Text.Glyphize (Font, createFace, createFontWithOptions, + Variation, FontOptions (..), defaultFontOptions) +import Graphics.Text.Font.Choose (Pattern, getValue0, getValue') +import qualified Data.ByteString as B + +import System.IO.Unsafe (unsafePerformIO) + +-- Warning: file-read sideeffect. +instantiatePattern :: Pattern -> [Variation] -> IO Font +instantiatePattern pat variations = createFontWithOptions options face + where + bytes = unsafePerformIO $ B.readFile $ getValue0 "file" pat + face = createFace bytes $ fromMaybe 0 $ getValue' "index" pat + options = foldl value2opt defaultFontOptions $ normalizePattern pat + + value2opt opts ("slant", (_, ValueInt x):_) = opts {optionSynthSlant = Just x} + value2opt opts ("fontvariations", _:_) = opts {optionVariations = variations} + value2opt opts ("size", (_, ValueDouble x):_) = opts {optionPtEm = Just x} + value2opt opts ("pixelsize", (_, ValueDouble x):_) = opts { + optionPPEm = Just (toEnum $ fromEnum x, toEnum $ fromEnum x) + } diff --git a/fontconfig-harfbuzz/LICENSE b/fontconfig-harfbuzz/LICENSE new file mode 100644 index 0000000..b26c099 --- /dev/null +++ b/fontconfig-harfbuzz/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2023 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/fontconfig-harfbuzz/Setup.hs b/fontconfig-harfbuzz/Setup.hs new file mode 100644 index 0000000..9a994af --- /dev/null +++ b/fontconfig-harfbuzz/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/app/Main.hs b/fontconfig-harfbuzz/app/Main.hs similarity index 97% rename from app/Main.hs rename to fontconfig-harfbuzz/app/Main.hs index 7102898..b7a7ed5 100644 --- a/app/Main.hs +++ b/fontconfig-harfbuzz/app/Main.hs @@ -34,6 +34,7 @@ main = do ft_With_FreeType $ \ft -> do inst <- instantiatePattern ft font (fromMaybe 12 $ getValue' "size" font, 20) + let text = shape displayCallback $= do clear [ ColorBuffer ] diff --git a/fontconfig-harfbuzz/fontconfig-harfbuzz.cabal b/fontconfig-harfbuzz/fontconfig-harfbuzz.cabal new file mode 100644 index 0000000..e0006c1 --- /dev/null +++ b/fontconfig-harfbuzz/fontconfig-harfbuzz.cabal @@ -0,0 +1,88 @@ +-- Initial fontconfig-harfbuzz.cabal generated by cabal init. For further +-- documentation, see http://haskell.org/cabal/users-guide/ + +-- The name of the package. +name: fontconfig-harfbuzz + +-- 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: Bridges from FontConfig to Harfbuzz. + +-- A longer description of the package. +-- description: + +-- 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: alcinnz@argonaut-constellation.org + +-- 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: + + -- 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.12 && <4.13, fontconfig-pure, harfbuzz-pure + + -- Directories containing source files. + hs-source-dirs: . + + -- Base language which the package is written in. + default-language: Haskell2010 + + +executable fontconfig-harfbuzz + -- .hs or .lhs file containing the Main module. + main-is: Main.hs + + -- Modules included in this executable, other than Main. + -- other-modules: + + -- LANGUAGE extensions used by modules in this package. + -- other-extensions: + + -- Other library packages from which modules are imported. + build-depends: base >=4.12 && <4.13, typograffiti>=0.2, text, harfbuzz, + GLUT >= 2.7, gl, mtl, fontconfig-pure, freetype2 + + -- Directories containing source files. + hs-source-dirs: app + + -- Base language which the package is written in. + default-language: Haskell2010 + diff --git a/fontconfig-pure.cabal b/fontconfig-pure.cabal index 5fc486f..ceeb2f1 100644 --- a/fontconfig-pure.cabal +++ b/fontconfig-pure.cabal @@ -107,11 +107,3 @@ test-suite test-fontconfig type: exitcode-stdio-1.0 main-is: Test.hs build-depends: base >= 4.12 && <4.13, fontconfig-pure, hspec, QuickCheck - -executable view-font - main-is: Main.hs - build-depends: base >=4.12 && <4.13, typograffiti>=0.2, text, - GLUT >= 2.7, gl, mtl, fontconfig-pure, freetype2 - hs-source-dirs: app - default-language: Haskell2010 - -- 2.30.2