diff options
Diffstat (limited to 'include/cru/win')
-rw-r--r-- | include/cru/win/Exception.hpp | 9 | ||||
-rw-r--r-- | include/cru/win/String.hpp | 75 | ||||
-rw-r--r-- | include/cru/win/graph/direct/Factory.hpp | 4 | ||||
-rw-r--r-- | include/cru/win/graph/direct/Font.hpp | 3 | ||||
-rw-r--r-- | include/cru/win/graph/direct/Resource.hpp | 4 | ||||
-rw-r--r-- | include/cru/win/graph/direct/TextLayout.hpp | 11 | ||||
-rw-r--r-- | include/cru/win/native/Cursor.hpp | 2 | ||||
-rw-r--r-- | include/cru/win/native/GodWindow.hpp | 2 | ||||
-rw-r--r-- | include/cru/win/native/InputMethod.hpp | 10 | ||||
-rw-r--r-- | include/cru/win/native/Resource.hpp | 4 | ||||
-rw-r--r-- | include/cru/win/native/Window.hpp | 2 |
11 files changed, 25 insertions, 101 deletions
diff --git a/include/cru/win/Exception.hpp b/include/cru/win/Exception.hpp index 234aea69..3a95aa5d 100644 --- a/include/cru/win/Exception.hpp +++ b/include/cru/win/Exception.hpp @@ -10,7 +10,7 @@ namespace cru::platform::win { class HResultError : public platform::PlatformException { public: explicit HResultError(HRESULT h_result); - explicit HResultError(HRESULT h_result, const std::string_view& message); + explicit HResultError(HRESULT h_result, std::string_view message); CRU_DEFAULT_COPY(HResultError) CRU_DEFAULT_MOVE(HResultError) @@ -27,8 +27,7 @@ inline void ThrowIfFailed(const HRESULT h_result) { if (FAILED(h_result)) throw HResultError(h_result); } -inline void ThrowIfFailed(const HRESULT h_result, - const std::string_view& message) { +inline void ThrowIfFailed(const HRESULT h_result, std::string_view message) { if (FAILED(h_result)) throw HResultError(h_result, message); } @@ -36,8 +35,8 @@ class Win32Error : public platform::PlatformException { public: // ::GetLastError is automatically called to get the error code. // The same as Win32Error(::GetLastError(), message) - explicit Win32Error(const std::string_view& message); - Win32Error(DWORD error_code, const std::string_view& message); + explicit Win32Error(std::string_view message); + Win32Error(DWORD error_code, std::string_view message); CRU_DEFAULT_COPY(Win32Error) CRU_DEFAULT_MOVE(Win32Error) diff --git a/include/cru/win/String.hpp b/include/cru/win/String.hpp deleted file mode 100644 index ac07f57b..00000000 --- a/include/cru/win/String.hpp +++ /dev/null @@ -1,75 +0,0 @@ -/* -Because the text encoding problem on Windows, here I write some functions -related to text encoding. The utf-8 and utf-16 conversion function is provided -by win32 api. However win32 api does not provide any function about charactor -iteration or index by code point. (At least I haven't found.) I don't use icu -because it is not easy to build it on Windows and the bundled version in Windows -(https://docs.microsoft.com/en-us/windows/win32/intl/international-components-for-unicode--icu-) -is only available after Windows 10 Creators Update. - -Luckily, both utf-8 and utf-16 encoding are easy to learn and program with if we -only do simple iteration rather than do much sophisticated work about -complicated error situations. (And I learn the internal of the encoding by the -way.) -*/ - -#pragma once -#include "WinPreConfig.hpp" - -#include "cru/common/StringUtil.hpp" - -#include <cstdint> -#include <stdexcept> -#include <string> -#include <string_view> - -namespace cru::platform::win { -std::string ToUtf8String(const std::wstring_view& string); -std::wstring ToUtf16String(const std::string_view& string); - -inline bool IsSurrogatePair(wchar_t c) { return c >= 0xD800 && c <= 0xDFFF; } - -inline bool IsSurrogatePairLeading(wchar_t c) { - return c >= 0xD800 && c <= 0xDBFF; -} - -inline bool IsSurrogatePairTrailing(wchar_t c) { - return c >= 0xDC00 && c <= 0xDFFF; -} - -class Utf16Iterator : public Object { - static_assert( - sizeof(wchar_t) == 2, - "Emmm, according to my knowledge, wchar_t should be 2-length on " - "Windows. If not, Utf16 will be broken."); - - public: - Utf16Iterator(const std::wstring_view& string) : string_(string) {} - - CRU_DEFAULT_COPY(Utf16Iterator) - CRU_DEFAULT_MOVE(Utf16Iterator) - - ~Utf16Iterator() = default; - - public: - void SetToHead() { position_ = 0; } - - // Advance current position and get next code point. Return k_code_point_end - // if there is no next code unit(point). Throw TextEncodeException if decoding - // fails. - CodePoint Next(); - - Index CurrentPosition() const { return this->position_; } - - private: - std::wstring_view string_; - Index position_ = 0; -}; - -Index IndexUtf8ToUtf16(const std::string_view& utf8_string, Index utf8_index, - const std::wstring_view& utf16_string); - -Index IndexUtf16ToUtf8(const std::wstring_view& utf16_string, Index utf16_index, - const std::string_view& utf8_string); - -} // namespace cru::platform::win diff --git a/include/cru/win/graph/direct/Factory.hpp b/include/cru/win/graph/direct/Factory.hpp index 763d4b2b..e70454f5 100644 --- a/include/cru/win/graph/direct/Factory.hpp +++ b/include/cru/win/graph/direct/Factory.hpp @@ -38,11 +38,11 @@ class DirectGraphFactory : public DirectResource, public virtual IGraphFactory { std::unique_ptr<IGeometryBuilder> CreateGeometryBuilder() override; - std::unique_ptr<IFont> CreateFont(const std::string_view& font_family, + std::unique_ptr<IFont> CreateFont(std::u16string font_family, float font_size) override; std::unique_ptr<ITextLayout> CreateTextLayout(std::shared_ptr<IFont> font, - std::string text) override; + std::u16string text) override; private: Microsoft::WRL::ComPtr<ID3D11Device> d3d11_device_; diff --git a/include/cru/win/graph/direct/Font.hpp b/include/cru/win/graph/direct/Font.hpp index ecf9fd81..2195f3e4 100644 --- a/include/cru/win/graph/direct/Font.hpp +++ b/include/cru/win/graph/direct/Font.hpp @@ -11,7 +11,7 @@ class DWriteFont : public DirectGraphResource, public virtual IFont, public virtual IComResource<IDWriteTextFormat> { public: - DWriteFont(DirectGraphFactory* factory, const std::string_view& font_family, + DWriteFont(DirectGraphFactory* factory, std::u16string font_family, float font_size); CRU_DELETE_COPY(DWriteFont) @@ -27,6 +27,7 @@ class DWriteFont : public DirectGraphResource, float GetFontSize() override; private: + std::u16string font_family_; Microsoft::WRL::ComPtr<IDWriteTextFormat> text_format_; }; } // namespace cru::platform::graph::win::direct diff --git a/include/cru/win/graph/direct/Resource.hpp b/include/cru/win/graph/direct/Resource.hpp index d0a30dbd..6162ebd8 100644 --- a/include/cru/win/graph/direct/Resource.hpp +++ b/include/cru/win/graph/direct/Resource.hpp @@ -10,7 +10,7 @@ class DirectGraphFactory; class DirectResource : public Object, public virtual INativeResource { public: - static constexpr std::string_view k_platform_id = "Windows Direct"; + static constexpr std::u16string_view k_platform_id = u"Windows Direct"; protected: DirectResource() = default; @@ -22,7 +22,7 @@ class DirectResource : public Object, public virtual INativeResource { ~DirectResource() override = default; public: - std::string_view GetPlatformId() const final { return k_platform_id; } + std::u16string_view GetPlatformId() const final { return k_platform_id; } }; class DirectGraphResource : public DirectResource, diff --git a/include/cru/win/graph/direct/TextLayout.hpp b/include/cru/win/graph/direct/TextLayout.hpp index 40c63dbe..c53cf655 100644 --- a/include/cru/win/graph/direct/TextLayout.hpp +++ b/include/cru/win/graph/direct/TextLayout.hpp @@ -15,7 +15,7 @@ class DWriteTextLayout : public DirectGraphResource, public virtual IComResource<IDWriteTextLayout> { public: DWriteTextLayout(DirectGraphFactory* factory, std::shared_ptr<IFont> font, - std::string text); + std::u16string text); CRU_DELETE_COPY(DWriteTextLayout) CRU_DELETE_MOVE(DWriteTextLayout) @@ -28,8 +28,8 @@ class DWriteTextLayout : public DirectGraphResource, } public: - std::string GetText() override; - void SetText(std::string new_text) override; + std::u16string GetText() override; + void SetText(std::u16string new_text) override; std::shared_ptr<IFont> GetFont() override; void SetFont(std::shared_ptr<IFont> font) override; @@ -41,12 +41,11 @@ class DWriteTextLayout : public DirectGraphResource, // Return empty vector if text_range.count is 0. Text range could be in // reverse direction, it should be normalized first in implementation. std::vector<Rect> TextRangeRect(const TextRange& text_range) override; - Point TextSinglePoint(gsl::index position, bool trailing) override; + Point TextSinglePoint(Index position, bool trailing) override; TextHitTestResult HitTest(const Point& point) override; private: - std::string text_; - std::wstring w_text_; + std::u16string text_; std::shared_ptr<DWriteFont> font_; float max_width_ = std::numeric_limits<float>::max(); float max_height_ = std::numeric_limits<float>::max(); diff --git a/include/cru/win/native/Cursor.hpp b/include/cru/win/native/Cursor.hpp index 44a6a362..373b9170 100644 --- a/include/cru/win/native/Cursor.hpp +++ b/include/cru/win/native/Cursor.hpp @@ -7,7 +7,7 @@ namespace cru::platform::native::win { class WinCursor : public WinNativeResource, public virtual ICursor { - CRU_DEFINE_CLASS_LOG_TAG("cru::platform::native::win::WinCursor") + CRU_DEFINE_CLASS_LOG_TAG(u"cru::platform::native::win::WinCursor") public: WinCursor(HCURSOR handle, bool auto_destroy); diff --git a/include/cru/win/native/GodWindow.hpp b/include/cru/win/native/GodWindow.hpp index 0820bdb3..8b20e01f 100644 --- a/include/cru/win/native/GodWindow.hpp +++ b/include/cru/win/native/GodWindow.hpp @@ -5,7 +5,7 @@ namespace cru::platform::native::win { class GodWindow : public Object { - CRU_DEFINE_CLASS_LOG_TAG("cru::platform::native::win::GodWindow") + CRU_DEFINE_CLASS_LOG_TAG(u"cru::platform::native::win::GodWindow") public: explicit GodWindow(WinUiApplication* application); diff --git a/include/cru/win/native/InputMethod.hpp b/include/cru/win/native/InputMethod.hpp index 45422ace..113f460d 100644 --- a/include/cru/win/native/InputMethod.hpp +++ b/include/cru/win/native/InputMethod.hpp @@ -12,7 +12,7 @@ namespace cru::platform::native::win { class AutoHIMC : public Object { - CRU_DEFINE_CLASS_LOG_TAG("cru::platform::native::win::AutoHIMC") + CRU_DEFINE_CLASS_LOG_TAG(u"cru::platform::native::win::AutoHIMC") public: explicit AutoHIMC(HWND hwnd); @@ -35,7 +35,7 @@ class AutoHIMC : public Object { class WinInputMethodContext : public WinNativeResource, public virtual IInputMethodContext { - CRU_DEFINE_CLASS_LOG_TAG("cru::platform::native::win::WinInputMethodContext") + CRU_DEFINE_CLASS_LOG_TAG(u"cru::platform::native::win::WinInputMethodContext") public: WinInputMethodContext(gsl::not_null<WinNativeWindow*> window); @@ -65,12 +65,12 @@ class WinInputMethodContext : public WinNativeResource, IEvent<std::nullptr_t>* CompositionEvent() override; - IEvent<std::string_view>* TextEvent() override; + IEvent<std::u16string_view>* TextEvent() override; private: void OnWindowNativeMessage(WindowNativeMessageEventArgs& args); - std::string GetResultString(); + std::u16string GetResultString(); std::optional<AutoHIMC> TryGetHIMC(); @@ -82,7 +82,7 @@ class WinInputMethodContext : public WinNativeResource, Event<std::nullptr_t> composition_start_event_; Event<std::nullptr_t> composition_end_event_; Event<std::nullptr_t> composition_event_; - Event<std::string_view> text_event_; + Event<std::u16string_view> text_event_; }; class WinInputMethodManager : public WinNativeResource, diff --git a/include/cru/win/native/Resource.hpp b/include/cru/win/native/Resource.hpp index 7afaca0f..0de0e1a8 100644 --- a/include/cru/win/native/Resource.hpp +++ b/include/cru/win/native/Resource.hpp @@ -6,7 +6,7 @@ namespace cru::platform::native::win { class WinNativeResource : public Object, public virtual INativeResource { public: - static constexpr std::string_view k_platform_id = "Windows"; + static constexpr std::u16string_view k_platform_id = u"Windows"; protected: WinNativeResource() = default; @@ -18,6 +18,6 @@ class WinNativeResource : public Object, public virtual INativeResource { ~WinNativeResource() override = default; public: - std::string_view GetPlatformId() const final { return k_platform_id; } + std::u16string_view GetPlatformId() const final { return k_platform_id; } }; } // namespace cru::platform::native::win diff --git a/include/cru/win/native/Window.hpp b/include/cru/win/native/Window.hpp index 521a0a06..3e0b11cd 100644 --- a/include/cru/win/native/Window.hpp +++ b/include/cru/win/native/Window.hpp @@ -8,7 +8,7 @@ namespace cru::platform::native::win { class WinNativeWindow : public WinNativeResource, public virtual INativeWindow { - CRU_DEFINE_CLASS_LOG_TAG("cru::platform::native::win::WinNativeWindow") + CRU_DEFINE_CLASS_LOG_TAG(u"cru::platform::native::win::WinNativeWindow") public: WinNativeWindow(WinUiApplication* application, WindowClass* window_class, |