2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:30:37 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2001-03-09 04:12:39 +03:00
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
2001-03-09 04:12:39 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
2001-03-09 04:12:39 +03:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-29 00:14:13 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
2001-03-09 04:12:39 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
2006-02-22 00:33:47 +03:00
|
|
|
* Uri Bernstein <uriber@gmail.com>
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 18:30:37 +04:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-29 00:14:13 +04:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 18:30:37 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-29 00:14:13 +04:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 18:30:37 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2001-03-09 04:12:39 +03:00
|
|
|
|
|
|
|
#ifdef IBMBIDI
|
|
|
|
|
|
|
|
#include "nsBidiPresUtils.h"
|
|
|
|
#include "nsITextContent.h"
|
|
|
|
#include "nsTextFragment.h"
|
|
|
|
#include "nsLayoutAtoms.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2001-03-09 04:12:39 +03:00
|
|
|
#include "nsIRenderingContext.h"
|
|
|
|
#include "nsIServiceManager.h"
|
2004-02-24 00:29:06 +03:00
|
|
|
#include "nsFrameManager.h"
|
2001-03-09 04:12:39 +03:00
|
|
|
#include "nsBidiFrames.h"
|
2002-02-19 23:41:32 +03:00
|
|
|
#include "nsBidiUtils.h"
|
2006-02-22 00:33:47 +03:00
|
|
|
#include "nsCSSFrameConstructor.h"
|
2001-03-09 04:12:39 +03:00
|
|
|
|
|
|
|
static const PRUnichar kSpace = 0x0020;
|
|
|
|
static const PRUnichar kLineSeparator = 0x2028;
|
|
|
|
static const PRUnichar kObjectSubstitute = 0xFFFC;
|
|
|
|
static const PRUnichar kLRE = 0x202A;
|
|
|
|
static const PRUnichar kRLE = 0x202B;
|
2001-06-29 07:15:58 +04:00
|
|
|
static const PRUnichar kLRO = 0x202D;
|
|
|
|
static const PRUnichar kRLO = 0x202E;
|
2001-03-09 04:12:39 +03:00
|
|
|
static const PRUnichar kPDF = 0x202C;
|
|
|
|
static const PRUnichar ALEF = 0x05D0;
|
|
|
|
|
2002-02-19 23:41:32 +03:00
|
|
|
#define CHAR_IS_HEBREW(c) ((0x0590 <= (c)) && ((c)<= 0x05FF))
|
|
|
|
// Note: The above code are moved from gfx/src/windows/nsRenderingContextWin.cpp
|
|
|
|
|
2005-11-04 05:38:33 +03:00
|
|
|
nsIFrame*
|
|
|
|
NS_NewDirectionalFrame(nsIPresShell* aPresShell, PRUnichar aChar);
|
2001-03-09 04:12:39 +03:00
|
|
|
|
2001-10-25 07:21:53 +04:00
|
|
|
nsBidiPresUtils::nsBidiPresUtils() : mArraySize(8),
|
2001-03-09 04:12:39 +03:00
|
|
|
mIndexMap(nsnull),
|
2001-10-25 07:21:53 +04:00
|
|
|
mLevels(nsnull),
|
|
|
|
mSuccess(NS_ERROR_FAILURE),
|
2002-02-19 23:41:32 +03:00
|
|
|
mBidiEngine(nsnull)
|
2001-03-09 04:12:39 +03:00
|
|
|
{
|
2002-02-19 23:41:32 +03:00
|
|
|
mBidiEngine = new nsBidi();
|
2003-07-24 22:33:50 +04:00
|
|
|
if (mBidiEngine && mContentToFrameIndex.Init()) {
|
2001-03-09 04:12:39 +03:00
|
|
|
mSuccess = NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsBidiPresUtils::~nsBidiPresUtils()
|
|
|
|
{
|
|
|
|
if (mLevels) {
|
|
|
|
delete[] mLevels;
|
|
|
|
}
|
|
|
|
if (mIndexMap) {
|
|
|
|
delete[] mIndexMap;
|
|
|
|
}
|
2002-05-24 02:03:19 +04:00
|
|
|
delete mBidiEngine;
|
2001-03-09 04:12:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsBidiPresUtils::IsSuccessful() const
|
|
|
|
{
|
|
|
|
return NS_SUCCEEDED(mSuccess);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Some helper methods for Resolve() */
|
|
|
|
|
2006-02-22 00:33:47 +03:00
|
|
|
static nsresult
|
|
|
|
SplitInlineAncestors(nsPresContext* aPresContext,
|
|
|
|
nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
nsIPresShell *presShell = aPresContext->PresShell();
|
|
|
|
nsIFrame* frame = aFrame;
|
|
|
|
nsIFrame* parent = aFrame->GetParent();
|
|
|
|
nsIFrame* newFrame = aFrame->GetNextSibling();
|
|
|
|
nsIFrame* newParent;
|
|
|
|
|
|
|
|
while (nsLayoutAtoms::inlineFrame == parent->GetType() ||
|
|
|
|
nsLayoutAtoms::positionedInlineFrame == parent->GetType()) {
|
|
|
|
|
|
|
|
nsIFrame* grandparent = parent->GetParent();
|
|
|
|
NS_ASSERTION(grandparent, "Couldn't get parent's parent in nsBidiPresUtils::SplitInlineAncestors");
|
|
|
|
|
|
|
|
nsresult rv = presShell->FrameConstructor()->
|
|
|
|
CreateContinuingFrame(aPresContext, parent, grandparent, &newParent, PR_FALSE);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The new parent adopts the new frame
|
|
|
|
frame->SetNextSibling(nsnull);
|
|
|
|
rv = newParent->InsertFrames(nsLayoutAtoms::nextBidi, nsnull, newFrame);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The list name nsLayoutAtoms::nextBidi would indicate we don't want reflow
|
|
|
|
rv = grandparent->InsertFrames(nsLayoutAtoms::nextBidi, parent, newParent);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
frame = parent;
|
|
|
|
newFrame = newParent;
|
|
|
|
parent = grandparent;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-03-09 04:12:39 +03:00
|
|
|
static nsresult
|
2004-08-01 03:15:21 +04:00
|
|
|
CreateBidiContinuation(nsPresContext* aPresContext,
|
2001-03-09 04:12:39 +03:00
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsIFrame** aNewFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aNewFrame, "null OUT ptr");
|
2006-02-22 00:33:47 +03:00
|
|
|
NS_PRECONDITION(aFrame, "null ptr");
|
2001-03-09 04:12:39 +03:00
|
|
|
|
|
|
|
*aNewFrame = nsnull;
|
|
|
|
|
2003-12-21 08:36:36 +03:00
|
|
|
nsIPresShell *presShell = aPresContext->PresShell();
|
2001-03-09 04:12:39 +03:00
|
|
|
NS_ASSERTION(presShell, "PresShell must be set on PresContext before calling nsBidiPresUtils::CreateBidiContinuation");
|
|
|
|
|
2003-07-02 14:30:00 +04:00
|
|
|
nsIFrame* parent = aFrame->GetParent();
|
2003-02-22 03:32:13 +03:00
|
|
|
NS_ASSERTION(parent, "Couldn't get frame parent in nsBidiPresUtils::CreateBidiContinuation");
|
2006-02-22 00:33:47 +03:00
|
|
|
|
|
|
|
nsresult rv = presShell->FrameConstructor()->
|
|
|
|
CreateContinuingFrame(aPresContext, aFrame, parent, aNewFrame, PR_FALSE);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-03-09 04:12:39 +03:00
|
|
|
// The list name nsLayoutAtoms::nextBidi would indicate we don't want reflow
|
2006-02-22 00:33:47 +03:00
|
|
|
rv = parent->InsertFrames(nsLayoutAtoms::nextBidi, aFrame, *aNewFrame);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Split inline ancestor frames
|
|
|
|
rv = SplitInlineAncestors(aPresContext, aFrame);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2001-03-09 04:12:39 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2003-07-24 22:33:50 +04:00
|
|
|
/*
|
|
|
|
* Overview of the implementation of Resolve():
|
|
|
|
*
|
|
|
|
* Walk through the descendants of aBlockFrame and build:
|
|
|
|
* * mLogicalArray: an nsVoidArray of nsIFrame* pointers in logical order
|
|
|
|
* * mBuffer: an nsAutoString containing a representation of
|
|
|
|
* the content of the frames.
|
|
|
|
* In the case of text frames, this is the actual text context of the
|
|
|
|
* frames, but some other elements are represented in a symbolic form which
|
|
|
|
* will make the Unicode Bidi Algorithm give the correct results.
|
|
|
|
* Bidi embeddings and overrides set by CSS or <bdo> elements are
|
|
|
|
* represented by the corresponding Unicode control characters.
|
|
|
|
* <br> elements are represented by U+2028 LINE SEPARATOR
|
|
|
|
* Other inline elements are represented by U+FFFC OBJECT REPLACEMENT
|
|
|
|
* CHARACTER
|
|
|
|
*
|
|
|
|
* Then pass mBuffer to the Bidi engine for resolving of embedding levels
|
|
|
|
* by nsBidi::SetPara() and division into directional runs by
|
|
|
|
* nsBidi::CountRuns().
|
|
|
|
*
|
|
|
|
* Finally, walk these runs in logical order using nsBidi::GetLogicalRun() and
|
|
|
|
* correlate them with the frames indexed in mLogicalArray, setting the
|
|
|
|
* baseLevel, embeddingLevel, and charType properties according to the results
|
|
|
|
* returned by the Bidi engine and CalculateCharType().
|
|
|
|
*
|
|
|
|
* The rendering layer requires each text frame to contain text in only one
|
|
|
|
* direction and of only one character type, so we may need to call
|
|
|
|
* EnsureBidiContinuation() to split frames. We may also need to call
|
|
|
|
* RemoveBidiContinuation() to delete frames created by
|
|
|
|
* EnsureBidiContinuation() in previous reflows.
|
|
|
|
*/
|
2001-03-09 04:12:39 +03:00
|
|
|
nsresult
|
2004-08-01 03:15:21 +04:00
|
|
|
nsBidiPresUtils::Resolve(nsPresContext* aPresContext,
|
2001-03-09 04:12:39 +03:00
|
|
|
nsIFrame* aBlockFrame,
|
|
|
|
nsIFrame* aFirstChild,
|
2002-07-10 04:52:17 +04:00
|
|
|
PRBool& aForceReflow,
|
|
|
|
PRBool aIsVisualFormControl)
|
2001-03-09 04:12:39 +03:00
|
|
|
{
|
|
|
|
aForceReflow = PR_FALSE;
|
|
|
|
mLogicalFrames.Clear();
|
2003-07-24 22:33:50 +04:00
|
|
|
mContentToFrameIndex.Clear();
|
2005-11-04 05:38:33 +03:00
|
|
|
|
|
|
|
nsIPresShell* shell = aPresContext->PresShell();
|
2001-03-09 04:12:39 +03:00
|
|
|
|
2001-06-29 07:15:58 +04:00
|
|
|
// handle bidi-override being set on the block itself before calling
|
|
|
|
// InitLogicalArray.
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleVisibility* vis = aBlockFrame->GetStyleVisibility();
|
|
|
|
const nsStyleTextReset* text = aBlockFrame->GetStyleTextReset();
|
2001-06-29 07:15:58 +04:00
|
|
|
|
|
|
|
if (text->mUnicodeBidi == NS_STYLE_UNICODE_BIDI_OVERRIDE) {
|
|
|
|
nsIFrame *directionalFrame = nsnull;
|
2005-11-04 05:38:33 +03:00
|
|
|
|
2001-06-29 07:15:58 +04:00
|
|
|
if (NS_STYLE_DIRECTION_RTL == vis->mDirection) {
|
2005-11-04 05:38:33 +03:00
|
|
|
directionalFrame = NS_NewDirectionalFrame(shell, kRLO);
|
2001-06-29 07:15:58 +04:00
|
|
|
}
|
|
|
|
else if (NS_STYLE_DIRECTION_LTR == vis->mDirection) {
|
2005-11-04 05:38:33 +03:00
|
|
|
directionalFrame = NS_NewDirectionalFrame(shell, kLRO);
|
2001-06-29 07:15:58 +04:00
|
|
|
}
|
2005-11-04 05:38:33 +03:00
|
|
|
|
|
|
|
if (directionalFrame) {
|
2001-06-29 07:15:58 +04:00
|
|
|
mLogicalFrames.AppendElement(directionalFrame);
|
|
|
|
}
|
|
|
|
}
|
2001-03-09 04:12:39 +03:00
|
|
|
mSuccess = InitLogicalArray(aPresContext, aFirstChild, nsnull, PR_TRUE);
|
2005-11-04 05:38:33 +03:00
|
|
|
|
2001-06-29 07:15:58 +04:00
|
|
|
if (text->mUnicodeBidi == NS_STYLE_UNICODE_BIDI_OVERRIDE) {
|
2005-11-04 05:38:33 +03:00
|
|
|
nsIFrame* directionalFrame = NS_NewDirectionalFrame(shell, kPDF);
|
|
|
|
if (directionalFrame) {
|
2001-06-29 07:15:58 +04:00
|
|
|
mLogicalFrames.AppendElement(directionalFrame);
|
|
|
|
}
|
|
|
|
}
|
2001-03-09 04:12:39 +03:00
|
|
|
if (NS_FAILED(mSuccess) ) {
|
|
|
|
return mSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
CreateBlockBuffer(aPresContext);
|
|
|
|
|
|
|
|
PRInt32 bufferLength = mBuffer.Length();
|
|
|
|
|
|
|
|
if (bufferLength < 1) {
|
|
|
|
mSuccess = NS_OK;
|
|
|
|
return mSuccess;
|
|
|
|
}
|
|
|
|
PRInt32 runCount;
|
|
|
|
PRUint8 embeddingLevel;
|
|
|
|
|
|
|
|
nsBidiLevel paraLevel = embeddingLevel =
|
2001-06-01 02:19:43 +04:00
|
|
|
(NS_STYLE_DIRECTION_RTL == vis->mDirection)
|
2001-03-09 04:12:39 +03:00
|
|
|
? NSBIDI_RTL : NSBIDI_LTR;
|
|
|
|
|
2001-06-30 15:02:25 +04:00
|
|
|
mSuccess = mBidiEngine->SetPara(mBuffer.get(), bufferLength, paraLevel, nsnull);
|
2001-03-09 04:12:39 +03:00
|
|
|
if (NS_FAILED(mSuccess) ) {
|
|
|
|
return mSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool isVisual;
|
2002-07-10 04:52:17 +04:00
|
|
|
if (aIsVisualFormControl) {
|
|
|
|
isVisual = PR_FALSE;
|
|
|
|
} else {
|
2004-02-20 20:49:01 +03:00
|
|
|
isVisual = aPresContext->IsVisualMode();
|
2002-07-10 04:52:17 +04:00
|
|
|
}
|
2001-03-09 04:12:39 +03:00
|
|
|
mSuccess = mBidiEngine->CountRuns(&runCount);
|
|
|
|
if (NS_FAILED(mSuccess) ) {
|
|
|
|
return mSuccess;
|
|
|
|
}
|
|
|
|
PRInt32 runLength = 0;
|
|
|
|
PRInt32 fragmentLength = 0;
|
|
|
|
PRInt32 temp;
|
|
|
|
PRInt32 frameIndex = -1;
|
|
|
|
PRInt32 frameCount = mLogicalFrames.Count();
|
2003-02-23 14:10:28 +03:00
|
|
|
PRInt32 contentOffset = 0; // offset within current frame
|
2001-03-09 04:12:39 +03:00
|
|
|
PRInt32 lineOffset = 0; // offset within mBuffer
|
|
|
|
PRInt32 logicalLimit = 0;
|
|
|
|
PRInt32 numRun = -1;
|
|
|
|
PRUint8 charType;
|
|
|
|
PRUint8 prevType = eCharType_LeftToRight;
|
2003-02-23 14:10:28 +03:00
|
|
|
PRBool isTextFrame = PR_FALSE;
|
2001-03-09 04:12:39 +03:00
|
|
|
nsIFrame* frame = nsnull;
|
|
|
|
nsIFrame* nextBidi;
|
2003-07-02 14:30:00 +04:00
|
|
|
nsIContent* content = nsnull;
|
2001-03-09 04:12:39 +03:00
|
|
|
nsCOMPtr<nsITextContent> textContent;
|
|
|
|
const nsTextFragment* fragment;
|
2003-10-31 23:19:18 +03:00
|
|
|
nsIAtom* frameType = nsnull;
|
2001-03-09 04:12:39 +03:00
|
|
|
|
2004-08-24 22:50:29 +04:00
|
|
|
nsPropertyTable *propTable = aPresContext->PropertyTable();
|
|
|
|
|
2001-03-09 04:12:39 +03:00
|
|
|
for (; ;) {
|
|
|
|
if (fragmentLength <= 0) {
|
|
|
|
if (++frameIndex >= frameCount) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
contentOffset = 0;
|
|
|
|
|
|
|
|
frame = (nsIFrame*) (mLogicalFrames[frameIndex]);
|
2003-10-31 23:19:18 +03:00
|
|
|
frameType = frame->GetType();
|
|
|
|
if (nsLayoutAtoms::textFrame == frameType) {
|
2003-07-02 14:30:00 +04:00
|
|
|
content = frame->GetContent();
|
|
|
|
if (!content) {
|
|
|
|
mSuccess = NS_OK;
|
2001-03-09 04:12:39 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
textContent = do_QueryInterface(content, &mSuccess);
|
|
|
|
if (NS_FAILED(mSuccess) || (!textContent) ) {
|
|
|
|
break;
|
|
|
|
}
|
2004-05-08 00:55:17 +04:00
|
|
|
fragment = textContent->Text();
|
2001-03-09 04:12:39 +03:00
|
|
|
if (!fragment) {
|
|
|
|
mSuccess = NS_ERROR_FAILURE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fragmentLength = fragment->GetLength();
|
|
|
|
isTextFrame = PR_TRUE;
|
|
|
|
} // if text frame
|
|
|
|
else {
|
|
|
|
isTextFrame = PR_FALSE;
|
|
|
|
fragmentLength = 1;
|
|
|
|
}
|
|
|
|
} // if (fragmentLength <= 0)
|
|
|
|
if (runLength <= 0) {
|
|
|
|
if (++numRun >= runCount) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
lineOffset = logicalLimit;
|
|
|
|
if (NS_FAILED(mBidiEngine->GetLogicalRun(
|
|
|
|
lineOffset, &logicalLimit, &embeddingLevel) ) ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
runLength = logicalLimit - lineOffset;
|
|
|
|
if (isVisual) {
|
|
|
|
embeddingLevel = paraLevel;
|
|
|
|
}
|
|
|
|
} // if (runLength <= 0)
|
|
|
|
|
2003-10-31 23:19:18 +03:00
|
|
|
if (nsLayoutAtoms::directionalFrame == frameType) {
|
2005-12-03 18:44:43 +03:00
|
|
|
frame->Destroy(aPresContext);
|
2006-02-22 00:33:47 +03:00
|
|
|
frame = nsnull;
|
2001-03-09 04:12:39 +03:00
|
|
|
++lineOffset;
|
|
|
|
}
|
|
|
|
else {
|
2004-08-24 22:50:29 +04:00
|
|
|
propTable->SetProperty(frame, nsLayoutAtoms::embeddingLevel,
|
|
|
|
NS_INT32_TO_PTR(embeddingLevel), nsnull, nsnull);
|
|
|
|
propTable->SetProperty(frame, nsLayoutAtoms::baseLevel,
|
|
|
|
NS_INT32_TO_PTR(paraLevel), nsnull, nsnull);
|
2001-03-09 04:12:39 +03:00
|
|
|
if (isTextFrame) {
|
2001-06-29 07:15:58 +04:00
|
|
|
PRInt32 typeLimit = PR_MIN(logicalLimit, lineOffset + fragmentLength);
|
|
|
|
CalculateCharType(lineOffset, typeLimit, logicalLimit, runLength,
|
|
|
|
runCount, charType, prevType);
|
2001-03-09 04:12:39 +03:00
|
|
|
// IBMBIDI - Egypt - Start
|
2004-08-24 22:50:29 +04:00
|
|
|
propTable->SetProperty(frame, nsLayoutAtoms::charType,
|
|
|
|
NS_INT32_TO_PTR(charType), nsnull, nsnull);
|
2001-03-09 04:12:39 +03:00
|
|
|
// IBMBIDI - Egypt - End
|
|
|
|
|
|
|
|
if ( (runLength > 0) && (runLength < fragmentLength) ) {
|
2003-07-02 14:30:00 +04:00
|
|
|
if (!EnsureBidiContinuation(aPresContext, content, frame,
|
2001-03-09 04:12:39 +03:00
|
|
|
&nextBidi, frameIndex) ) {
|
|
|
|
break;
|
|
|
|
}
|
2003-02-25 03:44:04 +03:00
|
|
|
frame->AdjustOffsetsForBidi(contentOffset, contentOffset + runLength);
|
2001-03-09 04:12:39 +03:00
|
|
|
frame = nextBidi;
|
|
|
|
contentOffset += runLength;
|
|
|
|
} // if (runLength < fragmentLength)
|
|
|
|
else {
|
2003-02-25 03:44:04 +03:00
|
|
|
frame->AdjustOffsetsForBidi(contentOffset, contentOffset + fragmentLength);
|
2003-07-24 22:33:50 +04:00
|
|
|
PRInt32 newIndex = 0;
|
|
|
|
mContentToFrameIndex.Get(content, &newIndex);
|
|
|
|
if (newIndex > frameIndex) {
|
|
|
|
RemoveBidiContinuation(aPresContext, frame,
|
|
|
|
frameIndex, newIndex, temp);
|
2001-03-09 04:12:39 +03:00
|
|
|
aForceReflow = PR_TRUE;
|
|
|
|
runLength -= temp;
|
2005-01-25 16:37:28 +03:00
|
|
|
fragmentLength -= temp;
|
2001-03-09 04:12:39 +03:00
|
|
|
lineOffset += temp;
|
2003-07-24 22:33:50 +04:00
|
|
|
frameIndex = newIndex;
|
2001-03-09 04:12:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} // isTextFrame
|
|
|
|
else {
|
|
|
|
++lineOffset;
|
|
|
|
}
|
|
|
|
} // not directionalFrame
|
|
|
|
temp = runLength;
|
|
|
|
runLength -= fragmentLength;
|
|
|
|
fragmentLength -= temp;
|
2006-02-22 00:33:47 +03:00
|
|
|
|
|
|
|
// If the frame is at the end of a run, split all ancestor inlines that need splitting.
|
|
|
|
if (frame && fragmentLength <= 0 && runLength <= 0) {
|
|
|
|
// As long as we're on the last sibling, the parent doesn't have to be split.
|
|
|
|
nsIFrame* child = frame;
|
|
|
|
nsIFrame* parent = frame->GetParent();
|
|
|
|
while (parent &&
|
|
|
|
(nsLayoutAtoms::inlineFrame == parent->GetType() ||
|
|
|
|
nsLayoutAtoms::positionedInlineFrame == parent->GetType()) &&
|
|
|
|
!child->GetNextSibling()) {
|
|
|
|
child = parent;
|
|
|
|
parent = child->GetParent();
|
|
|
|
}
|
|
|
|
if (parent &&
|
|
|
|
(nsLayoutAtoms::inlineFrame == parent->GetType() ||
|
|
|
|
nsLayoutAtoms::positionedInlineFrame == parent->GetType()))
|
|
|
|
SplitInlineAncestors(aPresContext, child);
|
|
|
|
}
|
2001-03-09 04:12:39 +03:00
|
|
|
} // for
|
|
|
|
return mSuccess;
|
|
|
|
}
|
|
|
|
|
2006-02-22 00:33:47 +03:00
|
|
|
// Should this frame be treated as a leaf (e.g. when building mLogicalArray)?
|
|
|
|
PRBool IsBidiLeaf(nsIFrame* aFrame) {
|
|
|
|
nsIAtom* frameType = aFrame->GetType();
|
|
|
|
nsIFrame* kid = aFrame->GetFirstChild(nsnull);
|
|
|
|
return !kid
|
|
|
|
|| aFrame->GetStyleDisplay()->IsBlockLevel()
|
|
|
|
|| !(nsLayoutAtoms::inlineFrame == frameType
|
|
|
|
|| nsLayoutAtoms::positionedInlineFrame == frameType
|
|
|
|
|| nsLayoutAtoms::letterFrame == frameType
|
|
|
|
|| nsLayoutAtoms::blockFrame == frameType);
|
|
|
|
}
|
|
|
|
|
2001-03-09 04:12:39 +03:00
|
|
|
nsresult
|
2004-08-01 03:15:21 +04:00
|
|
|
nsBidiPresUtils::InitLogicalArray(nsPresContext* aPresContext,
|
2001-03-09 04:12:39 +03:00
|
|
|
nsIFrame* aCurrentFrame,
|
|
|
|
nsIFrame* aNextInFlow,
|
|
|
|
PRBool aAddMarkers)
|
|
|
|
{
|
|
|
|
nsIFrame* frame;
|
|
|
|
nsIFrame* directionalFrame;
|
|
|
|
nsresult res = NS_OK;
|
2005-11-04 05:38:33 +03:00
|
|
|
|
|
|
|
nsIPresShell* shell = aPresContext->PresShell();
|
2001-03-09 04:12:39 +03:00
|
|
|
|
|
|
|
for (frame = aCurrentFrame;
|
|
|
|
frame && frame != aNextInFlow;
|
2003-07-02 14:30:00 +04:00
|
|
|
frame = frame->GetNextSibling()) {
|
2005-11-04 05:38:33 +03:00
|
|
|
directionalFrame = nsnull;
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleDisplay* display = frame->GetStyleDisplay();
|
2001-03-09 04:12:39 +03:00
|
|
|
|
2001-06-29 07:15:58 +04:00
|
|
|
if (aAddMarkers && !display->IsBlockLevel() ) {
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleVisibility* vis = frame->GetStyleVisibility();
|
|
|
|
const nsStyleTextReset* text = frame->GetStyleTextReset();
|
2001-06-29 07:15:58 +04:00
|
|
|
switch (text->mUnicodeBidi) {
|
|
|
|
case NS_STYLE_UNICODE_BIDI_NORMAL:
|
|
|
|
break;
|
|
|
|
case NS_STYLE_UNICODE_BIDI_EMBED:
|
|
|
|
if (NS_STYLE_DIRECTION_RTL == vis->mDirection) {
|
2005-11-04 05:38:33 +03:00
|
|
|
directionalFrame = NS_NewDirectionalFrame(shell, kRLE);
|
2001-06-29 07:15:58 +04:00
|
|
|
}
|
|
|
|
else if (NS_STYLE_DIRECTION_LTR == vis->mDirection) {
|
2005-11-04 05:38:33 +03:00
|
|
|
directionalFrame = NS_NewDirectionalFrame(shell, kLRE);
|
2001-06-29 07:15:58 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_STYLE_UNICODE_BIDI_OVERRIDE:
|
|
|
|
if (NS_STYLE_DIRECTION_RTL == vis->mDirection) {
|
2005-11-04 05:38:33 +03:00
|
|
|
directionalFrame = NS_NewDirectionalFrame(shell, kRLO);
|
2001-06-29 07:15:58 +04:00
|
|
|
}
|
|
|
|
else if (NS_STYLE_DIRECTION_LTR == vis->mDirection) {
|
2005-11-04 05:38:33 +03:00
|
|
|
directionalFrame = NS_NewDirectionalFrame(shell, kLRO);
|
2001-06-29 07:15:58 +04:00
|
|
|
}
|
|
|
|
break;
|
2001-03-09 04:12:39 +03:00
|
|
|
}
|
2005-11-04 05:38:33 +03:00
|
|
|
|
2006-02-22 00:33:47 +03:00
|
|
|
// Create a directional frame before the first frame of an
|
|
|
|
// element specifying embedding or override
|
|
|
|
if (directionalFrame && !frame->GetPrevContinuation()) {
|
2001-06-29 07:15:58 +04:00
|
|
|
mLogicalFrames.AppendElement(directionalFrame);
|
|
|
|
}
|
|
|
|
}
|
2001-03-09 04:12:39 +03:00
|
|
|
|
2006-02-22 00:33:47 +03:00
|
|
|
if (IsBidiLeaf(frame)) {
|
2003-07-24 22:33:50 +04:00
|
|
|
/* Bidi leaf frame: add the frame to the mLogicalFrames array,
|
|
|
|
* and add its index to the mContentToFrameIndex hashtable. This
|
|
|
|
* will be used in RemoveBidiContinuation() to identify the last
|
|
|
|
* frame in the array with a given content.
|
|
|
|
*/
|
|
|
|
nsIContent* content = frame->GetContent();
|
|
|
|
if (content) {
|
|
|
|
mContentToFrameIndex.Put(content, mLogicalFrames.Count());
|
|
|
|
}
|
2001-03-09 04:12:39 +03:00
|
|
|
mLogicalFrames.AppendElement(frame);
|
|
|
|
}
|
2006-02-22 00:33:47 +03:00
|
|
|
else {
|
|
|
|
nsIFrame* kid = frame->GetFirstChild(nsnull);
|
|
|
|
res = InitLogicalArray(aPresContext, kid, aNextInFlow, aAddMarkers);
|
|
|
|
}
|
2001-03-09 04:12:39 +03:00
|
|
|
|
|
|
|
// If the element is attributed by dir, indicate direction pop (add PDF frame)
|
2005-11-04 05:38:33 +03:00
|
|
|
if (directionalFrame) {
|
|
|
|
directionalFrame = NS_NewDirectionalFrame(shell, kPDF);
|
|
|
|
|
2006-02-22 00:33:47 +03:00
|
|
|
// Create a directional frame after the last frame of an
|
|
|
|
// element specifying embedding or override
|
|
|
|
if (directionalFrame && !frame->GetNextContinuation()) {
|
2001-03-09 04:12:39 +03:00
|
|
|
mLogicalFrames.AppendElement(directionalFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // for
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsBidiPresUtils::CreateBlockBuffer(nsPresContext* aPresContext)
|
2001-03-09 04:12:39 +03:00
|
|
|
{
|
|
|
|
mBuffer.SetLength(0);
|
|
|
|
|
|
|
|
nsIFrame* frame;
|
|
|
|
nsIContent* prevContent = nsnull;
|
|
|
|
nsCOMPtr<nsITextContent> textContent;
|
|
|
|
PRUint32 i;
|
|
|
|
PRUint32 count = mLogicalFrames.Count();
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
frame = (nsIFrame*) (mLogicalFrames[i]);
|
2003-10-31 23:19:18 +03:00
|
|
|
nsIAtom* frameType = frame->GetType();
|
2001-03-09 04:12:39 +03:00
|
|
|
|
2003-10-31 23:19:18 +03:00
|
|
|
if (nsLayoutAtoms::textFrame == frameType) {
|
2003-07-02 14:30:00 +04:00
|
|
|
nsIContent* content = frame->GetContent();
|
|
|
|
if (!content) {
|
|
|
|
mSuccess = NS_OK;
|
2001-03-09 04:12:39 +03:00
|
|
|
break;
|
|
|
|
}
|
2003-07-02 14:30:00 +04:00
|
|
|
if (content == prevContent) {
|
2001-03-09 04:12:39 +03:00
|
|
|
continue;
|
|
|
|
}
|
2003-07-02 14:30:00 +04:00
|
|
|
prevContent = content;
|
2001-03-09 04:12:39 +03:00
|
|
|
textContent = do_QueryInterface(content, &mSuccess);
|
|
|
|
if ( (NS_FAILED(mSuccess) ) || (!textContent) ) {
|
|
|
|
break;
|
|
|
|
}
|
2004-05-08 00:55:17 +04:00
|
|
|
textContent->Text()->AppendTo(mBuffer);
|
2001-03-09 04:12:39 +03:00
|
|
|
}
|
2003-10-31 23:19:18 +03:00
|
|
|
else if (nsLayoutAtoms::brFrame == frameType) { // break frame
|
2001-03-09 04:12:39 +03:00
|
|
|
// Append line separator
|
|
|
|
mBuffer.Append( (PRUnichar) kLineSeparator);
|
|
|
|
}
|
2003-10-31 23:19:18 +03:00
|
|
|
else if (nsLayoutAtoms::directionalFrame == frameType) {
|
2001-03-09 04:12:39 +03:00
|
|
|
nsDirectionalFrame* dirFrame;
|
|
|
|
frame->QueryInterface(NS_GET_IID(nsDirectionalFrame),
|
|
|
|
(void**) &dirFrame);
|
|
|
|
mBuffer.Append(dirFrame->GetChar() );
|
|
|
|
}
|
|
|
|
else { // not text frame
|
|
|
|
// See the Unicode Bidi Algorithm:
|
|
|
|
// "...inline objects (such as graphics) are treated as if they are ... U+FFFC"
|
|
|
|
mBuffer.Append( (PRUnichar) kObjectSubstitute);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// XXX: TODO: Handle preformatted text ('\n')
|
|
|
|
mBuffer.ReplaceChar("\t\r\n", kSpace);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsBidiPresUtils::ReorderFrames(nsPresContext* aPresContext,
|
2001-03-09 04:12:39 +03:00
|
|
|
nsIRenderingContext* aRendContext,
|
|
|
|
nsIFrame* aFirstChild,
|
2006-02-22 00:33:47 +03:00
|
|
|
nsIFrame* aNextInFlow)
|
2001-03-09 04:12:39 +03:00
|
|
|
{
|
|
|
|
mLogicalFrames.Clear();
|
|
|
|
|
2006-02-22 00:33:47 +03:00
|
|
|
for (nsIFrame* frame = aFirstChild;
|
|
|
|
frame && frame != aNextInFlow;
|
|
|
|
frame = frame->GetNextSibling()) {
|
|
|
|
mLogicalFrames.AppendElement(frame);
|
2001-03-09 04:12:39 +03:00
|
|
|
}
|
2006-02-22 00:33:47 +03:00
|
|
|
|
|
|
|
PRBool reordered;
|
|
|
|
Reorder(reordered);
|
|
|
|
RepositionInlineFrames(aPresContext, aRendContext, aFirstChild, reordered);
|
2001-03-09 04:12:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2006-02-22 00:33:47 +03:00
|
|
|
nsBidiPresUtils::Reorder(PRBool& aReordered)
|
2001-03-09 04:12:39 +03:00
|
|
|
{
|
2006-02-22 00:33:47 +03:00
|
|
|
aReordered = PR_FALSE;
|
2001-03-09 04:12:39 +03:00
|
|
|
PRInt32 count = mLogicalFrames.Count();
|
|
|
|
|
|
|
|
if (mArraySize < count) {
|
|
|
|
mArraySize = count << 1;
|
|
|
|
if (mLevels) {
|
|
|
|
delete[] mLevels;
|
|
|
|
mLevels = nsnull;
|
|
|
|
}
|
|
|
|
if (mIndexMap) {
|
|
|
|
delete[] mIndexMap;
|
|
|
|
mIndexMap = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!mLevels) {
|
|
|
|
mLevels = new PRUint8[mArraySize];
|
|
|
|
if (!mLevels) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
2002-01-30 05:55:57 +03:00
|
|
|
memset(mLevels, 0, sizeof(PRUint8) * mArraySize);
|
2001-03-09 04:12:39 +03:00
|
|
|
|
|
|
|
nsIFrame* frame;
|
|
|
|
PRInt32 i;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
frame = (nsIFrame*) (mLogicalFrames[i]);
|
2006-02-22 00:33:47 +03:00
|
|
|
nsIFrame* firstLeaf = frame;
|
|
|
|
while (!IsBidiLeaf(firstLeaf)) {
|
|
|
|
firstLeaf = firstLeaf->GetFirstChild(nsnull);
|
|
|
|
}
|
|
|
|
mLevels[i] = NS_GET_EMBEDDING_LEVEL(firstLeaf);
|
2001-03-09 04:12:39 +03:00
|
|
|
}
|
|
|
|
if (!mIndexMap) {
|
|
|
|
mIndexMap = new PRInt32[mArraySize];
|
|
|
|
}
|
|
|
|
if (!mIndexMap) {
|
|
|
|
mSuccess = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
else {
|
2002-01-30 05:55:57 +03:00
|
|
|
memset(mIndexMap, 0, sizeof(PRUint32) * mArraySize);
|
2001-03-09 04:12:39 +03:00
|
|
|
|
|
|
|
mSuccess = mBidiEngine->ReorderVisual(mLevels, count, mIndexMap);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(mSuccess) ) {
|
|
|
|
mVisualFrames.Clear();
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
2001-08-27 10:15:54 +04:00
|
|
|
mVisualFrames.AppendElement(mLogicalFrames[mIndexMap[i]]);
|
2001-03-09 04:12:39 +03:00
|
|
|
if (i != mIndexMap[i]) {
|
2006-02-22 00:33:47 +03:00
|
|
|
aReordered = PR_TRUE;
|
2001-03-09 04:12:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} // NS_SUCCEEDED(mSuccess)
|
|
|
|
} // indexMap
|
|
|
|
|
|
|
|
if (NS_FAILED(mSuccess) ) {
|
2006-02-22 00:33:47 +03:00
|
|
|
aReordered = PR_FALSE;
|
2001-03-09 04:12:39 +03:00
|
|
|
}
|
|
|
|
return mSuccess;
|
|
|
|
}
|
|
|
|
|
2006-02-22 00:33:47 +03:00
|
|
|
static void
|
|
|
|
ReverseChildFramesPositioning(nsIFrame* aFirstChild)
|
2001-03-09 04:12:39 +03:00
|
|
|
{
|
2006-02-22 00:33:47 +03:00
|
|
|
if (!aFirstChild)
|
2001-03-09 04:12:39 +03:00
|
|
|
return;
|
|
|
|
|
2006-02-22 00:33:47 +03:00
|
|
|
// Get the right edge of the last sibling
|
|
|
|
nsIFrame* lastSibling;
|
|
|
|
for (lastSibling = aFirstChild; lastSibling->GetNextSibling(); lastSibling = lastSibling->GetNextSibling())
|
|
|
|
;
|
|
|
|
nscoord right = lastSibling->GetRect().XMost();
|
|
|
|
|
|
|
|
nsIFrame* frame;
|
|
|
|
for (frame = aFirstChild; frame; frame = frame->GetNextSibling()) {
|
|
|
|
right -= frame->GetRect().width;
|
|
|
|
frame->SetPosition(nsPoint(right, frame->GetPosition().y));
|
|
|
|
if (!IsBidiLeaf(frame))
|
|
|
|
ReverseChildFramesPositioning(frame->GetFirstChild(nsnull));
|
|
|
|
}
|
2001-03-09 04:12:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-02-22 00:33:47 +03:00
|
|
|
nsBidiPresUtils::RepositionInlineFrames(nsPresContext* aPresContext,
|
|
|
|
nsIRenderingContext* aRendContext,
|
|
|
|
nsIFrame* aFirstChild,
|
|
|
|
PRBool aReordered) const
|
2001-03-09 04:12:39 +03:00
|
|
|
{
|
2006-02-22 00:33:47 +03:00
|
|
|
PRInt32 count = mVisualFrames.Count();
|
|
|
|
nscoord left = aFirstChild->GetPosition().x;
|
2001-03-09 04:12:39 +03:00
|
|
|
nsIFrame* frame;
|
2006-02-22 00:33:47 +03:00
|
|
|
|
|
|
|
for (PRInt32 i = 0; i < count; i++) {
|
|
|
|
frame = (nsIFrame*) (mVisualFrames[i]);
|
|
|
|
if (aReordered) // Don't touch positioning if no reordering was done, to avoid killing margins.
|
|
|
|
frame->SetPosition(nsPoint(left, frame->GetPosition().y));
|
|
|
|
left += frame->GetRect().width;
|
2001-03-09 04:12:39 +03:00
|
|
|
|
2006-02-22 00:33:47 +03:00
|
|
|
// If this is an odd-level frame, reverse the positioning of its childern
|
|
|
|
if ((mLevels[mIndexMap[i]] & 1) && !IsBidiLeaf(frame))
|
|
|
|
ReverseChildFramesPositioning(frame->GetFirstChild(nsnull));
|
|
|
|
} // for
|
2001-03-09 04:12:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
2004-08-01 03:15:21 +04:00
|
|
|
nsBidiPresUtils::EnsureBidiContinuation(nsPresContext* aPresContext,
|
2001-03-09 04:12:39 +03:00
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsIFrame** aNewFrame,
|
|
|
|
PRInt32& aFrameIndex)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aNewFrame, "null OUT ptr");
|
|
|
|
if (!aNewFrame) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
*aNewFrame = nsnull;
|
|
|
|
|
|
|
|
if (!aFrame) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (aFrameIndex + 1 < mLogicalFrames.Count() ) {
|
|
|
|
nsIFrame* frame = (nsIFrame*)mLogicalFrames[aFrameIndex + 1];
|
2003-07-02 14:30:00 +04:00
|
|
|
if (frame->GetContent() == aContent) {
|
2001-03-09 04:12:39 +03:00
|
|
|
*aNewFrame = frame;
|
|
|
|
++aFrameIndex;
|
2006-02-22 00:33:47 +03:00
|
|
|
aFrame->SetNextContinuation(frame);
|
|
|
|
frame->SetPrevContinuation(aFrame);
|
|
|
|
|
|
|
|
// Make existing parent continuations non-fluid
|
|
|
|
nsIFrame* parent = frame->GetParent();
|
|
|
|
while (parent &&
|
|
|
|
(nsLayoutAtoms::inlineFrame == parent->GetType() ||
|
|
|
|
nsLayoutAtoms::positionedInlineFrame == parent->GetType())) {
|
|
|
|
nsIFrame* prevContinuation = parent->GetPrevContinuation();
|
|
|
|
if (prevContinuation) {
|
|
|
|
parent->SetPrevContinuation(prevContinuation);
|
|
|
|
prevContinuation->SetNextContinuation(parent);
|
|
|
|
}
|
|
|
|
parent = parent->GetParent();
|
|
|
|
}
|
2001-03-09 04:12:39 +03:00
|
|
|
}
|
|
|
|
}
|
2006-02-22 00:33:47 +03:00
|
|
|
if (!*aNewFrame) {
|
|
|
|
mSuccess = CreateBidiContinuation(aPresContext, aFrame, aNewFrame);
|
2001-03-09 04:12:39 +03:00
|
|
|
if (NS_FAILED(mSuccess) ) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
2006-02-22 00:33:47 +03:00
|
|
|
|
2001-03-09 04:12:39 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2003-07-24 22:33:50 +04:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsBidiPresUtils::RemoveBidiContinuation(nsPresContext* aPresContext,
|
2001-03-09 04:12:39 +03:00
|
|
|
nsIFrame* aFrame,
|
2003-07-24 22:33:50 +04:00
|
|
|
PRInt32 aFirstIndex,
|
|
|
|
PRInt32 aLastIndex,
|
2001-03-09 04:12:39 +03:00
|
|
|
PRInt32& aOffset) const
|
|
|
|
{
|
2003-07-24 22:33:50 +04:00
|
|
|
nsIFrame* frame;
|
|
|
|
PRInt32 index;
|
2001-03-09 04:12:39 +03:00
|
|
|
|
|
|
|
aOffset = 0;
|
|
|
|
|
2003-07-24 22:33:50 +04:00
|
|
|
for (index = aLastIndex; index > aFirstIndex; index--) {
|
2001-03-09 04:12:39 +03:00
|
|
|
frame = (nsIFrame*) mLogicalFrames[index];
|
2003-10-31 23:19:18 +03:00
|
|
|
if (nsLayoutAtoms::directionalFrame == frame->GetType()) {
|
2005-12-03 18:44:43 +03:00
|
|
|
frame->Destroy(aPresContext);
|
2001-03-09 04:12:39 +03:00
|
|
|
++aOffset;
|
|
|
|
}
|
|
|
|
else {
|
2003-07-02 14:30:00 +04:00
|
|
|
if (frame->GetStateBits() & NS_FRAME_IS_BIDI) {
|
2002-04-23 02:55:19 +04:00
|
|
|
// only delete Bidi frames
|
2006-02-22 00:33:47 +03:00
|
|
|
nsIFrame* parent = frame->GetParent();
|
|
|
|
parent->RemoveFrame(nsLayoutAtoms::nextBidi, frame);
|
|
|
|
// Make parent continuations fluid, so they can be
|
|
|
|
// reused or deleted by inline reflow code
|
|
|
|
while (parent) {
|
|
|
|
nsIFrame* parentPrev = parent->GetPrevContinuation();
|
|
|
|
if (parentPrev) {
|
|
|
|
parent->SetPrevInFlow(parentPrev);
|
|
|
|
parentPrev->SetNextInFlow(parent);
|
|
|
|
parent = parent->GetParent();
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
2002-04-23 02:55:19 +04:00
|
|
|
}
|
|
|
|
}
|
2001-03-09 04:12:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2004-08-01 03:15:21 +04:00
|
|
|
nsBidiPresUtils::FormatUnicodeText(nsPresContext* aPresContext,
|
2001-03-09 04:12:39 +03:00
|
|
|
PRUnichar* aText,
|
|
|
|
PRInt32& aTextLength,
|
|
|
|
nsCharType aCharType,
|
|
|
|
PRBool aIsOddLevel,
|
|
|
|
PRBool aIsBidiSystem)
|
|
|
|
{
|
2002-06-12 01:00:20 +04:00
|
|
|
NS_ASSERTION(aIsOddLevel == 0 || aIsOddLevel == 1, "aIsOddLevel should be 0 or 1");
|
2001-10-01 07:43:42 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
// ahmed
|
|
|
|
//adjusted for correct numeral shaping
|
2004-07-29 23:41:39 +04:00
|
|
|
PRUint32 bidiOptions = aPresContext->GetBidi();
|
2001-04-12 03:32:21 +04:00
|
|
|
switch (GET_BIDI_OPTION_NUMERAL(bidiOptions)) {
|
2001-03-09 04:12:39 +03:00
|
|
|
|
|
|
|
case IBMBIDI_NUMERAL_HINDI:
|
2002-02-19 23:41:32 +03:00
|
|
|
HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_HINDI);
|
2001-03-09 04:12:39 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IBMBIDI_NUMERAL_ARABIC:
|
2002-02-19 23:41:32 +03:00
|
|
|
HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_ARABIC);
|
2001-03-09 04:12:39 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IBMBIDI_NUMERAL_REGULAR:
|
|
|
|
|
|
|
|
switch (aCharType) {
|
|
|
|
|
|
|
|
case eCharType_EuropeanNumber:
|
2002-02-19 23:41:32 +03:00
|
|
|
HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_ARABIC);
|
2001-03-09 04:12:39 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case eCharType_ArabicNumber:
|
2002-02-19 23:41:32 +03:00
|
|
|
HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_HINDI);
|
2001-03-09 04:12:39 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IBMBIDI_NUMERAL_HINDICONTEXT:
|
2001-04-12 03:32:21 +04:00
|
|
|
if ( ( (GET_BIDI_OPTION_DIRECTION(bidiOptions)==IBMBIDI_TEXTDIRECTION_RTL) && (IS_ARABIC_DIGIT (aText[0])) ) || (eCharType_ArabicNumber == aCharType) )
|
2002-02-19 23:41:32 +03:00
|
|
|
HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_HINDI);
|
2001-03-09 04:12:39 +03:00
|
|
|
else if (eCharType_EuropeanNumber == aCharType)
|
2002-02-19 23:41:32 +03:00
|
|
|
HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_ARABIC);
|
2001-03-09 04:12:39 +03:00
|
|
|
break;
|
|
|
|
|
2003-05-08 22:38:19 +04:00
|
|
|
case IBMBIDI_NUMERAL_NOMINAL:
|
2001-03-09 04:12:39 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool doReverse = PR_FALSE;
|
2001-10-01 07:43:42 +04:00
|
|
|
PRBool doShape = PR_FALSE;
|
2001-03-09 04:12:39 +03:00
|
|
|
|
|
|
|
if (aIsBidiSystem) {
|
2001-10-01 07:43:42 +04:00
|
|
|
if ( (CHARTYPE_IS_RTL(aCharType)) ^ (aIsOddLevel) )
|
2001-03-09 04:12:39 +03:00
|
|
|
doReverse = PR_TRUE;
|
|
|
|
}
|
2001-10-01 07:43:42 +04:00
|
|
|
else {
|
|
|
|
if (aIsOddLevel)
|
|
|
|
doReverse = PR_TRUE;
|
|
|
|
if (eCharType_RightToLeftArabic == aCharType)
|
|
|
|
doShape = PR_TRUE;
|
2001-05-15 16:04:34 +04:00
|
|
|
}
|
2001-10-01 07:43:42 +04:00
|
|
|
|
|
|
|
if (doReverse || doShape) {
|
|
|
|
PRInt32 newLen;
|
|
|
|
|
|
|
|
if (mBuffer.Length() < aTextLength) {
|
|
|
|
mBuffer.SetLength(aTextLength);
|
|
|
|
}
|
2004-02-29 01:34:07 +03:00
|
|
|
PRUnichar* buffer = mBuffer.BeginWriting();
|
2001-10-01 07:43:42 +04:00
|
|
|
|
|
|
|
if (doReverse) {
|
2001-03-09 04:12:39 +03:00
|
|
|
rv = mBidiEngine->WriteReverse(aText, aTextLength, buffer,
|
2001-11-14 17:21:52 +03:00
|
|
|
NSBIDI_DO_MIRRORING, &newLen);
|
2001-10-01 07:43:42 +04:00
|
|
|
if (NS_SUCCEEDED(rv) ) {
|
|
|
|
aTextLength = newLen;
|
2002-01-12 06:18:55 +03:00
|
|
|
memcpy(aText, buffer, aTextLength * sizeof(PRUnichar) );
|
2001-10-01 07:43:42 +04:00
|
|
|
}
|
2001-03-09 04:12:39 +03:00
|
|
|
}
|
2001-10-01 07:43:42 +04:00
|
|
|
if (doShape) {
|
2002-04-24 04:26:49 +04:00
|
|
|
rv = ArabicShaping(aText, aTextLength, buffer, (PRUint32 *)&newLen,
|
|
|
|
PR_FALSE, PR_FALSE);
|
2001-10-01 07:43:42 +04:00
|
|
|
if (NS_SUCCEEDED(rv) ) {
|
|
|
|
aTextLength = newLen;
|
2002-01-12 06:18:55 +03:00
|
|
|
memcpy(aText, buffer, aTextLength * sizeof(PRUnichar) );
|
2001-10-01 07:43:42 +04:00
|
|
|
}
|
2001-06-29 07:15:58 +04:00
|
|
|
}
|
2001-10-01 07:43:42 +04:00
|
|
|
}
|
2002-04-24 03:50:17 +04:00
|
|
|
StripBidiControlCharacters(aText, aTextLength);
|
2001-03-09 04:12:39 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2002-04-24 03:50:17 +04:00
|
|
|
void
|
|
|
|
nsBidiPresUtils::StripBidiControlCharacters(PRUnichar* aText,
|
|
|
|
PRInt32& aTextLength) const
|
|
|
|
{
|
|
|
|
if ( (nsnull == aText) || (aTextLength < 1) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 stripLen = 0;
|
|
|
|
|
|
|
|
for (PRInt32 i = 0; i < aTextLength; i++) {
|
2004-05-18 15:01:49 +04:00
|
|
|
// XXX: This silently ignores surrogate characters.
|
|
|
|
// As of Unicode 4.0, all Bidi control characters are within the BMP.
|
|
|
|
if (mBidiEngine->IsBidiControl((PRUint32)aText[i])) {
|
2002-04-24 03:50:17 +04:00
|
|
|
++stripLen;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aText[i - stripLen] = aText[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aTextLength -= stripLen;
|
|
|
|
}
|
|
|
|
|
2001-03-09 04:12:39 +03:00
|
|
|
#if 0 // XXX: for the future use ???
|
|
|
|
void
|
|
|
|
RemoveDiacritics(PRUnichar* aText,
|
|
|
|
PRInt32& aTextLength)
|
|
|
|
{
|
|
|
|
if (aText && (aTextLength > 0) ) {
|
|
|
|
PRInt32 offset = 0;
|
|
|
|
|
|
|
|
for (PRInt32 i = 0; i < aTextLength && aText[i]; i++) {
|
|
|
|
if (IS_BIDI_DIACRITIC(aText[i]) ) {
|
|
|
|
++offset;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
aText[i - offset] = aText[i];
|
|
|
|
}
|
|
|
|
aTextLength = i - offset;
|
|
|
|
aText[aTextLength] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
2001-06-29 07:15:58 +04:00
|
|
|
nsBidiPresUtils::CalculateCharType(PRInt32& aOffset,
|
|
|
|
PRInt32 aCharTypeLimit,
|
|
|
|
PRInt32& aRunLimit,
|
|
|
|
PRInt32& aRunLength,
|
|
|
|
PRInt32& aRunCount,
|
2001-03-09 04:12:39 +03:00
|
|
|
PRUint8& aCharType,
|
|
|
|
PRUint8& aPrevCharType) const
|
2001-06-29 07:15:58 +04:00
|
|
|
|
2001-03-09 04:12:39 +03:00
|
|
|
{
|
|
|
|
PRBool strongTypeFound = PR_FALSE;
|
|
|
|
PRInt32 offset;
|
|
|
|
nsCharType charType;
|
|
|
|
|
|
|
|
aCharType = eCharType_OtherNeutral;
|
|
|
|
|
2001-06-29 07:15:58 +04:00
|
|
|
for (offset = aOffset; offset < aCharTypeLimit; offset++) {
|
2005-06-23 12:03:24 +04:00
|
|
|
// Make sure we give RTL chartype to all characters that would be classified
|
2001-03-09 04:12:39 +03:00
|
|
|
// as Right-To-Left by a bidi platform.
|
2005-06-23 12:03:24 +04:00
|
|
|
// (May differ from the UnicodeData, eg we set RTL chartype to some NSMs.)
|
2001-03-09 04:12:39 +03:00
|
|
|
if (IS_HEBREW_CHAR(mBuffer[offset]) ) {
|
|
|
|
charType = eCharType_RightToLeft;
|
|
|
|
}
|
2001-10-01 07:43:42 +04:00
|
|
|
else if (IS_ARABIC_ALPHABETIC(mBuffer[offset]) ) {
|
2001-03-09 04:12:39 +03:00
|
|
|
charType = eCharType_RightToLeftArabic;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mBidiEngine->GetCharTypeAt(offset, &charType);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CHARTYPE_IS_WEAK(charType) ) {
|
2001-06-29 07:15:58 +04:00
|
|
|
|
|
|
|
if (strongTypeFound
|
|
|
|
&& (charType != aPrevCharType)
|
|
|
|
&& (CHARTYPE_IS_RTL(charType) || CHARTYPE_IS_RTL(aPrevCharType) ) ) {
|
|
|
|
// Stop at this point to ensure uni-directionality of the text
|
|
|
|
// (from platform's point of view).
|
|
|
|
// Also, don't mix Arabic and Hebrew content (since platform may
|
|
|
|
// provide BIDI support to one of them only).
|
|
|
|
aRunLength = offset - aOffset;
|
2001-10-01 07:43:42 +04:00
|
|
|
aRunLimit = offset;
|
2001-06-29 07:15:58 +04:00
|
|
|
++aRunCount;
|
2001-10-01 07:43:42 +04:00
|
|
|
break;
|
2001-06-29 07:15:58 +04:00
|
|
|
}
|
|
|
|
|
2001-03-09 04:12:39 +03:00
|
|
|
if ( (eCharType_RightToLeftArabic == aPrevCharType
|
2001-06-29 07:15:58 +04:00
|
|
|
|| eCharType_ArabicNumber == aPrevCharType)
|
2001-03-09 04:12:39 +03:00
|
|
|
&& eCharType_EuropeanNumber == charType) {
|
|
|
|
charType = eCharType_ArabicNumber;
|
|
|
|
}
|
2001-06-29 07:15:58 +04:00
|
|
|
|
2001-03-09 04:12:39 +03:00
|
|
|
// Set PrevCharType to the last strong type in this frame
|
|
|
|
// (for correct numeric shaping)
|
|
|
|
aPrevCharType = charType;
|
|
|
|
|
2001-10-01 07:43:42 +04:00
|
|
|
strongTypeFound = PR_TRUE;
|
|
|
|
aCharType = charType;
|
2001-03-09 04:12:39 +03:00
|
|
|
}
|
|
|
|
}
|
2001-10-01 07:43:42 +04:00
|
|
|
aOffset = offset;
|
2001-06-29 07:15:58 +04:00
|
|
|
}
|
|
|
|
|
2002-02-19 23:41:32 +03:00
|
|
|
nsresult nsBidiPresUtils::GetBidiEngine(nsBidi** aBidiEngine)
|
2001-03-09 04:12:39 +03:00
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
if (mBidiEngine) {
|
|
|
|
*aBidiEngine = mBidiEngine;
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
2001-11-12 23:51:48 +03:00
|
|
|
|
2004-10-29 16:28:19 +04:00
|
|
|
nsresult nsBidiPresUtils::RenderText(const PRUnichar* aText,
|
2001-11-12 23:51:48 +03:00
|
|
|
PRInt32 aLength,
|
|
|
|
nsBidiDirection aBaseDirection,
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext* aPresContext,
|
2001-11-12 23:51:48 +03:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
nscoord aX,
|
2004-10-29 16:28:19 +04:00
|
|
|
nscoord aY,
|
|
|
|
nsBidiPositionResolve* aPosResolve,
|
|
|
|
PRInt32 aPosResolveCount)
|
2001-11-12 23:51:48 +03:00
|
|
|
{
|
2004-10-29 16:28:19 +04:00
|
|
|
NS_ASSERTION((aPosResolve == nsnull) != (aPosResolveCount > 0), "Incorrect aPosResolve / aPosResolveCount arguments");
|
|
|
|
|
2001-11-12 23:51:48 +03:00
|
|
|
PRInt32 runCount;
|
|
|
|
|
|
|
|
mBuffer.Assign(aText);
|
|
|
|
|
|
|
|
nsresult rv = mBidiEngine->SetPara(mBuffer.get(), aLength, aBaseDirection, nsnull);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
rv = mBidiEngine->CountRuns(&runCount);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2004-10-29 16:28:19 +04:00
|
|
|
nscoord width, xEndRun, xStartText = aX;
|
2001-11-12 23:51:48 +03:00
|
|
|
PRBool isRTL = PR_FALSE;
|
|
|
|
PRInt32 i, start, limit, length;
|
2004-10-29 16:28:19 +04:00
|
|
|
PRUint32 visualStart = 0;
|
2001-11-12 23:51:48 +03:00
|
|
|
PRUint8 charType;
|
|
|
|
PRUint8 prevType = eCharType_LeftToRight;
|
|
|
|
nsBidiLevel level;
|
|
|
|
|
|
|
|
PRUint32 hints = 0;
|
|
|
|
aRenderingContext.GetHints(hints);
|
|
|
|
PRBool isBidiSystem = (hints & NS_RENDERING_HINT_BIDI_REORDERING);
|
2004-10-29 16:28:19 +04:00
|
|
|
|
|
|
|
for(int nPosResolve=0; nPosResolve < aPosResolveCount; ++nPosResolve)
|
|
|
|
{
|
|
|
|
aPosResolve[nPosResolve].visualIndex = kNotFound;
|
|
|
|
aPosResolve[nPosResolve].visualLeftTwips = kNotFound;
|
|
|
|
}
|
2001-11-12 23:51:48 +03:00
|
|
|
|
|
|
|
for (i = 0; i < runCount; i++) {
|
|
|
|
rv = mBidiEngine->GetVisualRun(i, &start, &length, &aBaseDirection);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
rv = mBidiEngine->GetLogicalRun(start, &limit, &level);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2002-02-08 04:53:59 +03:00
|
|
|
PRInt32 subRunLength = limit - start;
|
|
|
|
PRInt32 lineOffset = start;
|
2001-11-12 23:51:48 +03:00
|
|
|
PRInt32 typeLimit = PR_MIN(limit, aLength);
|
2002-02-08 04:53:59 +03:00
|
|
|
PRInt32 subRunCount = 1;
|
|
|
|
PRInt32 subRunLimit = typeLimit;
|
2001-11-12 23:51:48 +03:00
|
|
|
|
2004-07-07 10:49:10 +04:00
|
|
|
/*
|
|
|
|
* If |level| is even, i.e. the direction of the run is left-to-right, we
|
|
|
|
* render the subruns from left to right and increment the x-coordinate
|
|
|
|
* |aX| by the width of each subrun after rendering.
|
|
|
|
*
|
|
|
|
* If |level| is odd, i.e. the direction of the run is right-to-left, we
|
|
|
|
* render the subruns from right to left. We begin by incrementing |aX| by
|
|
|
|
* the width of the whole run, and then decrement it by the width of each
|
|
|
|
* subrun before rendering. After rendering all the subruns, we restore the
|
|
|
|
* x-coordinate of the end of the run for the start of the next run.
|
|
|
|
*/
|
|
|
|
if (level & 1) {
|
|
|
|
aRenderingContext.GetWidth(aText + start, subRunLength, width, nsnull);
|
|
|
|
aX += width;
|
|
|
|
xEndRun = aX;
|
|
|
|
}
|
|
|
|
|
2002-02-08 04:53:59 +03:00
|
|
|
while (subRunCount > 0) {
|
|
|
|
// CalculateCharType can increment subRunCount if the run
|
|
|
|
// contains mixed character types
|
|
|
|
CalculateCharType(lineOffset, typeLimit, subRunLimit, subRunLength, subRunCount, charType, prevType);
|
2001-11-12 23:51:48 +03:00
|
|
|
|
2002-02-08 04:53:59 +03:00
|
|
|
if (eCharType_RightToLeftArabic == charType) {
|
|
|
|
isBidiSystem = (hints & NS_RENDERING_HINT_ARABIC_SHAPING);
|
|
|
|
}
|
|
|
|
if (isBidiSystem && (CHARTYPE_IS_RTL(charType) ^ isRTL) ) {
|
|
|
|
// set reading order into DC
|
|
|
|
isRTL = !isRTL;
|
|
|
|
aRenderingContext.SetRightToLeftText(isRTL);
|
|
|
|
}
|
2004-10-29 16:28:19 +04:00
|
|
|
|
|
|
|
nsAutoString runVisualText;
|
|
|
|
runVisualText.Assign(aText + start, subRunLength);
|
|
|
|
FormatUnicodeText(aPresContext, runVisualText.BeginWriting(), subRunLength,
|
2002-02-08 04:53:59 +03:00
|
|
|
(nsCharType)charType, level & 1,
|
|
|
|
isBidiSystem);
|
|
|
|
|
2004-10-29 16:28:19 +04:00
|
|
|
aRenderingContext.GetWidth(runVisualText.get(), subRunLength, width, nsnull);
|
2004-07-07 10:49:10 +04:00
|
|
|
if (level & 1) {
|
|
|
|
aX -= width;
|
|
|
|
}
|
2004-10-29 16:28:19 +04:00
|
|
|
aRenderingContext.DrawString(runVisualText.get(), subRunLength, aX, aY, width);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The caller may request to calculate the visual position of one
|
|
|
|
* or more characters.
|
|
|
|
*/
|
|
|
|
for(int nPosResolve=0; nPosResolve<aPosResolveCount; ++nPosResolve)
|
|
|
|
{
|
|
|
|
nsBidiPositionResolve* posResolve = &aPosResolve[nPosResolve];
|
|
|
|
/*
|
|
|
|
* Did we already resolve this position's visual metric? If so, skip.
|
|
|
|
*/
|
|
|
|
if (posResolve->visualLeftTwips != kNotFound)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First find out if the logical position is within this run.
|
|
|
|
*/
|
|
|
|
if (start <= posResolve->logicalIndex &&
|
|
|
|
start + subRunLength > posResolve->logicalIndex) {
|
|
|
|
/*
|
|
|
|
* If this run is only one character long, we have an easy case:
|
|
|
|
* the visual position is the x-coord of the start of the run
|
|
|
|
* less the x-coord of the start of the whole text (saved in xStartText).
|
|
|
|
*/
|
|
|
|
if (subRunLength == 1) {
|
|
|
|
posResolve->visualIndex = visualStart;
|
|
|
|
posResolve->visualLeftTwips = aX - xStartText;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Otherwise, we need to measure the width of the run's part
|
|
|
|
* which is to the visual left of the index.
|
|
|
|
* In other words, the run is broken in two, around the logical index,
|
|
|
|
* and we measure the part which is visually left.
|
|
|
|
* If the run is right-to-left, this part will span from after the index
|
|
|
|
* up to the end of the run; if it is left-to-right, this part will span
|
|
|
|
* from the start of the run up to (and inclduing) the character before the index.
|
|
|
|
*/
|
|
|
|
else {
|
|
|
|
nscoord subWidth;
|
|
|
|
// The position in the text where this run's "left part" begins.
|
|
|
|
const PRUnichar* visualLeftPart;
|
|
|
|
if (level & 1) {
|
|
|
|
// One day, son, this could all be replaced with mBidiEngine.GetVisualIndex ...
|
|
|
|
posResolve->visualIndex = visualStart + (subRunLength - (posResolve->logicalIndex + 1 - start));
|
|
|
|
// Skipping to the "left part".
|
|
|
|
visualLeftPart = aText + posResolve->logicalIndex + 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
posResolve->visualIndex = visualStart + (posResolve->logicalIndex - start);
|
|
|
|
// Skipping to the "left part".
|
|
|
|
visualLeftPart = aText + start;
|
|
|
|
}
|
|
|
|
// The delta between the start of the run and the left part's end.
|
|
|
|
PRInt32 visualLeftLength = posResolve->visualIndex - visualStart;
|
|
|
|
aRenderingContext.GetWidth(visualLeftPart,
|
|
|
|
visualLeftLength,
|
|
|
|
subWidth, nsnull);
|
|
|
|
posResolve->visualLeftTwips = aX + subWidth - xStartText;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-07 10:49:10 +04:00
|
|
|
if (!(level & 1)) {
|
|
|
|
aX += width;
|
|
|
|
}
|
2002-02-08 04:53:59 +03:00
|
|
|
|
|
|
|
--subRunCount;
|
|
|
|
start = lineOffset;
|
|
|
|
subRunLimit = typeLimit;
|
|
|
|
subRunLength = typeLimit - lineOffset;
|
|
|
|
} // while
|
2004-07-07 10:49:10 +04:00
|
|
|
if (level & 1) {
|
|
|
|
aX = xEndRun;
|
|
|
|
}
|
2004-10-29 16:28:19 +04:00
|
|
|
|
|
|
|
visualStart += length;
|
2001-11-12 23:51:48 +03:00
|
|
|
} // for
|
|
|
|
|
|
|
|
// Restore original reading order
|
|
|
|
if (isRTL) {
|
|
|
|
aRenderingContext.SetRightToLeftText(PR_FALSE);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-03-09 04:12:39 +03:00
|
|
|
|
2002-06-12 01:00:20 +04:00
|
|
|
nsresult
|
|
|
|
nsBidiPresUtils::ReorderUnicodeText(PRUnichar* aText,
|
|
|
|
PRInt32& aTextLength,
|
|
|
|
nsCharType aCharType,
|
|
|
|
PRBool aIsOddLevel,
|
|
|
|
PRBool aIsBidiSystem)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aIsOddLevel == 0 || aIsOddLevel == 1, "aIsOddLevel should be 0 or 1");
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
PRBool doReverse = PR_FALSE;
|
|
|
|
|
|
|
|
if (aIsBidiSystem) {
|
|
|
|
if ( (CHARTYPE_IS_RTL(aCharType)) ^ (aIsOddLevel) )
|
|
|
|
doReverse = PR_TRUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (aIsOddLevel)
|
|
|
|
doReverse = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (doReverse) {
|
|
|
|
PRInt32 newLen;
|
|
|
|
|
|
|
|
if (mBuffer.Length() < aTextLength) {
|
|
|
|
mBuffer.SetLength(aTextLength);
|
|
|
|
}
|
2004-02-29 01:34:07 +03:00
|
|
|
PRUnichar* buffer = mBuffer.BeginWriting();
|
2002-06-12 01:00:20 +04:00
|
|
|
|
|
|
|
if (doReverse) {
|
|
|
|
rv = mBidiEngine->WriteReverse(aText, aTextLength, buffer,
|
|
|
|
NSBIDI_DO_MIRRORING, &newLen);
|
|
|
|
if (NS_SUCCEEDED(rv) ) {
|
|
|
|
aTextLength = newLen;
|
|
|
|
memcpy(aText, buffer, aTextLength * sizeof(PRUnichar) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-03-09 04:12:39 +03:00
|
|
|
#endif // IBMBIDI
|