2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2003, 2004, 2006, 2007, 2008 Apple Inc. All right reserved.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
22 #ifndef BidiCharacterRun_h
23 #define BidiCharacterRun_h
25 #include "platform/text/BidiContext.h"
26 #include "platform/text/TextDirection.h"
30 struct BidiCharacterRun {
31 BidiCharacterRun(int start, int stop, BidiContext* context, WTF::Unicode::Direction dir)
32 : m_override(context->override())
37 ASSERT(m_start <= m_stop);
38 if (dir == WTF::Unicode::OtherNeutral)
41 m_level = context->level();
43 // add level of run (cases I1 & I2)
45 if (dir == WTF::Unicode::LeftToRight || dir == WTF::Unicode::ArabicNumber || dir == WTF::Unicode::EuropeanNumber)
48 if (dir == WTF::Unicode::RightToLeft)
50 else if (dir == WTF::Unicode::ArabicNumber || dir == WTF::Unicode::EuropeanNumber)
55 // BidiCharacterRun are allocated out of the rendering partition.
56 PLATFORM_EXPORT void* operator new(size_t);
57 PLATFORM_EXPORT void operator delete(void*);
59 int start() const { return m_start; }
60 int stop() const { return m_stop; }
61 unsigned char level() const { return m_level; }
62 bool reversed(bool visuallyOrdered) const { return m_level % 2 && !visuallyOrdered; }
63 bool dirOverride(bool visuallyOrdered) { return m_override || visuallyOrdered; }
64 TextDirection direction() const { return reversed(false) ? RTL : LTR; }
66 BidiCharacterRun* next() const { return m_next; }
67 void setNext(BidiCharacterRun* next) { m_next = next; }
69 // Do not add anything apart from bitfields until after m_next. See https://bugs.webkit.org/show_bug.cgi?id=100173
71 bool m_hasHyphen : 1; // Used by BidiRun subclass which is a layering violation but enables us to save 8 bytes per object on 64-bit.
72 bool m_startsSegment : 1; // Same comment as m_hasHyphen.
73 unsigned char m_level;
74 BidiCharacterRun* m_next;
79 } // namespace WebCore
81 #endif // BidiCharacterRun_h