gfx/thebes/gfxDWriteTextAnalysis.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial