constexpr sal_Unicode cLRE_Embedding = 0x202A; // the start char of an LRE embedding
constexpr sal_Unicode cRLE_Embedding = 0x202B; // the start char of an RLE embedding
constexpr sal_Unicode cPopDirectionalFormat = 0x202C; // the unicode PDF (POP_DIRECTIONAL_FORMAT) char that terminates an LRE/RLE embedding
// check if there are already embedding characters at the strings start // if so change nothing const sal_Unicode cChar = rText[0]; if (cChar == cLRE_Embedding || cChar == cRLE_Embedding) return rText;
// since we only call the function getCharacterDirection // it does not matter which locale the CharClass is for. // Thus we can readily make use of SvtSysLocale::GetCharClass() // which should come at no cost...
SvtSysLocale aSysLocale; const CharClass &rCharClass = aSysLocale.GetCharClass();
// we should look for the first non-neutral LTR or RTL character // and use that to determine the embedding of the whole text... // Thus we can avoid to check every character of the text. bool bFound = false; bool bIsRtlText = false; for (sal_Int32 i = 0; i < nLen && !bFound; ++i)
{
i18n::DirectionProperty nDirection = rCharClass.getCharacterDirection( rText, i ); switch (nDirection)
{ case i18n::DirectionProperty_LEFT_TO_RIGHT : case i18n::DirectionProperty_LEFT_TO_RIGHT_EMBEDDING : case i18n::DirectionProperty_LEFT_TO_RIGHT_OVERRIDE : case i18n::DirectionProperty_EUROPEAN_NUMBER : case i18n::DirectionProperty_ARABIC_NUMBER : // yes! arabic numbers are written from left to right
{
bIsRtlText = false;
bFound = true; break;
}
case i18n::DirectionProperty_RIGHT_TO_LEFT : case i18n::DirectionProperty_RIGHT_TO_LEFT_ARABIC : case i18n::DirectionProperty_RIGHT_TO_LEFT_EMBEDDING : case i18n::DirectionProperty_RIGHT_TO_LEFT_OVERRIDE :
{
bIsRtlText = true;
bFound = true; break;
}
default:
{ // nothing to be done, character is considered to be neutral we need to look further ...
}
}
}
sal_Unicode cStart = cLRE_Embedding; // default is to use LRE embedding characters if (bIsRtlText)
cStart = cRLE_Embedding; // then use RLE embedding
// add embedding start and end chars to the text if the direction could be determined
OUString aRes( rText ); if (bFound)
{
aRes = OUStringChar(cStart) + aRes
+ OUStringChar(cPopDirectionalFormat);
}
return aRes;
}
static OUString lcl_getDescription( const LanguageTag& rTag )
{
OUString aStr( LanguageTagIcu::getDisplayName( rTag, Application::GetSettings().GetUILanguageTag())); if (aStr.isEmpty() || aStr == rTag.getBcp47())
{ // Place in curly brackets, so all on-the-fly tags without display name // are grouped together at the top of a listbox (but behind the // "[None]" entry), and not sprinkled all over, which alphabetically // might make sense in an English UI only anyway. Also a visual // indicator that it is a programmatical name, IMHO. return OUString::Concat("{") + aStr + "}";
} else
{ // The ICU display name might be identical to a predefined name or even // to another tag's ICU name; clarify that this is a generated name and // append the language tag in curly brackets to distinguish. return aStr + " {" + rTag.getBcp47() + "}";
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.