1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicsdeviceinterface/gdi/sgdi/BidiVisual.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,123 @@
1.4 +// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include "BidiVisual.h"
1.20 +#include "BidiCopy.h"
1.21 +#include "BidiTextImp.h"
1.22 +#include "BidiCompact.h"
1.23 +
1.24 +extern void BidiPanic(TInt aError);
1.25 +
1.26 +/** Construct the class with a full paragraph of text and the run array to be used
1.27 +to hold all the runs.
1.28 +
1.29 +@param aText The text to be analyzed. This must not be de-allocated until
1.30 +all operations on it through this class have been completed.
1.31 +@param aRightToLeft Paragraph directionality.
1.32 +@param aRunInfoArray The array to be used to hold the run information. This
1.33 +must not be de-allocated until all operations on it through this class have
1.34 +been completed. Ownership is not passed.
1.35 +@param aRunInfoLength The number of TRunInfo<\code> objects in aRunInfoArray. */
1.36 +EXPORT_C TBidiLogicalToVisual::TBidiLogicalToVisual(
1.37 + const TDesC& aText,
1.38 + TBool aRightToLeft,
1.39 + TBidirectionalState::TRunInfo* aRunInfoArray,
1.40 + TInt aRunInfoLength)
1.41 + : iText(aText), iRightToLeft(aRightToLeft),
1.42 + iRunInfoArray(aRunInfoArray), iRunInfoArrayLength(aRunInfoLength), iRuns(aRunInfoLength)
1.43 + {
1.44 + }
1.45 +
1.46 +/** Construct the class with a full paragraph of text and the run array to be used
1.47 +to hold all the runs. Directionality is taken as the implicit directionality
1.48 +of the text passed.
1.49 +
1.50 +@param aText The text to be analyzed. This must not be de-allocated until
1.51 +all operations on it through this class have been completed.
1.52 +@param aRunInfoArray The array to be used to hold the run information. This
1.53 +must not be de-allocated until all operations on it through this class have
1.54 +been completed. Ownership is not passed.
1.55 +@param aRunInfoLength The number of TRunInfo objects in aRunInfoArray. */
1.56 +EXPORT_C TBidiLogicalToVisual::TBidiLogicalToVisual(
1.57 + const TDesC& aText,
1.58 + TBidirectionalState::TRunInfo* aRunInfoArray,
1.59 + TInt aRunInfoLength)
1.60 + : iText(aText),
1.61 + iRunInfoArray(aRunInfoArray), iRunInfoArrayLength(aRunInfoLength), iRuns(aRunInfoLength)
1.62 + {
1.63 + iRightToLeft = BidiCopy::ImplicitDirectionalityIsRightToLeft(
1.64 + aText.Ptr(), aText.Length(), 0);
1.65 + }
1.66 +
1.67 +/** Process the text. This must be called before any call to GetVisualLine.
1.68 +
1.69 +@return The number of runs that were or would be required to reorder the complete
1.70 +line. If this is less than the value passed into the constructor as aRunInfoLength,
1.71 +the full text will not be able to be Reordered. */
1.72 +EXPORT_C TInt TBidiLogicalToVisual::Reorder()
1.73 + {
1.74 + TInt required = TBidirectionalState::GenerateBdRunArray(
1.75 + iText.Ptr(), iText.Length(), iRunInfoArray, iRunInfoArrayLength);
1.76 + iRuns = Min(required, iRunInfoArrayLength);
1.77 + TBidirectionalState state;
1.78 + state.ReorderLine(iRunInfoArray, iRuns, ETrue, ETrue, iRightToLeft,
1.79 + TChar::EOtherNeutral, TChar::EOtherNeutral);
1.80 + return required;
1.81 + }
1.82 +
1.83 +/** Get a line of visually ordered text.
1.84 +
1.85 +@param aLine Line of text in visual order. There must be aEnd - aStart + 4
1.86 +characters available in the buffer. Only characters within the range aStart
1.87 +to aEnd, plus perhaps a truncation character and up to two zero-width joiners
1.88 +will be present in the string at the end.
1.89 +@param aStart The first character in the text that is to be on the line.
1.90 +@param aEnd One plus the last character in the test that is to be on the line.
1.91 +@param aTruncationChar The character to mark the end of the text, if appropriate,
1.92 +or 0xFFFF if no truncation character is to be used. */
1.93 +EXPORT_C void TBidiLogicalToVisual::GetVisualLine(TDes& aLine,
1.94 + TInt aStart, TInt aEnd, TChar aTruncationChar)
1.95 + {
1.96 + __ASSERT_ALWAYS(aEnd - aStart + KMinCharAvailable <= aLine.MaxLength(), BidiPanic(KErrArgument));
1.97 +
1.98 + if(iText.Length() == 0)
1.99 + {
1.100 + aLine.Zero();
1.101 + return;//We can't do anything with iText, if its length is 0.
1.102 + }
1.103 +
1.104 + TRunInfoCompact::TReorderingContext context;
1.105 +
1.106 + const TText* input = &iText[0];
1.107 + context.iStart = aStart;
1.108 + context.iEnd = aEnd;
1.109 + context.iTruncation = aTruncationChar;
1.110 + context.iSource = input;
1.111 + context.iJoinsAtStart = TRunInfoCompact::JoinBefore(input, aStart);
1.112 + context.iJoinsAtEnd = aEnd < iText.Length() ? TRunInfoCompact::JoinBefore(input, aEnd) : EFalse;
1.113 +
1.114 + aLine.FillZ(1);
1.115 + TText* output = &aLine[0];
1.116 + TText* outputStart = output;
1.117 + TBidirectionalState::TRunInfo* endInfo = iRunInfoArray + iRuns;
1.118 + for (TBidirectionalState::TRunInfo* currentInfo = iRunInfoArray;
1.119 + currentInfo != endInfo; ++currentInfo)
1.120 + {
1.121 + TRunInfoCompact info(currentInfo->iStart,
1.122 + currentInfo->iLength, currentInfo->iDirection);
1.123 + output = info.Reorder(output, context);
1.124 + }
1.125 + aLine.SetLength(output - outputStart);
1.126 + }