Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Multi-keyed lookup table?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-08-07 (19:41)
From: Matt Gushee <matt@g...>
Subject: [Caml-list] Multi-keyed lookup table?
Hello, all--

I am trying to decide on a data structure that allows efficient lookup
of fonts according to various font properties. I am thinking that the
data structures describing fonts will be something like this:

  type font_weight =
    | Medium
    | Bold
    | Light
  type font_style =
    | Roman
    | Italic
    | Oblique
  type font_width =
    | Normal
    | Expanded
    | Condensed
  type encoding = string * int     (* e.g. : ("iso8859",15))
  type font_ref = string       (* reference to the font file *)
  type font_family =
    ((font_weight * font_style * font_width * encoding) * font_ref) 

  (* Example font family *)
  let arial = [
    ((Medium, Roman, Normal, ("iso10646",1)), "arial.ttf");
    ((Bold, Roman, Normal, ("iso10646",1)), "arialb.ttf");

  (* based on the 5 types used in CSS and other Web standards *)
  type font_class =
    | Serif           
    | SansSerif
    | Monospaced
    | Cursive
    | Fantasy

What I would like to have is a data structure that contains descriptions
of all fonts available on a particular system, such that an application
can do something like:

  get_font_by_class ~weight:Bold ~style:Italic ~encoding:("iso8859",1) SansSerif


  get_font_by_family  ~weight:Bold "Helvetica"

And obtain the font file name that matches the specified
characteristics. As I mentioned above, efficient lookup is important;
efficient creation of the data structure is probably not important; and
since there are no large objects involved, and the data refers to font
collections that may have hundreds of members, but probably not
thousands, I don't think memory usage is really an issue.

So, does anyone have an idea what sort of data structure would work

TIA for your suggestions.

Matt Gushee                 When a nation follows the Way,
Englewood, Colorado, USA    Horses bear manure through           its fields;   When a nation ignores the Way,
                            Horses bear soldiers through
                                its streets.
                            --Lao Tzu (Peter Merel, trans.)

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: