sl@0
|
1 |
// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include "BidiVisual.h"
|
sl@0
|
17 |
#include "BidiCopy.h"
|
sl@0
|
18 |
#include "BidiTextImp.h"
|
sl@0
|
19 |
#include "BidiCompact.h"
|
sl@0
|
20 |
|
sl@0
|
21 |
extern void BidiPanic(TInt aError);
|
sl@0
|
22 |
|
sl@0
|
23 |
/** Construct the class with a full paragraph of text and the run array to be used
|
sl@0
|
24 |
to hold all the runs.
|
sl@0
|
25 |
|
sl@0
|
26 |
@param aText The text to be analyzed. This must not be de-allocated until
|
sl@0
|
27 |
all operations on it through this class have been completed.
|
sl@0
|
28 |
@param aRightToLeft Paragraph directionality.
|
sl@0
|
29 |
@param aRunInfoArray The array to be used to hold the run information. This
|
sl@0
|
30 |
must not be de-allocated until all operations on it through this class have
|
sl@0
|
31 |
been completed. Ownership is not passed.
|
sl@0
|
32 |
@param aRunInfoLength The number of TRunInfo<\code> objects in aRunInfoArray. */
|
sl@0
|
33 |
EXPORT_C TBidiLogicalToVisual::TBidiLogicalToVisual(
|
sl@0
|
34 |
const TDesC& aText,
|
sl@0
|
35 |
TBool aRightToLeft,
|
sl@0
|
36 |
TBidirectionalState::TRunInfo* aRunInfoArray,
|
sl@0
|
37 |
TInt aRunInfoLength)
|
sl@0
|
38 |
: iText(aText), iRightToLeft(aRightToLeft),
|
sl@0
|
39 |
iRunInfoArray(aRunInfoArray), iRunInfoArrayLength(aRunInfoLength), iRuns(aRunInfoLength)
|
sl@0
|
40 |
{
|
sl@0
|
41 |
}
|
sl@0
|
42 |
|
sl@0
|
43 |
/** Construct the class with a full paragraph of text and the run array to be used
|
sl@0
|
44 |
to hold all the runs. Directionality is taken as the implicit directionality
|
sl@0
|
45 |
of the text passed.
|
sl@0
|
46 |
|
sl@0
|
47 |
@param aText The text to be analyzed. This must not be de-allocated until
|
sl@0
|
48 |
all operations on it through this class have been completed.
|
sl@0
|
49 |
@param aRunInfoArray The array to be used to hold the run information. This
|
sl@0
|
50 |
must not be de-allocated until all operations on it through this class have
|
sl@0
|
51 |
been completed. Ownership is not passed.
|
sl@0
|
52 |
@param aRunInfoLength The number of TRunInfo objects in aRunInfoArray. */
|
sl@0
|
53 |
EXPORT_C TBidiLogicalToVisual::TBidiLogicalToVisual(
|
sl@0
|
54 |
const TDesC& aText,
|
sl@0
|
55 |
TBidirectionalState::TRunInfo* aRunInfoArray,
|
sl@0
|
56 |
TInt aRunInfoLength)
|
sl@0
|
57 |
: iText(aText),
|
sl@0
|
58 |
iRunInfoArray(aRunInfoArray), iRunInfoArrayLength(aRunInfoLength), iRuns(aRunInfoLength)
|
sl@0
|
59 |
{
|
sl@0
|
60 |
iRightToLeft = BidiCopy::ImplicitDirectionalityIsRightToLeft(
|
sl@0
|
61 |
aText.Ptr(), aText.Length(), 0);
|
sl@0
|
62 |
}
|
sl@0
|
63 |
|
sl@0
|
64 |
/** Process the text. This must be called before any call to GetVisualLine.
|
sl@0
|
65 |
|
sl@0
|
66 |
@return The number of runs that were or would be required to reorder the complete
|
sl@0
|
67 |
line. If this is less than the value passed into the constructor as aRunInfoLength,
|
sl@0
|
68 |
the full text will not be able to be Reordered. */
|
sl@0
|
69 |
EXPORT_C TInt TBidiLogicalToVisual::Reorder()
|
sl@0
|
70 |
{
|
sl@0
|
71 |
TInt required = TBidirectionalState::GenerateBdRunArray(
|
sl@0
|
72 |
iText.Ptr(), iText.Length(), iRunInfoArray, iRunInfoArrayLength);
|
sl@0
|
73 |
iRuns = Min(required, iRunInfoArrayLength);
|
sl@0
|
74 |
TBidirectionalState state;
|
sl@0
|
75 |
state.ReorderLine(iRunInfoArray, iRuns, ETrue, ETrue, iRightToLeft,
|
sl@0
|
76 |
TChar::EOtherNeutral, TChar::EOtherNeutral);
|
sl@0
|
77 |
return required;
|
sl@0
|
78 |
}
|
sl@0
|
79 |
|
sl@0
|
80 |
/** Get a line of visually ordered text.
|
sl@0
|
81 |
|
sl@0
|
82 |
@param aLine Line of text in visual order. There must be aEnd - aStart + 4
|
sl@0
|
83 |
characters available in the buffer. Only characters within the range aStart
|
sl@0
|
84 |
to aEnd, plus perhaps a truncation character and up to two zero-width joiners
|
sl@0
|
85 |
will be present in the string at the end.
|
sl@0
|
86 |
@param aStart The first character in the text that is to be on the line.
|
sl@0
|
87 |
@param aEnd One plus the last character in the test that is to be on the line.
|
sl@0
|
88 |
@param aTruncationChar The character to mark the end of the text, if appropriate,
|
sl@0
|
89 |
or 0xFFFF if no truncation character is to be used. */
|
sl@0
|
90 |
EXPORT_C void TBidiLogicalToVisual::GetVisualLine(TDes& aLine,
|
sl@0
|
91 |
TInt aStart, TInt aEnd, TChar aTruncationChar)
|
sl@0
|
92 |
{
|
sl@0
|
93 |
__ASSERT_ALWAYS(aEnd - aStart + KMinCharAvailable <= aLine.MaxLength(), BidiPanic(KErrArgument));
|
sl@0
|
94 |
|
sl@0
|
95 |
if(iText.Length() == 0)
|
sl@0
|
96 |
{
|
sl@0
|
97 |
aLine.Zero();
|
sl@0
|
98 |
return;//We can't do anything with iText, if its length is 0.
|
sl@0
|
99 |
}
|
sl@0
|
100 |
|
sl@0
|
101 |
TRunInfoCompact::TReorderingContext context;
|
sl@0
|
102 |
|
sl@0
|
103 |
const TText* input = &iText[0];
|
sl@0
|
104 |
context.iStart = aStart;
|
sl@0
|
105 |
context.iEnd = aEnd;
|
sl@0
|
106 |
context.iTruncation = aTruncationChar;
|
sl@0
|
107 |
context.iSource = input;
|
sl@0
|
108 |
context.iJoinsAtStart = TRunInfoCompact::JoinBefore(input, aStart);
|
sl@0
|
109 |
context.iJoinsAtEnd = aEnd < iText.Length() ? TRunInfoCompact::JoinBefore(input, aEnd) : EFalse;
|
sl@0
|
110 |
|
sl@0
|
111 |
aLine.FillZ(1);
|
sl@0
|
112 |
TText* output = &aLine[0];
|
sl@0
|
113 |
TText* outputStart = output;
|
sl@0
|
114 |
TBidirectionalState::TRunInfo* endInfo = iRunInfoArray + iRuns;
|
sl@0
|
115 |
for (TBidirectionalState::TRunInfo* currentInfo = iRunInfoArray;
|
sl@0
|
116 |
currentInfo != endInfo; ++currentInfo)
|
sl@0
|
117 |
{
|
sl@0
|
118 |
TRunInfoCompact info(currentInfo->iStart,
|
sl@0
|
119 |
currentInfo->iLength, currentInfo->iDirection);
|
sl@0
|
120 |
output = info.Reorder(output, context);
|
sl@0
|
121 |
}
|
sl@0
|
122 |
aLine.SetLength(output - outputStart);
|
sl@0
|
123 |
}
|