diff --git a/src/gfx_layout.h b/src/gfx_layout.h index 33b976f29a..5408b3e0ce 100644 --- a/src/gfx_layout.h +++ b/src/gfx_layout.h @@ -171,10 +171,10 @@ public: FontMap runs; ///< Accessed by our ParagraphLayout::nextLine. FontState state_after; ///< Font state after the line. - ParagraphLayouter *layout; ///< Layout of the line. + std::unique_ptr layout = nullptr; ///< Layout of the line. - LineCacheItem() : buffer(nullptr), layout(nullptr) {} - ~LineCacheItem() { delete layout; free(buffer); } + LineCacheItem() : buffer(nullptr) {} + ~LineCacheItem() { free(buffer); } }; private: typedef std::map LineCache; diff --git a/src/gfx_layout_fallback.cpp b/src/gfx_layout_fallback.cpp index 39e5700051..6e2e02474f 100644 --- a/src/gfx_layout_fallback.cpp +++ b/src/gfx_layout_fallback.cpp @@ -82,9 +82,9 @@ public: * @param fontMapping THe mapping of the fonts. * @return The ParagraphLayout instance. */ -/* static */ ParagraphLayouter *FallbackParagraphLayoutFactory::GetParagraphLayout(char32_t *buff, char32_t *buff_end, FontMap &fontMapping) +/* static */ std::unique_ptr FallbackParagraphLayoutFactory::GetParagraphLayout(char32_t *buff, char32_t *buff_end, FontMap &fontMapping) { - return new FallbackParagraphLayout(buff, buff_end - buff, fontMapping); + return std::make_unique(buff, buff_end - buff, fontMapping); } /** diff --git a/src/gfx_layout_fallback.h b/src/gfx_layout_fallback.h index 89f6b3aaeb..ad3f7a3405 100644 --- a/src/gfx_layout_fallback.h +++ b/src/gfx_layout_fallback.h @@ -22,7 +22,7 @@ public: /** Helper for GetLayouter, to get whether the layouter supports RTL. */ static const bool SUPPORTS_RTL = false; - static ParagraphLayouter *GetParagraphLayout(char32_t *buff, char32_t *buff_end, FontMap &fontMapping); + static std::unique_ptr GetParagraphLayout(char32_t *buff, char32_t *buff_end, FontMap &fontMapping); static size_t AppendToBuffer(char32_t *buff, const char32_t *buffer_last, char32_t c); }; diff --git a/src/gfx_layout_icu.cpp b/src/gfx_layout_icu.cpp index 3d95390127..139cac083d 100644 --- a/src/gfx_layout_icu.cpp +++ b/src/gfx_layout_icu.cpp @@ -353,7 +353,7 @@ std::vector ItemizeStyle(std::vector &runs_current, FontMap &fon return runs; } -/* static */ ParagraphLayouter *ICUParagraphLayoutFactory::GetParagraphLayout(UChar *buff, UChar *buff_end, FontMap &font_mapping) +/* static */ std::unique_ptr ICUParagraphLayoutFactory::GetParagraphLayout(UChar *buff, UChar *buff_end, FontMap &font_mapping) { size_t length = buff_end - buff; /* Can't layout an empty string. */ @@ -374,7 +374,7 @@ std::vector ItemizeStyle(std::vector &runs_current, FontMap &fon run.Shape(buff, length); } - return new ICUParagraphLayout(std::move(runs), buff, length); + return std::make_unique(std::move(runs), buff, length); } /* static */ std::unique_ptr ICUParagraphLayoutFactory::break_iterator; diff --git a/src/gfx_layout_icu.h b/src/gfx_layout_icu.h index f0adaeb15b..ff9c45c01d 100644 --- a/src/gfx_layout_icu.h +++ b/src/gfx_layout_icu.h @@ -25,7 +25,7 @@ public: /** Helper for GetLayouter, to get whether the layouter supports RTL. */ static const bool SUPPORTS_RTL = true; - static ParagraphLayouter *GetParagraphLayout(UChar *buff, UChar *buff_end, FontMap &fontMapping); + static std::unique_ptr GetParagraphLayout(UChar *buff, UChar *buff_end, FontMap &fontMapping); static size_t AppendToBuffer(UChar *buff, const UChar *buffer_last, char32_t c); static void InitializeLayouter(); diff --git a/src/os/macosx/string_osx.cpp b/src/os/macosx/string_osx.cpp index bd4a7e8c1c..56d742ce1f 100644 --- a/src/os/macosx/string_osx.cpp +++ b/src/os/macosx/string_osx.cpp @@ -148,7 +148,7 @@ static CTRunDelegateCallbacks _sprite_font_callback = { &SpriteFontGetWidth }; -/* static */ ParagraphLayouter *CoreTextParagraphLayoutFactory::GetParagraphLayout(CharType *buff, CharType *buff_end, FontMap &fontMapping) +/* static */ std::unique_ptr CoreTextParagraphLayoutFactory::GetParagraphLayout(CharType *buff, CharType *buff_end, FontMap &fontMapping) { if (!MacOSVersionIsAtLeast(10, 5, 0)) return nullptr; @@ -209,7 +209,7 @@ static CTRunDelegateCallbacks _sprite_font_callback = { /* Create and return typesetter for the string. */ CFAutoRelease typesetter(CTTypesetterCreateWithAttributedString(str.get())); - return typesetter ? new CoreTextParagraphLayout(std::move(typesetter), buff, length, fontMapping) : nullptr; + return typesetter ? std::make_unique(std::move(typesetter), buff, length, fontMapping) : nullptr; } /* virtual */ std::unique_ptr CoreTextParagraphLayout::NextLine(int max_width) diff --git a/src/os/macosx/string_osx.h b/src/os/macosx/string_osx.h index 8d475882e2..d8f8fecc27 100644 --- a/src/os/macosx/string_osx.h +++ b/src/os/macosx/string_osx.h @@ -52,7 +52,7 @@ public: * @param fontMapping THe mapping of the fonts. * @return The ParagraphLayout instance. */ - static ParagraphLayouter *GetParagraphLayout(CharType *buff, CharType *buff_end, FontMap &fontMapping); + static std::unique_ptr GetParagraphLayout(CharType *buff, CharType *buff_end, FontMap &fontMapping); /** * Append a wide character to the internal buffer. diff --git a/src/os/windows/string_uniscribe.cpp b/src/os/windows/string_uniscribe.cpp index bcd4295e15..33ce5fd191 100644 --- a/src/os/windows/string_uniscribe.cpp +++ b/src/os/windows/string_uniscribe.cpp @@ -276,7 +276,7 @@ static std::vector UniscribeItemizeString(UniscribeParagraphLayoutF return items; } -/* static */ ParagraphLayouter *UniscribeParagraphLayoutFactory::GetParagraphLayout(CharType *buff, CharType *buff_end, FontMap &fontMapping) +/* static */ std::unique_ptr UniscribeParagraphLayoutFactory::GetParagraphLayout(CharType *buff, CharType *buff_end, FontMap &fontMapping) { int32_t length = buff_end - buff; /* Can't layout an empty string. */ @@ -315,7 +315,7 @@ static std::vector UniscribeItemizeString(UniscribeParagraphLayoutF } } - return new UniscribeParagraphLayout(std::move(ranges), buff); + return std::make_unique(std::move(ranges), buff); } /* virtual */ std::unique_ptr UniscribeParagraphLayout::NextLine(int max_width) diff --git a/src/os/windows/string_uniscribe.h b/src/os/windows/string_uniscribe.h index 0621f5885c..edb21f7c60 100644 --- a/src/os/windows/string_uniscribe.h +++ b/src/os/windows/string_uniscribe.h @@ -34,7 +34,7 @@ public: * @param fontMapping THe mapping of the fonts. * @return The ParagraphLayout instance. */ - static ParagraphLayouter *GetParagraphLayout(CharType *buff, CharType *buff_end, FontMap &fontMapping); + static std::unique_ptr GetParagraphLayout(CharType *buff, CharType *buff_end, FontMap &fontMapping); /** * Append a wide character to the internal buffer.