gfx/thebes/gfxDWriteTextAnalysis.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     2  * This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef GFX_DWRITETEXTANALYSIS_H
     7 #define GFX_DWRITETEXTANALYSIS_H
     9 #include "gfxDWriteCommon.h"
    11 // Helper source/sink class for text analysis.
    12 class TextAnalysis
    13     :   public IDWriteTextAnalysisSource,
    14         public IDWriteTextAnalysisSink        
    15 {
    16 public:
    18     // IUnknown interface
    19     IFACEMETHOD(QueryInterface)(IID const& iid, OUT void** ppObject)
    20     {
    21         if (iid == __uuidof(IDWriteTextAnalysisSource)) {
    22             *ppObject = static_cast<IDWriteTextAnalysisSource*>(this);
    23             return S_OK;
    24         } else if (iid == __uuidof(IDWriteTextAnalysisSink)) {
    25             *ppObject = static_cast<IDWriteTextAnalysisSink*>(this);
    26             return S_OK;
    27         } else if (iid == __uuidof(IUnknown)) {
    28             *ppObject = 
    29                 static_cast<IUnknown*>(static_cast<IDWriteTextAnalysisSource*>(this));
    30             return S_OK;
    31         } else {
    32             return E_NOINTERFACE;
    33         }
    34     }
    36     IFACEMETHOD_(ULONG, AddRef)()
    37     {
    38         return 1;
    39     }
    41     IFACEMETHOD_(ULONG, Release)()
    42     {
    43         return 1;
    44     }
    46     // A single contiguous run of characters containing the same analysis 
    47     // results.
    48     struct Run
    49     {
    50         UINT32 mTextStart;   // starting text position of this run
    51         UINT32 mTextLength;  // number of contiguous code units covered
    52         UINT32 mGlyphStart;  // starting glyph in the glyphs array
    53         UINT32 mGlyphCount;  // number of glyphs associated with this run of 
    54                              // text
    55         DWRITE_SCRIPT_ANALYSIS mScript;
    56         UINT8 mBidiLevel;
    57         bool mIsSideways;
    59         inline bool ContainsTextPosition(UINT32 aTextPosition) const
    60         {
    61             return aTextPosition >= mTextStart
    62                 && aTextPosition <  mTextStart + mTextLength;
    63         }
    65         Run *nextRun;
    66     };
    68 public:
    69     TextAnalysis(const wchar_t* text,
    70                  UINT32 textLength,
    71                  const wchar_t* localeName,
    72                  DWRITE_READING_DIRECTION readingDirection);
    74     ~TextAnalysis();
    76     STDMETHODIMP GenerateResults(IDWriteTextAnalyzer* textAnalyzer,
    77                                  Run **runHead);
    79     // IDWriteTextAnalysisSource implementation
    81     IFACEMETHODIMP GetTextAtPosition(UINT32 textPosition,
    82                                      OUT WCHAR const** textString,
    83                                      OUT UINT32* textLength);
    85     IFACEMETHODIMP GetTextBeforePosition(UINT32 textPosition,
    86                                          OUT WCHAR const** textString,
    87                                          OUT UINT32* textLength);
    89     IFACEMETHODIMP_(DWRITE_READING_DIRECTION) 
    90         GetParagraphReadingDirection() throw();
    92     IFACEMETHODIMP GetLocaleName(UINT32 textPosition,
    93                                  OUT UINT32* textLength,
    94                                  OUT WCHAR const** localeName);
    96     IFACEMETHODIMP 
    97         GetNumberSubstitution(UINT32 textPosition,
    98                               OUT UINT32* textLength,
    99                               OUT IDWriteNumberSubstitution** numberSubstitution);
   101     // IDWriteTextAnalysisSink implementation
   103     IFACEMETHODIMP 
   104         SetScriptAnalysis(UINT32 textPosition,
   105                           UINT32 textLength,
   106                           DWRITE_SCRIPT_ANALYSIS const* scriptAnalysis);
   108     IFACEMETHODIMP 
   109         SetLineBreakpoints(UINT32 textPosition,
   110                            UINT32 textLength,
   111                            const DWRITE_LINE_BREAKPOINT* lineBreakpoints);
   113     IFACEMETHODIMP SetBidiLevel(UINT32 textPosition,
   114                                 UINT32 textLength,
   115                                 UINT8 explicitLevel,
   116                                 UINT8 resolvedLevel);
   118     IFACEMETHODIMP 
   119         SetNumberSubstitution(UINT32 textPosition,
   120                               UINT32 textLength,
   121                               IDWriteNumberSubstitution* numberSubstitution);
   123 protected:
   124     Run *FetchNextRun(IN OUT UINT32* textLength);
   126     void SetCurrentRun(UINT32 textPosition);
   128     void SplitCurrentRun(UINT32 splitPosition);
   130 protected:
   131     // Input
   132     // (weak references are fine here, since this class is a transient
   133     //  stack-based helper that doesn't need to copy data)
   134     UINT32 mTextLength;
   135     const wchar_t* mText;
   136     const wchar_t* mLocaleName;
   137     DWRITE_READING_DIRECTION mReadingDirection;
   139     // Current processing state.
   140     Run *mCurrentRun;
   142     // Output is a list of runs starting here
   143     Run  mRunHead;
   144 };
   146 #endif /* GFX_DWRITETEXTANALYSIS_H */

mercurial