2
-- GIMP Toolkit (GTK) - text layout functions: Font
6
-- Created: 16 October 2005
8
-- Version $Revision: 1.1 $ from $Date: 2005/10/25 19:51:37 $
10
-- Copyright (C) 1999-2005 Axel Simon
12
-- This library is free software; you can redistribute it and/or
13
-- modify it under the terms of the GNU Lesser General Public
14
-- License as published by the Free Software Foundation; either
15
-- version 2.1 of the License, or (at your option) any later version.
17
-- This library is distributed in the hope that it will be useful,
18
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
-- Lesser General Public License for more details.
23
-- Maintainer : gtk2hs-users@lists.sourceforge.net
24
-- Stability : provisional
25
-- Portability : portable (depends on GHC)
27
-- Fonts. The selection of an appropriate font to render text becomes a
28
-- substantial task in the presence of Unicode where a single font does not
29
-- over the whole range of possible characters. Pango provides several
30
-- concepts to find appropriate fonts and to query information about them:
32
-- * 'FontDescription': Font descriptions provide a way to query and state
34
-- fonts. This data structure has several fields describing different
35
-- characteristics of a font. Each of these fields can be set of left
38
-- * 'FontMap' : A font map represents the set of fonts available for a
39
-- particular rendering system. In particular this map defines the
40
-- relation between font size and pixel size in terms of the output medium.
42
-- * 'FontFamily' : A font family represents a set of fonts that have
43
-- related faces, that is, their faces share a common design, but differ
44
-- in slant, weight, width and other aspects.
46
-- * 'FontFace': A face is a specific font where all characteristics are
47
-- fixed except for the size.
49
-- * 'FontMetrics': Information about the font that will be used to render
50
-- a specific 'Graphics.UI.Gtk.Pango.Context.Context' or
51
-- 'Graphics.UI.Gtk.Pango.Rendering.PangoItem'.
53
module Graphics.UI.Gtk.Pango.Font (
55
-- Functions to manage font descriptions.
56
module Graphics.UI.Gtk.Pango.Description,
59
pangoFontMapListFamilies,
61
#if PANGO_CHECK_VERSION(1,4,0)
62
pangoFontFamilyIsMonospace,
64
pangoFontFamilyListFaces,
66
#if PANGO_CHECK_VERSION(1,4,0)
67
pangoFontFaceListSizes,
69
pangoFontFaceDescribe,
75
import System.Glib.FFI
76
import System.Glib.UTFString
77
{#import Graphics.UI.Gtk.Types#}
78
import System.Glib.GObject (makeNewGObject)
79
{#import Graphics.UI.Gtk.Pango.Types#}
80
import Graphics.UI.Gtk.Pango.Description
82
{# context lib="pango" prefix="pango" #}
85
-- | Ask for the different font families that a particular back-end supports.
87
-- * The given 'FontMap' can be acquired by calling
88
-- 'Graphics.UI.Gtk.Cairo.cairoFontMapNew' or
90
pangoFontMapListFamilies :: FontMap -> IO [FontFamily]
91
pangoFontMapListFamilies fm = alloca $ \arrPtrPtr -> alloca $ \sizePtr -> do
92
{#call unsafe font_map_list_families#} fm arrPtrPtr sizePtr
93
arrPtr <- peek arrPtrPtr
95
ffsPtr <- peekArray (fromIntegral size)
96
(castPtr arrPtr::Ptr (Ptr FontFamily)) -- c2hs is wrong here
97
ffs <- mapM (makeNewGObject mkFontFamily . return . castPtr) ffsPtr
98
{#call unsafe g_free#} (castPtr arrPtr)
101
instance Show FontFamily where
102
show ff = unsafePerformIO $ do
103
strPtr <- {#call unsafe font_family_get_name#} ff
106
#if PANGO_CHECK_VERSION(1,4,0)
107
-- | Ask if the given family contains monospace fonts.
109
-- * A monospace font is a font designed for text display where the
110
-- characters form a regular grid. For Western languages this would
111
-- mean that the advance width of all characters are the same, but
112
-- this categorization also includes Asian fonts which include
113
-- double-width characters: characters that occupy two grid cells.
115
-- * The best way to find out the grid-cell size is to query the members
116
-- of the according 'FontMetrics' structure.
118
pangoFontFamilyIsMonospace :: FontFamily -> Bool
119
pangoFontFamilyIsMonospace ff = unsafePerformIO $
120
liftM toBool $ {#call unsafe font_family_is_monospace#} ff
123
-- | Ask for the faces contained in a particular family.
125
-- * Asks for all font faces in the given family. The faces in a family
126
-- share a common design, but differ in slant, weight, width and other
127
-- aspects. For example, the font family "Sans" contains several fonts
128
-- such as Helvetica and Arial.
130
pangoFontFamilyListFaces :: FontFamily -> IO [FontFace]
131
pangoFontFamilyListFaces ff = alloca $ \arrPtrPtr -> alloca $ \sizePtr -> do
132
{#call unsafe font_family_list_faces#} ff arrPtrPtr sizePtr
133
arrPtr <- peek arrPtrPtr
135
ffsPtr <- peekArray (fromIntegral size)
136
(castPtr arrPtr::Ptr (Ptr FontFace)) -- c2hs is wrong here
137
ffs <- mapM (makeNewGObject mkFontFace . return . castPtr) ffsPtr
138
{#call unsafe g_free#} (castPtr arrPtr)
141
instance Show FontFace where
142
show ff = unsafePerformIO $ do
143
strPtr <- {#call unsafe font_face_get_face_name#} ff
146
#if PANGO_CHECK_VERSION(1,4,0)
147
-- | Ask for available sizes of this font face.
149
-- * List the available sizes for a font. This is only applicable to bitmap
150
-- fonts since all other fonts can be scaled arbitrarily. For scalable
151
-- fonts, this function returns @Nothing@. The sizes returned are in
152
-- ascending order, their unit is points (1\/72 inch).
154
pangoFontFaceListSizes :: FontFace -> IO (Maybe [PangoUnit])
155
pangoFontFaceListSizes ff = alloca $ \arrPtrPtr -> alloca $ \sizePtr -> do
156
{#call unsafe font_face_list_sizes#} ff arrPtrPtr sizePtr
157
arrPtr <- peek arrPtrPtr
159
if arrPtr==nullPtr then return Nothing else do
160
sizes <- peekArray (fromIntegral size) arrPtr
161
{#call unsafe g_free#} (castPtr arrPtr)
162
return (Just (map intToPu sizes))
165
-- | Ask for a description of this face.
167
-- * Returns the family, style, variant, weight and stretch of a 'FontFace'.
168
-- The size field of the resulting font description will be unset.
170
pangoFontFaceDescribe :: FontFace -> IO FontDescription
171
pangoFontFaceDescribe ff = do
172
fdPtr <- {#call unsafe font_face_describe#} ff
173
makeNewFontDescription fdPtr