LCOV - app.info - layout/generic/nsTextRunTransformations.h

LCOV - code coverage report
| Current view: | directory - layout/generic - nsTextRunTransformations.h (source / functions) |  | Found | Hit | Coverage |
| Test: | app.info | Lines: | 21 | 0 | 0.0 %
| Date: | 2012-06-02 | Functions: | 13 | 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                 :  *
          24                 :  * Alternatively, the contents of this file may be used under the terms of
          25                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
          26                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
          27                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
          28                 :  * of those above. If you wish to allow use of your version of this file only
          29                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
          30                 :  * use your version of this file under the terms of the MPL, indicate your
          31                 :  * decision by deleting the provisions above and replace them with the notice
          32                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
          33                 :  * the provisions above, a recipient may use your version of this file under
          34                 :  * the terms of any one of the MPL, the GPL or the LGPL.
          35                 :  *
          36                 :  * ***** END LICENSE BLOCK ***** */
          37                 :
          38                 : #ifndef NSTEXTRUNTRANSFORMATIONS_H_
          39                 : #define NSTEXTRUNTRANSFORMATIONS_H_
          40                 :
          41                 : #include "gfxFont.h"
          42                 :
          43                 : class nsTransformedTextRun;
          44                 : class nsStyleContext;
          45                 :
          46               0 : class nsTransformingTextRunFactory {
          47                 : public:
          48               0 :   virtual ~nsTransformingTextRunFactory() {}
          49                 :
          50                 :   // Default 8-bit path just transforms to Unicode and takes that path
          51                 :   nsTransformedTextRun* MakeTextRun(const PRUint8* aString, PRUint32 aLength,
          52                 :                                     const gfxFontGroup::Parameters* aParams,
          53                 :                                     gfxFontGroup* aFontGroup, PRUint32 aFlags,
          54                 :                                     nsStyleContext** aStyles, bool aOwnsFactory = true);
          55                 :   nsTransformedTextRun* MakeTextRun(const PRUnichar* aString, PRUint32 aLength,
          56                 :                                     const gfxFontGroup::Parameters* aParams,
          57                 :                                     gfxFontGroup* aFontGroup, PRUint32 aFlags,
          58                 :                                     nsStyleContext** aStyles, bool aOwnsFactory = true);
          59                 :
          60                 :   virtual void RebuildTextRun(nsTransformedTextRun* aTextRun, gfxContext* aRefContext) = 0;
          61                 : };
          62                 :
          63                 : /**
          64                 :  * Builds textruns that render their text using a font-variant (i.e.,
          65                 :  * smallcaps).
          66                 :  */
          67               0 : class nsFontVariantTextRunFactory : public nsTransformingTextRunFactory {
          68                 : public:
          69                 :   virtual void RebuildTextRun(nsTransformedTextRun* aTextRun, gfxContext* aRefContext);
          70                 : };
          71                 :
          72                 : /**
          73                 :  * Builds textruns that transform the text in some way (e.g., capitalize)
          74                 :  * and then render the text using some other textrun implementation.
          75                 :  */
          76               0 : class nsCaseTransformTextRunFactory : public nsTransformingTextRunFactory {
          77                 : public:
          78                 :   // We could add an optimization here so that when there is no inner
          79                 :   // factory, no title-case conversion, and no upper-casing of SZLIG, we override
          80                 :   // MakeTextRun (after making it virtual in the superclass) and have it
          81                 :   // just convert the string to uppercase or lowercase and create the textrun
          82                 :   // via the fontgroup.
          83                 :
          84                 :   // Takes ownership of aInnerTransformTextRunFactory
          85               0 :   nsCaseTransformTextRunFactory(nsTransformingTextRunFactory* aInnerTransformingTextRunFactory,
          86                 :                                 bool aAllUppercase = false)
          87                 :     : mInnerTransformingTextRunFactory(aInnerTransformingTextRunFactory),
          88               0 :       mAllUppercase(aAllUppercase) {}
          89                 :
          90                 :   virtual void RebuildTextRun(nsTransformedTextRun* aTextRun, gfxContext* aRefContext);
          91                 :
          92                 : protected:
          93                 :   nsAutoPtr<nsTransformingTextRunFactory> mInnerTransformingTextRunFactory;
          94                 :   bool                                    mAllUppercase;
          95                 : };
          96                 :
          97                 : /**
          98                 :  * So that we can reshape as necessary, we store enough information
          99                 :  * to fully rebuild the textrun contents.
         100                 :  */
         101                 : class nsTransformedTextRun : public gfxTextRun {
         102                 : public:
         103                 :   static nsTransformedTextRun *Create(const gfxTextRunFactory::Parameters* aParams,
         104                 :                                       nsTransformingTextRunFactory* aFactory,
         105                 :                                       gfxFontGroup* aFontGroup,
         106                 :                                       const PRUnichar* aString, PRUint32 aLength,
         107                 :                                       const PRUint32 aFlags, nsStyleContext** aStyles,
         108                 :                                       bool aOwnsFactory);
         109                 :
         110               0 :   ~nsTransformedTextRun() {
         111               0 :     if (mOwnsFactory) {
         112               0 :       delete mFactory;
         113                 :     }
         114               0 :   }
         115                 :
         116                 :   void SetCapitalization(PRUint32 aStart, PRUint32 aLength,
         117                 :                          bool* aCapitalization,
         118                 :                          gfxContext* aRefContext);
         119                 :   virtual bool SetPotentialLineBreaks(PRUint32 aStart, PRUint32 aLength,
         120                 :                                         PRUint8* aBreakBefore,
         121                 :                                         gfxContext* aRefContext);
         122                 :   /**
         123                 :    * Called after SetCapitalization and SetPotentialLineBreaks
         124                 :    * are done and before we request any data from the textrun. Also always
         125                 :    * called after a Create.
         126                 :    */
         127               0 :   void FinishSettingProperties(gfxContext* aRefContext)
         128                 :   {
         129               0 :     if (mNeedsRebuild) {
         130               0 :       mNeedsRebuild = false;
         131               0 :       mFactory->RebuildTextRun(this, aRefContext);
         132                 :     }
         133               0 :   }
         134                 :
         135                 :   // override the gfxTextRun impls to account for additional members here
         136                 :   virtual NS_MUST_OVERRIDE size_t SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf);
         137                 :   virtual NS_MUST_OVERRIDE size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf);
         138                 :
         139                 :   nsTransformingTextRunFactory       *mFactory;
         140                 :   nsTArray<nsRefPtr<nsStyleContext> > mStyles;
         141                 :   nsTArray<bool>                      mCapitalize;
         142                 :   nsString                            mString;
         143                 :   bool                                mOwnsFactory;
         144                 :   bool                                mNeedsRebuild;
         145                 :
         146                 : private:
         147               0 :   nsTransformedTextRun(const gfxTextRunFactory::Parameters* aParams,
         148                 :                        nsTransformingTextRunFactory* aFactory,
         149                 :                        gfxFontGroup* aFontGroup,
         150                 :                        const PRUnichar* aString, PRUint32 aLength,
         151                 :                        const PRUint32 aFlags, nsStyleContext** aStyles,
         152                 :                        bool aOwnsFactory)
         153                 :     : gfxTextRun(aParams, aString, aLength, aFontGroup, aFlags),
         154                 :       mFactory(aFactory), mString(aString, aLength),
         155               0 :       mOwnsFactory(aOwnsFactory), mNeedsRebuild(true)
         156                 :   {
         157               0 :     mCharacterGlyphs = reinterpret_cast<CompressedGlyph*>(this + 1);
         158                 :
         159                 :     PRUint32 i;
         160               0 :     for (i = 0; i < aLength; ++i) {
         161               0 :       mStyles.AppendElement(aStyles[i]);
         162                 :     }
         163               0 :   }
         164                 : };
         165                 :
         166                 : #endif /*NSTEXTRUNTRANSFORMATIONS_H_*/

Generated by: LCOV version 1.7