Back to index

lightning-sunbird  0.9+nobinonly
nsBidiPresUtils.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is mozilla.org code.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * IBM Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 2000
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   IBM Corporation
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either of the GNU General Public License Version 2 or later (the "GPL"),
00028  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #ifdef IBMBIDI
00041 
00042 #ifndef nsBidiPresUtils_h___
00043 #define nsBidiPresUtils_h___
00044 
00045 #include "nsVoidArray.h"
00046 #include "nsIFrame.h"
00047 #include "nsBidi.h"
00048 #include "nsBidiUtils.h"
00049 #include "nsCOMPtr.h"
00050 #include "nsDataHashtable.h"
00051 
00056 struct nsBidiPositionResolve
00057 {
00058   // [in] Logical index within string.
00059   PRInt32 logicalIndex;
00060   // [out] Visual index within string.
00061   // If the logical position was not found, set to kNotFound.
00062   PRInt32 visualIndex;
00063   // [out] Visual position of the character, from the left (on the X axis), in twips.
00064   // Eessentially, this is the X position (relative to the rendering context) where the text was drawn + the font metric of the visual string to the left of the given logical position.
00065   // If the logical position was not found, set to kNotFound.
00066   PRInt32 visualLeftTwips;
00067 };
00068 
00069 class nsBidiPresUtils {
00070 public:
00071   nsBidiPresUtils();
00072   ~nsBidiPresUtils();
00073   PRBool IsSuccessful(void) const;
00074   
00090   nsresult Resolve(nsPresContext* aPresContext,
00091                    nsIFrame*       aBlockFrame,
00092                    nsIFrame*       aFirstChild,
00093                    PRBool&         aForceReflow,
00094                    PRBool          aIsVisualFormControl);
00095 
00102   void ReorderFrames(nsPresContext*      aPresContext,
00103                      nsIRenderingContext* aRendContext,
00104                      nsIFrame*            aFirstChild,
00105                      nsIFrame*            aNextInFlow,
00106                      PRInt32              aChildCount);
00107 
00115   nsresult FormatUnicodeText(nsPresContext* aPresContext,
00116                              PRUnichar*      aText,
00117                              PRInt32&        aTextLength,
00118                              nsCharType      aCharType,
00119                              PRBool          aIsOddLevel,
00120                              PRBool          aIsBidiSystem);
00121 
00127   nsresult ReorderUnicodeText(PRUnichar*      aText,
00128                               PRInt32&        aTextLength,
00129                               nsCharType      aCharType,
00130                               PRBool          aIsOddLevel,
00131                               PRBool          aIsBidiSystem);
00132 
00136   nsresult GetBidiEngine(nsBidi** aBidiEngine);
00137 
00154   nsresult RenderText(const PRUnichar*     aText,
00155                       PRInt32              aLength,
00156                       nsBidiDirection      aBaseDirection,
00157                       nsPresContext*      aPresContext,
00158                       nsIRenderingContext& aRenderingContext,
00159                       nscoord              aX,
00160                       nscoord              aY,
00161                       nsBidiPositionResolve* aPosResolve = nsnull,
00162                       PRInt32              aPosResolveCount = 0);
00163 
00164 private:
00170   void CreateBlockBuffer(nsPresContext* aPresContext);
00171 
00177   nsresult InitLogicalArray(nsPresContext* aPresContext,
00178                             nsIFrame*       aCurrentFrame,
00179                             nsIFrame*       aNextInFlow,
00180                             PRBool          aAddMarkers = PR_FALSE);
00188   nsresult Reorder(nsPresContext* aPresContext,
00189                    PRBool&         aBidiEnabled);
00190   
00198   void RepositionInlineFrames(nsPresContext*      aPresContext,
00199                               nsIRenderingContext* aRendContext,
00200                               nsIFrame*            aFirstChild,
00201                               PRInt32              aChildCount) const;
00202   
00203   void RepositionContainerFrame(nsPresContext* aPresContext,
00204                                 nsIFrame*       aContainer,
00205                                 PRInt32&        aMinX,
00206                                 PRInt32&        aMaxX) const;
00224   PRBool EnsureBidiContinuation(nsPresContext* aPresContext,
00225                                 nsIContent*     aContent,
00226                                 nsIFrame*       aFrame,
00227                                 nsIFrame**      aNewFrame,
00228                                 PRInt32&        aFrameIndex);
00229 
00247   void RemoveBidiContinuation(nsPresContext* aPresContext,
00248                               nsIFrame*       aFrame,
00249                               PRInt32         aFirstIndex,
00250                               PRInt32         aLastIndex,
00251                               PRInt32&        aOffset) const;
00252   void CalculateCharType(PRInt32& aOffset,
00253                          PRInt32  aCharTypeLimit,
00254                          PRInt32& aRunLimit,
00255                          PRInt32& aRunLength,
00256                          PRInt32& aRunCount,
00257                          PRUint8& aCharType,
00258                          PRUint8& aPrevCharType) const;
00259   
00260   void StripBidiControlCharacters(PRUnichar* aText,
00261                                   PRInt32&   aTextLength) const;
00262   nsAutoString    mBuffer;
00263   nsVoidArray     mLogicalFrames;
00264   nsVoidArray     mVisualFrames;
00265   nsDataHashtable<nsISupportsHashKey, PRInt32> mContentToFrameIndex;
00266   PRInt32         mArraySize;
00267   PRInt32*        mIndexMap;
00268   PRUint8*        mLevels;
00269   nsresult        mSuccess;
00270 
00271   nsBidi*         mBidiEngine;
00272 };
00273 
00274 #endif /* nsBidiPresUtils_h___ */
00275 
00276 #endif // IBMBIDI