1 // Copyright 2016 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef UI_GFX_WIN_TEXT_ANALYSIS_SOURCE_H_ 6 #define UI_GFX_WIN_TEXT_ANALYSIS_SOURCE_H_ 7 8 #include <dwrite.h> 9 #include <wrl.h> 10 11 #include "base/macros.h" 12 #include "base/strings/string16.h" 13 #include "ui/gfx/gfx_export.h" 14 15 namespace gfx { 16 namespace win { 17 18 // Implements an IDWriteTextAnalysisSource, describing a single pre-defined 19 // chunk of text with a uniform locale, reading direction, and number 20 // substitution. 21 class TextAnalysisSource 22 : public Microsoft::WRL::RuntimeClass< 23 Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::ClassicCom>, 24 IDWriteTextAnalysisSource> { 25 public: 26 // Factory method to avoid exporting the class and all it derives from. 27 static GFX_EXPORT HRESULT 28 Create(IDWriteTextAnalysisSource** text_analysis_out, 29 const base::string16& text, 30 const base::string16& locale_name, 31 IDWriteNumberSubstitution* number_substitution, 32 DWRITE_READING_DIRECTION reading_direction); 33 34 // Use Create() to construct these objects. Direct calls to the constructor 35 // are an error - it is only public because a WRL helper function creates the 36 // objects. 37 TextAnalysisSource(); 38 // IDWriteTextAnalysisSource: 39 HRESULT STDMETHODCALLTYPE GetLocaleName(UINT32 text_position, 40 UINT32* text_length, 41 const WCHAR** locale_name) override; 42 HRESULT STDMETHODCALLTYPE GetNumberSubstitution( 43 UINT32 text_position, 44 UINT32* text_length, 45 IDWriteNumberSubstitution** number_substitution) override; 46 DWRITE_READING_DIRECTION STDMETHODCALLTYPE 47 GetParagraphReadingDirection() override; 48 HRESULT STDMETHODCALLTYPE GetTextAtPosition(UINT32 text_position, 49 const WCHAR** text_string, 50 UINT32* text_length) override; 51 HRESULT STDMETHODCALLTYPE GetTextBeforePosition(UINT32 text_position, 52 const WCHAR** text_string, 53 UINT32* text_length) override; 54 55 HRESULT STDMETHODCALLTYPE 56 RuntimeClassInitialize(const base::string16& text, 57 const base::string16& locale_name, 58 IDWriteNumberSubstitution* number_substitution, 59 DWRITE_READING_DIRECTION reading_direction); 60 61 protected: 62 ~TextAnalysisSource() override; 63 64 private: 65 base::string16 text_; 66 base::string16 locale_name_; 67 Microsoft::WRL::ComPtr<IDWriteNumberSubstitution> number_substitution_; 68 DWRITE_READING_DIRECTION reading_direction_; 69 70 DISALLOW_ASSIGN(TextAnalysisSource); 71 }; 72 73 } // namespace win 74 } // namespace gfx 75 76 #endif // UI_GFX_WIN_TEXT_ANALYSIS_SOURCE_H_ 77