LCOV - code coverage report
Current view: directory - layout/generic - nsTextFrameUtils.h (source / functions) Found Hit Coverage
Test: app.info Lines: 21 0 0.0 %
Date: 2012-06-02 Functions: 11 0 0.0 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
       2                 :  * ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is Novell code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is Novell Corporation.
      18                 :  * Portions created by the Initial Developer are Copyright (C) 2006
      19                 :  * the Initial Developer. All Rights Reserved.
      20                 :  *
      21                 :  * Contributor(s):
      22                 :  *   robert@ocallahan.org
      23                 :  *   Ehsan Akhgari <ehsan.akhgari@gmail.com>
      24                 :  *
      25                 :  * Alternatively, the contents of this file may be used under the terms of
      26                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      27                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      29                 :  * of those above. If you wish to allow use of your version of this file only
      30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      31                 :  * use your version of this file under the terms of the MPL, indicate your
      32                 :  * decision by deleting the provisions above and replace them with the notice
      33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      34                 :  * the provisions above, a recipient may use your version of this file under
      35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      36                 :  *
      37                 :  * ***** END LICENSE BLOCK ***** */
      38                 : 
      39                 : #ifndef NSTEXTFRAMEUTILS_H_
      40                 : #define NSTEXTFRAMEUTILS_H_
      41                 : 
      42                 : #include "gfxFont.h"
      43                 : #include "gfxSkipChars.h"
      44                 : #include "nsTextFragment.h"
      45                 : 
      46                 : #define BIG_TEXT_NODE_SIZE 4096
      47                 : 
      48                 : #define CH_NBSP   160
      49                 : #define CH_SHY    173
      50                 : #define CH_CJKSP  12288 // U+3000 IDEOGRAPHIC SPACE (CJK Full-Width Space)
      51                 : 
      52                 : #define CH_LRM  8206  //<!ENTITY lrm     CDATA "&#8206;" -- left-to-right mark, U+200E NEW RFC 2070 -->
      53                 : #define CH_RLM  8207  //<!ENTITY rlm     CDATA "&#8207;" -- right-to-left mark, U+200F NEW RFC 2070 -->
      54                 : #define CH_LRE  8234  //<!CDATA "&#8234;" -- left-to-right embedding, U+202A -->
      55                 : #define CH_RLO  8238  //<!CDATA "&#8238;" -- right-to-left override, U+202E -->
      56                 : 
      57                 : class nsTextFrameUtils {
      58                 : public:
      59                 :   // These constants are used as textrun flags for textframe textruns.
      60                 :   enum {
      61                 :     // The following flags are set by TransformText
      62                 : 
      63                 :     // the text has at least one untransformed tab character
      64                 :     TEXT_HAS_TAB             = 0x010000,
      65                 :     // the original text has at least one soft hyphen character
      66                 :     TEXT_HAS_SHY             = 0x020000,
      67                 :     TEXT_WAS_TRANSFORMED     = 0x040000,
      68                 :     TEXT_UNUSED_FLAG         = 0x080000,
      69                 : 
      70                 :     // The following flags are set by nsTextFrame
      71                 : 
      72                 :     TEXT_IS_SIMPLE_FLOW      = 0x100000,
      73                 :     TEXT_INCOMING_WHITESPACE = 0x200000,
      74                 :     TEXT_TRAILING_WHITESPACE = 0x400000,
      75                 :     TEXT_COMPRESSED_LEADING_WHITESPACE = 0x800000,
      76                 :     TEXT_NO_BREAKS           = 0x1000000,
      77                 :     TEXT_IS_TRANSFORMED      = 0x2000000,
      78                 :     // This gets set if there's a break opportunity at the end of the textrun.
      79                 :     // We normally don't use this break opportunity because the following text
      80                 :     // will have a break opportunity at the start, but it's useful for line
      81                 :     // layout to know about it in case the following content is not text
      82                 :     TEXT_HAS_TRAILING_BREAK  = 0x4000000
      83                 : 
      84                 :     // The following are defined by gfxTextRunWordCache rather than here,
      85                 :     // so that it also has access to the _INCOMING flag
      86                 :     // TEXT_TRAILING_ARABICCHAR
      87                 :     // TEXT_INCOMING_ARABICCHAR
      88                 :   };
      89                 : 
      90                 :   // These constants are used in TransformText to represent context information
      91                 :   // from previous textruns.
      92                 :   enum {
      93                 :     INCOMING_NONE       = 0,
      94                 :     INCOMING_WHITESPACE = 1,
      95                 :     INCOMING_ARABICCHAR = 2
      96                 :   };
      97                 : 
      98                 :   /**
      99                 :    * Returns true if aChars/aLength are something that make a space
     100                 :    * character not be whitespace when they follow the space character.
     101                 :    * For now, this is true if and only if aChars starts with a ZWJ. (This
     102                 :    * is what Uniscribe assumes.)
     103                 :    */
     104                 :   static bool
     105               0 :   IsSpaceCombiningSequenceTail(const PRUnichar* aChars, PRInt32 aLength) {
     106               0 :     return aLength > 0 && aChars[0] == 0x200D; // ZWJ
     107                 :   }
     108                 : 
     109                 :   enum CompressionMode {
     110                 :     COMPRESS_NONE,
     111                 :     COMPRESS_WHITESPACE,
     112                 :     COMPRESS_WHITESPACE_NEWLINE
     113                 :   };
     114                 : 
     115                 :   /**
     116                 :    * Create a text run from a run of Unicode text. The text may have whitespace
     117                 :    * compressed. A preformatted tab is sent to the text run as a single space.
     118                 :    * (Tab spacing must be performed by textframe later.) Certain other
     119                 :    * characters are discarded.
     120                 :    * 
     121                 :    * @param aCompressWhitespace control what is compressed to a
     122                 :    * single space character: no compression, compress spaces (not followed
     123                 :    * by combining mark) and tabs, and compress those plus newlines.
     124                 :    * @param aIncomingFlags a flag indicating whether there was whitespace
     125                 :    * or an Arabic character preceding this text. We set it to indicate if
     126                 :    * there's an Arabic character or whitespace preceding the end of this text.
     127                 :    */
     128                 :   static PRUnichar* TransformText(const PRUnichar* aText, PRUint32 aLength,
     129                 :                                   PRUnichar* aOutput,
     130                 :                                   CompressionMode aCompression,
     131                 :                                   PRUint8 * aIncomingFlags,
     132                 :                                   gfxSkipCharsBuilder* aSkipChars,
     133                 :                                   PRUint32* aAnalysisFlags);
     134                 : 
     135                 :   static PRUint8* TransformText(const PRUint8* aText, PRUint32 aLength,
     136                 :                                 PRUint8* aOutput,
     137                 :                                 CompressionMode aCompression,
     138                 :                                 PRUint8 * aIncomingFlags,
     139                 :                                 gfxSkipCharsBuilder* aSkipChars,
     140                 :                                 PRUint32* aAnalysisFlags);
     141                 : 
     142                 :   static void
     143               0 :   AppendLineBreakOffset(nsTArray<PRUint32>* aArray, PRUint32 aOffset)
     144                 :   {
     145               0 :     if (aArray->Length() > 0 && (*aArray)[aArray->Length() - 1] == aOffset)
     146               0 :       return;
     147               0 :     aArray->AppendElement(aOffset);
     148                 :   }
     149                 : 
     150                 : };
     151                 : 
     152                 : class nsSkipCharsRunIterator {
     153                 : public:
     154                 :   enum LengthMode {
     155                 :     LENGTH_UNSKIPPED_ONLY   = false,
     156                 :     LENGTH_INCLUDES_SKIPPED = true
     157                 :   };
     158               0 :   nsSkipCharsRunIterator(const gfxSkipCharsIterator& aStart,
     159                 :       LengthMode aLengthIncludesSkipped, PRUint32 aLength)
     160                 :     : mIterator(aStart), mRemainingLength(aLength), mRunLength(0),
     161                 :       mVisitSkipped(false),
     162               0 :       mLengthIncludesSkipped(aLengthIncludesSkipped) {
     163               0 :   }
     164               0 :   void SetVisitSkipped() { mVisitSkipped = true; }
     165               0 :   void SetOriginalOffset(PRInt32 aOffset) {
     166               0 :     mIterator.SetOriginalOffset(aOffset);
     167               0 :   }
     168               0 :   void SetSkippedOffset(PRUint32 aOffset) {
     169               0 :     mIterator.SetSkippedOffset(aOffset);
     170               0 :   }
     171                 : 
     172                 :   // guaranteed to return only positive-length runs
     173                 :   bool NextRun();
     174               0 :   bool IsSkipped() const { return mSkipped; }
     175                 :   // Always returns something > 0
     176               0 :   PRInt32 GetRunLength() const { return mRunLength; }
     177               0 :   const gfxSkipCharsIterator& GetPos() const { return mIterator; }
     178               0 :   PRInt32 GetOriginalOffset() const { return mIterator.GetOriginalOffset(); }
     179               0 :   PRUint32 GetSkippedOffset() const { return mIterator.GetSkippedOffset(); }
     180                 : 
     181                 : private:
     182                 :   gfxSkipCharsIterator mIterator;
     183                 :   PRInt32              mRemainingLength;
     184                 :   PRInt32              mRunLength;
     185                 :   bool                 mSkipped;
     186                 :   bool                 mVisitSkipped;
     187                 :   bool                 mLengthIncludesSkipped;
     188                 : };
     189                 : 
     190                 : #endif /*NSTEXTFRAMEUTILS_H_*/

Generated by: LCOV version 1.7