1 /*
2 * Copyright (C) 2010 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 COMPUTER, 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 COMPUTER, 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 THIRD_PARTY_BLINK_RENDERER_PLATFORM_FONTS_FONT_ORIENTATION_H_
27 #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_FONTS_FONT_ORIENTATION_H_
28
29 #include "third_party/blink/renderer/platform/platform_export.h"
30 #include "third_party/blink/renderer/platform/text/character.h"
31 #include "third_party/blink/renderer/platform/wtf/forward.h"
32
33 namespace blink {
34
35 enum class FontOrientation {
36 // Horizontal; i.e., writing-mode: horizontal-tb
37 kHorizontal = 0,
38 // Baseline is vertical but use rotated horizontal typography;
39 // i.e., writing-mode: vertical-*; text-orientation: sideways-*
40 kVerticalRotated = 1,
41 // Vertical with upright CJK and rotated non-CJK;
42 // i.e., writing-mode: vertical-*, text-orientation: mixed
43 kVerticalMixed = 2,
44 // Vertical with all upright;
45 // i.e., writing-mode: vertical-*, text-orientation: upright
46 kVerticalUpright = 3,
47 };
48 const unsigned kFontOrientationBitCount = 2;
49 const unsigned kFontOrientationAnyUprightMask = 2;
50
IsVerticalAnyUpright(FontOrientation orientation)51 inline bool IsVerticalAnyUpright(FontOrientation orientation) {
52 return static_cast<unsigned>(orientation) & kFontOrientationAnyUprightMask;
53 }
IsVerticalNonCJKUpright(FontOrientation orientation)54 inline bool IsVerticalNonCJKUpright(FontOrientation orientation) {
55 return orientation == FontOrientation::kVerticalUpright;
56 }
IsVerticalUpright(FontOrientation orientation,UChar32 character)57 inline bool IsVerticalUpright(FontOrientation orientation, UChar32 character) {
58 return orientation == FontOrientation::kVerticalUpright ||
59 (orientation == FontOrientation::kVerticalMixed &&
60 Character::IsUprightInMixedVertical(character));
61 }
IsVerticalBaseline(FontOrientation orientation)62 inline bool IsVerticalBaseline(FontOrientation orientation) {
63 return orientation != FontOrientation::kHorizontal;
64 }
65
AdjustOrientationForCharacterInMixedVertical(FontOrientation orientation,UChar32 character)66 inline FontOrientation AdjustOrientationForCharacterInMixedVertical(
67 FontOrientation orientation,
68 UChar32 character) {
69 if (orientation != FontOrientation::kVerticalMixed)
70 return orientation;
71 return Character::IsUprightInMixedVertical(character)
72 ? FontOrientation::kVerticalUpright
73 : FontOrientation::kVerticalRotated;
74 }
75
76 PLATFORM_EXPORT String ToString(FontOrientation);
77
78 } // namespace blink
79
80 #endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_FONTS_FONT_ORIENTATION_H_
81