Changeset - r28510:44c3f063764d
[Not reviewed]
master
0 5 0
Peter Nelson - 11 months ago 2024-01-12 01:39:44
peter1138@openttd.org
Codechange: Return vector references instead of pointer to first item.
5 files changed with 21 insertions and 26 deletions:
0 comments (0 inline, 0 general)
src/gfx_layout.h
Show inline comments
 
@@ -93,16 +93,16 @@ public:
 
	/** Visual run contains data about the bit of text with the same font. */
 
	class VisualRun {
 
	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<GlyphID> &GetGlyphs() const = 0;
 
		virtual const std::vector<float> &GetPositions() const = 0;
 
		virtual int GetLeading() const = 0;
 
		virtual const int *GetGlyphToCharMap() const = 0;
 
		virtual const std::vector<int> &GetGlyphToCharMap() const = 0;
 
	};
 

	
 
	/** A single line worth of VisualRuns. */
 
	class Line {
 
	public:
 
		virtual ~Line() = default;
src/gfx_layout_fallback.cpp
Show inline comments
 
@@ -46,16 +46,16 @@ public:
 
		Font *font;       ///< The font used to layout these.
 

	
 
	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<int>(this->glyphs.size()); }
 
		const GlyphID *GetGlyphs() const override { return this->glyphs.data(); }
 
		const float *GetPositions() const override { return this->positions.data(); }
 
		const std::vector<GlyphID> &GetGlyphs() const override { return this->glyphs; }
 
		const std::vector<float> &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<int> &GetGlyphToCharMap() const override { return this->glyph_to_char; }
 
	};
 

	
 
	/** A single line worth of VisualRuns. */
 
	class FallbackLine : public std::vector<FallbackVisualRun>, public ParagraphLayouter::Line {
 
	public:
 
		int GetLeading() const override;
src/gfx_layout_icu.cpp
Show inline comments
 
@@ -68,15 +68,15 @@ public:
 
		int total_advance;
 
		const Font *font;
 

	
 
	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<GlyphID> &GetGlyphs() const override { return this->glyphs; }
 
		const std::vector<float> &GetPositions() const override { return this->positions; }
 
		const std::vector<int> &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(); }
 
		int GetGlyphCount() const override { return this->glyphs.size(); }
 
		int GetAdvance() const { return this->total_advance; }
 
	};
src/os/macosx/string_osx.cpp
Show inline comments
 
@@ -78,15 +78,15 @@ public:
 
		Font *font;
 

	
 
	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<GlyphID> &GetGlyphs() const override { return this->glyphs; }
 
		const std::vector<float> &GetPositions() const override { return this->positions; }
 
		const std::vector<int> &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(); }
 
		int GetGlyphCount() const override { return (int)this->glyphs.size(); }
 
		int GetAdvance() const { return this->total_advance; }
 
	};
src/os/windows/string_uniscribe.cpp
Show inline comments
 
@@ -79,25 +79,21 @@ public:
 

	
 
		int start_pos;
 
		int total_advance;
 
		int num_glyphs;
 
		Font *font;
 

	
 
		mutable int *glyph_to_char = nullptr;
 
		mutable std::vector<int> 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<GlyphID> &GetGlyphs() const override { return this->glyphs; }
 
		const std::vector<float> &GetPositions() const override { return this->positions; }
 
		const std::vector<int> &GetGlyphToCharMap() const override;
 

	
 
		const Font *GetFont() const override { return this->font;  }
 
		int GetLeading() const override { return this->font->fc->GetHeight(); }
 
		int GetGlyphCount() const override { return this->num_glyphs; }
 
		int GetAdvance() const { return this->total_advance; }
 
	};
 
@@ -489,22 +485,21 @@ UniscribeParagraphLayout::UniscribeVisua
 
	}
 
	this->positions[this->num_glyphs * 2] = advance + x;
 
}
 

	
 
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<int> &UniscribeParagraphLayout::UniscribeVisualRun::GetGlyphToCharMap() const
 
{
 
	if (this->glyph_to_char == nullptr) {
 
		this->glyph_to_char = CallocT<int>(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. */
 
		for (int c = 0; c < (int)this->char_to_glyph.size(); c++) {
 
			/* If multiple chars map to one glyph, only refer back to the first character. */
 
			if (this->glyph_to_char[this->char_to_glyph[c]] == 0) this->glyph_to_char[this->char_to_glyph[c]] = c + this->start_pos;
0 comments (0 inline, 0 general)