packages feed

fontwhich 0.2 → 0.2.1

raw patch · 4 files changed

+45/−17 lines, 4 files

Files

ChangeLog.md view
@@ -1,5 +1,9 @@ # fontwhich releases +## 0.2.1 (2026-03-26)+- check and warn about characters without font coverage+- output base font name when not text given+ ## 0.2 (2026-03-12) - add --unicode for unicode data output (uses `unicode-data`) - rename --hex to --utf8 (for hex bytes)
README.md view
@@ -11,7 +11,7 @@ `$ fontwhich --version`  ```-0.2+0.2.1 ```  `$ fontwhich --help`@@ -19,7 +19,7 @@ ``` fontwhich -Usage: fontwhich [--version] [-f|--font FONT] [-l|--lang LANG] [-b|--utf8] +Usage: fontwhich [--version] [-f|--font FONT] [-l|--lang LANG] [-b|--utf8]                  [-u|--unicode] [TEXT]    Describes the fonts used to render text with pango@@ -54,7 +54,7 @@ `$ fontwhich -l ja`  ```-Primary font for ja is: "Noto Sans CJK JP"+Primary Sans font for ja is: "Noto Sans CJK JP" ```  `$ fontwhich --utf8 🌳`@@ -88,11 +88,21 @@   ## Building and installation-On Fedora:+On Fedora, install system deps with `cabal-rpm builddep`.++C library dependencies:++- Fedora: cairo-devel pango-devel gobject-introspection-devel+- Ubuntu: libcairo2-dev libpango1.0-dev libgirepository1.0-dev++Then: ```-$ cabal-rpm builddep $ cabal install ```+or+```+$ stack install+```  There is a copr repo: <https://copr.fedorainfracloud.org/coprs/petersen/fontwhich/> @@ -100,6 +110,8 @@ Code assisted with Gemini 3.1.  The tool is related conceptually to <https://github.com/sudipshil9862/whichfont> (C codebase).++"fontwhich" as in "sandwhich" but with fonts.  ## Collaborate 
fontwhich.cabal view
@@ -1,6 +1,6 @@ cabal-version:       2.2 name:                fontwhich-version:             0.2+version:             0.2.1 synopsis:            Determine fonts used to render text description:         Fontwhich is a commandline tool that used pango to determine which@@ -17,7 +17,9 @@ build-type:          Simple extra-doc-files:     README.md                      ChangeLog.md-tested-with:         GHC == 9.6.7+tested-with:         GHC == 9.2.8+                      || == 9.4.8+                      || == 9.6.7                       || == 9.8.4                       || == 9.10.3                       || == 9.12.3
src/Main.hs view
@@ -1,6 +1,6 @@ -- SPDX-License-Identifier: BSD-3-Clause -import Control.Monad.Extra (forM_, when, whenJust)+import Control.Monad.Extra (filterM, forM_, when, whenJust) import qualified Data.ByteString as B import Data.Char (ord) import Data.Maybe (fromMaybe)@@ -41,7 +41,8 @@   fontMap <- PangoCairo.fontMapGetDefault   context <- Pango.fontMapCreateContext fontMap   attr <- Pango.attrListNew-  baseFont <- Pango.fontDescriptionFromString $ T.pack $ fromMaybe "Sans" mfont+  let baseName = fromMaybe "Sans" mfont+  baseFont <- Pango.fontDescriptionFromString $ T.pack baseName   mplang <- Pango.languageFromString $ T.pack <$> mlang    if null txt then do@@ -60,7 +61,7 @@                 desc' <- Pango.fontDescribe font                 mfamily <- Pango.fontDescriptionGetFamily desc'                 whenJust mfamily $ \family ->-                  putStrLn $ "Primary font" +-+ maybe "" ("for" +-+) mlang +-+ "is:" +-+ show family+                  putStrLn $ "Primary" +-+ baseName +-+ "font" +-+ maybe "" ("for" +-+) mlang +-+ "is:" +-+ show family                 return True -- stop after first font     else do       let myText = T.pack $ unwords txt@@ -90,6 +91,9 @@       let itemBytes = B.take (fromIntegral len) $ B.drop (fromIntegral offset) utf8Bytes       return (T.unpack $ TE.decodeUtf8 itemBytes, item) +quoteStr :: String -> String+quoteStr str = '\'' : str ++ "'"+ printItemInfo :: Bool -> Bool -> (String, Pango.Item) -> IO () printItemInfo hex unicode (str,item) = do   -- Get the Analysis struct from the Item@@ -101,16 +105,22 @@   mfamily <-     case maybeFont of       Nothing -> do-        putStrLn "No font assigned"+        putStrLn "No font installed?"         return Nothing-      Just font ->-        Pango.fontDescribe font >>= Pango.fontDescriptionGetFamily+      Just font -> do+        notcovered <- filterM (fmap not . Pango.fontHasChar font) str+        if null notcovered+          then Pango.fontDescribe font >>= Pango.fontDescriptionGetFamily+          else do+          putStrLn $ "no font coverage for" +-+ quoteStr notcovered ++ "!"+          return Nothing -  let hexStr = if hex-             then unwords $ map hexify str-             else ""+  let hexStr =+        if hex+        then unwords $ map hexify str+        else ""   putStrLn $-    '\'' : str ++ "'" +-+ hexStr +-+ ":" +-+ maybe "Unknown" T.unpack mfamily+    quoteStr str +-+ hexStr +-+ ":" +-+ maybe "Unknown" T.unpack mfamily   when unicode $     forM_ str $ \char -> do     putChar char