sl@0: // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include "BidiVisual.h" sl@0: #include "BidiCopy.h" sl@0: #include "BidiTextImp.h" sl@0: #include "BidiCompact.h" sl@0: sl@0: extern void BidiPanic(TInt aError); sl@0: sl@0: /** Construct the class with a full paragraph of text and the run array to be used sl@0: to hold all the runs. sl@0: sl@0: @param aText The text to be analyzed. This must not be de-allocated until sl@0: all operations on it through this class have been completed. sl@0: @param aRightToLeft Paragraph directionality. sl@0: @param aRunInfoArray The array to be used to hold the run information. This sl@0: must not be de-allocated until all operations on it through this class have sl@0: been completed. Ownership is not passed. sl@0: @param aRunInfoLength The number of TRunInfo<\code> objects in aRunInfoArray. */ sl@0: EXPORT_C TBidiLogicalToVisual::TBidiLogicalToVisual( sl@0: const TDesC& aText, sl@0: TBool aRightToLeft, sl@0: TBidirectionalState::TRunInfo* aRunInfoArray, sl@0: TInt aRunInfoLength) sl@0: : iText(aText), iRightToLeft(aRightToLeft), sl@0: iRunInfoArray(aRunInfoArray), iRunInfoArrayLength(aRunInfoLength), iRuns(aRunInfoLength) sl@0: { sl@0: } sl@0: sl@0: /** Construct the class with a full paragraph of text and the run array to be used sl@0: to hold all the runs. Directionality is taken as the implicit directionality sl@0: of the text passed. sl@0: sl@0: @param aText The text to be analyzed. This must not be de-allocated until sl@0: all operations on it through this class have been completed. sl@0: @param aRunInfoArray The array to be used to hold the run information. This sl@0: must not be de-allocated until all operations on it through this class have sl@0: been completed. Ownership is not passed. sl@0: @param aRunInfoLength The number of TRunInfo objects in aRunInfoArray. */ sl@0: EXPORT_C TBidiLogicalToVisual::TBidiLogicalToVisual( sl@0: const TDesC& aText, sl@0: TBidirectionalState::TRunInfo* aRunInfoArray, sl@0: TInt aRunInfoLength) sl@0: : iText(aText), sl@0: iRunInfoArray(aRunInfoArray), iRunInfoArrayLength(aRunInfoLength), iRuns(aRunInfoLength) sl@0: { sl@0: iRightToLeft = BidiCopy::ImplicitDirectionalityIsRightToLeft( sl@0: aText.Ptr(), aText.Length(), 0); sl@0: } sl@0: sl@0: /** Process the text. This must be called before any call to GetVisualLine. sl@0: sl@0: @return The number of runs that were or would be required to reorder the complete sl@0: line. If this is less than the value passed into the constructor as aRunInfoLength, sl@0: the full text will not be able to be Reordered. */ sl@0: EXPORT_C TInt TBidiLogicalToVisual::Reorder() sl@0: { sl@0: TInt required = TBidirectionalState::GenerateBdRunArray( sl@0: iText.Ptr(), iText.Length(), iRunInfoArray, iRunInfoArrayLength); sl@0: iRuns = Min(required, iRunInfoArrayLength); sl@0: TBidirectionalState state; sl@0: state.ReorderLine(iRunInfoArray, iRuns, ETrue, ETrue, iRightToLeft, sl@0: TChar::EOtherNeutral, TChar::EOtherNeutral); sl@0: return required; sl@0: } sl@0: sl@0: /** Get a line of visually ordered text. sl@0: sl@0: @param aLine Line of text in visual order. There must be aEnd - aStart + 4 sl@0: characters available in the buffer. Only characters within the range aStart sl@0: to aEnd, plus perhaps a truncation character and up to two zero-width joiners sl@0: will be present in the string at the end. sl@0: @param aStart The first character in the text that is to be on the line. sl@0: @param aEnd One plus the last character in the test that is to be on the line. sl@0: @param aTruncationChar The character to mark the end of the text, if appropriate, sl@0: or 0xFFFF if no truncation character is to be used. */ sl@0: EXPORT_C void TBidiLogicalToVisual::GetVisualLine(TDes& aLine, sl@0: TInt aStart, TInt aEnd, TChar aTruncationChar) sl@0: { sl@0: __ASSERT_ALWAYS(aEnd - aStart + KMinCharAvailable <= aLine.MaxLength(), BidiPanic(KErrArgument)); sl@0: sl@0: if(iText.Length() == 0) sl@0: { sl@0: aLine.Zero(); sl@0: return;//We can't do anything with iText, if its length is 0. sl@0: } sl@0: sl@0: TRunInfoCompact::TReorderingContext context; sl@0: sl@0: const TText* input = &iText[0]; sl@0: context.iStart = aStart; sl@0: context.iEnd = aEnd; sl@0: context.iTruncation = aTruncationChar; sl@0: context.iSource = input; sl@0: context.iJoinsAtStart = TRunInfoCompact::JoinBefore(input, aStart); sl@0: context.iJoinsAtEnd = aEnd < iText.Length() ? TRunInfoCompact::JoinBefore(input, aEnd) : EFalse; sl@0: sl@0: aLine.FillZ(1); sl@0: TText* output = &aLine[0]; sl@0: TText* outputStart = output; sl@0: TBidirectionalState::TRunInfo* endInfo = iRunInfoArray + iRuns; sl@0: for (TBidirectionalState::TRunInfo* currentInfo = iRunInfoArray; sl@0: currentInfo != endInfo; ++currentInfo) sl@0: { sl@0: TRunInfoCompact info(currentInfo->iStart, sl@0: currentInfo->iLength, currentInfo->iDirection); sl@0: output = info.Reorder(output, context); sl@0: } sl@0: aLine.SetLength(output - outputStart); sl@0: }