SVGFonts-1.0: src/Test/Fonts.hs
module Main where
import Data.Tree
import Graphics.SVGFonts.ReadFont
import Graphics.Formats.Collada.ColladaTypes (Geometry, SceneNode(..))
import Graphics.Formats.Collada.GenerateObjects (lightedScene, lightedSceneNode, emptyAnim)
import Graphics.Formats.Collada.GenerateCollada (genCollada)
import Graphics.Formats.Collada.Transformations (extrude, atop, translate, changeDiffuseColor, changeAmbientColor)
import Graphics.Formats.Collada.Vector2D3D (V3(..),V4(..))
import Graphics.Triangulation.Triangulation (triangulate, deleteHoles, gjpTri)
import Graphics.Triangulation.KETTriangulation (ketTri)
import qualified Data.Map as Map
import System.Environment
main = do
args <- getArgs
let str = if null args then "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTVXYZ0123456789" -- UW
-- "The fluffiest bunny VVAV \x2192\x2193 x2200\x2203\x21d2\x2192\x2190 ss"
else head args
resolution = (ConstDx, 100) -- (Exactly 512, 512) (ConstDx, 512) (XPowerOfTwo, 512) (OneTexture, 512)
-- The y resolution is constant. The x resolution of a glyph changes in non-mono-spaced fonts.
-- Rx: Exactly: Use this resolution
-- ConstDx: The x-resolution of a glvph is chosen so that the pixels of all glyphs have the same size
-- XPowerOfTwo: With this option the resolution nearest of a power of two is chosen,
-- i.e. "l" would have (256,512), while "w" would have (512,512)
-- OneTexture: The whole string as one texture (not implemented yet)
mode = INSIDE_V2
-- mode: INSIDE_V1_V2: the string is inside v1 v2 boundaries (height/length-relation not kept)
-- mode: INSIDE_V1: stay inside v1 boundary, size of v2 adjusted to height/length-relation
-- mode: INSIDE_V2: stay inside v2 boundary, size of v1 adjusted to height/length-relation
spacing = HADV -- KERN
-- spacing: MONO: Use mono spacing between glyphs. The longest glyph influences the bbox that is used
-- HADV: Every glyph has a unique constant horiz. advance
-- KERN: Same as HADV but sometimes overridden by kerning:
-- i.e. the horizontal advance in "VV" is bigger than in "VA"
bit = makeOutlMaps "../../../src/Test/Bitstream.svg" resolution
lin = makeOutlMaps "../../../src/Test/LinLibertine.svg" resolution
o = V3 0 0 0 -- origin
v1 = V3 (-5) 0 0 -- direction of char-advance
v2 = V3 0 0 1 -- height direction
v3 = V3 0 0.1 0 -- extrusion
f :: String -> [String] -- assigning a property to every character by a unique string
f str = take (length str) (concat (repeat ["r","s"]))
props :: Props
props = Map.fromList [("p", Outl lin "to3d"), ("q", Outl lin "to3d2"),
("r", Tex bit "red"), ("s", Tex bit "blue") ]
-- transformation of a Geoemtry Node (i.e. triangulation) has to be done with a string assignment,
-- because there has to be a finite number of functions for Data.Map
transf :: Transf
transf = Map.fromList [("to3d",to3d), ("to3d2",to3d2), ("red", red.bgWhite), ("blue",blue.bgWhite), ("id",id)]
-- not the perfect solution since some points are generated twice
to3d geom = red $ ( ((extrude v3).deleteHoles) geom ) `atop`
( tri ((translate v3) geom) )
to3d2 geom = blue $ ( ((extrude (V3 0 0.05 0)).deleteHoles) geom ) `atop`
( tri ((translate (V3 0 0.05 0)) geom) )
tri = (triangulate ketTri).deleteHoles -- gjpTri
red = changeDiffuseColor "red" (V4 1 0 0 1) -- if used with textures diffuse is interpreted as foreground color
blue = changeDiffuseColor "blue" (V4 0 0 1 1)
bgWhite = changeAmbientColor "white" (V4 1 1 1 1) -- if used with textures interpreted as background color
texmap = makeTexMap resolution props transf
n0 = displayString str "line0" resolution mode spacing (o,v1,v2) f props transf texmap
-- n1 = displayString "test" "line1" resolution mode spacing (V3 0 0 (-1),v1,v2) f props transf texmap
node = Node EmptyRoot [n0]
genCollada (lightedScene node) emptyAnim
putStrLn "Collada File generated"