summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2012-04-16 22:02:12 -0400
committerPetr Mladek <pmladek@suse.cz>2012-04-17 11:36:41 +0200
commit7a028f6c1e7fb80a22002ad6fed1604dab327e36 (patch)
tree836d32342d04f0fbaad8303e1ea511a521aa26bd /sc
parentfcb1cc5f3788ae1ae3309159d66111767e8781fe (diff)
fdo#48431: More reliable way to check for RTL text.
This is probably more reliable way to fix fdo#32530 such that it won't cause the regression in rendering Thai texts as reported in fdo#48431. Signed-off-by: Petr Mladek <pmladek@suse.cz>
Diffstat (limited to 'sc')
-rw-r--r--sc/source/ui/inc/output.hxx2
-rw-r--r--sc/source/ui/view/output2.cxx59
2 files changed, 35 insertions, 26 deletions
diff --git a/sc/source/ui/inc/output.hxx b/sc/source/ui/inc/output.hxx
index 9a81555eab05..5bdb10189a43 100644
--- a/sc/source/ui/inc/output.hxx
+++ b/sc/source/ui/inc/output.hxx
@@ -102,12 +102,12 @@ private:
long mnPosX;
long mnPosY;
long mnInitPosX;
- sal_uInt8 mnScript;
bool mbBreak;
bool mbCellIsValue;
bool mbAsianVertical;
bool mbPixelToLogic;
bool mbHyphenatorSet;
+ bool mbRTL;
ScFieldEditEngine* mpEngine;
ScBaseCell* mpCell;
const ScPatternAttr* mpPattern;
diff --git a/sc/source/ui/view/output2.cxx b/sc/source/ui/view/output2.cxx
index 82a9905677a1..7f9a9eb7fedf 100644
--- a/sc/source/ui/view/output2.cxx
+++ b/sc/source/ui/view/output2.cxx
@@ -70,10 +70,14 @@
#include "scmod.hxx"
#include "fillinfo.hxx"
+#include <com/sun/star/i18n/DirectionProperty.hpp>
+
#include <boost/ptr_container/ptr_vector.hpp>
#include <math.h>
+using namespace com::sun::star;
+
//! Autofilter-Breite mit column.cxx zusammenfassen
#define DROPDOWN_BITMAP_SIZE 18
@@ -1330,6 +1334,29 @@ void ScOutputData::GetOutputArea( SCCOL nX, SCSIZE nArrY, long nPosX, long nPosY
rParam.maClipRect.Justify();
}
+namespace {
+
+bool beginsWithRTLCharacter(const rtl::OUString& rStr)
+{
+ if (rStr.isEmpty())
+ return false;
+
+ switch (ScGlobal::pCharClass->getCharacterDirection(rStr, 0))
+ {
+ 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:
+ return true;
+ default:
+ ;
+ }
+
+ return false;
+}
+
+}
+
void ScOutputData::DrawStrings( sal_Bool bPixelToLogic )
{
OSL_ENSURE( pDev == pRefDevice ||
@@ -1564,18 +1591,8 @@ void ScOutputData::DrawStrings( sal_Bool bPixelToLogic )
if (aVars.GetHorJust() == SVX_HOR_JUSTIFY_STANDARD)
{
// fdo#32530: Default alignment depends on value vs
- // string, and the script type of the 1st letter.
- sal_uInt8 nScript1st = 0;
- rtl::OUString aStr = aVars.GetString();
- if (!aStr.isEmpty())
- {
- aStr = aStr.copy(0, 1);
- nScript1st = pDoc->GetStringScriptType(aStr);
- if (!nScript1st)
- nScript1st = ScGlobal::GetDefaultScriptType();
- }
-
- if (nScript1st == SCRIPTTYPE_COMPLEX)
+ // string, and the direction of the 1st letter.
+ if (beginsWithRTLCharacter(aVars.GetString()))
eOutHorJust = bCellIsValue ? SVX_HOR_JUSTIFY_LEFT : SVX_HOR_JUSTIFY_RIGHT;
else
eOutHorJust = bCellIsValue ? SVX_HOR_JUSTIFY_RIGHT : SVX_HOR_JUSTIFY_LEFT;
@@ -2155,12 +2172,12 @@ ScOutputData::DrawEditParam::DrawEditParam(const ScPatternAttr* pPattern, const
mnArrY(0),
mnX(0), mnY(0), mnCellX(0), mnCellY(0),
mnPosX(0), mnPosY(0), mnInitPosX(0),
- mnScript(0),
mbBreak( (meHorJust == SVX_HOR_JUSTIFY_BLOCK) || lcl_GetBoolValue(*pPattern, ATTR_LINEBREAK, pCondSet) ),
mbCellIsValue(bCellIsValue),
mbAsianVertical(false),
mbPixelToLogic(false),
mbHyphenatorSet(false),
+ mbRTL(false),
mpEngine(NULL),
mpCell(NULL),
mpPattern(pPattern),
@@ -2590,8 +2607,8 @@ void ScOutputData::DrawEditStandard(DrawEditParam& rParam)
if (eOutHorJust == SVX_HOR_JUSTIFY_STANDARD)
{
// fdo#32530: Default alignment depends on value vs string, and the
- // script type of the 1st letter.
- if (rParam.mnScript == SCRIPTTYPE_COMPLEX)
+ // direction of the 1st letter.
+ if (rParam.mbRTL)
eOutHorJust = rParam.mbCellIsValue ? SVX_HOR_JUSTIFY_LEFT : SVX_HOR_JUSTIFY_RIGHT;
else
eOutHorJust = rParam.mbCellIsValue ? SVX_HOR_JUSTIFY_RIGHT : SVX_HOR_JUSTIFY_LEFT;
@@ -4596,20 +4613,13 @@ void ScOutputData::DrawEdit(sal_Bool bPixelToLogic)
else
lcl_ClearEdit( *pEngine ); // also calls SetUpdateMode(sal_False)
- // fdo#32530: Get the script type of the first letter.
- sal_uInt8 nScript = 0;
+ // fdo#32530: Check if the first character is RTL.
rtl::OUString aStr = pDoc->GetString(nCellX, nCellY, nTab);
- if (!aStr.isEmpty())
- {
- aStr = aStr.copy(0, 1);
- nScript = pDoc->GetStringScriptType(aStr);
- }
- if (nScript == 0)
- nScript = ScGlobal::GetDefaultScriptType();
DrawEditParam aParam(pPattern, pCondSet, lcl_SafeIsValue(pCell));
aParam.mbPixelToLogic = bPixelToLogic;
aParam.mbHyphenatorSet = bHyphenatorSet;
+ aParam.mbRTL = beginsWithRTLCharacter(aStr);
aParam.mpEngine = pEngine;
aParam.mpCell = pCell;
aParam.mnArrY = nArrY;
@@ -4620,7 +4630,6 @@ void ScOutputData::DrawEdit(sal_Bool bPixelToLogic)
aParam.mnPosX = nPosX;
aParam.mnPosY = nPosY;
aParam.mnInitPosX = nInitPosX;
- aParam.mnScript = nScript;
aParam.mpOldPattern = pOldPattern;
aParam.mpOldCondSet = pOldCondSet;
aParam.mpThisRowInfo = pThisRowInfo;