From f7cc88f37055c533cd11d9d7fd402dd2c0fec305 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Fri, 12 Jan 2024 01:39:44 +0000 Subject: [PATCH] Codechange: Return vector references instead of pointer to first item. --- src/gfx_layout.h | 6 +++--- src/gfx_layout_fallback.cpp | 6 +++--- src/gfx_layout_icu.cpp | 6 +++--- src/os/macosx/string_osx.cpp | 6 +++--- src/os/windows/string_uniscribe.cpp | 23 +++++++++-------------- 5 files changed, 21 insertions(+), 26 deletions(-) diff --git a/src/gfx_layout.h b/src/gfx_layout.h index 0fe321921b..136e345b4c 100644 --- a/src/gfx_layout.h +++ b/src/gfx_layout.h @@ -96,10 +96,10 @@ public: virtual ~VisualRun() = default; virtual const Font *GetFont() const = 0; virtual int GetGlyphCount() const = 0; - virtual const GlyphID *GetGlyphs() const = 0; - virtual const float *GetPositions() const = 0; + virtual const std::vector &GetGlyphs() const = 0; + virtual const std::vector &GetPositions() const = 0; virtual int GetLeading() const = 0; - virtual const int *GetGlyphToCharMap() const = 0; + virtual const std::vector &GetGlyphToCharMap() const = 0; }; /** A single line worth of VisualRuns. */ diff --git a/src/gfx_layout_fallback.cpp b/src/gfx_layout_fallback.cpp index fe4156deb5..04f1335a95 100644 --- a/src/gfx_layout_fallback.cpp +++ b/src/gfx_layout_fallback.cpp @@ -49,10 +49,10 @@ public: FallbackVisualRun(Font *font, const char32_t *chars, int glyph_count, int char_offset, int x); const Font *GetFont() const override { return this->font; } int GetGlyphCount() const override { return static_cast(this->glyphs.size()); } - const GlyphID *GetGlyphs() const override { return this->glyphs.data(); } - const float *GetPositions() const override { return this->positions.data(); } + const std::vector &GetGlyphs() const override { return this->glyphs; } + const std::vector &GetPositions() const override { return this->positions; } int GetLeading() const override { return this->GetFont()->fc->GetHeight(); } - const int *GetGlyphToCharMap() const override { return this->glyph_to_char.data(); } + const std::vector &GetGlyphToCharMap() const override { return this->glyph_to_char; } }; /** A single line worth of VisualRuns. */ diff --git a/src/gfx_layout_icu.cpp b/src/gfx_layout_icu.cpp index c73e84866c..64c8e6752b 100644 --- a/src/gfx_layout_icu.cpp +++ b/src/gfx_layout_icu.cpp @@ -71,9 +71,9 @@ public: public: ICUVisualRun(const ICURun &run, int x); - const GlyphID *GetGlyphs() const override { return this->glyphs.data(); } - const float *GetPositions() const override { return this->positions.data(); } - const int *GetGlyphToCharMap() const override { return this->glyph_to_char.data(); } + const std::vector &GetGlyphs() const override { return this->glyphs; } + const std::vector &GetPositions() const override { return this->positions; } + const std::vector &GetGlyphToCharMap() const override { return this->glyph_to_char; } const Font *GetFont() const override { return this->font; } int GetLeading() const override { return this->font->fc->GetHeight(); } diff --git a/src/os/macosx/string_osx.cpp b/src/os/macosx/string_osx.cpp index 55927b161e..6e52c74b69 100644 --- a/src/os/macosx/string_osx.cpp +++ b/src/os/macosx/string_osx.cpp @@ -81,9 +81,9 @@ public: CoreTextVisualRun(CTRunRef run, Font *font, const CoreTextParagraphLayoutFactory::CharType *buff); CoreTextVisualRun(CoreTextVisualRun &&other) = default; - const GlyphID *GetGlyphs() const override { return &this->glyphs[0]; } - const float *GetPositions() const override { return &this->positions[0]; } - const int *GetGlyphToCharMap() const override { return &this->glyph_to_char[0]; } + const std::vector &GetGlyphs() const override { return this->glyphs; } + const std::vector &GetPositions() const override { return this->positions; } + const std::vector &GetGlyphToCharMap() const override { return this->glyph_to_char; } const Font *GetFont() const override { return this->font; } int GetLeading() const override { return this->font->fc->GetHeight(); } diff --git a/src/os/windows/string_uniscribe.cpp b/src/os/windows/string_uniscribe.cpp index c8dc6ea1eb..fd6881b533 100644 --- a/src/os/windows/string_uniscribe.cpp +++ b/src/os/windows/string_uniscribe.cpp @@ -82,19 +82,15 @@ public: int num_glyphs; Font *font; - mutable int *glyph_to_char = nullptr; + mutable std::vector glyph_to_char; public: UniscribeVisualRun(const UniscribeRun &range, int x); UniscribeVisualRun(UniscribeVisualRun &&other) noexcept; - ~UniscribeVisualRun() override - { - free(this->glyph_to_char); - } - const GlyphID *GetGlyphs() const override { return &this->glyphs[0]; } - const float *GetPositions() const override { return &this->positions[0]; } - const int *GetGlyphToCharMap() const override; + const std::vector &GetGlyphs() const override { return this->glyphs; } + const std::vector &GetPositions() const override { return this->positions; } + const std::vector &GetGlyphToCharMap() const override; const Font *GetFont() const override { return this->font; } int GetLeading() const override { return this->font->fc->GetHeight(); } @@ -492,16 +488,15 @@ UniscribeParagraphLayout::UniscribeVisualRun::UniscribeVisualRun(const Uniscribe UniscribeParagraphLayout::UniscribeVisualRun::UniscribeVisualRun(UniscribeVisualRun&& other) noexcept : glyphs(std::move(other.glyphs)), positions(std::move(other.positions)), char_to_glyph(std::move(other.char_to_glyph)), - start_pos(other.start_pos), total_advance(other.total_advance), num_glyphs(other.num_glyphs), font(other.font) + start_pos(other.start_pos), total_advance(other.total_advance), num_glyphs(other.num_glyphs), font(other.font), + glyph_to_char(std::move(other.glyph_to_char)) { - this->glyph_to_char = other.glyph_to_char; - other.glyph_to_char = nullptr; } -const int *UniscribeParagraphLayout::UniscribeVisualRun::GetGlyphToCharMap() const +const std::vector &UniscribeParagraphLayout::UniscribeVisualRun::GetGlyphToCharMap() const { - if (this->glyph_to_char == nullptr) { - this->glyph_to_char = CallocT(this->GetGlyphCount()); + if (this->glyph_to_char.empty()) { + this->glyph_to_char.resize(this->GetGlyphCount()); /* The char to glyph array contains the first glyph index of the cluster that is associated * with each character. It is possible for a cluster to be formed of several chars. */