---
name: "Defoma::Common"
section: "3pm"
platform: "linux"
package: "defoma"
version: "0.11.11"
release: "Debian 6.0 (Squeeze)"
platforms: ["linux"]
url: "https://new.carta.tech/Defoma::Common"
---

# Defoma::Common(3pm)

Defoma module providing miscellaneous functions.

## NAME

Defoma::Common - Defoma module providing miscellaneous functions.

## SYNOPSIS

use Defoma::Common;

$h = parse\_hints\_start( *hints...* );

$hsub = parse\_hints\_subhints( *hints\_hash*, *face* );

$hsub = parse\_hints\_subhints\_inherit( *hints\_hash*, *face* );

parse\_hints\_cut( *hints\_hash*, *hinttypes...* );

parse\_hints\_cut\_except( *hints\_hash*, *hinttypes...* );

@hints = parse\_hints\_build( *hints\_hash* );

$charset = get\_charset( *xencoding* );

$xencoding = get\_xencoding( *charset*, *encoding* );

@XLFDs = get\_xlfd\_of\_font( *font*,  level =\> *level*,  face =\> *face* );

my $num = weight\_ascii2integer( *weightstring* );

my $num = weight\_a2i( *weightstring* );

## DESCRIPTION

**parse\_hints\_start** is a function to convert hints in an array to a hash. Hints consist of a list of hinttype and its value(s). Following is the example of hints in an array form.

\--FontName Helvetica-BoldItalic --Family Helvetica --GeneralFamily SansSerif --Weight Bold --Shape NoSerif Italic --Charset ISO8859-1

In this example, FontName, Family, GeneralFamily, Weight, Shape and Charset are hinttypes. Items starting with double minus characters '--' are taken as hinttype. The others are taken as values. The function converts this array to a hash described in the following style.

```
FontName => 'Helvetica-BoldItalic',
Family => 'Helvetica',
GeneralFamily => 'SansSerif',
Weight => 'Bold',
Shape => 'NoSerif Italic',
Charset => 'ISO8859-1'
```

You see that hinttypes are used as keys of a hash, and that Shape has two values, NoSerif and Italic. If a certain hinttype has more than  one values, they are combined into a single string separated by space.

**parse\_hints\_subhints** is a function to get a sub hint hash pointed by *face* from the hint hash specified by *hints\_hash*. Please look at following example of a hint hash.

```
$h = {Inherit => 'Charset Weight',
      FontName => 'Helvetica',
      Charset => 'ISO8859-1',
      Weight => 'Medium',
      Shape => 'Upright',
      FontName1 => 'Helvetica-Bold',
      Weight1 => 'Bold',
      FontName2 => 'Helvetica-Unicode',
      Charset2 => 'ISO10646-1'};
```

You see there're some numbered hinttypes. **parse\_hints\_subhints** extracts the hints of the specific number from it. For example, you can extract the non-numbered hints FontName and Charset by:

```
$hsub = parse_hints_subhints($h, 0);
```

and the content of $hsub will be:

```
FontName => 'Helvetica',
Charset => 'ISO8859-1',
Weight => 'Medium',
Shape => 'Upright'
```

If you set 1 to the second argument of **parse\_hints\_subhints**, the content of $hsub will be:

```
FontName => 'Helvetica-Bold',
Weight => 'Bold'
```

Note that the number of each hinttype is removed.

**parse\_hints\_subhints\_inherit** is almost the same as **parse\_hints\_subhints**, only differs it inherits non-numbered hints specified by Inherit hinttype.  Following is the result of  **parse\_hints\_subhints\_inherit** with 1 and 2 set to the second argument in the example of **parse\_hints\_subhints**.

```
FontName => 'Helvetica-Bold',
Weight => 'Bold',
Charset => 'ISO8859-1'
FontName => 'Helvetica-Unicode',
Weight => 'Medium',
Charset => 'ISO10646-1'
```

**parse\_hints\_cut** is a function to remove hinttypes specified by *hinttypes* and their values from the hint hash. It is supposed to be used together with **parse\_hints\_build** function.

**parse\_hints\_cut\_except** is a function to remove all hinttypes except those specified by *hinttypes* and their values from the hint hash. It is supposed to be used together with **parse\_hints\_build** function.

**parse\_hints\_build** is a function to convert hints in a hash to an array.

**get\_charset** is a function to convert X-RegistryEncoding specified by *xencoding* into Charset. X-RegistryEncoding is the last two elements of XLFD, like iso8859-1 and jisx0208.1983-0. The returned values of these two are ISO8859-1 and JISX0208 respectively.

**get\_xencoding** is a function to convert Charset and Encoding specified by *charset* and *encoding* into X-RegistryEncoding. *encoding* is often omitted.

**weight\_ascii2integer** is a function to convert Weight in string (like Bold and Medium) into a numeric value (integer). Medium is always zero, and the bolder, the larger, the lighter, the smaller. For example, Bold is +2, and Light is -2. **weight\_a2i** is abbreviation for **weight\_ascii2integer**.

**get\_xlfd\_of\_font** is a function to get an array of XLFDs of a font specified by *font*. You can control the amount of gained XLFDs by *level* and  *face* options. *level* must be either of *'min'*, *'normal'*, or *'max'*. When *min* is specified, not-slanted not-boldized XLFDs registered in xfont category will be returned. When  *normal* is specified, XLFDs including boldized and/or slanted (but not reverse slanted) ones registered in xfont category will be returned. When *max* is specified, all generated XLFDs will be returned.

## EXAMPLES

```
$h = parse_hints_start(@_);
@shape = split(/ /, $h->{Shape});
@alias = split(/ /, $h->{Alias});
$priority = $h->{Priority};
$realname = $h->{FontName};
$realname =~ s/ .*//;
parse_hints_cut($h, 'Priority', 'FontName', 'Charset');
@hints = parse_hints_build($h);
```

## SEE ALSO

[**defoma**(1)](/defoma/1.md).
