Code

Merge and cleanup of GSoC C++-ification project.
[inkscape.git] / src / libnrtype / nr-type-pos-def.h
1 #ifndef __NR_TYPE_POS_DEF_H__
2 #define __NR_TYPE_POS_DEF_H__
4 #define NR_POS_STYLE_NORMAL              0
5 #define NR_POS_STYLE_ITALIC              1
6 #define NR_POS_STYLE_OBLIQUE             2
8 #define NR_POS_WEIGHT_THIN               32
9 #define NR_POS_WEIGHT_EXTRA_LIGHT        64
10 #define NR_POS_WEIGHT_ULTRA_LIGHT        64
11 #define NR_POS_WEIGHT_LIGHT              96
12 #define NR_POS_WEIGHT_BOOK              128
13 #define NR_POS_WEIGHT_NORMAL            128
14 #define NR_POS_WEIGHT_MEDIUM            144
15 #define NR_POS_WEIGHT_SEMIBOLD          160
16 #define NR_POS_WEIGHT_DEMIBOLD          160
17 #define NR_POS_WEIGHT_BOLD              192
18 #define NR_POS_WEIGHT_ULTRA_BOLD        224
19 #define NR_POS_WEIGHT_EXTRA_BOLD        224
20 #define NR_POS_WEIGHT_BLACK             255
22 #define NR_POS_STRETCH_ULTRA_CONDENSED    48
23 #define NR_POS_STRETCH_EXTRA_CONDENSED    48
24 #define NR_POS_STRETCH_CONDENSED                  88
25 #define NR_POS_STRETCH_SEMI_CONDENSED    108
26 #define NR_POS_STRETCH_NORMAL                    128
27 #define NR_POS_STRETCH_SEMI_EXPANDED     148
28 #define NR_POS_STRETCH_EXPANDED              168
29 #define NR_POS_STRETCH_EXTRA_EXPANDED    228
30 #define NR_POS_STRETCH_ULTRA_EXPANDED    228
32 // This is an enumerate, rather than on/off property,
33 // for I sincerely hope the vocabulary of this property will be
34 // extended by the W3C in the future to allow for more fancy fonts
35 #define NR_POS_VARIANT_NORMAL                    0
36 #define NR_POS_VARIANT_SMALLCAPS                 1
38 /* Mapping from CSS weight numbers.
40    for i in `seq 9`; do
41      if [ $i -le 4 ]; then w=$((32 * $i));
42      elif [ $i = 5 ]; then w=144;
43      elif [ $i -lt 9 ]; then w=$((32 * $(($i - 1))));
44      else w=255;
45      fi;
46      printf '#define NR_POS_WEIGHT_CSS%d00\t\t%3d\n' $i $w;
47    done
49    This calculation approximately matches the old to-and-from-text code,
50    I don't claim it to be reasonable.  ("approximately": some of the old
51    code wrote strings like "semi" and "heavy" that weren't being parsed
52    at the other end, and it had CSS100 darker than CSS200.)
53  */
54 #define NR_POS_WEIGHT_CSS100             32
55 #define NR_POS_WEIGHT_CSS200             64
56 #define NR_POS_WEIGHT_CSS300             96
57 #define NR_POS_WEIGHT_CSS400            128
58 #define NR_POS_WEIGHT_CSS500            144
59 #define NR_POS_WEIGHT_CSS600            160
60 #define NR_POS_WEIGHT_CSS700            192
61 #define NR_POS_WEIGHT_CSS800            224
62 #define NR_POS_WEIGHT_CSS900            255
65 class NRTypePosDef {
66 public:
67         unsigned int italic : 1;
68         unsigned int oblique : 1;
69         unsigned int weight : 8;
70         unsigned int stretch : 8;
71         unsigned int variant : 8;
72         /* These can probably be made sensible sizes rather than bitfields; for the moment we'll
73            keep the old definition. */
75 public:
76         NRTypePosDef() :
77           italic(0),
78           oblique(0),
79           weight(NR_POS_WEIGHT_NORMAL),
80           stretch(NR_POS_STRETCH_NORMAL),
81           variant(NR_POS_VARIANT_NORMAL)
82           { }
84         NRTypePosDef(char const *description);
86         bool signature() {return this->italic + 
87                         this->oblique * 255 +
88                         this->weight * 255 * 255 +
89                         this->stretch * 255 * 255 * 255 + 
90                         this->variant * 255 * 255 * 255 * 255;};
91 };
93 int parse_name_for_style (char const *c);
94 int parse_name_for_weight (char const *c);
95 int parse_name_for_stretch (char const *c);
96 int parse_name_for_variant (char const *c);
97 const char *style_to_css (int style);
98 const char *weight_to_css (int weight);
99 const char *stretch_to_css (int stretch);
100 const char *variant_to_css (int variant);
102 #endif /* __NR_TYPE_POS_DEF_H__ */