packages feed

line2pdf 0.0.1 → 0.0.2

raw patch · 2 files changed

+85/−19 lines, 2 filesdep ~base

Dependency ranges changed: base

Files

line2pdf.cabal view
@@ -1,5 +1,5 @@ name:               line2pdf-version:            0.0.1+version:            0.0.2 copyright:          2008 Audrey Tang license:            BSD3 license-file:       LICENSE@@ -9,11 +9,17 @@ description:        Simple command-line utility to convert text into PDF stability:          experimental build-type:         Simple+cabal-version:      >= 1.2 category:           Text extra-source-files: README -executable:         line2pdf-main-is:            line2pdf.hs-extensions:         ImplicitParams-build-depends:      base, bytestring, containers-hs-source-dirs:     .+flag small_base+    description: Choose the new smaller, split-up base package.++executable line2pdf+    main-is:            line2pdf.hs+    extensions:         ImplicitParams+    if flag(small_base)+        build-depends: base >= 3, containers, bytestring+    else+        build-depends: base < 3
line2pdf.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE ImplicitParams #-}-module Main where++module Main (main) where import Data.IORef import System.IO import System.IO.Unsafe@@ -28,6 +29,7 @@ type M = IO type Obj = Int +main :: IO () main = do     args <- getArgs @@ -85,6 +87,7 @@     pr$ ">>" ++ "endobj\n"     return rv +writeLocations :: M () writeLocations = do     locs <- IM.elems <$> readRef __LOC__     pr$ concatMap fmt locs@@ -94,29 +97,31 @@         pad = replicate (10-l) '0'         l = length x  +printObj :: String -> M Obj+printObj str = markObj $ (pr str >>) . return++writeHeader :: M (Obj, Obj, Obj, Obj) writeHeader = do-    info <- markObj $ \info -> do-        pr$ "/CreationDate(D:20080707163949+08'00')"-         ++ "/Producer(line2pdf.hs)"-         ++ "/Title(Untitled)"-        return info-    encoding <- markObj $ \encoding -> do-        pr$ strDefaultEncoding-        return encoding+    info <- printObj $ "/CreationDate(D:20080707163949+08'00')"+                    ++ "/Producer(line2pdf.hs)"+                    ++ "/Title(Untitled)"+    encoding <- printObj strDefaultEncoding     everyFont <- (`mapM` ([1..] `zip` baseFonts)) $ \(n, font) -> do         markObj $ \obj -> do             pr$ "/Type/Font" ++ "/Subtype/Type1" ++ "/Name/F"-            pr$ show n+            pr$ show (n :: Int)             pr$ "/Encoding " ++ show encoding ++ " 0 R"             pr$ font             return $ "/F" ++ show n ++ " " ++ show obj ++ " 0 R"+    tradFont <- tradChineseFonts     root    <- incrObj     tPages  <- incrObj     markObj $ \resources -> do-        pr$ "/Font<<" ++ concat everyFont ++ ">>"+        pr$ "/Font<<" ++ concat everyFont ++ concat tradFont ++ ">>"             ++ "/ProcSet[/PDF/Text]" ++ "/XObject<<>>"         return (info, root, tPages, resources) +baseFonts :: [String] baseFonts =     [ "/BaseFont/Courier"     , "/BaseFont/Courier-Oblique"@@ -139,11 +144,19 @@     putStr str     modifyRef __POS__ (+ (length str)) +currentLocation :: IO Int currentLocation = readRef __POS__ +newRef :: a -> M (IORef a) newRef = newIORef++readRef :: IORef a -> M a readRef = readIORef++writeRef :: IORef a -> a -> M () writeRef = writeIORef++modifyRef :: IORef a -> (a -> a) -> M () modifyRef = modifyIORef  incrObj :: M Obj@@ -181,14 +194,15 @@      streamPos <- currentLocation     pr$ "BT\n";-    let fontN = 1-        ptSize = 12+    let fontN = 30 :: Int+        ptSize = 12 :: Int     pr$ "/F" ++ show fontN ++ " " ++ show ptSize ++ " Tf\n"     pr$ "1 0 0 1 50 " ++ show (pageHeight - 40) ++ " Tm\n"     pr$ "12 TL\n"      return streamPos +endPage :: Int -> M () endPage streamStart = do     pr$ "ET\n"     streamEnd <- currentLocation@@ -220,6 +234,7 @@     endPage =<< readRef pos     reverse <$> readRef __PAGE__ +strDefaultEncoding :: String strDefaultEncoding = "/Type/Encoding"     ++ "/Differences[0 /.notdef/.notdef/.notdef/.notdef"     ++ "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef"@@ -260,5 +275,50 @@     ++ "/divide/oslash/ugrave/uacute/ucircumflex/udieresis"     ++ "/yacute/thorn/ydieresis]" +pageWidth :: Int pageWidth = 792++pageHeight :: Int pageHeight = 612++tradChineseFonts :: M [String]+tradChineseFonts = do+    tradFont <- newRef []+    let addFont o fn = modifyRef tradFont+            (("/F" ++ show (fn :: Int) ++ " " ++ show o ++ " 0 R"):)++        markFont fn suffix = do+            markObj $ \obj -> do+                addFont obj fn+                pr$ "/Type/Font"+                 ++ "/Subtype/Type0"+                 ++ "/Name/F"+                pr$ show fn ++ "/BaseFont/MingLiU"+                pr$ suffix ++ "/Encoding/ETen-B5-H"+                pr$ "/DescendantFonts[" ++ show (succ obj) ++ " 0 R]"+            markObj $ \obj -> do+                pr$ "/Type/Font"+                 ++ "/Subtype/CIDFontType2"+                 ++ "/BaseFont/MingLiU"+                pr$ suffix ++ "/FontDescriptor " ++ show (succ obj) ++ " 0 R"+                 ++ "/CIDSystemInfo<<"+                 ++ "/Registry(Adobe)"+                 ++ "/Ordering(CNS1)"+                 ++ "/Supplement 0"+                 ++ ">>"+                 ++ "/DW 1000"+                 ++ "/W[13500 14000 500]"+            printObj $ "/Type/FontDescriptor"+                    ++ "/FontName/MingLiU"+                    ++ "/FontBBox[0 -199 1000 801]"+                    ++ "/Flags 7"+                    ++ "/CapHeight 0"+                    ++ "/Ascent 800"+                    ++ "/Descent -199"+                    ++ "/StemV 0"+                    ++ "/ItalicAngle 0"+    markFont 30 ""+    markFont 31 ",Italic"+    markFont 32 ",Bold"+    markFont 33 ",BoldItalic"+    readRef tradFont