Font features specified in @font-face blocks don't apply to local() families
[WebKit.git] / Source / WebCore / platform / text / TextFlags.h
1 /*
2  * Copyright (C) 2003, 2006 Apple Inc.  All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
24  */
25
26 #ifndef TextFlags_h
27 #define TextFlags_h
28
29 namespace WebCore {
30
31 enum TextRenderingMode { AutoTextRendering, OptimizeSpeed, OptimizeLegibility, GeometricPrecision };
32
33 enum FontSmoothingMode { AutoSmoothing, NoSmoothing, Antialiased, SubpixelAntialiased };
34
35 // This setting is used to provide ways of switching between multiple rendering modes that may have different
36 // metrics. It is used to switch between CG and GDI text on Windows.
37 enum class FontRenderingMode { Normal, Alternate };
38
39 enum FontOrientation { Horizontal, Vertical };
40
41 enum class NonCJKGlyphOrientation { Mixed, Upright };
42
43 // Here, "Leading" and "Trailing" are relevant after the line has been rearranged for bidi.
44 // ("Leading" means "left" and "Trailing" means "right.")
45 enum ExpansionBehaviorFlags {
46     ForbidTrailingExpansion = 0 << 0,
47     AllowTrailingExpansion = 1 << 0,
48     ForceTrailingExpansion = 2 << 0,
49     TrailingExpansionMask = 3 << 0,
50
51     ForbidLeadingExpansion = 0 << 2,
52     AllowLeadingExpansion = 1 << 2,
53     ForceLeadingExpansion = 2 << 2,
54     LeadingExpansionMask = 3 << 2,
55 };
56 typedef unsigned ExpansionBehavior;
57
58 enum FontSynthesisValues {
59     FontSynthesisNone = 0x0,
60     FontSynthesisWeight = 0x1,
61     FontSynthesisStyle = 0x2
62 };
63 typedef unsigned FontSynthesis;
64 const unsigned FontSynthesisWidth = 2;
65
66 enum class FontVariantLigatures {
67     Normal,
68     Yes,
69     No
70 };
71
72 enum class FontVariantPosition {
73     Normal,
74     Subscript,
75     Superscript
76 };
77
78 enum class FontVariantCaps {
79     Normal,
80     Small,
81     AllSmall,
82     Petite,
83     AllPetite,
84     Unicase,
85     Titling
86 };
87
88 enum class FontVariantNumericFigure {
89     Normal,
90     LiningNumbers,
91     OldStyleNumbers
92 };
93
94 enum class FontVariantNumericSpacing {
95     Normal,
96     ProportionalNumbers,
97     TabularNumbers
98 };
99
100 enum class FontVariantNumericFraction {
101     Normal,
102     DiagonalFractions,
103     StackedFractions
104 };
105
106 enum class FontVariantNumericOrdinal {
107     Normal,
108     Yes
109 };
110
111 enum class FontVariantNumericSlashedZero {
112     Normal,
113     Yes
114 };
115
116 enum class FontVariantAlternates {
117     Normal,
118     HistoricalForms
119 };
120
121 enum class FontVariantEastAsianVariant {
122     Normal,
123     Jis78,
124     Jis83,
125     Jis90,
126     Jis04,
127     Simplified,
128     Traditional
129 };
130
131 enum class FontVariantEastAsianWidth {
132     Normal,
133     Full,
134     Proportional
135 };
136
137 enum class FontVariantEastAsianRuby {
138     Normal,
139     Yes
140 };
141
142 struct FontVariantSettings {
143     FontVariantSettings()
144         : commonLigatures(FontVariantLigatures::Normal)
145         , discretionaryLigatures(FontVariantLigatures::Normal)
146         , historicalLigatures(FontVariantLigatures::Normal)
147         , contextualAlternates(FontVariantLigatures::Normal)
148         , position(FontVariantPosition::Normal)
149         , caps(FontVariantCaps::Normal)
150         , numericFigure(FontVariantNumericFigure::Normal)
151         , numericSpacing(FontVariantNumericSpacing::Normal)
152         , numericFraction(FontVariantNumericFraction::Normal)
153         , numericOrdinal(FontVariantNumericOrdinal::Normal)
154         , numericSlashedZero(FontVariantNumericSlashedZero::Normal)
155         , alternates(FontVariantAlternates::Normal)
156         , eastAsianVariant(FontVariantEastAsianVariant::Normal)
157         , eastAsianWidth(FontVariantEastAsianWidth::Normal)
158         , eastAsianRuby(FontVariantEastAsianRuby::Normal)
159     {
160     }
161
162     FontVariantSettings(
163         FontVariantLigatures commonLigatures,
164         FontVariantLigatures discretionaryLigatures,
165         FontVariantLigatures historicalLigatures,
166         FontVariantLigatures contextualAlternates,
167         FontVariantPosition position,
168         FontVariantCaps caps,
169         FontVariantNumericFigure numericFigure,
170         FontVariantNumericSpacing numericSpacing,
171         FontVariantNumericFraction numericFraction,
172         FontVariantNumericOrdinal numericOrdinal,
173         FontVariantNumericSlashedZero numericSlashedZero,
174         FontVariantAlternates alternates,
175         FontVariantEastAsianVariant eastAsianVariant,
176         FontVariantEastAsianWidth eastAsianWidth,
177         FontVariantEastAsianRuby eastAsianRuby)
178             : commonLigatures(commonLigatures)
179             , discretionaryLigatures(discretionaryLigatures)
180             , historicalLigatures(historicalLigatures)
181             , contextualAlternates(contextualAlternates)
182             , position(position)
183             , caps(caps)
184             , numericFigure(numericFigure)
185             , numericSpacing(numericSpacing)
186             , numericFraction(numericFraction)
187             , numericOrdinal(numericOrdinal)
188             , numericSlashedZero(numericSlashedZero)
189             , alternates(alternates)
190             , eastAsianVariant(eastAsianVariant)
191             , eastAsianWidth(eastAsianWidth)
192             , eastAsianRuby(eastAsianRuby)
193     {
194     }
195
196     bool isAllNormal() const
197     {
198         return commonLigatures == FontVariantLigatures::Normal
199             && discretionaryLigatures == FontVariantLigatures::Normal
200             && historicalLigatures == FontVariantLigatures::Normal
201             && contextualAlternates == FontVariantLigatures::Normal
202             && position == FontVariantPosition::Normal
203             && caps == FontVariantCaps::Normal
204             && numericFigure == FontVariantNumericFigure::Normal
205             && numericSpacing == FontVariantNumericSpacing::Normal
206             && numericFraction == FontVariantNumericFraction::Normal
207             && numericOrdinal == FontVariantNumericOrdinal::Normal
208             && numericSlashedZero == FontVariantNumericSlashedZero::Normal
209             && alternates == FontVariantAlternates::Normal
210             && eastAsianVariant == FontVariantEastAsianVariant::Normal
211             && eastAsianWidth == FontVariantEastAsianWidth::Normal
212             && eastAsianRuby == FontVariantEastAsianRuby::Normal;
213     }
214
215     bool operator==(const FontVariantSettings& other) const
216     {
217         return commonLigatures == other.commonLigatures
218             && discretionaryLigatures == other.discretionaryLigatures
219             && historicalLigatures == other.historicalLigatures
220             && contextualAlternates == other.contextualAlternates
221             && position == other.position
222             && caps == other.caps
223             && numericFigure == other.numericFigure
224             && numericSpacing == other.numericSpacing
225             && numericFraction == other.numericFraction
226             && numericOrdinal == other.numericOrdinal
227             && numericSlashedZero == other.numericSlashedZero
228             && alternates == other.alternates
229             && eastAsianVariant == other.eastAsianVariant
230             && eastAsianWidth == other.eastAsianWidth
231             && eastAsianRuby == other.eastAsianRuby;
232     }
233
234     bool operator!=(const FontVariantSettings& other) const { return !(*this == other); }
235
236     unsigned uniqueValue() const
237     {
238         return static_cast<unsigned>(commonLigatures) << 26
239             | static_cast<unsigned>(discretionaryLigatures) << 24
240             | static_cast<unsigned>(historicalLigatures) << 22
241             | static_cast<unsigned>(contextualAlternates) << 20
242             | static_cast<unsigned>(position) << 18
243             | static_cast<unsigned>(caps) << 15
244             | static_cast<unsigned>(numericFigure) << 13
245             | static_cast<unsigned>(numericSpacing) << 11
246             | static_cast<unsigned>(numericFraction) << 9
247             | static_cast<unsigned>(numericOrdinal) << 8
248             | static_cast<unsigned>(numericSlashedZero) << 7
249             | static_cast<unsigned>(alternates) << 6
250             | static_cast<unsigned>(eastAsianVariant) << 3
251             | static_cast<unsigned>(eastAsianWidth) << 1
252             | static_cast<unsigned>(eastAsianRuby) << 0;
253     }
254
255     FontVariantLigatures commonLigatures;
256     FontVariantLigatures discretionaryLigatures;
257     FontVariantLigatures historicalLigatures;
258     FontVariantLigatures contextualAlternates;
259     FontVariantPosition position;
260     FontVariantCaps caps;
261     FontVariantNumericFigure numericFigure;
262     FontVariantNumericSpacing numericSpacing;
263     FontVariantNumericFraction numericFraction;
264     FontVariantNumericOrdinal numericOrdinal;
265     FontVariantNumericSlashedZero numericSlashedZero;
266     FontVariantAlternates alternates;
267     FontVariantEastAsianVariant eastAsianVariant;
268     FontVariantEastAsianWidth eastAsianWidth;
269     FontVariantEastAsianRuby eastAsianRuby;
270 };
271
272 struct FontVariantLigaturesValues {
273     FontVariantLigaturesValues(
274         FontVariantLigatures commonLigatures,
275         FontVariantLigatures discretionaryLigatures,
276         FontVariantLigatures historicalLigatures,
277         FontVariantLigatures contextualAlternates)
278             : commonLigatures(commonLigatures)
279             , discretionaryLigatures(discretionaryLigatures)
280             , historicalLigatures(historicalLigatures)
281             , contextualAlternates(contextualAlternates)
282     {
283     }
284
285     FontVariantLigatures commonLigatures;
286     FontVariantLigatures discretionaryLigatures;
287     FontVariantLigatures historicalLigatures;
288     FontVariantLigatures contextualAlternates;
289 };
290
291 struct FontVariantNumericValues {
292     FontVariantNumericValues(
293         FontVariantNumericFigure figure,
294         FontVariantNumericSpacing spacing,
295         FontVariantNumericFraction fraction,
296         FontVariantNumericOrdinal ordinal,
297         FontVariantNumericSlashedZero slashedZero)
298             : figure(figure)
299             , spacing(spacing)
300             , fraction(fraction)
301             , ordinal(ordinal)
302             , slashedZero(slashedZero)
303     {
304     }
305
306     FontVariantNumericFigure figure;
307     FontVariantNumericSpacing spacing;
308     FontVariantNumericFraction fraction;
309     FontVariantNumericOrdinal ordinal;
310     FontVariantNumericSlashedZero slashedZero;
311 };
312
313 struct FontVariantEastAsianValues {
314     FontVariantEastAsianValues(
315         FontVariantEastAsianVariant variant,
316         FontVariantEastAsianWidth width,
317         FontVariantEastAsianRuby ruby)
318             : variant(variant)
319             , width(width)
320             , ruby(ruby)
321     {
322     }
323
324     FontVariantEastAsianVariant variant;
325     FontVariantEastAsianWidth width;
326     FontVariantEastAsianRuby ruby;
327 };
328
329 enum FontWidthVariant {
330     RegularWidth,
331     HalfWidth,
332     ThirdWidth,
333     QuarterWidth,
334     LastFontWidthVariant = QuarterWidth
335 };
336
337 const unsigned FontWidthVariantWidth = 2;
338
339 COMPILE_ASSERT(!(LastFontWidthVariant >> FontWidthVariantWidth), FontWidthVariantWidth_is_correct);
340
341 enum FontWeight {
342     FontWeight100,
343     FontWeight200,
344     FontWeight300,
345     FontWeight400,
346     FontWeight500,
347     FontWeight600,
348     FontWeight700,
349     FontWeight800,
350     FontWeight900,
351     FontWeightNormal = FontWeight400,
352     FontWeightBold = FontWeight700
353 };
354
355 enum FontItalic {
356     FontItalicOff = 0,
357     FontItalicOn = 1
358 };
359
360 enum FontSmallCaps {
361     FontSmallCapsOff = 0,
362     FontSmallCapsOn = 1
363 };
364
365 enum {
366     FontStyleNormalBit = 0,
367     FontStyleItalicBit,
368     FontWeight100Bit,
369     FontWeight200Bit,
370     FontWeight300Bit,
371     FontWeight400Bit,
372     FontWeight500Bit,
373     FontWeight600Bit,
374     FontWeight700Bit,
375     FontWeight800Bit,
376     FontWeight900Bit,
377     FontTraitsMaskWidth
378 };
379
380 enum FontTraitsMask {
381     FontStyleNormalMask = 1 << FontStyleNormalBit,
382     FontStyleItalicMask = 1 << FontStyleItalicBit,
383     FontStyleMask = FontStyleNormalMask | FontStyleItalicMask,
384
385     FontWeight100Mask = 1 << FontWeight100Bit,
386     FontWeight200Mask = 1 << FontWeight200Bit,
387     FontWeight300Mask = 1 << FontWeight300Bit,
388     FontWeight400Mask = 1 << FontWeight400Bit,
389     FontWeight500Mask = 1 << FontWeight500Bit,
390     FontWeight600Mask = 1 << FontWeight600Bit,
391     FontWeight700Mask = 1 << FontWeight700Bit,
392     FontWeight800Mask = 1 << FontWeight800Bit,
393     FontWeight900Mask = 1 << FontWeight900Bit,
394     FontWeightMask = FontWeight100Mask | FontWeight200Mask | FontWeight300Mask | FontWeight400Mask | FontWeight500Mask | FontWeight600Mask | FontWeight700Mask | FontWeight800Mask | FontWeight900Mask
395 };
396
397 enum class Kerning {
398     Auto,
399     Normal,
400     NoShift
401 };
402
403 }
404
405 #endif