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.
13 : public IDWriteTextAnalysisSource
,
14 public IDWriteTextAnalysisSink
19 IFACEMETHOD(QueryInterface
)(IID
const& iid
, OUT
void** ppObject
)
21 if (iid
== __uuidof(IDWriteTextAnalysisSource
)) {
22 *ppObject
= static_cast<IDWriteTextAnalysisSource
*>(this);
24 } else if (iid
== __uuidof(IDWriteTextAnalysisSink
)) {
25 *ppObject
= static_cast<IDWriteTextAnalysisSink
*>(this);
27 } else if (iid
== __uuidof(IUnknown
)) {
29 static_cast<IUnknown
*>(static_cast<IDWriteTextAnalysisSource
*>(this));
36 IFACEMETHOD_(ULONG
, AddRef
)()
41 IFACEMETHOD_(ULONG
, Release
)()
46 // A single contiguous run of characters containing the same analysis
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
55 DWRITE_SCRIPT_ANALYSIS mScript
;
59 inline bool ContainsTextPosition(UINT32 aTextPosition
) const
61 return aTextPosition
>= mTextStart
62 && aTextPosition
< mTextStart
+ mTextLength
;
69 TextAnalysis(const wchar_t* text
,
71 const wchar_t* localeName
,
72 DWRITE_READING_DIRECTION readingDirection
);
76 STDMETHODIMP
GenerateResults(IDWriteTextAnalyzer
* textAnalyzer
,
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
);
97 GetNumberSubstitution(UINT32 textPosition
,
98 OUT UINT32
* textLength
,
99 OUT IDWriteNumberSubstitution
** numberSubstitution
);
101 // IDWriteTextAnalysisSink implementation
104 SetScriptAnalysis(UINT32 textPosition
,
106 DWRITE_SCRIPT_ANALYSIS
const* scriptAnalysis
);
109 SetLineBreakpoints(UINT32 textPosition
,
111 const DWRITE_LINE_BREAKPOINT
* lineBreakpoints
);
113 IFACEMETHODIMP
SetBidiLevel(UINT32 textPosition
,
116 UINT8 resolvedLevel
);
119 SetNumberSubstitution(UINT32 textPosition
,
121 IDWriteNumberSubstitution
* numberSubstitution
);
124 Run
*FetchNextRun(IN OUT UINT32
* textLength
);
126 void SetCurrentRun(UINT32 textPosition
);
128 void SplitCurrentRun(UINT32 splitPosition
);
132 // (weak references are fine here, since this class is a transient
133 // stack-based helper that doesn't need to copy data)
135 const wchar_t* mText
;
136 const wchar_t* mLocaleName
;
137 DWRITE_READING_DIRECTION mReadingDirection
;
139 // Current processing state.
142 // Output is a list of runs starting here
146 #endif /* GFX_DWRITETEXTANALYSIS_H */