mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2026-07-24 12:06:41 +00:00
Codechange: use size_t for glyph/run counts, remove unneeded glyph count instance variable
This commit is contained in:
+2
-2
@@ -592,7 +592,7 @@ static int DrawLayoutLine(const ParagraphLayouter::Line &line, int y, int left,
|
||||
int dpi_right = dpi->left + dpi->width - 1;
|
||||
TextColour last_colour = initial_colour;
|
||||
|
||||
for (int run_index = 0; run_index < line.CountRuns(); run_index++) {
|
||||
for (size_t run_index = 0; run_index < line.CountRuns(); run_index++) {
|
||||
const ParagraphLayouter::VisualRun &run = line.GetVisualRun(run_index);
|
||||
const auto &glyphs = run.GetGlyphs();
|
||||
const auto &positions = run.GetPositions();
|
||||
@@ -607,7 +607,7 @@ static int DrawLayoutLine(const ParagraphLayouter::Line &line, int y, int left,
|
||||
if (do_shadow && (!fc->GetDrawGlyphShadow() || !colour_has_shadow)) continue;
|
||||
SetColourRemap(do_shadow ? TC_BLACK : colour);
|
||||
|
||||
for (int i = 0; i < run.GetGlyphCount(); i++) {
|
||||
for (size_t i = 0; i < run.GetGlyphCount(); i++) {
|
||||
GlyphID glyph = glyphs[i];
|
||||
|
||||
/* Not a valid glyph (empty) */
|
||||
|
||||
+3
-3
@@ -270,7 +270,7 @@ ParagraphLayouter::Position Layouter::GetCharPosition(std::string_view::const_it
|
||||
|
||||
/* Scan all runs until we've found our code point index. */
|
||||
size_t best_index = SIZE_MAX;
|
||||
for (int run_index = 0; run_index < line->CountRuns(); run_index++) {
|
||||
for (size_t run_index = 0; run_index < line->CountRuns(); run_index++) {
|
||||
const ParagraphLayouter::VisualRun &run = line->GetVisualRun(run_index);
|
||||
const auto &positions = run.GetPositions();
|
||||
const auto &charmap = run.GetGlyphToCharMap();
|
||||
@@ -308,13 +308,13 @@ ptrdiff_t Layouter::GetCharAtPosition(int x, size_t line_index) const
|
||||
|
||||
const auto &line = this->at(line_index);
|
||||
|
||||
for (int run_index = 0; run_index < line->CountRuns(); run_index++) {
|
||||
for (size_t run_index = 0; run_index < line->CountRuns(); run_index++) {
|
||||
const ParagraphLayouter::VisualRun &run = line->GetVisualRun(run_index);
|
||||
const auto &glyphs = run.GetGlyphs();
|
||||
const auto &positions = run.GetPositions();
|
||||
const auto &charmap = run.GetGlyphToCharMap();
|
||||
|
||||
for (int i = 0; i < run.GetGlyphCount(); i++) {
|
||||
for (size_t i = 0; i < run.GetGlyphCount(); i++) {
|
||||
/* Not a valid glyph (empty). */
|
||||
if (glyphs[i] == 0xFFFF) continue;
|
||||
|
||||
|
||||
+3
-3
@@ -143,7 +143,7 @@ public:
|
||||
* Get the number of glyphs.
|
||||
* @return The number of glyphs for this run.
|
||||
*/
|
||||
virtual int GetGlyphCount() const = 0;
|
||||
virtual size_t GetGlyphCount() const = 0;
|
||||
|
||||
/**
|
||||
* Get the glyphs to draw.
|
||||
@@ -191,14 +191,14 @@ public:
|
||||
* Get the number of runs in this line.
|
||||
* @return The number of runs.
|
||||
*/
|
||||
virtual int CountRuns() const = 0;
|
||||
virtual size_t CountRuns() const = 0;
|
||||
|
||||
/**
|
||||
* Get a reference to the given run.
|
||||
* @param run The index into the runs.
|
||||
* @return The reference to the run.
|
||||
*/
|
||||
virtual const VisualRun &GetVisualRun(int run) const = 0;
|
||||
virtual const VisualRun &GetVisualRun(size_t run) const = 0;
|
||||
|
||||
/**
|
||||
* Get the number of elements the given character occupies in the underlying text buffer of the Layouter.
|
||||
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
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()); }
|
||||
size_t GetGlyphCount() const override { return this->glyphs.size(); }
|
||||
std::span<const GlyphID> GetGlyphs() const override { return this->glyphs; }
|
||||
std::span<const Position> GetPositions() const override { return this->positions; }
|
||||
int GetLeading() const override { return this->GetFont()->fc->GetHeight(); }
|
||||
@@ -60,8 +60,8 @@ public:
|
||||
public:
|
||||
int GetLeading() const override;
|
||||
int GetWidth() const override;
|
||||
int CountRuns() const override;
|
||||
const ParagraphLayouter::VisualRun &GetVisualRun(int run) const override;
|
||||
size_t CountRuns() const override;
|
||||
const ParagraphLayouter::VisualRun &GetVisualRun(size_t run) const override;
|
||||
|
||||
int GetInternalCharLength(char32_t) const override { return 1; }
|
||||
};
|
||||
@@ -159,12 +159,12 @@ int FallbackParagraphLayout::FallbackLine::GetWidth() const
|
||||
return positions.back().right + 1;
|
||||
}
|
||||
|
||||
int FallbackParagraphLayout::FallbackLine::CountRuns() const
|
||||
size_t FallbackParagraphLayout::FallbackLine::CountRuns() const
|
||||
{
|
||||
return static_cast<int>(this->size());
|
||||
return this->size();
|
||||
}
|
||||
|
||||
const ParagraphLayouter::VisualRun &FallbackParagraphLayout::FallbackLine::GetVisualRun(int run) const
|
||||
const ParagraphLayouter::VisualRun &FallbackParagraphLayout::FallbackLine::GetVisualRun(size_t run) const
|
||||
{
|
||||
return this->at(run);
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public:
|
||||
|
||||
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(); }
|
||||
size_t GetGlyphCount() const override { return this->glyphs.size(); }
|
||||
int GetAdvance() const { return this->total_advance; }
|
||||
};
|
||||
|
||||
@@ -86,8 +86,8 @@ public:
|
||||
public:
|
||||
int GetLeading() const override;
|
||||
int GetWidth() const override;
|
||||
int CountRuns() const override { return (uint)this->size(); }
|
||||
const VisualRun &GetVisualRun(int run) const override { return this->at(run); }
|
||||
size_t CountRuns() const override { return this->size(); }
|
||||
const VisualRun &GetVisualRun(size_t run) const override { return this->at(run); }
|
||||
|
||||
int GetInternalCharLength(char32_t c) const override
|
||||
{
|
||||
|
||||
@@ -61,7 +61,7 @@ public:
|
||||
|
||||
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(); }
|
||||
size_t GetGlyphCount() const override { return this->glyphs.size(); }
|
||||
int GetAdvance() const { return this->total_advance; }
|
||||
};
|
||||
|
||||
@@ -84,8 +84,8 @@ public:
|
||||
|
||||
int GetLeading() const override;
|
||||
int GetWidth() const override;
|
||||
int CountRuns() const override { return this->size(); }
|
||||
const VisualRun &GetVisualRun(int run) const override { return this->at(run); }
|
||||
size_t CountRuns() const override { return this->size(); }
|
||||
const VisualRun &GetVisualRun(size_t run) const override { return this->at(run); }
|
||||
|
||||
int GetInternalCharLength(char32_t c) const override
|
||||
{
|
||||
|
||||
@@ -80,7 +80,6 @@ public:
|
||||
|
||||
int start_pos;
|
||||
int total_advance;
|
||||
int num_glyphs;
|
||||
Font *font;
|
||||
|
||||
mutable std::vector<int> glyph_to_char;
|
||||
@@ -95,7 +94,7 @@ public:
|
||||
|
||||
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; }
|
||||
size_t GetGlyphCount() const override { return this->glyphs.size(); }
|
||||
int GetAdvance() const { return this->total_advance; }
|
||||
};
|
||||
|
||||
@@ -104,8 +103,8 @@ public:
|
||||
public:
|
||||
int GetLeading() const override;
|
||||
int GetWidth() const override;
|
||||
int CountRuns() const override { return (uint)this->size(); }
|
||||
const VisualRun &GetVisualRun(int run) const override { return this->at(run); }
|
||||
size_t CountRuns() const override { return this->size(); }
|
||||
const VisualRun &GetVisualRun(size_t run) const override { return this->at(run); }
|
||||
|
||||
int GetInternalCharLength(char32_t c) const override
|
||||
{
|
||||
@@ -471,11 +470,10 @@ int UniscribeParagraphLayout::UniscribeLine::GetWidth() const
|
||||
|
||||
UniscribeParagraphLayout::UniscribeVisualRun::UniscribeVisualRun(const UniscribeRun &range, int x) : glyphs(range.ft_glyphs), char_to_glyph(range.char_to_glyph), start_pos(range.pos), total_advance(range.total_advance), font(range.font)
|
||||
{
|
||||
this->num_glyphs = (int)glyphs.size();
|
||||
this->positions.reserve(this->num_glyphs);
|
||||
this->positions.reserve(this->GetGlyphCount());
|
||||
|
||||
int advance = x;
|
||||
for (int i = 0; i < this->num_glyphs; i++) {
|
||||
for (size_t i = 0; i < this->GetGlyphCount(); i++) {
|
||||
int x_advance = range.advances[i];
|
||||
this->positions.emplace_back(range.offsets[i].du + advance, range.offsets[i].du + advance + x_advance - 1, range.offsets[i].dv);
|
||||
|
||||
@@ -485,7 +483,7 @@ 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), font(other.font),
|
||||
glyph_to_char(std::move(other.glyph_to_char))
|
||||
{
|
||||
}
|
||||
@@ -504,7 +502,7 @@ std::span<const int> UniscribeParagraphLayout::UniscribeVisualRun::GetGlyphToCha
|
||||
|
||||
/* We only marked the first glyph of each cluster in the loop above. Fill the gaps. */
|
||||
int last_char = this->glyph_to_char[0];
|
||||
for (int g = 0; g < this->GetGlyphCount(); g++) {
|
||||
for (size_t g = 0; g < this->GetGlyphCount(); g++) {
|
||||
if (this->glyph_to_char[g] != 0) last_char = this->glyph_to_char[g];
|
||||
this->glyph_to_char[g] = last_char;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user