Allow wildcards in --epub-embed-font arguments.

Closes #1939.
This commit is contained in:
John MacFarlane 2015-02-13 23:29:12 -08:00
parent d5469b30fe
commit e32227f744
3 changed files with 17 additions and 6 deletions

9
README
View file

@ -608,9 +608,12 @@ Options affecting specific writers
`--epub-embed-font=`*FILE*
: Embed the specified font in the EPUB. This option can be repeated
to embed multiple fonts. To use embedded fonts, you
will need to add declarations like the following to your CSS (see
`--epub-stylesheet`):
to embed multiple fonts. Wildcards can also be used: for example,
`DejaVuSans-*.ttf`. However, if you use wildcards on the command
line, be sure to escape them or put the whole filename in single quotes,
to prevent them from being interpreted by the shell. To use the
embedded fonts, you will need to add declarations like the following
to your CSS (see `--epub-stylesheet`):
@font-face {
font-family: DejaVuSans;

View file

@ -253,7 +253,8 @@ Library
haddock-library >= 1.1 && < 1.3,
old-time,
deepseq-generics >= 0.1 && < 0.2,
JuicyPixels >= 3.1.6.1 && < 3.3
JuicyPixels >= 3.1.6.1 && < 3.3,
filemanip >= 0.3 && < 0.4
if flag(old-locale)
Build-Depends: old-locale >= 1 && < 1.1,
time >= 1.2 && < 1.5

View file

@ -36,6 +36,7 @@ import Data.List ( isPrefixOf, isInfixOf, intercalate )
import System.Environment ( getEnv )
import Text.Printf (printf)
import System.FilePath ( takeExtension, takeFileName )
import System.FilePath.Glob ( namesMatching )
import qualified Data.ByteString.Lazy as B
import qualified Data.ByteString.Lazy.Char8 as B8
import qualified Text.Pandoc.UTF8 as UTF8
@ -57,7 +58,7 @@ import Text.Pandoc.Options ( WriterOptions(..)
import Text.Pandoc.Definition
import Text.Pandoc.Walk (walk, walkM)
import Control.Monad.State (modify, get, execState, State, put, evalState)
import Control.Monad (foldM, mplus, liftM)
import Control.Monad (foldM, mplus, liftM, when)
import Text.XML.Light ( unode, Element(..), unqual, Attr(..), add_attrs
, strContent, lookupAttr, Node(..), QName(..), parseXML
, onlyElems, node, ppElement)
@ -387,8 +388,14 @@ writeEPUB opts doc@(Pandoc meta _) = do
picEntries <- foldM readPicEntry [] pics
-- handle fonts
let matchingGlob f = do
xs <- namesMatching f
when (null xs) $
warn $ f ++ " did not match any font files."
return xs
let mkFontEntry f = mkEntry (takeFileName f) `fmap` B.readFile f
fontEntries <- mapM mkFontEntry $ writerEpubFonts opts'
fontFiles <- concat <$> mapM matchingGlob (writerEpubFonts opts')
fontEntries <- mapM mkFontEntry fontFiles
-- set page progression direction attribution
let progressionDirection = case epubPageDirection metadata of