diff --git a/src/gfx_layout.h b/src/gfx_layout.h --- 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 --- 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 --- 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 --- 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 --- 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::UniscribeVisua 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. */