1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
/*
* Copyright (C) 2000 Lars Knoll (knoll@kde.org)
* Copyright (C) 2003, 2004, 2006, 2007, 2008 Apple Inc. All right reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#ifndef BidiCharacterRun_h
#define BidiCharacterRun_h
#include "platform/text/BidiContext.h"
#include "platform/text/TextDirection.h"
namespace blink {
struct BidiCharacterRun {
BidiCharacterRun(bool override,
unsigned char level,
int start,
int stop,
WTF::Unicode::CharDirection dir,
WTF::Unicode::CharDirection overrideDir)
: m_override(override),
m_level(level),
m_next(0),
m_start(start),
m_stop(stop) {
ASSERT(m_start <= m_stop);
if (dir == WTF::Unicode::OtherNeutral)
dir = overrideDir;
m_level = level;
// add level of run (cases I1 & I2)
if (m_level % 2) {
if (dir == WTF::Unicode::LeftToRight ||
dir == WTF::Unicode::ArabicNumber ||
dir == WTF::Unicode::EuropeanNumber)
m_level++;
} else {
if (dir == WTF::Unicode::RightToLeft)
m_level++;
else if (dir == WTF::Unicode::ArabicNumber ||
dir == WTF::Unicode::EuropeanNumber)
m_level += 2;
}
}
BidiCharacterRun(int start, int stop, unsigned char level)
: m_override(false),
m_level(level),
m_next(0),
m_start(start),
m_stop(stop) {}
// BidiCharacterRun are allocated out of the rendering partition.
PLATFORM_EXPORT void* operator new(size_t);
PLATFORM_EXPORT void operator delete(void*);
int start() const { return m_start; }
int stop() const { return m_stop; }
unsigned char level() const { return m_level; }
bool reversed(bool visuallyOrdered) const {
return m_level % 2 && !visuallyOrdered;
}
bool dirOverride(bool visuallyOrdered) {
return m_override || visuallyOrdered;
}
TextDirection direction() const {
return reversed(false) ? TextDirection::kRtl : TextDirection::kLtr;
}
BidiCharacterRun* next() const { return m_next; }
void setNext(BidiCharacterRun* next) { m_next = next; }
// Do not add anything apart from bitfields until after m_next. See
// https://bugs.webkit.org/show_bug.cgi?id=100173
bool m_override : 1;
// Used by BidiRun subclass which is a layering violation but enables us to
// save 8 bytes per object on 64-bit.
bool m_hasHyphen : 1;
unsigned char m_level;
BidiCharacterRun* m_next;
int m_start;
int m_stop;
};
} // namespace blink
#endif // BidiCharacterRun_h
|