Clean up TextRun-related code
[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     DefaultExpansion = AllowTrailingExpansion | ForbidLeadingExpansion,
57 };
58 typedef unsigned ExpansionBehavior;
59
60 enum FontSynthesisValues {
61     FontSynthesisNone = 0x0,
62     FontSynthesisWeight = 0x1,
63     FontSynthesisStyle = 0x2
64 };
65 typedef unsigned FontSynthesis;
66 const unsigned FontSynthesisWidth = 2;
67
68 enum class FontVariantLigatures {
69     Normal,
70     Yes,
71     No
72 };
73
74 enum class FontVariantPosition {
75     Normal,
76     Subscript,
77     Superscript
78 };
79
80 enum class FontVariantCaps {
81     Normal,
82     Small,
83     AllSmall,
84     Petite,
85     AllPetite,
86     Unicase,
87     Titling
88 };
89
90 enum class FontVariantNumericFigure {
91     Normal,
92     LiningNumbers,
93     OldStyleNumbers
94 };
95
96 enum class FontVariantNumericSpacing {
97     Normal,
98     ProportionalNumbers,
99     TabularNumbers
100 };
101
102 enum class FontVariantNumericFraction {
103     Normal,
104     DiagonalFractions,
105     StackedFractions
106 };
107
108 enum class FontVariantNumericOrdinal {
109     Normal,
110     Yes
111 };
112
113 enum class FontVariantNumericSlashedZero {
114     Normal,
115     Yes
116 };
117
118 enum class FontVariantAlternates {
119     Normal,
120     HistoricalForms
121 };
122
123 enum class FontVariantEastAsianVariant {
124     Normal,
125     Jis78,
126     Jis83,
127     Jis90,
128     Jis04,
129     Simplified,
130     Traditional
131 };
132
133 enum class FontVariantEastAsianWidth {
134     Normal,
135     Full,
136     Proportional
137 };
138
139 enum class FontVariantEastAsianRuby {
140     Normal,
141     Yes
142 };
143
144 struct FontVariantSettings {
145     FontVariantSettings()
146         : commonLigatures(FontVariantLigatures::Normal)
147         , discretionaryLigatures(FontVariantLigatures::Normal)
148         , historicalLigatures(FontVariantLigatures::Normal)
149         , contextualAlternates(FontVariantLigatures::Normal)
150         , position(FontVariantPosition::Normal)
151         , caps(FontVariantCaps::Normal)
152         , numericFigure(FontVariantNumericFigure::Normal)
153         , numericSpacing(FontVariantNumericSpacing::Normal)
154         , numericFraction(FontVariantNumericFraction::Normal)
155         , numericOrdinal(FontVariantNumericOrdinal::Normal)
156         , numericSlashedZero(FontVariantNumericSlashedZero::Normal)
157         , alternates(FontVariantAlternates::Normal)
158         , eastAsianVariant(FontVariantEastAsianVariant::Normal)
159         , eastAsianWidth(FontVariantEastAsianWidth::Normal)
160         , eastAsianRuby(FontVariantEastAsianRuby::Normal)
161     {
162     }
163
164     FontVariantSettings(
165         FontVariantLigatures commonLigatures,
166         FontVariantLigatures discretionaryLigatures,
167         FontVariantLigatures historicalLigatures,
168         FontVariantLigatures contextualAlternates,
169         FontVariantPosition position,
170         FontVariantCaps caps,
171         FontVariantNumericFigure numericFigure,
172         FontVariantNumericSpacing numericSpacing,
173         FontVariantNumericFraction numericFraction,
174         FontVariantNumericOrdinal numericOrdinal,
175         FontVariantNumericSlashedZero numericSlashedZero,
176         FontVariantAlternates alternates,
177         FontVariantEastAsianVariant eastAsianVariant,
178         FontVariantEastAsianWidth eastAsianWidth,
179         FontVariantEastAsianRuby eastAsianRuby)
180             : commonLigatures(commonLigatures)
181             , discretionaryLigatures(discretionaryLigatures)
182             , historicalLigatures(historicalLigatures)
183             , contextualAlternates(contextualAlternates)
184             , position(position)
185             , caps(caps)
186             , numericFigure(numericFigure)
187             , numericSpacing(numericSpacing)
188             , numericFraction(numericFraction)
189             , numericOrdinal(numericOrdinal)
190             , numericSlashedZero(numericSlashedZero)
191             , alternates(alternates)
192             , eastAsianVariant(eastAsianVariant)
193             , eastAsianWidth(eastAsianWidth)
194             , eastAsianRuby(eastAsianRuby)
195     {
196     }
197
198     bool isAllNormal() const
199     {
200         return commonLigatures == FontVariantLigatures::Normal
201             && discretionaryLigatures == FontVariantLigatures::Normal
202             && historicalLigatures == FontVariantLigatures::Normal
203             && contextualAlternates == FontVariantLigatures::Normal
204             && position == FontVariantPosition::Normal
205             && caps == FontVariantCaps::Normal
206             && numericFigure == FontVariantNumericFigure::Normal
207             && numericSpacing == FontVariantNumericSpacing::Normal
208             && numericFraction == FontVariantNumericFraction::Normal
209             && numericOrdinal == FontVariantNumericOrdinal::Normal
210             && numericSlashedZero == FontVariantNumericSlashedZero::Normal
211             && alternates == FontVariantAlternates::Normal
212             && eastAsianVariant == FontVariantEastAsianVariant::Normal
213             && eastAsianWidth == FontVariantEastAsianWidth::Normal
214             && eastAsianRuby == FontVariantEastAsianRuby::Normal;
215     }
216
217     bool operator==(const FontVariantSettings& other) const
218     {
219         return commonLigatures == other.commonLigatures
220             && discretionaryLigatures == other.discretionaryLigatures
221             && historicalLigatures == other.historicalLigatures
222             && contextualAlternates == other.contextualAlternates
223             && position == other.position
224             && caps == other.caps
225             && numericFigure == other.numericFigure
226             && numericSpacing == other.numericSpacing
227             && numericFraction == other.numericFraction
228             && numericOrdinal == other.numericOrdinal
229             && numericSlashedZero == other.numericSlashedZero
230             && alternates == other.alternates
231             && eastAsianVariant == other.eastAsianVariant
232             && eastAsianWidth == other.eastAsianWidth
233             && eastAsianRuby == other.eastAsianRuby;
234     }
235
236     bool operator!=(const FontVariantSettings& other) const { return !(*this == other); }
237
238     unsigned uniqueValue() const
239     {
240         return static_cast<unsigned>(commonLigatures) << 26
241             | static_cast<unsigned>(discretionaryLigatures) << 24
242             | static_cast<unsigned>(historicalLigatures) << 22
243             | static_cast<unsigned>(contextualAlternates) << 20
244             | static_cast<unsigned>(position) << 18
245             | static_cast<unsigned>(caps) << 15
246             | static_cast<unsigned>(numericFigure) << 13
247             | static_cast<unsigned>(numericSpacing) << 11
248             | static_cast<unsigned>(numericFraction) << 9
249             | static_cast<unsigned>(numericOrdinal) << 8
250             | static_cast<unsigned>(numericSlashedZero) << 7
251             | static_cast<unsigned>(alternates) << 6
252             | static_cast<unsigned>(eastAsianVariant) << 3
253             | static_cast<unsigned>(eastAsianWidth) << 1
254             | static_cast<unsigned>(eastAsianRuby) << 0;
255     }
256
257     FontVariantLigatures commonLigatures;
258     FontVariantLigatures discretionaryLigatures;
259     FontVariantLigatures historicalLigatures;
260     FontVariantLigatures contextualAlternates;
261     FontVariantPosition position;
262     FontVariantCaps caps;
263     FontVariantNumericFigure numericFigure;
264     FontVariantNumericSpacing numericSpacing;
265     FontVariantNumericFraction numericFraction;
266     FontVariantNumericOrdinal numericOrdinal;
267     FontVariantNumericSlashedZero numericSlashedZero;
268     FontVariantAlternates alternates;
269     FontVariantEastAsianVariant eastAsianVariant;
270     FontVariantEastAsianWidth eastAsianWidth;
271     FontVariantEastAsianRuby eastAsianRuby;
272 };
273
274 struct FontVariantLigaturesValues {
275     FontVariantLigaturesValues(
276         FontVariantLigatures commonLigatures,
277         FontVariantLigatures discretionaryLigatures,
278         FontVariantLigatures historicalLigatures,
279         FontVariantLigatures contextualAlternates)
280             : commonLigatures(commonLigatures)
281             , discretionaryLigatures(discretionaryLigatures)
282             , historicalLigatures(historicalLigatures)
283             , contextualAlternates(contextualAlternates)
284     {
285     }
286
287     FontVariantLigatures commonLigatures;
288     FontVariantLigatures discretionaryLigatures;
289     FontVariantLigatures historicalLigatures;
290     FontVariantLigatures contextualAlternates;
291 };
292
293 struct FontVariantNumericValues {
294     FontVariantNumericValues(
295         FontVariantNumericFigure figure,
296         FontVariantNumericSpacing spacing,
297         FontVariantNumericFraction fraction,
298         FontVariantNumericOrdinal ordinal,
299         FontVariantNumericSlashedZero slashedZero)
300             : figure(figure)
301             , spacing(spacing)
302             , fraction(fraction)
303             , ordinal(ordinal)
304             , slashedZero(slashedZero)
305     {
306     }
307
308     FontVariantNumericFigure figure;
309     FontVariantNumericSpacing spacing;
310     FontVariantNumericFraction fraction;
311     FontVariantNumericOrdinal ordinal;
312     FontVariantNumericSlashedZero slashedZero;
313 };
314
315 struct FontVariantEastAsianValues {
316     FontVariantEastAsianValues(
317         FontVariantEastAsianVariant variant,
318         FontVariantEastAsianWidth width,
319         FontVariantEastAsianRuby ruby)
320             : variant(variant)
321             , width(width)
322             , ruby(ruby)
323     {
324     }
325
326     FontVariantEastAsianVariant variant;
327     FontVariantEastAsianWidth width;
328     FontVariantEastAsianRuby ruby;
329 };
330
331 enum FontWidthVariant {
332     RegularWidth,
333     HalfWidth,
334     ThirdWidth,
335     QuarterWidth,
336     LastFontWidthVariant = QuarterWidth
337 };
338
339 const unsigned FontWidthVariantWidth = 2;
340
341 COMPILE_ASSERT(!(LastFontWidthVariant >> FontWidthVariantWidth), FontWidthVariantWidth_is_correct);
342
343 enum FontWeight {
344     FontWeight100,
345     FontWeight200,
346     FontWeight300,
347     FontWeight400,
348     FontWeight500,
349     FontWeight600,
350     FontWeight700,
351     FontWeight800,
352     FontWeight900,
353     FontWeightNormal = FontWeight400,
354     FontWeightBold = FontWeight700
355 };
356
357 enum FontItalic {
358     FontItalicOff = 0,
359     FontItalicOn = 1
360 };
361
362 enum FontSmallCaps {
363     FontSmallCapsOff = 0,
364     FontSmallCapsOn = 1
365 };
366
367 enum {
368     FontStyleNormalBit = 0,
369     FontStyleItalicBit,
370     FontWeight100Bit,
371     FontWeight200Bit,
372     FontWeight300Bit,
373     FontWeight400Bit,
374     FontWeight500Bit,
375     FontWeight600Bit,
376     FontWeight700Bit,
377     FontWeight800Bit,
378     FontWeight900Bit,
379     FontTraitsMaskWidth
380 };
381
382 enum FontTraitsMask {
383     FontStyleNormalMask = 1 << FontStyleNormalBit,
384     FontStyleItalicMask = 1 << FontStyleItalicBit,
385     FontStyleMask = FontStyleNormalMask | FontStyleItalicMask,
386
387     FontWeight100Mask = 1 << FontWeight100Bit,
388     FontWeight200Mask = 1 << FontWeight200Bit,
389     FontWeight300Mask = 1 << FontWeight300Bit,
390     FontWeight400Mask = 1 << FontWeight400Bit,
391     FontWeight500Mask = 1 << FontWeight500Bit,
392     FontWeight600Mask = 1 << FontWeight600Bit,
393     FontWeight700Mask = 1 << FontWeight700Bit,
394     FontWeight800Mask = 1 << FontWeight800Bit,
395     FontWeight900Mask = 1 << FontWeight900Bit,
396     FontWeightMask = FontWeight100Mask | FontWeight200Mask | FontWeight300Mask | FontWeight400Mask | FontWeight500Mask | FontWeight600Mask | FontWeight700Mask | FontWeight800Mask | FontWeight900Mask
397 };
398
399 enum class Kerning {
400     Auto,
401     Normal,
402     NoShift
403 };
404
405 }
406
407 #endif