fix logic
[personal-kdelibs.git] / khtml / rendering / bidi.h
blob664c714f2d8ee3db0226e2e39a41067041d7ccd1
1 /*
2 * This file is part of the html renderer for KDE.
4 * Copyright (C) 2000 Lars Knoll (knoll@kde.org)
5 * Copyright (C) 2003 Apple Computer, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
23 #ifndef BIDI_H
24 #define BIDI_H
26 #include <QtCore/QString>
28 namespace khtml {
29 class RenderArena;
30 class RenderObject;
31 class InlineBox;
33 class BidiContext {
34 public:
35 BidiContext(unsigned char level, QChar::Direction embedding, BidiContext *parent = 0, bool override = false);
36 ~BidiContext();
38 void ref() const;
39 void deref() const;
41 unsigned char level;
42 bool override : 1;
43 QChar::Direction dir : 5;
44 QChar::Direction basicDir : 5;
46 BidiContext *parent;
49 // refcounting....
50 mutable int count;
53 struct BidiRun {
54 BidiRun(int _start, int _stop, RenderObject *_obj, BidiContext *context, QChar::Direction dir)
55 : start( _start ), stop( _stop ), obj( _obj ), box(0), nextRun(0)
57 if(dir == QChar::DirON) dir = context->dir;
59 level = context->level;
61 // add level of run (cases I1 & I2)
62 if( level % 2 ) {
63 if(dir == QChar::DirL || dir == QChar::DirAN || dir == QChar::DirEN)
64 level++;
65 } else {
66 if( dir == QChar::DirR )
67 level++;
68 else if( dir == QChar::DirAN || dir == QChar::DirEN)
69 level += 2;
73 void detach(RenderArena* renderArena);
75 // Overloaded new operator.
76 void* operator new(size_t sz, RenderArena* renderArena) throw();
78 // Overridden to prevent the normal delete from being called.
79 void operator delete(void* ptr, size_t sz);
81 private:
82 // The normal operator new is disallowed.
83 void* operator new(size_t sz) throw();
85 public:
86 int start;
87 int stop;
89 RenderObject *obj;
90 InlineBox* box;
92 // explicit + implicit levels here
93 uchar level;
95 bool compact : 1;
97 BidiRun* nextRun;
100 struct BidiIterator;
101 struct BidiState;
103 struct BidiStatus {
104 BidiStatus() : eor(QChar::DirON), lastStrong(QChar::DirON), last(QChar::DirON) {}
106 QChar::Direction eor;
107 QChar::Direction lastStrong;
108 QChar::Direction last;
113 #endif