Skip to content

Commit d9e9b8a

Browse files
author
Dimitri van Heesch
committed
Merge branch 'ahoogol-master'
2 parents 9538bfd + 989de07 commit d9e9b8a

17 files changed

+609
-186
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@
1313

1414
/doxygen_docs
1515
/doxygen.tag
16+
/build

qtools/qstring.cpp

Lines changed: 73 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11614,32 +11614,83 @@ static inline bool is_neutral(unsigned short dir) {
1161411614
#endif
1161511615

1161611616
/*!
11617-
This function returns the basic directionality of the string (QChar::DirR for
11618-
right to left and QChar::DirL for left to right). Useful to find the right
11619-
alignment.
11620-
*/
11621-
QChar::Direction QString::basicDirection()
11617+
This function returns the directionality of the string.
11618+
11619+
\returns a value of DirLTR, DirRTL, DirMixed or DirNeutral that indicates
11620+
if the entire text represented by this text is unidirectional,
11621+
and which direction, or if it is mixed-directional or all characters are neutral.
11622+
*/
11623+
QString::Direction QString::direction() const
1162211624
{
1162311625
#ifndef QT_NO_UNICODETABLES
11624-
// find base direction
11625-
unsigned int pos = 0;
11626-
while ((pos < length()) &&
11627-
(at(pos) != RLE) &&
11628-
(at(pos) != LRE) &&
11629-
(at(pos) != RLO) &&
11630-
(at(pos) != LRO) &&
11631-
(at(pos).direction() > 1) &&
11632-
(at(pos).direction() != QChar::DirAL)) // not R and not L
11633-
pos++;
11634-
11635-
if ((at(pos).direction() == QChar::DirR) ||
11636-
(at(pos).direction() == QChar::DirAL) ||
11637-
(at(pos) == RLE) ||
11638-
(at(pos) == RLO))
11639-
return QChar::DirR;
11626+
// find direction
11627+
unsigned char resultDir = DirNeutral;
11628+
for (unsigned int pos = 0; pos < length(); pos++)
11629+
{
11630+
if ((at(pos) != RLE) &&
11631+
(at(pos) != LRE) &&
11632+
(at(pos) != RLO) &&
11633+
(at(pos) != LRO) &&
11634+
(at(pos).direction() > 1) &&
11635+
(at(pos).direction() != QChar::DirAL)) // not R and not L
11636+
continue;
11637+
11638+
if ((at(pos).direction() == QChar::DirR) ||
11639+
(at(pos).direction() == QChar::DirAL) ||
11640+
(at(pos) == RLE) ||
11641+
(at(pos) == RLO))
11642+
resultDir |= DirRTL;
11643+
else
11644+
resultDir |= DirLTR;
11645+
if (resultDir == DirMixed)
11646+
return DirMixed;
11647+
}
11648+
return static_cast<Direction>(resultDir);
11649+
#else
11650+
return DirLTR;
1164011651
#endif
11652+
}
11653+
11654+
/*!
11655+
This function returns the basic directionality of the string. Useful to find the right
11656+
alignment.
1164111657
11642-
return QChar::DirL;
11658+
The base direction is derived from the first character in the string
11659+
with bidirectional character type L, R, or AL.
11660+
If the first such character has type L, DirLTR is returned.
11661+
If the first such character has type R or AL, DirRTL is returned.
11662+
If the string does not contain any character of these types, then DirNeutral is returned.
11663+
This is a lightweight function for use when only the base direction is needed and
11664+
no further bidi processing of the text is needed.
11665+
11666+
\returns DirRTL, DirLTR or DirNeutral
11667+
*/
11668+
QString::Direction QString::basicDirection() const
11669+
{
11670+
#ifndef QT_NO_UNICODETABLES
11671+
// find base direction
11672+
unsigned int pos = 0;
11673+
while ((pos < length()) &&
11674+
(at(pos) != RLE) &&
11675+
(at(pos) != LRE) &&
11676+
(at(pos) != RLO) &&
11677+
(at(pos) != LRO) &&
11678+
(at(pos).direction() > 1) &&
11679+
(at(pos).direction() != QChar::DirAL)) // not R and not L
11680+
pos++;
11681+
11682+
if (pos == length())
11683+
return DirNeutral;
11684+
11685+
if ((at(pos).direction() == QChar::DirR) ||
11686+
(at(pos).direction() == QChar::DirAL) ||
11687+
(at(pos) == RLE) ||
11688+
(at(pos) == RLO))
11689+
return DirRTL;
11690+
return DirLTR;
11691+
#else
11692+
return DirLTR;
11693+
#endif
1164311694
}
1164411695

1164511696
#ifndef QT_NO_UNICODETABLES

qtools/qstring.h

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,38 @@ class Q_EXPORT QString
369369
QString &operator=( QChar c );
370370
QString &operator=( char c );
371371

372+
enum Direction
373+
{
374+
/// No strongly directional text.
375+
/*!
376+
* As return value for direction() or baseDirection(), it means that the source string
377+
* is missing or empty, or contains neither left-to-right nor right-to-left characters.
378+
*/
379+
DirNeutral = 0x0,
380+
/// Left-to-right text.
381+
/*!
382+
* - As return value for direction(), it means that the source string
383+
* contains no right-to-left characters.
384+
* - As return value for basicDirection(), it means that the first strong character
385+
* of the source string has a left-to-right direction.
386+
*/
387+
DirLTR = 0b01,
388+
/// Right-to-left text.
389+
/*!
390+
* - As return value for direction(), it means that the source string
391+
* contains no left-to-right characters.
392+
* - As return value for basicDirection(), it means that the first strong character
393+
* of the source string has a right-to-left direction.
394+
*/
395+
DirRTL = 0b10,
396+
/// Mixed-directional text
397+
/*!
398+
* As return value for direction(), it means that the source string
399+
* contains both left-to-right and right-to-left characters.
400+
*/
401+
DirMixed = 0b11
402+
};
403+
372404
//QT_STATIC_CONST QString null;
373405
//bool isNull() const;
374406

@@ -535,8 +567,9 @@ class Q_EXPORT QString
535567
#endif
536568
// new functions for BiDi
537569
void compose();
538-
QChar::Direction basicDirection();
539-
QString visual(int index = 0, int len = -1);
570+
QString::Direction direction() const;
571+
QString::Direction basicDirection() const;
572+
QString visual(int index = 0, int len = -1);
540573

541574
#ifndef QT_NO_COMPAT
542575
const char* data() const { return latin1(); }

src/config.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,19 @@ Go to the <a href="commands.html">next</a> section or return to the
343343
<value name='Ukrainian'/>
344344
<value name='Vietnamese'/>
345345
</option>
346+
<option type='enum' id='OUTPUT_TEXT_DIRECTION' defval='None'>
347+
<docs>
348+
<![CDATA[
349+
The \c OUTPUT_TEXT_DIRECTION tag is used to specify the direction in which all
350+
documentation generated by doxygen is written. Doxygen will use this
351+
information to generate all generated output in the proper direction.
352+
]]>
353+
</docs>
354+
<value name='None'/>
355+
<value name='LTR'/>
356+
<value name='RTL'/>
357+
<value name='Context'/>
358+
</option>
346359
<option type='bool' id='BRIEF_MEMBER_DESC' defval='1'>
347360
<docs>
348361
<![CDATA[

src/docparser.cpp

Lines changed: 122 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7232,8 +7232,129 @@ static QCString processCopyDoc(const char *data,uint &len)
72327232
buf.addChar(0);
72337233
return buf.get();
72347234
}
7235+
//---------------------------------------------------------------------------
7236+
QString::Direction getTextDirByConfig(const QString &text)
7237+
{
7238+
QCString configDir = Config_getEnum(OUTPUT_TEXT_DIRECTION);
7239+
if (configDir == "None")
7240+
return QString::DirNeutral;
7241+
if (configDir == "Context")
7242+
return text.basicDirection();
7243+
if (configDir == "LTR")
7244+
{
7245+
QString::Direction textDir = text.direction();
7246+
if (textDir == QString::DirMixed)
7247+
return QString::DirLTR;
7248+
return textDir;
7249+
}
7250+
if (configDir == "RTL")
7251+
{
7252+
QString::Direction textDir = text.direction();
7253+
if (textDir == QString::DirMixed)
7254+
return QString::DirRTL;
7255+
return textDir;
7256+
}
7257+
return QString::DirNeutral;
7258+
}
72357259

7236-
//--------------------------------------------------------------------------
7260+
QString::Direction getTextDirByConfig(const DocNode *node)
7261+
{
7262+
QCString configDir = Config_getEnum(OUTPUT_TEXT_DIRECTION);
7263+
if (configDir == "None")
7264+
return QString::DirNeutral;
7265+
if (configDir == "Context")
7266+
return node->getTextBasicDir();
7267+
if (configDir == "LTR")
7268+
{
7269+
QString::Direction textDir = node->getTextDir();
7270+
if (textDir == QString::DirMixed)
7271+
return QString::DirLTR;
7272+
return textDir;
7273+
}
7274+
if (configDir == "RTL")
7275+
{
7276+
QString::Direction textDir = node->getTextDir();
7277+
if (textDir == QString::DirMixed)
7278+
return QString::DirRTL;
7279+
return textDir;
7280+
}
7281+
return QString::DirNeutral;
7282+
}
7283+
7284+
QString::Direction getTextDirByConfig(const DocPara *para, int nodeIndex)
7285+
{
7286+
QCString configDir = Config_getEnum(OUTPUT_TEXT_DIRECTION);
7287+
if (configDir == "None")
7288+
return QString::DirNeutral;
7289+
if (configDir == "Context")
7290+
return para->getTextBasicDir(nodeIndex);
7291+
if (configDir == "LTR")
7292+
{
7293+
QString::Direction textDir = para->getTextDir(nodeIndex);
7294+
if (textDir == QString::DirMixed)
7295+
return QString::DirLTR;
7296+
return textDir;
7297+
}
7298+
if (configDir == "RTL")
7299+
{
7300+
QString::Direction textDir = para->getTextDir(nodeIndex);
7301+
if (textDir == QString::DirMixed)
7302+
return QString::DirRTL;
7303+
return textDir;
7304+
}
7305+
return QString::DirNeutral;
7306+
}
7307+
7308+
QCString getDirHtmlClassOfNode(QString::Direction textDir, const char *initValue)
7309+
{
7310+
QCString classFromDir;
7311+
if (textDir == QString::DirLTR)
7312+
classFromDir = "DocNodeLTR";
7313+
else if (textDir == QString::DirRTL)
7314+
classFromDir = "DocNodeRTL";
7315+
else
7316+
classFromDir = "";
7317+
7318+
if (initValue != NULL && !classFromDir.isEmpty())
7319+
return QCString(" class=\"") + initValue + " " + classFromDir + "\"";
7320+
if (initValue != NULL)
7321+
return QCString(" class=\"") + initValue + "\"";
7322+
if (!classFromDir.isEmpty())
7323+
return QCString(" class=\"") + classFromDir + "\"";
7324+
return "";
7325+
}
7326+
7327+
QCString getDirHtmlClassOfPage(QCString pageTitle)
7328+
{
7329+
QCString result = "";
7330+
result += " class=\"PageDoc";
7331+
QString::Direction titleDir = getTextDirByConfig(pageTitle);
7332+
if (titleDir == QString::DirLTR)
7333+
result += " PageDocLTR-title";
7334+
else if (titleDir == QString::DirRTL)
7335+
result += " PageDocRTL-title";
7336+
result += "\"";
7337+
return result;
7338+
}
7339+
7340+
QCString getHtmlDirEmbedingChar(QString::Direction textDir)
7341+
{
7342+
if (textDir == QString::DirLTR)
7343+
return "&#x202A;";
7344+
if (textDir == QString::DirRTL)
7345+
return "&#x202B;";
7346+
return "";
7347+
}
7348+
7349+
QCString getJsDirEmbedingChar(QString::Direction textDir)
7350+
{
7351+
if (textDir == QString::DirLTR)
7352+
return "\\u202A";
7353+
if (textDir == QString::DirRTL)
7354+
return "\\u202B";
7355+
return "";
7356+
}
7357+
//---------------------------------------------------------------------------
72377358

72387359
DocRoot *validatingParseDoc(const char *fileName,int startLine,
72397360
Definition *ctx,MemberDef *md,

0 commit comments

Comments
 (0)