| 1 | /* |
| 2 | * Copyright (C) 2003, 2006, 2017 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 | #pragma once |
| 27 | |
| 28 | namespace WebCore { |
| 29 | |
| 30 | enum class TextRenderingMode : uint8_t { |
| 31 | AutoTextRendering, |
| 32 | OptimizeSpeed, |
| 33 | OptimizeLegibility, |
| 34 | GeometricPrecision |
| 35 | }; |
| 36 | |
| 37 | enum class FontSmoothingMode : uint8_t { |
| 38 | AutoSmoothing, |
| 39 | NoSmoothing, |
| 40 | Antialiased, |
| 41 | SubpixelAntialiased |
| 42 | }; |
| 43 | |
| 44 | // This setting is used to provide ways of switching between multiple rendering modes that may have different |
| 45 | // metrics. It is used to switch between CG and GDI text on Windows. |
| 46 | enum class FontRenderingMode : uint8_t { |
| 47 | Normal, |
| 48 | Alternate |
| 49 | }; |
| 50 | |
| 51 | enum class FontOrientation : uint8_t { |
| 52 | Horizontal, |
| 53 | Vertical |
| 54 | }; |
| 55 | |
| 56 | enum class NonCJKGlyphOrientation : uint8_t { |
| 57 | Mixed, |
| 58 | Upright |
| 59 | }; |
| 60 | |
| 61 | // Here, "Leading" and "Trailing" are relevant after the line has been rearranged for bidi. |
| 62 | // ("Leading" means "left" and "Trailing" means "right.") |
| 63 | enum ExpansionBehaviorFlags { |
| 64 | ForbidTrailingExpansion = 0 << 0, |
| 65 | AllowTrailingExpansion = 1 << 0, |
| 66 | ForceTrailingExpansion = 2 << 0, |
| 67 | TrailingExpansionMask = 3 << 0, |
| 68 | |
| 69 | ForbidLeadingExpansion = 0 << 2, |
| 70 | AllowLeadingExpansion = 1 << 2, |
| 71 | ForceLeadingExpansion = 2 << 2, |
| 72 | LeadingExpansionMask = 3 << 2, |
| 73 | |
| 74 | DefaultExpansion = AllowTrailingExpansion | ForbidLeadingExpansion, |
| 75 | }; |
| 76 | typedef unsigned ExpansionBehavior; |
| 77 | |
| 78 | enum FontSynthesisValues { |
| 79 | FontSynthesisNone = 0x0, |
| 80 | FontSynthesisWeight = 0x1, |
| 81 | FontSynthesisStyle = 0x2, |
| 82 | FontSynthesisSmallCaps = 0x4 |
| 83 | }; |
| 84 | typedef unsigned FontSynthesis; |
| 85 | const unsigned FontSynthesisWidth = 3; |
| 86 | |
| 87 | enum class FontVariantLigatures : uint8_t { |
| 88 | Normal, |
| 89 | Yes, |
| 90 | No |
| 91 | }; |
| 92 | |
| 93 | enum class FontVariantPosition : uint8_t { |
| 94 | Normal, |
| 95 | Subscript, |
| 96 | Superscript |
| 97 | }; |
| 98 | |
| 99 | enum class FontVariantCaps : uint8_t { |
| 100 | Normal, |
| 101 | Small, |
| 102 | AllSmall, |
| 103 | Petite, |
| 104 | AllPetite, |
| 105 | Unicase, |
| 106 | Titling |
| 107 | }; |
| 108 | |
| 109 | enum class FontVariantNumericFigure : uint8_t { |
| 110 | Normal, |
| 111 | LiningNumbers, |
| 112 | OldStyleNumbers |
| 113 | }; |
| 114 | |
| 115 | enum class FontVariantNumericSpacing : uint8_t { |
| 116 | Normal, |
| 117 | ProportionalNumbers, |
| 118 | TabularNumbers |
| 119 | }; |
| 120 | |
| 121 | enum class FontVariantNumericFraction : uint8_t { |
| 122 | Normal, |
| 123 | DiagonalFractions, |
| 124 | StackedFractions |
| 125 | }; |
| 126 | |
| 127 | enum class FontVariantNumericOrdinal : uint8_t { |
| 128 | Normal, |
| 129 | Yes |
| 130 | }; |
| 131 | |
| 132 | enum class FontVariantNumericSlashedZero : uint8_t { |
| 133 | Normal, |
| 134 | Yes |
| 135 | }; |
| 136 | |
| 137 | enum class FontVariantAlternates : uint8_t { |
| 138 | Normal, |
| 139 | HistoricalForms |
| 140 | }; |
| 141 | |
| 142 | enum class FontVariantEastAsianVariant : uint8_t { |
| 143 | Normal, |
| 144 | Jis78, |
| 145 | Jis83, |
| 146 | Jis90, |
| 147 | Jis04, |
| 148 | Simplified, |
| 149 | Traditional |
| 150 | }; |
| 151 | |
| 152 | enum class FontVariantEastAsianWidth : uint8_t { |
| 153 | Normal, |
| 154 | Full, |
| 155 | Proportional |
| 156 | }; |
| 157 | |
| 158 | enum class FontVariantEastAsianRuby : uint8_t { |
| 159 | Normal, |
| 160 | Yes |
| 161 | }; |
| 162 | |
| 163 | struct FontVariantSettings { |
| 164 | FontVariantSettings() |
| 165 | : commonLigatures(FontVariantLigatures::Normal) |
| 166 | , discretionaryLigatures(FontVariantLigatures::Normal) |
| 167 | , historicalLigatures(FontVariantLigatures::Normal) |
| 168 | , contextualAlternates(FontVariantLigatures::Normal) |
| 169 | , position(FontVariantPosition::Normal) |
| 170 | , caps(FontVariantCaps::Normal) |
| 171 | , numericFigure(FontVariantNumericFigure::Normal) |
| 172 | , numericSpacing(FontVariantNumericSpacing::Normal) |
| 173 | , numericFraction(FontVariantNumericFraction::Normal) |
| 174 | , numericOrdinal(FontVariantNumericOrdinal::Normal) |
| 175 | , numericSlashedZero(FontVariantNumericSlashedZero::Normal) |
| 176 | , alternates(FontVariantAlternates::Normal) |
| 177 | , eastAsianVariant(FontVariantEastAsianVariant::Normal) |
| 178 | , eastAsianWidth(FontVariantEastAsianWidth::Normal) |
| 179 | , eastAsianRuby(FontVariantEastAsianRuby::Normal) |
| 180 | { |
| 181 | } |
| 182 | |
| 183 | FontVariantSettings( |
| 184 | FontVariantLigatures commonLigatures, |
| 185 | FontVariantLigatures discretionaryLigatures, |
| 186 | FontVariantLigatures historicalLigatures, |
| 187 | FontVariantLigatures contextualAlternates, |
| 188 | FontVariantPosition position, |
| 189 | FontVariantCaps caps, |
| 190 | FontVariantNumericFigure numericFigure, |
| 191 | FontVariantNumericSpacing numericSpacing, |
| 192 | FontVariantNumericFraction numericFraction, |
| 193 | FontVariantNumericOrdinal numericOrdinal, |
| 194 | FontVariantNumericSlashedZero numericSlashedZero, |
| 195 | FontVariantAlternates alternates, |
| 196 | FontVariantEastAsianVariant eastAsianVariant, |
| 197 | FontVariantEastAsianWidth eastAsianWidth, |
| 198 | FontVariantEastAsianRuby eastAsianRuby) |
| 199 | : commonLigatures(commonLigatures) |
| 200 | , discretionaryLigatures(discretionaryLigatures) |
| 201 | , historicalLigatures(historicalLigatures) |
| 202 | , contextualAlternates(contextualAlternates) |
| 203 | , position(position) |
| 204 | , caps(caps) |
| 205 | , numericFigure(numericFigure) |
| 206 | , numericSpacing(numericSpacing) |
| 207 | , numericFraction(numericFraction) |
| 208 | , numericOrdinal(numericOrdinal) |
| 209 | , numericSlashedZero(numericSlashedZero) |
| 210 | , alternates(alternates) |
| 211 | , eastAsianVariant(eastAsianVariant) |
| 212 | , eastAsianWidth(eastAsianWidth) |
| 213 | , eastAsianRuby(eastAsianRuby) |
| 214 | { |
| 215 | } |
| 216 | |
| 217 | bool isAllNormal() const |
| 218 | { |
| 219 | return commonLigatures == FontVariantLigatures::Normal |
| 220 | && discretionaryLigatures == FontVariantLigatures::Normal |
| 221 | && historicalLigatures == FontVariantLigatures::Normal |
| 222 | && contextualAlternates == FontVariantLigatures::Normal |
| 223 | && position == FontVariantPosition::Normal |
| 224 | && caps == FontVariantCaps::Normal |
| 225 | && numericFigure == FontVariantNumericFigure::Normal |
| 226 | && numericSpacing == FontVariantNumericSpacing::Normal |
| 227 | && numericFraction == FontVariantNumericFraction::Normal |
| 228 | && numericOrdinal == FontVariantNumericOrdinal::Normal |
| 229 | && numericSlashedZero == FontVariantNumericSlashedZero::Normal |
| 230 | && alternates == FontVariantAlternates::Normal |
| 231 | && eastAsianVariant == FontVariantEastAsianVariant::Normal |
| 232 | && eastAsianWidth == FontVariantEastAsianWidth::Normal |
| 233 | && eastAsianRuby == FontVariantEastAsianRuby::Normal; |
| 234 | } |
| 235 | |
| 236 | bool operator==(const FontVariantSettings& other) const |
| 237 | { |
| 238 | return commonLigatures == other.commonLigatures |
| 239 | && discretionaryLigatures == other.discretionaryLigatures |
| 240 | && historicalLigatures == other.historicalLigatures |
| 241 | && contextualAlternates == other.contextualAlternates |
| 242 | && position == other.position |
| 243 | && caps == other.caps |
| 244 | && numericFigure == other.numericFigure |
| 245 | && numericSpacing == other.numericSpacing |
| 246 | && numericFraction == other.numericFraction |
| 247 | && numericOrdinal == other.numericOrdinal |
| 248 | && numericSlashedZero == other.numericSlashedZero |
| 249 | && alternates == other.alternates |
| 250 | && eastAsianVariant == other.eastAsianVariant |
| 251 | && eastAsianWidth == other.eastAsianWidth |
| 252 | && eastAsianRuby == other.eastAsianRuby; |
| 253 | } |
| 254 | |
| 255 | bool operator!=(const FontVariantSettings& other) const { return !(*this == other); } |
| 256 | |
| 257 | unsigned uniqueValue() const |
| 258 | { |
| 259 | return static_cast<unsigned>(commonLigatures) << 26 |
| 260 | | static_cast<unsigned>(discretionaryLigatures) << 24 |
| 261 | | static_cast<unsigned>(historicalLigatures) << 22 |
| 262 | | static_cast<unsigned>(contextualAlternates) << 20 |
| 263 | | static_cast<unsigned>(position) << 18 |
| 264 | | static_cast<unsigned>(caps) << 15 |
| 265 | | static_cast<unsigned>(numericFigure) << 13 |
| 266 | | static_cast<unsigned>(numericSpacing) << 11 |
| 267 | | static_cast<unsigned>(numericFraction) << 9 |
| 268 | | static_cast<unsigned>(numericOrdinal) << 8 |
| 269 | | static_cast<unsigned>(numericSlashedZero) << 7 |
| 270 | | static_cast<unsigned>(alternates) << 6 |
| 271 | | static_cast<unsigned>(eastAsianVariant) << 3 |
| 272 | | static_cast<unsigned>(eastAsianWidth) << 1 |
| 273 | | static_cast<unsigned>(eastAsianRuby) << 0; |
| 274 | } |
| 275 | |
| 276 | // FIXME: this would be much more compact with bitfields. |
| 277 | FontVariantLigatures commonLigatures; |
| 278 | FontVariantLigatures discretionaryLigatures; |
| 279 | FontVariantLigatures historicalLigatures; |
| 280 | FontVariantLigatures contextualAlternates; |
| 281 | FontVariantPosition position; |
| 282 | FontVariantCaps caps; |
| 283 | FontVariantNumericFigure numericFigure; |
| 284 | FontVariantNumericSpacing numericSpacing; |
| 285 | FontVariantNumericFraction numericFraction; |
| 286 | FontVariantNumericOrdinal numericOrdinal; |
| 287 | FontVariantNumericSlashedZero numericSlashedZero; |
| 288 | FontVariantAlternates alternates; |
| 289 | FontVariantEastAsianVariant eastAsianVariant; |
| 290 | FontVariantEastAsianWidth eastAsianWidth; |
| 291 | FontVariantEastAsianRuby eastAsianRuby; |
| 292 | }; |
| 293 | |
| 294 | struct FontVariantLigaturesValues { |
| 295 | FontVariantLigaturesValues( |
| 296 | FontVariantLigatures commonLigatures, |
| 297 | FontVariantLigatures discretionaryLigatures, |
| 298 | FontVariantLigatures historicalLigatures, |
| 299 | FontVariantLigatures contextualAlternates) |
| 300 | : commonLigatures(commonLigatures) |
| 301 | , discretionaryLigatures(discretionaryLigatures) |
| 302 | , historicalLigatures(historicalLigatures) |
| 303 | , contextualAlternates(contextualAlternates) |
| 304 | { |
| 305 | } |
| 306 | |
| 307 | FontVariantLigatures commonLigatures; |
| 308 | FontVariantLigatures discretionaryLigatures; |
| 309 | FontVariantLigatures historicalLigatures; |
| 310 | FontVariantLigatures contextualAlternates; |
| 311 | }; |
| 312 | |
| 313 | struct FontVariantNumericValues { |
| 314 | FontVariantNumericValues( |
| 315 | FontVariantNumericFigure figure, |
| 316 | FontVariantNumericSpacing spacing, |
| 317 | FontVariantNumericFraction fraction, |
| 318 | FontVariantNumericOrdinal ordinal, |
| 319 | FontVariantNumericSlashedZero slashedZero) |
| 320 | : figure(figure) |
| 321 | , spacing(spacing) |
| 322 | , fraction(fraction) |
| 323 | , ordinal(ordinal) |
| 324 | , slashedZero(slashedZero) |
| 325 | { |
| 326 | } |
| 327 | |
| 328 | FontVariantNumericFigure figure; |
| 329 | FontVariantNumericSpacing spacing; |
| 330 | FontVariantNumericFraction fraction; |
| 331 | FontVariantNumericOrdinal ordinal; |
| 332 | FontVariantNumericSlashedZero slashedZero; |
| 333 | }; |
| 334 | |
| 335 | struct FontVariantEastAsianValues { |
| 336 | FontVariantEastAsianValues( |
| 337 | FontVariantEastAsianVariant variant, |
| 338 | FontVariantEastAsianWidth width, |
| 339 | FontVariantEastAsianRuby ruby) |
| 340 | : variant(variant) |
| 341 | , width(width) |
| 342 | , ruby(ruby) |
| 343 | { |
| 344 | } |
| 345 | |
| 346 | FontVariantEastAsianVariant variant; |
| 347 | FontVariantEastAsianWidth width; |
| 348 | FontVariantEastAsianRuby ruby; |
| 349 | }; |
| 350 | |
| 351 | enum class FontWidthVariant : uint8_t { |
| 352 | RegularWidth, |
| 353 | HalfWidth, |
| 354 | ThirdWidth, |
| 355 | QuarterWidth, |
| 356 | LastFontWidthVariant = QuarterWidth |
| 357 | }; |
| 358 | |
| 359 | const unsigned FontWidthVariantWidth = 2; |
| 360 | |
| 361 | COMPILE_ASSERT(!(static_cast<unsigned>(FontWidthVariant::LastFontWidthVariant) >> FontWidthVariantWidth), FontWidthVariantWidth_is_correct); |
| 362 | |
| 363 | enum class FontSmallCaps : uint8_t { |
| 364 | Off = 0, |
| 365 | On = 1 |
| 366 | }; |
| 367 | |
| 368 | enum class Kerning : uint8_t { |
| 369 | Auto, |
| 370 | Normal, |
| 371 | NoShift |
| 372 | }; |
| 373 | |
| 374 | enum class FontOpticalSizing : uint8_t { |
| 375 | Enabled, |
| 376 | Disabled |
| 377 | }; |
| 378 | |
| 379 | // https://www.microsoft.com/typography/otspec/fvar.htm#VAT |
| 380 | enum class FontStyleAxis : uint8_t { |
| 381 | slnt, |
| 382 | ital |
| 383 | }; |
| 384 | |
| 385 | enum class AllowUserInstalledFonts : uint8_t { |
| 386 | No, |
| 387 | Yes |
| 388 | }; |
| 389 | |
| 390 | } |
| 391 | |