1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/thebes/gfxDWriteTextAnalysis.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,146 @@ 1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef GFX_DWRITETEXTANALYSIS_H 1.10 +#define GFX_DWRITETEXTANALYSIS_H 1.11 + 1.12 +#include "gfxDWriteCommon.h" 1.13 + 1.14 +// Helper source/sink class for text analysis. 1.15 +class TextAnalysis 1.16 + : public IDWriteTextAnalysisSource, 1.17 + public IDWriteTextAnalysisSink 1.18 +{ 1.19 +public: 1.20 + 1.21 + // IUnknown interface 1.22 + IFACEMETHOD(QueryInterface)(IID const& iid, OUT void** ppObject) 1.23 + { 1.24 + if (iid == __uuidof(IDWriteTextAnalysisSource)) { 1.25 + *ppObject = static_cast<IDWriteTextAnalysisSource*>(this); 1.26 + return S_OK; 1.27 + } else if (iid == __uuidof(IDWriteTextAnalysisSink)) { 1.28 + *ppObject = static_cast<IDWriteTextAnalysisSink*>(this); 1.29 + return S_OK; 1.30 + } else if (iid == __uuidof(IUnknown)) { 1.31 + *ppObject = 1.32 + static_cast<IUnknown*>(static_cast<IDWriteTextAnalysisSource*>(this)); 1.33 + return S_OK; 1.34 + } else { 1.35 + return E_NOINTERFACE; 1.36 + } 1.37 + } 1.38 + 1.39 + IFACEMETHOD_(ULONG, AddRef)() 1.40 + { 1.41 + return 1; 1.42 + } 1.43 + 1.44 + IFACEMETHOD_(ULONG, Release)() 1.45 + { 1.46 + return 1; 1.47 + } 1.48 + 1.49 + // A single contiguous run of characters containing the same analysis 1.50 + // results. 1.51 + struct Run 1.52 + { 1.53 + UINT32 mTextStart; // starting text position of this run 1.54 + UINT32 mTextLength; // number of contiguous code units covered 1.55 + UINT32 mGlyphStart; // starting glyph in the glyphs array 1.56 + UINT32 mGlyphCount; // number of glyphs associated with this run of 1.57 + // text 1.58 + DWRITE_SCRIPT_ANALYSIS mScript; 1.59 + UINT8 mBidiLevel; 1.60 + bool mIsSideways; 1.61 + 1.62 + inline bool ContainsTextPosition(UINT32 aTextPosition) const 1.63 + { 1.64 + return aTextPosition >= mTextStart 1.65 + && aTextPosition < mTextStart + mTextLength; 1.66 + } 1.67 + 1.68 + Run *nextRun; 1.69 + }; 1.70 + 1.71 +public: 1.72 + TextAnalysis(const wchar_t* text, 1.73 + UINT32 textLength, 1.74 + const wchar_t* localeName, 1.75 + DWRITE_READING_DIRECTION readingDirection); 1.76 + 1.77 + ~TextAnalysis(); 1.78 + 1.79 + STDMETHODIMP GenerateResults(IDWriteTextAnalyzer* textAnalyzer, 1.80 + Run **runHead); 1.81 + 1.82 + // IDWriteTextAnalysisSource implementation 1.83 + 1.84 + IFACEMETHODIMP GetTextAtPosition(UINT32 textPosition, 1.85 + OUT WCHAR const** textString, 1.86 + OUT UINT32* textLength); 1.87 + 1.88 + IFACEMETHODIMP GetTextBeforePosition(UINT32 textPosition, 1.89 + OUT WCHAR const** textString, 1.90 + OUT UINT32* textLength); 1.91 + 1.92 + IFACEMETHODIMP_(DWRITE_READING_DIRECTION) 1.93 + GetParagraphReadingDirection() throw(); 1.94 + 1.95 + IFACEMETHODIMP GetLocaleName(UINT32 textPosition, 1.96 + OUT UINT32* textLength, 1.97 + OUT WCHAR const** localeName); 1.98 + 1.99 + IFACEMETHODIMP 1.100 + GetNumberSubstitution(UINT32 textPosition, 1.101 + OUT UINT32* textLength, 1.102 + OUT IDWriteNumberSubstitution** numberSubstitution); 1.103 + 1.104 + // IDWriteTextAnalysisSink implementation 1.105 + 1.106 + IFACEMETHODIMP 1.107 + SetScriptAnalysis(UINT32 textPosition, 1.108 + UINT32 textLength, 1.109 + DWRITE_SCRIPT_ANALYSIS const* scriptAnalysis); 1.110 + 1.111 + IFACEMETHODIMP 1.112 + SetLineBreakpoints(UINT32 textPosition, 1.113 + UINT32 textLength, 1.114 + const DWRITE_LINE_BREAKPOINT* lineBreakpoints); 1.115 + 1.116 + IFACEMETHODIMP SetBidiLevel(UINT32 textPosition, 1.117 + UINT32 textLength, 1.118 + UINT8 explicitLevel, 1.119 + UINT8 resolvedLevel); 1.120 + 1.121 + IFACEMETHODIMP 1.122 + SetNumberSubstitution(UINT32 textPosition, 1.123 + UINT32 textLength, 1.124 + IDWriteNumberSubstitution* numberSubstitution); 1.125 + 1.126 +protected: 1.127 + Run *FetchNextRun(IN OUT UINT32* textLength); 1.128 + 1.129 + void SetCurrentRun(UINT32 textPosition); 1.130 + 1.131 + void SplitCurrentRun(UINT32 splitPosition); 1.132 + 1.133 +protected: 1.134 + // Input 1.135 + // (weak references are fine here, since this class is a transient 1.136 + // stack-based helper that doesn't need to copy data) 1.137 + UINT32 mTextLength; 1.138 + const wchar_t* mText; 1.139 + const wchar_t* mLocaleName; 1.140 + DWRITE_READING_DIRECTION mReadingDirection; 1.141 + 1.142 + // Current processing state. 1.143 + Run *mCurrentRun; 1.144 + 1.145 + // Output is a list of runs starting here 1.146 + Run mRunHead; 1.147 +}; 1.148 + 1.149 +#endif /* GFX_DWRITETEXTANALYSIS_H */