1 #include "font-style-to-pos.h"
2 #include <style.h>
4 /* 'lighter' and 'darker' have to be resolved earlier */
5 /**
6 Given a style struct (CSS representation), sets the corresponding fields in a NRTypePosDef.
7 */
8 NRTypePosDef
9 font_style_to_pos (SPStyle const &style)
10 {
11 NRTypePosDef ret;
13 switch (style.font_weight.computed) {
14 case SP_CSS_FONT_WEIGHT_100:
15 ret.weight = NR_POS_WEIGHT_CSS100;
16 break;
18 case SP_CSS_FONT_WEIGHT_200:
19 ret.weight = NR_POS_WEIGHT_CSS200;
20 break;
22 case SP_CSS_FONT_WEIGHT_300:
23 ret.weight = NR_POS_WEIGHT_CSS300;
24 break;
26 case SP_CSS_FONT_WEIGHT_400:
27 case SP_CSS_FONT_WEIGHT_NORMAL:
28 ret.weight = NR_POS_WEIGHT_CSS400;
29 break;
31 case SP_CSS_FONT_WEIGHT_500:
32 ret.weight = NR_POS_WEIGHT_CSS500;
33 break;
35 case SP_CSS_FONT_WEIGHT_600:
36 ret.weight = NR_POS_WEIGHT_CSS600;
37 break;
39 case SP_CSS_FONT_WEIGHT_700:
40 case SP_CSS_FONT_WEIGHT_BOLD:
41 ret.weight = NR_POS_WEIGHT_CSS700;
42 break;
44 case SP_CSS_FONT_WEIGHT_800:
45 ret.weight = NR_POS_WEIGHT_CSS800;
46 break;
48 case SP_CSS_FONT_WEIGHT_900:
49 ret.weight = NR_POS_WEIGHT_CSS900;
50 break;
52 case SP_CSS_FONT_WEIGHT_LIGHTER:
53 case SP_CSS_FONT_WEIGHT_BOLDER:
54 default:
55 g_warning("Unrecognized font_weight.computed value");
56 ret.weight = NR_POS_WEIGHT_NORMAL;
57 break;
58 }
60 switch (style.font_style.computed) {
61 case SP_CSS_FONT_STYLE_ITALIC:
62 ret.italic = 1;
63 break;
65 case SP_CSS_FONT_STYLE_OBLIQUE:
66 ret.oblique = 1;
67 break;
69 case SP_CSS_FONT_STYLE_NORMAL:
70 default:
71 ret.italic = 0;
72 ret.oblique = 0;
73 break;
74 }
76 switch (style.font_stretch.computed) {
77 case SP_CSS_FONT_STRETCH_ULTRA_CONDENSED:
78 case SP_CSS_FONT_STRETCH_EXTRA_CONDENSED:
79 ret.stretch = NR_POS_STRETCH_EXTRA_CONDENSED;
80 break;
82 case SP_CSS_FONT_STRETCH_CONDENSED:
83 case SP_CSS_FONT_STRETCH_NARROWER:
84 ret.stretch = NR_POS_STRETCH_CONDENSED;
85 break;
87 case SP_CSS_FONT_STRETCH_SEMI_CONDENSED:
88 ret.stretch = NR_POS_STRETCH_SEMI_CONDENSED;
89 break;
91 case SP_CSS_FONT_STRETCH_SEMI_EXPANDED:
92 ret.stretch = NR_POS_STRETCH_SEMI_EXPANDED;
93 break;
95 case SP_CSS_FONT_STRETCH_EXPANDED:
96 case SP_CSS_FONT_STRETCH_WIDER:
97 ret.stretch = NR_POS_STRETCH_EXPANDED;
98 break;
100 case SP_CSS_FONT_STRETCH_EXTRA_EXPANDED:
101 case SP_CSS_FONT_STRETCH_ULTRA_EXPANDED:
102 ret.stretch = NR_POS_STRETCH_EXTRA_EXPANDED;
103 break;
105 default:
106 ret.stretch = NR_POS_STRETCH_NORMAL;
107 break;
108 }
110 switch (style.font_variant.computed) {
111 case SP_CSS_FONT_VARIANT_SMALL_CAPS:
112 ret.variant = NR_POS_VARIANT_SMALLCAPS;
113 break;
114 default:
115 ret.variant = NR_POS_VARIANT_NORMAL;
116 break;
117 }
119 return ret;
120 }