mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use unique_ptr instead of raw pointer for string layouts. (#13128)
parent
cf7710fb61
commit
fe0afef36f
|
@ -171,10 +171,10 @@ public:
|
||||||
FontMap runs; ///< Accessed by our ParagraphLayout::nextLine.
|
FontMap runs; ///< Accessed by our ParagraphLayout::nextLine.
|
||||||
|
|
||||||
FontState state_after; ///< Font state after the line.
|
FontState state_after; ///< Font state after the line.
|
||||||
ParagraphLayouter *layout; ///< Layout of the line.
|
std::unique_ptr<ParagraphLayouter> layout = nullptr; ///< Layout of the line.
|
||||||
|
|
||||||
LineCacheItem() : buffer(nullptr), layout(nullptr) {}
|
LineCacheItem() : buffer(nullptr) {}
|
||||||
~LineCacheItem() { delete layout; free(buffer); }
|
~LineCacheItem() { free(buffer); }
|
||||||
};
|
};
|
||||||
private:
|
private:
|
||||||
typedef std::map<LineCacheKey, LineCacheItem, LineCacheCompare> LineCache;
|
typedef std::map<LineCacheKey, LineCacheItem, LineCacheCompare> LineCache;
|
||||||
|
|
|
@ -82,9 +82,9 @@ public:
|
||||||
* @param fontMapping THe mapping of the fonts.
|
* @param fontMapping THe mapping of the fonts.
|
||||||
* @return The ParagraphLayout instance.
|
* @return The ParagraphLayout instance.
|
||||||
*/
|
*/
|
||||||
/* static */ ParagraphLayouter *FallbackParagraphLayoutFactory::GetParagraphLayout(char32_t *buff, char32_t *buff_end, FontMap &fontMapping)
|
/* static */ std::unique_ptr<ParagraphLayouter> FallbackParagraphLayoutFactory::GetParagraphLayout(char32_t *buff, char32_t *buff_end, FontMap &fontMapping)
|
||||||
{
|
{
|
||||||
return new FallbackParagraphLayout(buff, buff_end - buff, fontMapping);
|
return std::make_unique<FallbackParagraphLayout>(buff, buff_end - buff, fontMapping);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -22,7 +22,7 @@ public:
|
||||||
/** Helper for GetLayouter, to get whether the layouter supports RTL. */
|
/** Helper for GetLayouter, to get whether the layouter supports RTL. */
|
||||||
static const bool SUPPORTS_RTL = false;
|
static const bool SUPPORTS_RTL = false;
|
||||||
|
|
||||||
static ParagraphLayouter *GetParagraphLayout(char32_t *buff, char32_t *buff_end, FontMap &fontMapping);
|
static std::unique_ptr<ParagraphLayouter> 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);
|
static size_t AppendToBuffer(char32_t *buff, const char32_t *buffer_last, char32_t c);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -353,7 +353,7 @@ std::vector<ICURun> ItemizeStyle(std::vector<ICURun> &runs_current, FontMap &fon
|
||||||
return runs;
|
return runs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ ParagraphLayouter *ICUParagraphLayoutFactory::GetParagraphLayout(UChar *buff, UChar *buff_end, FontMap &font_mapping)
|
/* static */ std::unique_ptr<ParagraphLayouter> ICUParagraphLayoutFactory::GetParagraphLayout(UChar *buff, UChar *buff_end, FontMap &font_mapping)
|
||||||
{
|
{
|
||||||
size_t length = buff_end - buff;
|
size_t length = buff_end - buff;
|
||||||
/* Can't layout an empty string. */
|
/* Can't layout an empty string. */
|
||||||
|
@ -374,7 +374,7 @@ std::vector<ICURun> ItemizeStyle(std::vector<ICURun> &runs_current, FontMap &fon
|
||||||
run.Shape(buff, length);
|
run.Shape(buff, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ICUParagraphLayout(std::move(runs), buff, length);
|
return std::make_unique<ICUParagraphLayout>(std::move(runs), buff, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ std::unique_ptr<icu::BreakIterator> ICUParagraphLayoutFactory::break_iterator;
|
/* static */ std::unique_ptr<icu::BreakIterator> ICUParagraphLayoutFactory::break_iterator;
|
||||||
|
|
|
@ -25,7 +25,7 @@ public:
|
||||||
/** Helper for GetLayouter, to get whether the layouter supports RTL. */
|
/** Helper for GetLayouter, to get whether the layouter supports RTL. */
|
||||||
static const bool SUPPORTS_RTL = true;
|
static const bool SUPPORTS_RTL = true;
|
||||||
|
|
||||||
static ParagraphLayouter *GetParagraphLayout(UChar *buff, UChar *buff_end, FontMap &fontMapping);
|
static std::unique_ptr<ParagraphLayouter> GetParagraphLayout(UChar *buff, UChar *buff_end, FontMap &fontMapping);
|
||||||
static size_t AppendToBuffer(UChar *buff, const UChar *buffer_last, char32_t c);
|
static size_t AppendToBuffer(UChar *buff, const UChar *buffer_last, char32_t c);
|
||||||
|
|
||||||
static void InitializeLayouter();
|
static void InitializeLayouter();
|
||||||
|
|
|
@ -148,7 +148,7 @@ static CTRunDelegateCallbacks _sprite_font_callback = {
|
||||||
&SpriteFontGetWidth
|
&SpriteFontGetWidth
|
||||||
};
|
};
|
||||||
|
|
||||||
/* static */ ParagraphLayouter *CoreTextParagraphLayoutFactory::GetParagraphLayout(CharType *buff, CharType *buff_end, FontMap &fontMapping)
|
/* static */ std::unique_ptr<ParagraphLayouter> CoreTextParagraphLayoutFactory::GetParagraphLayout(CharType *buff, CharType *buff_end, FontMap &fontMapping)
|
||||||
{
|
{
|
||||||
if (!MacOSVersionIsAtLeast(10, 5, 0)) return nullptr;
|
if (!MacOSVersionIsAtLeast(10, 5, 0)) return nullptr;
|
||||||
|
|
||||||
|
@ -209,7 +209,7 @@ static CTRunDelegateCallbacks _sprite_font_callback = {
|
||||||
/* Create and return typesetter for the string. */
|
/* Create and return typesetter for the string. */
|
||||||
CFAutoRelease<CTTypesetterRef> typesetter(CTTypesetterCreateWithAttributedString(str.get()));
|
CFAutoRelease<CTTypesetterRef> typesetter(CTTypesetterCreateWithAttributedString(str.get()));
|
||||||
|
|
||||||
return typesetter ? new CoreTextParagraphLayout(std::move(typesetter), buff, length, fontMapping) : nullptr;
|
return typesetter ? std::make_unique<CoreTextParagraphLayout>(std::move(typesetter), buff, length, fontMapping) : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* virtual */ std::unique_ptr<const ParagraphLayouter::Line> CoreTextParagraphLayout::NextLine(int max_width)
|
/* virtual */ std::unique_ptr<const ParagraphLayouter::Line> CoreTextParagraphLayout::NextLine(int max_width)
|
||||||
|
|
|
@ -52,7 +52,7 @@ public:
|
||||||
* @param fontMapping THe mapping of the fonts.
|
* @param fontMapping THe mapping of the fonts.
|
||||||
* @return The ParagraphLayout instance.
|
* @return The ParagraphLayout instance.
|
||||||
*/
|
*/
|
||||||
static ParagraphLayouter *GetParagraphLayout(CharType *buff, CharType *buff_end, FontMap &fontMapping);
|
static std::unique_ptr<ParagraphLayouter> GetParagraphLayout(CharType *buff, CharType *buff_end, FontMap &fontMapping);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Append a wide character to the internal buffer.
|
* Append a wide character to the internal buffer.
|
||||||
|
|
|
@ -276,7 +276,7 @@ static std::vector<SCRIPT_ITEM> UniscribeItemizeString(UniscribeParagraphLayoutF
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ ParagraphLayouter *UniscribeParagraphLayoutFactory::GetParagraphLayout(CharType *buff, CharType *buff_end, FontMap &fontMapping)
|
/* static */ std::unique_ptr<ParagraphLayouter> UniscribeParagraphLayoutFactory::GetParagraphLayout(CharType *buff, CharType *buff_end, FontMap &fontMapping)
|
||||||
{
|
{
|
||||||
int32_t length = buff_end - buff;
|
int32_t length = buff_end - buff;
|
||||||
/* Can't layout an empty string. */
|
/* Can't layout an empty string. */
|
||||||
|
@ -315,7 +315,7 @@ static std::vector<SCRIPT_ITEM> UniscribeItemizeString(UniscribeParagraphLayoutF
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new UniscribeParagraphLayout(std::move(ranges), buff);
|
return std::make_unique<UniscribeParagraphLayout>(std::move(ranges), buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* virtual */ std::unique_ptr<const ParagraphLayouter::Line> UniscribeParagraphLayout::NextLine(int max_width)
|
/* virtual */ std::unique_ptr<const ParagraphLayouter::Line> UniscribeParagraphLayout::NextLine(int max_width)
|
||||||
|
|
|
@ -34,7 +34,7 @@ public:
|
||||||
* @param fontMapping THe mapping of the fonts.
|
* @param fontMapping THe mapping of the fonts.
|
||||||
* @return The ParagraphLayout instance.
|
* @return The ParagraphLayout instance.
|
||||||
*/
|
*/
|
||||||
static ParagraphLayouter *GetParagraphLayout(CharType *buff, CharType *buff_end, FontMap &fontMapping);
|
static std::unique_ptr<ParagraphLayouter> GetParagraphLayout(CharType *buff, CharType *buff_end, FontMap &fontMapping);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Append a wide character to the internal buffer.
|
* Append a wide character to the internal buffer.
|
||||||
|
|
Loading…
Reference in New Issue